home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c100 / 4.ddi / COM.ZIP / COM.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-02  |  2.1 KB  |  120 lines

  1. /*
  2.  * COM - Communication script compiler.
  3.  *
  4.  * Copyright 1990, QED Software.  All rights reserved.
  5.  *
  6.  * Written by Tim Capps.
  7.  *
  8.  */
  9.  
  10. extern "C" {
  11. #include <stdio.h>
  12. #include <string.h>
  13. #include <stdlib.h>
  14. #include <ctype.h>
  15. #include <io.h>
  16. }
  17.          
  18. #ifdef BORLAND
  19.  #include <iostream.h>
  20. #else
  21.  #include <stream.hpp>
  22. #endif
  23.  
  24. #include "pcodes.h"                // P-code engine equates
  25.  
  26. int yyparse();                    /* YACC prototype                        */
  27.     
  28. extern int yydebug;
  29.     
  30. FILE *comIn;                    /* Resource source file                    */
  31. FILE *comOut;                    /* Binary file                            */
  32.      
  33. int lineCount;                    /* Line counter                            */
  34.     
  35. int errCount;                    /* Error counter                        */
  36.  
  37. char infile[100];
  38. char outfile[100];
  39.  
  40. main(int argc, char *argv[])
  41. {
  42.     int    refnum;
  43.     long len;
  44.     int    status;
  45.     
  46.     char *c;
  47.     
  48.     cout << "COM - Communications script Compiler\n";
  49.     
  50.     lineCount=1;
  51.     
  52.     if (argc<2) {
  53.         cout << "Usage: COM sourcefile\n";
  54.         exit(0);
  55.     }
  56.  
  57.     (void) strcpy(infile,argv[1]);
  58.     c=strchr(infile,'.');
  59.     if (c==0) {
  60.         (void) strcat(infile,".S");        /* Default to .S extension      */
  61.     }       
  62.  
  63.     (void) strcpy(outfile,argv[1]);
  64.     c=strchr(outfile,'.');                /* Did they give us an extension? */
  65.     if (c!=0) {
  66.         *c=0;                            /* Yes, hack it off.              */
  67.     }
  68.     (void) strcat(outfile,".BIN");        /* Set output ext to .BIN          */
  69.     
  70.     /* Open the source file */
  71.     comIn = fopen (infile, "r");
  72.     if (comIn==0) {
  73.         cout << "%Error - Cannot open source file.\n";
  74.         exit(1);
  75.     }
  76.     
  77.     /* Open the binary file */
  78.     comOut = fopen (outfile, "w+b");
  79.     if (comOut==0) {
  80.         cout << "%Error - Cannot open binary file.\n";
  81.         exit(1);
  82.     }
  83.  
  84.     if (argc==3) {                        /* Debug - interactive mode */
  85.         comIn=stdin;
  86.     }
  87.  
  88.     status=yyparse();
  89.     
  90.     if(errCount) {
  91.         cout << "%Errors were found - binary file is incomplete.\n";
  92.     }
  93.  
  94.     fclose(comIn);
  95.  
  96.     fputc(PC_END, comOut);                // Put an EXIT at the end of pcode
  97.     fclose(comOut);
  98.     
  99.     exit(errCount);
  100. }
  101.  
  102. /*
  103.  *    BISON Error handler
  104.  */
  105. void
  106. yyerror(char *s)
  107. {
  108.     fprintf(stderr,"\"%s\", line %i %s\n",infile,lineCount,s);
  109.     errCount++;
  110. }
  111.  
  112. /*
  113.  *    Bison emergency exit
  114.  */
  115. void
  116. done(int x)
  117. {
  118.     exit(x);
  119. }
  120.