local FileName arFileNameFrPath(String name) { FileName fname = fnameParse(name); fnameSetType(fname, FTYPE_AR_INT); return fname; }
local SrcLineList inclHandleLine(int lno, String fname) { if (INCLUDING(ifState)) { fileState.lineNumber = lno - 1; /* The next line is 'lno' */ if (fname) { fileState.curFile = fname; /* rhx: We trust the programmer of the #line statement in the .as file that the filename is correct. If in an error case the file cannot be found the compiler aborts with a (Fatal Error) message. #1 (Fatal Error) Could not open file `dir/file.ext' with mode `r'. It would actually be very helpful for a programmer if we could abort the compilation already here with an error message saying that the filename appearing in the #line directive cannot be found. */ fileState.curFname = fnameParse(fname); } sposGrowGloLineTbl(fileState.curFname, fileState.lineNumber, inclSerialLineNo); return listNil(SrcLine); } return listNil(SrcLine); }
static FILE * getCfgFile(int argc, char **argv) { FileName cfgFileName; FILE *file; char *name; name = getOption(argc, argv, "-Wconfig=", NULL); /* Should strip off any ".conf" */ if (!name) { cfgFileName = cfgFindFile(CONFFILE, ""); if (!cfgFileName) cfgFileName = cfgFindFile(OLDCONFFILE, ""); } else cfgFileName = fnameParse(name); if (!cfgFileName) { fprintf(stderr, "Can't find config file\n"); return NULL; } if ((file = fileTryOpen(cfgFileName, osIoRdMode)) == NULL) fprintf(stderr, "Can't open: %s\n", fnameUnparse(cfgFileName)); return file; }
void compGLoopInit(int argc, char **argv, FILE *fout, FileName *pfn, EmitInfo *pfinfo) { int iargc; Bool tmpHistory; FILE * fin; FileName fname; compInit(); iargc = cmdArguments(1, argc, argv); argc -= iargc; argv += iargc; emitDoneOptions(argc, argv); *pfn = fnameStdin(); *pfinfo = emitInfoNew(*pfn); compFileInit(*pfinfo); comsgFini(); fintInit(); /* Helpful start-up banner ... */ fprintf(osStdout,"%s\n",comsgString(ALDOR_M_GloopBanner)); if (comsgOkRelease()) { fprintf(osStdout, "%s: %s(%s) version %d.%d.%d", "Release", verName, "C", /* C-language version */ verMajorVersion, verMinorVersion, verMinorFreeze); if (*verPatchLevel) fprintf(osStdout, "(%s)", verPatchLevel); fprintf(osStdout, " for %s %s\n", CONFIG, DEBUG_CONFIG); } (void)fputs("Type \"#int help\" for more details.\n",osStdout); if (osFileIsThere(cmdInitFile)) { fname = fnameParse(cmdInitFile); fin = fileMustOpen(fname, osIoRdMode); fnameFree(fname); intStepNo = -1; tmpHistory = fintHistory; fintHistory = false; fprintf(fout, "Reading %s...\n", cmdInitFile); compGLoopEval(fin, fout, *pfinfo); fclose(fin); } else { intStepNo = 0; tmpHistory = fintHistory; } fintHistory = tmpHistory; }
local Lib arExtractEntry(Archive ar, ArEntry arent) { Lib lib; lib = libExtract(fnameParse(arent->name), arFile(ar), arent->pos); lib->arent = arent; arent->lib = lib; return lib; }
local void testArchive() { Archive ar; FileName fname = fnameParse("arch-test/foo.al"); int status; status = system("mkdir arch-test"); testIntEqual("", 0, status); status = system("ar r arch-test/foo.al Makefile"); testIntEqual("", 0, status); ar = arFrString("arch-test/foo.al"); testIsNotNull("t0", ar); status = system("rm -rf arch-test"); testIntEqual("", 0, status); }
/* * Compile files controlled by the argument vector and * return the total error count. */ int compFilesLoop(int argc, char **argv) { int i, iargc, totErrors, nErrors; FileName fn; Bool isSolo; compInit(); iargc = cmdArguments(1, argc, argv); argc -= iargc; argv += iargc; if (argc == 0) { if (comsgOkBreakLoop()) bloopMsgFPrintf(osStdout, ALDOR_W_NoFiles, cmdName); comsgWarning(NULL, ALDOR_W_NoFiles, cmdName); } emitDoneOptions(argc, argv); ccGetReady(); isSolo = (cmdFileCount == 1); compFinfov = (EmitInfo *) stoAlloc((unsigned) OB_Other, (cmdFileCount+1) * sizeof(EmitInfo)); for (i = 0; i <= cmdFileCount; i += 1) compFinfov[i] = 0; totErrors = 0; for (i = 0; i < cmdFileCount; i++) { fn = fnameParse(argv[i]); compFinfov[i] = emitInfoNew(fn); nErrors = 0; if (!fileIsReadable(fn)) { if (comsgOkBreakLoop()) bloopMsgFPrintf(osStdout, ALDOR_F_CantOpen, argv[i]); comsgFatal(NULL, ALDOR_F_CantOpen, argv[i]); } switch (ftypeNo(fnameType(fn))) { #if 0 case FTYPENO_C: nErrors = compCFile(compFinfov[i]); break; #endif case FTYPENO_OBJECT: case FTYPENO_AR_OBJ: case FTYPENO_AR_INT: break; case FTYPENO_FOAMEXPR: case FTYPENO_INTERMED: if (!isSolo) fprintf(osStdout, "\n%s:\n", argv[i]); nErrors = compSavedFile(compFinfov[i]); break; default: if (!ftypeEqual(fnameType(fn), "")) { if (comsgOkBreakLoop()) bloopMsgFPrintf(osStdout, ALDOR_F_BadFType, argv[i], fnameType(fn), FTYPE_SRC); comsgFatal(NULL, ALDOR_F_BadFType, argv[i], fnameType(fn), FTYPE_SRC); } /* Fall through. */ case FTYPENO_NONE: case FTYPENO_SRC: case FTYPENO_INCLUDED: case FTYPENO_ABSYN: case FTYPENO_OLDABSYN: if (!isSolo) fprintf(osStdout, "\n%s:\n", argv[i]); nErrors = compSourceFile(compFinfov[i]); break; } totErrors += nErrors; fnameFree(fn); } if (cmdFileCount > 0 && totErrors == 0) { compFinfov[cmdFileCount] = emitInfoNewAXLmain(); compAXLmainFile(compFinfov[cmdFileCount]); emitLink(cmdFileCount + 1, compFinfov); argc -= cmdFileCount; argv += cmdFileCount; emitInterp(argc, argv); emitRun (argc, argv); } if (totErrors > 0) emitAllDone(); for (i = 0; i < cmdFileCount + 1; i++) emitInfoFree(compFinfov[i]); stoFree((Pointer) compFinfov); compFinfov = 0; if (!isSolo) phGrandTotals(cmdVerboseFlag); compFini(); return totErrors; }
int compInteractiveLoop(int argc, char **argv, FILE *fin, FILE *fout) { int iargc, totErrors, lineno; FileName fn; EmitInfo finfo; AbSyn ab; Stab stab; Foam foam; Bool readingInitFile = true, tmpHistory; Bool endOfInput = false; FILE *fin0 = fin; compInit(); iargc = cmdArguments(1, argc, argv); argc -= iargc; argv += iargc; emitDoneOptions(argc, argv); if (osFileIsThere(cmdInitFile)) { FileName fname; fname = fnameParse(cmdInitFile); fin = fileMustOpen(fname, osIoRdMode); fnameFree(fname); intStepNo = 0; tmpHistory = fintHistory; fintHistory = false; fprintf(fout, "Reading %s...\n", cmdInitFile); } else { intStepNo = 1; readingInitFile = false; tmpHistory = fintHistory; } fn = fnameStdin(); finfo = emitInfoNew(fn); lineno = 0; compFileInit(finfo); stab = stabFile(); comsgFini(); fintInit(); for (; !endOfInput; intStepNo++) { comsgInit(); breakSetRoot(NULL); car(stab)->isChecked = false; if (SetJmp(compFintJmpBuf)) { if (feof(fin)) break; } comsgPromptPrint(fin, fout, fintHistory ? "%%%d := " : "%%%d >> ", intStepNo); osSetBreakHandler(compFintBreakHandler0); ab = compFileFront(finfo, stab, fin, &lineno); breakSetRoot(ab); if (compIsMoreAfterFront(finfo) && !abIsEmptySequence(ab)) { ab = (AbSyn) fintWrap(ab, intStepNo); foam = compFileMiddle(finfo, stab, ab); if (foam) { Bool ok = fint(foam); if (ok && fintVerbose) fintPrintType(fout, ab); foamFree(foam); fintDisplayTimings(); } } comsgFini(); /* abFree(ab); !! ab is seeping into types. */ if (feof(fin)) { if (readingInitFile) { fclose(fin); fin = fin0; lineno = 0; readingInitFile = false; fintHistory = tmpHistory; intStepNo = 0; comsgFini(); } else endOfInput = true; } } totErrors = comsgErrorCount(); fintFini(); compFileFini(finfo); emitAllDone(); emitInfoFree(finfo); fnameFree(fn); compFini(); return totErrors; }
/* * Subsume options in response file into argument vector. * Only the slots 'argi0..*pargc-1 are treated as arguments. */ Bool cmdSubsumeResponseFiles(int argi0, int *pargc, String **pargv) { int nresps = 0, i; String *argv; String envopts; assert(*pargc >= 1); /* Copy the original args into a new r/w vector. * The extra slot is potentially used in handling AXIOMXLARGS. */ argv = (String *) stoAlloc(OB_Other, (*pargc+1) * sizeof(String *)); for (i = 0; i < *pargc; i++) argv[i] = strCopy((*pargv)[i]); *pargv = argv; /* Check for ALDORARGS/AXIOMXLARGS environment variable. */ envopts = osGetEnv("ALDORARGS"); if (!envopts) envopts = osGetEnv("AXIOMXLARGS"); if (envopts) { envopts = strCopy(envopts); for (i = *pargc - 1; i >= argi0; i--) (*pargv)[i+1] = (*pargv)[i]; (*pargv)[argi0] = strCopy("-aFake"); (*pargc)++; cmdOneResponse(pargc, pargv, envopts, argi0, argi0+1); nresps++; strFree(envopts); } while (cmdHasOption('a', NULL, *pargc, *pargv)) { String fileName = 0, fileText; FileName fn; int opt = 0, nextArg, startArg, j; for (nextArg = argi0, j = 0; ; ) { startArg = nextArg; opt = cmdGetOption(*pargc,*pargv, &nextArg,&j,&fileName); /* Have response file option by itself. */ if (optIs(opt, 'a')) break; /* Next option is response file option. Must be last */ else if (j > 0 && optIs((*pargv)[startArg][j], 'a')) { int oldStartArg = startArg, oldJ = j; startArg = nextArg; opt = cmdGetOption(*pargc,*pargv, &nextArg,&j,&fileName); (*pargv)[oldStartArg][oldJ] = '\0'; ++startArg; break; } } if (! fileName || ! fileName[0]) /* Can't use cmdUseError here - no msg db! */ comsgFatal(NULL,ALDOR_F_CmdBadOption,"-a",cmdName); fn = fnameParse(fileName); if (! fileIsReadable(fn)) comsgFatal(NULL, ALDOR_F_CantOpen, fileName); /* We now have an existing response file */ fileText = fileContentsString(fn); cmdOneResponse(pargc, pargv, fileText, startArg, nextArg); fileFreeContentsString(fileText); nresps++; } return nresps > 0; }