/***** ** ** Module Header ******************************************************* ** ** ** ** Modules Revision 3.0 ** ** Providing a flexible user environment ** ** ** ** File: ModuleCmd_Whatis.c ** ** First Edition: 95/12/31 ** ** ** ** Authors: Jens Hamisch, jens@Strawberry.COM ** ** ** ** ModuleCmd_Apropos ** ** ** ** Notes: ** ** ** ** ************************************************************************ ** ****/ /** ** Copyright *********************************************************** ** ** ** ** Copyright 1991-1994 by John L. Furlan. ** ** see LICENSE.GPL, which must be provided, for details ** ** ** ** ************************************************************************ **/ static char Id[] = "@(#)$Id: ModuleCmd_Whatis.c,v 1.3 2002/04/29 21:16:48 rkowen Exp $"; static void *UseId[] = { &UseId, Id }; /** ************************************************************************ **/ /** HEADERS **/ /** ************************************************************************ **/ #include "modules_def.h" /** ************************************************************************ **/ /** LOCAL DATATYPES **/ /** ************************************************************************ **/ /** not applicable **/ /** ************************************************************************ **/ /** CONSTANTS **/ /** ************************************************************************ **/ /** not applicable **/ /** ************************************************************************ **/ /** MACROS **/ /** ************************************************************************ **/ #define WHATIS_SOME 0 #define WHATIS_ALL 1 /** ************************************************************************ **/ /** LOCAL DATA **/ /** ************************************************************************ **/ static char module_name[] = "ModuleCmd_Whatis.c"; /** File name of this module **/ #if WITH_DEBUGGING_MODULECMD static char _proc_ModuleCmd_Whatis[] = "ModuleCmd_Whatis"; static char _proc_ModuleCmd_Apropos[] = "ModuleCmd_Apropos"; #endif #if WITH_DEBUGGING_UTIL_1 static char _proc_whatis_dir[] = "whatis_dir"; static char _proc_read_cache[] = "read_cache"; static char _proc_apropos_cache[] = "apropos_cache"; #endif static char cache_name[] = APR_CACHE; /** ************************************************************************ **/ /** PROTOTYPES **/ /** ************************************************************************ **/ static int read_cache( int, char**, FILE*, int); static int whatis_dir( char*, int, char**, FILE*, int); static char *apropos_cache(void); /*++++ ** ** Function-Header ***************************************************** ** ** ** ** Function: ModuleCmd_Whatis ** ** ** ** Description: Display the passed modules 'whatis' information ** ** ** ** First Edition: 95/12/31 ** ** ** ** Parameters: Tcl_Interp *interp Attached Tcl Interp. ** ** int argc Number of arguments ** ** char *argv[] Argument list ** ** ** ** Result: int TCL_ERROR Failure ** ** TCL_OK Successfull operation ** ** ** ** Attached Globals: g_flags These are set up accordingly before ** ** this function is called in order to ** ** control everything ** ** g_current_module The module which is handled ** ** by the current command ** ** ** ** ************************************************************************ ** ++++*/ int ModuleCmd_Whatis( Tcl_Interp *interp, int argc, char *argv[]) { struct stat stats; Tcl_Interp *whatis_interp; Tcl_DString cmdbuf; int i, result = TCL_OK, done = 0; char modulefile[ MOD_BUFSIZE], modulename[ MOD_BUFSIZE], *modpath, /** Buffer for the contents of the **/ /** environment variable MODULEPATH **/ **wptr, *dirname, *cache_file = (char *) NULL; /** Name of the cache file **/ FILE *cachefp = (FILE *) NULL; /** Cache file pointer **/ #if WITH_DEBUGGING_MODULECMD ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Whatis, NULL); #endif /** ** Initialize the command buffer and set up the modules flag to ** 'whatisonly' **/ Tcl_DStringInit( &cmdbuf); g_flags |= M_WHATIS; /** ** Handle each passed module file. Create a Tcl interpreter for each ** module file to be handled and initialize it with custom module commands **/ if ( argc) { /** ** User provided a list of modules for ``whatis'' info **/ for(i=0; i **/ unwind1: null_free((void *) &cache_file); null_free((void *) &modpath); unwind0: return( TCL_ERROR); /** --- EXIT PROCEDURE (FAILURE) --> **/ } /** End of 'ModuleCmd_Whatis' **/ /*++++ ** ** Function-Header ***************************************************** ** ** ** ** Function: ModuleCmd_Apropos ** ** ** ** Description: Scan the whatis database in order to find something ** ** matching the passed strings ** ** ** ** First Edition: 95/12/31 ** ** ** ** Parameters: Tcl_Interp *interp Attached Tcl Interp. ** ** int argc Number of arguments ** ** char *argv[] Argument list ** ** ** ** Result: int TCL_ERROR Failure ** ** TCL_OK Successfull operation ** ** ** ** Attached Globals: ** ** ** ** ************************************************************************ ** ++++*/ int ModuleCmd_Apropos( Tcl_Interp *interp, int argc, char *argv[]) { struct stat stats; char *dirname; char *modpath; /** Buffer for the contents of the **/ /** environment variable MODULEPATH **/ int i, done = 0; char *c; char *cache_file; /** Name of the cache file **/ FILE *cachefp = (FILE *) NULL; /** Cache file pointer **/ #if WITH_DEBUGGING_MODULECMD ErrorLogger( NO_ERR_START, LOC, _proc_ModuleCmd_Apropos, NULL); #endif /** ** Ignore case ... convert all arguments to lower case **/ if( sw_icase) for( i=0; i **/ } /** End of 'ModuleCmd_Apropos' **/ /*++++ ** ** Function-Header ***************************************************** ** ** ** ** Function: whatis_dir ** ** ** ** Description: Print all files beyond the passed directory ** ** ** ** First Edition: 91/10/23 ** ** ** ** Parameters: char *dir Directory to be scanned ** ** int argc Number of tokens ** ** char **argv List of tokens to check ** ** FILE *cfp Cache file pointer ** ** ** ** Result: int TCL_OK Successfull operation ** ** ** ** Attached Globals: g_flags These are set up accordingly before ** ** this function is called in order to ** ** control everything ** ** g_current_module The module which is handled ** ** by the current command ** ** ** ** ************************************************************************ ** ++++*/ static int whatis_dir( char *dir, int argc, char **argv, FILE *cfp, int whatis_list) { fi_ent *dirlst_head = NULL; /** Directory list base pointer **/ int count = 0; /** Number of elements in the top **/ /** level directory list **/ int tcount = 0; /** Total number of files to print **/ char **list; /** flat list of module files **/ int start = 0, i, k; int result = TCL_OK; Tcl_Interp *whatis_interp; Tcl_DString cmdbuf; char modulefile[ MOD_BUFSIZE]; char **wptr, *c; struct stat stats; #if WITH_DEBUGGING_UTIL_1 ErrorLogger( NO_ERR_START, LOC, _proc_whatis_dir, "dir='", dir, NULL); #endif /** ** Normal reading of the files **/ if( NULL == (dirlst_head = get_dir( dir, NULL, &count, &tcount))) if( OK != ErrorLogger( ERR_READDIR, LOC, dir, NULL)) goto unwind0; if( NULL == (list = (char**) malloc( tcount * sizeof( char**)))) if( OK != ErrorLogger( ERR_ALLOC, LOC, NULL)) goto unwind1; dirlst_to_list( list, dirlst_head, count, &start, NULL, NULL); /** ** Initialize the command buffer and set up the modules flag to 'whatislay ** only' **/ Tcl_DStringInit( &cmdbuf); g_flags |= M_WHATIS; /** ** Check all the files in the flat list for the passed tokens **/ for( i=0; i **/ unwind2: delete_cache_list( list, start); unwind1: delete_dirlst( dirlst_head, count); unwind0: return( TCL_ERROR); /** ------- EXIT (FAILURE) --------> **/ } /** End of 'whatis_dir' **/ /*++++ ** ** Function-Header ***************************************************** ** ** ** ** Function: read_cache ** ** ** ** Description: Grep in the cache file for the passed tokens ** ** ** ** First Edition: 91/10/23 ** ** ** ** Parameters: int argc Number of tokens ** ** char **argv List of tokens to check ** ** FILE *cfp Cache file pointer ** ** ** ** Result: int TCL_OK Successfull operation ** ** ** ** Attached Globals: - ** ** ** ** ************************************************************************ ** ++++*/ static int read_cache( int argc, char **argv, FILE *cfp, int whatis_list) { char *wptr, *c; char modulefile[ MOD_BUFSIZE]; char buffer[ MOD_BUFSIZE]; int k; #if WITH_DEBUGGING_UTIL_1 /* ErrorLogger( NO_ERR_START, LOC, _proc_read_cache, "dir='", dir, NULL); */ #endif while( wptr = fgets( buffer, MOD_BUFSIZE, cfp)) { /** ** Ingnore case? **/ if( sw_icase) { strncpy( modulefile, wptr, MOD_BUFSIZE); for( c = modulefile; c && *c; c++) *c = tolower( *c); c = modulefile; } else c = wptr; c = strchr( c, ':'); c++; /** ** Seek for the passed tokens **/ if ( whatis_list) fprintf( stderr, "%s", wptr); else for( k=0; k --> INSTPATH/etc/ ** / --> /RC_FILE ** / --> / **/ if( env = getenv( "MODULEWHATISCACHE")) { if((char *) NULL == (env_file = strrchr( env, '/'))) { env_file = env; env_path = instpath; } else { *env_file++ = '\0'; env_path = env; } if( !*env_file) env_file = cache_name; } else { env_path = instpath; env_file = cache_name; } /** ** Finaly we have to change INSTPATH -> INSTPATH/etc **/ if( env_path == instpath) { if((char *) NULL == (buffer = stringer(NULL,0, env_path,"/etc/",env_file,NULL))) goto unwind0; } else { if((char *) NULL == (buffer = stringer(NULL,0, env_path,"/",env_file,NULL))) goto unwind0; } /** ** Return the name of the cache file **/ #if WITH_DEBUGGING_UTIL_1 ErrorLogger( NO_ERR_END, LOC, _proc_apropos_cache, NULL); #endif return( buffer); unwind0: return (char *) NULL; } /** End of 'apropos_cache' **/