1 | /*****
2 | ** ** Module Header ******************************************************* **
3 | ** **
4 | ** Modules Revision 3.0 **
5 | ** Providing a flexible user environment **
6 | ** **
7 | ** File: ModuleCmd_Refresh.c **
8 | ** First Edition: 2005/06/02 **
9 | ** **
10 | ** Authors: John Furlan, jlf@behere.com **
11 | ** Jens Hamisch, jens@Strawberry.COM **
12 | ** Andrew Ruder, aer@absoft.com **
13 | ** **
14 | ** Description: Similar to a 'update' command but only refreshes **
15 | ** the non-persistent elements **
16 | ** **
17 | ** Exports: ModuleCmd_Refresh **
18 | ** **
19 | ** Notes: **
20 | ** **
21 | ** ************************************************************************ **
22 | ****/
23 |
24 | /** ** Copyright *********************************************************** **
25 | ** **
26 | ** Copyright 1991-1994 by John L. Furlan. **
27 | ** see LICENSE.GPL, which must be provided, for details **
28 | ** **
29 | ** ************************************************************************ **/
30 |
31 | static char Id[] = "@(#)$Id: ModuleCmd_Refresh.c.src.html,v 1.5 2006/01/18 05:35:11 rkowen Exp $";
32 | static void *UseId[] = { &UseId, Id };
33 |
34 | /** ************************************************************************ **/
35 | /** HEADERS **/
36 | /** ************************************************************************ **/
37 |
38 | #include "modules_def.h"
39 |
40 | /** ************************************************************************ **/
41 | /** LOCAL DATATYPES **/
42 | /** ************************************************************************ **/
43 |
44 | /** not applicable **/
45 |
46 | /** ************************************************************************ **/
47 | /** CONSTANTS **/
48 | /** ************************************************************************ **/
49 |
50 | /** not applicable **/
51 |
52 | /** ************************************************************************ **/
53 | /** MACROS **/
54 | /** ************************************************************************ **/
55 |
56 | /** not applicable **/
57 |
58 | /** ************************************************************************ **/
59 | /** LOCAL DATA **/
60 | /** ************************************************************************ **/
61 |
62 | static char module_name[] = "ModuleCmd_Refresh.c"; /** File name of this module **/
63 | #if WITH_DEBUGGING_MODULECMD
64 | static char _proc_ModuleCmd_Refresh[] = "ModuleCmd_Refresh";
65 | #endif
66 |
67 | /** ************************************************************************ **/
68 | /** PROTOTYPES **/
69 | /** ************************************************************************ **/
70 |
71 | /** not applicable **/
72 |
73 |
74 | /*++++
75 | ** ** Function-Header ***************************************************** **
76 | ** **
77 | ** Function: ModuleCmd_Refresh **
78 | ** **
79 | ** Description: Execution of the module-command 'refresh' **
80 | ** Does only the non-persistent modules settings **
81 | ** (aliases) **
82 | ** **
83 | ** First Edition: 2005/06/02 **
84 | ** **
85 | ** Parameters: Tcl_Interp *interp Attached Tcl Interp. **
86 | ** char *argv[] Argument list **
87 | ** **
88 | ** Result: int TCL_ERROR Failure **
89 | ** TCL_OK Successfull operation **
90 | ** **
91 | ** Attached Globals: specified_module The module name
92 | ** g_flags These are set up accordingly before **
93 | ** this function is called in order to **
94 | ** control everything **
95 | ** g_current_module The module which is handled **
96 | ** by the current command **
97 | ** **
98 | ** ************************************************************************ **
99 | ++++*/
100 |
101 | int ModuleCmd_Refresh( Tcl_Interp *interp,
102 | int argc,
103 | char *argv[])
104 | {
105 | Tcl_Interp *refr_interp;
106 | Tcl_DString cmdbuf;
107 | int i,
108 | result,
109 | count;
110 | char *list[ MOD_BUFSIZE];
111 | char *files[ MOD_BUFSIZE];
112 | char *lmenv;
113 | char *loaded;
114 |
115 | #if WITH_DEBUGGING_MODULECMD
116 | ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Refresh, NULL);
117 | #endif
118 |
119 | /**
120 | ** Begin by getting the list of loaded modules.
121 | **/
122 |
123 | loaded = getenv( "LOADEDMODULES" );
124 | if (!loaded || !*loaded)
125 | goto success0;
126 |
127 | loaded = strdup(loaded);
128 | if( !loaded )
129 | if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
130 | goto unwind0;
131 |
132 | if (!(lmenv = getLMFILES(interp))) {
133 | if ( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
134 | goto unwind1;
135 | else
136 | goto success1;
137 | }
138 |
139 | if (*lmenv == '\0')
140 | goto success1;
141 |
142 | count = 1;
143 | for( list[ 0] = strtok( loaded, ":");
144 | list[ count] = strtok( NULL, ":");
145 | count++ );
146 |
147 | count = 1;
148 | for( files[ 0] = strtok( lmenv, ":");
149 | files[ count] = strtok( NULL, ":");
150 | count++ );
151 |
152 | /**
153 | ** Initialize the command buffer and set up the modules flag
154 | ** to 'non-persist only'
155 | **/
156 |
157 | Tcl_DStringInit( &cmdbuf);
158 | g_flags |= M_NONPERSIST;
159 |
160 | /**
161 | ** Handle each loaded module file. Create a Tcl interpreter for each
162 | ** module file to be handled and initialize it with custom module commands
163 | **/
164 |
165 | for(i=0; i < count && list[i]; i++) {
166 | /**
167 | ** Set the name of the current module
168 | **/
169 | g_specified_module = list[i];
170 |
171 | refr_interp = Tcl_CreateInterp();
172 | if ( TCL_OK != (result = InitializeModuleCommands ( refr_interp ))) {
173 | Tcl_DeleteInterp( refr_interp );
174 | null_free((void *) &loaded);
175 | return (result);
176 | }
177 |
178 | /**
179 | ** Execute the module
180 | **/
181 |
182 | g_current_module = list[i];
183 |
184 | result = CallModuleProcedure( refr_interp, &cmdbuf, files[i],
185 | "ModulesNonPersist", 0);
186 |
187 | /**
188 | ** Remove the Tcl interpreter ...
189 | **/
190 |
191 | Tcl_DeleteInterp( refr_interp);
192 |
193 | } /** for **/
194 |
195 | /**
196 | ** Leave the 'nonpersist mode', free up what has been used and return
197 | **/
198 |
199 | g_flags &= ~M_NONPERSIST;
200 |
201 | Tcl_DStringFree( &cmdbuf);
202 |
203 | success1:
204 | null_free((void *) &loaded);
205 |
206 | success0:
207 | #if WITH_DEBUGGING_MODULECMD
208 | ErrorLogger( NO_ERR_END, LOC, _proc_ModuleCmd_Refresh, NULL);
209 | #endif
210 |
211 | return( TCL_OK); /** -------- EXIT (SUCCESS) -------> **/
212 |
213 | unwind1:
214 | null_free((void *) &loaded);
215 |
216 | unwind0:
217 | return( TCL_ERROR ); /** -------- EXIT (FAILURE) -------> **/
218 | } /** End of 'ModuleCmd_Refresh' **/