-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModuleCmd_List.c
207 lines (166 loc) · 5.98 KB
/
ModuleCmd_List.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
/*****
** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: ModuleCmd_List.c **
** First Edition: 1991/10/23 **
** **
** Authors: John Furlan, jlf@behere.com **
** Jens Hamisch, jens@Strawberry.COM **
** **
** Description: Lists the currently loaded modulefiles. **
** **
** Exports: ModuleCmd_List **
** **
** Notes: **
** **
** ************************************************************************ **
****/
/** ** Copyright *********************************************************** **
** **
** Copyright 1991-1994 by John L. Furlan. **
** see LICENSE.GPL, which must be provided, for details **
** **
** ************************************************************************ **/
static char Id[] = "@(#)$Id: f5f07d5ab873d3201bb61c060dc2d91c7257a953 $";
static void *UseId[] = { &UseId, Id };
/** ************************************************************************ **/
/** HEADERS **/
/** ************************************************************************ **/
#include "modules_def.h"
/** ************************************************************************ **/
/** LOCAL DATATYPES **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** CONSTANTS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** MACROS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** LOCAL DATA **/
/** ************************************************************************ **/
static const char module_name[] = "ModuleCmd_List.c"; /** File name of this module **/
static const char _proc_ModuleCmd_List[] = "ModuleCmd_List";
/** ************************************************************************ **/
/** PROTOTYPES **/
/** ************************************************************************ **/
/** not applicable **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: ModuleCmd_List **
** **
** Description: Execution of the module-command 'list' **
** Lists all modules stored in the environment variable **
** 'LOADEDMODULES' **
** **
** First Edition: 1991/10/23 **
** **
** Parameters: Tcl_Interp *interp Attached Tcl Interp. **
** int argc Number of args **
** char *argv[] Argument list **
** **
** Result: int TCL_ERROR Failure **
** TCL_OK Successful operation **
** **
** Attached Globals: **
** **
** ************************************************************************ **
++++*/
int ModuleCmd_List(Tcl_Interp *interp, int argc, char *argv[])
{
/**
** Get the list of loaded modules at first
**/
char *loaded, *lmfiles;
int i, count1, count2;
char *list[MOD_BUFSIZE];
char *files[MOD_BUFSIZE];
char *tmplist[MOD_BUFSIZE], *s;
int len;
#if WITH_DEBUGGING_MODULECMD
ErrorLogger(NO_ERR_START, LOC, _proc_ModuleCmd_List, NULL);
#else
(void)_proc_ModuleCmd_List;
#endif /* WITH_DEBUGGING_MODULECMD */
lmfiles = getLMFILES(interp);
loaded = getenv("LOADEDMODULES");
if (!loaded || !*loaded) {
if (sw_format & (SW_TERSE | SW_LONG | SW_HUMAN)) {
fprintf(stderr, "No Modulefiles Currently Loaded.\n");
}
} else {
/**
** Now tokenize it, form a list and print it out.
**/
if (sw_format & SW_LONG) {
fprintf(stderr, "%s", long_header);
}
if (sw_format & (SW_TERSE | SW_LONG | SW_HUMAN)) {
fprintf(stderr, "Currently Loaded Modulefiles:\n");
}
/**
** LOADEDMODULES and _LMFILES_ should provide a list of loaded
** modules and assigned files in the SAME ORDER
** but double check, because if they aren't you will get a crash.
**/
count1 = 1;
for ((list[0] = xstrtok(loaded, ":"));
(list[count1] = xstrtok(NULL, ":")); count1++) {
; /* do nothing */
}
count2 = 1;
for ((files[0] = xstrtok(lmfiles, ":"));
(files[count2] = xstrtok(NULL, ":")); count2++) {
; /* do nothing */
}
if (count1 != count2) {
ErrorLogger(ERR_ENVVAR, LOC, NULL);
}
/**
** We have to build a single list of files for each loaded entry
** in order to be able to figure out the length of the directory
** part
**/
for ((i = 0); (i < count1); i++) {
len = ((int)strlen(files[i]) - (int)strlen(list[i]));
tmplist[i] = files[i];
/**
** We have to source all relevant .modulerc and .version files
** on the path
**/
s = (files[i] + len);
while (s) {
if (s = strchr(s, '/')) {
*s = '\0';
}
SourceRC(interp, files[i], modulerc_file);
SourceVers(interp, files[i], list[i]);
if (s) {
*s++ = '/';
}
}
/* (bracketing (or lack thereof) got confusing around here) */
/**
** Print this guy:
**/
}
print_aligned_files(interp, NULL, NULL, tmplist, count1, 1);
}
/**
** Return on success
**/
#if WITH_DEBUGGING_MODULECMD
ErrorLogger(NO_ERR_END, LOC, _proc_ModuleCmd_List, NULL);
#else
(void)_proc_ModuleCmd_List;
#endif /* WITH_DEBUGGING_MODULECMD */
return (TCL_OK);
} /** End of 'ModuleCmd_List' function **/
/* End of ModuleCmd_List.c file */