1 /*****
2 ** ** Module Header ******************************************************* **
3 ** **
4 ** Modules Revision 3.0 **
5 ** Providing a flexible user environment **
6 ** **
7 ** File: ModuleCmd_Purge.c **
8 ** First Edition: 1991/10/23 **
9 ** **
10 ** Authors: John Furlan, jlf@behere.com **
11 ** Jens Hamisch, jens@Strawberry.COM **
12 ** **
13 ** Description: Removes all loaded modulefiles from the environment. **
14 ** **
15 ** Exports: ModuleCmd_Purge **
16 ** **
17 ** Notes: **
18 ** **
19 ** ************************************************************************ **
20 ****/
21
22 /** ** Copyright *********************************************************** **
23 ** **
24 ** Copyright 1991-1994 by John L. Furlan. **
25 ** see LICENSE.GPL, which must be provided, for details **
26 ** **
27 ** ************************************************************************ **/
28
29 static char Id[] = "@(#)$Id: 7c14ae7dd9ea5b6b1497782b3a24764b84b9883a $";
30 static void *UseId[] = { &UseId, Id };
31
32 /** ************************************************************************ **/
33 /** HEADERS **/
34 /** ************************************************************************ **/
35
36 #include "modules_def.h"
37
38 /** ************************************************************************ **/
39 /** LOCAL DATATYPES **/
40 /** ************************************************************************ **/
41
42 /** not applicable **/
43
44 /** ************************************************************************ **/
45 /** CONSTANTS **/
46 /** ************************************************************************ **/
47
48 /** not applicable **/
49
50 /** ************************************************************************ **/
51 /** MACROS **/
52 /** ************************************************************************ **/
53
54 /** not applicable **/
55
56 /** ************************************************************************ **/
57 /** LOCAL DATA **/
58 /** ************************************************************************ **/
59
60 static char module_name[] = "ModuleCmd_Purge.c"; /** File name of this module **/
61
62 /** ************************************************************************ **/
63 /** PROTOTYPES **/
64 /** ************************************************************************ **/
65
66 /** not applicable **/
67
68
69 /*++++
70 ** ** Function-Header ***************************************************** **
71 ** **
72 ** Function: ModuleCmd_Purge **
73 ** **
74 ** Description: Execution of the module-command 'purge' **
75 ** **
76 ** First Edition: 1991/10/23 **
77 ** **
78 ** Parameters: Tcl_Interp *interp Attached Tcl Interp. **
79 ** int argc Number of arguments **
80 ** char *argv[] Argument list **
81 ** **
82 ** Result: int TCL_ERROR Failure **
83 ** TCL_OK Successful operation **
84 ** **
85 ** Attached Globals: **
86 ** **
87 ** ************************************************************************ **
88 ++++*/
89
ModuleCmd_Purge(Tcl_Interp * interp,int argc,char * argv[])90 int ModuleCmd_Purge( Tcl_Interp *interp,
91 int argc,
92 char *argv[])
93 {
94 char *lmodules = NULL,
95 *cur_module = NULL,
96 *loaded_modules,
97 *unload_argv[ MOD_BUFSIZE];
98 int unload_argc = 0,
99 status;
100 char *unload_argv_rev[ MOD_BUFSIZE];
101 int reverse;
102
103 #if WITH_DEBUGGING_MODULECMD
104 fprintf( stderr, "ModuleCmd_Purge(%d):DEBUG: Starting\n", __LINE__);
105 #endif
106
107 /**
108 ** Get the list of currently loaded modules from the environment variable
109 ** LOADEDMODULES
110 **/
111 loaded_modules = EMGetEnv( interp, "LOADEDMODULES");
112 if(!loaded_modules || ! *loaded_modules) {
113 /* nothing to do */
114 null_free((void *)&loaded_modules);
115 return( TCL_OK); /** ---- EXIT (Nothing to list) ---- **/
116 }
117
118 if((char *) NULL == (lmodules = stringer(NULL,0, loaded_modules, NULL)))
119 if( OK != ErrorLogger( ERR_STRING, LOC, NULL))
120 return( TCL_ERROR); /** -------- EXIT (FAILURE) -------- **/
121
122 /**
123 ** Build a NULL terminated list of loaded modules
124 **/
125 for( cur_module = strtok( lmodules, ":");
126 cur_module && unload_argc < MOD_BUFSIZE-1;
127 cur_module = strtok( NULL, ":"))
128 unload_argv[ unload_argc++] = cur_module;
129
130 unload_argv[ unload_argc] = NULL;
131
132 for( reverse=0; reverse<unload_argc; reverse++ ) {
133 unload_argv_rev[unload_argc - (reverse + 1)] = unload_argv[reverse];
134 }
135
136 unload_argv_rev[ unload_argc] = NULL;
137
138 /**
139 ** Unload 'em all
140 ** We always say the load succeeded. ModuleCmd_Load will
141 ** output any necessary error messages.
142 **/
143 /* ModuleCmd_Load( interp, 0, unload_argc, unload_argv); */
144 ModuleCmd_Load( interp, 0, unload_argc, unload_argv_rev);
145
146 status = TCL_OK;
147
148 /**
149 ** Free, what has been allocated and pass the load's result to the caller
150 **/
151 null_free((void *) &lmodules);
152
153 #if WITH_DEBUGGING_MODULECMD
154 fprintf( stderr, "ModuleCmd_Purge(%d):DEBUG: End\n", __LINE__);
155 #endif
156
157 return( status);
158
159 } /** End of 'ModuleCmd_Purge' **/
160