/* Given the name of a file exported from indexer, parse it back into * the linked list form. * */ SortedListPtr parseFileToList(char *filename) { FILE *fp = fopen(filename,"r"); if(fp == NULL) { printf("Unable to open file %s\n",filename); return NULL; } SortedListPtr newList = SLCreate(*compareWordStruct); WordPtr curWord = NULL; char line[128]; while(fgets(line,128,fp) != NULL) { //Trim the newline character. if(strlen(line) > 0) { line[strlen(line)-1] = '\0'; //printf("Input trimmed.\n"); } //Classify the type of line. enum lineType curLine = classifyLine(line); //printf("Line type: %d\n",curLine); switch(curLine) { case WordLine: //Extract the word from the line. curWord = extractWord(line); //printf("Inserting new word into list.\n"); SLInsert(newList, curWord); break; case FileStatsLine: //Parse the line //Add the file stats to curWord's filestatslist curWord->filestats = buildFileStatsList(line); break; case Throwaway: //Do nothing I guess. break; } } fclose(fp); return newList; }
/// Main int main(int argc, char **argv) { FILE *fh; int RC=10; char readbuf[BUFSIZ]; argc--; argv++; if(argc>0) { setup_filename = *argv; argc--; argv++; } if(argc>0) { configin_filename = *argv; argc--; argv++; } if(argc>0) { configout_filename = *argv; argc--; argv++; } printf("Files: Setup=%s, Config in=%s, Config out=%s\n", setup_filename,configin_filename,configout_filename); if(fh=fopen(setup_filename,"r")) { int skip=0; lineNumber=1; while(fgets(readbuf,BUFSIZ,fh)!=NULL) { stripNL(readbuf); switch (classifyLine(readbuf)) { case L_SKIP: // skip this line break; case L_MODULE: if(!skip) { stripComment(readbuf); addStrToList(&moduleList, &moduleTail, readbuf); } break; case L_DEFINE: if(!skip) { addStrToList(&defineList, &defineTail, readbuf); } break; case L_OPTION: if(strcmp(readbuf,"*static*")==NULL) skip=0; if(strcmp(readbuf,"*doconfig*")==NULL) skip=0; if(strcmp(readbuf,"*shared*")==NULL) skip=1; if(strcmp(readbuf,"*noconfig*")==NULL) skip=1; break; } lineNumber++; } fclose(fh); if(processDefines() && processModules()) RC=0; } else { printf("Cannot read `%s'\n",setup_filename); } return RC; }