CommandToolLookup.mesa
Copyright © 1985 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) April 16, 1985 5:50:29 pm PST
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: LORNIL, procData: Commander.CommandProcHandle ← NIL];
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
FindMatchingFiles: PROC [root: ROPE, defaultExtension: ROPE, requireExact: BOOLTRUE, searchRules: REF ANY] RETURNS [paths: LORNIL];
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)
FindMatchingCommands: PROC [root: ROPE, requireExact: BOOL, searchRules: REF] RETURNS [paths: LORNIL, data: Commander.CommandProcHandle ← NIL];
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
DoWithRules: PROC [rules: REF, inner: WithRulesProc] RETURNS [stop: BOOLFALSE];
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.
WithRulesProc: TYPE = PROC [rule: ROPE] RETURNS [stop: BOOLFALSE];
ShowAmbiguous: PROC [out: STREAM, list: LOR];
Prints the standard message about ambiguity in the form
{Ambiguous:
name
...
}
END.