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
$109.41
Apple Inc.
+2.67
MSFT
$45.74
Microsoft Corpora
+0.58
GOOG
$504.89
Google Inc.
+9.50

MacTech Search:
Community Search:

Software Updates via MacUpdate

Command-C 1.1.7 - Clipboard sharing tool...
Command-C is a revolutionary app which makes easy to share your clipboard between iOS and OS X using your local WiFi network, even if the app is not currently opened. Copy anything (text, pictures,... Read more
Tidy Up 4.0.2 - Find duplicate files and...
Tidy Up is a complete duplicate finder and disk-tidiness utility. With Tidy Up you can search for duplicate files and packages by the owner application, content, type, creator, extension, time... Read more
Typinator 6.3 - 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
GraphicConverter 9.5 - Graphics editor w...
GraphicConverter is an all-purpose image-editing program that can import 200 different graphic-based formats, edit the image, and export it to any of 80 available file formats. The high-end editing... Read more
Toast Titanium 12.0.1 - The ultimate med...
Toast Titanium goes way beyond the very basic burning in the Mac OS and iLife software, and sets the standard for burning CDs, DVDs, and now Blu-ray discs on the Mac. Create superior sounding audio... Read more
QuickBooks 2015 16.0.2.1422 R3 - Financi...
Save 20% on QuickBooks Pro for Mac today through this special discount link QuickBooks Pro 2013 helps you manage your business easily and efficiently. Organize your finances all in one place, track... Read more
Remotix 3.0.6 - Access all your computer...
Remotix is a fast and powerful application to easily access multiple Macs (and PCs) from your own Mac. Features: Complete Apple Screen Sharing support - including Mac OS X login, clipboard... Read more
BetterZip Quick Look Generator 1.5 - Let...
BetterZip Quick Look Generator lets you view the contents of compressed archives through OS X's Quick Look functions. Simply select an archive in the Finder, in Mail, or Spotlight and press the... Read more
Sandvox 2.9.3 - Easily build eye-catchin...
Sandvox is for Mac users who want to create a professional looking website quickly and easily. With Sandvox, you don't need to be a Web genius to build a stylish, feature-rich, standards-compliant... Read more
Pixelmator 3.3.1 - Powerful layer-based...
Pixelmator is a beautifully designed, easy-to-use, fast, and powerful image editor for OS X. It has everything you need to create, edit, and enhance your images. Pixelmator is a layer-based image... Read more

Latest Forum Discussions

See All

Pentaction: Medieval (Games)
Pentaction: Medieval 1.0 Device: iOS Universal Category: Games Price: $1.99, Version: 1.0 (iTunes) Description: Pentaction: Medieval is a turn-based strategy board-game about chance and skill on the battlefield. Take control of your... | Read more »
Hipstify Review
Hipstify Review By Jennifer Allen on December 17th, 2014 Our Rating: :: COOL FILTERSUniversal App - Designed for iPhone and iPad Add filters, quotes, and fancy frames to your images, thanks to Hipstify.   | Read more »
Mighty Smighties Gets Evolve Cards and N...
Mighty Smighties Gets Evolve Cards and New Worlds Posted by Jessica Fisher on December 17th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »
Duckie Deck Card Wars Review
Duckie Deck Card Wars Review By Amy Solomon on December 17th, 2014 Our Rating: :: STYLISH GAME OF CARDSUniversal App - Designed for iPhone and iPad Duckie Deck Card Wars adapts the classic card game War for use on devices, complete... | Read more »
PDF Office Review
PDF Office Review By Jennifer Allen on December 17th, 2014 Our Rating: :: CONVENIENT PDF EDITINGiPad Only App - Designed for the iPad Want to create your own PDF files? Import them from elsewhere? Adapt a web page into a PDF? PDF... | Read more »
The Out There: Ω Edition Update will be...
The Out There: Ω Edition Update will be Releasing in 2015, Bringing Better Graphics and Additional Content Posted by Jessica Fisher on December 17th, 2014 [ permalink ] | Read more »
Pinball Planet Pro (Games)
Pinball Planet Pro 1.02 Device: iOS Universal Category: Games Price: $2.99, Version: 1.02 (iTunes) Description: - Our missionWe've always loved to play pinball games but we noticed most modern pinball games are simulators for the... | Read more »
Ultrakam 4k. The Professional Camera App...
Ultrakam 4k. The Professional Camera App. 3.0 Device: iOS Universal Category: Photography Price: $9.99, Version: 3.0 (iTunes) Description: In March 2014, Ultrakam brought Film Resolution for iPhone for the first time ever and now is... | Read more »
Email+ (Business)
Email+ 1.0 Device: iOS Universal Category: Business Price: $2.99, Version: 1.0 (iTunes) Description: Send email, fast! | Read more »
Mayor it up in SimCity BuildIt, Out Now
Mayor it up in SimCity BuildIt, Out Now Posted by Jessica Fisher on December 16th, 2014 [ permalink ] Universal App - Designed for iPhone and iPad | Read more »

Price Scanner via MacPrices.net

Holiday sales continue: MacBook Pros for up t...
 B&H Photo has new MacBook Pros on sale for up to $300 off MSRP as part of their Holiday pricing. Shipping is free, and B&H charges NY sales tax only: - 15″ 2.2GHz Retina MacBook Pro: $1699... Read more
Google Search App For iOS Gets A Major Makeov...
Google has given iOS users an early Christmas present with a substantial update of it’s not-very-often-upgraded Google Search app. Google Search has been my go-to tool for Web searches since it was... Read more
ShopKeep Apple Pay And Chip Card Reader Avail...
ShopKeep, a cloud-based technology provider to more than 10,000 small business owners to manage retail shops and restaurants with iPads, has released its new Apple Pay and chip card reader. This... Read more
Holiday sale! 27-inch 5K iMac for $2299, save...
 B&H Photo has the 27″ 3.5GHz 5K iMac in stock today and on sale for $2299 including free shipping plus NY sales tax only. Their price is $200 off MSRP, and it’s the lowest price available for... Read more
Holiday Sale! 3.7GHz Quad Core Mac Pro availa...
 B&H Photo has the 3.7GHz Quad Core Mac Pro on sale for $2599 including free shipping plus NY sales tax only. Their price is $400 off MSRP, and it’s the lowest price for this model from any... Read more
iPhone 6 Number 3 Canadian Google Search Of 2...
CTVNews.ca reports that Apple’s iPhone 6 was the third highest-trending Google Canada search topic of 2014, exceeded only by Robin Williams largely after his death by suicide in August, and the FIFA... Read more
New iPad mini 3 Counter-Top & Wall Mount...
newMacgadgets has announced new secure all-acrylic displays for the iPad mini 3 (also works fine with the mini 2, last year’s iPad mini With Retina Display, and the original iPad mini). The new iPad... Read more
Holiday sales continue, MacBook Airs for up t...
B&H Photo has 2014 MacBook Airs on sale for up to $120 off MSRP, for a limited time, for the Thanksgiving/Christmas Holiday shopping season. Shipping is free, and B&H charges NY sales tax... Read more
B&H lowers price on 27-inch 3.2GHz iMac t...
B&H Photo has lowered their price on the 27″ 3.2GHz iMac, now on sale for $1629 including free shipping plus NY sales tax only. Their price is $170 off MSRP, and it’s the lowest price for this... Read more
15-inch 2.0GHz Retina MacBook Pro available f...
B&H Photo has lowered their price on leftover 2013 15″ 2.0GHz Retina MacBook Pros to $1499 including free shipping plus NY sales tax only. Their price is $500 off original MSRP. Read more

Jobs Board

*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
*Apple* Retail - Multiple Positions (US) - A...
Job Description: Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, Read more
*Apple* Retail - Multiple Positions (US) - A...
Sales Specialist - Retail Customer Service and Sales Transform Apple Store visitors into loyal Apple customers. When customers enter the store, you're also the Read more
Project Manager / Business Analyst, WW *Appl...
…a senior project manager / business analyst to work within our Worldwide Apple Fulfillment Operations and the Business Process Re-engineering team. This role will work Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.