SystemNamesImpl.mesa
Copyright Ó 1987, 1989, 1991, 1992, 1993 by Xerox Corporation. All rights reserved.
Doug Wyatt, January 24, 1987 7:03:35 pm PST
Willie-sue, August 19, 1991 2:12 pm PDT
JKF December 20, 1988 11:01:09 am PST
Carl Hauser, December 9, 1988 5:41:01 pm PST
Michael Plass, May 11, 1989 5:45:31 pm PDT
Christian Jacobi, March 31, 1993 3:20 pm PST
This impl of SystemNames simply gets the needed info from the environment string instead of going through YellowPages
DIRECTORY
EnvironmentVariables USING [Get],
IO,
RefText,
Rope,
SystemNames USING [Release, ReleaseOption],
SystemVersion USING [release],
ThisMachine USING [Name];
SystemNamesImpl: CEDAR MONITOR
IMPORTS EnvironmentVariables, IO, RefText, Rope, SystemVersion, ThisMachine
EXPORTS SystemNames ~ {
ROPE: TYPE ~ Rope.ROPE;
Release: TYPE ~ SystemNames.Release;
ReleaseOption: TYPE ~ SystemNames.ReleaseOption;
ReleaseArray: TYPE ~ ARRAY Release OF ROPE;
releaseNames: REF ReleaseArray ~ NEW[ReleaseArray ¬ ALL[NIL]];
defaultDir: ROPE ~ "Cedar";
machineLocalDir: ROPE ~ "tmp";
Initialize: PROC ~ {
Version: TYPE ~ RECORD [major, minor: INT];
current: Version ~ [major: SystemVersion.release.major, minor: SystemVersion.release.minor];
previous: Version ~ IF current.minor>0 THEN [major: current.major, minor: current.minor-1]
ELSE
[major: 0, minor: 0]; -- must edit this by hand each major release
next: Version ~ [major: current.major, minor: current.minor+1];
versions: ARRAY Release OF Version ¬ [previous: previous, current: current, next: next];
FOR r: Release IN Release DO
v: Version ~ versions[r];
releaseNames[r] ¬ Rope.Flatten[IO.PutFR["%g.%g", IO.int[v.major], IO.int[v.minor]]];
ENDLOOP;
};
ReleaseName: PUBLIC PROC [release: Release ¬ current] RETURNS [ROPE] ~ {
RETURN [releaseNames[release]];
};
userName: ROPE ¬ NIL;
UserName: PUBLIC ENTRY PROC RETURNS [name: ROPE] ~ {
IF userName = NIL THEN userName ¬ EnvironmentVariables.Get["USER"];
name ¬ userName;
};
homeDirectory: ROPE ¬ NIL;
SimpleHomeDirectory: PUBLIC ENTRY PROC RETURNS [wdir: Rope.ROPE] ~ {
IF homeDirectory = NIL THEN {
temp: ROPE ¬ EnvironmentVariables.Get["HOME"];
IF temp.Fetch[temp.Length[]-1] # '/ THEN temp ¬ temp.Concat["/"];
homeDirectory ¬ temp;
};
wdir ¬ homeDirectory;
};
MachineName: PUBLIC PROC RETURNS [machine: ROPE ¬ NIL] ~ {
machine ¬ ThisMachine.Name[];
IF machine=NIL THEN machine ¬ "AnonymousMachine";
};
ReleaseDir: PUBLIC PROC [dir: ROPE, release: Release] RETURNS [ROPE] ~ {
releaseName: ROPE ~ releaseNames[release];
IF dir = NIL THEN dir ¬ defaultDir;
RETURN[Rope.Flatten[Rope.Concat[dir, releaseName]]];
};
ReleaseSubDir: PUBLIC PROC [subDirs: ROPE, release: Release] RETURNS [ROPE] ~ {
releaseName: ROPE ~ releaseNames[release];
IF Rope.IsEmpty[subDirs] THEN RETURN[releaseName]
ELSE
RETURN[Rope.Flatten[Rope.Cat[releaseName, "/", subDirs]]];
};
MachineLocalDir: PUBLIC PROC [subDirs: ROPE, option: ReleaseOption,
release: Release ¬ current] RETURNS [ROPE] ~ {
RETURN[ConstructDir[machineLocalDir, subDirs, option, release]];
};
CedarDir: PUBLIC PROC [subDirs: ROPE, release: Release, dir: ROPE] RETURNS [ROPE] ~ {
IF dir=NIL THEN dir ¬ defaultDir;
RETURN[ConstructDir[dir, subDirs, $releaseDir, release]];
};
UserCedarDir: PUBLIC PROC [subDirs: ROPE, option: ReleaseOption, release: Release]
RETURNS [ROPE] ~ {
dir: ROPE ¬ NIL;
SELECT option FROM
releaseDir => dir ¬ ReleaseDir[dir, release];
releaseOmitted => NULL;
ENDCASE => ERROR;
RETURN[ConstructName[dir, subDirs, TRUE]];
};
ConstructDir: PROC [ dir, subDirs: ROPE, option: ReleaseOption, release: Release]
RETURNS [ROPE] ~ {
SELECT option FROM
releaseDir => dir ¬ ReleaseDir[dir, release];
releaseSubDir => subDirs ¬ ReleaseSubDir[subDirs, release];
releaseOmitted => NULL;
ENDCASE => ERROR;
RETURN[ConstructName[dir: dir, subDirs: subDirs]];
};
ConstructName: PROC [dir, subDirs: ROPE ¬ NIL, userRelative: BOOL ¬ FALSE]
RETURNS [fName: ROPE] = {
GetTildeRope: PROC RETURNS [r: Rope.ROPE] = {
ie return something like: "/palain/wyatt/Cedar"
r ¬ SimpleHomeDirectory[];
IF r = NIL THEN ERROR -- can't happen. presumably the user logged on.
ELSE RETURN[Rope.Concat[r, ".cedar"]];
};
scratch: REF TEXT ~ RefText.ObtainScratch[120];
text: REF TEXT ¬ scratch;
IF userRelative THEN text ¬ RefText.AppendRope[text, GetTildeRope[]];
text ¬ RefText.AppendChar[text, '/ ];
IF NOT Rope.IsEmpty[dir] THEN {
text ¬ RefText.AppendRope[text, dir];
text ¬ RefText.AppendChar[text, '/ ];
};
IF NOT Rope.IsEmpty[subDirs] THEN {
text ¬ RefText.AppendRope[text, subDirs];
text ¬ RefText.AppendChar[text, '/ ];
};
fName ¬ Rope.FromRefText[text];
RefText.ReleaseScratch[scratch];
};
Initialize[];
}.