home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / unix / volume11 / watcher / part01 / open_cf.c < prev    next >
C/C++ Source or Header  |  1987-09-27  |  897b  |  41 lines

  1. /*
  2.    open_cf: open the control file.  It is either specified on the
  3.    command line or DEF_CONTROL or DEF_CONTROL2.
  4.  
  5.    Kenneth Ingham
  6.  
  7.    Copyright (C) 1987 The University of New Mexico
  8. */
  9.  
  10. #include "defs.h"
  11.  
  12. open_cf()
  13. {
  14.     extern char controlname[];
  15.     extern FILE *cf;
  16.     extern int cflag;
  17.  
  18.     if (cflag) { /* specified control file */
  19.         cf = fopen(controlname, "r");
  20.         if (cf == NULL) {
  21.             fprintf(stderr, "Unable to open '%s'\n",
  22.                 controlname);
  23.             exit(1);
  24.         }
  25.     }
  26.     else { /* try defaults */
  27.         if ((cf = fopen(DEF_CONTROL, "r")) == NULL) { /* #1 */
  28.             if ((cf = fopen(DEF_CONTROL2, "r")) == NULL) { /*#2*/
  29.                 fprintf(stderr, "Unable to open %s or %s\n",
  30.                     DEF_CONTROL, DEF_CONTROL2);
  31.                 exit(1);
  32.             }
  33.             /* if we're here #2 must have worked */
  34.             (void) strcpy(controlname, DEF_CONTROL2);
  35.         }
  36.         else
  37.             /* if we're here #1 must have worked */
  38.             (void) strcpy(controlname, DEF_CONTROL);
  39.     }
  40. }
  41.