File locate_module.c

 ** ** Module Header ******************************************************* **
 ** 									     **
 **   Modules Revision 3.0						     **
 **   Providing a flexible user environment				     **
 ** 									     **
 **   File:		locate_module.c					     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Authors:	John Furlan, jlf@behere.com				     **
 **		Jens Hamisch, jens@Strawberry.COM			     **
 ** 									     **
 **   Description: 	Contains the routines which locate the actual	     **
 **			modulefile given a modulefilename by looking in all  **
 **			of the paths in MODULEPATH. 			     **
 ** 									     **
 **   Exports:		Locate_ModuleFile				     **
 **			SortedDirList					     **
 **			SplitIntoList					     **
 **			FreeList					     **
 **			SourceRC					     **
 **			SourceVers					     **
 ** 									     **
 **   Notes:								     **
 ** 									     **
 ** ************************************************************************ **
References Variables: Idlocate_module.c

Included Files


Preprocessor definitions

#define SRCFRAG 100

Local Variables

Id
static char Id[]
Used in:  locate_module.c

UseId
static void* UseId[]

module_name
static char module_name[]
Used in: GetModuleName()
  Locate_ModuleFile()
  SortedDirList()
  SourceRC()
  SourceVers()
  SplitIntoList()

buf
static char buf[1024]
Used in: Locate_ModuleFile()

modfil_buf
static char modfil_buf[1024]
Used in: GetModuleName()


Global Function Locate_ModuleFile()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		Locate_ModuleFile				     **
 ** 									     **
 **   Description:	Searches for a modulefile given a string argument    **
 **			which is either a full path or a modulefile name     **
 **			-- usually the argument the user gave. If it's not a **
 **			full path, the directories in the MODULESPATH	     **
 **			environment variable are searched to find a match    **
 **			for the given name.				     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	Tcl_Interp	*interp		Attached Tcl interpr.**
 **			char		*modulename	Name of the module to**
 **							be located	     **
 **			char		*realname	Real modulename (with**
 **							version)	     **
 **			char		*filename	Real    full module  **
 **							file path	     **
 ** 									     **
 **   Result:		int		TCL_OK or TCL_ERROR		     **
 **			filename	the full path of the required module **
 **					file is copied in here		     **
 ** 									     **
 **   Attached Globals:	g_current_module	The module which is handled  **
 **						by the current command	     **
 ** 									     **
 ** ************************************************************************ **
int Locate_ModuleFile ( Tcl_Interp* interp, char* modulename, char* realname, char* filename )
Prototyped in: modules_def.h
Calls: GetModuleName()locate_module.c
  Module_Error()error.c
  SplitIntoList()locate_module.c
  VersionLookup()cmdVersion.c
  getenv(), strcat(), strcmp(), strcpy(), strlen(), strncpy(), strrchr()
Called by: ModuleCmd_Display()ModuleCmd_Display.c
  ModuleCmd_Load()ModuleCmd_Load.c
  ModuleCmd_Switch()ModuleCmd_Switch.c
  ModuleCmd_Whatis()ModuleCmd_Whatis.c
  PerModuleHelp()ModuleCmd_Help.c
  print_aligned_files()ModuleCmd_Avail.c
References Variables: buflocate_module.c
  g_current_modulemain.c
  module_namelocate_module.c

Global Function SortedDirList()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		SortedDirList					     **
 ** 									     **
 **   Description:	Checks the given path for the given modulefile.	     **
 **			If the path + the module filename is the modulefile, **
 **			then it is returned as the first element in the list.**
 **			If the path + the module filename is a directory, the**
 **			directory is read and sorted as the list.	     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	Tcl_Interp	*interp		According Tcl Interp.**
 **			char		*path		Path to start seeking**
 **			char		*modulename	Name of the module   **
 **			int		*listcnt	Buffer to return the **
 **							size of the created  **
 **							list in elements     **
 ** 									     **
 **   Result:		char**		NULL	Any failure (alloc, param)   **
 **					else	Base pointer to the newly    **
 **						created list.		     **
 **			*listcnt		Number of elements in the    **
 **						list if one was created, un- **
 **						changed otherwise	     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
char** SortedDirList ( Tcl_Interp* interp, char* path, char* modulename, int* listcnt )
Prototyped in: modules_def.h
Calls: Module_Error()error.c
  check_magic()utility.c
  calloc(), closedir(), malloc(), opendir(), qsort(), readdir(), realloc(), stat(), strcat(), strcmp(), strcpy(), strdup(), strlen()
Called by: GetModuleName()locate_module.c
  checkConflict()cmdConflict.c
  cmdConflict()cmdConflict.c
  cmdIsLoaded()cmdIsLoaded.c
  cmdPrereq()cmdConflict.c
References Functions: filename_compare()locate_module.c
References Variables: module_namelocate_module.c

Global Function SourceRC()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		SourceRC					     **
 ** 									     **
 **   Description:	Source the passed global RC file		     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	Tcl_Interp	*interp		Tcl interpreter	     **
 **			char		*path		Path to be used      **
 **			char		*name		Name of the RC file  **
 **									     **
 **   Result:		int		TCL_OK		Success		     **
 **					TCL_ERROR	Failure		     **
 **									     **
 **   Attached Globals:	g_flags		These are set up accordingly before  **
 **					this function is called in order to  **
 **					control everything		     **
 ** 									     **
 ** ************************************************************************ **
int SourceRC ( Tcl_Interp* interp, char* path, char* name )
Prototyped in: modules_def.h
Calls: Execute_TclFile()cmdModule.c
  Module_Error()error.c
  check_magic()utility.c
  malloc(), realloc(), stat(), strcat(), strcmp(), strcpy(), strdup()
Called by: GetModuleName()locate_module.c
  ModuleCmd_List()ModuleCmd_List.c
  main()main.c
  print_aligned_files()ModuleCmd_Avail.c
  print_dir()ModuleCmd_Avail.c
References Variables: g_flagsmain.c
  module_namelocate_module.c

Global Function SourceVers()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		SourceVers					     **
 ** 									     **
 **   Description:	Source the '.version' file			     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	Tcl_Interp	*interp		Tcl interpreter	     **
 **			char		*path		Path to be used      **
 **			char		*name		Name of the module   **
 **									     **
 **   Result:		int		TCL_OK		Success		     **
 **					TCL_ERROR	Failure		     **
 **									     **
 **   Attached Globals:	g_flags		These are set up accordingly before  **
 **					this function is called in order to  **
 **					control everything		     **
 ** 									     **
 ** ************************************************************************ **
int SourceVers ( Tcl_Interp* interp, char* path, char* name )
Prototyped in: modules_def.h
Calls: Execute_TclFile()cmdModule.c
  Module_Error()error.c
  VersionLookup()cmdVersion.c
  check_magic()utility.c
  cmdModuleVersion()cmdVersion.c
  Tcl_GetVar(), stat(), strcat(), strcmp(), strcpy()
Called by: GetModuleName()locate_module.c
  ModuleCmd_List()ModuleCmd_List.c
  print_aligned_files()ModuleCmd_Avail.c
  print_dir()ModuleCmd_Avail.c
References Variables: _defaultmain.c
  g_flagsmain.c
  module_namelocate_module.c
  version_filemain.c

Global Function SplitIntoList()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		SplitIntoList					     **
 ** 									     **
 **   Description: 	Splits a path-type environment variable into an array**
 **			of char* list.					     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	Tcl_Interp	*interp		According Tcl Interp.**
 **			char		*pathenv	Path to split 	     **
 **			int		*numpaths	Buffer to write the  **
 **							number of array ele- **
 **							ments to.	     **
 ** 									     **
 **   Result:		char**		NULL	Any failure (alloc, param.)  **
 **					else	Base pointer of the created  **
 **						array			     **
 **			*numpaths		Number of elements if an ar- **
 **						ray has been created, unchan-**
 **						ged otherwise.		     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
char** SplitIntoList ( Tcl_Interp* interp, char* pathenv, int* numpaths )
Prototyped in: modules_def.h
Calls: Module_Error()error.c
  xdup()utility.c
  calloc(), malloc(), realloc(), strcpy(), strlen(), strtok()
Called by: Locate_ModuleFile()locate_module.c
  ModuleCmd_Init()ModuleCmd_Init.c
  cmdConflict()cmdConflict.c
  cmdIsLoaded()cmdIsLoaded.c
  cmdPrereq()cmdConflict.c
References Variables: module_namelocate_module.c

Local Function GetModuleName()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		GetModuleName					     **
 ** 									     **
 **   Description:	Given a path and a module filename, this function    **
 **			checks to find the modulefile.			     **
 ** 									     **
 **   Notes:		This function is RECURSIVE			     **
 **									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	Tcl_Interp	*interp		According Tcl Interp.**
 **			char		*path		Path to start seeking**
 **			char		*prefix		Module name prefix   **
 **			char		*modulename	Name of the module   **
 ** 									     **
 **   Result:		char*	NULL	Any failure( parameters, alloc)	     **
 **				else	Pointer to an allocated buffer con-  **
 **					taining the complete module file path**
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
static char* GetModuleName ( Tcl_Interp* interp, char* path, char* prefix, char* modulename )
Prototyped in: locate_module.c
Calls: GetModuleName()locate_module.c
  Module_Error()error.c
  SortedDirList()locate_module.c
  SourceRC()locate_module.c
  SourceVers()locate_module.c
  VersionLookup()cmdVersion.c
  check_magic()utility.c
  malloc(), realloc(), stat(), strcat(), strchr(), strcmp(), strcpy(), strdup(), strlen()
Called by: GetModuleName()locate_module.c
  Locate_ModuleFile()locate_module.c
References Variables: _defaultmain.c
  g_current_modulemain.c
  modfil_buflocate_module.c
  module_namelocate_module.c
  modulerc_filemain.c

Local Function filename_compare()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		filename_compare				     **
 ** 									     **
 **   Description: 	This is a reverse compare function to reverse the    **
 **			filename list. The function is used as compare func- **
 **			tion for qsort.					     **
 ** 									     **
 **   First Edition:	91/10/23					     **
 ** 									     **
 **   Parameters:	const void	*fi1	First filename to compare    **
 **			const void	*fi2	Second filename to compare   **
 ** 									     **
 **   Result:		int	-1	filename 1 > filename 2		     **
 **				0	filename 1 == filename 2	     **
 **				1	filename 1 < filename 2		     **
 ** 									     **
 **   Attached Globals:							     **
 ** 									     **
 ** ************************************************************************ **
static int filename_compare ( const void* fi1, const void* fi2 )
Prototyped in: locate_module.c
Calls: strcmp()
Used in: SortedDirList()locate_module.c