InitMicroDVars:
PUBLIC PROC[cmdLine, wDir:
ROPE, argv: CommandTool.ArgumentVector]
RETURNS[srcFileList: SrcFile, ok: BOOL, start: BasicTime.GMT] = {
lastFileName: ROPE;
i: NAT ← 1;
lastSrcFile: SrcFile ← NIL;
ok ← FALSE;
fatalErrors ← FALSE;
listingLevel ← listFull;
srcFileList ← NIL;
outFile ← NEW[OutputFileRec];
savedWDir ← wDir;
reportStrm ← TSStream["MicroD"];
StartupMessage[reportStrm, cmdLine, start ← BasicTime.Now[]];
IF argv.argc = 1
THEN {
reportStrm.PutRope["Command line is empty - quitting\n"];
RETURN
};
DO
-- global switches
arg: ROPE = argv[i];
IF arg.Fetch[0] # '- THEN EXIT;
ParseGlobalFlags[arg];
i ← i + 1;
ENDLOOP;
now for file names and perhaps following local switches
DO
arg: ROPE;
arg ← argv[i];
IF arg.Fetch[0] = '- THEN {
look at switches
ch: CHAR;
SELECT ch ← arg.Fetch[1]
FROM
-- is switch
'~ => ParseGlobalFlags[arg];
'A, 'a => lastSrcFile.listingFlag ← listAbsOnly;
'C, 'c => lastSrcFile.listingFlag ← listConcise;
'L, 'l => lastSrcFile.listingFlag ← listFull;
'N, 'n => lastSrcFile.listingFlag ← listNotIM;
'O, 'o => {
outFile.fullName ← FullNameWithExt[NIL, lastFileName, wDir, "MB"];
lastFileName ← NIL
};
ENDCASE =>
MDOps.Report[infoOnly,
IO.PutFR["\n Unknown local switch (%g)\n", IO.char[ch]]];
}
ELSE {
-- fileName
IF lastFileName #
NIL
THEN {
srcFile: SrcFile ←
NEW[SrcFileRec ← [fullName: lastFileName, listingFlag: listingLevel]];
IF srcFileList =
NIL
THEN srcFileList ← lastSrcFile ← srcFile
ELSE { lastSrcFile.next ← srcFile; lastSrcFile ← lastSrcFile.next };
};
lastFileName ← arg;
};
i ← i + 1;
IF i >= argv.argc THEN EXIT; -- finished
ENDLOOP;
IF lastFileName #
NIL
THEN {
srcFile: SrcFile ← NEW[SrcFileRec ← [fullName: lastFileName]];
IF srcFileList =
NIL
THEN srcFileList ← lastSrcFile ← srcFile
ELSE { lastSrcFile.next ← srcFile; lastSrcFile ← lastSrcFile.next };
};
IF srcFileList =
NIL
THEN {
reportStrm.PutRope["No source files - quitting\n"];
RETURN
};
lastFileName ← lastSrcFile.fullName;
IF listingLevel # -2
AND outFile.fullName =
NIL
THEN {
outFile.fullName ← FullNameWithExt[NIL, lastFileName, wDir, "mb"];
};
listingFile ← NEW[OutputFileRec];
listingFile.fullName ← FullNameWithExt[outFile.fullName, lastFileName, wDir, "dls"];
listingFile.strm ← FS.StreamOpen[listingFile.fullName, $create];
StartupMessage[listingFile.strm, cmdLine, start];
IF mapIM
THEN {
mapFile ← NEW[OutputFileRec];
mapFile.fullName ← FullNameWithExt[outFile.fullName, lastFileName, wDir, "csMap"];
}
ELSE mapFile ← NIL;
IF mapRM
THEN {
regsFile ← NEW[OutputFileRec];
regsFile.fullName ← FullNameWithExt[outFile.fullName, lastFileName, wDir, "regs"];
}
ELSE regsFile ← NIL;
IF mapOccupied
THEN {
occupiedFile ← NEW[OutputFileRec];
occupiedFile.fullName ←
FullNameWithExt[outFile.fullName, lastFileName, wDir, "occupiedMC"];
}
ELSE occupiedFile ← NIL;
IF mapChart
THEN {
chartFile ← NEW[OutputFileRec];
chartFile.fullName ← FullNameWithExt[outFile.fullName, lastFileName, wDir, "csChart"];
}
ELSE chartFile ← NIL;
IF listAbs
THEN {
absFile ← NEW[OutputFileRec];
absFile.fullName ← FullNameWithExt[outFile.fullName, lastFileName, wDir, "absDLS"];
}
ELSE absFile ← NIL;
ok ← TRUE;
FOR sfl: SrcFile ← srcFileList, sfl.next
UNTIL sfl =
NIL
DO
sfl.fullName ← FullNameWithExt[sfl.fullName, NIL, wDir, "dib"];
sfl.of ←
FS.Open[sfl.fullName !
FS.Error =>
{ MDOps.Report[infoOnly, error.explanation]; ok ← FALSE; CONTINUE } ];
IF ~ok THEN RETURN;
sfl.createDate ← FS.GetInfo[sfl.of].created;
ENDLOOP;
ok ← TRUE;
};
StartupMessage:
PROC[out:
STREAM, cmdLine:
ROPE, start: BasicTime.
GMT] = {
out.PutRope["\n\n**********************************************************\n"];
out.PutF["\t\t MicroD (microcode placer) of %g, started @ %g\n",
IO.time[Loader.BCDBuildTime[MDInitImpl.StartupMessage]], IO.time[start]];
out.PutRope["Command is: "];
out.PutRope[cmdLine]; out.PutChar['\n];
};
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 ← ext # 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] ]
};