CrankCommands.mesa
Copyright Ó 1991 by Xerox Corporation. All rights reserved.
Michael Plass, September 7, 1991 11:25 pm PDT
DIRECTORY CrankTypes, CrankIO, CrankAnalyze, Atom, Commander, CommanderOps, Rope;
CrankCommands: CEDAR PROGRAM
IMPORTS CrankIO, CrankAnalyze, Atom, Commander, CommanderOps, Rope
~ BEGIN
ROPE: TYPE ~ Rope.ROPE;
CrankCommand: Commander.CommandProc ~ {
arg0: ROPE ~ CommanderOps.NextArgument[cmd];
skipAttributes: LIST OF ATOM ¬ LIST[$DECLTYPECODE, $TYPE, $CONTEXT, $STE, $TYPECODE, $NEEDTYPECODE];
parseOnly: BOOL ¬ FALSE;
IF arg0 = NIL THEN ERROR CommanderOps.Failed[cmd.procData.doc];
FOR arg: ROPE ¬ arg0, CommanderOps.NextArgument[cmd] UNTIL arg = NIL DO
IF Rope.Match["-*", arg]
THEN {
FOR i: INT IN [1..Rope.Size[arg]) DO
c: CHAR ~ Rope.Fetch[arg, i];
SELECT c FROM
's => skipAttributes ¬ CONS[Atom.MakeAtom[CommanderOps.NextArgument[cmd]], skipAttributes];
'a => skipAttributes ¬ NIL;
'p => parseOnly ¬ TRUE;
ENDCASE => ERROR CommanderOps.Failed[cmd.procData.doc];
ENDLOOP;
}
ELSE {
fileName: ROPE ~ arg;
IF parseOnly
THEN {
Inner: PROC [tree: CrankTypes.Tree, context: CrankTypes.Context] = {
outputName: ROPE = CrankIO.MakeOutputName[fileName, "sexpr"];
out: ROPE ~ CrankIO.WriteSTree[tree, outputName, united, fileName, skipAttributes];
msg ¬ Rope.Cat[msg, " ", out];
};
CrankAnalyze.Convert[fileName: fileName, analyze: FALSE, action: Inner];
}
ELSE {
out: ROPE ~ CrankAnalyze.ConvertFile[fileName: fileName, skipAttributes: skipAttributes];
msg ¬ Rope.Cat[msg, " ", out];
};
};
ENDLOOP;
};
Commander.Register["Crank", CrankCommand, "Convert mesa files to a s-expressions\n args: ( <filename> | -s <skipAttribute> | -a ) ...\n-s skipAttribute tells an attribute to omit when writing the tree\n-a writes all attributes, even those normally skipped\n-p means parse only (no type analysis)"];
END.