void testFile(void) { FileName testFile; FILE *fout; printf("fileSetHandler:\n"); fileSetHandler(fileSetHandler((FileErrorFun) 0)); printf("pathInit:\n"); pathInit(); printf("fileRdFind: yabba -- "); testFile = fileRdFind(binSearchPath(), "yabba", ""); if (testFile) printf("dir \"%s\", name \"%s\", type \"%s\"\n", fnameDir(testFile), fnameName(testFile), fnameType(testFile)); else printf("Not found\n"); printf("fileRdFind: cat -- "); testFile = fileRdFind(binSearchPath(), "cat", osExecFileType); if (testFile) { printf("dir \"%s\", name \"%s\", type \"%s\"\n", fnameDir(testFile), fnameName(testFile), fnameType(testFile)); printf("fileRdOpen: "); fout = fileRdOpen(testFile); printf("Opened \"%s\"\n",fnameName(testFile)); fclose(fout); } else printf("Not found\n"); printf("DONE.\n"); fnameFree(testFile); /* fileRemove(testFile); */ }
String compRootFromCmdLine(String cwd, String file) { FileName fname = fnameParseStaticWithin(file, cwd); String binDir = fnameDir(fname); FileName rootDir = fnameNew(binDir, "..", ""); String root = fnameUnparse(rootDir); return root; }
/* * Compile .as file, returning error count. */ int compSourceFile(EmitInfo finfo) { AbSyn ab; Stab stab; Foam foam; int msgCount; compFileInit(finfo); breakSetRoot(NULL); stab = stabFile(); ab = compFileFront(finfo, stab, NULL, NULL); breakSetRoot(ab); if (emitIsOutputNeededOrWarn(finfo, FTYPENO_CPP)) { /* Need to inspect finfo to get the filename */ FileName fn = emitFileName(finfo, FTYPENO_INTERMED); genCpp(ab,fnameDir(fn),fnameName(fn)); emitTheCpp(); } if (compIsMoreAfterFront(finfo)) { foam = compFileMiddle(finfo, stab, ab); compFileSave(finfo, stab, foam); compFileBack(finfo, foam); foamFree(foam); } msgCount = comsgErrorCount(); compFileFini(finfo); /* abFree(ab); !! ab is seeping into types. */ if (msgCount < 1) breakInterrupt(); return msgCount; }
local SrcLineList inclFile(String fname, Bool reincluding, Bool top, long *pnlines) { Scope("inclFile"); SrcLineList sll; Hash fhash; FileName fn; FileState o_fileState; IfState fluid(ifState); String curdir; o_fileState = fileState; /* no fluid(struct) */ ifState = NoIf; fileState.lineNumber = 0; fn = inclFind(fname, fileState.curDir); if (fn != 0) { fileState.curDir = strCopy(fnameDir(fn)); fileState.curFile = strCopy(fnameUnparseStatic(fn)); fileState.curFname = fn; } curdir = fileState.curDir; if (fn == 0) { fileState = o_fileState; if (top) { comsgFatal(NULL, ALDOR_F_CantOpen, fname); NotReached(sll = 0); } else sll = inclError(ALDOR_F_CantOpen, fname); } else { fhash = fileHash(fn); fname = strCopy (fnameUnparseStatic(fn)); if (!reincluding && listMemq(Hash)(includedFileCodes, fhash)) { sll = listNil(SrcLine); } else if (listMemq(Hash)(fileState.fileCodes, fhash)) { String s = inclActiveFileChain (fileState.fileNames, "->"); fileState = o_fileState; sll = inclError(ALDOR_E_InclInfinite, s); strFree(s); } else { includedFileCodes = listCons(Hash) (fhash,includedFileCodes); fileState.fileCodes = listCons(Hash) (fhash,fileState.fileCodes); fileState.fileNames = listCons(String)(fname,fileState.fileNames); fileState.infile = fileRdOpen(fn); sll = inclFileContents(); listFreeCons(Hash) (fileState.fileCodes); listFreeCons(String)(fileState.fileNames); fclose(fileState.infile); } fnameFree(fn); strFree(curdir); /*!! curFile is used in src lines */ strFree(fname); } if (pnlines) *pnlines = fileState.lineNumber; fileState = o_fileState; Return(sll); }