From: jhmeyers@miu.edu (John H Meyers)
Subject: MENUADJ -- protect variables from STO
Date: 16 Feb 1997 00:00:00 GMT
Message-ID: <5e6h2d$dn8$1@news.iastate.edu>
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Reply-To: jhmeyers@miu.edu
Newsgroups: comp.sys.hp48


People who have accidentally lost a program by storing something else
into its variable have asked for some means to protect variables against
being stored into.  One means of doing so is to simply not display the
VAR menu; after all, if your variable names are kept hidden, then
they are safely out of harm's way ("harm" meaning left-shift
followed by a menu key, which means "store into this variable").

But then, if your program names are safely hidden, how do you
execute them when their keys are not displayed?

Another solution is to display a temporary or custom menu
(see "Customizing" -- Chapter 30 of the G/GX User's Guide);
in such a menu, you can display the variable names, retaining
the ability of each key to "execute" (or recall) the variable's
contents, but disallowing the variables to be stored into; it may
not be obvious how to do this correctly, however; therefore the
following aid has been created to help you.

The program below accepts a list (possibly just a list of variable
names) which is intended to be displayed as a menu; this program
modifies that list in such a way that the only variables which
can be stored into are those already containing numbers,
while protecting all the rest.

You can display a menu identical to the VAR menu, except for this
protection, by doing VARS MENUADJ TMENU (for a temporary menu) or
VARS MENUADJ MENU (for a menu stored under the CST key), where
MENUADJ is the program which follows.  This program is similar
to one posted previously, but has been enhanced to retain the
"tabbed label" for any keys referring to directories, and also
to make each such tabbed label revert when pressed to the
VAR menu in the given named directory, since folks seem to be
confused by keys which change directories without displaying
the new variables in the new directory.

If you have already prepared any custom menus containing
references to unprotected variables, you can apply this program
to the existing menu in order to add protection to it.

If you edit any protected menu, the "invisible" protection will
disappear!  Therefore, be sure to re-apply it after any edits.

How it works: Basically, it changes each name into a program
(without program delimiters) which in turn contains the name;
this makes the menu executor treat it as a program,
establishing no connection to the original name,
even though only the original name is visible in the label.

For directory names, each simple name is expanded into a list
consisting of the original name followed by a program which
evaluates the name (changing to the named directory) and
also changes back to the VAR menu.

%%HP: T(3); @ ascii translation mode 3
@ Program name (MENUADJ) must agree with the name appearing
@ inside the program, since this program recursively calls itself.
\<< 1 \<< @ set up for DOLIST (see below)
  CASE
    DUP TYPE 6 == @ global names (of variables)
      THEN
        CASE @ directory or non-number object types
          DUP VTYPE 15 == THEN DUP { 2 MENU } +
            #54AFh SYSEVAL #5445h SYSEVAL 2 \->LIST END
          DUP VTYPE 1 > THEN #3FF9h SYSEVAL #5445h SYSEVAL END
        END
      END
    DUP TYPE 5 == THEN DUP SIZE { MENUADJ } IFT END @ inner list
  END \>> DOLIST \>>

You can use the above with HP48S/SX if you store the previously published
DOLIST substitute program in your HOME directory.

Be careful with SYSEVAL's -- a wrong address or usage could clear memory!

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