home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / MODEM / UWPC201.ZIP / UW-SRC.ZIP / TERMCC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1991-05-27  |  3.6 KB  |  119 lines

  1. /*-------------------------------------------------------------------------
  2.  
  3.   TERMCC.C - Main module for the Termcap Compiler.
  4.  
  5.     This file is part of the Termcap Compiler source code.
  6.     Copyright (C) 1990-1991  Rhys Weatherley
  7.  
  8.     This program is free software; you can redistribute it and/or modify
  9.     it under the terms of the GNU General Public License as published by
  10.     the Free Software Foundation; either version 1, or (at your option)
  11.     any later version.
  12.  
  13.     This program is distributed in the hope that it will be useful,
  14.     but WITHOUT ANY WARRANTY; without even the implied warranty of
  15.     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16.     GNU General Public License for more details.
  17.  
  18.     You should have received a copy of the GNU General Public License
  19.     along with this program; if not, write to the Free Software
  20.     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21.  
  22.   Revision History:
  23.   ================
  24.  
  25.    Version  DD/MM/YY  By  Description
  26.    -------  --------  --  --------------------------------------
  27.      1.0    23/03/91  RW  Original Version of NAME.H
  28.  
  29.   You may contact the author by:
  30.   =============================
  31.  
  32.    e-mail: rhys@cs.uq.oz.au
  33.      mail: Rhys Weatherley
  34.        5 Horizon Drive
  35.        Jamboree Heights
  36.        Queensland 4074
  37.        Australia
  38.  
  39. -------------------------------------------------------------------------*/
  40.  
  41. #include <string.h>        /* String processing routines */
  42. #include <stdio.h>        /* Standard I/O routines */
  43.  
  44. /*
  45.  * Define some buffers to hold the names of the input and output files.
  46.  */
  47. char    InFileName[BUFSIZ];
  48. char    OutFileName[BUFSIZ];
  49.  
  50. extern    int    numerrors;
  51.  
  52. int    main    (argc,argv)
  53. int    argc;
  54. char    *argv[];
  55. {
  56.   FILE *infile;
  57.   int posn;
  58.  
  59.   /* Print the program banner and copyright message */
  60.   printf ("TERMCC version 1.01, Copyright (C) 1991 Rhys Weatherley\n");
  61.   printf ("TERMCC comes with ABSOLUTELY NO WARRANTY; see the file COPYING for details.\n");
  62.   printf ("This is free software, and you are welcome to redistribute it\n");
  63.   printf ("under certain conditions; see the file COPYING for details.\n");
  64.  
  65.   /* Determine the input and output files */
  66.   if (argc <= 1)
  67.     usage ();
  68.    else
  69.     {
  70.       strcpy (InFileName,argv[1]);
  71.       posn = strlen (InFileName);    /* Find ".", "/" or "\" */
  72.       while (posn > 0 && InFileName[posn - 1] != '.' &&
  73.                InFileName[posn - 1] != '\\' &&
  74.          InFileName[posn - 1] != '.')
  75.     --posn;
  76.       if (posn == 0 || InFileName[posn - 1] != '.')
  77.         strcat (InFileName,".CAP");
  78.  
  79.       /* Get the default output filename */
  80.       strcpy (OutFileName,InFileName);
  81.       posn = strlen (OutFileName);    /* Find last "." */
  82.       while (posn > 0 && OutFileName[posn - 1] != '.')
  83.         --posn;
  84.       if (posn > 0)
  85.         strcpy (OutFileName + posn,"TRM");    /* Replace extension */
  86.     } /* else */
  87.   if (argc == 3)
  88.     strcpy (OutFileName,argv[2]);
  89.    else if (argc > 3)
  90.     usage ();
  91.  
  92.   /* Parse the input file to create the resultant file */
  93.   if ((infile = fopen (InFileName,"rt")) == NULL)
  94.     {
  95.       fprintf (stderr,"\n");
  96.       perror (InFileName);
  97.       exit (1);
  98.     } /* if */
  99.   initlex (infile);    /* Initialise the lexical analyser */
  100.   yyparse ();        /* Parse the input file */
  101.   fixups ();        /* Do all label fixups */
  102.   dumpcode ();        /* Dump the code to the output file */
  103.   fclose (infile);    /* Close the input file at the end */
  104.  
  105.   if (numerrors == 0)
  106.     exit (0);
  107.    else
  108.     exit (1);
  109. } /* main */
  110.  
  111. /*
  112.  * Print a usage message for the program and exit.
  113.  */
  114. usage ()
  115. {
  116.   fprintf (stderr,"\nUsage: TERMCC infile[.CAP] [outfile[.TRM]]\n");
  117.   exit (1);
  118. } /* usage */
  119.