SourceFileOpsBasicImpl.mesa
Copyright Ó 1989, 1990, 1991 by Xerox Corporation. All rights reserved.
Last tweaked by Mike Spreitzer on December 11, 1990 7:50 pm PST
Willie-s, October 10, 1991 12:40 pm PDT
Some basic feedback operations on source files. This is the impl to use when nothing better is available.
DIRECTORY BasicTime, Convert, IO, PFS, PFSNames, Rope, SourceFileOps;
SourceFileOpsBasicImpl: CEDAR MONITOR
IMPORTS Convert, IO, PFS, PFSNames, Rope
EXPORTS SourceFileOps
= BEGIN OPEN SourceFileOps;
Position: TYPE ~ SourceFileOps.Position;
STREAM: TYPE ~ IO.STREAM;
GetSelection: PUBLIC PROC [selection: WhichSelection ¬ primary] RETURNS [pos: Position, contents: ROPE] = {
RETURN [noPosition, NIL]};
FormatPosition: PUBLIC PROC [pos: Position] RETURNS [Rope.ROPE] ~ {
name: ROPE ¬ "a broken file name";
time: ROPE ¬ "a broken time";
IF pos.fileName#NIL AND pos.fileName#PFSNames.EmptyPath
THEN name ¬ PFS.RopeFromPath[pos.fileName !PFS.Error => CONTINUE]
ELSE name ¬ "an unnamed file";
IF pos.uniqueID.egmt.gmt=BasicTime.nullGMT
THEN time ¬ "unspecified time"
ELSE time ¬ Convert.RopeFromTime[pos.uniqueID.egmt.gmt, years, seconds, FALSE, FALSE !Convert.Error => CONTINUE];
IF pos.uniqueID.egmt.usecs#0 THEN time ¬ IO.PutFR["%g + %gus", [rope[time]], [cardinal[pos.uniqueID.egmt.usecs]] ];
IF pos.uniqueID.host#[0, 0] THEN time ¬ IO.PutFR["%g host [%xH, %xH]", [rope[time]], [cardinal[pos.uniqueID.host.a]], [cardinal[pos.uniqueID.host.b]] ];
RETURN name.Cat[" created at ", time, " ", FmtIdxs[pos]]};
FmtIdxs: PUBLIC PROC [pos: Position] RETURNS [ROPE] ~ {
SELECT TRUE FROM
pos.index = ALL[noRange] => RETURN [" (no position)"];
pos.index[line] = noRange => RETURN IO.PutFR1[" (%g)", [rope[FmtRange[pos.index[char], "char ", "chars "]]]];
pos.index[char] = noRange => RETURN IO.PutFR1[" (%g)", [rope[FmtRange[pos.index[line], "line ", "line "]]]];
ENDCASE => RETURN IO.PutFR[" (%g = %g)", [rope[FmtRange[pos.index[char], "char ", "chars "]]], [rope[FmtRange[pos.index[line], "line ", "line "]]]]};
FmtRange: PUBLIC PROC [r: Range, introSingular, introPlural: ROPE ¬ NIL] RETURNS [ROPE] ~ {
IF r = noRange THEN RETURN introPlural.Concat["unspecified"];
IF r.last = noIndex THEN RETURN introSingular.Concat[Convert.RopeFromInt[r.first]];
RETURN IO.PutFR["%g%g..%g", [rope[introPlural]], [integer[r.first]], [integer[r.last]] ]};
OpenSource: PUBLIC PROC [desc: ROPE, pos: Position, feedBack: IO.STREAM ¬ NIL, selection: WhichSelection ¬ feedback] = {
feedBack.PutRope[desc];
feedBack.PutRope[" is in "];
feedBack.PutRope[FormatPosition[pos]];
feedBack.PutRope[".\N"];
RETURN};
END.