XNSCHNameImpl.mesa
Demers, January 15, 1987 6:08:08 pm PST
DIRECTORY
DefaultRemoteNames USING [Get],
Rope USING [Cat, Index, IsEmpty, Length, ROPE, Substr],
XNSCHName USING [DomainName, maxDomainLength, maxObjectLength, maxOrganizationLength, Name];
XNSCHNameImpl: CEDAR PROGRAM
IMPORTS --DefaultRemoteNames,-- Rope
EXPORTS XNSCHName
~ {
OPEN XNSCHName;
ROPE: TYPE ~ Rope.ROPE;
FieldTooLong: PUBLIC SIGNAL [which: CARDINAL] ~ CODE;
GetDefaultDomain: PROC [hint: ROPE] RETURNS [default: ROPE] ~ {
default ← IF NOT Rope.IsEmpty[hint]
THEN hint
ELSE (DefaultRemoteNames.Get[]).domain;
ELSE "PARC";
};
GetDefaultOrganization: PROC [hint: ROPE] RETURNS [default: ROPE] ~ {
default ← IF NOT Rope.IsEmpty[hint]
THEN hint
ELSE (DefaultRemoteNames.Get[]).organization;
ELSE "Xerox";
};
NameFromRope: PUBLIC PROC [rope: ROPE,
defaultDomain: ROPENIL, defaultOrganization: ROPENIL]
RETURNS [name: Name] ~ {
pos1, pos2, pos3, len: INT;
len1, len2, len3: INT ← 0;
len ← Rope.Length[rope];
pos1 ← 0;
{
len1 ← Rope.Index[s1~rope, pos1~pos1, s2~":"];
pos2 ← len1 + 1;
pos3 ← pos2 + 1;
IF len1 > maxObjectLength THEN {
SIGNAL FieldTooLong[1];
len1 ← maxObjectLength };
};
name.object ← Rope.Substr[base~rope, start~pos1, len~len1];
IF pos2 <= len THEN {
pos3 ← Rope.Index[s1~rope, pos1~pos2, s2~":"];
len2 ← pos3 - pos2;
pos3 ← pos3 + 1;
IF len2 > maxDomainLength THEN {
SIGNAL FieldTooLong[2];
len2 ← maxDomainLength };
};
IF len2 > 0
THEN name.domain ← Rope.Substr[base~rope, start~pos2, len~len2]
ELSE name.domain ← GetDefaultDomain[defaultDomain];
IF pos3 <= len THEN {
len3 ← len - pos3;
IF len3 > maxOrganizationLength THEN {
SIGNAL FieldTooLong[3];
len3 ← maxOrganizationLength;
};
};
IF len3 > 0
THEN name.organization ← Rope.Substr[base~rope, start~pos3, len~len3]
ELSE name.organization ← GetDefaultOrganization[defaultOrganization];
};
DomainNameFromRope: PUBLIC PROC [rope: ROPE,
defaultDomain: ROPENIL, defaultOrganization: ROPENIL]
RETURNS [domainName: DomainName] ~ {
pos2, pos3, len: INT;
len2, len3: INT ← 0;
len ← Rope.Length[rope];
pos2 ← 0;
{
len2 ← Rope.Index[s1~rope, pos1~pos2, s2~":"];
pos3 ← len2 + 1;
IF len2 > maxDomainLength THEN {
SIGNAL FieldTooLong[2];
len2 ← maxDomainLength };
};
IF len2 > 0
THEN domainName.domain ← Rope.Substr[base~rope, start~pos2, len~len2]
ELSE domainName.domain ← GetDefaultDomain[defaultDomain];
IF pos3 <= len THEN {
len3 ← len - pos3;
IF len3 > maxOrganizationLength THEN {
SIGNAL FieldTooLong[3];
len3 ← maxOrganizationLength;
};
};
IF len3 > 0
THEN domainName.organization ← Rope.Substr[base~rope, start~pos3, len~len3]
ELSE domainName.organization ← GetDefaultOrganization[defaultOrganization];
};
RopeFromName: PUBLIC PROC [name: Name] RETURNS [rope: ROPE] ~ {
rope ← Rope.Cat[name.object, ":", name.domain, ":", name.organization];
};
RopeFromDomainName: PUBLIC PROC [domainName: DomainName] RETURNS [rope: ROPE] ~ {
rope ← Rope.Cat[domainName.domain, ":", domainName.organization];
};
}...