extended-char.sl 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  2. %
  3. % Extender-Char.SL - 9-bit terminal input characters
  4. %
  5. % Author: Alan Snyder
  6. % Hewlett-Packard/CRC
  7. % Date: 31 August 1982
  8. %
  9. % Changes:
  10. % 10/15/82: added M-X macro, for convenience
  11. %
  12. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  13. % Note: this file defines MACROS, so you may need to load it at compile-time.
  14. % Note: this file loads FAST-INT.
  15. (load fast-int common strings)
  16. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  17. % Extended Character Manipulation Functions (or Macros)
  18. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  19. (ds X-Base (chr)
  20. % Return the base character corresponding to CHR. In other words, clear the
  21. % Meta and Control bits.
  22. (& chr 2#001111111))
  23. (ds X-Zero-Base (chr)
  24. % Return the given character with its base code set to 0.
  25. (& chr 2#110000000))
  26. (ds X-UnMeta (chr)
  27. % Turn off the Meta bit in the given character.
  28. (& chr 2#101111111))
  29. (ds X-UnControl (chr)
  30. % Turn off the Control bit in the given character.
  31. (& chr 2#011111111))
  32. (ds X-Meta? (chr)
  33. % Does CHR have the Meta bit set?
  34. (not (= (& chr 2#010000000) 0)))
  35. (ds X-Control? (chr)
  36. % Does CHR have the Control bit set?
  37. (not (= (& chr 2#100000000) 0)))
  38. (ds X-Set-Meta (chr)
  39. % Set the Meta bit in CHR.
  40. (| chr 2#010000000))
  41. (ds X-Set-Control (chr)
  42. % Set the Control bit in CHR.
  43. (| chr 2#100000000))
  44. % This version of "UpperCaseP" handles extended characters.
  45. (de X-UpperCaseP (chr)
  46. (UpperCaseP (X-Base chr)))
  47. % This version of "LowerCaseP" handles extended characters.
  48. (de X-LowerCaseP (chr)
  49. (LowerCaseP (X-Base chr)))
  50. (de X-Char-DownCase (chr)
  51. (let ((bits (X-Zero-Base chr))
  52. (base (X-Base chr))
  53. )
  54. (| bits (Char-DownCase base))))
  55. (de X-Char-UpCase (chr)
  56. (let ((bits (X-Zero-Base chr))
  57. (base (X-Base chr))
  58. )
  59. (| bits (Char-UpCase base))))
  60. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  61. % Extended Character Creation Macro
  62. %
  63. % Examples of legal uses:
  64. % (x-char a) => A
  65. % (x-char lower a) => a
  66. % (x-char control a) => C-A
  67. % (x-char c-a) => C-A
  68. % (x-char ^A) => (ascii control A - code 1)
  69. % (x-char meta control TAB) => C-M-Tab
  70. % (x-char control ^A) => C-^A (^A is ASCII code 1)
  71. % (x-char C-M-^A) => C-M-^A (^A is ASCII code 1)
  72. %
  73. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  74. (dm X-Char (form)
  75. (Create-Extended-Character (cdr form)))
  76. (de Create-Extended-Character (L)
  77. (let ((plist (gensym)))
  78. (for (in x L)
  79. (do (cond ((IdP x) (X-Char-process-id x plist))
  80. ((FixP x) (X-Char-process-fix x plist))
  81. (t (put plist 'error T))
  82. )))
  83. (let ((base (get plist 'base)))
  84. (if (or (get plist 'error) (null base))
  85. (StdError (BldMsg "Invalid X-CHAR: %p" (cons 'X-CHAR L))))
  86. (if (and (get plist 'Lower) (>= base #\A) (<= base #\Z))
  87. (setf base (+ base 2#100000)))
  88. (if (get plist 'Control)
  89. (setf base (X-Set-Control base)))
  90. (if (get plist 'Meta)
  91. (setf base (X-Set-Meta base)))
  92. base
  93. )))
  94. (de X-char-process-id (id plist)
  95. (prog (temp id2)
  96. (cond ((eq id 'Meta) (put plist 'Meta T))
  97. ((eq id 'Control) (put plist 'Control T))
  98. ((eq id 'Lower) (put plist 'Lower T))
  99. ((eq id 'Return) (put plist 'base 13))
  100. ((< (setf temp (ID2Int id)) 128) (put plist 'base temp))
  101. ((setf temp (get id 'CharConst)) (put plist 'base temp))
  102. ((and (>= (size (setf temp (id2string id))) 2)
  103. (= (indx temp 1) #\-))
  104. (setf id2 (intern (substring temp 2 (+ 1 (size temp)))))
  105. (selectq (indx temp 0)
  106. (#\M (put plist 'Meta T) (X-char-process-id id2 plist))
  107. (#\C (put plist 'Control T) (X-char-process-id id2 plist))
  108. (t (put plist 'error T))
  109. ))
  110. ((and (= (size temp) 1) (= (indx temp 0) #\^))
  111. (put plist 'Ascii-Control T)
  112. (put plist 'base (& (indx temp 1) 2#11111))
  113. )
  114. (t (put plist 'error T))
  115. )))
  116. (de X-Char-process-fix (x plist)
  117. (cond ((and (>= x 0) (<= x 9)) (put plist 'base (+ x #\0)))
  118. (t (put plist 'error T))
  119. ))
  120. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  121. % X-Chars
  122. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  123. % Generate a list of character codes from a list of "character descriptors",
  124. % which are argument lists to the X-CHAR macro.
  125. (dm x-chars (chlist)
  126. (cons 'list
  127. (for (in x (cdr chlist))
  128. (collect (cons 'x-char (if (pairp x) x (list x)))))))
  129. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  130. % Printable names for extended characters:
  131. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  132. (fluid '(character-name-table))
  133. % An association list of (character code . name), used by x-char-name.
  134. (setf character-name-table '(
  135. (8#0 . "Null")
  136. (8#7 . "Bell")
  137. (8#10 . "Backspace")
  138. (8#11 . "Tab")
  139. (8#12 . "Newline")
  140. (8#15 . "Return")
  141. (8#33 . "Escape")
  142. (8#40 . "Space")
  143. (8#177 . "Rubout")
  144. ))
  145. (de x-char-name (ch)
  146. % Return a string giving the name for an extended character.
  147. (cond
  148. ((not (FixP ch)) (BldMsg "<%o>" ch))
  149. ((atsoc ch character-name-table) (cdr (atsoc ch character-name-table)))
  150. ((X-Control? ch) (string-concat "C-" (x-char-name (X-UnControl ch))))
  151. ((X-Meta? ch) (string-concat "M-" (x-char-name (X-UnMeta ch))))
  152. ((GraphicP ch) (string ch))
  153. ((and (>= ch 0) (< ch (char space)))
  154. (string-concat "^" (x-char-name (LXor ch 8#100))))
  155. (t (BldMsg "<%o>" ch))
  156. ))
  157. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  158. % M-X Macro
  159. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  160. (defmacro m-x (command-string)
  161. `(list (x-char M-X) ,command-string))