NamesImpl.Mesa
Last modified by Swinehart, August 30, 1983 9:20 am
Last modified by Stewart, August 29, 1983 8:44 pm
DIRECTORY
Atom USING [ MakeAtom ],
Convert USING [ RopeFromInt ],
Names,
PupDefs USING [
AnyLocalPupAddress, PupAddress, PupAddressLookup ],
Rope USING [ Cat, Concat, Fetch, Length, MakeRope, ROPE, Size, SkipTo, Substr ],
RPC USING [ MakeKey, EncryptionKey ],
UserCredentials USING [ Get ]
;
NamesImpl: CEDAR PROGRAM
IMPORTS
Atom, Convert, PupDefs, RPC, Rope, UserCredentials
EXPORTS Names = {
ROPE: TYPE=Names.ROPE;
FileSpec: TYPE = Names.FileSpec;
FileSpecBody: TYPE = Names.FileSpecBody;
larkRegistry: ROPE=".Lark";
Obligatory concrete
NetError: PUBLIC ERROR[problem: Names.NetProblem] = CODE;
ParseFile: PUBLIC PROCEDURE[
server: ROPENIL,
dirName: ROPENIL,
dirPassword: ROPENIL,
fileName: ROPE←] RETURNS [spec: FileSpec] ={
start, end: INT;
spec←NEW[FileSpecBody←[
server: IF server#NIL THEN server ELSE "Indigo",
name: CurrentRName[],
password: UserCredentials.Get[].password]];
spec.dirName←IF dirName#NIL THEN Registrize[dirName] ELSE spec.name;
start𡤀
IF Rope.Fetch[fileName, start]='[ THEN {
end←Rope.SkipTo[fileName, start, "]"];
spec.server←Rope.Substr[fileName, start+1, end-start-1];
start𡤎nd+1; };
IF dirPassword#NIL THEN {
spec.dirPassword𡤍irPassword;
IF Rope.Fetch[fileName, start]='< THEN {
end←Rope.SkipTo[fileName, start, ">"];
spec.dirName←Rope.Substr[fileName, start+1, end-start-1];
start𡤎nd+1; }
ELSE IF dirName=NIL THEN ERROR; }
ELSE spec.dirPassword ← spec.password;
spec.fileName←Rope.Substr[fileName, start]; };
Registrize: PUBLIC PROC[name: ROPE] RETURNS [ROPE] = {
dot: INT;
IF name=NIL THEN RETURN[NIL];
dot←Rope.SkipTo[name, 0, "."];
IF dot=name.Length[] THEN name←Rope.Concat[name, DefaultRegistry[]];
RETURN[name]; };
CurrentRName: PUBLIC PROC RETURNS [ROPE] = {
RETURN[UserCredentials.Get[].name]; };
CurrentPasskey: PUBLIC PROC[passwordText: ROPE] RETURNS [RPC.EncryptionKey] = {
IF passwordText=NIL THEN passwordText←UserCredentials.Get[].password;
RETURN[RPC.MakeKey[passwordText]]; };
OwnNetAddress: PUBLIC PROC RETURNS [netAddress: Names.NetAddress] = TRUSTED {
pa: PupDefs.PupAddress;
pa ← PupDefs.AnyLocalPupAddress[[0,0]];
netAddress ← [net: pa.net, host: pa.host]; };
DefaultRegistry: PUBLIC PROC RETURNS [registry: ROPE] = {
name: ROPE=CurrentRName[];
dot: INT=Rope.SkipTo[name, 0, "."];
IF dot=name.Length[] THEN ERROR;
RETURN[name.Substr[dot]]; };
GetDefaultInstance: PUBLIC PROC[netAddress: Names.NetAddress, tryForName: BOOLTRUE]
RETURNS [instance: ROPE] = {
pa: PupDefs.PupAddress = [ net: [netAddress.net], host: [netAddress.host], socket: [a: 0, b: 0]];
IF tryForName THEN instance ← PupDefs.PupAddressLookup[pa!ANY=>CONTINUE];
IF instance=NIL THEN {
instance ← PupDefs.PupAddressToRope[pa];
instance ← Rope.Cat[Convert.RopeFromInt[pa.net, 8, FALSE], "#",
Convert.RopeFromInt[pa.host, 8, FALSE], "#0"];
IF instance#NIL THEN instance ← instance.Substr[len: instance.Length[]-1];
};
};
Conversion routines
LowerCaseRope: PROC[r: ROPE] RETURNS [ROPE] = {
RETURN[Rope.MakeRope[base: r, size: r.Size[], fetch: LCFetch]]};
LCFetch: SAFE PROC[data: REF, index: INT] RETURNS [c: CHAR] = TRUSTED {
SELECT (c←NARROW[data,ROPE].Fetch[index]) FROM IN ['A..'Z]=>c𡤌+('a-'A); ENDCASE};
RnameToRspec: PUBLIC PROC[name: Names.Rname, defaultRegistry: ROPENIL] RETURNS [spec: Names.Rspec] ={
j: INT𡤀
i: INT;
WHILE (i←Rope.SkipTo[s: name, pos: j, skip: "."])#Rope.Size[name] DO j←i+1; ENDLOOP;
IF j#0 THEN defaultRegistry←Rope.Substr[base: name, start: j] ELSE j←i+1;
IF Rope.Size[defaultRegistry]=0 THEN RETURN[NIL];
spec←NEW[Names.RspecBody←[simpleName: Rope.Substr[name, 0, j-1],
registry: defaultRegistry]]; };
RspecToName: PUBLIC PROC[spec: Names.Rspec] RETURNS [name: Names.Rname] = {
RETURN[Rope.Concat[spec.simpleName, Rope.Concat[".", spec.registry]]]; };
RspecToSortName: PUBLIC PROC[spec: Names.Rspec] RETURNS [name: ROPE] ={
RETURN[Rope.Concat[spec.registry, Rope.Concat[".", spec.simpleName]]]; };
RNameAtom: PUBLIC PROC[rName: Names.Rname] RETURNS [ATOM] = {
RETURN[Atom.MakeAtom[LowerCaseRope[rName]]]; };
}.