MDInitImpl.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Willie-sue, September 29, 1987 4:33:38 pm PDT
taken from mdinit.bcpl
DIRECTORY
BasicTime USING [GMT, Now],
CommandTool USING [ArgumentVector],
FS USING [ComponentPositions, Error, OpenFile, ExpandName, GetInfo, Open, StreamOpen],
IO,
Loader USING [BCDBuildTime],
Rope,
ViewerClasses USING [Viewer],
ViewerIO USING [CreateViewerStreams],
ViewerOps USING [FindViewer, OpenIcon],
MDDefs,
MDGlobalVars,
MDOps;
MDInitImpl: CEDAR PROGRAM
IMPORTS
BasicTime, FS, IO, Loader, Rope, ViewerIO, ViewerOps,
MDGlobalVars, MDOps
EXPORTS
MDOps
= BEGIN OPEN MDDefs, MDGlobalVars;
savedWDir: ROPENIL;
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;
};
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 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: ROPEIF 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] ]
};
ParseGlobalFlags: PROC[arg: ROPE] = {
ch: CHAR;
FOR j: INT IN [1..arg.Length[]) DO
SELECT ch ← arg.Fetch[j] FROM
'A, 'a => listingLevel ← listAbsOnly;
'C, 'C => listingLevel ← listConcise;
'E, 'e => mapChart ← TRUE;  -- chart Every location
'H, 'h => listAbs ← TRUE;   -- abs listing for Hardware debugging
'I, 'i => ignoreOnPage ← TRUE; -- Ignore OnPage directives
'M, 'm => mapIM ← TRUE;   -- Map of IM by page
'N, 'n => listingLevel ← listNotIM; -- No IM listing
'O, 'o => mapOccupied ← TRUE;  -- write Occupied location map
'P, 'P => listingLevel ← listPrintMB; -- just Print the .MBs
'R, 'r => mapRM ← TRUE;   -- RM Map
'S, 's => listSymbols ← TRUE;  -- Symbols for all memories
'X, 'x => external ← TRUE;   -- allow eXternal references
'~ => NULL;  -- signals additional global switches
ENDCASE =>
MDOps.Report[infoOnly,
IO.PutFR["\n Unknown global switch (%g)\n", IO.char[ch]]];
ENDLOOP;
};
END.