Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!sdd.hp.com!hp-pcd!hpcvra.cv.hp.com!rnews!hpcvbbs!akcs.joehorn From: akcs.joehorn@hpcvbbs.UUCP (Joseph K. Horn) Newsgroups: comp.sys.handhelds Subject: HP 48 Faster PGDIR Message-ID: <284dca48:3374comp.sys.handhelds@hpcvbbs.UUCP> Date: 6 Jun 91 05:40:08 GMT Lines: 85 FPGDIR, a FAST PGDIR, by Joseph K Horn. Makes PGDIR obsolete. When you use PGDIR on a very large directory, it can take a long time to finish. For example, I just used Donnelly's XTIME function to time PGDIR on a big directory, and it took a painful 50 seconds! Bill Wickes explains why in his excellent book, "HP 48 Insights": "PGDIR removes a directory specified by name. It does this by recursively executing CLVAR and PURGE recursively on each subdirectory until the original directory is empty. (This process can take a relatively long time if the directory is large.)" [Part I, page 96] Guess what! There's a better way! Those of you with HP-41CX's will remember the CLRALMS command that cleared all the alarms out. If you had a lot of alarms, it took a long time to finish, because it looped through the alarm buffer clearing each one individually. But a much better way was to treat the entire buffer as one object, and clear it in one fell swoop. This was possible with the buffer clearing functions available in several plug-in ROMs. For example, with the Extended-IL ROM, just execute 10 CLRBUF, and instantly the entire alarm buffer gets cleared, no matter how large it is. It turns out that there is a similar trick for purging directories on the HP 48. Rather than painfully looping through them, clearing their contents, we can treat the whole thing as a single object and PURGE it in one fell swoop. Here's the trick. The HP 48 Owner's Manual says: "Once a directory is empty, you can purge it like any other variable -- put its name on the stack and execute PURGE." [Volume 1, page 123] But "empty" means "when VARS == { }". And VARS == { } when all the vars are "hidden" behind a null-named object (see NULLNAME.DOC on Goodies Disk #1). So the quick way to purge a directory is: (1) Put its name on the stack; (2) Get into that directory: DUP EVAL; (3) Unhide everything (just in case): '' PURGE; (4) Hide all its vars: 0 '' STO; (5) Go back to the parent directory: UPDIR; (6) Purge the "empty" directory: PURGE. This process is automated by the following replacement for PGDIR: ---------------------< FPGDIR >--------------------------------- %%HP:T(1); \<< IF DUP TYPE 6 == THEN IF DUP VTYPE -1 == THEN DROP ELSE IF DUP VTYPE 15 == THEN DUP EVAL 0 # 15777h SYSEVAL DUP PURGE STO UPDIR PURGE ELSE 515 DOERR END END ELSE 514 DOERR END \>> ---------------------------------------------------------------- Except for its improved speed, its action is exactly like PGDIR. It even generates the same error messages as PGDIR in case of bad arguments. Nonexistent names simply get dropped (like PGDIR does). To use: place name of directory on stack, and run it. It does full argument type checking, so it should be idiot proof. I keep it assigned to my blue-shifted DEL key. That way it takes only three keystrokes to delete a directory (tic, menu, FPGDIR). It should be in "system RPL" ... but that's left as an exercise for the reader. :-) -- Joseph K Horn -- Peripheral Vision, Ltd. --