DIRECTORY IndexProperties, IndexToolPrivate, IndexTree, IO, Rope, TextNode, TiogaOps, TiogaOpsDefs, ViewerClasses; IndexPropertiesImpl: CEDAR PROGRAM IMPORTS IndexToolPrivate, IndexTree, IO, Rope, TextNode, TiogaOps EXPORTS IndexProperties, TiogaOpsDefs = BEGIN OPEN IndexToolPrivate; ROPE: TYPE = Rope.ROPE; NodeBody: PUBLIC TYPE = TextNode.Body; IndexEntryToRope: PUBLIC PROCEDURE [ix: IndexEntry] RETURNS [rope: ROPE] = { phrases: LIST OF ROPE _ ix.phrases; WHILE phrases # NIL DO rope _ Rope.Concat[rope, IO.PutFR["\"%q\" ", IO.rope[phrases.first]]]; phrases _ phrases.rest; ENDLOOP; rope _ Rope.Concat[rope, IO.PutFR["%g ", IO.int[ix.bytePosition]]]; IF ix.primary THEN rope _ Rope.Concat[rope, "Primary "]; SELECT ix.type FROM single => NULL; beginRange => rope _ Rope.Concat[rope, "BeginRange "]; endRange => rope _ Rope.Concat[rope, "EndRange "]; see => { phrases _ ix.seePhrases; rope _ Rope.Concat[rope, "See "]; WHILE phrases # NIL DO rope _ Rope.Concat[rope, IO.PutFR["\"%q\" ", IO.rope[phrases.first]]]; phrases _ phrases.rest; ENDLOOP; }; ENDCASE; IF ix.sortAsPhrases # NIL THEN { phrases _ ix.sortAsPhrases; rope _ Rope.Concat[rope, "SortAs "]; WHILE phrases # NIL DO rope _ Rope.Concat[rope, IO.PutFR["\"%q\" ", IO.rope[phrases.first]]]; phrases _ phrases.rest; ENDLOOP; }; rope _ Rope.Concat[rope, IO.PutFR["VersionStamp \"%q\"\n", IO.rope[ix.versionStamp]]]; }; IndexPropToEntries: PUBLIC PROCEDURE [rope: ROPE] RETURNS [entries: LIST OF IndexEntry _ NIL] = { stream: IO.STREAM; NextEntry: PROCEDURE RETURNS [entries: LIST OF IndexEntry _ NIL] = { ix: IndexEntry _ IndexParse[stream]; IF ix # NIL THEN entries _ CONS[ix, NextEntry[]]; }; IF rope # NIL AND rope.Length > 0 THEN { stream _ IO.RIS[rope]; entries _ NextEntry[]; }; }; UnrecognizedKeyword: PUBLIC SIGNAL = CODE; KeywordExpectedButMissing: PUBLIC SIGNAL = CODE; BytePositionMissing: PUBLIC SIGNAL = CODE; IndexParse: PUBLIC PROCEDURE [stream: IO.STREAM] RETURNS [ix: IndexEntry _ NIL] = { tokens: LIST OF REF _ IO.GetRefAnyLine[stream ! IO.EndOfStream => GOTO Quit]; Phrases: PROCEDURE RETURNS [phrases: LIST OF ROPE _ NIL] = { IF tokens = NIL THEN RETURN; IF tokens.first # NIL THEN { p: ROPE; IF NOT ISTYPE[tokens.first, ROPE] THEN RETURN; p _ NARROW[tokens.first, ROPE]; tokens _ tokens.rest; phrases _ CONS[p, Phrases[]]; }; }; BytePosition: PROCEDURE RETURNS [bytePosition: INTEGER] = { IF tokens = NIL OR NOT ISTYPE[tokens.first, REF INT] THEN SIGNAL BytePositionMissing; bytePosition _ NARROW[tokens.first, REF INT]^; tokens _ tokens.rest; }; Keyword: PROCEDURE RETURNS [keyword: ATOM] = { IF tokens = NIL THEN RETURN [$EndOfLine]; IF NOT ISTYPE[tokens.first, ATOM] THEN SIGNAL KeywordExpectedButMissing; keyword _ NARROW[tokens.first, ATOM]; tokens _ tokens.rest; }; IF tokens = NIL OR tokens.first = NIL THEN RETURN; ix _ NEW[IndexEntryRec]; ix.phrases _ Phrases[]; ix.bytePosition _ BytePosition[]; ix.type _ single; WHILE tokens # NIL DO SELECT Keyword[] FROM $BeginRange => ix.type _ beginRange; $EndRange => ix.type _ endRange; $Primary => ix.primary _ TRUE; $See => ix.seePhrases _ Phrases[]; $SortAs => ix.seePhrases _ Phrases[]; $VersionStamp => ix.versionStamp _ Phrases[].first; $EndOfLine => EXIT; ENDCASE => SIGNAL UnrecognizedKeyword; ENDLOOP; EXITS Quit => NULL; }; ScanIndexProperties: PUBLIC PROCEDURE [viewer: ViewerClasses.Viewer, indexHandle: IndexHandle] = { root: TextNode.Ref _ TiogaOps.ViewerDoc[viewer]; node: TextNode.Ref _ TiogaOps.FirstChild[root]; WHILE node # NIL DO ixRope: ROPE _ NARROW[TiogaOps.GetProp[node, $Index], ROPE]; entries: LIST OF IndexEntry _ IndexPropToEntries[ixRope]; versionStamp: ROPE _ IndexToolPrivate.IndexVersionStamp[TiogaOps.GetRope[node]]; WHILE entries # NIL DO ix: IndexEntry _ entries.first; ix.stickyPointer _ TextNode.LocWithin[root, ix.bytePosition]; ix.valid _ versionStamp.Equal[ix.versionStamp]; IndexTree.InsertNewIndexEntry[indexHandle, entries.first]; entries _ entries.rest; ENDLOOP; node _ TiogaOps.StepForward[node]; ENDLOOP; }; END. ΆIndexPropertiesImpl.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Created by Rick Beach, July 12, 1983 3:14 pm Rick Beach, February 27, 1985 9:45:58 pm PST Κ’˜codešœ™Kšœ Οmœ1™˜Pšžœ žœž˜K˜K˜=K˜/K˜:K˜Kšžœ˜—K˜"Kšžœ˜—K˜—K˜—K˜Kšžœ˜—…—€ό