<> <> <> <> <> DIRECTORY BasicTime USING [GMT, Now], CommandTool USING [ArgumentVector], FS USING [ComponentPositions, Error, nullOpenFile, OpenFile, Close, ExpandName, Open, StreamOpen], IO, Rope, ViewerClasses USING [Viewer], ViewerIO USING [CreateViewerStreams], ViewerOps USING [FindViewer, OpenIcon], MicroDefs, MicroGlobalVars, MicroOps, MicroUtils USING []; MicroInitImpl: CEDAR PROGRAM IMPORTS BasicTime, FS, IO, Rope, ViewerIO, ViewerOps, MicroDefs, MicroGlobalVars, MicroOps EXPORTS MicroOps, MicroUtils = BEGIN OPEN MicroDefs, MicroGlobalVars; savedWDir: ROPE _ NIL; InitMicroVars: PUBLIC PROC[cmdLine, wDir: ROPE, argv: CommandTool.ArgumentVector] RETURNS[srcFileList: SrcFile, ok: BOOL, start: BasicTime.GMT] = { fixFile, mbFile, rsFile, lsFile, erFile, stFile, lastFileName: ROPE; xListF, ltoF, rsF, ucF: BOOL _ FALSE; binF, stF: BOOL _ TRUE; i: NAT _ 1; lastSrcFile: SrcFile _ NIL; ok _ FALSE; srcFileList _ NIL; errorFileRec _ fixupsFileRec _ listingFileRec _ symbolsFileRec _ NIL; savedWDir _ wDir; reportStrm _ TSStream["Micro Assembler"]; StartupMessage[reportStrm, cmdLine, start _ BasicTime.Now[]]; IF argv.argc = 1 THEN { SIGNAL MicroDefs.Failure["Command line is empty - quitting\n"]; <> RETURN }; DO -- global switches arg: ROPE _ argv[i]; IF arg.Fetch[0] # '- THEN EXIT; FOR j: INT IN [1..arg.Length[]) DO SELECT arg.Fetch[j] FROM 'L, 'l => xListF _ TRUE; 'N, 'n => binF _ FALSE; 'O, 'o => stF _ FALSE; 'U, 'u => ucF _ TRUE; ENDCASE => NULL; ENDLOOP; i _ i + 1; ENDLOOP; <<>> <> <> DO src: BOOL _ TRUE; ucF: BOOL _ FALSE; IF i >= argv.argc THEN EXIT; -- finished lastFileName _ argv[i]; i _ i + 1; DO arg: ROPE; IF i >= argv.argc THEN EXIT; -- finished arg _ argv[i]; IF arg.Fetch[0] # '- THEN EXIT; <> SELECT arg.Fetch[1] FROM -- is switch 'B, 'b => { binF _ TRUE; mbFile _ lastFileName; src _ FALSE }; 'L, 'l => { xListF _ TRUE; lsFile _ lastFileName; src _ FALSE }; 'E, 'e => { erFile _ lastFileName; src _ FALSE }; 'S, 's => { stF _ TRUE; stFile _ lastFileName; src _ FALSE }; 'R, 'r => { rsF _ TRUE; rsFile _ lastFileName; src _ FALSE }; 'U, 'u => ucF _ TRUE; ENDCASE => NULL; i _ i + 1; ENDLOOP; IF src THEN { srcFile: SrcFile _ NEW[SrcFileRec _ [fullName: lastFileName, upperCaseFlag: ucF]]; IF srcFileList = NIL THEN srcFileList _ lastSrcFile _ srcFile ELSE { lastSrcFile.next _ srcFile; lastSrcFile _ lastSrcFile.next }; }; ENDLOOP; IF srcFileList = NIL THEN { SIGNAL MicroDefs.Failure["No source files - quitting\n"]; <> RETURN }; IF rsFile # NIL THEN { -- check if the restore symbols file exists of: FS.OpenFile _ FS.nullOpenFile; rsFile _ FullNameWithExt[rsFile, NIL, wDir, "st"]; of _ FS.Open[rsFile ! FS.Error => CONTINUE]; IF of = FS.nullOpenFile THEN { SIGNAL MicroDefs.Failure[IO.PutFR["Could not open %g - quitting\n", IO.rope[rsFile]]]; <> RETURN; }; FS.Close[of ! FS.Error => CONTINUE]; restoreSymbolsFile _ rsFile; } ELSE restoreSymbolsFile _ NIL; <<>> mbFile _ FullNameWithExt[mbFile, lastFileName, wDir, ""]; erFile _ FullNameWithExt[erFile, mbFile, wDir, "er"]; IF xListF THEN lsFile _ FullNameWithExt[lsFile, mbFile, wDir, "ls"]; stFile _ FullNameWithExt[stFile, mbFile, wDir, "st"]; fixFile _ FullNameWithExt["Micro.fixups", NIL, wDir, ""]; FOR sfl: SrcFile _ srcFileList, sfl.next UNTIL sfl = NIL DO sfl.fullName _ FullNameWithExt[sfl.fullName, NIL, wDir, "mc"] ENDLOOP; errorFileRec _ NEW[OutputFileRec _ [fullName: erFile] ]; errorFileRec.strm _ FS.StreamOpen[fileName: erFile, accessOptions: $create, keep: 2]; StartupMessage[errorFileRec.strm, cmdLine, start]; fixupsFileRec _ NEW[OutputFileRec _ [fullName: fixFile] ]; IF lsFile # NIL THEN { listingFileRec _ NEW[OutputFileRec _ [fullName: lsFile] ]; listingFileRec.strm _ FS.StreamOpen[fileName: lsFile, accessOptions: $create, keep: 2]; }; IF stF THEN { symbolsFileRec _ NEW[OutputFileRec _ [fullName: stFile] ]; symbolsFileRec.strm _ FS.StreamOpen[fileName: stFile, accessOptions: $create, keep: 2]; }; binaryFile _ NEW[OutputFileRec _ [fullName: mbFile] ]; expandedListingFlag _ xListF; writeBinaryFlag _ binF; convertToUpperFlag _ ucF; errorCount _ 0; ok _ TRUE; }; InPushFile: PUBLIC PROC[fileName: ROPE] RETURNS[fullName: ROPE, fileOK: BOOL] = { srcFile: SrcFile; fullName _ FS.ExpandName[fileName, savedWDir].fullFName; srcFile _ NEW[SrcFileRec _ [fullName: fullName, upperCaseFlag: convertToUpperFlag]]; fileOK _ MicroOps.InPush[srcFile]; }; TSStream: PROC[name: ROPE] RETURNS [out: STREAM] = { v: ViewerClasses.Viewer _ ViewerOps.FindViewer[name]; out _ ViewerIO.CreateViewerStreams[name, v].out; IF v#NIL THEN IF v.iconic THEN ViewerOps.OpenIcon[v]; }; StartupMessage: PROC[out: STREAM, cmdLine: ROPE, start: BasicTime.GMT] = { out.PutRope["\n\n**********************************************************\n"]; out.PutF["\t\t Micro Assembler, started @ %g\n", IO.time[start]]; out.PutRope["Command is: "]; out.PutRope[cmdLine]; out.PutChar['\n]; }; FullNameWithExt: PUBLIC PROC[preferred, other, wDir, ext: ROPE] RETURNS[fullName: ROPE] = { <> <> forceExt: BOOL _ preferred = NIL; basis: ROPE _ IF preferred # NIL THEN preferred ELSE other; cp: FS.ComponentPositions; IF basis = NIL THEN RETURN; [fullName, cp, ] _ FS.ExpandName[basis, wDir]; IF cp.ext.length # 0 THEN IF ~forceExt THEN RETURN ELSE fullName _ Rope.Substr[fullName, 0, cp.ext.start-1]; RETURN[IF ext.Length[] = 0 THEN fullName ELSE fullName.Cat[".", ext] ] }; END.