VersionMap2PrettyImpl.Mesa
Copyright Ó 1990 by Xerox Corporation. All rights reserved.
Last tweaked by Mike Spreitzer on April 10, 1992 9:31 am PDT
DIRECTORY Convert, IO, PFS, Rope, VersionMap2, VersionMap2Pretty;
VersionMap2PrettyImpl: CEDAR PROGRAM
IMPORTS Convert, IO, PFS, Rope, VersionMap2
EXPORTS VersionMap2Pretty
=
BEGIN OPEN VersionMap2, VersionMap2Pretty;
FormatName: PUBLIC PROC [name: Name] RETURNS [ROPE] ~ {
IF name=nullName THEN RETURN ["*"];
RETURN [PFS.RopeFromPath[name]]};
ParseName: PUBLIC PROC [r: ROPE] RETURNS [Name] ~ {
IF r.Equal["*"] THEN RETURN [nullName];
RETURN [PFS.PathFromRope[r]]};
FormatCreated: PUBLIC PROC [c: Created] RETURNS [r: ROPE] ~ {
IF c=nullCreated THEN RETURN ["*"];
r ← Convert.RopeFromTime[from: c.egmt.gmt, end: seconds, useAMPM: FALSE];
IF c.egmt.usecs#0 THEN {
sep: INT ~ r.FindBackward[" "];
r ← r.Replace[start: sep, len: 0, with: IO.PutFR1[".%06d", [cardinal[c.egmt.usecs]]]]};
IF c.host # [0, 0] THEN r ← IO.PutFR["%g at [%g, %g]", [rope[r]], [cardinal[c.host.a]], [cardinal[c.host.b]] ];
RETURN};
ParseCreated: PUBLIC PROC [r: ROPE] RETURNS [c: Created ← nullCreated] ~ {
ENABLE Convert.Error => GOTO Err;
dotpos: INT ~ r.Find["."];
IF r.Equal["*"] THEN RETURN [nullCreated];
IF dotpos > 0 THEN {
sep: INT ~ r.Index[s2: " ", pos1: dotpos];
usr: ROPE ~ r.Substr[start: dotpos+1, len: sep-(dotpos+1)];
IF sep >= r.Length THEN GOTO Err;
c.egmt.usecs ← Convert.CardFromRope[usr];
r ← r.Replace[start: dotpos, len: sep-dotpos, with: NIL]};
{atpos: INT ~ r.Find[" at ["];
IF atpos > 0 THEN {
commapos: INT ~ r.Index[atpos, ","];
closepos: INT ~ r.Index[commapos, "]"];
IF closepos >= r.Length[] THEN GOTO Err;
c.host.a ← Convert.CardFromRope[r.Substr[atpos+5, commapos-(atpos+5)]];
c.host.b ← Convert.CardFromRope[r.Substr[commapos+1, closepos-(commapos+1)]];
r ← r.Substr[len: atpos]};
c.egmt.gmt ← Convert.TimeFromRope[r];
RETURN};
EXITS Err => ERROR Error[[client, $CreatedSyntaxError, IO.PutFR1["\"%q\" does not follow created syntax", [rope[r]]], r]]};
FormatStamp: PUBLIC PROC [s: VersionStamp] RETURNS [r: ROPE] ~ {
IF s=nullStamp THEN RETURN ["*"];
r ← IO.PutFR["%08x%08x", [cardinal[s[0]]], [cardinal[s[1]]] ];
RETURN};
ParseStamp: PUBLIC PROC [r: ROPE] RETURNS [s: VersionStamp ← nullStamp] ~ {
IF r.Equal["*"] THEN RETURN [nullStamp];
IF r.Length[] # 16 THEN ERROR Error[[client, $StampSyntaxError, IO.PutFR1["\"%q\" does not follow version stamp syntax", [rope[r]]], r]];
{ENABLE Convert.Error => ERROR Error[[client, $StampSyntaxError, IO.PutFR1["\"%q\" does not follow version stamp syntax", [rope[r]]], r]];
s[0] ← Convert.CardFromRope[r.Substr[len: 8], 16];
s[1] ← Convert.CardFromRope[r.Substr[start: 8], 16];
RETURN}};
FormatTuple: PUBLIC PROC [t: VersionTuple] RETURNS [ROPE] ~ {
RETURN Rope.Cat[FormatName[t.name], " of ", FormatCreated[t.created], " ver ", FormatStamp[t.stamp] ]};
ParseTuple: PUBLIC PROC [r: ROPE] RETURNS [t: VersionTuple ← nullTuple] ~ {
verpos: INT ~ r.FindBackward[" ver "];
IF verpos < 0 THEN ERROR Error[[client, $TupleSyntaxError, IO.PutFR1["\"%q\" does not follow version tuple syntax (<name> of <created> ver <version stamp>)", [rope[r]]], r]];
{ofpos: INT ~ r.FindBackward[" of ", verpos];
IF ofpos <= 0 THEN ERROR Error[[client, $TupleSyntaxError, IO.PutFR1["\"%q\" does not follow version tuple syntax (<name> of <created> ver <version stamp>)", [rope[r]]], r]];
t.name ← ParseName[r.Substr[len: ofpos]];
t.created ← ParseCreated[r.Substr[start: ofpos+4, len: verpos-(ofpos+4)]];
t.stamp ← ParseStamp[r.Substr[start: verpos+5]];
RETURN}};
ListMap: PUBLIC PROC [map: Map, to: IO.STREAM, inOrder: BOOL, filters: MapList ← NIL]
~ {FactoredListMap[map, to, inOrder, PatternFactorMapList[filters]]};
FactoredListMap: PUBLIC PROC [map: Map, to: IO.STREAM, inOrder: BOOL, pfml: PatternFactoredMapList ← []] ~ {
ListTuple: PROC [t: VersionTuple] RETURNS [BOOL] ~ {
to.PutRope[FormatTuple[t]];
to.PutRope["\n"];
RETURN [FALSE]};
IF map.FactoredScan[ListTuple, inOrder, pfml].found THEN ERROR;
RETURN};
END.