CitingFilesCommand: Commander.CommandProc = {
ENABLE PFS.Error => IF error.group = user THEN ERROR CommanderOps.Failed[error.explanation];
argv: CommanderOps.ArgumentVector ~ CommanderOps.Parse[cmd];
target, prefix, suffix, xrefname: ROPE;
xrefStream: IO.STREAM;
scratch, tokBuff: REF TEXT;
Break1:
PROC [c:
CHAR]
RETURNS [
IO.CharClass] ~ {
RETURN[IF c <= ' THEN sepr ELSE other]};
Break2:
PROC [c:
CHAR]
RETURNS [
IO.CharClass] ~ {
RETURN[
SELECT c
FROM
IO.LF, IO.CR => break,
<= ' => sepr,
ENDCASE => other]};
SkipLine:
PROC ~ {
DO c:
CHAR ← xrefStream.GetChar[];
IF c=IO.LF OR c=IO.CR THEN EXIT;
ENDLOOP};
IF argv.argc NOT IN [2..5] THEN CommanderOps.Failed[IO.PutFR1["Usage: %g subject [suffix [prefix [xRefFileName]]]", [rope[argv[0]]] ]];
target ← argv[1].Concat[":"];
IF argv.argc>2 THEN suffix ← argv[2] ELSE suffix ← ".mesa";
IF argv.argc>3 THEN prefix ← argv[3] ELSE prefix ← "/r/";
IF argv.argc>4 THEN xrefname ← argv[4] ELSE xrefname ← "/r/Cedar.depends";
xrefStream ← PFS.StreamOpen[PFS.PathFromRope[xrefname]];
tokBuff ← scratch ← RefText.ObtainScratch[300];
{
ENABLE
IO.EndOfStream => {
cmd.err.PutF["%g not defined in %g.\n", [rope[argv[1]]], [rope[xrefname]] ];
CONTINUE};
DO
tokBuff ← xrefStream.GetToken[Break1, tokBuff].token;
IF Rope.Equal[RefText.TrustTextAsRope[tokBuff], target]
THEN {
SkipLine[];
DO
stem: ROPE ← xrefStream.GetTokenRope[Break2].token;
IF stem.Equal["\r"] OR stem.Equal["\l"] THEN EXIT;
cmd.out.PutF[" %g%g%g", [rope[prefix]], [rope[stem]], [rope[suffix]] ];
ENDLOOP;
cmd.out.PutChar['\n];
EXIT}
ELSE {
IF tokBuff.length>0 AND tokBuff[tokBuff.length-1]=': THEN SkipLine[];
SkipLine[];
};
ENDLOOP;
};
xrefStream.Close[];
RefText.ReleaseScratch[scratch];
RETURN
};
Commander.Register[key: "CitingFiles", proc: CitingFilesCommand, doc: "subject [suffix [prefix [xRefFileName]]] --- lists <prefix[/r/]><dep><suffix[.mesa]> for every <dep> that xRefFileName[/r/Cedar.depends] says depends on <subject>"];