-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModuleCmd_Refresh.c
206 lines (165 loc) · 5.91 KB
/
ModuleCmd_Refresh.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
/*****
** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: ModuleCmd_Refresh.c **
** First Edition: 2005/06/02 **
** **
** Authors: John Furlan, [email protected] **
** Jens Hamisch, [email protected] **
** Andrew Ruder, [email protected] **
** **
** Description: Similar to a 'update' command but only refreshes **
** the non-persistent elements **
** **
** Exports: ModuleCmd_Refresh **
** **
** 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 **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** MACROS **/
/** ************************************************************************ **/
/** not applicable **/
/** ************************************************************************ **/
/** LOCAL DATA **/
/** ************************************************************************ **/
static char module_name[] = __FILE__;
/** ************************************************************************ **/
/** PROTOTYPES **/
/** ************************************************************************ **/
/** not applicable **/
/*++++
** ** Function-Header ***************************************************** **
** **
** Function: ModuleCmd_Refresh **
** **
** Description: Execution of the module-command 'refresh' **
** Does only the non-persistent modules settings **
** (aliases) **
** **
** First Edition: 2005/06/02 **
** **
** Parameters: Tcl_Interp *interp Attached Tcl Interp. **
** char *argv[] Argument list **
** **
** Result: int TCL_ERROR Failure **
** TCL_OK Successful operation **
** **
** Attached Globals: specified_module The module name
** g_flags These are set up accordingly before **
** this function is called in order to **
** control everything **
** g_current_module The module which is handled **
** by the current command **
** **
** ************************************************************************ **
++++*/
int ModuleCmd_Refresh( Tcl_Interp *interp,
int argc,
char *argv[])
{
Tcl_Interp *refr_interp;
Tcl_DString cmdbuf;
int i,
result,
count;
char *list[ MOD_BUFSIZE];
char *files[ MOD_BUFSIZE];
char *lmenv;
char *loaded;
/**
** Begin by getting the list of loaded modules.
**/
loaded = EMGetEnv(interp, "LOADEDMODULES" );
if (!loaded || !*loaded)
goto success0;
loaded = stringer(NULL,0, loaded, NULL);
if( !loaded )
if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
goto unwind0;
if (!(lmenv = getLMFILES(interp))) {
if ( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
goto unwind1;
else
goto success1;
}
if (*lmenv == '\0')
goto success1;
count = 1;
for( list[ 0] = xstrtok( loaded, ":");
(list[ count] = xstrtok( NULL, ":"));
count++ );
count = 1;
for( files[ 0] = xstrtok( lmenv, ":");
(files[ count] = xstrtok( NULL, ":"));
count++ );
/**
** Initialize the command buffer and set up the modules flag
** to 'non-persist only'
**/
Tcl_DStringInit( &cmdbuf);
g_flags |= M_NONPERSIST;
/**
** Handle each loaded module file. Create a Tcl interpreter for each
** module file to be handled and initialize it with custom module commands
**/
for(i=0; i < count && list[i]; i++) {
/**
** Set the name of the current module
**/
g_specified_module = list[i];
refr_interp = EM_CreateInterp();
if ( TCL_OK != (result = Module_Init ( refr_interp ))) {
EM_DeleteInterp( refr_interp );
null_free((void *) &loaded);
return (result);
}
/**
** Execute the module
**/
g_current_module = list[i];
result = CallModuleProcedure( refr_interp, &cmdbuf, files[i],
"ModulesNonPersist", 0);
/**
** Remove the Tcl interpreter ...
**/
EM_DeleteInterp( refr_interp);
} /** for **/
/**
** Leave the 'nonpersist mode', free up what has been used and return
**/
g_flags &= ~M_NONPERSIST;
Tcl_DStringFree( &cmdbuf);
success1:
null_free((void *) &loaded);
success0:
return( TCL_OK); /** -------- EXIT (SUCCESS) -------> **/
unwind1:
null_free((void *) &loaded);
unwind0:
return( TCL_ERROR ); /** -------- EXIT (FAILURE) -------> **/
} /** End of 'ModuleCmd_Refresh' **/