DIRECTORY Commander USING [CommandProcHandle, Handle], IO USING [STREAM], Rope USING [ROPE]; CommandToolLookup: CEDAR DEFINITIONS = BEGIN LOR: TYPE = LIST OF ROPE; LORA: TYPE = LIST OF REF ANY; ROPE: TYPE = Rope.ROPE; STREAM: TYPE = IO.STREAM; DoLookup: PROC [cmd: Commander.Handle, arg: ROPE] RETURNS [paths: LOR _ NIL, procData: Commander.CommandProcHandle _ NIL]; FindMatchingFiles: PROC [root: ROPE, defaultExtension: ROPE, requireExact: BOOL _ TRUE, searchRules: REF ANY] RETURNS [paths: LOR _ NIL]; FindMatchingCommands: PROC [root: ROPE, requireExact: BOOL, searchRules: REF] RETURNS [paths: LOR _ NIL, data: Commander.CommandProcHandle _ NIL]; DoWithRules: PROC [rules: REF, inner: WithRulesProc] RETURNS [stop: BOOL _ FALSE]; WithRulesProc: TYPE = PROC [rule: ROPE] RETURNS [stop: BOOL _ FALSE]; ShowAmbiguous: PROC [out: STREAM, list: LOR]; END. @CommandToolLookup.mesa Copyright c 1985 by Xerox Corporation. All rights reserved. Russ Atkinson (RRA) April 16, 1985 5:50:29 pm PST Performs the standard CommandTool lookup for arg, according to the following: 1. Search for an exact match (if one is found, return it immediately) 1.1. Search for the registered command arg in search rule order 1.2. Search for the file arg.load in search rule order 1.3. Search for the file arg.cm in search rule order 2. Search for an unambiguous match (don't return early) 2.1. Accumulate matches for the registered command arg* in search rule order (if more than one match, return early to avoid costly file searches) 2.2. Accumulate matches for the file arg*.load in search rule order 2.3. Accumulate matches for the file arg*.cm in search rule order At the end we have the following results: If paths = NIL, then no match was found of any kind If paths # NIL AND paths.rest # NIL, then paths has all of the ambiguous matches If paths # NIL AND paths.rest = NIL, then: If procData # NIL, then a command was found If procData = NIL, then a file was found Performs the standard CommandTool lookup for the specified file, using the given searchRules (see DoWithRules for details about the rules). If defaultExtension # NIL, then the target is Concat[root, defaultExtension] If defaultExtension = NIL, then the target is root If requireExact, then the target must completely match If NOT requireExact, then root must be a prefix of the short name (not counting suffix) Performs the standard CommandTool lookup for the command specified by arg (see DoWithRules for details about the rules). At the end we have the following results: paths is sorted in increasing order (case not significant) If paths = NIL, then no match was found of any kind If paths # NIL AND paths.rest # NIL, then paths has all of the ambiguous matches If paths # NIL AND paths.rest = NIL, then: If procData # NIL, then a command was found If procData = NIL, then a file was found Performs the inner procedure for each rule specified by rules. The rules can be of type LORA, LOR, or ROPE. If the rules are of type LORA or LOR, then DoWithRules is called recursively on each element. If any inner proc returns TRUE, then DoWithRules will return TRUE and stop early. Prints the standard message about ambiguity in the form {Ambiguous: name ... } Κ˜codešœ™Kšœ Οmœ1™