DIRECTORY Menus USING [MenuProc], SpellingToolDefinition, SpellingToolShared USING [CorrectTiogaOpsCallWithLocks, Selection, ProcessSelection, MapWordsInSelection], SDict USING [Empty, GetStringValue, MorphCorrection, NoText, NotFound, Retrieve, Text], SDictRpcControl USING [ImportInterface, UnimportInterface], Rope USING [ROPE, Concat, FromRefText], RPC USING [CallFailed], RPCSignals USING [ImportFailed], TiogaOpsDefs USING [Ref], TiogaOps USING [NoSelection], IO USING [rope, PutF, STREAM]; SpellingToolDefinitionImpl: CEDAR MONITOR IMPORTS SpellingToolShared, Rope, IO, RPC, RPCSignals, 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"] ! RPCSignals.ImportFailed => GOTO importFailed]; dictionaryImported _ TRUE; EXITS importFailed => NULL; }; totalDefinitionsCnt _ 0; totalDefinitionsWorkedCount _ 0; }; FinalizeDictionaryServer: PUBLIC ENTRY PROC [] = { IF dictionaryImported THEN { 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"] ! RPCSignals.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; definition _ SDict.Retrieve[definition, $Next]; 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; }; }; }. VSpellingToolDefinitionImpl.mesa Last Edited by: Nix, November 21, 1983 6:21 pm Κ;˜Jšœ™J™.J˜šΟk ˜ Jšœœ ˜Jšœ˜JšœœR˜jIcodešœœL˜WKšœœ&˜;Jšœœœ˜'Kšœœ˜Kšœ œ˜ Kšœ œ˜Kšœ œ˜Jšœœœ˜—J˜JšΟbœœœ˜*Jšœœœ.˜WJšœ˜"Jšœ˜Jšœœœœ˜Jšœœœ˜J˜Jšœœœ˜!Kšœœ˜Kšœ2œ˜:Kšœ œœ˜K˜š Οnœœœœœ˜HKšœ˜šœœœ˜%Jšœpœ˜ƒJšœœ˜š˜Jšœœ˜—J˜—Jšœ˜Jšœ ˜ J˜J˜—K˜šŸœœœœ˜2šœœ˜J˜$Jšœœ˜J˜—Jšœœ˜J˜J˜J˜—š Ÿœœœœ,œ˜[Jšœ'˜'Jšœ5˜5J˜J˜—J˜•StartOfExpansion† -- [parent: REF ANY, clientData: REF ANY _ NIL, mouseButton: Menus.MouseButton _ red, shift: BOOL _ FALSE, control: BOOL _ FALSE] -- šžœœœœ˜9Jšœœ˜š Ÿœœœ œœ˜