TestProfiles.mesa
Copyright Ó 1988, 1989, 1990, 1991 by Xerox Corporation. All rights reserved.
Dave Rumph, January 18, 1990 10:28:37 am PST
Michael Plass, November 25, 1991 11:24 am PST
DIRECTORY Commander, CommanderOps, IO, PFS, Profiles, Rope;
TestProfiles: CEDAR PROGRAM
IMPORTS Commander, CommanderOps, IO, PFS, Profiles
~ BEGIN
ROPE: TYPE = Rope.ROPE;
profile: Profiles.Profile ¬ NIL;
CreateProfile: Commander.CommandProc ~ {
PROC [cmd: Handle] RETURNS [result: REFNIL, msg: ROPENIL]
profile: Profiles.Profile ← NIL;
tokens: LIST OF ROPE ¬ CommanderOps.ParseToList[cmd: cmd].list;
IF tokens=NIL THEN RETURN[$Failure, "Can't find any filenames\n"];
profile ¬ Profiles.Create[tokens !
PFS.Error => {msg ¬ error.explanation ; GOTO Oops}
];
cmd.propertyList ← CommanderOps.PutLocalProperty[key: $TestProfile, val: profile, aList: cmd.propertyList, origList: cmd.propertyList];
EXITS Oops => RETURN [$Failure];
};
ProfileLine: Commander.CommandProc ~ {
PROC [cmd: Handle] RETURNS [result: REFNIL, msg: ROPENIL]
profile: Profiles.Profile ← NARROW[CommanderOps.GetProp[cmd, $TestProfile]];
IF profile=NIL THEN RETURN [$Failure, "Can't find profile on property list"];
FOR tokens: LIST OF ROPE ¬ CommanderOps.ParseToList[cmd: cmd].list, tokens.rest UNTIL tokens=NIL DO
IO.PutF[stream: cmd.out, format: "Key: %g, Value: %g\n", v1: [rope[tokens.first]], v2: [rope[Profiles.Line[profile, tokens.first, "(not found)"]]]];
ENDLOOP;
};
Init: PROC ~ {
Commander.Register[key: "CreateProfile", proc: CreateProfile, doc: "Create a profile from the list of filenames on the command line\n"];
Commander.Register[key: "ProfileLine", proc: ProfileLine, doc: "Look up the keys on the command line in the profile stored on the command tool's property list\n"];
};
Init[];
END.