MGLabelWriter.mesa
Last Edited by: Kimr, October 1, 1984 11:10:16 am PDT
Last Edited by: Mayo, September 17, 1984 5:33:25 pm PDT
DIRECTORY
CD,
CDIO,
CDOrient,
CDImports,
Parquet,
Rope,
TerminalIO;
MGLabelWriter: CEDAR PROGRAM
IMPORTS CDIO, CDImports, Parquet, Rope, TerminalIO =
BEGIN
cellName: Rope.ROPE;
CellRef: TYPE = REF CellRec;
CellRec: TYPE = RECORD[
name: Rope.ROPE ← "ASTERISK",
tile: Parquet.Tile ← NIL,
inTileSet: BOOLEANTRUE
];
cellArray: ARRAY CHAR OF CellRef ← ALL[NEW[CellRec]] ;
WriteLabelCommand: Parquet.ModuleGeneratorProc =
PROC[context: Context] RETURNS [Module];
BEGIN
module: Parquet.Module;
pc, startOfLine: Parquet.PlacedTile;
objectName: Rope.ROPE;
label: Rope.ROPE ;
ch: CHAR;
length: INT;
[module: module, pc: pc] ← Parquet.NewModule[context];
import font design if necessary, making sure technologies match
{
fontDesign: CD.Design;
import: REF CDImports.Import ← NIL;
fileName: Rope.ROPE ← TerminalIO.RequestRope["Input font file -> "];
importeeName: Rope.ROPE;
TerminalIO.WriteRope["Reading font file\n"];
fontDesign ← CDIO.ReadDesign[from: fileName];
IF fontDesign = NIL THEN {
TerminalIO.WriteRope["Could not find font file.\n"];
RETURN[NIL];
};
importeeName ← fontDesign.name;
IF fontDesign.technology # context.eventualOwner.technology THEN {
TerminalIO.WriteRope["Font is not of appropriate technology\n"];
RETURN[NIL];
};
TerminalIO.WriteRope["Importing font file\n"];
import ← CDImports.GetImport[design: context.eventualOwner, importeeName: importeeName, createIfNotFound: false];
IF import=NIL OR import.importee=NIL THEN {
done: BOOL;
done ← CDImports.DoImport[design: context.eventualOwner, importee: fontDesign, allowConflicts: interactive];
import ← CDImports.GetImport[design: context.eventualOwner, importeeName: importeeName, createIfNotFound: false]
};
IF import=NIL OR import.importee=NIL THEN {
TerminalIO.WriteRope["Had trouble reading the font file.\n"];
RETURN[NIL];
};
context.tiles ← import.importee;
};
get label from user
label ← TerminalIO.RequestRope[" Input label -> "];
length ← Rope.Length[label];
place each character as an imported cell in the module
FOR i: INT ← 0, i+1 WHILE i < length DO
ch ← Rope.Fetch[label, i];
objectName ← cellArray[ch].name;
IF (cellArray[ch].tile = NIL) AND (cellArray[ch].inTileSet) THEN {
cellArray[ch].tile ← Parquet.InstantiateTile[context: context, cellName: objectName];
IF cellArray[ch].tile = NIL THEN
cellArray[ch].inTileSet ← FALSE;
};
IF cellArray[ch].inTileSet THEN {
pc ← Parquet.AdjacentTile[oldTile: pc, newTile: cellArray[ch].tile, dir: $rightOf];
IF i = 0 THEN
startOfLine ← pc;
}
ELSE {
TerminalIO.WriteRope[cellArray[ch].name];
TerminalIO.WriteRope[" not in tile set\n"];
};
ENDLOOP;
DO
label ← TerminalIO.RequestRope[" Input another label -> "];
length ← Rope.Length[label];
IF length = 0 THEN
RETURN [module];
FOR i: INT ← 0, i+1 WHILE i < length DO
ch ← Rope.Fetch[label, i];
objectName ← cellArray[ch].name;
IF (cellArray[ch].tile = NIL) AND (cellArray[ch].inTileSet) THEN {
cellArray[ch].tile ← Parquet.InstantiateTile[context: context, cellName: objectName];
IF cellArray[ch].tile = NIL THEN
cellArray[ch].inTileSet ← FALSE;
};
IF cellArray[ch].inTileSet AND i = 0 THEN {
pc ← Parquet.AdjacentTile[oldTile: startOfLine, newTile: cellArray[ch].tile, dir: $below];
startOfLine ← pc;
}
ELSE
IF cellArray[ch].inTileSet THEN
pc ← Parquet.AdjacentTile[oldTile: pc, newTile: cellArray[ch].tile, dir: $rightOf]
ELSE {
TerminalIO.WriteRope[cellArray[ch].name];
TerminalIO.WriteRope[" not in tile set\n"];
};
ENDLOOP;
ENDLOOP;
END;
Init: PROC[] = {
cellName ← "LA"; cellArray['a] ← NEW[CellRec]; cellArray['a].name ← cellName;
cellName ← "LB"; cellArray['b] ← NEW[CellRec]; cellArray['b].name ← cellName;
cellName ← "LC"; cellArray['c] ← NEW[CellRec]; cellArray['c].name ← cellName;
cellName ← "LD"; cellArray['d] ← NEW[CellRec]; cellArray['d].name ← cellName;
cellName ← "LE"; cellArray['e] ← NEW[CellRec]; cellArray['e].name ← cellName;
cellName ← "LF"; cellArray['f] ← NEW[CellRec]; cellArray['f].name ← cellName;
cellName ← "LG"; cellArray['g] ← NEW[CellRec]; cellArray['g].name ← cellName;
cellName ← "LH"; cellArray['h] ← NEW[CellRec]; cellArray['h].name ← cellName;
cellName ← "LI"; cellArray['i] ← NEW[CellRec]; cellArray['i].name ← cellName;
cellName ← "LJ"; cellArray['j] ← NEW[CellRec]; cellArray['j].name ← cellName;
cellName ← "LK"; cellArray['k] ← NEW[CellRec]; cellArray['k].name ← cellName;
cellName ← "LL"; cellArray['l] ← NEW[CellRec]; cellArray['l].name ← cellName;
cellName ← "LM"; cellArray['m] ← NEW[CellRec]; cellArray['m].name ← cellName;
cellName ← "LN"; cellArray['n] ← NEW[CellRec]; cellArray['n].name ← cellName;
cellName ← "LO"; cellArray['o] ← NEW[CellRec]; cellArray['o].name ← cellName;
cellName ← "LP"; cellArray['p] ← NEW[CellRec]; cellArray['p].name ← cellName;
cellName ← "LQ"; cellArray['q] ← NEW[CellRec]; cellArray['q].name ← cellName;
cellName ← "LR"; cellArray['r] ← NEW[CellRec]; cellArray['r].name ← cellName;
cellName ← "LS"; cellArray['s] ← NEW[CellRec]; cellArray['s].name ← cellName;
cellName ← "LT"; cellArray['t] ← NEW[CellRec]; cellArray['t].name ← cellName;
cellName ← "LU"; cellArray['u] ← NEW[CellRec]; cellArray['u].name ← cellName;
cellName ← "LV"; cellArray['v] ← NEW[CellRec]; cellArray['v].name ← cellName;
cellName ← "LW"; cellArray['w] ← NEW[CellRec]; cellArray['w].name ← cellName;
cellName ← "LX"; cellArray['x] ← NEW[CellRec]; cellArray['x].name ← cellName;
cellName ← "LY"; cellArray['y] ← NEW[CellRec]; cellArray['y].name ← cellName;
cellName ← "LZ"; cellArray['z] ← NEW[CellRec]; cellArray['z].name ← cellName;
cellName ← "UA"; cellArray['A] ← NEW[CellRec]; cellArray['A].name ← cellName;
cellName ← "UB"; cellArray['B] ← NEW[CellRec]; cellArray['B].name ← cellName;
cellName ← "UC"; cellArray['C] ← NEW[CellRec]; cellArray['C].name ← cellName;
cellName ← "UD"; cellArray['D] ← NEW[CellRec]; cellArray['D].name ← cellName;
cellName ← "UE"; cellArray['E] ← NEW[CellRec]; cellArray['E].name ← cellName;
cellName ← "UF"; cellArray['F] ← NEW[CellRec]; cellArray['F].name ← cellName;
cellName ← "UG"; cellArray['G] ← NEW[CellRec]; cellArray['G].name ← cellName;
cellName ← "UH"; cellArray['H] ← NEW[CellRec]; cellArray['H].name ← cellName;
cellName ← "UI"; cellArray['I] ← NEW[CellRec]; cellArray['I].name ← cellName;
cellName ← "UJ"; cellArray['J] ← NEW[CellRec]; cellArray['J].name ← cellName;
cellName ← "UK"; cellArray['K] ← NEW[CellRec]; cellArray['K].name ← cellName;
cellName ← "UL"; cellArray['L] ← NEW[CellRec]; cellArray['L].name ← cellName;
cellName ← "UM"; cellArray['M] ← NEW[CellRec]; cellArray['M].name ← cellName;
cellName ← "UN"; cellArray['N] ← NEW[CellRec]; cellArray['N].name ← cellName;
cellName ← "UO"; cellArray['O] ← NEW[CellRec]; cellArray['O].name ← cellName;
cellName ← "UP"; cellArray['P] ← NEW[CellRec]; cellArray['P].name ← cellName;
cellName ← "UQ"; cellArray['Q] ← NEW[CellRec]; cellArray['Q].name ← cellName;
cellName ← "UR"; cellArray['R] ← NEW[CellRec]; cellArray['R].name ← cellName;
cellName ← "US"; cellArray['S] ← NEW[CellRec]; cellArray['S].name ← cellName;
cellName ← "UT"; cellArray['T] ← NEW[CellRec]; cellArray['T].name ← cellName;
cellName ← "UU"; cellArray['U] ← NEW[CellRec]; cellArray['U].name ← cellName;
cellName ← "UV"; cellArray['V] ← NEW[CellRec]; cellArray['V].name ← cellName;
cellName ← "UW"; cellArray['W] ← NEW[CellRec]; cellArray['W].name ← cellName;
cellName ← "UX"; cellArray['X] ← NEW[CellRec]; cellArray['X].name ← cellName;
cellName ← "UY"; cellArray['Y] ← NEW[CellRec]; cellArray['Y].name ← cellName;
cellName ← "UZ"; cellArray['Z] ← NEW[CellRec]; cellArray['Z].name ← cellName;
cellName ← "N1"; cellArray['1] ← NEW[CellRec]; cellArray['1].name ← cellName;
cellName ← "N2"; cellArray['2] ← NEW[CellRec]; cellArray['2].name ← cellName;
cellName ← "N3"; cellArray['3] ← NEW[CellRec]; cellArray['3].name ← cellName;
cellName ← "N4"; cellArray['4] ← NEW[CellRec]; cellArray['4].name ← cellName;
cellName ← "N5"; cellArray['5] ← NEW[CellRec]; cellArray['5].name ← cellName;
cellName ← "N6"; cellArray['6] ← NEW[CellRec]; cellArray['6].name ← cellName;
cellName ← "N7"; cellArray['7] ← NEW[CellRec]; cellArray['7].name ← cellName;
cellName ← "N8"; cellArray['8] ← NEW[CellRec]; cellArray['8].name ← cellName;
cellName ← "N9"; cellArray['9] ← NEW[CellRec]; cellArray['9].name ← cellName;
cellName ← "N0"; cellArray['0] ← NEW[CellRec]; cellArray['0].name ← cellName;
cellName ← "SLASH"; cellArray['/ ] ← NEW[CellRec]; cellArray['/].name ← cellName;
cellName ← "LEFTPAREN"; cellArray['(] ← NEW[CellRec]; cellArray['(].name ← cellName;
cellName ← "COLON"; cellArray[':] ← NEW[CellRec]; cellArray[':].name ← cellName;
cellName ← "RIGHTPAREN"; cellArray[')] ← NEW[CellRec]; cellArray[')].name ← cellName;
cellName ← "COMMA"; cellArray[',] ← NEW[CellRec]; cellArray[',].name ← cellName;
cellName ← "PERIOD"; cellArray['.] ← NEW[CellRec]; cellArray['.].name ← cellName;
cellName ← "SPLAT"; cellArray['#] ← NEW[CellRec]; cellArray['.].name ← cellName;
cellName ← "DOLLARSIGN"; cellArray['$] ← NEW[CellRec]; cellArray['.].name ← cellName;
cellName ← "EXCLMARK"; cellArray['!] ← NEW[CellRec]; cellArray['.].name ← cellName;
cellName ← "PERCENT"; cellArray['%] ← NEW[CellRec]; cellArray['.].name ← cellName;
cellName ← "AMPERSAND"; cellArray['&] ← NEW[CellRec]; cellArray['.].name ← cellName;
cellName ← "ASTERISK"; cellArray['*] ← NEW[CellRec]; cellArray['.].name ← cellName;
cellName ← "QUESTIONMARK"; cellArray['?] ← NEW[CellRec]; cellArray['.].name ← cellName;
[] ← Parquet.RegisterGenerator[generatorName: "WriteLabel", proc: WriteLabelCommand, needsTiles: FALSE];
};
Init[];
END.