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: 5baa4abe56ea1394baa1a5b33b827f517148b14c $";
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 Successful 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
cmdModuleWhatis(ClientData client_data,Tcl_Interp * interp,int argc,CONST84 char * argv[])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
140 == (whatis = module_malloc(whatis_size * sizeof(char *)))){
141 ErrorLogger( ERR_ALLOC, LOC, NULL);
142 return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/
143 }
144 }
145
146 /**
147 ** Display mode?
148 **/
149
150 if( g_flags & M_DISPLAY) {
151 fprintf( stderr, "%s\t ", argv[ 0]);
152 for( i=1; i<argc; i++)
153 fprintf( stderr, "%s ", argv[ i]);
154 fprintf( stderr, "\n");
155 return( TCL_OK); /** ------- EXIT PROCEDURE -------> **/
156 }
157
158 /**
159 ** Check if printing is requested
160 **/
161
162 if( g_flags & M_WHATIS ) {
163 while( i < argc) {
164
165 /**
166 ** Conditionally we have to enlarge our buffer
167 **/
168
169 while( whatis_ndx + 2 >= whatis_size) {
170 whatis_size += WHATIS_FRAG;
171 if(!(whatis = module_realloc( whatis, whatis_size *
172 sizeof( char *)))) {
173 ErrorLogger( ERR_ALLOC, LOC, NULL);
174 return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/
175 }
176 }
177
178 /**
179 ** Put the string on the buffer
180 **/
181
182 if((char *) NULL == (whatis[ whatis_ndx++] = strdup( argv[ i++]))) {
183 if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
184 return( TCL_ERROR);
185 whatis_ndx--;
186 }
187
188 } /** while **/
189 } /** if **/
190
191 /**
192 ** Put a trailing terminator on the buffer
193 **/
194
195 whatis[ whatis_ndx] = (char *) NULL;
196
197 #if WITH_DEBUGGING_CALLBACK
198 ErrorLogger( NO_ERR_END, LOC, _proc_cmdModuleWhatis, NULL);
199 #endif
200
201 return( TCL_OK);
202
203 } /** End of 'cmdModuleWhatis' **/
204
205 /*++++
206 ** ** Function-Header ***************************************************** **
207 ** **
208 ** Function: cmdModuleWhatisInit **
209 ** cmdModuleWhatisShut **
210 ** **
211 ** Description: Initialization of internat data structures for the **
212 ** Module whatis command **
213 ** **
214 ** First Edition: 1995/12/31 **
215 ** **
216 ** Parameters: - **
217 ** **
218 ** Result: - **
219 ** **
220 ** ************************************************************************ **
221 ++++*/
222
cmdModuleWhatisInit()223 void cmdModuleWhatisInit()
224 {
225 whatis_ndx = 0;
226
227 } /** End of 'cmdModuleWhatisInit' **/
228
cmdModuleWhatisShut()229 void cmdModuleWhatisShut()
230 {
231 char **ptr = whatis;
232
233 if( whatis) {
234 while( *ptr) { /** go until NULL token **/
235 free( *ptr);
236 *ptr = (char *) NULL;
237 ptr++;
238 }
239 whatis_ndx = 0;
240 }
241
242 } /** End of 'cmdModuleWhatisShut' **/
243