-
Notifications
You must be signed in to change notification settings - Fork 0
/
cmdIsLoaded.c
184 lines (147 loc) · 5.95 KB
/
cmdIsLoaded.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
/*****
** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: cmdIsLoaded.c **
** First Edition: 2000/04/12 **
** **
** Description: The Tcl conflict and prereq commands. **
** **
** Exports: cmdIsLoaded **
** **
** Notes: **
** **
** ************************************************************************ **
****/
/** ** Copyright *********************************************************** **
** **
** Copyright 1991-1994 by John L. Furlan. **
** see LICENSE.GPL, which must be provided, for details **
** **
** ************************************************************************ **/
static char Id[] = "@(#)$Id: 97f15a6c37e9bfa0bccc33603bc5f838466f1260 $";
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[] = "cmdIsLoaded.c"; /** File name of this module **/
#if WITH_DEBUGGING_CALLBACK
static char _proc_cmdIsLoaded[] = "cmdIsLoaded";
#endif
/** ************************************************************************ **/
/** PROTOTYPES **/
/** ************************************************************************ **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: cmdIsLoaded **
** **
** Description: Callback function for 'is-loaded' **
** **
** First Edition: 2000/04/12 **
** **
** 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 **
** **
** ************************************************************************ **
++++*/
int cmdIsLoaded( ClientData client_data,
Tcl_Interp *interp,
int argc,
CONST84 char *argv[])
{
char **pathlist;
char **modulelist;
char *modulepath;
char *notloaded_flag = (char *) argv[1];
int i, j, k, numpaths, nummodules;
#if WITH_DEBUGGING_CALLBACK
ErrorLogger( NO_ERR_START, LOC, _proc_cmdIsLoaded, NULL);
#endif
/**
** Parameter check. Usage is 'is-loaded <module> [<module> ...]'
**/
if( argc < 2) {
if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], "is-loaded-modules", NULL))
return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/
}
/**
** There's no prerequisite check in case of whatis
**/
if( g_flags & M_WHATIS)
return( TCL_OK); /** -------- EXIT (SUCCESS) -------> **/
/**
** Load the MODULEPATH and split it into a list of paths
**/
if( !(modulepath = (char *) getenv( "MODULEPATH"))) {
if( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
return( TCL_ERROR); /** -------- EXIT (FAILURE) -------> **/
}
#if WITH_DEBUGGING_CALLBACK_1
ErrorLogger( NO_ERR_DEBUG, LOC, "Got modulepath: '", modulepath, "'", NULL);
#endif
if( !(pathlist = SplitIntoList( interp, modulepath, &numpaths, _colon)))
return( TCL_OK); /** -------- EXIT (SUCCESS) -------> **/
/**
** Check/Display all passed modules
**/
for( i=1; i<argc && argv[i] && notloaded_flag; i++) {
for( j = 0; j < numpaths && notloaded_flag; j++) {
if( NULL == (modulelist = SortedDirList( interp, pathlist[j],
(char *) argv[i], &nummodules)))
continue;
/**
** Now actually check if the prerequisites are fullfilled
** The notloaded_flag controls the exit from both loops in case
** a prerequisite is missing.
**/
for( k=0; k < nummodules && notloaded_flag; k++) {
if( !IsLoaded( interp, modulelist[k], NULL, NULL)) {
notloaded_flag = (char *) argv[i];
} else {
notloaded_flag = NULL;
}
}
/**
** Free what has been allocted in the loop
**/
FreeList( modulelist, nummodules);
} /** for( j) **/
} /** for( i) **/
/**
** Display an error message if this was *NOT* display mode and a
** missing prerequisite has been found
**/
Tcl_SetResult( interp, notloaded_flag ? "0" : "1", TCL_STATIC);
#if WITH_DEBUGGING_CALLBACK
ErrorLogger( NO_ERR_END, LOC, _proc_cmdIsLoaded, NULL);
#endif
return( TCL_OK);
} /** End of 'cmdIsLoaded' **/