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

Tokkun Studio unveils alpha trailer for...
We are back on the MMORPG news train, and this time it comes from the sort of international developers Tokkun Studio. They are based in France and Japan, so it counts. Anyway, semantics aside, they have released an alpha trailer for the upcoming... | Read more »
Win a host of exclusive in-game Honor of...
To celebrate its latest Jujutsu Kaisen crossover event, Honor of Kings is offering a bounty of login and achievement rewards kicking off the holiday season early. [Read more] | Read more »
Miraibo GO comes out swinging hard as it...
Having just launched what feels like yesterday, Dreamcube Studio is wasting no time adding events to their open-world survival Miraibo GO. Abyssal Souls arrives relatively in time for the spooky season and brings with it horrifying new partners to... | Read more »
Ditch the heavy binders and high price t...
As fun as the real-world equivalent and the very old Game Boy version are, the Pokemon Trading Card games have historically been received poorly on mobile. It is a very strange and confusing trend, but one that The Pokemon Company is determined to... | Read more »
Peace amongst mobile gamers is now shatt...
Some of the crazy folk tales from gaming have undoubtedly come from the EVE universe. Stories of spying, betrayal, and epic battles have entered history, and now the franchise expands as CCP Games launches EVE Galaxy Conquest, a free-to-play 4x... | Read more »
Lord of Nazarick, the turn-based RPG bas...
Crunchyroll and A PLUS JAPAN have just confirmed that Lord of Nazarick, their turn-based RPG based on the popular OVERLORD anime, is now available for iOS and Android. Starting today at 2PM CET, fans can download the game from Google Play and the... | Read more »
Digital Extremes' recent Devstream...
If you are anything like me you are impatiently waiting for Warframe: 1999 whilst simultaneously cursing the fact Excalibur Prime is permanently Vault locked. To keep us fed during our wait, Digital Extremes hosted a Double Devstream to dish out a... | Read more »
The Frozen Canvas adds a splash of colou...
It is time to grab your gloves and layer up, as Torchlight: Infinite is diving into the frozen tundra in its sixth season. The Frozen Canvas is a colourful new update that brings a stylish flair to the Netherrealm and puts creativity in the... | Read more »
Back When AOL WAS the Internet – The Tou...
In Episode 606 of The TouchArcade Show we kick things off talking about my plans for this weekend, which has resulted in this week’s show being a bit shorter than normal. We also go over some more updates on our Patreon situation, which has been... | Read more »
Creative Assembly's latest mobile p...
The Total War series has been slowly trickling onto mobile, which is a fantastic thing because most, if not all, of them are incredibly great fun. Creative Assembly's latest to get the Feral Interactive treatment into portable form is Total War:... | Read more »

Price Scanner via MacPrices.net

Early Black Friday Deal: Apple’s newly upgrad...
Amazon has Apple 13″ MacBook Airs with M2 CPUs and 16GB of RAM on early Black Friday sale for $200 off MSRP, only $799. Their prices are the lowest currently available for these newly upgraded 13″ M2... Read more
13-inch 8GB M2 MacBook Airs for $749, $250 of...
Best Buy has Apple 13″ MacBook Airs with M2 CPUs and 8GB of RAM in stock and on sale on their online store for $250 off MSRP. Prices start at $749. Their prices are the lowest currently available for... Read more
Amazon is offering an early Black Friday $100...
Amazon is offering early Black Friday discounts on Apple’s new 2024 WiFi iPad minis ranging up to $100 off MSRP, each with free shipping. These are the lowest prices available for new minis anywhere... Read more
Price Drop! Clearance 14-inch M3 MacBook Pros...
Best Buy is offering a $500 discount on clearance 14″ M3 MacBook Pros on their online store this week with prices available starting at only $1099. Prices valid for online orders only, in-store... Read more
Apple AirPods Pro with USB-C on early Black F...
A couple of Apple retailers are offering $70 (28%) discounts on Apple’s AirPods Pro with USB-C (and hearing aid capabilities) this weekend. These are early AirPods Black Friday discounts if you’re... Read more
Price drop! 13-inch M3 MacBook Airs now avail...
With yesterday’s across-the-board MacBook Air upgrade to 16GB of RAM standard, Apple has dropped prices on clearance 13″ 8GB M3 MacBook Airs, Certified Refurbished, to a new low starting at only $829... Read more
Price drop! Apple 15-inch M3 MacBook Airs now...
With yesterday’s release of 15-inch M3 MacBook Airs with 16GB of RAM standard, Apple has dropped prices on clearance Certified Refurbished 15″ 8GB M3 MacBook Airs to a new low starting at only $999.... Read more
Apple has clearance 15-inch M2 MacBook Airs a...
Apple has clearance, Certified Refurbished, 15″ M2 MacBook Airs now available starting at $929 and ranging up to $410 off original MSRP. These are the cheapest 15″ MacBook Airs for sale today at... Read more
Apple drops prices on 13-inch M2 MacBook Airs...
Apple has dropped prices on 13″ M2 MacBook Airs to a new low of only $749 in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty... Read more
Clearance 13-inch M1 MacBook Airs available a...
Apple has clearance 13″ M1 MacBook Airs, Certified Refurbished, now available for $679 for 8-Core CPU/7-Core GPU/256GB models. Apple’s one-year warranty is included, shipping is free, and each... Read more

Jobs Board

Seasonal Cashier - *Apple* Blossom Mall - J...
Seasonal Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Seasonal Fine Jewelry Commission Associate -...
…Fine Jewelry Commission Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) Read more
Seasonal Operations Associate - *Apple* Blo...
Seasonal Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Read more
Hair Stylist - *Apple* Blossom Mall - JCPen...
Hair Stylist - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.