From: jrlatala@shell.golden.net (john R. Latala)
Newsgroups: comp.sys.hp48
Subject: recursive upload of HP48 to a kermit server
Date: 19 Oct 1998 09:40:43 GMT
Organization: Golden Triangle Online
Lines: 566
Message-ID: <70f1er$nuf$1@cougar.golden.net>
NNTP-Posting-Host: 199.166.210.4
X-Newsreader: TIN [version 1.2 PL2]
Xref: republic.btigate.com comp.sys.hp48:17499

    Here's a routine I call ->PC that will copy the contents of the HOME
directory and any subdirectories to an attached KERMIT server.  As the copy
proceeds your HP48's directory structure will be mirrored onto the KERMIT
server.  Required directories on the server will be created as they are
needed and the HP48 files copied into them.

    Before the copying is done a CHKSUMS variable is created in your HOME
directory which lists the checksum of each variable in your HP48.

    A CFLAGS variable is also created in your HOME directory which contains
the current system flags.

    Since the HP48 can create variables names that are illegal on many
systems a method has been created to allow user certain variables to be
renamed during upload to the KERMIT server.  A method also exists to indicate
that a variable should NOT be uploaded to the KERMIT server.

    The renaming is done through a variable called 'Kpar' which stands for
KERMIT parameters.  Kpar contains two parallel lists which are the old name
(i.e.  names on the HP48) and the new names (i.e.  names on the KERMIT
server) respectively.

    The format of 'Kpar' is:

        {
          { "oldname1" "oldname2" "oldname3" ... "oldnameN" }
          { "newname1" "newname2" ""         ... "newnameN" }
        }

    Notice that the names are strings!  This was done because if an entry in
the new name list is empty the variable will not be uploaded to the KERMIT
server.

    In the above example the matching entry to "oldname3" is "" which means
that the variable 'oldname3' will NOT be uploaded to the KERMIT server.

    If you're uploading the files to post them on the internet you may want
to convert some of them to ASCII using Wick's ->ASC program first.  This
usually happens with variables with 'strange' contents like Library Data or
big GROBs.  If you didn't do the conversion you'll probably end up with some
lines that are much longer than 80 characters (especially with the GROBs).

    To help with this situation there are two helper programs called ASCIFY
and DASCIFY.  ASCIFY converts variables from their native representation into
ASCII and DASCIFY converts ASCII variables back into their native
representation.

    The operation of these variables is controlled by putting a 'ASCpar'
variable in any directory that has variables that need to be converted before
they are uploaded.

    The format of 'ASCpar' is:

        { flag { name1 name2 ... nameN } }

    The 'flag' is a boolean (0 or 1) to indicate if the current directory has
had it's variables ASCified or not.  A true (1) means the listed variables
have been ASCified.

    ASCIFY will not re-ASCify variables if the flag of the current ASCpar
indicates that the variables have already been ASCified.  Conversely DASCIFY
will not try to restore any variables if the flag indicates that they haven't
been ASCified.

    The problem now is that we need a way to run a particular program, in
this case ASCIFY or DASCIFY, in each subdirectory of your calculator.

    This problem is solved using a program called SWEEP.  This is an HP48
adaption of a program I currently have for my PC that does the same thing; it
runs the same program in each and every subdirectory.

    SWEEP takes a single object from the stack and evaluates in the current
directory then in any subdirectory contained in the current directory.

    In our case we'd ASCify all the variables in all the directories by
executing:

        'ASCIFY' SWEEP

    from the HOME directory.  This would run ASCIFY in each and every
subdirectory on your HP48.

    The last routine supplied is called TSCROLL.  It will scroll the LCD
display up one line then display the text message.  Lines that are longer
than 22 characters will be broken up and scrolled so you can see the whole
message.  Any embedded linefeeds in the message will be honored as the
message is scrolled.

INSTALLATION
------------

    The attached programs are in a subdirectory but that was just done to
make it easier to get them back onto your HP48.  Once you've downloaded the
directory you should move ->PC, ToPC, ASCIFY, DASCIFY, SWEEP and TSCROLL.

OPERATION
---------

    The ->PC routine can be called from anywhere but it will always start
uploading from the HOME directory.  If it was called from a directory other
than HOME it will return you to that original directory when it's done.

    To run ->PC do the following:

        - connect your HP48 to the computer with the KERMIT server

        - configure the server so the generic change directory and
          the remote host commands are enabled

        - start the KERMIT server

        - execute ->PC on the HP48 (probably from the HOME directory)

        - wait until the dust settles

    The sequence of events that happen when you run ->PC are as follows:

        - generate the checksum list

        - store in as { HOME CHKSUMS }

        - store the current flags as { HOME CFLAGS }

        - starting at HOME run ASCIFY in each subdirectory to convert
          selected variables into ASCII

        - starting at HOME upload each subdirectory to the KERMIT server.
          As subdirectories are found on the HP48 matching directories
          are created on the KERMIT server. Then the HP48 files in that
          directory are copied into the created subdirectory on the 
          KERMIT server

        - starting at HOME run DASCIFY in each subdirectory to convert
          selected variables back into their native representation

        - purge { HOME CHKSUMS }

        - purge { HOME CFLAGS }

        - done

KERMIT VERSIONS
---------------

    There are many different KERMIT servers out there.  While developing this
program the only KERMIT server I had access to was the MS-DOS version
supplied by Columbia University.  To get technical the tagline supplied by
the program is:

         IBM-PC MS-DOS Kermit: 3.15 15 Sept 1997
        Copyright (C) Trustees of Columbia University 1982, 1997.

        Type ? or HELP for help
         MS-DOS Kermit: 3.15 15 Sept 1997 patch level 0 
        MS-Kermit>quit



    I initially was using version 3.12 but was having a lot of problems.
When I changed to version 3.15 almost everything started working!  I just
needed to do a bit of tuning.

    So far I've had no problems with the program but I'd like to make it a
little more bulletproof especially where it talks with the server.  For
instance I'm not sure what will happen if the server runs out of space during
the upload.  This could be improved because there is a KERMIT server SPACE
command which will report how much free space there is on the server.  Use of
that command along with the SIZE command would be an improvement.

    The problem is that the SPACE command is optional, a KERMIT server isn't
required to support it!

    The biggest 'problem' is that the method used to tell the KERMIT server
to create a subdirectory is very machine specific.  A KERMIT server provides
various generic commands, one of which is change directory, but there isn't a
generic version of create/make directory.

    ->PC uses the generic change directory command and it uses a remote host
(i.e.  operating system specific) create directory command.  If you need to
make changes to get it to work with your KERMIT server then look at the two
'helper' routines at the front of 'ToPC'.

    Getting this to work properly will be more trouble because proper program
operation now depends on more than just a vanilla HP48.

HP48 SX/GX LIMITATIONS
----------------------

    Even though the whole program is written in RPL as given below it will
NOT work on an HP48SX.  To fix that I think all you've got to do is replace
the GX specific HEAD and TAIL commands after which it should work.

    HEAD might be something like \<< 1 GET \>> while TAIL might be something
like \<< 2 OVER SIZE SUB \>> or something like that.

    If anybody has problems let me know ...

    Here's the progam ...  don't forget that you should move all the routines
into the HOME directory.  They're just packaged as a DIR because that makes
it easier to get them to/from your PC.

%%HP: T(3)A(D)F(.);
DIR
  @
  @ upload the contents of the calculator to a kermit server. 
  @
  \->PC
    \<< 
      @ save the path so we can restore it correctly later
      PATH 
      \-> p
      \<< 
        HOME 
        HEX
        "Getting checksums" TSCROLL 
        @ save the depth for calculating the size of the checksum list
        DEPTH 
        @ path list contains only the current directory
        PATH 1 \->LIST 
        \-> d pl
        \<<
          @ any directory paths left to traverse?
          WHILE pl SIZE 0 \=/ REPEAT 
            @ get another directory
            pl HEAD 
            @ show the user which directory we're going to go into
            DUP \->STR "Entering " SWAP + TSCROLL 
            @ go into it
            EVAL 
            @ get a sorted list of all variables
            VARS SORT 
            @ drop this directory from the path list
            pl TAIL 'pl' STO 
            \-> v
            \<< 
              @ go through all the variables
              1 v SIZE
              FOR i
                @ get the name of the next variable
                v i GET 
                \-> n
                \<<
                  @ is it a directory?
                  IF n RCL TYPE 15 == THEN 
                    @ add it to the end of the path list
                    pl PATH n + 1 \->LIST + 'pl' STO
                  ELSE 
                    @ show the user the current variable
                    n "" + TSCROLL 
                    @ get the checksum 
                    n RCL BYTES DROP 
                    @ tag the checksum with the variables full name
                    PATH n + \->STR \->TAG
                  END
                \>>
              NEXT
            \>>
          END 
          @ calculate # of items in checksum list, make the list and leave
          @ it on the stack
          DEPTH d - \->LIST
        \>> 
        @ back to the HOME directory
        HOME
        @ save the checksum list
        'CHKSUMS' STO
        @ save the current flags
        "Saving flags" TSCROLL 
        RCLF 'CFLAGS' STO
        @ convert required variables to ASCII
        "ASCifying" TSCROLL
        'ASCIFY' SWEEP
        @ upload the variables in this directory to the server
        "Uploading ..." TSCROLL 
        ToPC
        @ convert required variables from ASCII back to original form
        "UnASCifying" TSCROLL 
        'DASCIFY' SWEEP
        @ purge the checksum list
        "Purging checksums" TSCROLL 
        'CHKSUMS' PURGE
        @ purge the current flags variable
        "Purging flags" TSCROLL 
        'CFLAGS' PURGE 
        @ back to the directory where we were called from
        p EVAL
        @ tell them we're done
        "Done ... " TSCROLL
        @ freeze the LCD display so user can see we've finished
        3 FREEZE
      \>>
    \>>
  @
  @ helper function for ->PC which actually does the work of uploading all
  @ the variables in a directory to a kermit server. 
  @
  @ Note: This file recursively calls itself so if you want to change the
  @       name you'll have to do it in ->PC as well as down below in ToPC!
  @
  ToPC
    \<<
      @ make a directory on server
      \<< \-> n \<< "MKDIR " n + "C" PKT \>> \>>
      @ change to a different directory on server
      \<< \-> n \<< "C" n SIZE 32 + CHR + n + "G" PKT DROP \>> \>>
      @ is ther a Kpar variable in this directory?
      IFERR PATH 'Kpar' + RCL THEN 
        @ No, use two empty lists
        DROP { } { }
      ELSE 
        @ extract the new name and old name lists from the Kpar variable
        OBJ\-> DROP
      END 
      VARS 
      \-> mkdir cd on nn v
      \<<
        @ are there any variables in this directory?
        IF v SIZE 0 \=/ THEN 
          @ examine each one
          1 v SIZE
          FOR i 
            @ get the variable name and it's string version
            v i GET DUP "" + 
            \-> n s
            \<<
              @ is this variable in the old names list?
              IF on s POS DUP 0 \=/ THEN
                @ yes, get the matching name out of the new name list
                nn SWAP GET 's' STO
              ELSE
                DROP 
                @ convert any non-alphanumeric characters to 'X' characters
                "" 
                1 s SIZE
                FOR j 
                  @ get a character
                  s j j SUB 
                  \-> c
                  \<<
                    @ is it alphanumeric?
                    IF "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789" 
                      c POS 0 \=/
                    THEN 
                      @ keep the character
                      c
                    ELSE 
                      @ replace it
                      "X"
                    END 
                    +
                  \>>
                NEXT 
                's' STO
              END
              @ if the new name is empty we ignore this variable
              IF s "" \=/ THEN
                @ is it a directory?
                IF n RCL TYPE 15 == THEN 
                  @ tell user we're going into the directory
                  "Into " s + TSCROLL 
                  @ make the directory on the server
                  s mkdir EVAL 
                  @ change into the directory on the server
                  s cd EVAL 
                  @ change into the directory locally
                  n EVAL 
                  @ upload variables in the directory
                  ToPC 
                  @ return to local parent
                  UPDIR
                  @ return server to parent directory
                  ".." cd EVAL
                  @ tell user we're out of that directory
                  "Out of " s + TSCROLL
                ELSE 
                  @ it's just a variable so upload it to server
                  "Sending "
                  IF n "" + s == THEN 
                    @ show user variable name
                    s + TSCROLL 
                    n
                  ELSE 
                    @ show user old name and new name
                    n + " as " + s + TSCROLL 
                    n "'" s + "'" + OBJ\-> 2 \->LIST 1 \->LIST
                  END 
                  SEND
                END
              END
            \>>
          NEXT
        END
      \>>
    \>>
  @
  @ Looks for an ASCpar variable in the current directory. If it finds it 
  @ it uses the first argument to determine if this directory has been 
  @ ASCified or not. If the directory hasn't been ASCified then each 
  @ variable mentioned in the second argument of ASCpar is converted to
  @ ASCII using ->ASC.
  @
  @ When the conversion is complete the first argument of ASCpar is set
  @ to show that this directory has been ASCified.
  @
  @ Format of the ASCpar is:
  @
  @   { flag { name1 name2 ... nameN } }
  @
  @ Where 'flag' is is a true (1) or false (0) indicator to show if the 
  @ directory has been ASCified.
  @
  @ The names are the names of the variables in the CURRENT directory that
  @ should be ASCified.
  @
  ASCIFY
    \<<
      @ is there an ASCpar variable in this directory?
      IFERR PATH 'ASCpar' + RCL THEN 
        DROP "no 'ASCpar' variable" TSCROLL
      ELSE 
        DROP
        @ is the ASCII flag set?
        IF ASCpar 1 GET THEN
          @ directory already has it's variables converted to ASCII
          "Directory is ASCIFIED" TSCROLL
        ELSE 
          @ get the list of names and convert each variable
          1 ASCpar 2 GET SIZE
          FOR i
            @ get the variable name
            ASCpar 2 GET i GET
            \-> n
            \<< 
              @ show user name
              n "" + TSCROLL
              @ does variable still exist?
              IFERR n RCL THEN
                @ Oops!
                " doesn't exist" + TSCROLL
              ELSE
                @ convert variable to ASCII using ->ASC
                \->ASC n STO
              END
            \>>
          NEXT 
          @ set the ASCII flag in ASCpar
          1 ASCpar 2 GET 2 \->LIST 'ASCpar' STO
        END
      END
    \>>
  @
  @ converts ASCII objects back into their original form using ASCpar.
  @
  @ See comment for ASCIFY
  @
  DASCIFY
    \<<
      IFERR PATH 'ASCpar' + RCL THEN 
        DROP "no 'ASCpar' variable" TSCROLL
      ELSE 
        DROP
        IF ASCpar 1 GET NOT THEN
          "Dir is unASCIFIED" TSCROLL
        ELSE 
          1 ASCpar 2 GET SIZE
          FOR i
            ASCpar 2 GET i GET
            \-> n
            \<< 
              n "" + TSCROLL
              IFERR n RCL THEN
                " doesn't exist" + TSCROLL
              ELSE
                ASC\-> n STO
              END
            \>>
          NEXT 
          0 ASCpar 2 GET 2 \->LIST 'ASCpar' STO
        END
      END
    \>>
  @
  @ runs a given object in the current directory then runs the same object
  @ in any subdirectories.
  @
  SWEEP
    \<<
      @ was an object supplied?
      IF DEPTH 0 == THEN
        "Need OBJ" DOERR
      ELSE 
        @ save the object
        \-> e
        \<< 
          @ show user current path
          PATH \->STR TSCROLL 
          @ evaluate the object in this directory
          e EVAL 
          @ now look for any subdirectories
          15 TVARS 
          \-> l
          \<<
            @ any subdirectories?
            IF l SIZE 0 \=/ THEN 
              @ yes, do each one of them
              1 l SIZE
              FOR i
                @ get subdirectory name
                l i GET 
                \-> n
                \<< 
                  @ go into that subdirectory
                  n EVAL 
                  @ sweep it with the same object
                  e SWEEP 
                  @ get out of that subdirectory
                  UPDIR
                \>>
              NEXT
            END
          \>>
        \>>
      END
    \>>
  @
  @ scrolls the LCD then display the specified text on the LCD
  @
  @ "message" ->
  @
  TSCROLL
    \<< 
      @ save the text they want to display
      \-> t
      \<<
        WHILE t "" \=/ REPEAT 
          @ scroll the display
          LCD\-> DUP { # 0h # 18h } { # 82h # 37h } SUB 
          { # 0h # 10h } SWAP REPL 
          { # 0h # 30h } # 83h # 8h BLANK
          REPL 
          \->LCD 
          @ look for a CR in the text?
          t 10 CHR POS 
          \-> p
          \<<
            @ is there a CR somewhere in the first 22 characters?
            IF p 0 \=/ p 22 \<= AND THEN 
              @ take everything up to the CR and display it
              t 1 p 1 - SUB 7 DISP
              @ remove everything up to and including the CR
              t p 1 + OVER SIZE SUB 't' STO
            ELSE 
              @ either there's no CR or it's farther down than the first 22
              @ characters so we'll use the first 22 characters
              t 1 22 SUB 7 DISP 
              @ remove the first 22 characters
              t 23 OVER SIZE SUB 't' STO
            END
          \>>
        END
      \>>
    \>>
END


--
john R. Latala
jrlatala@golden.net