TiogaDWIMCommands.mesa
Copyright Ó 1992 by Xerox Corporation. All rights reserved.
Mike Spreitzer March 1, 1987 5:45:39 pm PST
Last tweaked by Mike Spreitzer on November 30, 1987 2:48:46 pm PST
Willie-s, April 6, 1992 12:43 pm PDT
TiogaDWIMCommands:
CEDAR
PROGRAM
IMPORTS Atom, Commander, CommanderOps, Convert, DefDWIM, DocCache, IO, PFS, Rope, TextNode, TiogaIO
=
FindDefCommand:
PROC [cmd: Commander.Handle]
RETURNS [result:
REF
ANY ¬
NIL, msg: Rope.
ROPE ¬
NIL]
--Commander.CommandProc-- ~ {
argv: CommanderOps.ArgumentVector;
fromDoc: TextNode.Ref ¬ NIL;
fromPos: INT;
searchOrder: DefDWIM.SearchOrder;
deep, verbose: BOOL;
fp: DefDWIM.FoundPlace;
from: DefDWIM.Place;
argv ¬ CommanderOps.Parse[cmd !CommanderOps.Failed => {msg ¬ errorMsg; GOTO Failed}];
IF argv.argc # 7 THEN RETURN [$Failure, "Usage: FindDef subject filename pos searchOrder deep verbose"];
fromDoc ¬ DocCache.GetDoc[argv[2] !
TiogaIO.Error => {msg ¬ Rope.Cat["TiogaIO.FromFile[", argv[2], "] => FromFileError"]; GOTO Failed};
PFS.Error => {msg ¬ IO.PutFR["TiogaIO.FromFile[%g] => PFS.Error[%g, %g]", [rope[argv[2]]], [atom[error.code]], [rope[error.explanation]] ]; GOTO Failed}];
fromPos ¬ Convert.IntFromRope[argv[3] !Convert.Error => {msg ¬ "pos should be an INT literal"; GOTO Failed}];
SELECT Atom.MakeAtom[argv[4]]
FROM
$fb, $fwdThenBkwd => searchOrder ¬ fwdThenBkwd;
$bf, $bkwdThenFwd => searchOrder ¬ bkwdThenFwd;
$fs, $fromStart => searchOrder ¬ fromStart;
ENDCASE => {msg ¬ "searchOrder should be one of: fb, fwdThenBkwd, bf, bkwdThenFwd, fs, fromStart"; GOTO Failed};
deep ¬ Convert.BoolFromRope[argv[5] !Convert.Error => {msg ¬ "deep should be a BOOLEAN literal"; GOTO Failed}];
verbose ¬ Convert.BoolFromRope[argv[6] !Convert.Error => {msg ¬ "verbose should be a BOOLEAN literal"; GOTO Failed}];
from ¬ [argv[2], TextNode.LocRelative[[fromDoc, 0], fromPos], searchOrder];
fp ¬ DefDWIM.FindDef[argv[1], from, deep, verbose !DefDWIM.Failure => {msg ¬ Rope.Cat["DefDWIM.Failre[", FmtPlace[where], ", ", why, "]"]; GOTO Failed}];
msg ¬ Rope.Concat["Found ", FmtPlace[fp.where]];
RETURN;
EXITS Failed => result ¬ $Failure};
FmtPlace:
PROC [place: DefDWIM.Place]
RETURNS [Rope.
ROPE] ~ {
pos: INT ¬ TextNode.LocOffset[[TextNode.Root[place.loc.node], 0], place.loc];
RETURN IO.PutFR["%g|%g", [rope[place.fileName]], [integer[pos]]]};