Merge branch '4562_mcedit_macros_paste'
[midnight-commander.git] / src / vfs / extfs / helpers / hp48+.in
blob17c03abca48cf16e64c68de8a53f6281b518ca1f
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=${MC_TEST_EXTFS_LIST_CMD:-"kermit -l /dev/ttyS1 -b 9600"}
27 NOW=`date +"%m-%d-%Y %H:%M"`
29 hp48_cmd()
31 $KERMIT -C "SET EXIT WARNING OFF,REMOTE $1,QUIT"
34 hp48_cd()
36 (echo SET EXIT WARNING OFF;echo REMOTE HOST HOME
37 for HP48_DIR in `echo "$1" | tr '/' ' '`;do
38 if [ "x$HP48_DIR" != "x." ];then echo REMOTE HOST "$HP48_DIR"; fi
39 done
40 echo QUIT)| $KERMIT -B >/dev/null
44 # Parses the reply to the DIRECTORY command.
46 # Here's an example reply (taken from [1][2]):
48 # { HOME } 105617
49 # STRAY 185.5 Directory 29225
50 # YEN 30.5 Program 53391
51 # JYTLIGHT 21848.5 String 62692
52 # IOPAR 37.5 List 61074
54 # The meaning of the fields (according to [3][4]):
56 # { Current_directory } Free_space
57 # Object_name Object_size_bytes Object_type Object_CRC
58 # ...
60 # [1] http://newarea48.tripod.com/kermit.html
61 # [2] http://www.hpmuseum.org/forum/thread-4684.html
62 # [3] https://groups.google.com/d/msg/comp.sys.hp48/bYTCu9K3k20/YWQfF--W3EEJ
63 # [4] http://www.columbia.edu/kermit/hp48.html (also has a link to the HP's user manual).
65 hp48_parser()
67 HP48_DIRS=
69 read -r INPUT
70 while [ "x$INPUT" != "xEOF" ]
72 set -- $INPUT
74 obj_name=$1
75 obj_size=$2
76 obj_type=$3
78 obj_size=`echo $obj_size | $AWK '{ print int($0) }'` # Truncates floats to ints; anything else to "0".
80 if [ "$obj_size" != "0" ]; then # Skips the 1st reply line (purportedly there aren't zero-size files b/c, according to resource [4], the size is "including name").
81 case "$obj_type" in
82 Directory)
83 HP48_DIRS="$HP48_DIRS $obj_name"
84 printf "%crwxr-xr-x 1 %-8d %-8d %8d %s %s\n" 'd' \
85 0 0 $obj_size "$NOW" "$HP48_CDIR/$obj_name"
88 printf "%crw-r--r-- 1 %-8d %-8d %8d %s %s\n" '-' \
89 0 0 $obj_size "$NOW" "$HP48_CDIR/$obj_name"
91 esac
94 read -r INPUT
95 done
97 for HP48_DIR in $HP48_DIRS;
98 do
99 HP48_PDIR="$HP48_CDIR"
100 HP48_CDIR="$HP48_CDIR/$HP48_DIR"; hp48_cmd "HOST $HP48_DIR" >/dev/null
101 hp48_list
102 HP48_CDIR="$HP48_PDIR"; hp48_cmd "HOST UPDIR" >/dev/null
103 done
106 hp48_list()
108 # It's hard to see why this "EOF" thing is needed. The loop above can be changed to "while read -r obj_name ...". @TODO.
109 { hp48_cmd "DIRECTORY"; echo; echo EOF; } | hp48_parser
112 # override any locale for dates
113 LC_ALL=C
114 export LC_ALL
116 case "$1" in
117 list) HP48_CDIR=
118 hp48_cmd "HOST HOME" >/dev/null
119 hp48_list
120 exit 0;;
121 copyout)
122 cd "`dirname "$4"`"
123 hp48_cd "`dirname "$3"`"
124 $KERMIT -B -g "`basename "$3"`" -a "$4" >/dev/null
125 exit 0;;
126 copyin)
127 cd "`dirname "$4"`"
128 hp48_cd "`dirname "$3"`"
129 $KERMIT -B -s "$4" -a "`basename "$3"`" >/dev/null
130 exit 0;;
131 esac
132 exit 1