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"];
reportStrm.PutRope["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;
now for file names and perhaps following local switches
start at the top of this loop with a file name
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;
look at switches
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"];
reportStrm.PutRope["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]]];
reportStrm.PutF["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;
};
FullNameWithExt:
PUBLIC PROC[preferred, other, wDir, ext:
ROPE]
RETURNS[fullName: ROPE] = {
IF preferred = NIL THEN use other as basis for name;
IF other used, then strip any existing extension and append ext
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] ]
};