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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
|
/*****
** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: cmdInfo.c **
** First Edition: 1991/10/23 **
** **
** Authors: John Furlan, jlf@behere.com **
** Jens Hamisch, jens@Strawberry.COM **
** **
** Description: The Tcl module-info routine which provides informa- **
** tion about the state of Modules as the modulefile **
** is being parsed. **
** **
** Exports: cmdModuleInfo **
** **
** Notes: **
** **
** ************************************************************************ **
****/
/** ** Copyright *********************************************************** **
** **
** Copyright 1991-1994 by John L. Furlan. **
** see LICENSE.GPL, which must be provided, for details **
** **
** ************************************************************************ **/
static char Id[] = "@(#)$Id: 451d721552b7050eb97f9b9290d952f1816a2693 $";
static void *UseId[] = { &UseId, Id };
/** ************************************************************************ **/
/** HEADERS **/
/** ************************************************************************ **/
#include "modules_def.h"
/** ************************************************************************ **/
/** LOCAL DATATYPES **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** CONSTANTS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** MACROS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** LOCAL DATA **/
/** ************************************************************************ **/
static char module_name[] = "cmdInfo.c"; /** File name of this module **/
#if WITH_DEBUGGING_CALLBACK
static char _proc_cmdModuleInfo[] = "cmdModuleInfo";
#endif
/** ************************************************************************ **/
/** PROTOTYPES **/
/** ************************************************************************ **/
/** not applicable **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: cmdModuleInfo **
** **
** Description: Callback function for 'module-info' **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: ClientData client_data **
** Tcl_Interp *interp According Tcl interp.**
** int argc Number of arguments **
** char *argv[] 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. **
** g_specified_module The module name from the **
** command line. **
** g_current_module The module which is handled **
** by the current command **
** **
** ************************************************************************ **
++++*/
int cmdModuleInfo( ClientData client_data,
Tcl_Interp *interp,
int argc,
CONST84 char *argv[])
{
char *s, *t, buf[ BUFSIZ];
#if WITH_DEBUGGING_CALLBACK
ErrorLogger( NO_ERR_START, LOC, _proc_cmdModuleInfo, NULL);
#endif
/**
** Parameter check
**/
if( argc < 2) {
if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], "info-descriptor ",
"descriptor-args", NULL))
return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/
}
if( !strcmp(argv[1], "type")) {
/**
** 'module-info type'
** returns 'C' to refer to the C-version of modules
** (the Tcl-only version returns 'Tcl')
**/
Tcl_SetResult( interp, "C", TCL_STATIC);
} else if( !strcmp( argv[1], "flags")) {
/**
** 'module-info flags' ?
**/
char tmpbuf[6];
sprintf( tmpbuf, "%d", g_flags);
Tcl_SetResult( interp, tmpbuf, TCL_VOLATILE);
} else if( !strcmp( argv[1], "mode")) {
/**
** 'module-info mode'
** without suggestion this will return the name of the state we're in.
**/
if( argc < 3) {
if( g_flags & M_SWSTATE1)
Tcl_SetResult( interp, "switch1", TCL_STATIC);
else if( g_flags & M_SWSTATE2)
Tcl_SetResult( interp, "switch2", TCL_STATIC);
else if( g_flags & M_SWSTATE3)
Tcl_SetResult( interp, "switch3", TCL_STATIC);
else if( g_flags & M_LOAD)
Tcl_SetResult( interp, "load", TCL_STATIC);
else if( g_flags & M_REMOVE)
Tcl_SetResult( interp, "remove", TCL_STATIC);
else if( g_flags & M_DISPLAY)
Tcl_SetResult( interp, "display", TCL_STATIC);
else if( g_flags & M_HELP)
Tcl_SetResult( interp, "help", TCL_STATIC);
else if( g_flags & M_WHATIS)
Tcl_SetResult( interp, "whatis", TCL_STATIC);
else if( g_flags & M_NONPERSIST)
Tcl_SetResult( interp, "nonpersist", TCL_STATIC);
else
Tcl_SetResult( interp, "unknown", TCL_STATIC);
} else {
/**
** 'module-info mode <my_suggestion>'
** results in a boolean return indicating whether this is the
** correct state ...
**/
Tcl_SetResult( interp, "0", TCL_STATIC);
if( !strcmp( argv[2], "load")) {
if( g_flags & M_LOAD) Tcl_SetResult( interp, "1", TCL_STATIC);
}
else if( !strcmp( argv[2], "remove")) {
if( g_flags & M_REMOVE) Tcl_SetResult( interp, "1", TCL_STATIC);
}
else if( !strcmp( argv[2], "display")) {
if( g_flags & M_DISPLAY) Tcl_SetResult( interp,"1", TCL_STATIC);
}
else if( !strcmp( argv[2], "nonpersist")) {
if( g_flags & M_NONPERSIST) Tcl_SetResult( interp,"1", TCL_STATIC);
}
else if( !strcmp( argv[2], "help")) {
if( g_flags & M_HELP) Tcl_SetResult( interp, "1", TCL_STATIC);
}
else if( !strcmp( argv[2], "whatis")) {
if( g_flags & M_WHATIS) Tcl_SetResult( interp, "1", TCL_STATIC);
}
else if( !strcmp( argv[2], "switch1")) {
if( g_flags & M_SWSTATE1) Tcl_SetResult( interp,"1",TCL_STATIC);
}
else if( !strcmp(argv[2], "switch2")) {
if( g_flags & M_SWSTATE2) Tcl_SetResult( interp,"1",TCL_STATIC);
}
else if( !strcmp(argv[2], "switch3")) {
if( g_flags & M_SWSTATE3) Tcl_SetResult( interp,"1",TCL_STATIC);
}
else if( !strcmp(argv[2], "switch")) {
if( g_flags & M_SWITCH) Tcl_SetResult( interp, "1", TCL_STATIC);
} else {
ErrorLogger( ERR_USAGE, LOC, argv[0], "mode ", "[load|remove|"
"display|help|whatis|switch1|switch2|switch3|switch|nonpersist]", NULL);
return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/
}
}
} else if( !strcmp( argv[1], "user")) {
/**
** 'module-info user'
** without suggestion this will return the current user level
**/
if( argc < 3) {
if( UL_NOVICE == sw_userlvl)
Tcl_SetResult( interp, "novice", TCL_STATIC);
else if( UL_ADVANCED == sw_userlvl)
Tcl_SetResult( interp, "advanced", TCL_STATIC);
else if( UL_EXPERT == sw_userlvl)
Tcl_SetResult( interp, "expert", TCL_STATIC);
else
Tcl_SetResult( interp, "unknown", TCL_STATIC);
} else {
/**
** 'module-info user <my_suggestion>'
** results in a boolean return indicating whether this is the
** correct user level ...
**/
Tcl_SetResult( interp, "0", TCL_STATIC);
if( !strcmp( argv[2], "novice")) {
if( UL_NOVICE == sw_userlvl)
Tcl_SetResult( interp, "1", TCL_STATIC);
}
else if( !strcmp( argv[2], "advanced")) {
if( UL_ADVANCED == sw_userlvl)
Tcl_SetResult( interp, "1", TCL_STATIC);
}
else if( !strcmp( argv[2], "expert")) {
if( UL_EXPERT == sw_userlvl)
Tcl_SetResult( interp, "1", TCL_STATIC);
} else {
ErrorLogger( ERR_USAGE, LOC, argv[0], "user ",
"[novice|advanced|expert]", NULL);
return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/
}
}
} else if( !strcmp(argv[1], "name")) {
/**
** 'module-info name'
** returns the name of the current module
**/
Tcl_SetResult( interp, g_current_module, TCL_VOLATILE);
} else if( !strcmp(argv[1], "shell")) {
/**
** 'module-info shell'
** returns the name of the current user shell
**/
if( argc < 3) {
Tcl_SetResult( interp, shell_name, TCL_VOLATILE);
} else {
if( !strcmp( argv[2], shell_name))
Tcl_SetResult( interp, "1", TCL_STATIC);
else
Tcl_SetResult( interp, "0", TCL_STATIC);
}
} else if( !strcmp(argv[1], "shelltype")) {
/**
** 'module-info shelltype'
** returns the name of the current user shelltype family
**/
if( argc < 3) {
Tcl_SetResult( interp, shell_derelict, TCL_VOLATILE);
} else {
if( !strcmp( argv[2], shell_derelict))
Tcl_SetResult( interp, "1", TCL_STATIC);
else
Tcl_SetResult( interp, "0", TCL_STATIC);
}
} else if( !strcmp(argv[1], "trace")) {
/**
** 'module-info trace'
** Check whether tracing is turned on
**/
char *cmd, *module;
if( argc > 2)
cmd = (char *) argv[ 2];
else
cmd = module_command;
if( argc > 3)
module = (char *) argv[ 3];
else
module = g_current_module;
if( CheckTracing(interp, cmd, module))
Tcl_SetResult( interp, "1", TCL_STATIC);
else
Tcl_SetResult( interp, "0", TCL_STATIC);
} else if( !strcmp(argv[1], "tracepat")) {
char *cmd, *pattern;
if( argc > 2)
cmd = (char *) argv[ 2];
else
cmd = module_command;
if((char *) NULL == (pattern = GetTraceSel(interp, cmd)))
Tcl_SetResult( interp, "*undef*", TCL_STATIC);
else
Tcl_SetResult( interp, pattern, TCL_VOLATILE);
} else if( !strcmp(argv[1], "alias")) {
/**
** 'module-info alias'
** Print the value of the passed alias
**/
if( argc < 3) {
if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], "alias ",
"name", NULL))
return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/
}
if( AliasLookup( (char *) argv[2], &s, &t)) {
/* sprintf( buf, "%s/%s", s, t); */
strcpy( buf, s);
strcat( buf, "/");
strcat( buf, t);
Tcl_SetResult( interp, buf, TCL_VOLATILE);
} else {
Tcl_SetResult( interp, "*undef*", TCL_STATIC);
}
} else if( !strcmp(argv[1], "symbols")) {
/**
** 'module-info symbols'
** List all symbolic names of the passed or current module file
**/
char *name;
name = (argc < 3) ? g_current_module : (char *) argv[2];
if((char *) NULL == (s = ExpandVersions( name)))
Tcl_SetResult( interp, "*undef*", TCL_STATIC);
else
Tcl_SetResult( interp, (char *) s, TCL_VOLATILE);
} else if( !strcmp(argv[1], "version")) {
/**
** 'module-info version'
** Returns the full qualified module name and version of the passed
** symbolic version specifier
**/
if( VersionLookup( (char *) argv[2], &s, &t)) {
if( t) {
/* sprintf( buf, "%s/%s", s, t); */
strcpy( buf, s);
strcat( buf, "/");
strcat( buf, t);
} else {
/* sprintf( buf, "%s", s); */
strcpy( buf, s);
}
Tcl_SetResult( interp, buf, TCL_VOLATILE);
} else {
Tcl_SetResult( interp, "*undef*", TCL_STATIC);
}
} else if( !strcmp(argv[1], "specified")) {
/**
** 'module-info specified'
** gives the module name as specified on the command line
**/
if( g_specified_module) {
/* TCL_STATIC because it comes from the command line */
Tcl_SetResult( interp, g_specified_module, TCL_STATIC);
} else {
Tcl_SetResult( interp, "*undef*", TCL_STATIC);
}
} else {
/**
** unknown command ....
**/
if( OK != ErrorLogger( ERR_INFO_DESCR, LOC, argv[1], NULL))
return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/
}
#if WITH_DEBUGGING_CALLBACK
ErrorLogger( NO_ERR_END, LOC, _proc_cmdModuleInfo, NULL);
#endif
return( TCL_OK);
} /** End of 'cmdModuleInfo' **/
|