1    | /*****
2    |  ** ** Module Header ******************************************************* **
3    |  ** 									     **
4    |  **   Modules Revision 3.0						     **
5    |  **   Providing a flexible user environment				     **
6    |  ** 									     **
7    |  **   File:		ModuleCmd_Clear.c				     **
8    |  **   First Edition:	91/10/23					     **
9    |  ** 									     **
10   |  **   Authors:	John Furlan, jlf@behere.com				     **
11   |  **		Jens Hamisch, jens@Strawberry.COM			     **
12   |  ** 									     **
13   |  **   Description:	Clears out Modules' concept of the currently loaded  **
14   |  **			modules.					     **
15   |  ** 									     **
16   |  **   Exports:		ModuleCmd_Clear					     **
17   |  ** 									     **
18   |  **   Notes:								     **
19   |  ** 									     **
20   |  ** ************************************************************************ **
21   |  ****/
22   | 
23   | /** ** Copyright *********************************************************** **
24   |  ** 									     **
25   |  ** Copyright 1991-1994 by John L. Furlan.                      	     **
26   |  ** see LICENSE.GPL, which must be provided, for details		     **
27   |  ** 									     ** 
28   |  ** ************************************************************************ **/
29   | 
30   | static char Id[] = "@(#)$Id: ModuleCmd_Clear.c.src.html,v 1.2 2005/11/25 20:09:37 rkowen Exp $";
31   | static void *UseId[] = { &UseId, Id };
32   | 
33   | /** ************************************************************************ **/
34   | /** 				      HEADERS				     **/
35   | /** ************************************************************************ **/
36   | 
37   | #include "modules_def.h"
38   | 
39   | /** ************************************************************************ **/
40   | /** 				  LOCAL DATATYPES			     **/
41   | /** ************************************************************************ **/
42   | 
43   | /** not applicable **/
44   | 
45   | /** ************************************************************************ **/
46   | /** 				     CONSTANTS				     **/
47   | /** ************************************************************************ **/
48   | 
49   | /** not applicable **/
50   | 
51   | /** ************************************************************************ **/
52   | /**				      MACROS				     **/
53   | /** ************************************************************************ **/
54   | 
55   | /** not applicable **/
56   | 
57   | /** ************************************************************************ **/
58   | /** 				    LOCAL DATA				     **/
59   | /** ************************************************************************ **/
60   | 
61   | #if WITH_DEBUGGING_MODULECMD
62   | static	char	module_name[] = "ModuleCmd_Clear.c";	/** File name of this module **/
63   | static	char	_proc_ModuleCmd_Clear[] = "ModuleCmd_Clear";
64   | #endif
65   | 
66   | /** ************************************************************************ **/
67   | /**				    PROTOTYPES				     **/
68   | /** ************************************************************************ **/
69   | 
70   | /** not applicable **/
71   | 
72   | 
73   | /*++++
74   |  ** ** Function-Header ***************************************************** **
75   |  ** 									     **
76   |  **   Function:		ModuleCmd_Clear					     **
77   |  ** 									     **
78   |  **   Description:	Execution of the module-command 'clear'		     **
79   |  **			Resets the modules runtime information but doesn't   **
80   |  **			apply further changes to the environment at all      **
81   |  ** 									     **
82   |  **   First Edition:	91/10/23					     **
83   |  ** 									     **
84   |  **   Parameters:	Tcl_Interp	*interp		Attached Tcl Interp. **
85   |  **			int		 argc		Number of arguments  **
86   |  **			char 		*argv[]		Argument list	     **
87   |  ** 									     **
88   |  **   Result:		int	TCL_ERROR	Failure			     **
89   |  **				TCL_OK		Successfull operation	     **
90   |  ** 									     **
91   |  **   Attached Globals:							     **
92   |  ** 									     **
93   |  ** ************************************************************************ **
94   |  ++++*/
95   | 
96   | int ModuleCmd_Clear(	Tcl_Interp	*interp,
97   | 		    	int         	 argc,
98   | 		    	char		*argv[])
99   | {
100  |     char         buf[10];
101  |     char*        clearargv[4];
102  |     
103  | #if WITH_DEBUGGING_MODULECMD
104  |     ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Clear, NULL);
105  | #endif
106  | 
107  |     /**
108  |      **  Ask the user if he's really sure about what he's doing ...
109  |      **/
110  | 
111  |     if( argc == 1 && !strcmp( argv[0], "yes")) {
112  | 	buf[0] = 'y';
113  |     } else {
114  | 	fprintf( stderr,
115  |             "\nAre you sure you want to clear all loaded modules!? [n] ");
116  | 	fgets( buf, 10, stdin);
117  |     }
118  | 
119  |     /**
120  |      **  Reset the shell variables 'LOADEDMODULES' and '_LMFILES_'
121  |      **/
122  | 	
123  |     if( buf[0] == 'y') {
124  | 
125  |         clearargv[0] = "setenv";
126  |         clearargv[1] = "LOADEDMODULES";
127  |         clearargv[2] = "";
128  |         clearargv[3] = NULL;
129  |         cmdSetEnv( (ClientData) 0, interp, 3, clearargv);
130  | 
131  |         clearargv[0] = "setenv";
132  |         clearargv[1] = "_LMFILES_";
133  |         clearargv[2] = "";
134  |         clearargv[3] = NULL;
135  |         cmdSetEnv( (ClientData) 0, interp, 3, clearargv);
136  | 
137  |     } else {
138  |         fprintf( stderr, "\nLOADEDMODULES was NOT cleared.\n");
139  |     }
140  |     
141  |     /**
142  |      **  Return on success
143  |      **/
144  | 
145  | #if WITH_DEBUGGING_MODULECMD
146  |     ErrorLogger( NO_ERR_END, LOC, _proc_ModuleCmd_Clear, NULL);
147  | #endif
148  | 
149  |     return( TCL_OK);
150  | }