-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdLog.c
212 lines (186 loc) · 6.66 KB
/
cmdLog.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
/*****
** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: cmdLog.c **
** First Edition: 1995/12/26 **
** **
** Authors: Jens Hamisch, [email protected] **
** R.K. Owen, <[email protected]> or <[email protected]> **
** **
** Description: The Tcl module-log routine which provides an **
** interface to the modulecmd syslog/stderr output. **
** **
** Exports: cmdModuleLog **
** **
** Notes: **
** **
** ************************************************************************ **
****/
/** ** Copyright *********************************************************** **
** **
** Copyright 1991-1994 by John L. Furlan. **
** see LICENSE.GPL, which must be provided, for details **
** **
** ************************************************************************ **/
static char Id[] = "@(#)$Id$";
static void *UseId[] = { &UseId, Id };
/** ************************************************************************ **/
/** HEADERS **/
/** ************************************************************************ **/
#include "modules_def.h"
/** ************************************************************************ **/
/** LOCAL DATATYPES **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** CONSTANTS **/
/** ************************************************************************ **/
#define PART_LEN 256 /** Length of the string parts for **/
/** facility list handling **/
/** ************************************************************************ **/
/** MACROS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** LOCAL DATA **/
/** ************************************************************************ **/
static char module_name[] = __FILE__;
static char _stderr[] = "stderr";
static char _stdout[] = "stdout";
static char _null[] = "null";
static char _none[] = "none";
/** ************************************************************************ **/
/** PROTOTYPES **/
/** ************************************************************************ **/
/** not applicable **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: cmdModuleLog **
** **
** Description: Callback function for 'module-log' **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: ClientData client_data **
** Tcl_Interp *interp According Tcl interp.**
** int objc Number of arguments **
** Tcl_Obj *objv[] Argument array **
** **
** Result: int TCL_OK Successful completion **
** TCL_ERROR Any error **
** **
** Attached Globals: g_flags These are set up accordingly before **
** this function is called in order to **
** control everything **
** **
** ************************************************************************ **
++++*/
int cmdModuleLog(
ClientData client_data,
Tcl_Interp * interp,
int objc,
Tcl_Obj * CONST84 objv[]
) {
char **facptr, **vptr, *s;
int i;
uvec *faclist,
*tmpuv = NULL;
/**
** Whatis mode?
**/
if (g_flags & (M_WHATIS | M_HELP))
return (TCL_OK); /** ------- EXIT PROCEDURE -------> **/
/**
** Parameter check
**/
if (objc < 3) {
if (OK != ErrorLogger(ERR_USAGE, LOC, Tcl_GetString(objv[0]),
" error-weight", " facility", NULL))
return (TCL_ERROR); /** ------ EXIT (FAILURE) -----> **/
}
/**
** Display mode?
**/
if (g_flags & M_DISPLAY) {
fprintf(stderr, "%s\t ", Tcl_GetString(*objv++));
while (--objc)
fprintf(stderr, "%s ", Tcl_GetString(*objv++));
fprintf(stderr, "\n");
return (TCL_OK); /** -------- EXIT PROCEDURE -------> **/
}
/**
** Get the current facility pointer.
**/
if (!(facptr = GetFacilityPtr((char *)Tcl_GetString(objv[1]))))
return ((OK == ErrorLogger(ERR_INVWGHT_WARN, LOC,
Tcl_GetString(objv[1]), NULL))
? TCL_OK : TCL_ERROR);
/**
** Allocate memory for the facility list
**/
if (!(faclist = uvec_ctor(objc)))
return ((OK == ErrorLogger(ERR_UVEC, LOC, NULL))
? TCL_OK : TCL_ERROR);
/**
** Scan all given facilities and add them to the list
** Which can be listed as individual arguments or joined together
** with a ':' (or both)
**/
for (i = 2; i < objc; i++) {
s = Tcl_GetString(objv[i]);
/* check for at least one ':' */
if (strchr(s, ':')) {
tmpuv = str2uvec(":", s);
vptr = uvec_vector(tmpuv);
while (vptr && *vptr) {
if(0 > uvec_add(faclist,*vptr++))
return ((OK == ErrorLogger(ERR_UVEC,
LOC, NULL)) ? TCL_OK : TCL_ERROR);
}
uvec_dtor(&tmpuv);
} else {
if(0 > uvec_add(faclist, Tcl_GetString(objv[i])))
return ((OK == ErrorLogger(ERR_UVEC, LOC, NULL))
? TCL_OK : TCL_ERROR);
}
}
/**
** Now scan the whole list and delete the invalid ones
**/
for (i = uvec_number(faclist) - 1; i >= 0; i--) {
s = uvec_vector(faclist)[i];
if (s && !*s)
continue; /* skip empty ones */
if ('.' == *s || *psep == *s || /** filename **/
!strcmp(_stderr, s) || !strcmp(_stdout, s) ||
/** special **/
!strcmp(_null, s) || !strcmp(_none, s) || /** null **/
CheckFacility(s, NULL, NULL)) { /** syslog **/
/* got a keeper */
} else {
/**
** bad facility found
**/
if (OK != ErrorLogger(ERR_INVFAC_WARN, LOC, s, NULL))
break; /** for **/
if (0 > uvec_delete(faclist,i))
return ((OK == ErrorLogger(ERR_UVEC, LOC, NULL))
? TCL_OK : TCL_ERROR);
}
} /** for **/
s = uvec2str(faclist,":");
/**
** Now, 's' should contain the new list of facilities. Check whether
** there has been one allocated so far ...
** We do not need the original faclist any more.
**/
uvec_dtor(&faclist);
if ((char *)NULL != *facptr)
null_free((void *)facptr);
*facptr = s;
return (TCL_OK);
} /** End of 'cmdModuleLog' **/