home *** CD-ROM | disk | FTP | other *** search
- /*
- * COM - Communication script compiler.
- *
- * Copyright 1990, QED Software. All rights reserved.
- *
- * Written by Tim Capps.
- *
- */
-
- extern "C" {
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include <ctype.h>
- #include <io.h>
- }
-
- #ifdef BORLAND
- #include <iostream.h>
- #else
- #include <stream.hpp>
- #endif
-
- #include "pcodes.h" // P-code engine equates
-
- int yyparse(); /* YACC prototype */
-
- extern int yydebug;
-
- FILE *comIn; /* Resource source file */
- FILE *comOut; /* Binary file */
-
- int lineCount; /* Line counter */
-
- int errCount; /* Error counter */
-
- char infile[100];
- char outfile[100];
-
- main(int argc, char *argv[])
- {
- int refnum;
- long len;
- int status;
-
- char *c;
-
- cout << "COM - Communications script Compiler\n";
-
- lineCount=1;
-
- if (argc<2) {
- cout << "Usage: COM sourcefile\n";
- exit(0);
- }
-
- (void) strcpy(infile,argv[1]);
- c=strchr(infile,'.');
- if (c==0) {
- (void) strcat(infile,".S"); /* Default to .S extension */
- }
-
- (void) strcpy(outfile,argv[1]);
- c=strchr(outfile,'.'); /* Did they give us an extension? */
- if (c!=0) {
- *c=0; /* Yes, hack it off. */
- }
- (void) strcat(outfile,".BIN"); /* Set output ext to .BIN */
-
- /* Open the source file */
- comIn = fopen (infile, "r");
- if (comIn==0) {
- cout << "%Error - Cannot open source file.\n";
- exit(1);
- }
-
- /* Open the binary file */
- comOut = fopen (outfile, "w+b");
- if (comOut==0) {
- cout << "%Error - Cannot open binary file.\n";
- exit(1);
- }
-
- if (argc==3) { /* Debug - interactive mode */
- comIn=stdin;
- }
-
- status=yyparse();
-
- if(errCount) {
- cout << "%Errors were found - binary file is incomplete.\n";
- }
-
- fclose(comIn);
-
- fputc(PC_END, comOut); // Put an EXIT at the end of pcode
- fclose(comOut);
-
- exit(errCount);
- }
-
- /*
- * BISON Error handler
- */
- void
- yyerror(char *s)
- {
- fprintf(stderr,"\"%s\", line %i %s\n",infile,lineCount,s);
- errCount++;
- }
-
- /*
- * Bison emergency exit
- */
- void
- done(int x)
- {
- exit(x);
- }
-