From: jhmeyers@miu.edu (John H Meyers)
Subject: Tiny string viewer (String Reformat)
Date: 16 Oct 1996 00:00:00 GMT
Message-ID: <543no9$f2n@news.iastate.edu>
references: <540tps$90k@senator-bedfellow.MIT.EDU>
organization: MIU Computer Services,  Fairfield, IA 52557.  Not Approved.
reply-to: jhmeyers@miu.edu
newsgroups: comp.sys.hp48


In article <540tps$90k@senator-bedfellow.MIT.EDU>,
chris@omega.mit.edu (Dr. Christopher Fortin) writes:

> I recently was using ALG48, and ended up with a huge string representing
> a numeric answer. Is there any way in the editor, or stringwriter, to
> automatically reformat the string to fit in the number of columns
> available on the screen? That would let me scroll down to see the number,
> which would be easier than just seeing one line scrolling across.

  Here's a 169-byte program which will display any string in screenfuls,
  "wrapping" lines to fit.  Press any non-shift key to continue to the
  next screenful (if there is no more, then the program will exit and
  return to the normal stack display).

  This program is constructed to allow a string of *any*length*
  (even filling all of memory) to be displayed, provided some
  minimum memory (about 150 bytes) is still free.

  If you display an object other than a string, then the program will
  first convert it to a string (this requires memory for the result string).

  If we were sure that we did not want to display a list, then we could
  just "append a string" where shown in the listing, and the results
  would be identical; however, using the SysRPL EDITDECOMP$ function
  also accommodates lists.  The \->STR function can be used, but it
  does not "break" long lines as conveniently as the other options.

An HP48 (S/G) version of "more" (display in screenfuls, with wrapped text):

%%HP: T(3); @ ascii translation: \=/ is "not equal", \010 is a "newline"
\<< DUP                 @ preserve original object
  IF DUP TYPE 2 \=/     @ if not already a string
  THEN                  @ either do "" + or \->STR or else:
    #15A0Eh SYSEVAL     @ decompile as for command line editing
  END 1                 @ string, current display position
  DO CLLCD 1 7          @ clear screen, display 7 lines at a time
@ Be sure to replace "\010" with a quoted *newline* (right-shift decimal-pt):
  FOR i DUP2 DUP 22 + SUB 1 OVER "\010" POS @ where is next newline, if any
  DUP NOT 22 * + SUB DUP i DISP SIZE + @ display line, increment text pointer
  NEXT 0 WAIT DROP        @ display, wait for key, discard keycode
  UNTIL DUP2 SWAP SIZE >  @ until entire string has been displayed
  END DROP2               @ drop string and text pointer
\>> @ 169 bytes (on stack), #40C3h checksum

Caution: Be careful to get the SYSEVAL address right!
         (a wrong address could cause a Memory Clear).
         If you want to "play it safe" then substitute: "" +
         (then program will work for everything except a list)
         or use just \->STR (then it will display anything,
         but not always formatted as nicely).

Those of you who want to adapt this to display 33 characters per line
(why?) can figure out that changing 22 to 33 will do it!  You could
build a whole new string with newlines inserted, if that would suit you;
you would want to decompile to a width of 33 if not a string to begin with.

In the absence of trapping CANCEL and cleaning up the stack, this program
will leave 2 to 3 extra objects on the stack if canceled.

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

