<> <> <> DIRECTORY Commander: TYPE USING [Handle, Register], CommandUtil: TYPE USING [ Echo, Failed, GetNth, GetSwitches, ListLength, PairList, Parse, SetExtension, Switches], IO: TYPE USING [char, CR, Put, PutChar, PutRope, rope, STREAM, time, UserAbort], ListerOps: TYPE USING [ListProc], ListerUtil: TYPE USING [SetTypescript], OSMiscOps: TYPE USING [BcdCreateTime], Rope: TYPE USING [Find, Length, ROPE, Substr]; CLControl: PROGRAM IMPORTS Commander, CommandUtil, IO, ListerOps, ListerUtil, OSMiscOps, Rope = { <> StandardDefaults: PACKED ARRAY CHAR ['a..'z] OF BOOL = ALL[FALSE]; <> <> <> <> <> <> DoCommand: SAFE PROC[cmd: Commander.Handle] = TRUSTED { switches: Rope.ROPE; results: CommandUtil.PairList; rootName, procName: Rope.ROPE; inputName, outputName: Rope.ROPE; commandArgs: CommandUtil.PairList; localSwitches: CommandUtil.Switches; defaultSwitches: CommandUtil.Switches _ StandardDefaults; WriteHerald: PROC [stream: IO.STREAM, id: Rope.ROPE] = { stream.Put[ IO.rope["Cedar 3.4 Symbol Lister of "], IO.time[OSMiscOps.BcdCreateTime[]], IO.char[IO.CR]]; IF id # NIL THEN stream.Put[IO.rope[id], IO.rope[" -- "]]; stream.Put[IO.time[], IO.char[IO.CR]]}; RepeatCommand: PROC [s: IO.STREAM] = { IO.PutRope[s, "\nListing "]; IO.PutRope[s, inputName]; IO.PutRope[s, ", output to "]; IO.PutRope[s, outputName]; IO.PutChar[s, IO.CR]}; ExtractParts: PROC [s: Rope.ROPE] RETURNS [root, rest: Rope.ROPE] = { dotIndex: INT _ Rope.Find[s, "."]; IF dotIndex < 0 THEN RETURN[s, NIL]; root _ Rope.Substr[s, 0, dotIndex]; rest _ Rope.Substr[s, dotIndex+1, s.Length[] - dotIndex - 1]}; ListerUtil.SetTypescript[cmd.out]; WriteHerald[cmd.out, NIL]; <
> DO { Initialize: PROC = INLINE {RepeatCommand[cmd.out]}; Finalize: PROC = INLINE {}; [inputName, commandArgs, results, switches] _ CommandUtil.Parse[cmd.commandLine ! CommandUtil.Failed => {GO TO badSyntax}]; IF inputName = NIL AND switches = NIL THEN EXIT; -- done listing cmd.out.PutRope["\nCommand: "]; CommandUtil.Echo[ d: cmd.out, operator: inputName, argList: commandArgs, resultList: results, switches: switches]; IF inputName = NIL THEN GO TO globalSwitches; SELECT CommandUtil.ListLength[results] FROM 0 => outputName _ NIL; 1 => outputName _ CommandUtil.GetNth[list: results, n: 0]; ENDCASE => GO TO badSemantics; [rootName, procName] _ ExtractParts[inputName]; localSwitches _ CommandUtil.GetSwitches[switches, defaultSwitches]; IF outputName = NIL THEN outputName _ rootName; outputName _ CommandUtil.SetExtension[outputName, "cl"]; Initialize[]; ListerUtil.SetTypescript[cmd.out]; ListerOps.ListProc[ input: rootName, proc: procName, output: outputName, options: [ full: localSwitches['h] OR localSwitches['o], stripped: localSwitches['s], radix: IF localSwitches['h] THEN hex ELSE octal] ! UNWIND => Finalize[]]; Finalize[]; IF cmd.in.UserAbort[] THEN EXIT; EXITS globalSwitches => { defaultSwitches _ CommandUtil.GetSwitches[switches, defaultSwitches]; switches _ NIL; results _ NIL}; badSemantics => { results _ NIL; cmd.out.PutRope["\n -- Illegal command"]}}; REPEAT badSyntax => {cmd.out.PutRope["-- Illegal syntax"]}; ENDLOOP; }; <> Commander.Register["cl", DoCommand, "Produces a code listing for a .bcd file."]; Commander.Register["CodeLister", DoCommand, "Produces a code listing for a .bcd file."]; }.