UXIOTestImpl.mesa
Copyright Ó 1994 by Xerox Corporation. All rights reserved.
Willie-s, March 18, 1994 1:24 pm PST
DIRECTORY
Atom,
Commander,
CStrings,
IO,
UXIO,
Rope,
UnixSysCalls,
UnixTypes,
UXStrings;
NewUXIOTestImpl: CEDAR PROGRAM
IMPORTS Atom, Commander, IO, UnixSysCalls, UXIO, UXStrings
~ BEGIN OPEN UnixTypes;
where: ARRAY[0..6) OF INT ¬ [446, 50264, 243144, 55468, 234330, 158217];
debug: BOOL ¬ FALSE;
DoInternalSetIndex: Commander.CommandProc ~ {
o: IO.STREAM ¬ UXIO.CreateStandardStream[output];
s: IO.STREAM ¬ NIL;
infile: Rope.ROPE ~ "/project/bonsai2.0/testlib/BlackWalnut.mailLog";
s ¬ UXIO.CreateFileStream[infile, read];
FOR i: INT IN [0..6) DO
s.SetIndex[where[i]];
o.PutF["GetIndex: %g, SetIndex was: %g\n", [integer[s.GetIndex[]]], [integer[where[i]]] ];
o.PutRope[s.GetLineRope[]];
o.PutChar['\n];
ENDLOOP;
IO.Close[o];
IO.Close[s];
};
DoGetTokenTest: Commander.CommandProc ~ {
o: IO.STREAM ¬ cmd.out;
s: IO.STREAM ¬ NIL;
pos: INT ¬ 0;
infile: Rope.ROPE ~ "/project/bonsai2.0/testlib/BlackWalnut.mailLog";
MyTokenProc: IO.BreakProc = {
cc: IO.CharClass;
what: Rope.ROPE;
SELECT char FROM
'[, '], '(, '), '{, '}, '", '+, '-, '*, '/, '@, '← => { cc ¬ break; what ¬ "break"};
IN [IO.NUL .. IO.SP] => { cc ¬ sepr; what ¬ "sepr" };
',, ':, '; => { cc ¬ sepr; what ¬ "sepr" };
ENDCASE => { cc ¬ other; what ¬ "other"};
IF debug THEN o.PutF[" <<%g, %g>> ", [character[char]], [rope[what]] ];
RETURN[cc];
};
s ¬ UXIO.CreateFileStream[infile, read];
o.PutF["GetIndex: %g, EndOf: %g\n", [integer[s.GetIndex[]]], [boolean[s.EndOf[]]] ];
FOR i: INT IN [0..5) DO
o.PutF["(%g) %g\n", [integer[i]], [rope[s.GetTokenRope[MyTokenProc].token] ]];
ENDLOOP;
pos ¬ s.GetIndex[];
o.PutF["GetIndex: %g, EndOf: %g\n", [integer[s.GetIndex[]]], [boolean[s.EndOf[]]] ];
FOR i: INT IN [6..9) DO
o.PutF["(%g) %g\n", [integer[i]], [rope[s.GetTokenRope[MyTokenProc].token] ]];
ENDLOOP;
o.PutF["GetIndex: %g, EndOf: %g\n", [integer[s.GetIndex[]]], [boolean[s.EndOf[]]] ];
o.PutF1["Now do SetIndex back to %g\n", [integer[pos]] ];
s.SetIndex[pos];
FOR i: INT IN [6..9) DO
o.PutF["(%g) %g\n", [integer[i]], [rope[s.GetTokenRope[MyTokenProc].token] ]];
ENDLOOP;
o.PutF["GetIndex: %g, EndOf: %g\n", [integer[s.GetIndex[]]], [boolean[s.EndOf[]]] ];
IO.Close[s];
};
mode: UnixTypes.Mode ¬ UXIO.defaultMode;
DoStat: Commander.CommandProc ~ {
o: IO.STREAM ¬ cmd.out;
infile: Rope.ROPE ~ "/project/bonsai2.0/testlib/BlackWalnut.mailLog";
stat: UnixTypes.Stat;
cName: CStrings.CString ~ UXStrings.Create[infile];
res: RES;
fd: UnixTypes.FD ¬ UnixSysCalls.Open[cName, [access: RDONLY], mode];
IF fd = error THEN { o.PutRope["UnixSysCalls.Open failed\n"]; RETURN };
TRUSTED { res ¬ UnixSysCalls.FStat[fd, @stat] };
IF res # success THEN { o.PutRope["FStat failed\n"]; RETURN };
o.PutFL["[ino: %g, mode: %g, uid: %g, gid: %g, size: %g]\n",
LIST[[integer[stat.ino]], [integer[LOOPHOLE[stat.mode]]], [integer[stat.uid]], [integer[stat.gid]], [integer[stat.size]] ]];
[] ¬ UnixSysCalls.Close[fd];
};
DoStream: PROC [s: IO.STREAM] ~ {
IO.PutRope[s, "Hello world; Cedar is alive on a Sun\L"];
IO.PutF1[s, "a rope: %g\L", [rope["rope"]]];
IO.PutF1[s, "an int: %g\L", [integer[LAST[INT]]]];
IO.PutF1[s, "an int: %g\L", [integer[FIRST[INT]]]];
IO.PutF1[s, "a char: %g\L", [character['c]]];
IO.PutF1[s, "an atom: %g\L", [atom[Atom.MakeAtom["atom"]]]];
IO.PutF1[s, "a bool: %g\L", [boolean[TRUE]]];
IO.PutF1[s, "a card: %g\L", [cardinal[LAST[CARD]]]];
IO.PutF1[s, "a card: %g\L", [cardinal[FIRST[CARD]]]];
IO.PutF1[s, "a time: %g\L", [time[BasicTime.nullGMT]]];
IO.PutF1[s, "a real: %g\L", [real[1.0]]];
};
DoStandard: Commander.CommandProc ~ {
s: IO.STREAM ¬ UXIO.CreateStandardStream[output];
DoStream[s];
};
DoFile: Commander.CommandProc ~ {
s: IO.STREAM ¬ UXIO.CreateFileStream["myfile", write];
DoStream[s];
cmd.out.PutRope["wrote file myfile\n"];
};
Commander.Register["UXIODoStat", DoStat];
Commander.Register["UXIODoInternalSetIndex", DoInternalSetIndex];
Commander.Register["UXIODoGetTokenTest", DoGetTokenTest];
Commander.Register["UXIODoStandard", DoStandard];
Commander.Register["UXIODoFile", DoFile];
END.
Commander.Register["UXIOXXX", yyy];