/****************************************************************************** New version: This file provides a single subroutine, get_fpcnt, for stripping comments from a control file and returning the file pointer to the (temporary) open stripped file. Usage: int main(int argc, char *argv[]) { FILE *fp_cnt; fp_cnt = get_fpcnt(argc, argv); ... } Old version: FILE: MAIN_CNT.C USAGE: MAIN CONTROL_FILE_NAME This is a main routine for calling functions (named "do_it") that use a control file specified on the command line. The control file may have comments; it will be copied, minus its comments, to a temporary file, which will then serve as the actual control file. Eric Firing 88-02-07 Fri 03-17-1989 Added variable buffering; added removal of the temporary control file. Both of these are controlled by preprocessor directives, since they are not available on all machines. Wed 07-11-1990 (JR) Used tmpnam() to generate unique temporary control file name 98/12/01 (EF) Changed the file mode to binary for the filtered control file handle that is passed to do_it(), so that ftell/fseek will work on DOS/WIN. The problem was first noticed with the mingw version of cygwin. ******************************************************************************/ #include "common.h" /* malloc(), free(), exit() */ #include "dbhost.h" /* PROTOTYPE_ALLOWED */ #include "io_nc.h" /* strip_comments() */ #include "ioserv.h" #include "errno.h" FILE *get_fpcnt(int argc, char *argv[]) { FILE *fp_cnt; FILE *fp_cnt_nc; char cntfile[256]; char *fn_ptr; if (argc < 2) { fprintf(stderr, "\nEnter control file name ==> "); scanf("%255s",cntfile); fn_ptr = cntfile; } else { fn_ptr = argv[1]; } if ((fp_cnt = fopen(fn_ptr, "r")) == NULL) { fprintf(stderr, " \n%%%% ERROR: Can't open %s\n\n", fn_ptr); exit(-1); } if ((fp_cnt_nc = tmpfile()) == NULL) { perror("\n%%%% ERROR: Can't open temporary file\n\n"); exit(-1); } /*fprintf(stderr, "\nStripping comments from control file\n");*/ strip_comments(fp_cnt, fp_cnt_nc); fclose(fp_cnt); rewind(fp_cnt_nc); return(fp_cnt_nc); }