SourceFileOpsBasicImpl.mesa
Copyright Ó 1989, 1990 by Xerox Corporation. All rights reserved.
Last tweaked by Mike Spreitzer on December 11, 1990 7:50 pm PST
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, SourceFileOpsExtras;
SourceFileOpsBasicImpl: CEDAR MONITOR
IMPORTS Convert, IO, PFS, PFSNames, Rope
EXPORTS SourceFileOps, SourceFileOpsExtras
= BEGIN OPEN SourceFileOpsExtras;
FullPosition: TYPE ~ SourceFileOpsExtras.Position;
ShortPosition: TYPE ~ SourceFileOps.Position;
STREAM: TYPE ~ IO.STREAM;
GetSelection: PUBLIC PROC [selection: WhichSelection ← primary] RETURNS [ShortPosition] = {
RETURN [SourceFileOps.noPosition]};
FullGetSelection: PUBLIC PROC [selection: WhichSelection ← primary] RETURNS [pos: FullPosition, contents: ROPE] = {
RETURN [noPosition, NIL]};
FormatPosition: PUBLIC PROC [pos: ShortPosition] RETURNS [Rope.ROPE]
~ {RETURN FullFormatPosition[Expand[pos]]};
FullFormatPosition: PUBLIC PROC [pos: FullPosition] 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.time=BasicTime.nullGMT
THEN time ← "unspecified time"
ELSE time ← Convert.RopeFromTime[pos.uniqueID.egmt.time, 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, " ", FullFmtIdxs[pos]]};
FmtIdxs: PUBLIC PROC [pos: ShortPosition] RETURNS [ROPE]
~ {RETURN FullFmtIdxs[Expand[pos]]};
FullFmtIdxs: PUBLIC PROC [pos: FullPosition] 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: ROPENIL] 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: ShortPosition, feedBack: STREAMNIL, selection: WhichSelection ← feedback]
= {FullOpenSource[desc, Expand[pos], feedBack, selection]};
FullOpenSource: PUBLIC PROC [desc: ROPE, pos: FullPosition, feedBack: IO.STREAMNIL, selection: WhichSelection ← feedback] = {
feedBack.PutRope[desc];
feedBack.PutRope[" is in "];
feedBack.PutRope[FullFormatPosition[pos]];
feedBack.PutRope[".\N"];
RETURN};
Expand: PROC [s: ShortPosition] RETURNS [FullPosition] ~ {
RETURN [[s.fileName, nullUniqueID, s.index]]};
END.