-- ConvertAsciiCmds.mesa
-- Written by Michael Plass on October 14, 1982 2:28 pm
-- Last edit by Michael Plass on October 14, 1982 2:28 pm
-- Maureen Stone February 8, 1984 4:13:09 pm PST
DIRECTORY
FitJaM USING [InitProc],
JaM USING [State, PopRope, PushRope, PushInt, PopInt, Register],
Rope;
ConvertAsciiCmds: CEDAR PROGRAM
IMPORTS JaM, Rope
EXPORTS FitJaM
= BEGIN
ROPE: TYPE = Rope.ROPE;
State: TYPE = JaM.State;
PopRope: PROCEDURE [f: State] RETURNS [rope: ROPE] = {RETURN[JaM.PopRope[f]]};
PushRope: PROCEDURE [f: State, rope: ROPE] = {JaM.PushRope[f,rope]};
ConvertAcsiiCharToInteger: PROCEDURE [f: State] = {
char: CHAR ← PopRope[f].Fetch[0];
byte: [0..256) ← char - 000C;
JaM.PushInt[f, byte];
};
ConvertIntegerToAcsiiChar: PROCEDURE [f: State] = {
byte: [0..256) ← JaM.PopInt[f];
PushRope[f, Rope.FromChar[000C + byte]];
};
ConvertIntegerToAcsiiString: PROCEDURE [f: State] = {
byte: [0..256) ← JaM.PopInt[f];
b0: CHAR ← '0 + byte MOD 8;
b1: CHAR ← '0 + byte/8 MOD 8;
b2: CHAR ← '0 + byte/64 MOD 8;
IF 000C + byte IN (' ..'}] AND 000C + byte # '\" AND 000C + byte # '\\ THEN PushRope[f, Rope.FromChar[000C + byte]]
ELSE PushRope[f, Rope.Cat["\\", Rope.FromChar[b2], Rope.FromChar[b1], Rope.FromChar[b0]]];
};
ConvertAsciiCmdsInit: PUBLIC FitJaM.InitProc = {
JaM.Register[state, ".cvaci", ConvertAcsiiCharToInteger];
JaM.Register[state, ".cviac", ConvertIntegerToAcsiiChar];
JaM.Register[state, ".cvias", ConvertIntegerToAcsiiString];
};
END.