<> <> <> DIRECTORY BcdDefs: TYPE USING [VersionStamp], IO: TYPE USING [PutChar, PutDecimal, PutString], Exec: TYPE USING [CommandLine, AddCommand, commandLine, w], IO: TYPE USING [Create, GetLeaderProperties], UnsafeStorage: TYPE USING [GetSystemUZone], OSMiscOps: TYPE USING [FileError, FindFile, GenerateUniqueId], PGSConDefs: TYPE USING [], Runtime: TYPE USING [GetBcdTime], IO: TYPE USING [Handle, Delete], ConvertUnsafe: TYPE USING [ String, SubStringDescriptor, AppendChar, AppendString, EquivalentSubStrings], TableCommand: TYPE USING [CompileStrings, MakeModule], Time: TYPE USING [Append, Current, Unpack], TTY: TYPE USING [Handle, PutChar, PutDecimal], UserTerminal: TYPE USING [CursorArray, GetCursorPattern, SetCursorPattern]; TableControl: PROGRAM IMPORTS IO, Exec, IO, UnsafeStorage, OSMiscOps, Runtime, IO, ConvertUnsafe, TableCommand, Time, TTY, UserTerminal EXPORTS TableCommand, PGSConDefs = { <> savedCursor: UserTerminal.CursorArray; TableCursor: UserTerminal.CursorArray = [ 177777b, 177777b, 177777b, 160007b, 160007b, 160007b, 160007b, 160007b, 160007b, 160007b, 160007b, 160007b, 160007b, 177777b, 177777b, 177777b]; <> zone: PUBLIC UNCOUNTED ZONE; Rubout: ERROR = CODE; CommandEnded: PROC RETURNS [BOOL] = { RETURN [command.i >= command.s.Length[]]}; CommandChar: PROC RETURNS [char: CHAR] = { IF command.i < command.s.Length[] THEN { char _ command.s[command.i]; command.i _ command.i+1} ELSE char _ '\000; RETURN}; ReadCommand: PROC [command: Rope.ROPE] RETURNS [name, switches: Rope.ROPE, BOOL] = { input: Rope.ROPE _ [80]; i: CARDINAL; c: CHAR; activeString: Rope.ROPE _ name; DO IF CommandEnded[] THEN EXIT; c _ CommandChar[]; SELECT c FROM ' => IF input.Length[] # 0 THEN EXIT; IO.CR => EXIT; ENDCASE => ConvertUnsafe.AppendChar[input, c]; ENDLOOP; i _ name.Length[] _ switches.Length[] _ 0; WHILE i < input.Length[] AND input[i] = ' DO i _ i+1 ENDLOOP; --parse command-- FOR i IN [i..input.Length[]) DO SELECT (c_input[i]) FROM '/ => activeString _ switches; ' , IO.CR => EXIT; ENDCASE => ConvertUnsafe.AppendChar[activeString,c]; ENDLOOP; FOR i IN [0..switches.Length[]) DO -- convert all to lower case IF (c_switches[i]) IN ['A..'Z] THEN switches[i] _ VAL[(c.ORD -'A.ORD) + 'a.ORD]; ENDLOOP; RETURN [name.Length[] # 0 OR switches.Length[] # 0]}; ExtensionIs: PROC [name, ext: Rope.ROPE] RETURNS [BOOL] = { RETURN[Rope.Find[s1: name, s2: ext, case: FALSE] > -1]}; GenerateVersion: PUBLIC PROC RETURNS [version: BcdDefs.VersionStamp] = { RETURN [OSMiscOps.GenerateUniqueId[]]}; WriteHerald: PROC[stream: IO.STREAM] = { stream.PutRope["Cedar 3.3 Table Compiler of "]; stream.Put[IO.time[Runtime.GetBcdTime[]], IO.char[IO.CR]]; stream.PutRope[IO.rope["TableCompiler.log -- "] IO.time[], IO.char[IO.CR]]}; <> warningsLogged: PUBLIC BOOL; seterrstream, resetoutstream: PUBLIC PROC = {NULL}; outeol: PUBLIC PROC [n: INTEGER] = { THROUGH [1..n] DO log.PutChar['\n] ENDLOOP}; outstring: PUBLIC PROC [string: Rope.ROPE] = log.PutRope; <> sourceName: PUBLIC Rope.ROPE _ NIL; pgsVersion: PUBLIC BcdDefs.VersionStamp _ [0, 0, Runtime.GetBcdTime[]]; sourceVersion: PUBLIC BcdDefs.VersionStamp _ [0, 0, 0]; objectVersion: PUBLIC BcdDefs.VersionStamp _ [0, 0, 0]; Main: SAFE PROC [Commander.Handle] = TRUSTED { input: {strings, binary}; -- compiling strings compact: BOOL; dStar: BOOL; rootName: Rope.ROPE; interfaceName: Rope.ROPE; formatName: Rope.ROPE; bcdName: Rope.ROPE; GetCommand: PROC = { file: Rope.ROPE; sw: Rope.ROPE; i: CARDINAL; c: CHAR; done: BOOL _ FALSE; sense: BOOL; GetSwitch: PROC RETURNS [c: CHAR] = { sense _ TRUE; WHILE i < sw.Length[] DO c _ sw.Fetch[i]; i _ i + 1; IF c = '- OR c = '~ THEN sense _ ~sense ELSE EXIT; ENDLOOP; RETURN}; sourceName _ NIL; dStar _ TRUE; [file, sw] _ ReadCommand[cmd.commandLine]; IF sw.Length[] = 0 AND file.Length[] = 0 THEN RETURN; CommandUtil.SetExtension[file, "mesa"]; IF ExtensionIs[file, ".mesa"] THEN {input _ $strings; compact _ TRUE} ELSE input _ $binary; i _ 0; WHILE i < sw.Length[] DO SELECT (c_GetSwitch[]) FROM 'a => dStar _ ~sense; 'c => compact _ sense; 'm => input _ $binary; 's => {input _ $strings; compact _ FALSE}; 't => {input _ $strings; compact _ TRUE}; 'g => done _ TRUE; ENDCASE => GO TO barf; REPEAT barf => ERROR Rubout; ENDLOOP; sourceName _ file; WHILE ~done AND ReadCommand[file, sw] DO [file, sw] _ ReadCommand[cmd.commandLine] i _ 0; WHILE i < sw.Length[] DO SELECT (c_GetSwitch[]) FROM 'f => formatName _ file _ CommandUtil.SetExtension[file, "format"]; 'i => interfaceName _ file _ CommandUtil.SetExtension[file, "bcd"]; 'o => bcdName _ file _ CommandUtil.SetExtension[file, "bcd"]; 'g => done _ TRUE; ENDCASE => ERROR Rubout; ENDLOOP; ENDLOOP}; LogCommand: PROC = { SELECT input FROM $strings => { log.PutRope["\nCompiling "]; log.PutRope[sourceName]; log.PutRope[", exporting "]; log.PutRope[rootName]; log.PutRope[" to "]; log.PutRope[interfaceName]; IF bcdName.Length[] # 0 THEN {log.PutRope[", BCD to "]; log.PutRope[bcdName]}; log.PutRope["\nRecord format on "]; log.PutRope[formatName]}; $binary => { log.PutRope["\nProcessing "]; log.PutRope[sourceName]; log.PutRope[", exporting "]; log.PutRope[rootName]; log.PutRope[" to "]; log.PutRope[interfaceName]; IF bcdName.Length[] # 0 THEN {log.PutRope[", BCD to "]; log.PutRope[bcdName]}}; ENDCASE; log.PutChar[IO.CR]}; <> zone _ UnsafeStorage.GetSystemUZone[]; command _ Exec.commandLine; log _ FileIO.Open["TableCompiler.log", write]; WriteHerald[]; <
> DO BEGIN ENABLE OSMiscOps.FileError => { log.PutRope["Can't open "]; log.PutRope[name]; log.PutChar[IO.CR]; GO TO FileFault}; GetCommand[ ! Rubout => {GOTO Abort}]; IF sourceName = NIL THEN EXIT; rootName.Length[] _ 0; FOR i: CARDINAL IN [0..sourceName.Length[]) DO IF sourceName[i] = '. THEN EXIT; ConvertUnsafe.AppendChar[rootName, sourceName[i]]; ENDLOOP; IF interfaceName.Length[] = 0 THEN ConvertUnsafe.AppendString[interfaceName, "SELF"]; IF formatName.Length[] = 0 THEN { ConvertUnsafe.AppendString[formatName, rootName]; ConvertUnsafe.AppendString[formatName, "Format."]}; LogCommand[]; IF bcdName.Length[] = 0 THEN { ConvertUnsafe.AppendString[bcdName, rootName]; ConvertUnsafe.AppendString[bcdName, ".bcd"]}; savedCursor _ UserTerminal.GetCursorPattern[]; UserTerminal.SetCursorPattern[TableCursor]; SELECT input FROM $strings => { nChars, nStrings: CARDINAL; [nStrings, nChars] _ TableCommand.CompileStrings[ inputFile: sourceName, interfaceId: interfaceName, formatId: formatName, moduleId: bcdName, compact: compact, altoCode: ~dStar]; log.PutRope["ConvertUnsafe: "]; log.Put[IO.int[[nStrings]]; log.PutRope[", characters: "]; log.Put[IO.int[[nChars]]; log.PutChar[IO.CR]}; $binary => TableCommand.MakeModule[ inputFile: sourceName, interfaceId: interfaceName, moduleId: bcdName, altocode: ~dStar]; ENDCASE; log.PutChar[IO.CR]; UserTerminal.SetCursorPattern[savedCursor]; EXITS FileFault => NULL; Abort => log.PutChar['?]; END; IF sourceName # NIL THEN zone.FREE[@sourceName]; ENDLOOP; IF log # NIL THEN IO.Delete[log]; zone _ NIL}; Commander.Register["TableCompiler", Main, NIL]; }.