1    | /*****
2    |  ** ** Module Header ******************************************************* **
3    |  ** 									     **
4    |  **   Modules Revision 3.0						     **
5    |  **   Providing a flexible user environment				     **
6    |  ** 									     **
7    |  **   File:		cmdIsLoaded.c					     **
8    |  **   First Edition:	2000/04/12					     **
9    |  ** 									     **
10   |  **   Description:	The Tcl conflict and prereq commands.		     **
11   |  ** 									     **
12   |  **   Exports:		cmdIsLoaded					     **
13   |  ** 									     **
14   |  **   Notes:								     **
15   |  ** 									     **
16   |  ** ************************************************************************ **
17   |  ****/
18   | 
19   | /** ** Copyright *********************************************************** **
20   |  ** 									     **
21   |  ** Copyright 1991-1994 by John L. Furlan.                      	     **
22   |  ** see LICENSE.GPL, which must be provided, for details		     **
23   |  ** 									     ** 
24   |  ** ************************************************************************ **/
25   | 
26   | static char Id[] = "@(#)$Id: cmdIsLoaded.c.src.html,v 1.6 2006/01/18 05:35:11 rkowen Exp $";
27   | static void *UseId[] = { &UseId, Id };
28   | 
29   | /** ************************************************************************ **/
30   | /** 				      HEADERS				     **/
31   | /** ************************************************************************ **/
32   | 
33   | #include "modules_def.h"
34   | 
35   | /** ************************************************************************ **/
36   | /** 				  LOCAL DATATYPES			     **/
37   | /** ************************************************************************ **/
38   | 
39   | /** not applicable **/
40   | 
41   | /** ************************************************************************ **/
42   | /** 				     CONSTANTS				     **/
43   | /** ************************************************************************ **/
44   | 
45   | /** not applicable **/
46   | 
47   | /** ************************************************************************ **/
48   | /**				      MACROS				     **/
49   | /** ************************************************************************ **/
50   | 
51   | /** not applicable **/
52   | 
53   | /** ************************************************************************ **/
54   | /** 				    LOCAL DATA				     **/
55   | /** ************************************************************************ **/
56   | 
57   | static	char	module_name[] = "cmdIsLoaded.c";	/** File name of this module **/
58   | #if WITH_DEBUGGING_CALLBACK
59   | static	char	_proc_cmdIsLoaded[] = "cmdIsLoaded";
60   | #endif
61   | 
62   | /** ************************************************************************ **/
63   | /**				    PROTOTYPES				     **/
64   | /** ************************************************************************ **/
65   | 
66   | /*++++
67   |  ** ** Function-Header ***************************************************** **
68   |  ** 									     **
69   |  **   Function:		cmdIsLoaded					     **
70   |  ** 									     **
71   |  **   Description:	Callback function for 'is-loaded'		     **
72   |  ** 									     **
73   |  **   First Edition:	2000/04/12					     **
74   |  ** 									     **
75   |  **   Parameters:	ClientData	 client_data			     **
76   |  **			Tcl_Interp	*interp		According Tcl interp.**
77   |  **			int		 argc		Number of arguments  **
78   |  **			char		*argv[]		Argument array	     **
79   |  ** 									     **
80   |  **   Result:		int	TCL_OK		Successfull completion	     **
81   |  **				TCL_ERROR	Any error		     **
82   |  ** 									     **
83   |  **   Attached Globals:	g_flags		These are set up accordingly before  **
84   |  **					this function is called in order to  **
85   |  **					control everything		     **
86   |  ** 									     **
87   |  ** ************************************************************************ **
88   |  ++++*/
89   | 
90   | int	cmdIsLoaded(	ClientData	 client_data,
91   | 	    		Tcl_Interp	*interp,
92   | 	    		int		 argc,
93   | 	    		CONST84 char	*argv[])
94   | {
95   |     char	 **pathlist;
96   |     char	 **modulelist;
97   |     char	  *modulepath;
98   |     char	  *notloaded_flag = (char *) argv[1];
99   |     int     	   i, j, k, numpaths, nummodules;
100  | 	
101  | #if WITH_DEBUGGING_CALLBACK
102  |     ErrorLogger( NO_ERR_START, LOC, _proc_cmdIsLoaded, NULL);
103  | #endif
104  | 
105  |     /** 
106  |      **  Parameter check. Usage is 'is-loaded <module> [<module> ...]'
107  |      **/
108  | 
109  |     if( argc < 2) {
110  | 	if( OK != ErrorLogger( ERR_USAGE, LOC, argv[0], "is-loaded-modules", NULL))
111  | 	    return( TCL_ERROR);		/** -------- EXIT (FAILURE) -------> **/
112  |     }
113  | 
114  |     /**
115  |      **  There's no prerequisite check in case of whatis
116  |      **/
117  | 
118  |     if( g_flags & M_WHATIS)
119  |         return( TCL_OK);		/** -------- EXIT (SUCCESS) -------> **/
120  | 
121  |     /**
122  |      **  Load the MODULEPATH and split it into a list of paths
123  |      **/
124  | 
125  |     if( !(modulepath = (char *) getenv( "MODULEPATH"))) {
126  | 	if( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
127  | 	    return( TCL_ERROR);		/** -------- EXIT (FAILURE) -------> **/
128  |     }
129  | 
130  | #if WITH_DEBUGGING_CALLBACK_1
131  |     ErrorLogger( NO_ERR_DEBUG, LOC, "Got modulepath: '", modulepath, "'", NULL);
132  | #endif
133  | 
134  |     if( !(pathlist = SplitIntoList( interp, modulepath, &numpaths)))
135  |         return( TCL_OK);		/** -------- EXIT (SUCCESS) -------> **/
136  | 
137  |     /**
138  |      **  Check/Display all passed modules
139  |      **/
140  | 
141  |     for( i=1; i<argc && argv[i] && notloaded_flag; i++) {
142  |         for( j = 0; j < numpaths && notloaded_flag; j++) {
143  | 
144  |             if( NULL == (modulelist = SortedDirList( interp, pathlist[j], 
145  | 	        (char *) argv[i], &nummodules)))
146  |                 continue;
147  | 
148  | 	    /**
149  | 	     **  Now actually check if the prerequisites are fullfilled
150  | 	     **  The notloaded_flag controls the exit from both loops in case
151  | 	     **  a prerequisite is missing.
152  | 	     **/
153  | 
154  |             for( k=0; k < nummodules && notloaded_flag; k++) {
155  |                 if( !IsLoaded( interp, modulelist[k], NULL, NULL)) {
156  |                     notloaded_flag = (char *) argv[i];
157  |                 } else {
158  |                     notloaded_flag = NULL;
159  |                 }
160  |             }
161  | 
162  | 	    /**
163  | 	     **  Free what has been allocted in the loop
164  | 	     **/
165  | 
166  |             FreeList( modulelist, nummodules);
167  | 
168  |         } /** for( j) **/
169  |     } /** for( i) **/
170  | 
171  |     /**
172  |      **  Display an error message if this was *NOT* display mode and a
173  |      **  missing prerequisite has been found
174  |      **/
175  | 
176  |     Tcl_SetResult( interp, notloaded_flag ? "0" : "1", TCL_STATIC);
177  | 
178  | #if WITH_DEBUGGING_CALLBACK
179  |     ErrorLogger( NO_ERR_END, LOC, _proc_cmdIsLoaded, NULL);
180  | #endif
181  | 
182  |     return( TCL_OK);
183  | 
184  | } /** End of 'cmdIsLoaded' **/