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
 
AAPL
$519.01
Apple Inc.
+1.05
MSFT
$40.40
Microsoft Corpora
+0.65
GOOG
$556.54
Google Inc.
+20.10

MacTech Search:
Community Search:

Software Updates via MacUpdate

PDFpenPro 6.2 - Advanced PDF toolkit for...
PDFpenPro allows users to edit PDF's easily. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Create... Read more
PDFpen 6.2 - Edit and annotate PDFs with...
PDFpen allows users to easily edit PDF's. Add text, images and signatures. Fill out PDF forms. Merge or split PDF documents. Reorder and delete pages. Even correct text and edit graphics! Features... Read more
Monolingual 1.5.9 - Remove unwanted OS X...
Monolingual is a program for removing unnecesary language resources from OS X, in order to reclaim several hundred megabytes of disk space. It requires a 64-bit capable Intel-based Mac and at least... Read more
Maya 2015 - Professional 3D modeling and...
Maya is an award-winning software and powerful, integrated 3D modeling, animation, visual effects, and rendering solution. Because Maya is based on an open architecture, all your work can be scripted... Read more
Starcraft II: Wings of Liberty 1.1.1.180...
Download the patch by launching the Starcraft II game and downloading it through the Battle.net connection within the app. Starcraft II: Wings of Liberty is a strategy game played in real-time. You... Read more
Sibelius 7.5.0 - Music notation solution...
Sibelius is the world's best-selling music notation software for Mac. It is as intuitive to use as a pen, yet so powerful that it does most things in less than the blink of an eye. The demo includes... Read more
Typinator 5.9 - Speedy and reliable text...
Typinator turbo-charges your typing productivity. Type a little. Typinator does the rest. We've all faced projects that require repetitive typing tasks. With Typinator, you can store commonly used... Read more
MYStuff Pro 2.0.16 - Create inventories...
MYStuff Pro is the most flexible way to create detail-rich inventories for your home or small business. Add items to MYStuff by dragging and dropping existing information, uploading new images, or... Read more
TurboTax 2013.r17.002 - Manage your 2013...
TurboTax guides you through your tax return step by step, does all the calculations, and checks your return for errors and overlooked deductions. It lets you file your return electronically to get... Read more
TrailRunner 3.8.769 - Route planning for...
Note: While the software is classified as freeware, it is actually donationware. Please consider making a donation to help support development. TrailRunner is the perfect companion for runners,... Read more

Latest Forum Discussions

See All

Fourcast Review
Fourcast Review By Jennifer Allen on April 16th, 2014 Our Rating: :: VIDEO POTENTIALiPhone App - Designed for the iPhone, compatible with the iPad Fourcast is a great idea for combining video clips, but it does lack a number of... | Read more »
Hearthstone: Heroes of Warcraft is Avail...
Hearthstone: Heroes of Warcraft is Available on the U.S. App Store Right Now – Gogogogo! Posted by Rob Rich on April 16th, 2014 [ permalink ] | Read more »
Grammar Pop HD Review
Grammar Pop HD Review By Jennifer Allen on April 16th, 2014 Our Rating: :: FUN LEARNINGiPad Only App - Designed for the iPad Learning the different parts of speech isn’t always fun, but Grammar Pop HD makes it much more... | Read more »
Groundskeeper2 Review
Groundskeeper2 Review By Nadia Oxford on April 16th, 2014 Our Rating: :: SLICE THOSE ALIEN SLIMEUniversal App - Designed for iPhone and iPad Putting aside some minor control issues, Groundskeeper2 is a fun and furious action/... | Read more »
Pinnacle Studio for iPhone (Photography...
Pinnacle Studio for iPhone 5.0 Device: iOS iPhone Category: Photography Price: $9.99, Version: 5.0 (iTunes) Description: | Read more »
Season 3 of Zombies, Run! Starts Right N...
Season 3 of Zombies, Run! | Read more »
Snupps Review
Snupps Review By Jennifer Allen on April 16th, 2014 Our Rating: :: USEFUL LISTINGUniversal App - Designed for iPhone and iPad Got a huge collection that you need to organize, or just want to share with others? Snupps has it covered... | Read more »
Toad Rider Goes Free for a Limited Time,...
Toad Rider Goes Free for a Limited Time, Starting This Week Posted by Tre Lawrence on April 16th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Knights of Pen & Paper is Free for a...
Knights of Pen & Paper is Free for a Limited Time – Don’t Wait for a Natural 20, Get it Now! Posted by Rob Rich on April 16th, 2014 [ permalink ] | Read more »
R.B.I. Baseball 14 Review
R.B.I. Baseball 14 Review By Blake Grundman on April 16th, 2014 Our Rating: :: RETRO REVIVEDUniversal App - Designed for iPhone and iPad What was old is new again, as the MLB attempts to taking baseball gaming back to its retro... | Read more »

Price Scanner via MacPrices.net

Microsoft Blinks – Drops Microsoft Office 365...
Microsoft has dropped the annual subscription fee for Microsoft Office 365 Personal – which is needed in order to create and edit documents in Microsoft Office for iPad. However, Apple’s iOS and OS X... Read more
New AVG Vault Apps for iOS and Android Help K...
AVG Technologies N.V. an online security company for 177 million active users, has announced the launch of its latest mobile application, AVG Vault. The free app introduces an innovative user... Read more
Free Local Carrot iPhone App Helps Find Fresh...
I love fresh vegetables. I’m not a vegan, although I was for several years in the 1980s, but fresh vegetables and other whole foods are still my dietary mainstays as a matter of taste rather than... Read more
Apple refurbished iPad Airs available startin...
Apple is now offering Certified Refurbished iPad Airs for up to $140 off MSRP. Apple’s one-year warranty is included with each model, and shipping is free. The following Airs are available today: -... Read more
21-inch 2.7GHz iMac on sale for $1179, save $...
B&H Photo has the 21″ 2.7GHz iMac on sale for $1179 including free shipping plus NY sales tax only. Their price is $120 off MSRP. Add an iMac to your shopping cart, and B&H will offer an... Read more
Download our app, iTracx, for iOS and Android
MacPrices is proud to offer readers a free iOS app (iPhones, iPads, & iPod touch) and Android app (Google Play and Amazon App Store) called iTracx, which allows you to glance at today’s lowest... Read more
Education discounts shave up to $300 off the...
Purchase a new Mac at The Apple Store for Education and take up to $300 off MSRP. All teachers, students, and staff of any educational institution qualify for the discount. Shipping is free, and all... Read more
Save $50 on Mac mini Server
B&H Photo has the 2012 Mac mini Server on sale for $949 including free shipping plus NY sales tax only. Their price is $50 off MSRP. Read more
PhatWare’s “Ultimate Writing App For iOS” Ren...
PhatWare Corp. has announced it has renamed its new WritePro word processing app for iPhone and iPad: WritePad Pro. The decision to change the app’s name to leverages the strong brand awareness and... Read more
Full Resolution Photo Editor Tint Mint 1.0 Re...
California based independent developer, Jeffrey Sun, creator of the iOS app Modern Editor, has released Tint Mint, a new photography app for editing enthusiasts. The app costs a dollar, and it packs... Read more

Jobs Board

*Apple* Retail - Manager - Holyoke - Apple I...
Job Summary Keeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you’re a master of them all. In the store’s fast-paced, Read more
*Apple* Retail - Manager - Apple (United Sta...
Job SummaryKeeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you're a master of them all. In the store's fast-paced, dynamic Read more
*Apple* Solutions Consultant (ASC) - Apple (...
**Job Summary** The ASC is an Apple employee who serves as an Apple brand ambassador and influencer in a Reseller's store. The ASC's role is to grow Apple Read more
*Apple* Retail - Market Leader - Cincinnati...
…challenges of developing individuals, building teams, and affecting growth across Apple Stores. You demonstrate successful leadership ability - focusing on excellence Read more
*Apple* Retail - Manager - SoHo - Apple (Uni...
Job SummaryKeeping an Apple Store thriving requires a diverse set of leadership skills, and as a Manager, you're a master of them all. In the store's fast-paced, dynamic Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.