<> <> 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 \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