File ModuleCmd_Avail.c

 ** ** Module Header ******************************************************* **
 ** 									     **
 **   Modules Revision 3.0						     **
 **   Providing a flexible user environment				     **
 ** 									     **
 **   File:		Modulate_Avail.c				     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Authors:	John Furlan, jlf@behere.com				     **
 **		Jens Hamisch, jens@Strawberry.COM			     **
 ** 									     **
 **   Description: 	This module command prints out the modulefiles that  **
 **			are available in the directories listed in the	     **
 **			MODULEPATH environment variable.		     **
 ** 									     **
 **   Exports:		ModuleCmd_Avail					     **
 **			print_aligned_files				     **
 **			check_dir					     **
 **			get_dir						     **
 **			dirlst_to_list					     **
 **			delete_dirlst					     **
 **			delete_cache_list				     **
 ** 									     **
 **   Notes:								     **
 ** 									     **
 ** ************************************************************************ **
References Variables: Id ModuleCmd_Avail.c

Included Files


Preprocessor definitions

#define DIREST 50

#define CACHE_VERSION "v3.0.0"

#define CACHE_UMASK 0

#define FILE_LIST_SEGM_SIZE 100


Typedef sd_node

typedef struct _subdir_node sd_node
struct _subdir_node  
   {  
      fi_ent* sd_dir;  
      struct _subdir_node* sd_next;  
   }  

Global Variable long_header

char long_header[]
Visible in:   ModuleCmd_Avail.c
    ModuleCmd_Bootstrap.c
    ModuleCmd_Clear.c
    ModuleCmd_Display.c
    ModuleCmd_Help.c
    ModuleCmd_Init.c
    ModuleCmd_List.c
    ModuleCmd_Load.c
    ModuleCmd_Purge.c
    ModuleCmd_Refresh.c
    ModuleCmd_Switch.c
    ModuleCmd_Update.c
    ModuleCmd_Use.c
    ModuleCmd_Whatis.c
    cmdAlias.c
    cmdConflict.c
    cmdInfo.c
    cmdIsLoaded.c
    cmdLog.c
    cmdMisc.c
    cmdModule.c
    cmdPath.c
    cmdSetenv.c
    cmdTrace.c
    cmdUlvl.c
    cmdUname.c
    cmdVerbose.c
    cmdVersion.c
    cmdWhatis.c
    cmdXResource.c
    error.c
    getopt.c
    init.c
    locate_module.c
    main.c
    modules_def.h
    utility.c
Used in: ModuleCmd_Avail() ModuleCmd_Avail.c
  ModuleCmd_List() ModuleCmd_List.c

Local Variables

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

UseId
static void* UseId[]

buffer
static char buffer[1024]

Used in: get_dir()  

buf
static char buf[8192]

Used in: dirlst_to_list()  

module_name
static char module_name[]

Used in: ModuleCmd_Avail()  
  _add_file_list()  
  check_dir()  
  dirlst_to_list()  
  get_dir()  
  mkdirnm()  
  print_aligned_files()  
  print_dir()  

short_format
static char short_format[]

Used in: print_aligned_files()  

short_format_part
static char short_format_part[]

Used in: print_aligned_files()  

short_format_full
static char short_format_full[]

Used in: print_aligned_files()  

long_format
static char long_format[]

Used in: print_aligned_files()  

_file_list_buffer
static char _file_list_buffer[200]

Used in: print_aligned_files()  

_file_list_ptr
static char** _file_list_ptr

Used in: _add_file_list()  
  _get_file_list()  
  _init_file_list()  
  _pick_file_list()  

_file_list_cnt
static int _file_list_cnt

Used in: _add_file_list()  
  _init_file_list()  

_file_list_wr_ndx
static int _file_list_wr_ndx

Used in: _add_file_list()  
  _get_file_list()  
  _init_file_list()  
  _pick_file_list()  
  print_aligned_files()  
  print_terse_files()  

_file_list_rd_ndx
static int _file_list_rd_ndx

Used in: _add_file_list()  
  _get_file_list()  
  _init_file_list()  

Global Function ModuleCmd_Avail()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		ModuleCmd_Avail					     **
 ** 									     **
 **   Description:	Execution of the 'module avail' command		     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	Tcl_Interp	*interp		Current Tcl Interpr. **
 **			char		*argv[]		Arguments to the     **
 **							command		     **
 ** 									     **
 **   Result:		int	TCL_OK		Successfull operation	     **
 **				TCL_ERROR	Any failure		     **
 ** 									     **
 **   Attached Globals:	g_specified_module	The module name from the     **
 **						command line.		     **
 ** 									     **
 ** ************************************************************************ **
int ModuleCmd_Avail ( Tcl_Interp* interp, int argc, char* argv[] )
Prototyped in: modules_def.h
Calls: Module_Error() error.c
  check_dir() ModuleCmd_Avail.c
  null_free() utility.c
  print_dir() ModuleCmd_Avail.c
  xgetenv() utility.c
  fprintf(), strchr()
Called by: cmdModule() cmdModule.c
References Variables: g_specified_module main.c
  long_header ModuleCmd_Avail.c
  module_name ModuleCmd_Avail.c
  sw_format main.c

Global Function check_dir()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		check_dir					     **
 ** 									     **
 **   Description:	Open and close the passed directory in order to check**
 **			if it does exist and is readable		     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	char	*dirname	Name of the directory to be  **
 **						checked			     **
 ** 									     **
 **   Result:		int	0	Not a directory or unreadable	     **
 **				1	OK				     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
int check_dir ( char* dirname )
Prototyped in: modules_def.h
Calls: Module_Error() error.c
  closedir(), opendir()
Called by: ModuleCmd_Apropos() ModuleCmd_Whatis.c
  ModuleCmd_Avail() ModuleCmd_Avail.c
  ModuleCmd_Whatis() ModuleCmd_Whatis.c
References Variables: module_name ModuleCmd_Avail.c

Global Function delete_cache_list()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		delete_cache_list				     **
 ** 									     **
 **   Description:	Remove an entire list of allocated strings and free  **
 **			up the used memory				     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	char	**list		List of filenames to be print**
 **			int	  tcount	Size ofd the list in elements**
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
void delete_cache_list ( char** list, int tcount )
Prototyped in: modules_def.h
Calls: null_free() utility.c
Called by: print_dir() ModuleCmd_Avail.c
  whatis_dir() ModuleCmd_Whatis.c

Global Function delete_dirlst()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		delete_dirlst					     **
 ** 									     **
 **   Description:	Delete an entire directory list including all sub-   **
 **			directory lists					     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	fi_ent	*dirlst_head	Head of the list to be re-   **
 **						moved			     **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
void delete_dirlst ( fi_ent* dirlst_head, int count )
Prototyped in: modules_def.h
Calls: delete_dirlst() ModuleCmd_Avail.c
  null_free() utility.c
Called by: delete_dirlst() ModuleCmd_Avail.c
  print_dir() ModuleCmd_Avail.c
  whatis_dir() ModuleCmd_Whatis.c

Global Function dirlst_to_list()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		dirlst_to_list					     **
 ** 									     **
 **   Description:	Transform the passed nested directory list into a    **
 **			flat list of strings				     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	char	**list		List to be created	     **
 **			fi_ent	 *dirlst_head	Head of the directory list   **
 **						to be transformed	     **
 **			int	  count		Number of elements in the    **
 **						directory list		     **
 **			int	 *beginning	Index of the element in List **
 **						to start appending the file- **
 **						names at.		     **
 **			char	 *path		prepend pathname to list     **
 **			char	 *module	A search pattern	     **
 **									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
void dirlst_to_list ( char** list, fi_ent* dirlst_head, int count, int* beginning, char* path, char* module )
Prototyped in: modules_def.h
Calls: Module_Error() error.c
  dirlst_to_list() ModuleCmd_Avail.c
  null_free() utility.c
  stringer() utility.c
  strdup(), strlen(), strncmp()
Called by: dirlst_to_list() ModuleCmd_Avail.c
  print_dir() ModuleCmd_Avail.c
  whatis_dir() ModuleCmd_Whatis.c
References Variables: buf ModuleCmd_Avail.c
  module_name ModuleCmd_Avail.c

Global Function get_dir()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		get_dir						     **
 ** 									     **
 **   Description:	Read in the passed directory and save every interes- **
 **			ting item in the directory list			     **
 **			skipping known version control directories:	     **
 **				CVS RCS .svn				     **
 **			unless they contain .version files		     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	char	*dir		Directory to be read	     **
 **			char	*prefix		Directory prefix (path)	     **
 **			int	*listcount	Buffer to store the number of**
 **						elements in the current      **
 **						directory list		     **
 **			int 	*total_count	Buffer for the total number  **
 **						of files read		     **
 ** 									     **
 **   Result:		fi_ent*		NULL	Failure			     **
 **					else	Directory list base pointer  **
 **			*listcount		Number of elements in the    **
 **						top level directory list     **
 **			*total_count		Total number of files read   **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
fi_ent* get_dir ( char* dir, char* prefix, int* listcount, int* total_count )
Prototyped in: modules_def.h
Calls: Module_Error() error.c
  check_magic() utility.c
  get_dir() ModuleCmd_Avail.c
  mkdirnm() ModuleCmd_Avail.c
  null_free() utility.c
  stringer() utility.c
  calloc(), closedir(), fclose(), fopen(), opendir(), qsort(), readdir(), realloc(), stat(), strcmp(), strdup(), strlen()
Called by: get_dir() ModuleCmd_Avail.c
  print_dir() ModuleCmd_Avail.c
  whatis_dir() ModuleCmd_Whatis.c
References Functions: fi_ent_cmp() ModuleCmd_Avail.c
References Variables: buffer ModuleCmd_Avail.c
  module_name ModuleCmd_Avail.c

Global Function print_aligned_files()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		print_aligned_files				     **
 ** 									     **
 **   Description:	Print out the filenames passed in a sorted array     **
 **			column by column taking care of the order being re-  **
 **			flected to the single columns			     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	char	**list		List of filenames to print   **
 **			char	 *path		common path		     **
 **			char	 *header	List header		     **
 **			int	  tcount	Size of the list in elements **
 **			int	  numbered	Controls printing of numbers **
 ** 						set to -1 for none	     **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	g_current_module	The module which is handled  **
 **						by the current command	     **
 ** 									     **
 ** ************************************************************************ **
void print_aligned_files ( Tcl_Interp* interp, char* path, char* header, char** list, int tcount, int numbered )
Prototyped in: modules_def.h
Calls: ExpandVersions() cmdVersion.c
  Locate_ModuleFile() locate_module.c
  Module_Error() error.c
  SourceRC() locate_module.c
  SourceVers() locate_module.c
  _add_file_list() ModuleCmd_Avail.c
  _init_file_list() ModuleCmd_Avail.c
  null_free() utility.c
  print_terse_files() ModuleCmd_Avail.c
  xgetenv() utility.c
  fileno(), fprintf(), gmtime(), ioctl(), isatty(), sprintf(), stat(), strchr(), strdup(), strlen(), strncmp(), strrchr()
Called by: ModuleCmd_List() ModuleCmd_List.c
  print_dir() ModuleCmd_Avail.c
References Variables: _file_list_buffer ModuleCmd_Avail.c
  _file_list_wr_ndx ModuleCmd_Avail.c
  g_current_module main.c
  long_format ModuleCmd_Avail.c
  module_name ModuleCmd_Avail.c
  modulerc_file main.c
  short_format ModuleCmd_Avail.c
  short_format_full ModuleCmd_Avail.c
  short_format_part ModuleCmd_Avail.c
  sw_format main.c

Local Function _add_file_list()

static void _add_file_list ( char* name )
Prototyped in: ModuleCmd_Avail.c
Calls: Module_Error() error.c
  malloc(), realloc(), strdup()
Called by: print_aligned_files() ModuleCmd_Avail.c
References Variables: _file_list_cnt ModuleCmd_Avail.c
  _file_list_ptr ModuleCmd_Avail.c
  _file_list_rd_ndx ModuleCmd_Avail.c
  _file_list_wr_ndx ModuleCmd_Avail.c
  module_name ModuleCmd_Avail.c

Local Function _get_file_list()

static char* _get_file_list ( void )
Prototyped in: ModuleCmd_Avail.c
Called by: print_terse_files() ModuleCmd_Avail.c
References Variables: _file_list_ptr ModuleCmd_Avail.c
  _file_list_rd_ndx ModuleCmd_Avail.c
  _file_list_wr_ndx ModuleCmd_Avail.c

Local Function _init_file_list()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		_add_file_list   				     **
 **			_init_file_list					     **
 **			_get_file_list					     **
 **			_pick_file_list					     **
 ** 									     **
 **   Description:	File list functions for terse module display mode    **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	char	*name		Name to be stored	     **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
static void _init_file_list ( void )
Prototyped in: ModuleCmd_Avail.c
Calls: null_free() utility.c
Called by: print_aligned_files() ModuleCmd_Avail.c
References Variables: _file_list_cnt ModuleCmd_Avail.c
  _file_list_ptr ModuleCmd_Avail.c
  _file_list_rd_ndx ModuleCmd_Avail.c
  _file_list_wr_ndx ModuleCmd_Avail.c

Local Function _pick_file_list()

static char* _pick_file_list ( int ndx )
Prototyped in: ModuleCmd_Avail.c
Called by: print_terse_files() ModuleCmd_Avail.c
References Variables: _file_list_ptr ModuleCmd_Avail.c
  _file_list_wr_ndx ModuleCmd_Avail.c

Local Function fi_ent_cmp()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		fi_ent_cmp					     **
 ** 									     **
 **   Description:	compares two file entry structures		     **
 **			Different cmdline arguments (i.e. -u, -c, -t, -z)    **
 **			will change what value is compared. As a default,    **
 **			the name is used.				     **
 **									     **
 **   Notes:		This procedure is used as comparison function for    **
 **			qsort()					 	     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	const void *fi1		First file entry	     **
 **			const void *fi2		Second one to compare	     **
 ** 									     **
 **   Result:		int	1 	fi2 > fi1			     **
 **    				-1	fi2 < fi1			     **
 **	  			0	fi2 == fi1			     **
 ** 									     **
 **   Attached Globals:							     **
 ** 									     **
 ** ************************************************************************ **
static int fi_ent_cmp ( const void* fi1, const void* fi2 )
Prototyped in: ModuleCmd_Avail.c
Calls: strcmp()
Used in: get_dir() ModuleCmd_Avail.c

Local Function mkdirnm()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		mkdirnm						     **
 ** 									     **
 **   Description:	Build a full pathname out of the passed directory    **
 **			and file					     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	char	*dir		The directory to be used     **
 **			char	*file		The filename w/o path	     **
 ** 									     **
 **   Result:		char*	NULL		Compound filename to long    **
 **				else		Pointer to the full path     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
static char* mkdirnm ( char* dir, char* file )
Prototyped in: ModuleCmd_Avail.c
Calls: Module_Error() error.c
  strcat(), strcmp(), strcpy(), strlen()
Called by: get_dir() ModuleCmd_Avail.c
References Variables: module_name ModuleCmd_Avail.c

Local Function print_dir()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		print_dir					     **
 ** 									     **
 **   Description:	Print all files beyond the passed directory	     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	char	*dir		Directory to be scanned	     **
 **			char	*module		A selcted module name or NULL**
 ** 									     **
 **   Result:		int	TCL_OK		Successfull operation	     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
static int print_dir ( Tcl_Interp* interp, char* dir, char* module )
Prototyped in: ModuleCmd_Avail.c
Calls: Module_Error() error.c
  SourceRC() locate_module.c
  SourceVers() locate_module.c
  delete_cache_list() ModuleCmd_Avail.c
  delete_dirlst() ModuleCmd_Avail.c
  dirlst_to_list() ModuleCmd_Avail.c
  get_dir() ModuleCmd_Avail.c
  null_free() utility.c
  print_aligned_files() ModuleCmd_Avail.c
  stringer() utility.c
  fprintf(), malloc(), memset(), strchr(), strlen()
Called by: ModuleCmd_Avail() ModuleCmd_Avail.c
References Variables: module_name ModuleCmd_Avail.c
  modulerc_file main.c
  sw_format main.c

Local Function print_spaced_file()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		print_spaced_file				     **
 ** 									     **
 **   Description:	Print out the passed filename and fill the output    **
 **			area up to the passed number of characters	     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	char	*name		Name to be printed	     **
 **			int	 maxwidth	With of the output field to  **
 **						be filled up		     **
 **			int	 space		Boolean value controlling if **
 **						the output area should be    **
 **						filled up with spaces or not **
 **			int	 number		value to start number list   **
 ** 						use -1 for none		     **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
static void print_spaced_file ( char* name, int maxwidth, int space, int number )
Prototyped in: ModuleCmd_Avail.c
Calls: chk4spch() utility.c
  _IO_putc(), fprintf(), strlen()
Called by: print_terse_files() ModuleCmd_Avail.c

Local Function print_terse_files()

 ** ** Function-Header ***************************************************** **
 ** 									     **
 **   Function:		print_terse_files				     **
 ** 									     **
 **   Description:	Print out the filenames in the _file_list array in   **
 **			case of terse output 				     **
 ** 									     **
 **   First Edition:	1991/10/23					     **
 ** 									     **
 **   Parameters:	int	  terminal_width	Terminal size	     **
 **			int	  len			max. filename length **
 **			char	 *header		header to print	     **
 **			int	  number		value to start number**
 ** 							use -1 for none	     **
 ** 									     **
 **   Result:		-						     **
 ** 									     **
 **   Attached Globals:	-						     **
 ** 									     **
 ** ************************************************************************ **
static void print_terse_files ( int terminal_width, int len, char* header, int numbered )
Prototyped in: ModuleCmd_Avail.c
Calls: _get_file_list() ModuleCmd_Avail.c
  _pick_file_list() ModuleCmd_Avail.c
  print_spaced_file() ModuleCmd_Avail.c
  fprintf(), strlen()
Called by: print_aligned_files() ModuleCmd_Avail.c
References Variables: _file_list_wr_ndx ModuleCmd_Avail.c
  sw_format main.c

Local Function test_version_dir()

static int test_version_dir ( struct dirent* dp )