-- 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
DIRECTORY JaMBasic, JaMInternal, JaMOps, Rope;
ConvertAsciiCmds: PROGRAM
IMPORTS JaMOps, Rope
= BEGIN
ROPE: TYPE = Rope.ROPE;
Frame: TYPE = JaMInternal.Frame;
PopRope: PROCEDURE [f: Frame] RETURNS [rope: ROPE] = {
s: string JaMBasic.Object ← JaMOps.PopString[f.opstk];
C: PROC[c: CHAR] RETURNS [BOOLEAN] =
{t[t.length]𡤌 t.length ← t.length+1; RETURN[FALSE]};
t: REF TEXTNEW[TEXT[s.length]];
t.length ← 0;
JaMOps.StringForAll[s, C];
rope ← Rope.FromRefText[t];
};
PushRope: PROCEDURE [f: Frame, rope: ROPE] = {
JaMOps.Push[
f.opstk,
JaMOps.MakeString[LOOPHOLE[rope.ToRefText[], LONG STRING]]
];
};
ConvertAcsiiCharToInteger: PROCEDURE [f: Frame] = {
char: CHAR ← PopRope[f].Fetch[0];
byte: [0..256) ← char - 000C;
JaMOps.PushInteger[f.opstk, byte];
};
ConvertIntegerToAcsiiChar: PROCEDURE [f: Frame] = {
byte: [0..256) ← JaMOps.PopInteger[f.opstk];
PushRope[f, Rope.FromChar[000C + byte]];
};
ConvertIntegerToAcsiiString: PROCEDURE [f: Frame] = {
byte: [0..256) ← JaMOps.PopInteger[f.opstk];
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]]];
};
JaMOps.RegisterExplicit[JaMOps.defaultFrame, ".cvaci", ConvertAcsiiCharToInteger];
JaMOps.RegisterExplicit[JaMOps.defaultFrame, ".cviac", ConvertIntegerToAcsiiChar];
JaMOps.RegisterExplicit[JaMOps.defaultFrame, ".cvias", ConvertIntegerToAcsiiString];
END.