** ** Module Header ******************************************************* **
** **
** Modules Revision 3.0 **
** Providing a flexible user environment **
** **
** File: ModuleCmd_Avail.c **
** First Edition: 91/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: **
** **
** ************************************************************************ **
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 DIREST 50
#define CACHE_VERSION "v3.0.0"
#define CACHE_UMASK 0
#define FILE_LIST_SEGM_SIZE 100
typedef struct _subdir_node sd_node
struct _subdir_node |
|
{ |
|
fi_ent* sd_dir; |
|
struct _subdir_node* sd_next; |
|
} |
|
char long_header[]
Local Variables
Id
static char Id[]
UseId
static void* UseId[]
namebuf
static char* namebuf
buf
static char buf[8192]
module_name
static char module_name[]
short_format
static char short_format[]
short_format_part
static char short_format_part[]
short_format_full
static char short_format_full[]
long_format
static char long_format[]
_file_list_buffer
static char _file_list_buffer[200]
_file_list_ptr
static char** _file_list_ptr
_file_list_cnt
static int _file_list_cnt
_file_list_wr_ndx
static int _file_list_wr_ndx
_file_list_rd_ndx
static int _file_list_rd_ndx
** ** Function-Header ***************************************************** **
** **
** Function: ModuleCmd_Avail **
** **
** Description: Execution of the 'module avail' command **
** **
** First Edition: 91/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: specified_module The module name from the **
** command line. **
** **
** ************************************************************************ **
int ModuleCmd_Avail ( Tcl_Interp* interp, int argc, char* argv[] )
** ** 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: 91/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 )
** ** Function-Header ***************************************************** **
** **
** Function: delete_cache_list **
** **
** Description: Remove an entire list of allocated strings and free **
** up the used memory **
** **
** First Edition: 91/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 )
** ** Function-Header ***************************************************** **
** **
** Function: delete_dirlst **
** **
** Description: Delete an entire directory list including all sub- **
** directory lists **
** **
** First Edition: 91/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 )
** ** Function-Header ***************************************************** **
** **
** Function: dirlst_to_list **
** **
** Description: Transform the passed nested directory list into a **
** flat list of strings **
** **
** First Edition: 91/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 )
** ** Function-Header ***************************************************** **
** **
** Function: get_dir **
** **
** Description: Read in the passed directory and save every interes- **
** ting item in the directory list **
** **
** First Edition: 91/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 )
** ** 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: 91/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
|
| 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
|
static void _add_file_list ( char* name )
static char* _get_file_list ( void )
** ** 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: 91/10/23 **
** **
** Parameters: char *name Name to be stored **
** **
** Result: - **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
static void _init_file_list ( void )
static char* _pick_file_list ( int ndx )
** ** Function-Header ***************************************************** **
** **
** Function: check_cache **
** **
** Description: Check whether an avail cache exists and is not out **
** of date **
** **
** First Edition: 96/01/03 **
** **
** Parameters: char *dir Directory to be checked **
** **
** Result: int 0 Do not use the cache **
** 1 Use the cache **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
static int check_cache ( char* dir )
** ** Function-Header ***************************************************** **
** **
** Function: create_cache_list **
** **
** Description: Read the passed cache-file and create a list of file-**
** names out of it **
** **
** First Edition: 91/10/23 **
** **
** Parameters: FILE *cacheinput Opened cache file **
** int *count Buffer to save the number of **
** filename to **
** char *module A module pattern ... **
** **
** Result: char** NULL Abort on failure **
** else Pointer to the just created **
** list **
** *count Number of elements in the **
** list **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
static char** create_cache_list ( FILE* cacheinput, int* count, char* module )
** ** 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: 91/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 )
** ** Function-Header ***************************************************** **
** **
** Function: mkdirnm **
** **
** Description: Build a full pathname out of the passed directory **
** and file **
** **
** First Edition: 91/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 )
** ** Function-Header ***************************************************** **
** **
** Function: print_dir **
** **
** Description: Print all files beyond the passed directory **
** **
** First Edition: 91/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 )
** ** 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: 91/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 )
** ** Function-Header ***************************************************** **
** **
** Function: print_terse_files **
** **
** Description: Print out the filenames in the _file_list array in **
** case of terse output **
** **
** First Edition: 91/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 )
** ** Function-Header ***************************************************** **
** **
** Function: store_dirlst **
** **
** Description: Write the contents of a cache file **
** **
** First Edition: 91/10/23 **
** **
** Parameters: FILE *cacheoutput Output stream to be used **
** FILE *cacheinfo Cache log file to be written **
** fi_ent *dirlist_head List of files to be printed **
** int count Number of entries in the pas-**
** sed 'dirlist' **
** Result: - **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
static void store_dirlst ( FILE* cacheinfo, FILE* cacheoutput, fi_ent* dirlst_head, int count, char* dir )
** ** Function-Header ***************************************************** **
** **
** Function: store_file **
** **
** Description: Store the name of the file passed as 'file entry' to **
** the specified output stream if it isn't a temp file **
** **
** First Edition: 91/10/23 **
** **
** Parameters: FILE *cacheoutput Output stream to be used **
** char *dir The current directory **
** fi_ent *file According file **
** **
** Result: - **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
static void store_file ( FILE* cacheoutput, char* dir, fi_ent* file )
** ** Function-Header ***************************************************** **
** **
** Function: store_files **
** **
** Description: Write a cache file using the given directory list **
** **
** First Edition: 91/10/23 **
** **
** Parameters: fi_ent *dirlist_head List of files to be printed **
** int count Number of entries in the pas-**
** sed 'dirlist' **
** int tcount Number of entries to write to**
** the cache file. This id the **
** total number of files stores **
** in the nested directory lists**
** char *dir The current directory **
** **
** Result: - **
** **
** Attached Globals: - **
** **
** ************************************************************************ **
static void store_files ( fi_ent* dirlst_head, int count, int tcount, char* dir )