home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume17 / ease2 / part01 / src / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-02-08  |  3.9 KB  |  122 lines

  1. /*    $Header: main.c,v 2.0 88/06/15 14:42:41 root Exp $    */
  2.  
  3. /*
  4.  * $Log:    main.c,v $
  5.  * Revision 2.0  88/06/15  14:42:41  root
  6.  * Baseline release for net posting. ADR.
  7.  * 
  8.  */
  9.  
  10. /*
  11.  *      main.c     -- Main procedure for Ease Translator.
  12.  *
  13.  *      author     -- James S. Schoner, Purdue University Computing Center
  14.  *                        West Lafayette, Indiana  47907
  15.  *
  16.  *      date       -- July 9, 1985
  17.  *
  18.  *    Copyright (c) 1985 by Purdue Research Foundation
  19.  *
  20.  *    All rights reserved.
  21.  *
  22.  */
  23.  
  24. #include "fixstrings.h"
  25. #include <stdio.h>
  26.  
  27. extern FILE *DIAGf;            /* diagnostic file */
  28. extern void InitError (), 
  29.         InitSymbolTable (),
  30.         DefScan (),
  31.         FatalError (),
  32.             PreLoad ();
  33.  
  34. int ErrorCount;                /* translation error count */
  35. void GetArgs ();            /* gets arguments to "et"  */
  36.  
  37. /*
  38.  *    main () -- Main procedure for the Ease Translator et.  If no files are 
  39.  *                  given as arguments to et, stdin is translated and written to 
  40.  *               stdout.  If one file is given, it is translated and written 
  41.  *               to stdout.  If two files are given, the first is translated
  42.  *               and written to the second.  If the first filename is "-",
  43.  *               standard input is assumed.  A translation is performed on 
  44.  *               valid Ease input only, producing a regular sendmail 
  45.  *           configuration file. 
  46.  *
  47.  */
  48. void
  49. main (argc, argv)
  50. int argc;        /* argument count for "et"  */
  51. char *argv[];        /* argument vector for "et" */
  52. {
  53.     InitError ();            /* initialize error conditions */
  54.     InitSymbolTable ();        /* initialize the symbol table */
  55.     PreLoad ();            /* preload special identifiers */
  56.     GetArgs (argc, argv);        /* set up argument files       */
  57.     (void) yyparse ();        /* perform translation           */
  58.     if (fflush (stdout) == EOF)
  59.         FatalError ("Cannot flush output stream/file", (char *) NULL);
  60.     DefScan ();                /* warn about undefined idents */
  61.     if (ErrorCount)
  62.         fprintf (DIAGf, "\n\n*** %d error(s) detected.\n", ErrorCount);
  63.     exit (ErrorCount);
  64. }
  65.  
  66.  
  67. /*
  68.  *    GetArgs () -- Processes arguments to the Ease translator "et".  The
  69.  *              arguments are files (margv) which may replace either/both
  70.  *              of the files standard input and standard output.  The 
  71.  *              following cases are possible:
  72.  *            
  73.  *              -- et f.e f.cf
  74.  *                Translate Ease file f.e and write result
  75.  *                to f.cf.
  76.  *
  77.  *              -- et f.e
  78.  *                Translate Ease file f.e and write result to
  79.  *                standard output.
  80.  *
  81.  *              -- et - f.cf
  82.  *                Translate standard input and write result to
  83.  *                f.cf.
  84.  *
  85.  *              -- et
  86.  *                Translate standard input and write result to
  87.  *                standard output.
  88.  *
  89.  *              Finally, a message indicating the volatility of the 
  90.  *              Ease output is written.
  91.  *
  92.  */
  93. void
  94. GetArgs (margc, margv)
  95. register int   margc;        /* argument count  */
  96. register char *margv[];        /* argument vector */
  97. {
  98.     switch (margc) {
  99.         case 1 : break;
  100.         case 2 :
  101.         case 3 : if (strcmp (margv[1], "-") && (freopen (margv[1], "r", stdin) == NULL))
  102.                 FatalError ("Cannot open input stream/file:", margv[1]);
  103.              if ((margc == 3) && (freopen (margv[2], "w", stdout) == NULL))
  104.                 FatalError ("Cannot open output file:", margv[2]);
  105.              break;
  106.         default: FatalError ("Usage: et [infile [outfile]]", (char *) NULL);
  107.              break;
  108.     }
  109.     printf ("###################################################\n");
  110.     printf ("##                                               ##\n");
  111.     printf ("##  WARNING: THIS FILE IS THE OUTPUT OF THE      ##\n");
  112.     printf ("##           `EASE' PRECOMPILER FOR SENDMAIL     ##\n");
  113.     printf ("##           CONFIGURATION FILES.                ##\n");
  114.     printf ("##                                               ##\n");
  115.     printf ("##           MAKE MODIFICATIONS TO THE SOURCE    ##\n");
  116.     printf ("##           FILE ONLY.  CHANGES MADE DIRECTLY   ##\n");
  117.     printf ("##           TO THIS FILE WILL DISAPPEAR THE     ##\n");
  118.     printf ("##           NEXT TIME THAT EASE IS RUN.         ##\n");
  119.     printf ("##                                               ##\n");
  120.     printf ("###################################################\n");
  121. }
  122.