extended-input.sl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % Extended-Input.SL - 9-bit terminal input (for 7 or 8 bit terminals)
  4. %
  5. % Author: Alan Snyder
  6. % Hewlett-Packard/CRC
  7. % Date: 31 August 1982
  8. % Revised: 17 February 1983
  9. %
  10. % 17-Feb-83 Alan Snyder
  11. % Added PUSH-BACK-INPUT-CHARACTER function. Revise mapping so that
  12. % bit prefix characters are recognized after mapping.
  13. % 22-Dec-82 Jeffrey Soreff
  14. % Added PUSH-BACK-EXTENDED-CHARACTER function.
  15. %
  16. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  17. (CompileTime (load extended-char fast-int fast-vectors))
  18. % Global variables:
  19. (fluid '(nmode-meta-bit-prefix-character
  20. nmode-control-bit-prefix-character
  21. nmode-control-meta-bit-prefix-character))
  22. (setf nmode-meta-bit-prefix-character (x-char C-!\))
  23. (setf nmode-control-bit-prefix-character (x-char C-^))
  24. (setf nmode-control-meta-bit-prefix-character (x-char C-Z))
  25. % Internal static variables:
  26. (fluid '(nmode-terminal-map nmode-lookahead-extended-char nmode-lookahead-char))
  27. (setf nmode-lookahead-extended-char nil)
  28. (setf nmode-lookahead-char nil)
  29. (de nmode-initialize-extended-input ()
  30. (setf nmode-terminal-map (MkVect 255))
  31. % Most input characters map to themselves.
  32. (for (from i 0 255)
  33. (do (vector-store nmode-terminal-map i i)))
  34. % Some ASCII control character map to Extended Control characters.
  35. % Exceptions: BACKSPACE, TAB, RETURN, LINEFEED, ESCAPE
  36. (for (from i 0 31)
  37. (unless (member i '#.(list (char BS) (char tab)
  38. (char CR) (char LF) (char ESC))))
  39. (do (let ((mch (X-Set-Control (+ i 64))))
  40. (vector-store nmode-terminal-map i mch)
  41. (vector-store nmode-terminal-map (+ i 128) (+ mch 128))
  42. )))
  43. )
  44. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  45. (de input-extended-character ()
  46. (if nmode-lookahead-extended-char
  47. (prog1 nmode-lookahead-extended-char
  48. (setf nmode-lookahead-extended-char nil))
  49. (input-direct-extended-character)))
  50. (de push-back-extended-character (ch)
  51. (setf nmode-lookahead-extended-char ch))
  52. (de input-direct-extended-character ()
  53. % Read an extended character from the terminal.
  54. % Recognize and interpret bit-prefix characters.
  55. (let* ((ch (input-terminal-character)))
  56. (cond
  57. ((= ch nmode-meta-bit-prefix-character)
  58. (nmode-append-separated-prompt "M-")
  59. (setf ch (input-terminal-character))
  60. (nmode-complete-prompt (x-char-name (x-unmeta ch)))
  61. (x-set-meta ch)
  62. )
  63. ((= ch nmode-control-bit-prefix-character)
  64. (nmode-append-separated-prompt "C-")
  65. (setf ch (input-terminal-character))
  66. (nmode-complete-prompt (x-char-name (x-uncontrol ch)))
  67. (x-set-control ch)
  68. )
  69. ((= ch nmode-control-meta-bit-prefix-character)
  70. (nmode-append-separated-prompt "C-M-")
  71. (setf ch (input-terminal-character))
  72. (nmode-complete-prompt (x-char-name (x-base ch)))
  73. (x-set-meta (x-set-control ch))
  74. )
  75. (t ch)
  76. )))
  77. (de push-back-input-character (ch)
  78. (setf nmode-lookahead-char ch)
  79. )
  80. (de input-terminal-character ()
  81. % Read an extended character from the terminal. Perform mapping from 8-bit
  82. % to 9-bit characters. Do not interpret bit prefix characters.
  83. (if nmode-lookahead-char
  84. (prog1 nmode-lookahead-char (setf nmode-lookahead-char nil))
  85. (vector-fetch nmode-terminal-map (input-direct-terminal-character))
  86. ))