From: jhmeyers@miu.edu (John H Meyers)
Subject: More PURGE & STO recovery & prevention
Date: 07 Oct 1996 00:00:00 GMT
Message-ID: <53afh6$gji@news.iastate.edu>
references: <32530CD1.597@m.cc.utah.edu>    <cmIn8gS00YUs0auo00@andrew.cmu.edu> <5308la$9dq@news.iastate.edu>    <530r06$pq1@uuneo.neosoft.com> <5320b2$s5g@news.iastate.edu>,<533ruk$vak@kralle.zdv.Uni-Mainz.DE>
organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
reply-to: jhmeyers@miu.edu
newsgroups: comp.sys.hp48


In article <533ruk$vak@kralle.zdv.Uni-Mainz.DE>,
muders@goofy.zdv.Uni-Mainz.DE (Thomas Muders) writes:

> Why don't you simply redefine the PURGE key so that you can't accidentally
> purge something if you want to edit it? It's very simple and effective!!

Okay for PURGE alone (provided you always keep USER mode on, turn it off
to enter PURGE into a program etc.); it becomes more complex to extend the
idea to protecting against left-shift VAR key, STO instead of RCL, etc.

BTW, see Joe Horn's GD#9/POSTINGS/LASTARG.DOC for an excellent summary of
the built-in PURGE & STO recovery features (apparently once documented in
S/SX manuals, but omitted from G/GX manuals).

Here's another obscure way to create menus referring to variables, but which
"protect" any variables containing other than numbers from being stored into:

%%HP: T(3); @ ascii translation mode 3 (see User's Guide)
@ name this program MENUADJ (or else change the name below):
\<< 1 \<< CASE DUP TYPE 6 ==
        THEN DUP VTYPE 1 > { # 3FF9h SYSEVAL # 5445h SYSEVAL } IFT END
      DUP TYPE 5 == THEN DUP SIZE { MENUADJ } IFT END
    END \>> DOLIST \>>
@ 152 bytes (on stack); checksum #8375h

To use MENUADJ, place a list consisting of variable names (or any list
acceptable as the argument of the MENU or TMENU commands) on the stack,
then do MENUADJ TMENU; the result is a menu in which all the variable
names referring to variables containing objects of type > 1 (i.e. not
just numbers) will be converted to "programs" which can not be stored
into, but the labels will still be the same as the variable names, and
pressing any key will do what pressing the variable's key would have done.

You can even do this for a whole directory:  VARS MENUADJ TMENU.

You can adjust the criteria of what object types are to be protected,
e.g.  ... THEN { list of types not protected } OVER VTYPE POS NOT ...

Directories would retain the "tabs" on their labels if they were
left "unprotected" (which is safe, because you can't store anything
into a directory in this way); however, the results would still not be
the same as with the VAR menu, because the displayed menu wouldn't change
(augmenting MENUADJ to cleverly deal with this is left as an exercise..)

Note that this program recursively calls itself, so that it will
even protect menus structured like this: { { label variable } ... },
which otherwise would again expose the variable to being stored into.
Menus defining multiple actions for different "shift-planes" are likewise OK.

You can "test" any menu to see whether variables are "exposed" to being
stored into, by doing right-shift VIEW; if you see any label followed by
a colon and its contents, then that label represents a variable which
you can store into (try this after left-shift MODES MENU, for example).
When you use MENUADJ, you will note that only variables containing numbers
still appear as variables which can be stored into.

For S/SX use, replace DOLIST with LISP (from GD#2) or other equivalent.

CAUTION:  Enter program carefully, verify size and checksum before use,
          back-up memory if possible before use (standard precautions
          for all programs containing SYSEVAL's, erroneous use of
          which can cause Memory Clear and other unpleasantries).

          The two "supported" entry points used above are:  ONE and ::N
          (which make an invisible "program" containing the global name)

Okay, ready for yet another weird method?

\<< VARS DUP DUP \<< RCL \>> DOLIST LIST\-> 1 + ROLL \->STR 2 OVER SIZE 1 -
    SUB "\->" SWAP + \<< \->STR STR\-> TMENU HALT 0 TMENU \>> + STR\-> \>>

The above program "copies" your entire current directory into a
"temporary environment," then it creates a menu containing all the
temporary objects, which are just the same as the original objects,
and then it halts, leaving you in this temporary environment,
which looks quite like the same VAR menu you were just using.

You can go ahead and store into these objects all you like, but they
are just temporary objects, and will not affect your "real" user memory!
(This applies even when you use left-shift menu-key to perform a STO).

You can even edit these variables via 'name' EDIT, but you will be editing
only the temporary copy (don't forget! -- recall to the stack anything
you wish to save, before exiting this environment).

One peculiarity about this menu is that pressing any menu key only *recalls*
the corresponding object; if it is a program you want to execute, you'll
have to also press EVAL to do so.  Another detail is that any pre-existing
global name references in these objects still refer to the (unchanged) objects
in your current VAR directory, no matter what you have done to the temporary
copies; however, any editing/recompilation of programs will change any
of these name references to refer to the temporary variables, and will then
have the same effect (recalling, but not executing), any which are programs.
In case this begins to derange your mind, just proceed to the next step.

When you conclude by pressing left-shift CONT, your "virtual universe" of
temporary variables vanishes, and you "wake up" back home where you were,
with nothing changed, just as did Dorothy in "The Wizard of Oz."

There...  "All's well that ends well"

-----------------------------------------------------------
With best wishes from:  John H Meyers  ( jhmeyers@mum.edu )
