From: jhmeyers@miu.edu (John H Meyers)
Newsgroups: comp.sys.hp48
Subject: BZ, BZM, BZDIR (about self-extracting variables:BZ1(or BZ))
Date: 23 May 1998 22:27:38 GMT
Organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
Lines: 133
Message-ID: <6k7igq$4on$1@news.iastate.edu>
References: <Pine.GSO.3.95.980522164028.20415A-100000@techst02.technion.ac.il>
Reply-To: jhmeyers@miu.edu
NNTP-Posting-Host: vax1.mum.edu
Xref: republic.btigate.com comp.sys.hp48:10940

In article <Pine.GSO.3.95.980522164028.20415A-100000@techst02.technion.ac.il>,
Dennis Erlich <c1296053@techst02.technion.ac.il> writes:

> Recently tried to convince xMRGLIB v4.2 to 'recognize' and to install
> BZ-compressor, just changed the name(from BZ1 to BZ) and everything
> became OK. When viewing the variables out of xMRG found out that the
> variable itself IS compressed (viewing through the variable browser
> reveals string of symbols) but when recalling it to the stack became an
> ordinary variable (unfortunately only of .VOL format, that xMRG can read)
> Is it an internal feature of BZ1 to create self-extracted files
> (with BZ-s presence, of course-they aren't independent!)
> or it's a part of xMRGLIB's code that allows it?

BZ is sometimes distributed in a "stand-alone" version in which
you may choose which of the two versions BZ1 and BZ4 you want,
the only difference being compression speed vs. how much memory
is used when compressing; you are then supposed to rename your
choice to BZ, regardless of which one you selected.

BZ normally operates on a stack object, either compressing it or
expanding it, as appropriate; a compressed object is recognized
by its being a string which begins with the two characters "BZ"
(followed by generally unreadable characters thereafter); this
system has the minor flaw that it can not compress any string
object that already begins with "BZ" (in fact, it tends to
crash upon any such attempt), but not many useful strings
happen to begin with these two characters.  About 50% of all
compressed object strings also happen to have an odd number
of half-bytes in the string, which eventually causes crashes
only when trying to do any further operations upon it,
such as editing, ascii-mode Kermit transfer, or encryption.

BZ itself does not create self-extracting objects, but other programs
may use BZ to create self-extracting objects by compressing the
original object and then embedding the resulting compressed string
within a program, in which the compressed string is followed by
a BZ command; when executed, this program therefore concludes
by leaving the expanded original object on the stack.

Simply recalling the variable in which this is stored ('name' RCL)
does not cause self-expansion; rather, you must evaluate the
variable name (do not even quote the name) in order to cause
the stored program to be executed.

Other programs may also use BZ to create self-executing compressed
programs, by following the original compressed program [string]
with the pair of commands BZ and EVAL; when such a variable name
is evaluated unquoted, it thus both expands and executes the
original program.

If the "BZ command" is expressed in the form "BZ" OBJ-> rather than
as either a global name BZ or a library function call, then the
ability to subsequently expand objects is slightly more flexible,
in that it allows one to vary between using a library version of BZ
or a version stored in a variable; otherwise you must use exactly
the same set-up during expansion as was present during compression.

If you want to see in what form a compressed variable has been stored,
try recalling that variable's contents to the stack (right-shift
followed by VAR menu key, or 'name' RCL); if you see only the
string "BZ..." on one line, then only the compressed string is stored;
if you see "BZ..." followed by more commands on a lower line, then a
self-extracting or self-executing program is stored in that variable.
(Be sure that flag -52 is cleared, as it normally is by default,
so that objects will be displayed on multiple lines as necessary;
otherwise you will not be able to see this distinction).

Reading the xMGRLIB documentation, it appears that this library
uses BZ to compress only its own special files (*.VOL), in which
you store equations, along with their variable descriptions and grobs;
it seems likely that xMGR performs compression and expansion upon
these files as and when needed or requested, rather than making
them "self-extracting" as described above.  However, Jack Levy's
BZM "menu line" program offers one means by which you can create
your own self-extracting and self-executing objects.

A User-RPL version of BZM follows below.

If you would be interested in compressing entire directories
into single objects (to save space in user variable memory),
see the following post:

"BZDIR improved even further (v 3.2)" 1997/11/11
<http://www.dejanews.com/getdoc.xp?AN=289467673>

-----------------------------------------------------------
With best wishes from:   John H Meyers   <jhmeyers@mum.edu>
-----------------------------------------------------------

%%HP: T(3); @ User-RPL programs for a BZM menu line
@ (for compressing and making self-extracting/executable objects)

@ The BZ compress/expand program (in either a variable or a library)
@ must be available when these programs are executed,
@ and whenever a self-extracting object is evaluated:

@ Carefully verify SYSEVAL addresses! (all in HEX); make a backup!

{ @ A list of programs, each followed by its name.
  @ To store the programs, perform OBJ-> DROP STO STO STO ...
  @ (You may wish to store these in HOME for general use)

@ BZM displays the menu for executing all the remaining functions:
\<< { Bz Sfx Exe { } Ubz Ok } TMENU \>> BZM

@ The Bz function performs BZ upon the level 1 object:
\<< "BZ" OBJ\-> \>> Bz

@ The Sfx function makes a self-extracting object from level 1
@ (you must then store it in whatever variable you want to keep it):
\<< Bzp L\->P \>> Sfx

@ The Exe function makes a self-executing object from level 1
@ (you must then store it in whatever variable you want to keep it):
\<< Bzp { EVAL } + L\->P \>> Exe

@ The Ubz function extracts the original object from anything made by
@ any of the above functions: Bz, Sfx, or Exe:
\<< DUP TYPE 8 == { #54AFh SYSEVAL #5459h SYSEVAL 1 GET } IFT Bz \>> Ubz

@ The Ok function returns to the previous menu:
\<< 0 TMENU \>> Ok

@ An internal function used by Sfx and Exe:
\<< Bz { "BZ" OBJ\-> } + \>> Bzp
@ If invoked accidentally, press EVAL to undo it.

@ Another internal function used by Sfx and Exe
@ (or you can use it to turn any list into a program):
\<< DUP TYPE 5 == { #54AFh SYSEVAL #5445h SYSEVAL } IFT \>> L\->P

} @ End of list of programs and names
