MorePfsNamesImpl.mesa
Copyright Ó 1990 by Xerox Corporation. All rights reserved.
Last tweaked by Mike Spreitzer on October 5, 1990 8:43:11 am PDT
DIRECTORY MorePfsNames, PFS, PFSNames, Rope, RopeParts, RuntimeError;
MorePfsNamesImpl:
CEDAR
PROGRAM
IMPORTS PFS, PFSNames, Rope, RopeParts
EXPORTS MorePfsNames
=
BEGIN OPEN RP:RopeParts, MorePfsNames;
ConsComponent:
PUBLIC
PROC [name: RopePart, version: Version ← [none]]
RETURNS [Component] ~ {
RETURN [[name: [name.base, name.start, name.len], version: version]]};
ConstructComponent:
PUBLIC
PROC [name: NamePart, version: Version ← [none]]
RETURNS [Component]
~ {RETURN ConsComponent[RP.InlineMake[name.base, name.start, name.len], version]};
ComponentName:
PUBLIC
PROC [c: Component]
RETURNS [RopePart]
~ {RETURN RP.InlineMake[c.name.base, c.name.start, c.name.len]};
ComponentToRope:
PUBLIC
PROC [c: Component]
RETURNS [
ROPE]
~ {RETURN PFS.RopeFromPath[PFSNames.ConstructName[LIST[c], FALSE, FALSE]]};
VersionToRope:
PUBLIC
PROC [v: Version]
RETURNS [
ROPE]
~ {RETURN ComponentToRope[ConsComponent[RP.nil, v]]};
Replace:
PUBLIC
PROC [base:
PATH, start:
INT ← 0, len:
INT ←
INT.
LAST, with:
PATH]
RETURNS [
PATH] ~ {
bl: INT ~ base.ComponentCount[];
wl: INT ~ with.ComponentCount[];
len ← MIN[len, bl-start];
IF start=0 AND len=bl THEN RETURN [with];
IF len=0 AND wl=0 THEN RETURN [base];
{cl: LIST OF Component ← NIL;
FOR i: INT IN [0..start) DO cl ← CONS[base.Fetch[i], cl] ENDLOOP;
FOR i: INT IN [0..wl) DO cl ← CONS[with.Fetch[i], cl] ENDLOOP;
FOR i: INT IN [start+len..bl) DO cl ← CONS[base.Fetch[i], cl] ENDLOOP;
RETURN PFSNames.ConstructName[components: cl, absolute: base.IsAbsolute[], directory: base.IsADirectory, reverse: TRUE]}};
Cons1:
PUBLIC
PROC [component: Component, absolute, directory:
BOOL ←
FALSE, unparsed:
REF ←
NIL]
RETURNS [name:
PATH] ~ {
RETURN PFSNames.ConstructName[LIST[component], absolute, directory, FALSE, unparsed]};
END.