<> <> <> <<>> <> 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: 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: ShortPosition, feedBack: STREAM _ NIL, selection: WhichSelection _ feedback] = {FullOpenSource[desc, Expand[pos], feedBack, selection]}; FullOpenSource: PUBLIC PROC [desc: ROPE, pos: FullPosition, feedBack: IO.STREAM _ NIL, 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.