Routines in File_rtn.c

The file contains the following routines:


DELETE_TMPFIL: Routine to delete a temporary output file

/************************************************************************/
/*																		*/
/*    DELETE_TMPFIL - Delete a temporary output file					*/
/*																		*/
/*    Calling Format:													*/
/*																		*/
/*		DELETE_TMPFIL (expfil_ptr);										*/
/*																		*/
/*    Where:															*/
/*																		*/
/*		expfil_ptr = Pointer to expanded file name returned				*/
/*				     by OPEN_TMPFIL										*/
/*																		*/
/*    This routine deletes the temporary version of the specified		*/
/*	  file name created by OPEN_TMPFIL.									*/
/*																		*/
/************************************************************************/

GET_IDXREC: Routine to read a record from an index file, allowing for comment characters, implicit links and nested files.

/************************************************************************/
/*																		*/
/*    GET_IDXREC - Read next valid record from an index file			*/
/*																		*/
/*    Calling Format:													*/
/*																		*/
/*		GET_IDXREC (inpbuf_ptr, buffer_size, file_ptr);					*/
/*																		*/
/*    Where:															*/
/*																		*/
/*		inpbuf_ptr  = Pointer to buffer for input record				*/
/*		buffer_size = Size of input buffer, including trailing null		*/
/*		file_ptr    = File pointer for file to be read from				*/
/*																		*/
/*    This routine is a shell around TXT_READ used specifically for		*/
/*	  index files that handles any special records in index files,		*/
/*	  including links to nested files.									*/
/*																		*/
/************************************************************************/

OPEN_APPEND: Routine to open an output file for append

/************************************************************************/
/*																		*/
/*    OPEN_APPEND - Open an output file in "append" mode				*/
/*																		*/
/*    Calling Format:													*/
/*																		*/
/*		file_ptr = OPEN_APPEND (filnam_ptr, relnam_ptr, expfil_ptr);	*/
/*																		*/
/*    Where:															*/
/*																		*/
/*		file_ptr   = Pointer to file handle for output file				*/
/*		filnam_ptr = Pointer to name of file to be opened				*/
/*		relnam_ptr = Pointer to name of related input file				*/
/*		expfil_ptr = Pointer to char[256] buffer to hold "expanded" name*/
/*																		*/
/*    This routine attempts to open the specified output file for		*/
/*	  input (thus resolving any environment variables) and, if that		*/
/*	  works, it closes the file and uses the expanded name to open		*/
/*	  it for append.													*/
/*																		*/
/*    The routine reports any errors encountered, and returns a NULL	*/
/*    pointer in this case; otherwise it logs a success	message.		*/
/*																		*/
/************************************************************************/

OPEN_INPUT: Routine to open an input file

/************************************************************************/
/*																		*/
/*    OPEN_INPUT - Open an input file									*/
/*																		*/
/*    Calling Format:													*/
/*																		*/
/*		file_ptr = OPEN_INPUT (filnam_ptr, envnam_ptr, expfil_ptr);		*/
/*																		*/
/*    Where:															*/
/*																		*/
/*	file_ptr   = Pointer to file handle for input file					*/
/*	filnam_ptr = Pointer to name of file to be opened					*/
/*	envnam_ptr = Pointer to name of environment variable for file		*/
/*				 if this starts with '@' then it means the file should	*/
/*				 ONLY be opened in the context of the following variable */
/*	expfil_ptr = Pointer to char[256] buffer to hold "expanded" name	*/
/*																		*/
/*    This routine attempts to open the specified input file via fopen.	*/
/*    It does so as follows:											*/
/*																		*/
/*    1. It tries to open *filnam_ptr with no disk/directory, unless	*/
/*		 the specified environment variable starts with an '@'.			*/
/*    2. If that fails it checks to see if a drive (:) was specified	*/
/*		 in the file name and, if so, exits with an error.				*/
/*    3. If not then it tries to translate the specified environment	*/
/*		 variable, after removing any leading '@', exiting with an		*/
/*		 error if it doesn't exist.										*/
/*    4. If then checks to see if the translated environment name ends	*/
/*		 in a '+' and, if not, exits with an error if the file name		*/
/*		 contains a directory (\).  If it does end in a '+' then the	*/
/*		 '+' is removed.												*/
/*    5. Else it adds a trailing ';' to the translated environment name	*/
/*		 (if one is needed) and prefixes each segment of the name to	*/
/*		 *filnam_ptr in turn, and attempts to open the result of each	*/
/*       as an input file, terminating when a file is opened or when	*/
/*	 	 there are no more segments.									*/
/*																		*/
/*    The routine reports any errors encountered, and returns a NULL	*/
/*    pointer in this case; otherwise it logs a success	message.		*/
/*																		*/
/************************************************************************/

OPEN_OUTPUT: Routine to open an output file

/************************************************************************/
/*																		*/
/*    OPEN_OUTPUT - Open an output file									*/
/*																		*/
/*    Calling Format:													*/
/*																		*/
/*		file_ptr = OPEN_OUTPUT (filnam_ptr, relnam_ptr, expfil_ptr);	*/
/*																		*/
/*    Where:															*/
/*																		*/
/*		file_ptr   = Pointer to file handle for output file				*/
/*		filnam_ptr = Pointer to name of file to be opened				*/
/*		relnam_ptr = Pointer to name of related input file				*/
/*		expfil_ptr = Pointer to char[256] buffer to hold "expanded" name*/
/*																		*/
/*    This routine attempts to open the specified output file via fopen.*/
/*    It builds up the file name from filnam_ptr and relnam_ptr as 		*/
/*    follows:															*/
/*																		*/
/*    1. If *filnam_ptr contains either device or directory, then the	*/
/*		 output file is created exactly as specified by *filnam_ptr.	*/
/*    2. Else, if *relnam_ptr contains either device or directory then	*/
/*		 the output file is created on/in that device/directory.		*/
/*    3. If the first character of *filnam_ptr is a ".", and it does	*/
/*       not contain a device or directory, then the file name is copied*/
/*		 from *relnam_ptr.												*/
/*    4. If the last character of *filnam_ptr is a ".", and it does		*/
/*       not contain a device or directory, then the "extension" is		*/
/*		 copied from *relnam_ptr.										*/
/*																		*/
/*    The routine reports any errors encountered, and returns a NULL	*/
/*    pointer in this case; otherwise it logs a success	message.		*/
/*																		*/
/************************************************************************/

OPEN_TMPFIL: Routine to open a temporary output file

/************************************************************************/
/*																		*/
/*    OPEN_TMPFIL - Open a temporary output file						*/
/*																		*/
/*    Calling Format:													*/
/*																		*/
/*		file_ptr = OPEN_TMPFIL (filnam_ptr, relnam_ptr, expfil_ptr);	*/
/*																		*/
/*    Where:															*/
/*																		*/
/*		file_ptr   = Pointer to file handle for output file				*/
/*		filnam_ptr = Pointer to name of file to be opened				*/
/*		relnam_ptr = Pointer to name of related input file				*/
/*		expfil_ptr = Pointer to char[256] buffer to hold "expanded" name*/
/*																		*/
/*    This routine is identical to OPEN_OUTPUT except that it replaces	*/
/*    the first character of the file name with "_" before opening the	*/
/*    file.  Note that the name returned is the "real" name, not the	*/
/*    one with the "_" inserted.										*/
/*																		*/
/*    The routine reports any errors encountered, and returns a NULL	*/
/*    pointer in this case; otherwise it logs a success	message.		*/
/*																		*/
/************************************************************************/

RENAME_TMPFIL: Routine to rename a temporary output file

/************************************************************************/
/*																		*/
/*    RENAME_TMPFIL - Rename a temporary output file					*/
/*																		*/
/*    Calling Format:													*/
/*																		*/
/*		RENAME_TMPFIL (expfil_ptr);										*/
/*																		*/
/*    Where:															*/
/*																		*/
/*		expfil_ptr = Pointer to expanded file name returned				*/
/*				     by OPEN_TMPFIL										*/
/*																		*/
/*    This routine backs up any file with the name *expfil_ptr, and		*/
/*    renames the temporary version created by OPEN_TMPFIL to that		*/
/*    name.																*/
/*																		*/
/*    The routine reports any errors encountered; otherwise it logs		*/
/*    a success message.												*/
/*																		*/
/************************************************************************/

TXT_READ: Routine to read a record from a text file, allowing for truncation and stripping off the trailing newline character.

/************************************************************************/
/*																		*/
/*    TXT_READ - Read a record from a text file							*/
/*																		*/
/*    Calling Format:													*/
/*																		*/
/*		rec_ptr = TXT_READ (inpbuf_ptr, buffer_size, file_ptr);			*/
/*																		*/
/*    Where:															*/
/*																		*/
/*		rec_ptr     = Pointer as returned by fgets						*/
/*		inpbuf_ptr  = Pointer to buffer for input record				*/
/*		buffer_size = Size of input buffer, including trailing null		*/
/*		file_ptr    = File pointer for file to be read from				*/
/*																		*/
/*    This routine is a shell around fgets that ensures that the buffer	*/
/*    is not over-ridden and which strips off any trailing newline		*/
/*    character.														*/
/*																		*/
/************************************************************************/

TXT_WRITE: Routine to write a record to a text file, adding a newline character at the end.

/************************************************************************/
/*																		*/
/*    TXT_WRITE - Write a record to a text file							*/
/*																		*/
/*    Calling Format:													*/
/*																		*/
/*		status = TXT_WRITE (outbuf_ptr, file_ptr);						*/
/*																		*/
/*    Where:															*/
/*																		*/
/*		status      = Status as returned by fputs						*/
/*		outbuf_ptr  = Pointer to output record to be written			*/
/*		file_ptr    = File pointer for file to write to					*/
/*																		*/
/*    This routine is a shell around fputs that adds a trailing newline	*/
/*    character to the record written.									*/
/*																		*/
/************************************************************************/