XlAccessImpl.mesa
Copyright Ó 1988, 1991, 1992, 1993 by Xerox Corporation. All rights reserved.
Christian Jacobi, May 11, 1988 6:05 pm PST
Christian Jacobi, March 10, 1993 10:43 am PST
Willie-s, September 30, 1991 6:24 pm PDT
NOTE: different source for different architectures.
This is for portable Cedar on top of PCR.
DIRECTORY Ascii, Atom, Convert, EnvironmentVariables, Identification
, IO, NetworkName, SystemNames, Rope, XlAccess;
XlAccessImpl:
CEDAR
PROGRAM
IMPORTS Ascii, Atom, Convert, EnvironmentVariables, IO, NetworkName, Rope, SystemNames
EXPORTS Identification, XlAccess =
BEGIN
hostName: Rope.ROPE ¬ SystemNames.MachineName[];
cirioPort: Rope.ROPE ¬ GetCirioPortRope[];
ident: Rope.ROPE ¬ IO.PutFR["%g (%g)", IO.rope[hostName], IO.rope[cirioPort]];
GetCirioPortNum:
PROC []
RETURNS [n:
CARD ¬ 0] = {
Get:
PROC []
RETURNS [
CARD] =
TRUSTED
MACHINE
CODE {
"CirioNubLocalGetPort"
};
n ¬ Get[ ! UNCAUGHT => CONTINUE ]
};
GetCirioPortRope:
PROC []
RETURNS [Rope.
ROPE] = {
RETURN [Convert.RopeFromCard[GetCirioPortNum[]]]
};
Self:
PUBLIC PROC [a:
ATOM ¬
NIL]
RETURNS [Rope.
ROPE] = {
SELECT a
FROM
NIL => RETURN [ident];
$Host => RETURN [hostName];
$Cirio => RETURN [cirioPort];
ENDCASE => RETURN [ident];
};
ServerNameFromProperties:
PROC [for:
ATOM]
RETURNS [name: Rope.
ROPE ¬
NIL] = {
IF for=NIL THEN for ¬ $X11;
WITH Atom.GetProp[for, $DISPLAY]
SELECT
FROM
r: Rope.ROPE => name ¬ r;
ENDCASE => {};
};
IsArpaAddress:
PROC [r: Rope.
ROPE]
RETURNS [
BOOL ¬
FALSE] ~ {
len: INT ~ Rope.Length[r];
IF len>0
AND Ascii.Digit[Rope.Fetch[r, 0]]
THEN
IF Rope.SkipOver[s: r, skip: "0123456789."] >= len
THEN
IF Rope.Match[pattern: "*.*.*.*", object: r] THEN RETURN [TRUE]
};
SubstituteLocalNames:
PROC [serverName: Rope.
ROPE]
RETURNS [Rope.
ROPE] = {
IF ~IsLocalHost[serverName] THEN RETURN [serverName]
ELSE {
localHost: Rope.ROPE ~ "localhost";
colonPos: INT ~ Rope.SkipTo[s: serverName, skip: ":"];
RETURN [ Rope.Replace[base: serverName, len: colonPos, with: localHost] ];
};
};
StripDisplayNumber:
PROC [name: Rope.
ROPE]
RETURNS [Rope.
ROPE] = {
colonPos: INT ¬ Rope.SkipTo[s: name, skip: ":"];
RETURN [Rope.Substr[name, 0, colonPos]]
};
IsLocalHost:
PUBLIC PROC [serverName: Rope.
ROPE]
RETURNS [
BOOL] = {
serverName ¬ StripDisplayNumber[serverName];
SELECT
TRUE
FROM
Rope.IsEmpty[serverName] => RETURN [TRUE];
Rope.Equal["localhost", serverName, FALSE] => RETURN [TRUE];
Rope.Equal["unix", serverName, FALSE] => RETURN [TRUE];
Rope.Equal["127.0.0.1", serverName, FALSE] => RETURN [TRUE];
Rope.Equal["[127.0.0.1]", serverName, FALSE] => RETURN [TRUE];
Rope.Equal[hostName, serverName, FALSE] => RETURN [TRUE];
ENDCASE => RETURN [FALSE]
};
DefaultServer:
PUBLIC
PROC [for:
ATOM ¬
NIL]
RETURNS [serverName: Rope.
ROPE] = {
IF for#$Unix
THEN {
serverName ¬ ServerNameFromProperties[for];
IF Rope.IsEmpty[serverName]
AND for#
NIL
THEN
serverName ¬ ServerNameFromProperties[NIL]
};
IF Rope.IsEmpty[serverName] THEN serverName ¬ EnvironmentVariables.Get["DISPLAY"];
serverName ¬ SubstituteLocalNames[serverName];
};
AddressFromNameFailed: PUBLIC ERROR [msg: Rope.ROPE] = CODE;
AddressFromName:
PUBLIC
PROC [name: Rope.
ROPE]
RETURNS [address: Rope.
ROPE ¬
NIL] = {
Raise: PROC[msg: Rope.ROPE] = {AddressFromNameFailed[msg]};
name ¬ StripDisplayNumber[name];
IF IsArpaAddress[name] THEN RETURN [name];
IF IsLocalHost[name] THEN RETURN ["127.0.0.1"];
address ¬ NetworkName.AddressFromName[family: $ARPA, name: name, components: host ! NetworkName.Error => Raise[msg]].addr;
};
END.