-- File: DBNamesImpl.mesa -- last edited by: -- Cattell, July 5, 1983 5:00 pm -- Donahue, July 28, 1983 3:13 pm -- Willie-sue, February 22, 1983 4:08 pm DIRECTORY DB, DBEnvironment, DBNames, NutOps, Rope, ViewerOps; DBNamesImpl: CEDAR PROGRAM IMPORTS Rope, DB, DBEnvironment, NutOps EXPORTS DBNames = BEGIN OPEN Rope, DB; Separator: PUBLIC CHAR _ '!; Sep: ROPE = Rope.FromChar[Separator]; EntityToName: PUBLIC PROC[ e: Entity, seg: DB.Segment _ NIL ] RETURNS[ name: ROPE ] = { IF NOT NutOps.IsSystemDomain[d: DomainOf[e]] THEN seg _ DB.SegmentOf[e]; name _ Rope.Cat[ DB.GetSegmentInfo[seg].filePath, Sep, NameOf[DomainOf[e]], Sep, NameOf[e] ]}; MakeName: PUBLIC PROC[seg: DB.Segment, d: Domain, eName: ROPE] RETURNS[name: ROPE] = { name _ Rope.Cat[GetSegmentInfo[seg].filePath, Sep, NameOf[d], Sep, eName]}; NameToEntity: PUBLIC PROC[name: ROPE, create: BOOL _ FALSE] RETURNS[e: Entity] = { segName, domainName, entityName: ROPE; domain: Domain; segment: DB.Segment; [segName, domainName, entityName] _ DecomposeName[name]; segment _ NutOps.AtomFromSegment[segName]; -- check to make sure that this is the right segment for the entity IF NOT Rope.Equal[DB.GetSegmentInfo[segment].filePath, segName] THEN RETURN[NIL]; domain _ DeclareDomain[ domainName, segment, Version[OldOnly] ! DBEnvironment.Error => CHECKED { domain _ NIL; CONTINUE } ]; e _ IF domain = NIL THEN NIL ELSE FetchEntity[ domain, entityName, segment ]; IF e = NIL AND domain # NIL AND create THEN e _ DeclareEntity[ domain, entityName ! DB.Error => CONTINUE ] }; SegmentOf: PUBLIC PROC[ name: ROPE ] RETURNS[ segment: DB.Segment ] = { segNameLength: INT = Rope.Find[name, Sep]; segName: ROPE = Rope.Substr[name, 0, segNameLength]; RETURN[ NutOps.AtomFromSegment[ segName ] ] }; DecomposeName: PUBLIC PROC[ name: ROPE ] RETURNS[ segment, domain, entity: ROPE ] = BEGIN segNameLength: INT = Rope.Find[ name, Sep ]; domainNameLength: INT = Rope.Find[ name, Sep, segNameLength+1 ] - segNameLength - 1; segment_ Rope.Substr[ name, 0, segNameLength ]; domain_ Rope.Substr[ name, segNameLength+1, domainNameLength ]; entity_ Rope.Substr[ name, segNameLength+domainNameLength+2 ]; END; END. . .