File: EnumerateDictImpl.mesa
Last Edited by: Nix, September 19, 1983 10:08 am
DIRECTORY
IO USING [Close, PutF, STREAM, Put, rope, int],
SDict USING [Text, GetStringValue, Retrieve, Empty],
SDictRpcControl USING [ImportInterface, UnimportInterface],
BasicTime USING [GetClockPulses, PulsesToMicroseconds],
CommandTool USING [Parse, ArgumentVector],
FS USING [StreamOpen, Error],
Rope USING [ROPE, Compare, Equal, Concat],
Commander USING [CommandProc, Register];
EnumerateDictImpl: CEDAR PROGRAM
IMPORTS IO, Commander, Rope, CommandTool, SDict, SDictRpcControl, FS, BasicTime = 
BEGIN
ROPE: TYPE = Rope.ROPE;
STREAM: TYPE = IO.STREAM;
stderr, stdout: STREAM;
timeSpell, timeWD, timeText: INT ← 0;
EnumerateDictionary: Commander.CommandProc = {
cmdLine: CommandTool.ArgumentVector ← CommandTool.Parse[cmd];
stdout ← stderr ← cmd.out;
IF cmdLine.argc # 4 THEN {
IO.PutF[ stderr, "usage: EnumerateDict <fromWord> <toWord> <outputFile>\n" ];
RETURN;
};
{
IF ~Rope.Equal[cmdLine.s[3],"-"] THEN
stdout ← FS.StreamOpen[cmdLine.s[3], create ! FS.Error => GOTO openFailed ];
StepThroughDictionary[cmdLine.s[1], cmdLine.s[2]];
IO.Close[stdout];
EXITS openFailed =>
IO.PutF[ stderr, "Could not write to file \"%g\"\n", IO.rope[cmdLine.s[3]]];
};
IO.PutF[ stderr, "Time in $Spelling: %g\n", IO.int[BasicTime.PulsesToMicroseconds[timeSpell]]];
IO.PutF[ stderr, "Time in retrieving text: %g\n", IO.int[BasicTime.PulsesToMicroseconds[timeText]]];
IO.PutF[ stderr, "Time in WD: %g\n", IO.int[BasicTime.PulsesToMicroseconds[timeWD]]];
};
StepThroughDictionary: PROC [ from, to: ROPE ] = TRUSTED {
handle: ROPE;
before: INT;
currentWord, entry, spelling: ROPE;
SDictRpcControl.ImportInterface[[type: "DICTIONARYSERVER", instance: "DictServer"]];
IO.PutF[ stderr, "Stepping from \"%g\" to \"%g\".\n", IO.rope[from], IO.rope[to] ];
handle ← SDict.Text[Rope.Concat[from," "]];
entry ← SDict.Retrieve[ handle, $Entry ];
DO
before ← BasicTime.GetClockPulses[];
currentWord ← SDict.Retrieve[ entry, $Spelling ! SDict.Empty => GOTO end ];
timeSpell ← BasicTime.GetClockPulses[] - before;
before ← BasicTime.GetClockPulses[];
spelling ← SDict.GetStringValue[currentWord];
timeText ← BasicTime.GetClockPulses[] - before;
IF Rope.Compare[spelling, to, FALSE] = greater THEN EXIT;
IO.Put[stdout, IO.rope[spelling]];
IO.Put[stdout, IO.rope["\n"]];
before ← BasicTime.GetClockPulses[];
entry ← SDict.Retrieve[ entry, $WD ! SDict.Empty => GOTO end];
timeWD ← BasicTime.GetClockPulses[] - before;
REPEAT
end => NULL;
ENDLOOP;
SDictRpcControl.UnimportInterface[];
};
Commander.Register[ key: "EnumerateDictionary", proc: EnumerateDictionary, doc: "Steps through the words in the dictionary."];
END.
CHANGE LOG
Created by Nix on September 14, 1983 11:56 am