home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / security / Watcher / open_cf.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-07-14  |  1.0 KB  |  47 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.    To make life easier dealing with lex, the control file is opened as
  6.    stdin.
  7.  
  8.    Kenneth Ingham
  9.  
  10.    Copyright (C) 1987 The University of New Mexico
  11. */
  12.  
  13. #include "defs.h"
  14.  
  15. open_cf()
  16. {
  17.     extern char *controlname;
  18.     extern int cflag;
  19.     extern int errno;
  20.     extern char *sys_errlist[];
  21.     FILE *cf;
  22.  
  23.     if (cflag) { /* specified control file */
  24.         cf = freopen(controlname, "r", stdin);
  25.         if (cf == NULL) {
  26.             fprintf(stderr, "Unable to open '%s': %s\n",
  27.                 controlname, sys_errlist[errno]);
  28.             exit(1);
  29.         }
  30.     }
  31.     else { /* try defaults */
  32.         if ((cf = freopen(DEF_CONTROL, "r", stdin)) == NULL) { /* #1 */
  33.             if ((cf = freopen(DEF_CONTROL2, "r", stdin)) == NULL) { /*#2*/
  34.                 fprintf(stderr, "Unable to open %s or %s: %s\n",
  35.                     DEF_CONTROL, DEF_CONTROL2,
  36.                     sys_errlist[errno]);
  37.                 exit(1);
  38.             }
  39.             /* if we're here #2 must have worked */
  40.             controlname = DEF_CONTROL2;
  41.         }
  42.         else
  43.             /* if we're here #1 must have worked */
  44.             controlname = DEF_CONTROL;
  45.     }
  46. }
  47.