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 TFile: EnumerateDictImpl.mesa Last Edited by: Nix, September 19, 1983 10:08 am Κ˜– "Cedar" stylešœ™J™0—unitšΟk ˜ Icodešœœœ˜/Jšœœ)˜4Jšœœ&˜;Jšœ œ(˜7Lšœ œ˜*Lšœœ˜Lšœœœ˜*Lšœ œ˜(—šΟbœœ˜ LšœœH˜R—Lš˜Lšœœœ˜Lšœœœœ˜Lšœœ˜L˜Lšœœ˜%•StartOfExpansion -- [cmd: Commander.Handle] -- šžœ˜.Lšœ=˜=Lšœ˜šœœ˜LšœK˜MLšœ˜L˜—˜šœ˜%Lšœ:œ˜L—Lšœ2˜2Lšœ˜šœ˜Lšœ3œ˜L—L˜—Lšœ*œ1˜_Lšœ0œ0˜dLšœ#œ.˜UL˜L˜J˜—šΟnœœ œœ˜:Jšœœ˜ Jšœœ˜ Jšœœ˜#LšœT˜TJšœ4œ œ ˜SJ˜,J˜)š˜Jšœ$˜$Jšœ@œ˜KJšœ0˜0Jšœ$˜$J˜-Jšœ/˜/Jšœœ œœ˜9Jšœ œ˜"Jšœ œ ˜Jšœ$˜$Jšœ4œ˜>Jšœ-˜-š˜Jšœœ˜ —Jšœ˜—J˜$J˜J˜—Jšœ~˜~J˜Iprocšœ˜Kšœ˜ Kšœ-˜-—…— \ Ύ