MTDriver.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Hal Murray May 27, 1985 8:03:30 pm PDT
Last Edited by: HGM, February 8, 1985 3:52:11 am PST
Last Edited by: Nichols, July 18, 1983 3:44 pm
Last Edited by: Taft, February 5, 1984 2:26:50 pm PST
DIRECTORY
Ascii USING [Lower],
Commander USING [CommandProc, Register],
CommandTool USING [ArgumentVector, Failed, Parse],
FS USING [Error, StreamOpen],
IO USING [Close, EndOf, GetChar, GetIndex, PeekChar, PutChar, PutRope, SetIndex, STREAM],
MT USING [Direction, Info, ParseHeaders, PrintHeaders, TranslateMessage, TranslateToArpa, TranslateToGrapevine],
Process USING [CheckForAbort],
Rope USING [Fetch, Length, ROPE];
MTDriver: CEDAR PROGRAM
IMPORTS Ascii, Commander, CommandTool, FS, IO, MT, Process, Rope
= BEGIN
Translate: Commander.CommandProc = {
Take a file that contains a message and do the translation. Syntax is "translate -a file" or "translate -g file".
argv: CommandTool.ArgumentVector = CommandTool.Parse[cmd !
CommandTool.Failed => {cmd.out.PutRope[errorMsg]; GOTO GoAway}];
direction: MT.Direction ← toArpa;
FOR i: NAT IN [1..argv.argc) DO
IF argv[i].Fetch[0] = '- THEN
SELECT Ascii.Lower[argv[i].Fetch[1]] FROM
'a => direction ← toArpa;
'g => direction ← toGrapevine;
ENDCASE
ELSE BEGIN
file: IO.STREAM ← FS.StreamOpen[argv[i] !
FS.Error => {cmd.out.PutRope[error.explanation]; LOOP}];
MT.TranslateMessage[file, cmd.out, cmd.out, direction, "Foo"];
file.Close[];
END;
ENDLOOP;
EXITS
GoAway => NULL };
Headers: Commander.CommandProc = {
Parse a file that contains a message show all forms of the headers.
argv: CommandTool.ArgumentVector = CommandTool.Parse[cmd !
CommandTool.Failed => {cmd.out.PutRope[errorMsg]; GOTO GoAway}];
FOR i: NAT IN [1..argv.argc) DO
file: IO.STREAM ← FS.StreamOpen[argv[i] !
FS.Error => {cmd.out.PutRope[error.explanation]; LOOP}];
info: MT.Info ← MT.ParseHeaders[file, cmd.out];
file.Close[];
cmd.out.PutRope["Raw: \n"];
MT.PrintHeaders[info, cmd.out];
cmd.out.PutRope["Arpa: \n"];
MT.TranslateToArpa[info];
MT.PrintHeaders[info, cmd.out];
cmd.out.PutRope["GV: \n"];
MT.TranslateToGrapevine[info];
MT.PrintHeaders[info, cmd.out];
file.Close[];
ENDLOOP;
EXITS
GoAway => NULL };
TestMT: Commander.CommandProc = {
argv: CommandTool.ArgumentVector = CommandTool.Parse[cmd !
CommandTool.Failed => {cmd.out.PutRope[errorMsg]; GOTO GoAway}];
file: IO.STREAM ← FS.StreamOpen[argv[1] !
FS.Error => {cmd.out.PutRope[error.explanation]; GOTO GoAway}];
pos1, pos2: INT;
direction: MT.Direction ← toGrapevine;
Find: PROC [in: IO.STREAM, what: Rope.ROPE] RETURNS [found: BOOL] = {
i, pos: INT;
found ← FALSE;
DO
IF in.EndOf THEN EXIT;
IF in.PeekChar[] = what.Fetch[] THEN {
pos ← file.GetIndex[];
FOR i IN [0..what.Length[]) DO
IF file.GetChar[] # what.Fetch[i] THEN
GO TO NotFound;
REPEAT
NotFound => NULL;
FINISHED => RETURN [TRUE];
ENDLOOP;
file.SetIndex[pos];
};
[] ← file.GetChar[];
ENDLOOP; };
PutRange: PROC [in, out: IO.STREAM, pos1, pos2: INT] = {
i: INT;
in.SetIndex[pos1];
FOR i IN [pos1..pos2) DO
out.PutChar[in.GetChar[]];
ENDLOOP; };
WHILE Find[file, "*start*\n"] DO
info: MT.Info;
pos1 ← file.GetIndex[];
info ← MT.ParseHeaders[file, cmd.out];
pos2 ← file.GetIndex[];
MT.TranslateToGrapevine[info];
cmd.out.PutRope["**Original header:**\n"];
PutRange[file, cmd.out, pos1, pos2];
cmd.out.PutChar['\n];
[] ← Find[file, "*translation*\n"];
pos1 ← file.GetIndex[];
[] ← Find[file, "\n\n"];
pos2 ← file.GetIndex[];
cmd.out.PutRope["-- Maxc translation --\n"];
PutRange[file, cmd.out, pos1, pos2];
cmd.out.PutRope["-- MT translation --\n"];
MT.PrintHeaders[info, cmd.out, FALSE];
cmd.out.PutChar['\n];
Process.CheckForAbort[];
ENDLOOP;
EXITS
GoAway => NULL };
Commander.Register["Headers", Headers, "Show Header Parsing."];
Commander.Register["Translate", Translate, "Translate a message to or from arpa format."];
Commander.Register["TestMT", TestMT, "Run a test on a file of translations."];
END.