Copyright (C) 1994, Digital Equipment Corp.
{\em Resources\/} are arbitrary texts that are associated with applications. Resources can be bundled into an application using the
m3bundle facility. They may also be found in the
file system.
This interface supports retrieval of resources using a {\em search
path}. A search path is a list of elements; each element is either
a Pathname.T that refers to a directory, or a Bundle.T,
typically created by m3bundle.
INTERFACERsrc ; IMPORT RefList, Rd, Thread; TYPE Path = RefList.T; (* of Pathname.T or Bundle.T *) EXCEPTION NotFound; PROCEDURE Open (name: TEXT; path: Path): Rd.T RAISES {NotFound};
Ifnameis an absolute pathname, then look fornamein the file system: A reader is returned ifFileRd.Open(name)is successeful; otherwise an exception is raised. Ifnameis not an absolute pathname, then search each element ofpath, from front to back, for the first occurrence of the resource callednameand return a reader on the resource. If the path element is a pathnamep, then a reader is returned ifFileRd.Open(Pathname.Join (p, name, NIL))is successful. If the path element is a bundleb, a reader is returned ifTextRd.New(Bundle.Get(b, name))is successful. TheNotFoundexception is raised if no element ofpathyields a successful reader onname. It is a checked runtime error ifpathcontains an element that is neither a pathname nor a bundle.
PROCEDURE Get (name: TEXT; path: Path): TEXT
RAISES {NotFound, Rd.Failure, Thread.Alerted};
A convenience procedure to retrieve the contents of the resourcenameas aTEXT.
The procedure
Get is logically equivalent to
VAR rd := Open(name, path);
BEGIN
TRY
RETURN Rd.GetText(rd, LAST(CARDINAL))
FINALLY
Rd.Close(rd)
END
END;
The implementation is slightly more efficient, because it
takes advantage of Bundle.Get procedure which returns the
contents of the bundle element as a TEXT. The Rd.Failure
exception is raised if Rd.GetText or Rd.Close report a
problem. The Thread.Alerted can be raised by the call to
Rd.GetText.
PROCEDURE BuildPath (a1, a2, a3, a4: REFANY := NIL): Path;
Build aPathfrom the non-NILelements. Each element must be either aBundle.Tor aTEXT. If it is aTEXT, is assumed to be the pathname of a directory, unless it starts with a dollar sign, in which case it is assumed to be environment variable whose value is the name of a directory; the value is retrieved usingEnv.Get. It is a checked runtime error of the pathname is not valid.
END Rsrc.