TweetFollow Us on Twitter

Library Manager
Volume Number:3
Issue Number:8
Column Tag:Pascal Procedures

Library Manager Cures HFS Brain Damage

By Dave Rausch, Fullerton, CA

Dave Raush is an expert on Mac music generation

“File Not Found!”

How many times have you run a compiler or linker program only to have it come up and say “file not found” after which the program returns you to the Finder or worse, crashes the system. Then you have to find the mystery file the program wants, then figure out which folder the program expects to find it, and try to coerce the program into locating it. Programs that make you do this are HFS brain damaged. They can’t find their way out of a paper bag. Microsoft is notorious for products which either can’t find files (MS Basic) or require files to be in certain folders (MS Word), or die when a file cannot be found (MS Fortran). While Apple provided an elegant way for applications to allow the user to find a document, via the standard file dialog, no thought was given to those types of programs which must locate a library or reference file that is either not known to the user, or not directly related to a user created document, but which is vital for the program to function. Think Technologies with their Lightspeed C and Pascal was one of the first companies to market a truly HFS smart compiler. If LS Pascal can’t find a file it needs, it asks the user to find it! What could be simpler or more straight forward? Who needs path managers? Who needs Finder DA’s? Who needs path name scripts? In this article I show how you can use this technique to make your applications HFS smart, by putting up a standard file dialog if a library file cannot be found. Once the user finds the file, it’s location is remembered in a resource so the dialog does not have to be repeated unless the file is moved or renamed. Why should a program (like 4th Dimension) prevent you from moving or renaming your files? Even though HFS has been with us for over a year and a half, many developers are still working around it, not with it. It’s time to make our programs HFS friendly and this article will show you how to do it.

Library Manager Tracks Your Files

As Macintosh programs become smarter and heftier, the need increases to maintain libraries of information that are external to the application itself. Because I am currently developing an application that requires three separate kinds of open file lists, I spent some time putting together what I call a “Library Manager” to help keep things straight. The classic example of a file you would use the library manager to track and open is the “dictionary”, a library type that may include a whole list of generic, technical, and user-defined files that should be opened automatically without unnecessary user intervention and without the user having to place them in either (a) the same folder with the application or (b) the System Folder which is beginning to get cluttered...; (Acius, are you paying attention?)

Fig. 1 Let the user find it!

Our application is a demonstration of how an application can be designed to keep track of and locate files without crashing, quiting or forcing the user to place or name files in a certain way. The demo application makes calls to what I have named the Library Manager, a unit of LS Pascal routines which provide the support for creating HFS friendly programs. By adding this Library Manager unit to your own projects, your applications can be made as HFS friendly as the products from Think Technologies.

Installing Library Manager

The Library Manager keeps track of application files using an application defined resource of type LMIR, Library Manager Information Resource. A separate LMIR resource is created for each file for which the application needs to know the whereabouts. The LMIR is shown defined below:

LMIR = RECORD  {Library Manager Info Record}
 rsrcID : integer;
 volname :  str31;
 vRef : integer;
 hfsvolume :   boolean;
 DirID :  Longint;
 filename : str63;
 fRefNum :  integer;
 next, prev :  LmirHdl;
 FTyp : integer;
 RecsOnFile, CurRec : integer;
 changed :  boolean;
 Status : (Open, Closed, NotFound);
 END;

Once the Library Manager code is added to an existing project and the routine OpenLib is called, the Manager is self-initializing. When a call is made to OpenLib for a LMIR resource that does not exist, OpenLib creates the resource and adds it to the current resource file. A typical setup routine is shown below that makes this call to OpenLib:

 PROCEDURE SetUpThings;
 BEGIN
 OpenLib(TopFile, ‘Application Default Library’); 
 {When program boots}
 OpenLinkedLib(TopFile, ‘User Default Library’); 
 {When program boots}
 END;

When OpenLib is called, if the appropriate LMIR resource does not exist or if the file the resource points to has been moved (or renamed, is unmounted, etc.) the user is prompted and allowed (not forced) to find or create a new library file. The message displayed to the user tells him the exact nature of the problem: The volume isn’t mounted, the file can’t be found, the file is already open for read/write, etc. All of the possible HFS file problems are clearly trapped and displayed here. No more “call Aldus, error number 1234” stuff.

For the developer, this means that once the library manager is added to his code and calls are made to OpenLib, he can

(1) Ignore prompts to find or create the library (until ready)

(2) Create a new library file someplace (and not be bothered again)

(3) Tell the program where he has moved the library file to

(4) Mount the volume that the library file is on, if that is the problem.

Note that moving the application won’t disturb the Library Manager’s ability to find a file, only tampering with the location or name of the library file itself.

Lotsa Lovely Linked Lists of Libraries

When calls are made to OpenLinkedLib additional library files are linked using a circular forward and backward chain. As many separate lists of files as desired can be created with OpenLib, and as many files can be added to any particular list with OpenLinkedLib as the application demands. Thus you can support a whole bunch of related files that must be opened at run time.

The linked lists allow you to search through all files of a given library type by using a loop along the lines of:

 next := top;
 repeat
 IFoundIt := YourSearchRoutine(next);
 next : next^^.next;
 until IFoundIt or (next = top);

Another agreeable aspect of linked lists is that the library manager requires you to define only one (global?) variable per list: the handle to the top item of the list.

Removing Files from a List

Call RemoveLib to close an open library file and remove it from the list. Note that RemoveLib always returns a valid handle if there are still any open libraries in the list. This allows you to remove even the “top” item from a library list, because RemoveLib automatically replaces it with a “new” top. If you are removing the top item from the list, you should reference it specifically when you pass it to RemoveLib.

 RemoveLib(Top); 
 { that is, whatever variable name you passed 
 to Open Lib originally }

not

 RemoveLib(next);

or

 RemoveLib(next^^.next);

if there’s a chance that next or next^^.next = Top.

A file that has been removed with RemoveLib can be reopened with OpenLinkedLib or OpenLib.

RemoveLib checks whether the changed field of the Library Manager Record is true. If so, it calls HandleChanges. HandleChanges does nothing! It is just included to give you the general idea.

Closing All Open Files in a List

At exit time, call CloseLibList for each library list that is open. It will close all open files in a list, by successive calls to RemoveLib, until the list is empty.

Access is by Resource Name, not Resource ID

As you will see when you examine OpenLib and GetLibResource, the library manager accesses files by a descriptive resource name rather than by resource ID.

The Library Manager was developed to work in conjunction with routines that will extend menus by allowing the user to create new menu items and associate those items with individual files. If you are allowing the user to extend libraries in this (or some similar) way, you should call GetLibResource before you call OpenLinkedLib or OpenLib to make sure that a “new” library descriptive name does not already exist. It is your responsibility to make sure that the names used to access resources are unique, the Library Manager does not check.

Library File Type

When the Library Manager creates a new file it assigns it type LMIR. Likewise, when you look for a file using the standard file dialog, it will only show you files of type LMIR. This can be modified according to your application’s requirements.

The Nitty Gritty of Tracking Things

The routines work with new roms or old roms, HFS or MFS volumes (or any mixture);

In order to actually install a LMIR resource, the user (or developer) is guided by the application through the Standard File Package.

In order to maintain compatibility between HFS and MFS, Apple fixed things so that the Standard File returns a working directory number instead of a volume reference number. The important thing about working directory numbers is that they are created on the fly and they are strictly temporary and relative to a particular session.

What is needed is to turn the working directory number into a Volume Name and a Directory ID. The procedure that does this is GetPathInfo. When a file needs to be opened, the procedure OpenWD creates a new working directory for the file from this information. This new working directory number is then passed to FSOpen as the volume reference. If the volume is MFS and not HFS, OpenWD simply returns the volume number instead of a working directory and FSOpen is still happy.

File IO on Open Files

The File reference number for an opened file is stored in the LMIR record. There are also fields to maintain information on file type, total records, current record number. You can, of course, add other fields to your LMIR definition (or remove some of mine).

The Program Lib Mgr Demo..

...does a minimum three things

1) It looks for mythical “application default” and “user default” library files.

2) It tells you the status of the files: Opened, Closed, NotFound.

3) It waits for you to press the mouse button and then closes the files (if any are open).

The first time you run the program it will prompt you to find or create the two files mentioned above. If you satisfy these requests, the next time it will simply open the files without your intervention. To see how the program handles various problems, try moving, deleting, renaming, dismounting one or both files and rerunning the program.

The program was developed in LightSpeed Pascal. If you are using something other than LightSpeed, remove the DisplayMsg procedure and use the DisplayMsg2 procedure.

The only resource that the file needs is an alert dialog, ID = 301 and its associated item list. If you run the program in Lightspeed project mode, make sure you use a project resource file, or the “current resource file” the LMIR resources will be added to will be your system file!

One last thing: this code will need to be modified to fit your particular needs. The Library Manager I’ve presented is meant to be suggestive, not definitive. I’m sure that you will have to make changes for your own application environment(s). But it will give you a good base to work from. Toward this end, direct access to procedures not specifically mentioned in this article is provided in the interface portion of the LibMgr unit.

Acknowledgements

The HFSRunning and NewRoms came from a utilities package developed by David O’Rourke that is in the public domain. Thanks, Dave!

And so, if there are no further questions, let’s break for lunch.


{1}
UNIT LibMgr;

INTERFACE
 USES
 Rom85, HFS;
 TYPE
 StandardType = (StandardGet, StandardPut);
 Outcome = (Success, Error, Cancellation);
 str63 = STRING[63];
 str31 = STRING[31];
 str80 = STRING[80];

 LmirPtr = ^Lmir;
 LmirHdl = ^LmirPtr;

 LMIR = RECORD  {Library Manager Info Record}
 rsrcID : integer;
 volname : str31;
 vRef : integer;
 hfsvolume : boolean;
 DirID : Longint;
 filename : str63;
 fRefNum : integer;
 next, prev : LmirHdl;
 FTyp : integer;
 RecsOnFile, CurRec : integer;
 changed : boolean;
 Status : (Open, Closed, NotFound);
 END;

 PROCEDURE GetPathInfo (vRefNum : integer;
 VAR rootVol : Str31;
 VAR hfsFlag : boolean;
 VAR WDirID : longint);

 FUNCTION OpenWD (VAR vRefNum : integer;
 DirID : longint) : OSErr;
 PROCEDURE OpenLib (VAR whichLib : LmirHdl;
 itsName : str255);
 PROCEDURE OpenLinkedLib (LinkTo : LmirHdl;
 ResName : str255);
 FUNCTION CreateLib (VAR newLib : LmirHdl) : boolean;
 FUNCTION FindLib (VAR theLib : LmirHdl) : boolean;
 PROCEDURE RemoveLib (VAR whichFile : LmirHdl);    
 {Close file and remove from list of open libraries}
 PROCEDURE CloseLibList (Top : LmirHdl); 
 {Close all open libraries in a given list and empty list}
 FUNCTION StandardFile (opCode : StandardType;
 oldName : Str255;
 fType : OSType;
 VAR vRef : integer) : str63;
 PROCEDURE GetLibraryResource (VAR theLibrary : LmirHdl;
 ResourceName : str255);

IMPLEMENTATION

 FUNCTION HFSRunning : boolean;
 CONST
 FSFCBLen = $3F6;
 VAR
 HFS : ^INTEGER;
 BEGIN
 HFS := POINTER(FSFCBLen);
 HFSRunning := (HFS^ > 0);
 END;

 FUNCTION NewRoms : boolean;
 CONST
 NewRomsID = 117;
 VAR
 RomVersion, Machine : INTEGER;
 BEGIN
 Environs(RomVersion, Machine);
 NewRoms := RomVersion >= NewRomsID;
 END;

 FUNCTION GetErrorMsg (Result : OSErr) : str80;
 BEGIN
 Result := abs(Result);
 CASE Result OF
33 : 
 GetErrorMsg := ‘the file directory is full.  ‘;
34 : 
 GetErrorMsg := ‘all allocation blocks on the volume are full.  ‘;
35 : 
 GetErrorMsg := ‘the specified volume is not mounted.  ‘;
36 : 
 GetErrorMsg := ‘there was an unspecified I/O Error.  ‘;
37 : 
 GetErrorMsg := ‘the file name or volume name is bad (perhaps zero-length). 
 ‘;
39 : 
 GetErrorMsg := ‘logical end-of-file was reached unexpetedly during read 
operation.  ‘;
40 : 
 GetErrorMsg := ‘an attempt was made to position before start of file. 
 ‘;
42 : 
 GetErrorMsg := ‘too many are files open.  ‘;
43 : 
 GetErrorMsg := ‘the file could not be found.  ‘;
44 : 
 GetErrorMsg := ‘the volume is locked by a hardware setting.  ‘;
45 : 
 GetErrorMsg := ‘the file is locked’;
46 : 
 GetErrorMsg := ‘the volume is locked by a software flag.  ‘;
47 : 
 GetErrorMsg := ‘the file is already in use.  ‘;
48 : 
 GetErrorMsg := ‘a file with the specified name exists and cannot be 
overwritten.  ‘;
49 : 
 GetErrorMsg := ‘the file is already open for read/write.  It cannot 
be reopened.  ‘;
50 : 
 GetErrorMsg := ‘no volume was specified and there is no default volume. 
‘;
51 : 
 GetErrorMsg := ‘a non-existent path was specified.  ‘;
52 : 
 GetErrorMsg := ‘there was an error finding current position in file. 
 ‘;
53 : 
 GetErrorMsg := ‘the specified volume is not on-line.  ‘;
54 : 
 GetErrorMsg := ‘there was an attempt to open a locked file for writing. 
 ‘;
55 : 
 GetErrorMsg := ‘there was an attempt to mount an already mounted volume. 
 ‘;
56 : 
 GetErrorMsg := ‘the specified drive number is not mounted.  ‘;
57 : 
 GetErrorMsg := ‘the volume lacks Macintosh-format directory.  ‘;
58 : 
 GetErrorMsg := ‘there was an external file system error.  ‘;
59 : 
 GetErrorMsg := ‘there was a problem during rename.  ‘;
60 : 
 GetErrorMsg := ‘the master directory block is bad; this volume must 
be reinitialized.  ‘;
61 : 
 GetErrorMsg := ‘the read/write permission of the file/folder does not 
allow writing . ‘;
108 : 
 GetErrorMsg := ‘there is insufficient application memory.  ‘;
120 : 
 GetErrorMsg := ‘the directory could not be found.  ‘;
121 : 
 GetErrorMsg := ‘too many working directories are open.  ‘;
122 : 
 GetErrorMsg := ‘a folder cannot be placed in its own subfolder.  ‘;
123 : 
 GetErrorMsg := ‘an attempt was made to do hierarchical operations on 
a nonhierarchical volume.  ‘;
127 : 
 GetErrorMsg := ‘there was an internal file system error.  ‘;
 END;
 END;

 PROCEDURE UpdateResource (vanilla : handle);
 BEGIN
 ChangedResource(vanilla);
 WriteResource(vanilla);
 END;

 PROCEDURE IOCheck (resultCode : OSErr);
 VAR
 ignore : INTEGER;
 errorString : Str255;
 BEGIN
 IF resultCode <> NoErr THEN
 BEGIN
 NumToString(resultCode, errorString);
 ParamText(‘Macintosh Error #’, errorString, ‘:  ‘, GetErrorMsg(resultCode));
 InitCursor;
 ignore := StopAlert(305, NIL);
 END
 END;

 FUNCTION StandardFile;
 {opCode : StandardType;  oldName : 
 Str255; fType : OSType; }
 {var vRef : integer) :  str63 }
 VAR
 where : Point;
 reply : SFReply;
 textType : SFTypeList;
 BEGIN
 where.h := 80;
 where.v := 55;
 textType[0] := fType;
 reply.vRefNum := vRef;
 IF opCode = StandardGet THEN
 SFGetFile(where, ‘Select Application to Launch’, NIL, 1, textType, NIL, 
reply)
 ELSE
 SFPutFile(where, ‘’, oldName, NIL, reply);
 WITH reply DO
 IF NOT good THEN
 StandardFile := ‘’
 ELSE
 BEGIN
 StandardFile := fName;
 vRef := vRefNum
 END
 END;

 PROCEDURE HandleChanges (changedFile : LmirHdl);
 BEGIN
 {A boolean field in the LMIR can be set if your   change records in 
memory but you do not immediately  write them out to the file... Then 
put whatever   routines you need to handle updates to records in 
 memory here}
 END;

 PROCEDURE RemoveLib;{var whichFile : LmirHdl);}
 VAR
 ReturnValidHdl : LmirHdl;
 BEGIN
 IF whichFile^^.changed THEN
 HandleChanges(whichFile);
 IF whichFile^^.status = Open THEN
 IOCheck(FSClose(whichFile^^.fRefNum));
 ReturnValidHdl := whichFile^^.next;
 whichFile^^.prev^^.next := whichFile^^.next;
 whichFile^^.next^^.prev := whichFile^^.prev;
 whichFile^^.status := Closed;
 UpdateResource(handle(whichFile));
 ReleaseResource(handle(whichFile));
 whichFile := ReturnValidHdl;
 END;

 PROCEDURE CloseLibList; {Top : LmirHdl; }
 VAR
 next : LmirHdl;
 BEGIN
 next := Top^^.next;
 REPEAT
 RemoveLib(next);
 UNTIL next = Top;
 RemoveLib(Top);
 END;

 FUNCTION OpenWD; {var vREfNum : integer; }
 { DirID : longint)  }
 {  : OSErr;   }
 VAR
 blk : WDPBRec;
 Result : OSErr;
 BEGIN
 blk.ioCompletion := NIL;
 Result := PBGetVol(@blk, false); 
 {this just sets ioWDProcID to whatever...}
 IF Result = NoErr THEN
 BEGIN
 WITH blk DO
 BEGIN
 ioNamePtr := NIL;
 ioVREfNum := vRefNum;
 ioWDDirID := DirID;
 END;
 Result := PBOPenWD(@blk, false);
 vRefNum := blk.ioVRefNum;
 END;
 OpenWD := Result;
 END;

 PROCEDURE GetPathInfo; { vRefNum : integer; }
 { var rootVol : Str31; }
 { var hfsFlag : boolean );}
 {var WDirID : longint;}
 VAR
 blk : CInfoPBRec;
 volBlk : HParamBlockRec;
 dirname : str255;
 BEGIN
 rootVol := ‘’;
 WITH volBlk DO
 BEGIN
 ioCompletion := NIL;
 ioNamePtr := @rootVol;
 ioVRefNum := vRefNum;
 ioVolindex := 0;
 ioVSigWord := 0;
 IOCheck(PBHGetVINfo(@volBlk, false));
 END;
 rootVol := Concat(rootVol, ‘:’);
 hfsFlag := HFSRunning;
 IF hfsFlag THEN
 WITH blk DO
 BEGIN
 ioCompletion := NIL;
 dirname := ‘’;
 ioNamePtr := @dirname;
 ioVRefNum := vRefNum;
 ioFDirINdex := -1;
 ioDrDirID := 0;
 IOCheck(PBGetCatINfo(@blk, false));
 WDirId := ioDrDirID;
 END;
 END;

 FUNCTION CreateLib; {newLib : LmirHdl; prompt : boolean) : boolean}
 CONST
 null = ‘’;
 VAR
 Result : OSERR;
 BEGIN
 CreateLib := False;
 WITH newLib^^ DO
 BEGIN
 Filename := StandardFile(StandardPut, ‘Make My Day’, ‘LMIR’, vref);
 IF Filename <> null THEN
 BEGIN
 Result := Create(FileName, vRef, ‘DAVE’, ‘LMIR’);
 IF Result = NoErr THEN
 BEGIN
 GetPathInfo(vRef, volName, hfsvolume, DirID);
 CreateLib := True;
 END
 ELSE
 IOCheck(Result);
 END
 END
 END;

 FUNCTION UserWantsToCreateLib : boolean;
 CONST
 yes = 1;
 VAR
 p1, p2, p3, p4 : str80;
 Response : integer;
 BEGIN
 p1 := ‘Create a new library? ‘;
 p2 := ‘’;
 p3 := ‘’;
 p4 := ‘’;
 ParamText(p1, p2, p3, p4);
 InitCursor;
 Response := CautionAlert(301, NIL);
 IF (Response = Yes) THEN
 UserWantsToCreateLib := true
 ELSE
 UserWantsToCreateLib := false;
 END;

 FUNCTION FindLib; {var  : theLib : LmirHdl; prompt : boolean; result 
: OSErr) : boolean}
 CONST
 null = ‘’;
 VAR
 dummy : OSERR;
 SaveRef : integer;
 BEGIN
 FindLib := False;
 WITH theLib^^ DO
 BEGIN
 Filename := StandardFile(StandardGet, ‘’, ‘LMIR’, vref);
 IF FileName <> null THEN
 BEGIN
 GetPathInfo(vRef, volName, hfsvolume, DirID);
 FindLib := True;
 END;
 END;
 END;

 FUNCTION UserWantsToFindLib (whichLib : LmirHdl;
 Reference : Str255;
 errorCode : OSErr) : boolean;
 CONST
 yes = 1;
 VAR
 p1, p2, p3, p4 : str80;
 Response : integer;
 UseName : str63;
 BEGIN
 IF whichLib^^.filename = ‘’ THEN
 UseName := Reference
 ELSE
 UseName := whichLib^^.filename;
 p1 := ConCat(‘The ‘, UseName, ‘ File was not opened because ‘);
 p2 := GetErrorMsg(ErrorCode);
 p3 := ‘Look for a library to open?  ‘;
 p4 := ‘’;
 ParamText(p1, p2, p3, p4);
 InitCursor;
 Response := CautionAlert(301, NIL);
 IF (Response = Yes) THEN
 UserWantsToFindLib := true
 ELSE
 UserWantsToFindLib := false;
 END;

 PROCEDURE GetUserHelp (whichLibrary : LmirHdl;
 ReferredToAs : str255;
 ErrMsg : OSErr);
 VAR
 Intent, Attainment, Cancelled : boolean;
 BEGIN
 whichLibrary^^.status := NotFound; 
 {Guilty until proven innocent}
 HLock(Handle(whichLibrary));

 IF UserWantsToFindLib(whichLibrary, ReferredToAs, ErrMsg) THEN
 IF FindLib(whichLibrary) THEN
 BEGIN
 UpdateResource(Handle(whichLibrary));
 whichLibrary^^.status := Closed;
 END;
 IF whichLibrary^^.status = NotFound THEN
 {User chose not to Open Existing File}
 REPEAT
 Intent := UserWantsToCreateLib;
 IF Intent THEN
 Attainment := CreateLib(whichLibrary);
 IF Intent AND Attainment THEN
 BEGIN
 UpdateResource(Handle(whichLibrary));
 whichLibrary^^.status := Closed;
 END;
 UNTIL (NOT Intent) OR (Attainment);
 HUnLock(Handle(whichLibrary));
 END;

 FUNCTION LibOpenedSuccessfully (LibToOpen : LmirHdl; VAR Result : OSErr) 
: boolean;
 VAR
 fRefNum : integer;
 SaveCurrentvol : integer;
 Success : boolean;
 Ignore : OSErr;
 BEGIN
 Success := False;
 Ignore := GetVol(NIL, SaveCurrentVol);
 {Save the default volume }
 MoveHHI(Handle(LibToOpen));
 HLock(Handle(LibToOpen));
 WITH LibToOpen^^ DO
 BEGIN
 result := SetVol(@volname, 0);
 {Is the root volume mounted?}
 IF Result = NoErr THEN
 result := GetVol(NIL, vRef);
 {Then make it default }
 IF (Result = NoErr) AND hfsVolume THEN
 {Open the Working Directory}
 Result := OpenWD(vRef, DirID);
 IF Result = NoErr THEN
 {Vref is now correct whether HFS or MFS}
 Result := FSOpen(fileName, vRef, fRefNum);
 IF Result = NoErr THEN
 BEGIN
 Success := True;
 status := open;
 END;
 END;
 HUnLock(Handle(LibToOpen));
 LibOpenedSuccessfully := Success;
 Ignore := SetVol(NIL, SaveCurrentVol);
 {Restore the original default volume}
 END;

 PROCEDURE InitLibResource (VAR Lib : LmirHdl;
 LibName : str255);

 BEGIN
 Lib := LmirHdl(newHandle(SizeOf(Lmir)));
 Lib^^.RsrcId := uniqueID(‘LMIR’);
 WITH Lib^^ DO
 BEGIN
 vRef := 0;
 RecsOnFile := 0;
 filename := ‘’;
 volname := ‘’;
 DirID := 0;
 FTyp := 0;
 RecsOnFile := 0;
 CurRec := 0;
 status := NotFound;
 changed := false;
 END;
 AddResource(Handle(Lib), ‘LMIR’, Lib^^.RsrcID, LibName);
 END;

 PROCEDURE GetLibraryResource; {var theLibrary : LmirHdl;  ResourceName 
: str255}
 BEGIN
 IF NewRoms THEN
 theLibrary := LmirHdl(Get1NamedResource( ‘LMIR’, ResourceName))
 ELSE
 theLibrary := LmirHdl(GetNamedResource( ‘LMIR’, ResourceName));
 END;

PROCEDURE OpenLib; {var whichLib : LmirHdl; itsName : str255}
 VAR
 Result : OSErr;
 BEGIN
 GetLibraryResource(whichLib, itsName);
 IF whichLib = NIL THEN
 InitLibResource(whichLib, itsName);
 {No resource even exists... Create one}

{Potential Problem #1 - The resource was *just* created by GetLibrary}
 IF whichLib^^.status = NotFound THEN 
 {A resource exists, but no file }
 GetUserHelp(whichLib, itsName, 43);
{Potential Problem #2 - The resource is there but the file couldn’t be 
opened}
 WHILE (whichLib^^.status = Closed) AND (NOT LibOpenedSuccessfully(whichLib, 
result)) DO
 GetUserHelp(whichLib, itsName, Result);

{Note: if the user refuses to either look for or create a file, then 
status will be set to NotFound}
{and the loop ends.  Of course, the loop also ends if a file is opened 
successfully.  }
 whichLib^^.next := whichLib;
 whichLib^^.prev := whichLib;
 END;

 PROCEDURE OpenLinkedLib; {LinkTo : LmirHdl;}
 { ResName : str255);}
 VAR
 nwLib : LmirHdl;
 BEGIN
 OpenLib(newLib, ResName);
 newLib^^.next := LinkTo^^.next;
 LinkTo^^.next := newLib;
 newLib^^.prev := LinkTo;
 newLib^^.next^^.prev := newLib;
 END;
END.

Fig. 2 Our demo puts up a standard file dialog

Fig. 3 Link Procedure


{2}
PROGRAM LibMgrDemo;
{$I-    Lightspeed Compiler Command}
 USES
 LibMgr;
 VAR
 TopFile : LmirHdl;

 PROCEDURE InitThings;
 BEGIN
 InitGraf(@thePort); {grafport for the screen}
 MoreMasters;
 MoreMasters;
 MoreMasters;
 InitFonts;
 InitWindows;
 InitMenus;
 TEInit;
 InitDialogs(NIL);
 FlushEvents(everyEvent, 0);
 InitCursor;
 END;

 PROCEDURE SetUpThings;
 BEGIN
 OpenLib(TopFile, ‘Application Default Library’); 
 {When program boots}
 OpenLinkedLib(TopFile, ‘User Default Library’); 
 {When program boots}
 END;

 PROCEDURE DisplayMsg2;
 VAR
 p1, p2, p3, p4 : str80;
 status : ARRAY[0..3] OF str80;
 x : integer;
 BEGIN
 Status[0] := ‘Open’;
 Status[1] := ‘Closed’;
 Status[3] := ‘Not Found’;
 x := Ord(TopFile^^.status);
 p1 := Concat(TopFile^^.filename, ‘ is ‘, Status[x], ‘.  ‘);
 x := Ord(TopFile^^.next^^.status);
 p2 := Concat(TopFile^^.next^^.filename, ‘ is ‘, Status[x], ‘.  ‘);
 p3 := ‘                                                             
  ‘;
 p4 := ‘Would you like a nice cool glass of lemonade?  ‘;
 ParamText(p1, p2, p3, p4);
 x := CautionAlert(301, NIL);
 END;

 PROCEDURE DisplayMsg;
 VAR
 next : LmirHdl;
 newRect : Rect;
 BEGIN
 SetRect(newRect, 80, 40, 430, 200);
 SetTextRect(newRect);
 ShowText;
 next := TopFile;
 REPEAT
 writeln(‘   The File ‘, next^^.filename, ‘ is ‘, next^^.status);
 next := next^^.next;
 UNTIL next = topfile;
 Writeln(‘   Press mouse button to close files and exit’);
 WHILE NOT button DO
 ;
 END;

 PROCEDURE CloseThings;
 BEGIN
 CloseLibList(TopFile);
 END;

BEGIN
 InitThings;
 SetUpThings;
 DisplayMsg;
 CloseThings;
END.

LibMgrRsrc.Rel

Type DITL

     ,301
3
*   1
Button Enabled
112 108 132 168
Yes

*   2
Button Enabled
112 246 132 306
No

*   3
StaticText Enabled
9 69 104 337
^0^1^2^3

Type ALRT
     ,301
60 60 210 420
301
CCCC
 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »
Embark into the frozen tundra of certain...
Chucklefish, developers of hit action-adventure sandbox game Starbound and owner of one of the cutest logos in gaming, has released their roguelike deck-builder Wildfrost. Created alongside developers Gaziter and Deadpan Games, Wildfrost will... | Read more »
MoreFun Studios has announced Season 4,...
Tension has escalated in the ever-volatile world of Arena Breakout, as your old pal Randall Fisher and bosses Fred and Perrero continue to lob insults and explosives at each other, bringing us to a new phase of warfare. Season 4, Into The Fog of... | Read more »
Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links below... | Read more »
Marvel Future Fight celebrates nine year...
Announced alongside an advertising image I can only assume was aimed squarely at myself with the prominent Deadpool and Odin featured on it, Netmarble has revealed their celebrations for the 9th anniversary of Marvel Future Fight. The Countdown... | Read more »
HoYoFair 2024 prepares to showcase over...
To say Genshin Impact took the world by storm when it was released would be an understatement. However, I think the most surprising part of the launch was just how much further it went than gaming. There have been concerts, art shows, massive... | Read more »
Explore some of BBCs' most iconic s...
Despite your personal opinion on the BBC at a managerial level, it is undeniable that it has overseen some fantastic British shows in the past, and now thanks to a partnership with Roblox, players will be able to interact with some of these... | Read more »

Price Scanner via MacPrices.net

You can save $300-$480 on a 14-inch M3 Pro/Ma...
Apple has 14″ M3 Pro and M3 Max MacBook Pros in stock today and available, Certified Refurbished, starting at $1699 and ranging up to $480 off MSRP. Each model features a new outer case, shipping is... Read more
24-inch M1 iMacs available at Apple starting...
Apple has clearance M1 iMacs available in their Certified Refurbished store starting at $1049 and ranging up to $300 off original MSRP. Each iMac is in like-new condition and comes with Apple’s... Read more
Walmart continues to offer $699 13-inch M1 Ma...
Walmart continues to offer new Apple 13″ M1 MacBook Airs (8GB RAM, 256GB SSD) online for $699, $300 off original MSRP, in Space Gray, Silver, and Gold colors. These are new MacBook for sale by... Read more
B&H has 13-inch M2 MacBook Airs with 16GB...
B&H Photo has 13″ MacBook Airs with M2 CPUs, 16GB of memory, and 256GB of storage in stock and on sale for $1099, $100 off Apple’s MSRP for this configuration. Free 1-2 day delivery is available... Read more
14-inch M3 MacBook Pro with 16GB of RAM avail...
Apple has the 14″ M3 MacBook Pro with 16GB of RAM and 1TB of storage, Certified Refurbished, available for $300 off MSRP. Each MacBook Pro features a new outer case, shipping is free, and an Apple 1-... Read more
Apple M2 Mac minis on sale for up to $150 off...
Amazon has Apple’s M2-powered Mac minis in stock and on sale for $100-$150 off MSRP, each including free delivery: – Mac mini M2/256GB SSD: $499, save $100 – Mac mini M2/512GB SSD: $699, save $100 –... Read more
Amazon is offering a $200 discount on 14-inch...
Amazon has 14-inch M3 MacBook Pros in stock and on sale for $200 off MSRP. Shipping is free. Note that Amazon’s stock tends to come and go: – 14″ M3 MacBook Pro (8GB RAM/512GB SSD): $1399.99, $200... Read more
Sunday Sale: 13-inch M3 MacBook Air for $999,...
Several Apple retailers have the new 13″ MacBook Air with an M3 CPU in stock and on sale today for only $999 in Midnight. These are the lowest prices currently available for new 13″ M3 MacBook Airs... Read more
Multiple Apple retailers are offering 13-inch...
Several Apple retailers have 13″ MacBook Airs with M2 CPUs in stock and on sale this weekend starting at only $849 in Space Gray, Silver, Starlight, and Midnight colors. These are the lowest prices... Read more
Roundup of Verizon’s April Apple iPhone Promo...
Verizon is offering a number of iPhone deals for the month of April. Switch, and open a new of service, and you can qualify for a free iPhone 15 or heavy monthly discounts on other models: – 128GB... Read more

Jobs Board

Relationship Banker - *Apple* Valley Financ...
Relationship Banker - Apple Valley Financial Center APPLE VALLEY, Minnesota **Job Description:** At Bank of America, we are guided by a common purpose to help Read more
IN6728 Optometrist- *Apple* Valley, CA- Tar...
Date: Apr 9, 2024 Brand: Target Optical Location: Apple Valley, CA, US, 92308 **Requisition ID:** 824398 At Target Optical, we help people see and look great - and Read more
Medical Assistant - Orthopedics *Apple* Hil...
Medical Assistant - Orthopedics Apple Hill York Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Now Read more
*Apple* Systems Administrator - JAMF - Activ...
…**Public Trust/Other Required:** None **Job Family:** Systems Administration **Skills:** Apple Platforms,Computer Servers,Jamf Pro **Experience:** 3 + years of Read more
Liquor Stock Clerk - S. *Apple* St. - Idaho...
Liquor Stock Clerk - S. Apple St. Boise Posting Begin Date: 2023/10/10 Posting End Date: 2024/10/14 Category: Retail Sub Category: Customer Service Work Type: Part Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.