[comp.sys.handhelds] Kermit menu for HP48

bson@rice-chex.ai.mit.edu (Jan Brittenson) (09/07/90)

   Here's a program which I've found very useful. It creates a list of
files available from a Kermit server and interactively let's you KGET
individual entries. It does a "D" "G" PKT (mentioned in the HP48
manual) and so needs certain customization to fit into your host's
particular `ls -l' format.

So, after KGETing the directory, edit KFILES:

KFILES
\<< "D" "G" PKT
  10 CHR SPLIT OBJ\-> 3 -
  \-> N
  \<< DROP 1 N
    START DUP
      SIZE 55 SWAP SUB
      IFERR "'"
        SWAP + OBJ\->
      THEN
      END 
      N ROLLD
    NEXT 
    N \->LIST
  \>>
  3 ROLLD
  DROP2 'KDAT' STO
\>>

  The routine initially breaks up the received string on LF (SPLIT
returns a list of substrings). The first two lines will be "ls -l" and
"total ###", the last line will be an empty line (the listing will end
with an LF) - "3 -" following OBJ-> reduces the actual number of lines
by 3. The DROP before the START loop removes the empty line from the
stack. Then each round in the loop one file name substring is
extracted from its line and the list of lines rolled down. The IFERR
construct is to avoid errors related to invalid characters (like
dashes) in file names - such names cannot be used with KGET anyway, so
they're kept as strings instead of names. The constant 55 is the
column in an `ls -l' listing where the actual filename appears.
Finally, the names are bundled up into a list, the initial two lines
removed, and the list stored in KDAT.


   To use KMENU, place your computer's Kermit in server mode, and
press VAR 'KDAT' PURGE CST KMENU. KMENU will ask Kermit for a list
of files and display a name catalog.

KMENU will ignore all keys except the follwing:

	[up arrow]		One name up
	[down arrow]		One name down
	[ENTER]			Put the current name on the stack
	[backspace]		Exit
	[ATTN]			Fire escape (will leave -1 on the stack)

And in the menu:

	KGET			KGET the current name
	KFILES			Update catalog



   It's not the fastest program around. Also note that KMENU stores
the list of names in KDAT; as long as such a variable exists and
contains a list object, KMENU will not automatically do KFILES upon
entry. Worth mentioning is also that KMENU will KGET objects into the
current directory.

Good luck!



[KMENU,KFILES,KDISP,KTOP,SPLIT: #F055h 1430 bytes]

%%HP: T(3)A(R)F(.);
DIR
  CST { KMENU }
  KTOP
    \<< KDAT SIZE
" files:" + 1 DISP
    \>>
  KDISP
    \<< \-> P MX C
      \<<
        IF P MX 6 -
>
        THEN MX 5 -
        ELSE P C -
        END 1 MAX \->
W
        \<< W 2 MX W
- 1 + 6 MIN 1 +
          FOR L DUP
" " KDAT 3 ROLL GET
+ L DISP 1 +
          NEXT DROP
W
        \>>
      \>>
    \>>
  KMENU
    \<< CLLCD KDAT
TYPE 5 \=/
      \<< KFILES
      \>> IFT KDAT
SIZE 1 \-> MX P
      \<< { KGET
KFILES } TMENU KTOP
P MX 4 KDISP 134
CHR \-> W ARROW
        \<<
          DO ARROW
KDAT P GET + P W -
2 + DISP -1 WAIT
" " KDAT P GET + P
W - 2 + DISP 7 FS?C
            \<< KTOP
            \>> IFT \->
K
            \<<
              CASE
K 25.1 SAME P 1 >
AND
THEN 'P' DECR W <
  \<< P MX 4 KDISP
'W' STO
  \>> IFT 0
END K 35.1 SAME P
MX < AND
THEN 'P' INCR W 5 +
>
  \<< P MX 1 KDISP
'W' STO
  \>> IFT 0
END K 51.1 SAME
THEN KDAT P GET 0
END K 11.1 SAME
THEN
  IFERR KDAT P GET
KGET P MX 4 KDISP
'W' STO KTOP
  THEN ERRM 1 DISP
7 SF
  END 0
END K 12.1 SAME
THEN
  IFERR KFILES
  THEN ERRM 1 DISP
7 SF
  END 0
END K 55.1 SAME
THEN 1
END 0
              END
            \>>
          UNTIL
          END 0
MENU
        \>>
      \>>
    \>>
  KFILES
    \<< "D" "G" PKT
10 CHR SPLIT OBJ\-> 3
- \-> N
      \<< DROP 1 N
        START DUP
SIZE 55 SWAP SUB
          IFERR "'"
SWAP + OBJ\->
          THEN
          END N
ROLLD
        NEXT N
\->LIST
      \>> 3 ROLLD
DROP2 'KDAT' STO
    \>>
  SPLIT
    \<< 1 \-> T N
      \<<
        WHILE DUP T
POS DUP
        REPEAT SWAP
1 3 ROLL \-> S B E
          \<< S B E 1
- SUB S E 1 + S
SIZE SUB
          \>> 'N'
INCR DROP
        END DROP N
\->LIST
      \>>
    \>>
END