1    | /*****
2    |  ** ** Module Header ******************************************************* **
3    |  ** 									     **
4    |  **   Modules Revision 3.0						     **
5    |  **   Providing a flexible user environment				     **
6    |  ** 									     **
7    |  **   File:		cmdWhatis.c					     **
8    |  **   First Edition:	1995/12/31					     **
9    |  ** 									     **
10   |  **   Authors:	Jens Hamisch, jens@Strawberry.COM			     **
11   |  ** 									     **
12   |  **   Description:	The Tcl module-verbose routine allows switchin ver-  **
13   |  **			bosity on and off during module file execution	     **
14   |  ** 									     **
15   |  **   Exports:		cmdModuleWhatis					     **
16   |  **			cmdModuleWhatisInit				     **
17   |  **			cmdModuleWhatisShut				     **
18   |  ** 									     **
19   |  **   Notes:								     **
20   |  ** 									     **
21   |  ** ************************************************************************ **
22   |  ****/
23   | 
24   | /** ** Copyright *********************************************************** **
25   |  ** 									     **
26   |  ** Copyright 1991-1994 by John L. Furlan.                      	     **
27   |  ** see LICENSE.GPL, which must be provided, for details		     **
28   |  ** 									     ** 
29   |  ** ************************************************************************ **/
30   | 
31   | static char Id[] = "@(#)$Id: cmdWhatis.c.src.html,v 1.6 2006/01/18 05:35:11 rkowen Exp $";
32   | static void *UseId[] = { &UseId, Id };
33   | 
34   | /** ************************************************************************ **/
35   | /** 				      HEADERS				     **/
36   | /** ************************************************************************ **/
37   | 
38   | #include "modules_def.h"
39   | 
40   | /** ************************************************************************ **/
41   | /** 				  LOCAL DATATYPES			     **/
42   | /** ************************************************************************ **/
43   | 
44   | /** not applicable **/
45   | 
46   | /** ************************************************************************ **/
47   | /** 				     CONSTANTS				     **/
48   | /** ************************************************************************ **/
49   | 
50   | #define	WHATIS_FRAG 100
51   | 
52   | /** ************************************************************************ **/
53   | /**				      MACROS				     **/
54   | /** ************************************************************************ **/
55   | 
56   | /** not applicable **/
57   | 
58   | /** ************************************************************************ **/
59   | /** 				    LOCAL DATA				     **/
60   | /** ************************************************************************ **/
61   | 
62   | static	char	module_name[] = "cmdWhatis.c";	/** File name of this module **/
63   | #if WITH_DEBUGGING_CALLBACK
64   | static	char	_proc_cmdModuleWhatis[] = "cmdModuleWhatis";
65   | #endif
66   | 
67   | /**
68   |  **  The whatis array ...
69   |  **/
70   | 
71   | char		**whatis = (char **) NULL;
72   | static	int	  whatis_size = 0, whatis_ndx = 0;
73   | 
74   | /** ************************************************************************ **/
75   | /**				    PROTOTYPES				     **/
76   | /** ************************************************************************ **/
77   | 
78   | /** not applicable **/
79   | 
80   | 
81   | /*++++
82   |  ** ** Function-Header ***************************************************** **
83   |  ** 									     **
84   |  **   Function:		cmdModuleWhatis					     **
85   |  ** 									     **
86   |  **   Description:	Callback function for 'verbose'			     **
87   |  ** 									     **
88   |  **   First Edition:	1995/12/31					     **
89   |  ** 									     **
90   |  **   Parameters:	ClientData	 client_data			     **
91   |  **			Tcl_Interp	*interp		According Tcl interp.**
92   |  **			int		 argc		Number of arguments  **
93   |  **			char		*argv[]		Argument array	     **
94   |  ** 									     **
95   |  **   Result:		int	TCL_OK		Successfull completion	     **
96   |  **				TCL_ERROR	Any error		     **
97   |  ** 									     **
98   |  **   Attached Globals:	sw_verbose	The verbose level selector	     **
99   |  **   			g_flags		These are set up accordingly before  **
100  |  **					this function is called in order to  **
101  |  **					control everything		     **
102  |  ** 									     **
103  |  ** ************************************************************************ **
104  |  ++++*/
105  | 
106  | int	cmdModuleWhatis(	ClientData	 client_data,
107  | 		      		Tcl_Interp	*interp,
108  | 		      		int		 argc,
109  | 		      		CONST84 char	*argv[])
110  | {
111  |     int i = 1;
112  | 
113  | #if WITH_DEBUGGING_CALLBACK
114  |     ErrorLogger( NO_ERR_START, LOC, _proc_cmdModuleWhatis, NULL);
115  | #endif
116  | 
117  |     /**
118  |      **  Help mode
119  |      **/
120  | 
121  |     if( g_flags & M_HELP)
122  |         return( TCL_OK);		/** -------- EXIT (SUCCESS) -------> **/
123  | 
124  |     /**
125  |      **  Parameter check
126  |      **/
127  | 
128  |     if( argc < 2) {
129  | 	if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], " string", NULL))
130  | 	    return( TCL_ERROR);		/** -------- EXIT (FAILURE) -------> **/
131  |     }
132  |   
133  |     /**
134  |      **  If we don't have any whatis list buffer until now, we will create one
135  |      **/
136  | 
137  |     if( !whatis) {
138  | 	whatis_size = WHATIS_FRAG;
139  | 	if((char **) NULL == (whatis = malloc(whatis_size * sizeof(char *)))){
140  | 	    ErrorLogger( ERR_ALLOC, LOC, NULL);
141  | 	    return( TCL_ERROR);		/** -------- EXIT (FAILURE) -------> **/
142  | 	}
143  |     }
144  | 
145  |     /**
146  |      **  Display mode?
147  |      **/
148  | 
149  |     if( g_flags & M_DISPLAY) {
150  | 	fprintf( stderr, "%s\t ", argv[ 0]);
151  | 	for( i=1; i<argc; i++)
152  | 	    fprintf( stderr, "%s ", argv[ i]);
153  | 	fprintf( stderr, "\n");
154  |         return( TCL_OK);		/** ------- EXIT PROCEDURE -------> **/
155  |     }
156  | 
157  |     /**
158  |      **  Check if printing is requested 
159  |      **/
160  | 
161  |     if( g_flags & M_WHATIS ) {
162  | 	while( i < argc) {
163  | 
164  | 	    /**
165  | 	     **  Conditionally we have to enlarge our buffer
166  | 	     **/
167  | 
168  | 	    while( whatis_ndx + 2 >= whatis_size) {
169  | 		whatis_size += WHATIS_FRAG;
170  | 		if((char **) NULL == (whatis = realloc( whatis, whatis_size *
171  | 		    sizeof( char *)))) {
172  | 		    ErrorLogger( ERR_ALLOC, LOC, NULL);
173  | 		    return( TCL_ERROR);	/** -------- EXIT (FAILURE) -------> **/
174  | 		}
175  | 	    }
176  | 
177  | 	    /**
178  | 	     **  Put the string on the buffer
179  | 	     **/
180  | 
181  | 	    if((char *) NULL == (whatis[ whatis_ndx++] = strdup( argv[ i++]))) {
182  | 		if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
183  | 		    return( TCL_ERROR);
184  | 		whatis_ndx--;
185  | 	    }
186  | 
187  | 	} /** while **/
188  |     } /** if **/
189  | 
190  |     /**
191  |      **  Put a trailing terminator on the buffer
192  |      **/
193  | 
194  |     whatis[ whatis_ndx] = (char *) NULL;
195  | 
196  | #if WITH_DEBUGGING_CALLBACK
197  |     ErrorLogger( NO_ERR_END, LOC, _proc_cmdModuleWhatis, NULL);
198  | #endif
199  | 
200  |     return( TCL_OK);
201  | 
202  | } /** End of 'cmdModuleWhatis' **/
203  |    
204  | /*++++
205  |  ** ** Function-Header ***************************************************** **
206  |  ** 									     **
207  |  **   Function:		cmdModuleWhatisInit				     **
208  |  **			cmdModuleWhatisShut				     **
209  |  ** 									     **
210  |  **   Description:	Initialization of internat data structures for the   **
211  |  **			Module whatis command				     **
212  |  ** 									     **
213  |  **   First Edition:	1995/12/31					     **
214  |  ** 									     **
215  |  **   Parameters:	-						     **
216  |  ** 									     **
217  |  **   Result:		-						     **
218  |  ** 									     **
219  |  ** ************************************************************************ **
220  |  ++++*/
221  | 
222  | void	cmdModuleWhatisInit()
223  | {
224  |     whatis_ndx = 0;
225  | 
226  | } /** End of 'cmdModuleWhatisInit' **/
227  | 
228  | void	cmdModuleWhatisShut()
229  | {
230  |     char **ptr = whatis;
231  | 
232  |     if( whatis) {
233  | 	while( *ptr) {		/** go until NULL token **/
234  | 	    free( *ptr);
235  | 	    *ptr = (char *) NULL;
236  | 	    ptr++;
237  | 	}
238  | 	whatis_ndx = 0;
239  |     }
240  | 
241  | } /** End of 'cmdModuleWhatisShut' **/