** ** 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: **
** **
** ************************************************************************ **
Included Files
- #include "modules_def.h"
- #include <stdio.h>
- #include <tcl.h>
- #include "config.h"
- #include <stdlib.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <ctype.h>
- #include <sys/stat.h>
- #include <sys/termios.h>
- #include <fcntl.h>
- #include <sys/ioctl.h>
- #include <dirent.h>
- #include <errno.h>
Preprocessor definitions
#define SRCFRAG 100
Local Variables
Id
static char Id[]
UseId
static void* UseId[]
module_name
static char module_name[]
buf
static char buf[1024]
modfil_buf
static char modfil_buf[1024]
** ** 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 )
** ** 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_name | locate_module.c
|
** ** 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 )
** ** 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 )
** ** 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 )
** ** 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 )
** ** 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 )