int16_t primeTokenizer(unsigned long stringStackSize) { TRACE(lstFile,"[primeTokenizer]"); /* Allocate and initialize the string stack and stack pointers */ strStack = malloc(stringStackSize); if (!strStack) { fatal(eNOMEMORY); } /* Initially, everything points to the bottom of the * string stack. */ tkn_strt = strStack; stringSP = strStack; /* Set up for input at the initial level of file parsing */ rePrimeTokenizer(); return 0; }
void openNestedFile(const char *fileName) { fileState_t *prev = FP; char fullpath[FNAME_SIZE + 1]; int i; /* Make sure we can handle another nested file */ if (++includeIndex >= MAX_INCL) fatal(eOVF); else { /* Clear the file state structure for the new include level */ memset(FP, 0, sizeof(fileState_t)); /* Try all source include pathes until we find the file or * until we exhaust the include path list. */ for (i = 0; ; i++) { /* Open the nested file -- try all possible pathes or * until we successfully open the file. */ /* The final path that we will try is the current directory */ if (i == nIncPathes) { sprintf(fullpath, "./%s", fileName); } else { sprintf(fullpath, "%s/%s", includePath[i], fileName); } FP->stream = fopen (fullpath, "rb"); if (!FP->stream) { /* We failed to open the file. If there are no more * include pathes to examine (including the current directory), * then error out. This is fatal. Otherwise, continue * looping. */ if (i == nIncPathes) { errmsg("Failed to open '%s': %s\n", fileName, strerror(errno)); fatal(eINCLUDE); break; /* Won't get here */ } } /* end else if */ else break; } /* Setup the newly opened file */ fprintf(errFile, "%01x=%s\n", FP->include, fullpath); FP->include = poffAddFileName(poffHandle, fullpath); /* The caller may change this, but the default behavior is * to inherit the kind and section of the including file * and the current data stack offset. */ FP->kind = prev->kind; FP->section = prev->section; FP->dstack = dstack; rePrimeTokenizer(); /* Get the first token from the file */ getToken(); } /* end else */ }