/* griddle -- Ghu's Region Internal Database Description LanguagE */ #include "griddleDefs.h" extern int yydebug; #define argcheck(i,m) if (++i >= argc) { error(m); exit(1); } #define argfile(fd,m,t) { \ fileName = *args++; \ if (strcmp(fileName, "-") == 0) \ fd = stdout; \ else if ((fd = fopen(fileName, t)) == NULL) \ systemError(m, fileName); \ } #define argfiler(fd,m) argfile(fd,m,"r") #define argfilew(fd,m) argfile(fd,m,"w") main(argc, argv) int argc; char *argv[]; { int i; int yyparse(); boolean initialize(); if (!initialize(argc, argv)) exit(1); #ifndef FRED if (indirFile == NULL) yyparse(); else indirectGriddle(); #else yyparse(); #endif readClassFile(); #ifndef FRED while (cvInput != NULL) { inputContentsVector(cvInput->string); cvInput = cvInput->nextString; } if (cvFile != NULL) outputContentsVector(); #else doFredStuff(); #endif } void resetRegionCounters() { int i; for (i=0; iname = malloc(strlen(name) + 1); newSymbol->type = NON_SYM; newSymbol->codeNumber = 0; strcpy(newSymbol->name, name); hashval = hash(name); mptr = symbolTable[hashval]; oldmptr = NULL; while (mptr != NULL) { if ((cmp = strcmp(name, mptr->name)) == 0) { error("Hey, symbol %s already in table!", name); exit(1); } else if (cmp > 0) { break; } else { oldmptr = mptr; mptr = mptr->next; } } if (oldmptr == NULL) symbolTable[hashval] = newSymbol; else oldmptr->next = newSymbol; newSymbol->next = mptr; return(newSymbol); } symbol * lookupSymbol(name) char *name; { symbol *result; int cmp; result = symbolTable[hash(name)]; while (result != NULL) { if ((cmp = strcmp(name, result->name)) == 0) return(result); else if (cmp > 0) result = NULL; else result = result->next; } return(insertSymbol(name)); } void yyerror(s) char *s; { error("\"%s\", line %d: %s\n", currentFileName, currentLineNumber, s); } void queueInputFile(name) char *name; { fileList *newFileName; newFileName = typeAlloc(fileList); newFileName->saveName = name; newFileName->fyle = NULL; newFileName->next = NULL; newFileName->saveLine = 1; if (inputStack == NULL) { inputStack = bottomOfInputStack = newFileName; } else { bottomOfInputStack->next = newFileName; bottomOfInputStack = newFileName; } } boolean openFirstFile(fredMode) boolean fredMode; { if (inputStack == NULL || strcmp(inputStack->saveName, "-") == 0) { inputStack = typeAlloc(fileList); inputStack->saveName = ""; inputStack->fyle = stdin; inputStack->saveLine = 1; inputStack->next = NULL; } else { if ((inputStack->fyle = fopen(inputStack->saveName, "r")) == NULL) { if (!fredMode) error("can't open input file %s\n", inputStack->saveName); free(inputStack); inputStack = NULL; return(FALSE); } } currentInput = inputStack->fyle; currentLineNumber = inputStack->saveLine; currentFileName = inputStack->saveName; purgeUnget(); return(TRUE); } void error(char *msg, ...) { fprintf(stderr, "error: "); va_list ap; va_start(ap, msg); vfprintf(stderr, msg, ap); va_end(ap); } void systemError(char *msg, ...) { fprintf(stderr, "error: "); va_list ap; va_start(ap, msg); vfprintf(stderr, msg, ap); va_end(ap); perror("Unix says"); exit(1); } void translate(s, c1, c2) char *s; char c1; char c2; { for (; *s != '\0'; ++s) if (*s == c1) *s = c2; } char * saveString(s) char *s; { char *result; result = (char *)malloc(strlen(s) + 1); strcpy(result, s); return(result); }