home *** CD-ROM | disk | FTP | other *** search
- /******************************************************************************
- *******************************************************************************
-
- Site: Western Michigan University Academic Computer Center
-
- System: Directory/File System Maintenance
-
- Program: maint
-
- Version=01 Level=00 01/24/92 Leonard J. Peirce
-
- Purpose: Search for a file in the current directory and return its
- location.
-
- Arguments: See individual routines
-
- External variables: See individual routines
-
- Maint external functions:
-
- Defined: file_locate, file_ptr_locate
-
- Called: prompt_getstr
-
- Files accessed: None
-
- Return codes: See individual routines
-
- Compiling instructions: See Makefile
-
- Linking instructions: See Makefile
-
- Other information: (C) Copyright 1992, Leonard J. Peirce
-
- ********************************************************************************
- *******************************************************************************/
-
- /******************************************************************************/
- /* */
- /* # I N C L U D E F I L E S */
- /* */
- /******************************************************************************/
-
- #ifdef ultrix
- #include <cursesX.h>
- #else
- #include <curses.h>
- #endif
- #include <ctype.h>
- #include "maint.h"
-
- /******************************************************************************/
- /* */
- /* # D E F I N E S */
- /* */
- /******************************************************************************/
-
- /******************************************************************************/
- /* */
- /* S T R U C T U R E S , U N I O N S , T Y P E D E F S */
- /* */
- /******************************************************************************/
-
- /******************************************************************************/
- /* */
- /* E X T E R N A L D E F I N I T I O N S & D E C L A R A T I O N S */
- /* */
- /******************************************************************************/
-
- extern int main_rows;
-
- extern void prompt_getstr();
-
- int file_locate(),
- file_search(),
- file_ptr_search();
-
- /******************************************************************************/
- /* */
- /* S T A T I C D E F I N I T I O N S & D E C L A R A T I O N S */
- /* */
- /******************************************************************************/
-
- /*******************************************************************************
- ********************************************************************************
-
- Function: file_locate
-
- Purpose: Get the filename prefix that is desired by the user and
- search for it.
-
- Global variables:
-
- Name Examine/Modify/Use/Read/Write
- ---- -----------------------------
- main_rows X
-
- Return Codes:
-
- Code Reason
- ---- ------
- file_search() return code from file_search
-
- ********************************************************************************
- *******************************************************************************/
-
- int file_locate(window,dirptr,num_file)
- /******* FORMAL PARAMETERS *******/
- WINDOW *window; /* where to read/write */
- ENT_DEF *dirptr; /* pointer to directory entry memory */
- short num_file; /* number of files in directory */
-
- { /*** file_locate ***/
- /******** LOCAL VARIABLES ********/
- char prefix[SPEC_MAX+1]; /* filename prefix read in */
-
-
- /* prompt and ye shall receive....... */
-
- prompt_getstr(window,"Search for: ",prefix,main_rows,SPEC_MAX);
-
- /* now search for the filename prefix in the directory entries */
-
- return(file_search(dirptr,prefix,num_file,strlen(prefix)));
-
- } /*** file_locate ***/
-
- /*******************************************************************************
- ********************************************************************************
-
- Function: file_search
-
- Purpose: Search for the filename prefix specified
-
- Global variables:
-
- Name Examine/Modify/Use/Read/Write
- ---- -----------------------------
- none
-
- Return Codes:
-
- Code Reason
- ---- ------
- i number of file in directory
- -1 file prefix not found in directory
-
- ********************************************************************************
- *******************************************************************************/
-
- int file_search(dirptr,prefix,num_file,length)
- /******* FORMAL PARAMETERS *******/
- register ENT_DEF *dirptr; /* pointer to directory entries */
- register char *prefix; /* filename prefix to find */
- register short num_file; /* number of files in directory */
- int length; /* length of prefix string */
-
- { /*** file_search ***/
- /******** LOCAL VARIABLES ********/
- register short i = 0; /* loop index and file entry counter */
- short done = 0; /* loop control flag */
-
-
- /* search from the beginning for the filename prefix until 1) we find
- * what we are looking for or 2) we run out of files; when we exit the
- * loop we look at why we exited to see if we found the file or not
- */
-
- while((i < num_file) && (!done))
- {
- if(!strncmp(dirptr->filename,prefix,length))
- done++; /* we found it; stop searching.... */
- else
- {
- ++i; /* count this file entry */
- ++dirptr; /* go to next file entry */
- }
- }
-
- /* did we find what we were looking for? */
-
- if(i == num_file) /* did we find the filename prefix? */
- i = -1; /* nope..... */
-
- return((int) i); /* say whether or not we found it... */
-
- } /*** file_search ***/
-
- /*******************************************************************************
- ********************************************************************************
-
- Function: file_ptr_search
-
- Purpose: Search for the filename by comparing pointers to the
- memory in the memory pool holding the memory.
-
- Global variables:
-
- Name Examine/Modify/Use/Read/Write
- ---- -----------------------------
- none
-
- Return Codes:
-
- Code Reason
- ---- ------
- i number of file in directory
- -1 file prefix not found in directory
-
- ********************************************************************************
- *******************************************************************************/
-
- int file_ptr_search(dirptr,filename,num_file)
- /******* FORMAL PARAMETERS *******/
- register ENT_DEF *dirptr; /* pointer to directory entries */
- register char *filename; /* pointer to memory holding filename */
- register short num_file; /* number of files in directory */
-
- { /*** file_ptr_search ***/
- /******** LOCAL VARIABLES ********/
- register short i = 0; /* loop index and file entry counter */
- short done = 0; /* loop control flag */
-
-
- /* search from the beginning for the filename pointer until 1) we find
- * what we are looking for or 2) we run out of files; when we exit the
- * loop we look at why we exited to see if we found the file or not
- */
-
- while((i < num_file) && (!done))
- {
- if(dirptr->filename == filename)
- done++; /* we found it; stop searching.... */
- else
- {
- ++i; /* count this file entry */
- ++dirptr; /* go to next file entry */
- }
- }
-
- /* did we find what we were looking for? */
-
- if(i == num_file) /* did we find the filename prefix? */
- i = -1; /* nope..... */
-
- return((int) i); /* say whether or not we found it... */
-
- } /*** file_ptr_search ***/
-