-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdWhatis.c
224 lines (194 loc) · 6.53 KB
/
cmdWhatis.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
213
214
215
216
217
218
219
220
221
222
223
224
/*****
** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: cmdWhatis.c **
** First Edition: 1995/12/31 **
** **
** Authors: Jens Hamisch, [email protected] **
** R.K. Owen, <[email protected]> or <[email protected]> **
** **
** Description: The Tcl module-verbose routine allows switchin ver- **
** bosity on and off during module file execution **
** **
** Exports: cmdModuleWhatis **
** cmdModuleWhatisInit **
** cmdModuleWhatisShut **
** **
** 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 WHATIS_FRAG 100
/** ************************************************************************ **/
/** MACROS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** LOCAL DATA **/
/** ************************************************************************ **/
static char module_name[] = __FILE__;
/**
** The whatis array ...
**/
char **whatis = (char **) NULL;
static int whatis_size = 0, whatis_ndx = 0;
/** ************************************************************************ **/
/** PROTOTYPES **/
/** ************************************************************************ **/
/** not applicable **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: cmdModuleWhatis **
** **
** Description: Callback function for 'verbose' **
** **
** First Edition: 1995/12/31 **
** **
** 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: sw_verbose The verbose level selector **
** g_flags These are set up accordingly before **
** this function is called in order to **
** control everything **
** **
** ************************************************************************ **
++++*/
int cmdModuleWhatis(
ClientData client_data,
Tcl_Interp * interp,
int objc,
Tcl_Obj * CONST84 objv[]
) {
int i = 1;
/**
** Help mode
**/
if (g_flags & M_HELP)
return (TCL_OK); /** -------- EXIT (SUCCESS) -------> **/
/**
** Parameter check
**/
if (objc < 2) {
if (OK !=
ErrorLogger(ERR_USAGE, LOC, Tcl_GetString(objv[0]),
" string", NULL))
return (TCL_ERROR);
/** -------- EXIT (FAILURE) -------> **/
}
/**
** If we don't have any whatis list buffer until now, we will create one
**/
if (!whatis) {
whatis_size = WHATIS_FRAG;
if ((char **)NULL
== (whatis = module_malloc(whatis_size * sizeof(char *)))) {
ErrorLogger(ERR_ALLOC, LOC, NULL);
return (TCL_ERROR);
/** -------- EXIT (FAILURE) -------> **/
}
}
/**
** Display mode?
**/
if (g_flags & M_DISPLAY) {
fprintf(stderr, "%s\t ", Tcl_GetString(objv[0]));
for (i = 1; i < objc; i++)
fprintf(stderr, "%s ", Tcl_GetString(objv[i]));
fprintf(stderr, "\n");
return (TCL_OK); /** ------- EXIT PROCEDURE -------> **/
}
/**
** Check if printing is requested
**/
if (g_flags & M_WHATIS) {
while (i < objc) {
/**
** Conditionally we have to enlarge our buffer
**/
while (whatis_ndx + 2 >= whatis_size) {
whatis_size += WHATIS_FRAG;
if (!(whatis = module_realloc(whatis,
whatis_size * sizeof(char *)))) {
ErrorLogger(ERR_ALLOC, LOC, NULL);
return (TCL_ERROR);
/** -------- EXIT (FAILURE) -------> **/
}
}
/**
** Put the string on the buffer
**/
if (!(whatis[whatis_ndx++]
= stringer(NULL, 0, Tcl_GetString(objv[i++]), NULL))) {
if (OK != ErrorLogger(ERR_ALLOC, LOC, NULL))
return (TCL_ERROR);
whatis_ndx--;
}
} /** while **/
} /** if **/
/**
** Put a trailing terminator on the buffer
**/
whatis[whatis_ndx] = (char *)NULL;
return (TCL_OK);
} /** End of 'cmdModuleWhatis' **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: cmdModuleWhatisInit **
** cmdModuleWhatisShut **
** **
** Description: Initialization of internat data structures for the **
** Module whatis command **
** **
** First Edition: 1995/12/31 **
** **
** Parameters: - **
** **
** Result: - **
** **
** ************************************************************************ **
++++*/
void cmdModuleWhatisInit()
{
whatis_ndx = 0;
} /** End of 'cmdModuleWhatisInit' **/
void cmdModuleWhatisShut()
{
char **ptr = whatis;
if( whatis) {
while(*ptr) { /** go until NULL token **/
null_free((void *) ptr);
ptr++;
}
whatis_ndx = 0;
}
} /** End of 'cmdModuleWhatisShut' **/