home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / quot210s.zip / src / quoterc.c < prev    next >
C/C++ Source or Header  |  1998-11-03  |  2KB  |  77 lines

  1. /*
  2.  * quoterc.c
  3.  *
  4.  * Main program for the Quoteriser database compiler.
  5.  *
  6.  *      Created: 13th September, 1998
  7.  * Version 1.00: 3rd November, 1998
  8.  *
  9.  * (C) 1998 Nicholas Paul Sheppard
  10.  *
  11.  * This file is distributed under the GNU General Public License. See the
  12.  * file copying.txt for details.
  13.  */
  14.  
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include "quoterc.h"
  19.  
  20.  
  21. int main(int argc, char **argv)
  22. {
  23.     char *    pszCmdFile;    /* file name of command file */
  24.     FILE *    fCmd;        /* stream handle of command file */
  25.     QCERROR    qe;        /* errors from QCProcessCommands() */
  26.     int    bAbort;        /* set to 1 to abort process */
  27.     int    i;        /* counter */
  28.  
  29.     /* initialise variables */
  30.     pszCmdFile = NULL;
  31.     fCmd = NULL;
  32.     bAbort = 0;
  33.  
  34.     if (argc < 2) {
  35.         /* print help screen */
  36.         printf("The Quoteriser: Database Compiler 1.00\n");
  37.         printf("(C) 1998 Nicholas Paul Sheppard. This program is distributed\n");
  38.         printf("under the GNU General Public License and comes with NO WARRANTY\n");
  39.         printf("WHATSOEVER. See the file copying.txt for details.\n\n");
  40.         printf("Usage: quoterc <file1> <file2> ...\n\n");
  41.         printf("  where: <fileN>  is the name of a command (.qc) file\n\n");
  42.         return (0);
  43.     }
  44.  
  45.     for (i = 1; !bAbort && (i < argc); i++) {
  46.         /* open command file */
  47.         if ((pszCmdFile = (char *)malloc(strlen(argv[i]) + 4)) == NULL) {
  48.             fprintf(stderr, "quoterc: memory allocation failure.\n");
  49.             bAbort = 1;
  50.         } else {
  51.             strcpy(pszCmdFile, argv[i]);
  52.             if ((fCmd = fopen(pszCmdFile, "r")) == NULL) {
  53.                 strcat(pszCmdFile, ".qc");
  54.                 if ((fCmd = fopen(pszCmdFile, "r")) == NULL) {
  55.                     fprintf(stderr, "quoterc: could not open %s or %s.\n", argv[i], pszCmdFile);
  56.                     bAbort = 1;
  57.                 }
  58.             }
  59.         }
  60.  
  61.         /* process command file */
  62.         if (!bAbort) {
  63.             if (QCProcessCommands(fCmd, &qe) != QC_ENONE) {
  64.                 fprintf(stderr, "%s: line %d: %s\n", pszCmdFile, qe.iLine, QCErrorString(qe.iError));
  65.                 bAbort = 1;
  66.             }
  67.         }
  68.  
  69.         /* clean up */
  70.         free(pszCmdFile);
  71.         if (fCmd != NULL)
  72.             fclose(fCmd);
  73.     }
  74.  
  75.     return (bAbort);
  76. }
  77.