1    | /*****
2    |  ** ** Module Header ******************************************************* **
3    |  ** 									     **
4    |  **   Modules Revision 3.0						     **
5    |  **   Providing a flexible user environment				     **
6    |  ** 									     **
7    |  **   File:		cmdLog.c					     **
8    |  **   First Edition:	1995/12/26					     **
9    |  ** 									     **
10   |  **   Authors:	Jens Hamisch, jens@Strawberry.COM			     **
11   |  ** 									     **
12   |  **   Description:	The Tcl module-trace routine which provides a con-   **
13   |  **			trolling interface to the modulecmd tracing feature  **
14   |  ** 									     **
15   |  **   Exports:		cmdModuleLog					     **
16   |  ** 									     **
17   |  **   Notes:								     **
18   |  ** 									     **
19   |  ** ************************************************************************ **
20   |  ****/
21   | 
22   | /** ** Copyright *********************************************************** **
23   |  ** 									     **
24   |  ** Copyright 1991-1994 by John L. Furlan.                      	     **
25   |  ** see LICENSE.GPL, which must be provided, for details		     **
26   |  ** 									     ** 
27   |  ** ************************************************************************ **/
28   | 
29   | static char Id[] = "@(#)$Id: cmdLog.c.src.html,v 1.6 2006/01/18 05:35:11 rkowen Exp $";
30   | static void *UseId[] = { &UseId, Id };
31   | 
32   | /** ************************************************************************ **/
33   | /** 				      HEADERS				     **/
34   | /** ************************************************************************ **/
35   | 
36   | #include "modules_def.h"
37   | 
38   | /** ************************************************************************ **/
39   | /** 				  LOCAL DATATYPES			     **/
40   | /** ************************************************************************ **/
41   | 
42   | /** not applicable **/
43   | 
44   | /** ************************************************************************ **/
45   | /** 				     CONSTANTS				     **/
46   | /** ************************************************************************ **/
47   | 
48   | #define	PART_LEN	256		/** Length of the string parts for   **/
49   | 					/** facility list handling	     **/
50   | 
51   | /** ************************************************************************ **/
52   | /**				      MACROS				     **/
53   | /** ************************************************************************ **/
54   | 
55   | /** not applicable **/
56   | 
57   | /** ************************************************************************ **/
58   | /** 				    LOCAL DATA				     **/
59   | /** ************************************************************************ **/
60   | 
61   | static	char	module_name[] = "cmdLog.c";	/** File name of this module **/
62   | #if WITH_DEBUGGING_CALLBACK
63   | static	char	_proc_cmdModuleLog[] = "cmdModuleLog";
64   | #endif
65   | 
66   | static	char	_stderr[] = "stderr";
67   | static	char	_stdout[] = "stdout";
68   | static	char	_null[] = "null";
69   | static	char	_none[] = "none";
70   | 
71   | /** ************************************************************************ **/
72   | /**				    PROTOTYPES				     **/
73   | /** ************************************************************************ **/
74   | 
75   | /** not applicable **/
76   | 
77   | 
78   | /*++++
79   |  ** ** Function-Header ***************************************************** **
80   |  ** 									     **
81   |  **   Function:		cmdModuleLog					     **
82   |  ** 									     **
83   |  **   Description:	Callback function for 'log'			     **
84   |  ** 									     **
85   |  **   First Edition:	1991/10/23					     **
86   |  ** 									     **
87   |  **   Parameters:	ClientData	 client_data			     **
88   |  **			Tcl_Interp	*interp		According Tcl interp.**
89   |  **			int		 argc		Number of arguments  **
90   |  **			char		*argv[]		Argument array	     **
91   |  ** 									     **
92   |  **   Result:		int	TCL_OK		Successfull completion	     **
93   |  **				TCL_ERROR	Any error		     **
94   |  ** 									     **
95   |  **   Attached Globals:	tracelist	List containing all tracing settings **
96   |  **   			g_flags		These are set up accordingly before  **
97   |  **					this function is called in order to  **
98   |  **					control everything		     **
99   |  ** 									     **
100  |  ** ************************************************************************ **
101  |  ++++*/
102  | 
103  | int	cmdModuleLog(	ClientData	 client_data,
104  | 	      		Tcl_Interp	*interp,
105  | 	      		int		 argc,
106  | 	      		CONST84 char	*argv[])
107  | {
108  |     char	**facptr;
109  |     int		  i, len = 0, alc_len = PART_LEN, save_len;
110  |     char	 *faclist, *s, *tmp, *t;
111  | 
112  | #if WITH_DEBUGGING_CALLBACK
113  |     ErrorLogger( NO_ERR_START, LOC, _proc_cmdModuleLog, NULL);
114  | #endif
115  | 
116  |     /**
117  |      **  Whatis mode?
118  |      **/
119  |     if( g_flags & (M_WHATIS | M_HELP))
120  |         return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
121  | 	
122  |     /**
123  |      **  Parameter check
124  |      **/
125  |     if( argc < 3) {
126  | 	if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], " error-weight",
127  | 	    " facility", NULL))
128  | 	    return( TCL_ERROR);		/** -------- EXIT (FAILURE) -------> **/
129  |     }
130  |   
131  |     /**
132  |      **  Display mode?
133  |      **/
134  |     if( g_flags & M_DISPLAY) {
135  | 	fprintf( stderr, "%s\t ", argv[ 0]);
136  | 	while( --argc)
137  | 	    fprintf( stderr, "%s ", *++argv);
138  | 	fprintf( stderr, "\n");
139  |         return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
140  |     }
141  | 	
142  |     /**
143  |      **  Get the current facility pointer.
144  |      **/
145  |     if((char **) NULL == (facptr = GetFacilityPtr( (char *) argv[1]))) 
146  | 	return(( OK == ErrorLogger(ERR_INVWGHT_WARN,LOC, argv[1],NULL))
147  | 	    ? TCL_OK : TCL_ERROR);
148  | 
149  |     /**
150  |      **  Allocate memory for the facility list
151  |      **/
152  |     if((char *) NULL == (faclist = (char *) malloc( alc_len)))
153  | 	return(( OK == ErrorLogger( ERR_ALLOC, LOC, NULL)) ?
154  | 	    TCL_OK : TCL_ERROR);
155  | 
156  |     /**
157  |      **  Scan all given facilities and add them to the list
158  |      **/
159  |     for( i=2; i<argc; i++) {
160  | 	save_len = len;
161  | 	len += strlen( argv[ i]) + 1;
162  | 
163  | 	while( len + 1 > alc_len) {
164  | 	    alc_len += PART_LEN;
165  | 	    if((char *) NULL == (faclist = (char *) realloc( faclist, alc_len)))
166  | 		return(( OK == ErrorLogger( ERR_ALLOC, LOC, NULL)) ?
167  | 		    TCL_OK : TCL_ERROR);
168  | 	}
169  | 
170  | 	faclist[save_len] = ':';
171  | 	strcpy( &faclist[save_len + 1], argv[ i]);
172  |     }
173  | 
174  |     /**
175  |      **  Now scan the whole list and copy all valid parts into a new buffer
176  |      **/
177  |     if((char *) NULL == (tmp = stringer(NULL, strlen( faclist), NULL))) {
178  | 	null_free((void *) &faclist);
179  | 	return(( OK == ErrorLogger( ERR_ALLOC, LOC, NULL)) ?
180  | 	    TCL_OK : TCL_ERROR);
181  |     }
182  | 
183  |     for( t = tmp, s = strtok( faclist, ":, \t");
184  | 	 s;
185  | 	 s = strtok( NULL, ":, \t") ) {
186  | 
187  | 	if( '.' == *s || '/' == *s ||			       /** filename  **/
188  | 	    !strcmp( _stderr, s) || !strcmp( _stdout, s) ||    /** special   **/
189  | 	    !strcmp( _null, s) || !strcmp( _none, s) ||        /** null	     **/
190  | 	    CheckFacility( s, &i, &i) ) {		       /** syslog    **/
191  | 
192  | 	    if( t != tmp) 
193  | 		*t++ = ':';
194  | 	    strcpy( t, s);
195  | 
196  | 	    t += strlen( s);
197  | 
198  | 	} else {
199  | 
200  | 	    /**
201  | 	     **  bad facility found
202  | 	     **/
203  | 
204  | 	    if( OK != ErrorLogger( ERR_INVFAC_WARN, LOC, s, NULL))
205  | 		break;  /** for **/
206  | 	}
207  |     } /** for **/
208  | 
209  |     /**
210  |      **  Now, 'tmp' should contain the new list of facilities. Check wheter
211  |      **  there has been one allocated so far ...
212  |      **  We do not need the orginal faclist any more.
213  |      **/
214  | 
215  |     null_free((void *) &faclist);
216  | 
217  |     if((char *) NULL != *facptr)
218  | 	null_free((void *) facptr);
219  | 
220  |     *facptr = tmp;
221  | 
222  | #if WITH_DEBUGGING_CALLBACK
223  |     ErrorLogger( NO_ERR_END, LOC, _proc_cmdModuleLog, NULL);
224  | #endif
225  | 
226  |     return( TCL_OK);
227  | 
228  | } /** End of 'cmdModuleLog' **/
229  |