hp48.in 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #!/bin/sh
  2. #
  3. # Written by Christofer Edvardsen <ce@earthling.net>, Feb 1998
  4. #
  5. # This script makes it possible to view and copy files to/from a hp48
  6. # (tested with a HP48G and the emulator x48)
  7. #
  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:"
  21. #
  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"
  26. hp48_cmd()
  27. {
  28. $KERMIT -C "SET EXIT WARNING OFF,REMOTE $1,QUIT"
  29. }
  30. hp48_cd()
  31. {
  32. (echo SET EXIT WARNING OFF;echo REMOTE HOST HOME
  33. for HP48_DIR in `echo "$1" | tr '/' ' '`;do
  34. if [ "x$HP48_DIR" != "x." ];then echo REMOTE HOST "$HP48_DIR"; fi
  35. done
  36. echo QUIT)| $KERMIT -B >/dev/null
  37. }
  38. hp48_retdir()
  39. {
  40. echo "$1"
  41. }
  42. hp48_retsize()
  43. {
  44. printf "%d" "$2" 2>/dev/null
  45. }
  46. hp48_parser()
  47. {
  48. HP48_DIRS=
  49. read -r INPUT
  50. while [ "x$INPUT" != "xEOF" ]
  51. do
  52. case `echo "$INPUT" | $AWK '{if (int($2)) if ($3 == "Directory") print "dir";else print "file"}'` in
  53. dir) HP48_DIRS="$HP48_DIRS `hp48_retdir \"$INPUT\"`"
  54. 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\"`";;
  55. file) printf "-rw-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\"`";;
  56. esac
  57. read -r INPUT
  58. done
  59. for HP48_DIR in $HP48_DIRS;
  60. do
  61. HP48_PDIR="$HP48_CDIR"
  62. HP48_CDIR="$HP48_CDIR/$HP48_DIR"; hp48_cmd "HOST $HP48_DIR" >/dev/null
  63. hp48_list
  64. HP48_CDIR="$HP48_PDIR"; hp48_cmd "HOST UPDIR" >/dev/null
  65. done
  66. }
  67. hp48_list()
  68. {
  69. { hp48_cmd "DIRECTORY"; echo; echo EOF; } | hp48_parser
  70. }
  71. # override any locale for dates
  72. LC_ALL=C
  73. export LC_ALL
  74. case "$1" in
  75. list) HP48_CDIR=
  76. hp48_cmd "HOST HOME" >/dev/null
  77. hp48_list
  78. exit 0;;
  79. copyout)
  80. cd "`dirname "$4"`"
  81. hp48_cd "`dirname "$3"`"
  82. $KERMIT -B -g "`basename "$3"`" -a "$4" >/dev/null
  83. exit 0;;
  84. copyin)
  85. cd "`dirname "$4"`"
  86. hp48_cd "`dirname "$3"`"
  87. $KERMIT -B -s "$4" -a "`basename "$3"`" >/dev/null
  88. exit 0;;
  89. esac
  90. exit 1