#include #include #include "globals.h" /* =============================================== skipSpaces(fp): skip white spaces in input =============================================== */ void skipSpaces( FILE *fp ) { int c; c = getc(fp); while ( isspace(c) ) { c = getc(fp); } ungetc( c, fp ); } /* =============================================== readToken(T, fp): read next token into T =============================================== */ void readToken( char T[], FILE *fp ) { int c; skipSpaces(fp); c = getc(fp); while ( ! isspace(c) ) { *T++ = c; c = getc(fp); } *T = '\0'; } /* ================================================================ readMacro(fp): read macro definition ================================================================ */ void readMacro( FILE *fp ) { } /* ================================================================ readComp(fp): read Logic-sim component definition ================================================================ */ void readComp( FILE *fp ) { /* ----------------------------------------------- Read coordinate ----------------------------------------------- */ readToken(coord, fp); } /* ================================================================ readLogSimCmd(fp): read ONE logci-sim component (stop till ';') ================================================================ */ void readLogSimCmd( FILE *fp ) { int c; /* ----------------------------------------------- Read circuit name (or Define circuitName) ----------------------------------------------- */ readToken(circuit, fp); if ( strcmp( circuit, "Define" ) == 0 ) { macro = 1; readToken(circuit, fp); readMacro( fp ); } else { macro = 0; readComp( fp ); } } int main(int argc, char *argv[]) { FILE *fp; FILE *ofp; if ( argc < 2 ) { printf("Usage: %s circuit-file\n", argv[0]); exit(1); } if ( (fp = fopen(argv[1], "r")) == NULL ) { printf("Error: cannot open circuit-file %s\n", argv[1]); exit(1); } /* if ( (ofp = fopen("sim4.cc", "w")) == NULL ) { printf("Error: cannot open OUTPUT circuit-file sim4.cc\n"); exit(1); } */ ofp = stdout; readComp(fp); if ( macro ) { processMacro(ofp); } else { processComp(ofp); } }