1    | /*****
2    |  ** ** Module Header ******************************************************* **
3    |  **									     **
4    |  **   Modules Revision 3.0						     **
5    |  **   Providing a flexible user environment				     **
6    |  **									     **
7    |  **   File:		ModuleCmd_Whatis.c				     **
8    |  **   First Edition:	95/12/31					     **
9    |  **									     **
10   |  **   Authors:	Jens Hamisch, jens@Strawberry.COM			     **
11   |  **									     **
12   |  **			ModuleCmd_Apropos				     **
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: ModuleCmd_Whatis.c.src.html,v 1.2 2005/11/25 20:09:37 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   | #define WHATIS_SOME	0
52   | #define WHATIS_ALL	1
53   | 
54   | /** ************************************************************************ **/
55   | /**				    LOCAL DATA				     **/
56   | /** ************************************************************************ **/
57   | 
58   | static	char	module_name[] = "ModuleCmd_Whatis.c";	/** File name of this module **/
59   | 
60   | #if WITH_DEBUGGING_MODULECMD
61   | static	char	_proc_ModuleCmd_Whatis[] = "ModuleCmd_Whatis";
62   | static	char	_proc_ModuleCmd_Apropos[] = "ModuleCmd_Apropos";
63   | #endif
64   | #if WITH_DEBUGGING_UTIL_1
65   | static	char	_proc_whatis_dir[] = "whatis_dir";
66   | static	char	_proc_read_cache[] = "read_cache";
67   | static	char	_proc_apropos_cache[] = "apropos_cache";
68   | #endif
69   | 
70   | static	char	cache_name[] = APR_CACHE;
71   | 
72   | /** ************************************************************************ **/
73   | /**				    PROTOTYPES				     **/
74   | /** ************************************************************************ **/
75   | 
76   | static	int	 read_cache( int, char**, FILE*, int);
77   | static	int	 whatis_dir( char*, int, char**, FILE*, int);
78   | static	char	*apropos_cache(void);
79   | 
80   | /*++++
81   |  ** ** Function-Header ***************************************************** **
82   |  **									     **
83   |  **   Function:		ModuleCmd_Whatis				     **
84   |  **									     **
85   |  **   Description:	Display the passed modules 'whatis' information	     **
86   |  **									     **
87   |  **   First Edition:	95/12/31					     **
88   |  **									     **
89   |  **   Parameters:	Tcl_Interp	*interp		Attached Tcl Interp. **
90   |  **			int		 argc		Number of arguments  **
91   |  **			char		*argv[]		Argument list	     **
92   |  **									     **
93   |  **   Result:		int	TCL_ERROR	Failure			     **
94   |  **				TCL_OK		Successfull operation	     **
95   |  **									     **
96   |  **   Attached Globals:	g_flags		These are set up accordingly before  **
97   |  **					this function is called in order to  **
98   |  **					control everything		     **
99   |  **			g_current_module	The module which is handled  **
100  |  **						by the current command	     **
101  |  **									     **
102  |  ** ************************************************************************ **
103  |  ++++*/
104  | 
105  | int ModuleCmd_Whatis(	Tcl_Interp	*interp,
106  | 			int		 argc,
107  | 			char		*argv[])
108  | {
109  |     struct stat	 stats;
110  |     Tcl_Interp	*whatis_interp;
111  |     Tcl_DString	 cmdbuf;
112  |     int		 i, result = TCL_OK, done = 0;
113  |     char	 modulefile[ MOD_BUFSIZE],
114  | 		 modulename[ MOD_BUFSIZE],
115  | 		*modpath,		/** Buffer for the contents of the   **/
116  | 					/** environment variable MODULEPATH  **/
117  | 		**wptr,
118  | 		*dirname,
119  | 		*cache_file = (char *) NULL;	/** Name of the cache file   **/
120  |     FILE	*cachefp = (FILE *) NULL;	/** Cache file pointer	     **/
121  | 
122  | #if WITH_DEBUGGING_MODULECMD
123  |     ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Whatis, NULL);
124  | #endif
125  | 
126  |     /**
127  |      **	 Initialize the command buffer and set up the modules flag to
128  |      **	 'whatisonly'
129  |      **/
130  |     Tcl_DStringInit( &cmdbuf);
131  |     g_flags |= M_WHATIS;
132  | 
133  |     /**
134  |      **	 Handle each passed module file. Create a Tcl interpreter for each
135  |      **	 module file to be handled and initialize it with custom module commands
136  |      **/
137  | 
138  |     if ( argc) {
139  |     /**
140  |      **	 User provided a list of modules for ``whatis'' info
141  |      **/
142  | 	for(i=0; i<argc && argv[i]; i++) {
143  | 
144  | 	    whatis_interp = Tcl_CreateInterp();
145  | 	    if( TCL_OK != (result = InitializeModuleCommands( whatis_interp))) {
146  | 		Tcl_DeleteInterp( whatis_interp);
147  | 		result = TCL_ERROR;
148  | 		break;
149  | 	    }
150  | 
151  | 	    /**
152  | 	     **	 locate the filename related to the passed module
153  | 	     **/
154  | 	    if( TCL_ERROR ==
155  | 		Locate_ModuleFile(whatis_interp,argv[i],modulename,modulefile)){
156  | 		Tcl_DeleteInterp( whatis_interp);
157  | 		if( OK != ErrorLogger( ERR_LOCATE, LOC, argv[i], NULL))
158  | 		    break;
159  | 		else
160  | 		    continue;
161  | 	    }
162  | 
163  | 	    /**
164  | 	     **	 Print out everything that would happen if the module file were
165  | 	     **	 executed ...
166  | 	     **/
167  | 	    g_current_module = modulename;
168  | 
169  | 	    cmdModuleWhatisInit();
170  | 	    result = CallModuleProcedure( whatis_interp, &cmdbuf, modulefile,
171  | 		"ModulesWhatis", 0);
172  | 
173  | 	    /**
174  | 	     **	 Print the result ...
175  | 	     **/
176  | 	    if( whatis) {
177  | 		wptr = whatis;
178  | 		while( *wptr)
179  | 		    fprintf( stderr, "%-21s: %s\n", argv[i], *wptr++);
180  | 	    }
181  | 
182  | 	    /**
183  | 	     **	 Remove the Tcl interpreter that has been used for printing ...
184  | 	     **/
185  | 	    Tcl_DeleteInterp( whatis_interp);
186  | 	    cmdModuleWhatisShut();
187  | 
188  | 	} /** for **/
189  |     } else {
190  |        /**
191  | 	**  User wants all module ``whatis'' info
192  | 	**/
193  | 
194  | 	/**
195  | 	 **  If no MODULEPATH defined, we can not output anything
196  | 	 **/
197  | 	if( !(modpath = (char *) xgetenv( "MODULEPATH")))
198  | 	    if( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
199  | 		goto unwind0;
200  | 
201  | 	/**
202  | 	 **  Check whether a cache file exists then list all the ``whatis'' info
203  | 	 **  Otherwise read all module files ...
204  | 	 **/
205  | 	cache_file = apropos_cache();
206  | 	if( !sw_create && cache_file && !stat( cache_file, &stats)) {
207  | 
208  | 	    /**
209  | 	     **	 Open the cache file
210  | 	     **/
211  | 	    if((FILE *) NULL == (cachefp = fopen( cache_file, "r"))) {
212  | 		if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
213  | 		    goto unwind1;
214  | 	
215  | 	    } else {
216  | 		
217  | 		/**
218  | 		 **  Read the cache and close the file
219  | 		 **/
220  | 		result = read_cache( argc, argv, cachefp, WHATIS_ALL);
221  | 
222  | 		if( EOF == fclose( cachefp))
223  | 		    if( OK != ErrorLogger( ERR_CLOSE, LOC, cache_file, NULL))
224  | 			goto unwind1;
225  | 
226  | 		done = 1;
227  | 	    }
228  | 	}
229  | 
230  | 	/**
231  | 	 **  If we're not done now, we have to scan the files
232  | 	 **/
233  | 	 if( !done) {
234  | 
235  | 	     /**
236  | 	      **  Open the cache file if neccessary
237  | 	      **/
238  | 	     if( sw_create && cache_file)
239  | 		 if((FILE *) NULL == (cachefp = fopen( cache_file, "w")))
240  | 		     if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
241  | 			 goto unwind1;
242  | 		
243  | 	     /**
244  | 	      **  Tokenize the module path string and check all dirs
245  | 	      **/
246  | 	     for( dirname = strtok( modpath, ":");
247  | 		  dirname;
248  | 		  dirname = strtok( NULL, ":") ) {
249  | 	
250  | 		 if( !check_dir( dirname))
251  | 		     continue;
252  | 	
253  | 		 whatis_dir( dirname, argc, argv, cachefp, WHATIS_ALL);
254  | 
255  | 	     } /** for **/
256  | 
257  | 	     /**
258  | 	      **  Close the cache file
259  | 	      **/
260  | 	     if( cachefp)
261  | 		 if( EOF == fclose( cachefp))
262  | 		     if( OK != ErrorLogger( ERR_CLOSE, LOC, cache_file, NULL))
263  | 			 goto unwind1;
264  | 	 }
265  |     }
266  | 
267  |     /**
268  |      **	 Leave the 'whatis only mode', free up what has been used and return
269  |      **/
270  |     g_flags &= ~M_WHATIS;
271  |     fprintf( stderr, "\n");
272  | 
273  |     Tcl_DStringFree( &cmdbuf);
274  | 
275  |     /**
276  |      **	 Free up allocated resources
277  |      **/
278  |     null_free((void *) &cache_file);
279  |     null_free((void *) &modpath);
280  | 
281  |     /**
282  |      **	 Return on success
283  |      **/
284  | 
285  | #if WITH_DEBUGGING_MODULECMD
286  |     ErrorLogger( NO_ERR_END, LOC, _proc_ModuleCmd_Whatis, NULL);
287  | #endif
288  | 
289  |     return( result);			/** --- EXIT PROCEDURE (result)  --> **/
290  | 
291  | unwind1:
292  |     null_free((void *) &cache_file);
293  |     null_free((void *) &modpath);
294  | unwind0:
295  |     return( TCL_ERROR);			/** --- EXIT PROCEDURE (FAILURE) --> **/
296  | 
297  | } /** End of 'ModuleCmd_Whatis' **/
298  | 
299  | /*++++
300  |  ** ** Function-Header ***************************************************** **
301  |  **									     **
302  |  **   Function:		ModuleCmd_Apropos				     **
303  |  **									     **
304  |  **   Description:	Scan the whatis database in order to find something  **
305  |  **			matching the passed strings			     **
306  |  **									     **
307  |  **   First Edition:	95/12/31					     **
308  |  **									     **
309  |  **   Parameters:	Tcl_Interp	*interp		Attached Tcl Interp. **
310  |  **			int		 argc		Number of arguments  **
311  |  **			char		*argv[]		Argument list	     **
312  |  **									     **
313  |  **   Result:		int	TCL_ERROR	Failure			     **
314  |  **				TCL_OK		Successfull operation	     **
315  |  **									     **
316  |  **   Attached Globals:							     **
317  |  **									     **
318  |  ** ************************************************************************ **
319  |  ++++*/
320  | 
321  | int ModuleCmd_Apropos(	Tcl_Interp	*interp,
322  | 			int		 argc,
323  | 			char		*argv[])
324  | {
325  |     struct stat	 stats;
326  |     char	*dirname;
327  |     char	*modpath;		/** Buffer for the contents of the   **/
328  | 					/** environment variable MODULEPATH  **/
329  |     int		 i, done = 0;
330  |     char	*c;
331  |     char	*cache_file;		/** Name of the cache file	     **/
332  |     FILE	*cachefp = (FILE *) NULL;	/** Cache file pointer	     **/
333  | 
334  | #if WITH_DEBUGGING_MODULECMD
335  |     ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Apropos, NULL);
336  | #endif
337  | 
338  |     /**
339  |      **	 Ignore case ... convert all arguments to lower case
340  |      **/
341  |     if( sw_icase)
342  | 	for( i=0; i<argc; i++)
343  | 	    for( c=argv[ i]; c && *c; c++)
344  | 		*c = tolower( *c);
345  | 
346  |     /**
347  |      **	 If there's no MODULEPATH defined, we cannot output anything
348  |      **/
349  |     if((char *) NULL == (modpath =  xgetenv( "MODULEPATH")))
350  | 	if( OK != ErrorLogger( ERR_MODULE_PATH, LOC, NULL))
351  | 	    goto unwind0;
352  | 
353  |     /**
354  |      **	 Check whether	there's a cache file. If it is, grep for the tokens
355  |      **	 in this file. Otherwise read all module files ...
356  |      **/
357  |     cache_file = apropos_cache();
358  |     if( !sw_create && cache_file && !stat( cache_file, &stats)) {
359  | 
360  | 	/**
361  | 	 **  Open the cache file
362  | 	 **/
363  | 	if((FILE *) NULL == (cachefp = fopen( cache_file, "r"))) {
364  | 	    if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
365  | 		goto unwind1;
366  | 	
367  | 	} else {
368  | 		
369  | 	    /**
370  | 	     **	 Read the cache and close the file
371  | 	     **/
372  | 	    read_cache( argc, argv, cachefp, WHATIS_SOME);
373  | 
374  | 	    if( EOF == fclose( cachefp))
375  | 		if( OK != ErrorLogger( ERR_CLOSE, LOC, cache_file, NULL))
376  | 		    goto unwind1;
377  | 
378  | 	    done = 1;
379  | 	}
380  |     }
381  | 
382  |     /**
383  |      **	 If we're not done now, we have to scan the files
384  |      **/
385  |     if( !done) {
386  | 
387  | 	/**
388  | 	 **  Open the cache file if neccessary
389  | 	 **/
390  | 	if( sw_create && cache_file)
391  | 	    if((FILE *) NULL == (cachefp = fopen( cache_file, "w")))
392  | 		if( OK != ErrorLogger( ERR_OPEN, LOC, cache_file, NULL))
393  | 		    goto unwind1;
394  | 
395  | 	/**
396  | 	 **  Tokenize the module path string and check all dirs
397  | 	 **/
398  | 	for( dirname = strtok( modpath, ":");
399  | 	     dirname;
400  | 	     dirname = strtok( NULL, ":") ) {
401  | 	
402  | 	    if( !check_dir( dirname))
403  | 		continue;
404  | 	
405  | 	    whatis_dir( dirname, argc, argv, cachefp, WHATIS_SOME);
406  | 
407  | 	} /** for **/
408  | 
409  | 	/**
410  | 	 **  Close the cache file
411  | 	 **/
412  | 	if( cachefp)
413  | 	    if( EOF == fclose( cachefp))
414  | 		if( OK != ErrorLogger( ERR_CLOSE, LOC, cache_file, NULL))
415  | 		    goto unwind1;
416  |     }
417  | 
418  |     /**
419  |      **	 Free up what has been allocated and exit from this procedure
420  |      **/
421  |     null_free((void *) &modpath);
422  | 
423  | #if WITH_DEBUGGING_MODULECMD
424  |     ErrorLogger( NO_ERR_END, LOC, _proc_ModuleCmd_Apropos, NULL);
425  | #endif
426  | 
427  |     return( TCL_OK);
428  | 
429  | unwind1:
430  |     null_free((void *) &modpath);
431  | unwind0:
432  |     return( TCL_ERROR);				/** ---- EXIT (FAILURE) ---> **/
433  | 
434  | } /** End of 'ModuleCmd_Apropos' **/
435  | 
436  | /*++++
437  |  ** ** Function-Header ***************************************************** **
438  |  **									     **
439  |  **   Function:		whatis_dir					     **
440  |  **									     **
441  |  **   Description:	Print all files beyond the passed directory	     **
442  |  **									     **
443  |  **   First Edition:	91/10/23					     **
444  |  **									     **
445  |  **   Parameters:	char	*dir		Directory to be scanned	     **
446  |  **			int	 argc		Number of tokens	     **
447  |  **			char   **argv		List of tokens to check	     **
448  |  **			FILE	*cfp		Cache file pointer	     **
449  |  **									     **
450  |  **   Result:		int	TCL_OK		Successfull operation	     **
451  |  **									     **
452  |  **   Attached Globals:	g_flags		These are set up accordingly before  **
453  |  **					this function is called in order to  **
454  |  **					control everything		     **
455  |  **			g_current_module	The module which is handled  **
456  |  **						by the current command	     **
457  |  **									     **
458  |  ** ************************************************************************ **
459  |  ++++*/
460  | 
461  | static	int	whatis_dir( char *dir, int argc, char **argv, FILE *cfp,
462  | 			    int whatis_list)
463  | {
464  |     fi_ent	 *dirlst_head = NULL;	/** Directory list base pointer	     **/
465  |     int		  count = 0;		/** Number of elements in the top    **/
466  | 					/** level directory list	     **/
467  |     int		  tcount = 0;		/** Total number of files to print   **/
468  |     char	**list;			/** flat list of module files	     **/
469  |     int		  start = 0, i, k;
470  |     int		  result = TCL_OK;
471  |     Tcl_Interp	 *whatis_interp;
472  |     Tcl_DString	  cmdbuf;
473  |     char	  modulefile[ MOD_BUFSIZE];
474  |     char	**wptr, *c;
475  |     struct stat	 stats;
476  | 
477  | #if WITH_DEBUGGING_UTIL_1
478  |     ErrorLogger( NO_ERR_START, LOC, _proc_whatis_dir, "dir='", dir, NULL);
479  | #endif
480  | 
481  |     /**
482  |      **	 Normal reading of the files
483  |      **/
484  | 
485  |     if( NULL == (dirlst_head = get_dir( dir, NULL, &count, &tcount)))
486  | 	if( OK != ErrorLogger( ERR_READDIR, LOC, dir, NULL))
487  | 	    goto unwind0;
488  | 
489  |     if( NULL == (list = (char**) malloc( tcount * sizeof( char**))))
490  | 	if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL))
491  | 	    goto unwind1;
492  | 
493  |     dirlst_to_list( list, dirlst_head, count, &start, NULL, NULL);
494  | 
495  |     /**
496  |      **	 Initialize the command buffer and set up the modules flag to 'whatislay
497  |      **	 only'
498  |      **/
499  | 
500  |     Tcl_DStringInit( &cmdbuf);
501  |     g_flags |= M_WHATIS;
502  | 
503  |     /**
504  |      **	 Check all the files in the flat list for the passed tokens
505  |      **/
506  | 
507  |     for( i=0; i<tcount; i++) {
508  | 
509  | 	whatis_interp = Tcl_CreateInterp();
510  | 	if( TCL_OK != (result = InitializeModuleCommands( whatis_interp))) {
511  | 	    Tcl_DeleteInterp( whatis_interp);
512  | 	    result = TCL_ERROR;
513  | 	    break; /** for( i) **/
514  | 	}
515  | 
516  | 	/**
517  | 	 **  locate the filename related to the passed module
518  | 	 **/
519  | 
520  | 	if( (char *) NULL == stringer(modulefile,MOD_BUFSIZE,
521  | 		dir,"/",list[i],NULL)) {
522  | 	    result = TCL_ERROR;
523  | 	    break; /** for( i) **/
524  | 	}
525  | 	g_current_module = list[ i];
526  | 
527  | 	if( stat( modulefile, &stats) || S_ISDIR( stats.st_mode))
528  | 	    continue;
529  | 
530  | 	cmdModuleWhatisInit();
531  | 	result = CallModuleProcedure( whatis_interp, &cmdbuf, modulefile,
532  | 	    "ModulesApropos", 0);
533  | 
534  | 	/**
535  | 	 **  Check if at least one of the passed tokens is found in the
536  | 	 **  retrieved whatis strings. If yes, print the string.
537  | 	 **/
538  | 
539  | 	if( whatis) {
540  | 	    wptr = whatis;
541  | 	    while( *wptr) {
542  | 
543  | 		/**
544  | 		 **  Cache output enabled?
545  | 		 **/
546  | 
547  | 		if( cfp)
548  | 		    fprintf( cfp, "%-21s: %s\n", list[i], *wptr);
549  | 
550  | 		/**
551  | 		 **  Ignore case?
552  | 		 **/
553  | 
554  | 		if( sw_icase) {
555  | 		    strncpy( modulefile, *wptr, MOD_BUFSIZE);
556  | 		    for( c = modulefile; c && *c; c++)
557  | 			*c = tolower( *c);
558  | 		    c = modulefile;
559  | 		} else
560  | 		    c = *wptr;
561  | 
562  | 		/**
563  | 		 **  Seek for the passed tokens
564  | 		 **/
565  | 
566  | 		if( whatis_list)
567  | 		    fprintf( stderr, "%-21s: %s\n", list[i], *wptr);
568  | 		else
569  | 		    for( k=0; k<argc; k++) {
570  | 			if( strstr( c, argv[ k]))
571  | 		    	    fprintf( stderr, "%-21s: %s\n", list[i], *wptr);
572  | 		    }
573  | 		wptr++;
574  | 	    }
575  | 	}
576  | 
577  | 	/**
578  | 	 **  Remove the Tcl interpreter that has been used for printing ...
579  | 	 **/
580  | 
581  | 	Tcl_DeleteInterp( whatis_interp);
582  | 	cmdModuleWhatisShut();
583  | 
584  |     } /** for( i) **/
585  | 
586  |     /**
587  |      **	 Cleanup
588  |      **/
589  |     g_flags &= ~M_WHATIS;
590  |     delete_dirlst( dirlst_head, count);
591  |     delete_cache_list( list, start);
592  | 
593  | #if WITH_DEBUGGING_UTIL_1
594  |     ErrorLogger( NO_ERR_END, LOC, _proc_whatis_dir, NULL);
595  | #endif
596  | 
597  |     return( result);			/** ------- EXIT (result) --------> **/
598  | 
599  | unwind2:
600  |     delete_cache_list( list, start);
601  | unwind1:
602  |     delete_dirlst( dirlst_head, count);
603  | unwind0:
604  |     return( TCL_ERROR);			/** ------- EXIT (FAILURE) --------> **/
605  | 
606  | } /** End of 'whatis_dir' **/
607  | 
608  | /*++++
609  |  ** ** Function-Header ***************************************************** **
610  |  **									     **
611  |  **   Function:		read_cache					     **
612  |  **									     **
613  |  **   Description:	Grep in the cache file for the passed tokens         **
614  |  **									     **
615  |  **   First Edition:	91/10/23					     **
616  |  **									     **
617  |  **   Parameters:	int	 argc		Number of tokens	     **
618  |  **			char   **argv		List of tokens to check	     **
619  |  **			FILE	*cfp		Cache file pointer	     **
620  |  **									     **
621  |  **   Result:		int	TCL_OK		Successfull operation	     **
622  |  **									     **
623  |  **   Attached Globals: -						     **
624  |  **									     **
625  |  ** ************************************************************************ **
626  |  ++++*/
627  | 
628  | static	int	read_cache( int argc, char **argv, FILE *cfp, int whatis_list)
629  | {
630  |     char	*wptr, *c;
631  |     char	 modulefile[ MOD_BUFSIZE];
632  |     char	 buffer[ MOD_BUFSIZE];
633  |     int		 k;
634  | 
635  | #if WITH_DEBUGGING_UTIL_1
636  | /*
637  |     ErrorLogger( NO_ERR_START, LOC, _proc_read_cache, "dir='", dir, NULL);
638  | */
639  | #endif
640  | 
641  |     while( wptr = fgets( buffer, MOD_BUFSIZE, cfp)) {
642  | 
643  | 	/**
644  | 	 **  Ingnore case?
645  | 	 **/
646  | 
647  | 	if( sw_icase) {
648  | 	    strncpy( modulefile, wptr, MOD_BUFSIZE);
649  | 	    for( c = modulefile; c && *c; c++)
650  | 		*c = tolower( *c);
651  | 	    c = modulefile;
652  | 	} else
653  | 	    c = wptr;
654  | 
655  | 	c = strchr( c, ':');
656  | 	c++;
657  | 
658  | 	/**
659  | 	 **  Seek for the passed tokens
660  | 	 **/
661  | 
662  | 	if ( whatis_list)
663  | 	    fprintf( stderr, "%s", wptr);
664  | 	else
665  | 	    for( k=0; k<argc; k++)
666  | 		if( strstr( c, argv[ k]))
667  | 		    fprintf( stderr, "%s", wptr);
668  |     }
669  | 
670  | #if WITH_DEBUGGING_UTIL_1
671  |     ErrorLogger( NO_ERR_END, LOC, _proc_read_cache, NULL);
672  | #endif
673  | 
674  |     return( TCL_OK);
675  | 
676  | } /** End of 'read_cache' **/
677  | 
678  | /*++++
679  |  ** ** Function-Header ***************************************************** **
680  |  **									     **
681  |  **   Function:		apropos_cache					     **
682  |  **									     **
683  |  **   Description:	Figure out, what's the name of the apropos cache file**
684  |  **									     **
685  |  **   First Edition:	91/10/23					     **
686  |  **									     **
687  |  **   Parameters:	-						     **
688  |  **									     **
689  |  **   Result:		char*	NULL		No cache file configured     **
690  |  **				Otherwise	Pointer to the file name     **
691  |  **									     **
692  |  **   Attached Globals: -						     **
693  |  **									     **
694  |  ** ************************************************************************ **
695  |  ++++*/
696  | 
697  | static	char	*apropos_cache()
698  | {
699  |     char	*buffer, *env, *env_file, *env_path;
700  | 
701  | #if WITH_DEBUGGING_UTIL_1
702  | /*
703  |     ErrorLogger( NO_ERR_START, LOC, _proc_apropos_cache, "dir='", dir, NULL);
704  | */
705  | #endif
706  | 
707  |     /**
708  |      **	 Figure out, what out global RC file is. This depends on the environ-
709  |      **	 ment variable 'MODULEWHATISCACHE', which can be set to one of the
710  |      **	 following:
711  |      **
712  |      **		<filename>	-->	PREFIX/etc/<filename>
713  |      **		<dir>/		-->	<dir>/RC_FILE
714  |      **		<dir>/<file>	-->	<dir>/<file>
715  |      **/
716  | 
717  |     if( env = getenv( "MODULEWHATISCACHE")) {
718  | 
719  | 	if((char *) NULL == (env_file = strrchr( env, '/'))) {
720  | 	    env_file = env;
721  | 	    env_path = instpath;
722  | 
723  | 	} else {
724  | 	    *env_file++ = '\0';
725  | 	    env_path = env;
726  | 	}
727  | 	
728  | 	if( !*env_file)
729  | 	    env_file = cache_name;
730  | 
731  |     } else {
732  | 	env_path = instpath;
733  | 	env_file = cache_name;
734  |     }
735  | 
736  |     /**
737  |      **	 Finaly we have to change PREFIX -> PREFIX/etc
738  |      **/
739  |     if( env_path == instpath) {
740  | 	if((char *) NULL == (buffer = stringer(NULL,0,
741  | 		env_path,"/etc/",env_file,NULL)))
742  | 	    goto unwind0;
743  |     } else {
744  | 	if((char *) NULL == (buffer = stringer(NULL,0,
745  | 		env_path,"/",env_file,NULL)))
746  | 	    goto unwind0;
747  |     }
748  | 
749  |     /**
750  |      **	 Return the name of the cache file
751  |      **/
752  | #if WITH_DEBUGGING_UTIL_1
753  |     ErrorLogger( NO_ERR_END, LOC, _proc_apropos_cache, NULL);
754  | #endif
755  | 
756  |     return( buffer);
757  | 
758  | unwind0:
759  |     return (char *) NULL;
760  | } /** End of 'apropos_cache' **/