extfs: hp48: misc fixes.
[midnight-commander.git] / src / vfs / extfs / helpers / hp48+.in
blob7c284946be7e506d4867b9b63ed64a7b7a9cdd3a
1 #!/bin/sh
3 # Written by Christofer Edvardsen <ce@earthling.net>, Feb 1998
5 # This script makes it possible to view and copy files to/from a hp48
6 # (tested with a HP48G and the emulator x48)
8 # To use the hp48 external filesystem:
9 # - read the relevant parts of your HP48 manual
10 # - install kermit
11 # - connect the HP48 to your computer or start x48
12 # - below change the line which reflects the serial device you use
13 # - configure your HP48 (<left shift> - i/o - iopar):
14 # port: wire
15 # baud: 9600
16 # transfer format: binary (fast transfers) or
17 # ascii (editable on the pc)
18 # - start the server on the HP48: <left shift> - i/o - srvr - serve
19 # or the shortcut <right shift> - <right arrow>
20 # - on MC's commandline enter "cd hp48://"
22 # Make sure you have kermit installed and that it's using the right serial
23 # device by changing /dev/ttyXX on the next line
24 AWK=@AWK@
25 KERMIT="kermit -l /dev/ttyS1 -b 9600"
27 hp48_cmd()
29 $KERMIT -C "SET EXIT WARNING OFF,REMOTE $1,QUIT"
32 hp48_cd()
34 (echo SET EXIT WARNING OFF;echo REMOTE HOST HOME
35 for HP48_DIR in `echo "$1" | tr '/' ' '`;do
36 if [ "x$HP48_DIR" != "x." ];then echo REMOTE HOST "$HP48_DIR"; fi
37 done
38 echo QUIT)| $KERMIT -B >/dev/null
41 hp48_retdir()
43 echo "$1"
46 hp48_retsize()
48 printf "%d" "$2" 2>/dev/null
52 # Parses the reply to the DIRECTORY command.
54 # Here's an example reply (taken from [1][2]):
56 # { HOME } 105617
57 # STRAY 185.5 Directory 29225
58 # YEN 30.5 Program 53391
59 # JYTLIGHT 21848.5 String 62692
60 # IOPAR 37.5 List 61074
62 # The meaning of the fields (according to [3][4]):
64 # { Current_directory } Free_space
65 # Object_name Object_size_bytes Object_type Object_CRC
66 # ...
68 # [1] http://newarea48.tripod.com/kermit.html
69 # [2] http://www.hpmuseum.org/forum/thread-4684.html
70 # [3] https://groups.google.com/d/msg/comp.sys.hp48/bYTCu9K3k20/YWQfF--W3EEJ
71 # [4] http://www.columbia.edu/kermit/hp48.html (also has a link to the HP's user manual).
73 hp48_parser()
75 HP48_DIRS=
76 read -r INPUT
77 while [ "x$INPUT" != "xEOF" ]
79 case `echo "$INPUT" | $AWK '{if (int($2)) if ($3 == "Directory") print "dir";else print "file"}'` in
80 dir) HP48_DIRS="$HP48_DIRS `hp48_retdir $INPUT`"
81 printf "drwxr-xr-x 1 %-8d %-8d %8d %s %s\n" 0 0 `hp48_retsize $INPUT` "`date +\"%b %d %Y %k:%M\"`" "$HP48_CDIR/`hp48_retdir $INPUT`";;
82 file) printf "%crw-r--r-- 1 %-8d %-8d %8d %s %s\n" '-' 0 0 `hp48_retsize $INPUT` "`date +\"%b %d %Y %k:%M\"`" "$HP48_CDIR/`hp48_retdir $INPUT`";;
83 esac
84 read -r INPUT
85 done
86 for HP48_DIR in $HP48_DIRS;
87 do
88 HP48_PDIR="$HP48_CDIR"
89 HP48_CDIR="$HP48_CDIR/$HP48_DIR"; hp48_cmd "HOST $HP48_DIR" >/dev/null
90 hp48_list
91 HP48_CDIR="$HP48_PDIR"; hp48_cmd "HOST UPDIR" >/dev/null
92 done
95 hp48_list()
97 { hp48_cmd "DIRECTORY"; echo; echo EOF; } | hp48_parser
100 # override any locale for dates
101 LC_ALL=C
102 export LC_ALL
104 case "$1" in
105 list) HP48_CDIR=
106 hp48_cmd "HOST HOME" >/dev/null
107 hp48_list
108 exit 0;;
109 copyout)
110 cd "`dirname "$4"`"
111 hp48_cd "`dirname "$3"`"
112 $KERMIT -B -g "`basename "$3"`" -a "$4" >/dev/null
113 exit 0;;
114 copyin)
115 cd "`dirname "$4"`"
116 hp48_cd "`dirname "$3"`"
117 $KERMIT -B -s "$4" -a "`basename "$3"`" >/dev/null
118 exit 0;;
119 esac
120 exit 1