1 /*****
2  ** ** Module Header ******************************************************* **
3  ** 									     **
4  **   Modules Revision 3.0						     **
5  **   Providing a flexible user environment				     **
6  ** 									     **
7  **   File:		ModuleCmd_Display.c				     **
8  **   First Edition:	1991/10/23					     **
9  ** 									     **
10  **   Authors:	John Furlan, jlf@behere.com				     **
11  **		Jens Hamisch, jens@Strawberry.COM			     **
12  ** 									     **
13  **   Description:	Displays what changes a modulefile will make to the  **
14  **			environment including any conflics or prerequisits.  **
15  ** 									     **
16  **   Exports:		ModuleCmd_Display				     **
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: cfcc53fe7ca045c95b9e8d0b0afb4be93c69eda6 $";
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 char local_line[] =
62     "-------------------------------------------------------------------\n";
63 static	char	module_name[] = "ModuleCmd_Display.c";	/** File name of this module **/
64 #if WITH_DEBUGGING_MODULECMD
65 static	char	_proc_ModuleCmd_Display[] = "ModuleCmd_Display";
66 #endif
67 
68 /** ************************************************************************ **/
69 /**				    PROTOTYPES				     **/
70 /** ************************************************************************ **/
71 
72 /** not applicable **/
73 
74 
75 /*++++
76  ** ** Function-Header ***************************************************** **
77  ** 									     **
78  **   Function:		ModuleCmd_Display				     **
79  ** 									     **
80  **   Description:	Execution of the module-command 'display'	     **
81  **			Display every change a module 'load' would apply to  **
82  **			the environment					     **
83  ** 									     **
84  **   First Edition:	1991/10/23					     **
85  ** 									     **
86  **   Parameters:	Tcl_Interp	*interp		Attached Tcl Interp. **
87  **			char 		*argv[]		Argument list	     **
88  ** 									     **
89  **   Result:		int	TCL_ERROR	Failure			     **
90  **				TCL_OK		Successful operation	     **
91  ** 									     **
92  **   Attached Globals:	g_specified_module	The module name from the     **
93  **						command line.		     **
94  **   			g_flags		These are set up accordingly before  **
95  **					this function is called in order to  **
96  **					control everything		     **
97  **			g_current_module	The module which is handled  **
98  **						by the current command	     **
99  ** 									     **
100  ** ************************************************************************ **
101  ++++*/
102 
ModuleCmd_Display(Tcl_Interp * interp,int argc,char * argv[])103 int ModuleCmd_Display(	Tcl_Interp	*interp,
104 			int		 argc,
105                   	char		*argv[])
106 {
107     Tcl_Interp	*disp_interp;
108     Tcl_DString	 cmdbuf;
109     int		 i,
110     		 result;
111     char	 modulefile[ MOD_BUFSIZE];
112     char	 modulename[ MOD_BUFSIZE];
113 
114 #if WITH_DEBUGGING_MODULECMD
115     ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Display, NULL);
116 #endif
117 
118     /**
119      **  Initialize the command buffer and set up the modules flag to 'display
120      **  only'
121      **/
122 
123     Tcl_DStringInit( &cmdbuf);
124     g_flags |= M_DISPLAY;
125 
126     /**
127      **  Handle each passed module file. Create a Tcl interpreter for each
128      **  module file to be handled and initialize it with custom module commands
129      **/
130 
131     for(i=0; i<argc && argv[i]; i++) {
132         /**
133          ** Set the name of the module specified on the command line
134          **/
135 
136         g_specified_module = argv[i];
137 
138 	disp_interp = EM_CreateInterp();
139 	if( TCL_OK != (result = InitializeModuleCommands( disp_interp))) {
140 	    EM_DeleteInterp( disp_interp);
141 	    return( result);		/** -------- EXIT (FAILURE) -------> **/
142 	}
143 
144 	/**
145 	 **  locate the filename related to the passed module
146 	 **/
147 
148 	if( Locate_ModuleFile(disp_interp, argv[i], modulename, modulefile) ==
149             TCL_ERROR) {
150 	    EM_DeleteInterp( disp_interp);
151 	    if( OK != ErrorLogger( ERR_LOCATE, LOC, argv[i], NULL))
152 		break;
153 	    else
154 		continue;
155 	}
156 
157 	/**
158 	 **  Print out everything that would happen if the module file were
159 	 **  executed ...
160 	 **/
161 
162         g_current_module = modulename;
163 
164         fprintf( stderr, "%s", local_line);
165 	fprintf( stderr, "%s:\n\n", modulefile);
166 
167 	result = CallModuleProcedure( disp_interp, &cmdbuf, modulefile,
168 	    "ModulesDisplay", 0);
169 
170         fprintf( stderr, "%s", local_line);
171 
172 	/**
173 	 **  Remove the Tcl interpreter that has been used for printing ...
174 	 **/
175 
176 	EM_DeleteInterp( disp_interp);
177 
178     } /** for **/
179 
180     /**
181      **  Leave the 'display only mode', free up what has been used and return
182      **/
183 
184     g_flags &= ~M_DISPLAY;
185     fprintf( stderr, "\n");
186 
187     Tcl_DStringFree( &cmdbuf);
188 
189 #if WITH_DEBUGGING_MODULECMD
190     ErrorLogger( NO_ERR_END, LOC, _proc_ModuleCmd_Display, NULL);
191 #endif
192 
193     return( TCL_OK);
194 
195 } /** End of 'ModuleCmd_Display' **/
196 
197