diff --git a/src/bot/crname.c b/src/bot/crname.c index b376ab6..3a0fdc3 100755 --- a/src/bot/crname.c +++ b/src/bot/crname.c @@ -1,58 +1,60 @@ +/** + * @file crname.c + * + * @brief Create a pathname piece by piece + */ + #include #include #include #include -#include "../../inc/complex.h" -#include "../../inc/proto.h" -#include "../../inc/mach.h" -void /*FUNCTION*/ crname(kname, kname_s, kdelim, kappnd, kappnd_s, - nerr) -char *kname; int kname_s; -byte kdelim; -char *kappnd; int kappnd_s; -long int *nerr; +#include "complex.h" +#include "proto.h" +#include "mach.h" + +/** + * Create a pathname piece by piece + * + * @param kname + * Current name to build upon + * @param kname_s + * The maximum allowable size of \p kname (incluing the trailing '\0') + * @param kdelim + * Delimiter to put before next part + * @param kappnd + * New part of path name to append to current name + * @param kappnd_s + * The maximum allowable size of \p kappnd (incluing the trailing '\0') + * @param nerr + * Error return flag. Set to 0 if no error occurred. + * + * @return Nothing + * + * @date 831110 Original version. + */ +void crname(kname, kname_s, kdelim, kappnd, kappnd_s, nerr) + char *kname; + int kname_s; + byte kdelim; + char *kappnd; + int kappnd_s; + long int *nerr; { - long int mname, nappnd, nname; + long int mname; ///< Maximum length of \p kname + long int nappnd; ///< Length of \p kappnd + long int nname; ///< Current length of \p kname char *cattemp; byte delimtemp; - /*===================================================================== - * PURPOSE: To create a pathname piece by piece. - *===================================================================== - * INPUT ARGUMENTS: - * KNAME: Current name to build upon. [c] - * KDELIM: Delimiter to put before next part. [c1] - * KAPPND: New part of path name to append to current name. [c] - *===================================================================== - * OUTPUT ARGUMENTS: - * KNAME: Concantenation of current name, delimiter, and new name. [c] - * NERR: Error return flag. Set to 0 if no error occurred. - *===================================================================== - * MODULE/LEVEL: SERVICE/4 - *===================================================================== - * GLOBAL INPUT: - * MACH: - *===================================================================== - * SUBROUTINES CALLED: - * SACLIB: INDEXB - *===================================================================== - * LOCAL VARIABLES: - * MNAME: Maximum length of KNAME. [i] - * NNAME: Current length of KNAME. [i] - * NAPPND: Length of KAPPND. [i] - *===================================================================== */ - /* PROCEDURE: */ *nerr = 0; - /* - Determine length of base and additional name. */ - + /* Determine length of base and additional name. */ mname = (kname_s - 1); nname = indexb( kname,kname_s ); nappnd = indexb( kappnd,kappnd_s ); - /* - Concantenate delimiter and new name to base name if they fit. */ - + /* Concantenate delimiter and new name to base name if they fit. */ if( mname >= (nname + nappnd + 1) ){ cattemp = malloc(nappnd+2); cattemp[0] = kdelim; @@ -60,8 +62,7 @@ long int *nerr; cattemp[nappnd+1] = '\0'; subscpy( kname, nname, -1, kname_s - 1, cattemp); free(cattemp); - } - else{ + } else { *nerr = 916; setmsg( "ERROR", *nerr ); apcmsg2(kname,nname); @@ -69,15 +70,5 @@ long int *nerr; apcmsg( &delimtemp, 1 ); apcmsg2(kappnd,nappnd); } - -L_8888: - - return; - - /*===================================================================== - * MODIFICATION HISTORY: - * 831110: Original version. - *===================================================================== */ - -} /* end of function */ +} diff --git a/src/co/zbasename.c b/src/co/zbasename.c index 0ab9624..77e1ebc 100755 --- a/src/co/zbasename.c +++ b/src/co/zbasename.c @@ -1,42 +1,45 @@ -/* -CDOC -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - - *** Function: zbasename_(name,name_len) - - *** Purpose: To return the name of the SAC base directory on a machine. - - *** Returns: The expanded base name. - - *** Notes: This program is designed to be called from a f77 routine. - - *** History: 04/19/87 Original version based upon zexpnd. - 04/22/87 Modified to blank fill returned base name. - 02/02/88 Modified to exit if SACAUX is not defined. - -!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -CEND -*/ +/** + * @file zbasename.c + * + * @brief Return the directory specified by environment variable SACAUX + */ #include #include #include -extern char *getenv(); - - -zbasename(name,name_len) -char name[]; -long name_len; - +/** + * Return the directory specified by environment variable SACAUX + * + * @param name + * Output directory name + * @param name_len + * The maximum length of \p name + * + * @return Nothing + * + * @note + * This program is designed to be called from a f77 routine. + * + * @date 04/19/87 Original version based upon zexpnd. + * @date 04/22/87 Modified to blank fill returned base name. + * @date 02/02/88 Modified to exit if SACAUX is not defined. + */ +void zbasename(name, name_len) + char name[]; + long name_len; { - char *temp; long i; - if ((temp = getenv("SACAUX")) != NULL) - strcpy(name,temp); - else { + if ((temp = getenv("SACAUX")) != NULL) { + if (strlen(temp) > name_len - 1) { + fprintf(stderr, "%s:%s: name_len = %ld is not large enough.\n", + __FILE__, __LINE__, name_len); + exit(1); + } + strcpy(name, temp); + } else { fprintf(stderr, "ERROR: Environmental variable SACAUX not defined.\n"); exit(1); } @@ -45,8 +48,5 @@ long name_len; name[i]=' '; name[name_len-1] = '\0'; - - return; } - diff --git a/src/co/zinquire.c b/src/co/zinquire.c index 0351b86..be7a852 100755 --- a/src/co/zinquire.c +++ b/src/co/zinquire.c @@ -1,42 +1,40 @@ +/** + * @file zinquire.c + * + * @brief To inquire about the existence of a disk file + */ + #include #include #include #include -#include "../../inc/complex.h" -#include "../../inc/proto.h" -void /*FUNCTION*/ zinquire(kname, lexist) -char *kname; -long *lexist; + +#include "complex.h" +#include "proto.h" + +/** + * To inquire about the existence of a disk file. + * + * @param kname + * Name of disk file to inquire about + * @param lexist + * Set to TRUE if file exists, FALSE otherwise. + * + * @return Nothing + * + * @date 871222 Original version. + */ +void zinquire(kname, lexist) + char *kname; + long *lexist; { char *nkname, *tok; - /*===================================================================== - * PURPOSE: To inquire about the existence of a disk file. - *===================================================================== - * INPUT ARGUMENTS: - * kname: Name of disk file. [c] - *===================================================================== - * OUTPUT ARGUMENTS: - * lexist: Set to .TRUE. if file exists, .FALSE. otherwise. [l] - *===================================================================== - * MODULE/LEVEL: co/5 - *===================================================================== - * MODIFICATION HISTORY: - * 871222: Original version. - *===================================================================== - * DOCUMENTED/REVIEWED: 871222 - *===================================================================== */ - /* PROCEDURE: */ /* - Check existance of file. */ - strcpy((nkname=malloc(strlen(kname)+1)),kname); tok = strtok(nkname," \0"); *lexist = !access(tok, 0 ); free(nkname); - -L_8888: - return; - -} /* end of function */ +} diff --git a/src/co/zopen.c b/src/co/zopen.c index ec8603a..5d1ff89 100755 --- a/src/co/zopen.c +++ b/src/co/zopen.c @@ -1,17 +1,66 @@ +/** + * @file zopen.c + * + * @brief Open an existing disk file + */ + #include #include #include #include + #include "complex.h" #include "proto.h" -#include -#define MRECLB 512 - #include "mach.h" -void /*FUNCTION*/ zopen_sac(nfu, kname, kname_s, ktype, ktype_s, nerr) -long int *nfu; -char *kname; int kname_s; -char *ktype; int ktype_s; + + +/** + * Open an existing disk file + * + * @param nfu + * address to store the file descriptor + * @param kname + * name of disk file to open + * @param kname_s + * The maximum allowable size of \p kname (incluing the trailing '\0') + * @param ktype + * Type of disk file to open [k]: + * = 'DATA' for unformatted, direct-access file. + * = 'RODATA' for read-only DATA file. + * = 'ROUNFR' for read-only FORTRAN unformatted file. + * = 'TEXT' for formatted sequential-access file. + * = 'ROTEXT' or 'READ' for read-only TEXT file. + * = 'SCRATCH' for temporary file 'tmp...' that gets + * deleted when the file is closed. + * @param ktype_s + * The maximum allowable size of \p ktype (incluing the trailing '\0') + * @param nerr + * Error return flag. Set to zero if no error. + * Possible error numbers from this call: + * 108 - File does not exist. + * 101 - System error occurred during open. + * + * @return Nothing + * + * @date 920805 Added 'ROUNFR' option. + * @date 920319 Added precompiler flag for SCRATCH file open on 1. + * @date 910320 Added option of status='SCRATCH' (wct) + * @date 871222 Moved file inquire to zinquire. + * Included MASSCOMP differences. + * @date 870729 Added 'RODATA' option. + * @date 860819 Changed to new message system. + * @date 851216 Modified for UNIX file I/O--D. Trimmer + * @date 841219 Expand KBASDR to path name, and convert full path name + * to lower case--D. Trimmer + * @date 830812 Original version. + * @date 870526 Documented/Reviewed + */ +void zopen_sac(nfu, kname, kname_s, ktype, ktype_s, nerr) + long int *nfu; + char *kname; + int kname_s; + char *ktype; + int ktype_s; long int *nerr; { long lexist, lnewfl, lro; @@ -19,65 +68,9 @@ long int *nerr; char *kname_c; void zopenc(); - /*===================================================================== - * PURPOSE: To open an existing disk file. - *===================================================================== - * INPUT ARGUMENTS: - * NFU: Fortran file unit to open file on. [i] - * KNAME: Name of disk file to open. [c] - * KTYPE: Type of disk file to open [k]: - * = 'DATA' for unformatted, direct-access file. - * = 'RODATA' for read-only DATA file. - * = 'ROUNFR' for read-only FORTRAN unformatted file. - * = 'TEXT' for formatted sequential-access file. - * = 'ROTEXT' or 'READ' for read-only TEXT file. - * = 'SCRATCH' for temporary file 'tmp...' that gets - * deleted when the file is closed. - * NLEN: Word length of file. [i] - *===================================================================== - * OUTPUT ARGUMENTS: - * NERR: Error return flag. Set to zero if no error. - * Possible error numbers from this call: - * 108 - File does not exist. - * 101 - System error occurred during open. - *===================================================================== - * MODULE/LEVEL: DFM/5 - *===================================================================== - * GLOBAL INPUT: - * MACH: MCPFN - *===================================================================== - * GLOBAL OUTPUT: - * OFM: KOUTM, MINTL - *===================================================================== - * LOCAL VARIABLES: - * MRECLB: Length of a fixed record in bytes for "DATA" type files. - *===================================================================== - * ASSUMPTIONS: - * - Record size of MRECLB bytes same in ZOPEN, ZNFILE, ZRABS, and ZWABS. - *===================================================================== - * KNOWN BUGS: - * - 'READ' option cannot be implemented using standard Fortran 77. - *===================================================================== - * MODIFICATION HISTORY: - * 920805: Added 'ROUNFR' option. - * 920319: Added precompiler flag for SCRATCH file open on 1. - * 910320: Added option of status='SCRATCH' (wct) - * 871222: Moved file inquire to zinquire. - * Included MASSCOMP differences. - * 870729: Added 'RODATA' option. - * 860819: Changed to new message system. - * 851216: Modified for UNIX file I/O--D. Trimmer - * 841219: Expand KBASDR to path name, and convert full path name - * to lower case--D. Trimmer - * 830812: Original version. - *===================================================================== - * DOCUMENTED/REVIEWED: 870526 - *===================================================================== */ - /* PROCEDURE: */ *nerr = 0; /* - Error exit if file does not exist. */ - kname_c = fstrdup(kname, kname_s); kname_s = strlen(kname_c) + 1; @@ -87,11 +80,10 @@ long int *nerr; *nerr = 108; setmsg( "ERROR", *nerr ); apcmsg( kname_c,kname_s ); - goto L_8888; + free(kname_c); } /* - Open data file. */ - if( memcmp(ktype,"DATA",4) == 0 ){ lnewfl = FALSE; lro = FALSE; @@ -104,7 +96,6 @@ long int *nerr; apcmsg( "(Insufficient access rights.)",30 ); else apcmsg( "(System error occurred.)",25 ); - goto L_8888; } } else if( memcmp(ktype,"RODATA",6) == 0 ){ @@ -119,7 +110,6 @@ long int *nerr; apcmsg( "(Insufficient access rights.)",30 ); else apcmsg( "(System error occurred.)",25 ); - goto L_8888; } } @@ -133,7 +123,6 @@ long int *nerr; apcmsg( "ROUNFR files not supported at this time-zopen",46 ); apimsg( noerr ); apcmsg( ")",2 ); - goto L_8888; } } @@ -147,7 +136,6 @@ long int *nerr; apcmsg( "RODIR files not supported at this time-zopen",45 ); apimsg( noerr ); apcmsg( ")",2 ); - goto L_8888; } } @@ -158,14 +146,8 @@ long int *nerr; apcmsg( "(Bad value for file type =",27 ); apcmsg( ktype,ktype_s ); apcmsg( ")",2 ); - goto L_8888; } -L_8888: free(kname_c); - kname_c = NULL; - return; - -} /* end of function */ - +} diff --git a/src/co/zopens.c b/src/co/zopens.c index 04441e1..05518c8 100755 --- a/src/co/zopens.c +++ b/src/co/zopens.c @@ -1,88 +1,77 @@ +/** + * @file zopens.c + * + * @brief Open an existing disk file + */ + #include #include #include -#include "../../inc/complex.h" -#include "../../inc/proto.h" #include -#define MRECLB 512 -#include "../../inc/mach.h" -void /*FUNCTION*/ zopens(nfu, kname, kname_s, ktype, ktype_s, nerr) -FILE **nfu; -char *kname; int kname_s; -char *ktype; int ktype_s; -long int *nerr; +#include "complex.h" +#include "proto.h" +#include "mach.h" + +/** + * Open an existing disk file + * + * @param nfu + * address to store the file pointer + * @param kname + * name of disk file to open + * @param kname_s + * The maximum allowable size of \p kname (incluing the trailing '\0') + * @param ktype + * Type of disk file to open [k]: + * = 'TEXT' for formatted sequential-access file. + * = 'ROTEXT' or 'READ' for read-only TEXT file. + * @param ktype_s + * The maximum allowable size of \p ktype (incluing the trailing '\0') + * @param nerr + * Error return flag. Set to zero if no error. + * Possible error numbers from this call: + * 108 - File does not exist. + * 101 - System error occurred during open. + * + * @return Nothing + * + * @date 920805 Added 'ROUNFR' option. + * @date 920319 Added precompiler flag for SCRATCH file open on 1. + * @date 910320 Added option of status='SCRATCH' (wct) + * @date 871222 Moved file inquire to zinquire. + * Included MASSCOMP differences. + * @date 870729 Added 'RODATA' option. + * @date 860819 Changed to new message system. + * @date 851216 Modified for UNIX file I/O--D. Trimmer + * @date 841219 Expand KBASDR to path name, and convert full path name + * to lower case--D. Trimmer + * @date 830812 Original version. + * @date 870526 Documented/Reviewed + */ +void zopens(nfu, kname, kname_s, ktype, ktype_s, nerr) + FILE **nfu; + char *kname; + int kname_s; + char *ktype; + int ktype_s; + long int *nerr; { char *nkname, *tok; long lexist; long int noerr; - /*===================================================================== - * PURPOSE: To open an existing disk file. - *===================================================================== - * INPUT ARGUMENTS: - * NFU: Fortran file unit to open file on. [i] - * KNAME: Name of disk file to open. [c] - * KTYPE: Type of disk file to open [k]: - * = 'DATA' for unformatted, direct-access file. - * = 'RODATA' for read-only DATA file. - * = 'ROUNFR' for read-only FORTRAN unformatted file. - * = 'TEXT' for formatted sequential-access file. - * = 'ROTEXT' or 'READ' for read-only TEXT file. - * = 'SCRATCH' for temporary file 'tmp...' that gets - * deleted when the file is closed. - *===================================================================== - * OUTPUT ARGUMENTS: - * NERR: Error return flag. Set to zero if no error. - * Possible error numbers from this call: - * 108 - File does not exist. - * 101 - System error occurred during open. - *===================================================================== - * MODULE/LEVEL: DFM/5 - *===================================================================== - * GLOBAL INPUT: - * MACH: MCPFN - *===================================================================== - * GLOBAL OUTPUT: - * OFM: KOUTM, MINTL - *===================================================================== - * LOCAL VARIABLES: - * MRECLB: Length of a fixed record in bytes for "DATA" type files. - *===================================================================== - * ASSUMPTIONS: - * - Record size of MRECLB bytes same in ZOPEN, ZNFILE, ZRABS, and ZWABS. - *===================================================================== - * KNOWN BUGS: - * - 'READ' option cannot be implemented using standard Fortran 77. - *===================================================================== - * MODIFICATION HISTORY: - * 920805: Added 'ROUNFR' option. - * 920319: Added precompiler flag for SCRATCH file open on 1. - * 910320: Added option of status='SCRATCH' (wct) - * 871222: Moved file inquire to zinquire. - * Included MASSCOMP differences. - * 870729: Added 'RODATA' option. - * 860819: Changed to new message system. - * 851216: Modified for UNIX file I/O--D. Trimmer - * 841219: Expand KBASDR to path name, and convert full path name - * to lower case--D. Trimmer - * 830812: Original version. - *===================================================================== - * DOCUMENTED/REVIEWED: 870526 - *===================================================================== */ - /* PROCEDURE: */ *nerr = 0; noerr = 0; /* - Error exit if file does not exist. */ - zinquire( kname, &lexist ); if( !lexist ){ *nerr = 108; setmsg( "ERROR", *nerr ); apcmsg( kname,kname_s ); - goto L_8888; + return; } if( (memcmp(ktype,"TEXT",4) == 0 || memcmp(ktype, @@ -99,24 +88,16 @@ long int *nerr; apcmsg( "(Fortran i/o error number =",28 ); apimsg( noerr ); apcmsg( ")",2 ); - goto L_8888; + return; } free(nkname); - - - } - else{ + } else{ *nerr = 101; setmsg( "ERROR", *nerr ); apcmsg( kname,kname_s ); apcmsg( "(Bad value for file type =",27 ); apcmsg( ktype,ktype_s ); apcmsg( ")",2 ); - goto L_8888; } - -L_8888: - return; - -} /* end of function */ +}