DIRECTORY IO USING [rope, PutF, STREAM], Menus USING [MenuProc], Rope USING [ROPE, Concat, FromRefText], RPC USING [CallFailed, ImportFailed], SDict USING [Empty, GetStringValue, MorphCorrection, NoText, NotFound, Retrieve, Text], SDictRpcControl USING [ImportInterface, UnimportInterface], SpellingToolDefinition, SpellingToolShared USING [CorrectTiogaOpsCallWithLocks, Selection, ProcessSelection, MapWordsInSelection], TiogaOps USING [NoSelection], TiogaOpsDefs USING [Ref]; SpellingToolDefinitionImpl: CEDAR MONITOR IMPORTS SpellingToolShared, Rope, IO, RPC, SDict, SDictRpcControl, TiogaOps EXPORTS SpellingToolDefinition = { OPEN SpellingToolShared; STREAM: TYPE = IO.STREAM; ROPE: TYPE = Rope.ROPE; dictionaryImported: BOOL _ FALSE; DefinitionCaveat: BOOL; totalDefinitionsCnt, totalDefinitionsWorkedCount: INT _ 0; permMessage: STREAM _ NIL; InitializeDictionaryServer: PUBLIC ENTRY PROC [outputStream: STREAM] = { permMessage _ outputStream; IF ~dictionaryImported THEN TRUSTED { SDictRpcControl.ImportInterface[[type: "DICTIONARYSERVER", instance: "DictServer"] ! RPC.ImportFailed => GOTO importFailed]; dictionaryImported _ TRUE; EXITS importFailed => NULL; }; totalDefinitionsCnt _ 0; totalDefinitionsWorkedCount _ 0; }; FinalizeDictionaryServer: PUBLIC ENTRY PROC [] = { IF dictionaryImported THEN TRUSTED { SDictRpcControl.UnimportInterface[]; dictionaryImported _ FALSE; }; permMessage _ NIL; }; DefinitionStats: PUBLIC PROC [] RETURNS [totalDefinitions, totalDefinitionsWorked: INT] = { totalDefinitions _ totalDefinitionsCnt; totalDefinitionsWorked _ totalDefinitionsWorkedCount; }; DefinitionButton: PUBLIC ENTRY Menus.MenuProc = TRUSTED { theWord, wordNoBlank: ROPE; DictionaryCommand: INTERNAL PROC [theWord: ROPE] = TRUSTED { entryHandle, item, definition: ROPE _ NIL; IF ~dictionaryImported THEN TRUSTED { IO.PutF[permMessage, "The dictionary server was down; I'll try to contact it again...\n"]; SDictRpcControl.ImportInterface[[type: "DICTIONARYSERVER", instance: "DictServer"] ! RPC.ImportFailed => GOTO importFailed]; dictionaryImported _ TRUE; IO.PutF[permMessage, "Glory be, the dictionary server is back up!\n"]; EXITS importFailed => { IO.PutF[permMessage, "Sorry, the dictionary server is still down.\n"]; RETURN; }; }; item _ SDict.Text[theWord]; { ENABLE { SDict.NoText => { IO.PutF[permMessage, "Text aged, try again.\n"]; GOTO gotError; }; SDict.NotFound => { IO.PutF[permMessage, "Not in the dictionary.\n"]; GOTO gotError; }; SDict.Empty => { IO.PutF[permMessage, "Empty?\n"]; GOTO gotError; }; SDict.MorphCorrection => { IO.PutF[permMessage, "Not in the dictionary, correction proposed: \"%g\".\n", IO.rope[word]]; GOTO gotError; }; }; IO.PutF[permMessage, "%g:\n", IO.rope[wordNoBlank]]; definition _ SDict.Retrieve[SDict.Retrieve[item,$Entry], $Definition]; DO IO.PutF[permMessage, "%g\n", IO.rope[SDict.GetStringValue[definition]]]; totalDefinitionsWorkedCount _ totalDefinitionsWorkedCount + 1; EXIT; ENDLOOP; EXITS gotError => NULL; }; }; { ENABLE { RPC.CallFailed => { SELECT why FROM timeout => IO.PutF[permMessage, "The dictionary server isn't up; try again later.\n"]; unbound => { dictionaryImported _ FALSE; SDictRpcControl.UnimportInterface[]; DictionaryCommand[theWord]; }; busy => IO.PutF[permMessage, "The dictionary server is busy; try again later.\n"]; runtimeProtocol, stubProtocol => IO.PutF[permMessage, "Screw in the RPC protocol, call a wizard.\n"]; ENDCASE => ERROR; GOTO dictionaryBlownAway; }; UNWIND => NULL; }; Locker: INTERNAL PROC [root: TiogaOpsDefs.Ref] = TRUSTED { ExtractOneWord: INTERNAL PROC [word: REF TEXT] RETURNS [stop: BOOLEAN _ TRUE] = TRUSTED { wordNoBlank _ Rope.FromRefText[word]; }; s: SpellingToolShared.Selection _ SpellingToolShared.ProcessSelection[FALSE,TRUE, TRUE].s; [] _ SpellingToolShared.MapWordsInSelection[s.start, s.end, ExtractOneWord, TRUE]; IF wordNoBlank = NIL THEN IO.PutF[permMessage, "No word has been selected.\n"] ELSE { IO.PutF[permMessage, "Looking up definition of \"%g\"...\n", IO.rope[wordNoBlank]]; theWord _ Rope.Concat[wordNoBlank, " "]; -- Bug in Dictionary server requires it. }; }; IF ~DefinitionCaveat THEN IO.PutF[permMessage, "Warning: the definition facility often fails to work.\n"]; SpellingToolShared.CorrectTiogaOpsCallWithLocks[Locker ! TiogaOps.NoSelection => { IO.PutF[permMessage, "No word is selected; please select a word.\n"]; GOTO dictionaryBlownAway}]; DefinitionCaveat _ TRUE; IF theWord = NIL THEN { IO.PutF[permMessage, "No word is selected; please select a word.\n"]; RETURN; }; totalDefinitionsCnt _ totalDefinitionsCnt + 1; DictionaryCommand[theWord]; EXITS dictionaryBlownAway => NULL; }; }; }. &SpellingToolDefinitionImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Created by: Nix Last Edited by: Spreitzer, February 25, 1986 10:59:16 pm PST Russ Atkinson (RRA) October 30, 1985 4:13:27 pm PST definition _ SDict.Retrieve[definition, $Next]; Edited on February 26, 1985 9:29:01 pm PST, by Spreitzer Commented out unreachable code. changes to: DictionaryCommand (local of DefinitionButton) Spreitzer, February 25, 1986 10:59:01 pm PST TRUSTED SDictRpcControl.UnimportInterface[] changes to: FinalizeDictionaryServer Κ„˜codešœ™Kšœ Οmœ1™