/[linedit]/src/terminfo.lisp
ViewVC logotype

Contents of /src/terminfo.lisp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.10 - (show annotations)
Sun Apr 8 12:21:10 2012 UTC (2 years ago) by jsquires
Branch: MAIN
CVS Tags: HEAD
Changes since 1.9: +2 -2 lines
Remove non-UTF-8 character from comment
1 ;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Package: TERMINFO -*-
2
3 ;;; Copyright 2001 Paul Foley (mycroft@actrix.gen.nz)
4 ;;;
5 ;;; Permission is hereby granted, free of charge, to any person obtaining
6 ;;; a copy of this Software to deal in the Software without restriction,
7 ;;; including without limitation the rights to use, copy, modify, merge,
8 ;;; publish, distribute, sublicense, and/or sell copies of the Software,
9 ;;; and to permit persons to whom the Software is furnished to do so,
10 ;;; provided that the above copyright notice and this permission notice
11 ;;; are included in all copies or substantial portions of the Software.
12 ;;;
13 ;;; THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
14 ;;; OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
15 ;;; WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 ;;; ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
17 ;;; LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 ;;; CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
19 ;;; OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
20 ;;; BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
21 ;;; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 ;;; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
23 ;;; USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
24 ;;; DAMAGE.
25 #+CMU (ext:file-comment "$Header: /tiger/var/lib/cvsroots/linedit/src/terminfo.lisp,v 1.10 2012/04/08 12:21:10 jsquires Exp $")
26
27 (in-package "COMMON-LISP-USER")
28
29 ;; DEFPACKAGE would warn here, since we export things outside the definition
30 (eval-when (:compile-toplevel :load-toplevel)
31 (unless (find-package "TERMINFO")
32 (make-package "TERMINFO" :nicknames '("TI") :use '("CL"))))
33
34 (in-package "TERMINFO")
35
36 (export '(*terminfo-directories* *terminfo* capability tparm tputs
37 set-terminal))
38
39 (defvar *terminfo-directories* '("/etc/terminfo/"
40 "/usr/share/terminfo/"
41 "/usr/share/misc/terminfo/"))
42
43 (defvar *terminfo* nil)
44
45 (eval-when (:compile-toplevel :load-toplevel :execute)
46 (defvar *capabilities* (make-hash-table :size 494)))
47
48 (flet ((required-argument ()
49 (error "A required argument was not supplied.")))
50 (defstruct (terminfo
51 (:print-function
52 (lambda (object stream depth)
53 (declare (ignore depth))
54 (print-unreadable-object (object stream :type t :identity t)
55 (format stream "~A" (first (terminfo-names object)))))))
56 (names (required-argument) :type list :read-only t)
57 (booleans (required-argument) :type (simple-array (member t nil) (*)))
58 (numbers (required-argument) :type (simple-array (signed-byte 16) (*)))
59 (strings (required-argument) :type (simple-array t (*)))))
60
61 #+CMU
62 (declaim (ext:start-block capability %capability))
63
64 (defun %capability (name terminfo)
65 (let ((whatsit (gethash name *capabilities*)))
66 (when (null whatsit)
67 (error "Terminfo capability ~S doesn't exist." name))
68 (if (or (null terminfo) (>= (cdr whatsit)
69 (length (funcall (car whatsit) terminfo))))
70 nil #| default |#
71 (let ((value (aref (funcall (car whatsit) terminfo) (cdr whatsit))))
72 (if (and (numberp value) (minusp value))
73 nil
74 value)))))
75
76 (declaim (inline capability))
77 (defun capability (name &optional (terminfo *terminfo*))
78 (%capability name terminfo))
79
80 #+CMU
81 (declaim (ext:end-block))
82
83 (define-compiler-macro capability (&whole form
84 name &optional (terminfo '*terminfo*))
85 (if (not (keywordp name))
86 form
87 (let ((value (gensym))
88 (tmp (gensym)))
89 (unless (gethash name *capabilities*)
90 (warn "Terminfo capability ~S doesn't exist." name))
91 `(let ((,value (load-time-value (cons nil nil)))
92 (,tmp ,terminfo))
93 (if (eq (car ,value) ,tmp)
94 (cdr ,value)
95 (setf (car ,value) ,tmp
96 (cdr ,value) (%capability ,name ,tmp)))))))
97
98
99 (defmacro defcap (name type index)
100 (let ((thing (ecase type
101 (boolean 'terminfo-booleans)
102 (integer 'terminfo-numbers)
103 (string 'terminfo-strings)))
104 (symbol (intern (string name) "KEYWORD")))
105 `(progn
106 (eval-when (:compile-toplevel)
107 ;; Mark capability as valid for the compiler-macro; needed when
108 ;; compiling TPUTS. If there's already a value present, leave
109 ;; it alone, else just put any non-NIL value there; it'll get
110 ;; fixed up when the file is loaded.
111 (setf (gethash ,symbol *capabilities*)
112 (gethash ,symbol *capabilities* t)))
113 (setf (gethash ,symbol *capabilities*) (cons #',thing ,index))
114 (define-symbol-macro ,name (capability ,symbol *terminfo*))
115 (export ',name "TERMINFO"))))
116
117 (defcap auto-left-margin boolean 0)
118 (defcap auto-right-margin boolean 1)
119 (defcap no-esc-ctlc boolean 2)
120 (defcap ceol-standout-glitch boolean 3)
121 (defcap eat-newline-glitch boolean 4)
122 (defcap erase-overstrike boolean 5)
123 (defcap generic-type boolean 6)
124 (defcap hard-copy boolean 7)
125 (defcap has-meta-key boolean 8)
126 (defcap has-status-line boolean 9)
127 (defcap insert-null-glitch boolean 10)
128 (defcap memory-above boolean 11)
129 (defcap memory-below boolean 12)
130 (defcap move-insert-mode boolean 13)
131 (defcap move-standout-mode boolean 14)
132 (defcap over-strike boolean 15)
133 (defcap status-line-esc-ok boolean 16)
134 (defcap dest-tabs-magic-smso boolean 17)
135 (defcap tilde-glitch boolean 18)
136 (defcap transparent-underline boolean 19)
137 (defcap xon-xoff boolean 20)
138 (defcap needs-xon-xoff boolean 21)
139 (defcap prtr-silent boolean 22)
140 (defcap hard-cursor boolean 23)
141 (defcap non-rev-rmcup boolean 24)
142 (defcap no-pad-char boolean 25)
143 (defcap non-dest-scroll-region boolean 26)
144 (defcap can-change boolean 27)
145 (defcap back-color-erase boolean 28)
146 (defcap hue-lightness-saturation boolean 29)
147 (defcap col-addr-glitch boolean 30)
148 (defcap cr-cancels-micro-mode boolean 31)
149 (defcap has-print-wheel boolean 32)
150 (defcap row-addr-glitch boolean 33)
151 (defcap semi-auto-right-margin boolean 34)
152 (defcap cpi-changes-res boolean 35)
153 (defcap lpi-changes-res boolean 36)
154
155 (defcap columns integer 0)
156 (defcap init-tabs integer 1)
157 (defcap lines integer 2)
158 (defcap lines-of-memory integer 3)
159 (defcap magic-cookie-glitch integer 4)
160 (defcap padding-baud-rate integer 5)
161 (defcap virtual-terminal integer 6)
162 (defcap width-status-line integer 7)
163 (defcap num-labels integer 8)
164 (defcap label-height integer 9)
165 (defcap label-width integer 10)
166 (defcap max-attributes integer 11)
167 (defcap maximum-windows integer 12)
168 (defcap max-colors integer 13)
169 (defcap max-pairs integer 14)
170 (defcap no-color-video integer 15)
171 (defcap buffer-capacity integer 16)
172 (defcap dot-vert-spacing integer 17)
173 (defcap dot-horz-spacing integer 18)
174 (defcap max-micro-address integer 19)
175 (defcap max-micro-jump integer 20)
176 (defcap micro-col-size integer 21)
177 (defcap micro-line-size integer 22)
178 (defcap number-of-pins integer 23)
179 (defcap output-res-char integer 24)
180 (defcap output-res-line integer 25)
181 (defcap output-res-horz-inch integer 26)
182 (defcap output-res-vert-inch integer 27)
183 (defcap print-rate integer 28)
184 (defcap wide-char-size integer 29)
185 (defcap buttons integer 30)
186 (defcap bit-image-entwining integer 31)
187 (defcap bit-image-type integer 32)
188
189 (defcap back-tab string 0)
190 (defcap bell string 1)
191 (defcap carriage-return string 2)
192 (defcap change-scroll-region string 3)
193 (defcap clear-all-tabs string 4)
194 (defcap clear-screen string 5)
195 (defcap clr-eol string 6)
196 (defcap clr-eos string 7)
197 (defcap column-address string 8)
198 (defcap command-character string 9)
199 (defcap cursor-address string 10)
200 (defcap cursor-down string 11)
201 (defcap cursor-home string 12)
202 (defcap cursor-invisible string 13)
203 (defcap cursor-left string 14)
204 (defcap cursor-mem-address string 15)
205 (defcap cursor-normal string 16)
206 (defcap cursor-right string 17)
207 (defcap cursor-to-ll string 18)
208 (defcap cursor-up string 19)
209 (defcap cursor-visible string 20)
210 (defcap delete-character string 21)
211 (defcap delete-line string 22)
212 (defcap dis-status-line string 23)
213 (defcap down-half-line string 24)
214 (defcap enter-alt-charset-mode string 25)
215 (defcap enter-blink-mode string 26)
216 (defcap enter-bold-mode string 27)
217 (defcap enter-ca-mode string 28)
218 (defcap enter-delete-mode string 29)
219 (defcap enter-dim-mode string 30)
220 (defcap enter-insert-mode string 31)
221 (defcap enter-secure-mode string 32)
222 (defcap enter-protected-mode string 33)
223 (defcap enter-reverse-mode string 34)
224 (defcap enter-standout-mode string 35)
225 (defcap enter-underline-mode string 36)
226 (defcap erase-chars string 37)
227 (defcap exit-alt-charset-mode string 38)
228 (defcap exit-attribute-mode string 39)
229 (defcap exit-ca-mode string 40)
230 (defcap exit-delete-mode string 41)
231 (defcap exit-insert-mode string 42)
232 (defcap exit-standout-mode string 43)
233 (defcap exit-underline-mode string 44)
234 (defcap flash-screen string 45)
235 (defcap form-feed string 46)
236 (defcap from-status-line string 47)
237 (defcap init-1string string 48)
238 (defcap init-2string string 49)
239 (defcap init-3string string 50)
240 (defcap init-file string 51)
241 (defcap insert-character string 52)
242 (defcap insert-line string 53)
243 (defcap insert-padding string 54)
244 (defcap key-backspace string 55)
245 (defcap key-catab string 56)
246 (defcap key-clear string 57)
247 (defcap key-ctab string 58)
248 (defcap key-dc string 59)
249 (defcap key-dl string 60)
250 (defcap key-down string 61)
251 (defcap key-eic string 62)
252 (defcap key-eol string 63)
253 (defcap key-eos string 64)
254 (defcap key-f0 string 65)
255 (defcap key-f1 string 66)
256 (defcap key-f10 string 67)
257 (defcap key-f2 string 68)
258 (defcap key-f3 string 69)
259 (defcap key-f4 string 70)
260 (defcap key-f5 string 71)
261 (defcap key-f6 string 72)
262 (defcap key-f7 string 73)
263 (defcap key-f8 string 74)
264 (defcap key-f9 string 75)
265 (defcap key-home string 76)
266 (defcap key-ic string 77)
267 (defcap key-il string 78)
268 (defcap key-left string 79)
269 (defcap key-ll string 80)
270 (defcap key-npage string 81)
271 (defcap key-ppage string 82)
272 (defcap key-right string 83)
273 (defcap key-sf string 84)
274 (defcap key-sr string 85)
275 (defcap key-stab string 86)
276 (defcap key-up string 87)
277 (defcap keypad-local string 88)
278 (defcap keypad-xmit string 89)
279 (defcap lab-f0 string 90)
280 (defcap lab-f1 string 91)
281 (defcap lab-f10 string 92)
282 (defcap lab-f2 string 93)
283 (defcap lab-f3 string 94)
284 (defcap lab-f4 string 95)
285 (defcap lab-f5 string 96)
286 (defcap lab-f6 string 97)
287 (defcap lab-f7 string 98)
288 (defcap lab-f8 string 99)
289 (defcap lab-f9 string 100)
290 (defcap meta-off string 101)
291 (defcap meta-on string 102)
292 (defcap newline string 103)
293 (defcap pad-char string 104)
294 (defcap parm-dch string 105)
295 (defcap parm-delete-line string 106)
296 (defcap parm-down-cursor string 107)
297 (defcap parm-ich string 108)
298 (defcap parm-index string 109)
299 (defcap parm-insert-line string 110)
300 (defcap parm-left-cursor string 111)
301 (defcap parm-right-cursor string 112)
302 (defcap parm-rindex string 113)
303 (defcap parm-up-cursor string 114)
304 (defcap pkey-key string 115)
305 (defcap pkey-local string 116)
306 (defcap pkey-xmit string 117)
307 (defcap print-screen string 118)
308 (defcap prtr-off string 119)
309 (defcap prtr-on string 120)
310 (defcap repeat-char string 121)
311 (defcap reset-1string string 122)
312 (defcap reset-2string string 123)
313 (defcap reset-3string string 124)
314 (defcap reset-file string 125)
315 (defcap restore-cursor string 126)
316 (defcap row-address string 127)
317 (defcap save-cursor string 128)
318 (defcap scroll-forward string 129)
319 (defcap scroll-reverse string 130)
320 (defcap set-attributes string 131)
321 (defcap set-tab string 132)
322 (defcap set-window string 133)
323 (defcap tab string 134)
324 (defcap to-status-line string 135)
325 (defcap underline-char string 136)
326 (defcap up-half-line string 137)
327 (defcap init-prog string 138)
328 (defcap key-a1 string 139)
329 (defcap key-a3 string 140)
330 (defcap key-b2 string 141)
331 (defcap key-c1 string 142)
332 (defcap key-c3 string 143)
333 (defcap prtr-non string 144)
334 (defcap char-padding string 145)
335 (defcap acs-chars string 146)
336 (defcap plab-norm string 147)
337 (defcap key-btab string 148)
338 (defcap enter-xon-mode string 149)
339 (defcap exit-xon-mode string 150)
340 (defcap enter-am-mode string 151)
341 (defcap exit-am-mode string 152)
342 (defcap xon-character string 153)
343 (defcap xoff-character string 154)
344 (defcap ena-acs string 155)
345 (defcap label-on string 156)
346 (defcap label-off string 157)
347 (defcap key-beg string 158)
348 (defcap key-cancel string 159)
349 (defcap key-close string 160)
350 (defcap key-command string 161)
351 (defcap key-copy string 162)
352 (defcap key-create string 163)
353 (defcap key-end string 164)
354 (defcap key-enter string 165)
355 (defcap key-exit string 166)
356 (defcap key-find string 167)
357 (defcap key-help string 168)
358 (defcap key-mark string 169)
359 (defcap key-message string 170)
360 (defcap key-move string 171)
361 (defcap key-next string 172)
362 (defcap key-open string 173)
363 (defcap key-options string 174)
364 (defcap key-previous string 175)
365 (defcap key-print string 176)
366 (defcap key-redo string 177)
367 (defcap key-reference string 178)
368 (defcap key-refresh string 179)
369 (defcap key-replace string 180)
370 (defcap key-restart string 181)
371 (defcap key-resume string 182)
372 (defcap key-save string 183)
373 (defcap key-suspend string 184)
374 (defcap key-undo string 185)
375 (defcap key-sbeg string 186)
376 (defcap key-scancel string 187)
377 (defcap key-scommand string 188)
378 (defcap key-scopy string 189)
379 (defcap key-screate string 190)
380 (defcap key-sdc string 191)
381 (defcap key-sdl string 192)
382 (defcap key-select string 193)
383 (defcap key-send string 194)
384 (defcap key-seol string 195)
385 (defcap key-sexit string 196)
386 (defcap key-sfind string 197)
387 (defcap key-shelp string 198)
388 (defcap key-shome string 199)
389 (defcap key-sic string 200)
390 (defcap key-sleft string 201)
391 (defcap key-smessage string 202)
392 (defcap key-smove string 203)
393 (defcap key-snext string 204)
394 (defcap key-soptions string 205)
395 (defcap key-sprevious string 206)
396 (defcap key-sprint string 207)
397 (defcap key-sredo string 208)
398 (defcap key-sreplace string 209)
399 (defcap key-sright string 210)
400 (defcap key-srsume string 211)
401 (defcap key-ssave string 212)
402 (defcap key-ssuspend string 213)
403 (defcap key-sundo string 214)
404 (defcap req-for-input string 215)
405 (defcap key-f11 string 216)
406 (defcap key-f12 string 217)
407 (defcap key-f13 string 218)
408 (defcap key-f14 string 219)
409 (defcap key-f15 string 220)
410 (defcap key-f16 string 221)
411 (defcap key-f17 string 222)
412 (defcap key-f18 string 223)
413 (defcap key-f19 string 224)
414 (defcap key-f20 string 225)
415 (defcap key-f21 string 226)
416 (defcap key-f22 string 227)
417 (defcap key-f23 string 228)
418 (defcap key-f24 string 229)
419 (defcap key-f25 string 230)
420 (defcap key-f26 string 231)
421 (defcap key-f27 string 232)
422 (defcap key-f28 string 233)
423 (defcap key-f29 string 234)
424 (defcap key-f30 string 235)
425 (defcap key-f31 string 236)
426 (defcap key-f32 string 237)
427 (defcap key-f33 string 238)
428 (defcap key-f34 string 239)
429 (defcap key-f35 string 240)
430 (defcap key-f36 string 241)
431 (defcap key-f37 string 242)
432 (defcap key-f38 string 243)
433 (defcap key-f39 string 244)
434 (defcap key-f40 string 245)
435 (defcap key-f41 string 246)
436 (defcap key-f42 string 247)
437 (defcap key-f43 string 248)
438 (defcap key-f44 string 249)
439 (defcap key-f45 string 250)
440 (defcap key-f46 string 251)
441 (defcap key-f47 string 252)
442 (defcap key-f48 string 253)
443 (defcap key-f49 string 254)
444 (defcap key-f50 string 255)
445 (defcap key-f51 string 256)
446 (defcap key-f52 string 257)
447 (defcap key-f53 string 258)
448 (defcap key-f54 string 259)
449 (defcap key-f55 string 260)
450 (defcap key-f56 string 261)
451 (defcap key-f57 string 262)
452 (defcap key-f58 string 263)
453 (defcap key-f59 string 264)
454 (defcap key-f60 string 265)
455 (defcap key-f61 string 266)
456 (defcap key-f62 string 267)
457 (defcap key-f63 string 268)
458 (defcap clr-bol string 269)
459 (defcap clear-margins string 270)
460 (defcap set-left-margin string 271)
461 (defcap set-right-margin string 272)
462 (defcap label-format string 273)
463 (defcap set-clock string 274)
464 (defcap display-clock string 275)
465 (defcap remove-clock string 276)
466 (defcap create-window string 277)
467 (defcap goto-window string 278)
468 (defcap hangup string 279)
469 (defcap dial-phone string 280)
470 (defcap quick-dial string 281)
471 (defcap tone string 282)
472 (defcap pulse string 283)
473 (defcap flash-hook string 284)
474 (defcap fixed-pause string 285)
475 (defcap wait-tone string 286)
476 (defcap user0 string 287)
477 (defcap user1 string 288)
478 (defcap user2 string 289)
479 (defcap user3 string 290)
480 (defcap user4 string 291)
481 (defcap user5 string 292)
482 (defcap user6 string 293)
483 (defcap user7 string 294)
484 (defcap user8 string 295)
485 (defcap user9 string 296)
486 (defcap orig-pair string 297)
487 (defcap orig-colors string 298)
488 (defcap initialize-color string 299)
489 (defcap initialize-pair string 300)
490 (defcap set-color-pair string 301)
491 (defcap set-foreground string 302)
492 (defcap set-background string 303)
493 (defcap change-char-pitch string 304)
494 (defcap change-line-pitch string 305)
495 (defcap change-res-horz string 306)
496 (defcap change-res-vert string 307)
497 (defcap define-char string 308)
498 (defcap enter-doublewide-mode string 309)
499 (defcap enter-draft-quality string 310)
500 (defcap enter-italics-mode string 311)
501 (defcap enter-leftward-mode string 312)
502 (defcap enter-micro-mode string 313)
503 (defcap enter-near-letter-quality string 314)
504 (defcap enter-normal-quality string 315)
505 (defcap enter-shadow-mode string 316)
506 (defcap enter-subscript-mode string 317)
507 (defcap enter-superscript-mode string 318)
508 (defcap enter-upward-mode string 319)
509 (defcap exit-doublewide-mode string 320)
510 (defcap exit-italics-mode string 321)
511 (defcap exit-leftward-mode string 322)
512 (defcap exit-micro-mode string 323)
513 (defcap exit-shadow-mode string 324)
514 (defcap exit-subscript-mode string 325)
515 (defcap exit-superscript-mode string 326)
516 (defcap exit-upward-mode string 327)
517 (defcap micro-column-address string 328)
518 (defcap micro-down string 329)
519 (defcap micro-left string 330)
520 (defcap micro-right string 331)
521 (defcap micro-row-address string 332)
522 (defcap micro-up string 333)
523 (defcap order-of-pins string 334)
524 (defcap parm-down-micro string 335)
525 (defcap parm-left-micro string 336)
526 (defcap parm-right-micro string 337)
527 (defcap parm-up-micro string 338)
528 (defcap select-char-set string 339)
529 (defcap set-bottom-margin string 340)
530 (defcap set-bottom-margin-parm string 341)
531 (defcap set-left-margin-parm string 342)
532 (defcap set-right-margin-parm string 343)
533 (defcap set-top-margin string 344)
534 (defcap set-top-margin-parm string 345)
535 (defcap start-bit-image string 346)
536 (defcap start-char-set-def string 347)
537 (defcap stop-bit-image string 348)
538 (defcap stop-char-set-def string 349)
539 (defcap subscript-characters string 350)
540 (defcap superscript-characters string 351)
541 (defcap these-cause-cr string 352)
542 (defcap zero-motion string 353)
543 (defcap char-set-names string 354)
544 (defcap key-mouse string 355)
545 (defcap mouse-info string 356)
546 (defcap req-mouse-pos string 357)
547 (defcap get-mouse string 358)
548 (defcap set-a-foreground string 359)
549 (defcap set-a-background string 360)
550 (defcap pkey-plab string 361)
551 (defcap device-type string 362)
552 (defcap code-set-init string 363)
553 (defcap set0-des-seq string 364)
554 (defcap set1-des-seq string 365)
555 (defcap set2-des-seq string 366)
556 (defcap set3-des-seq string 367)
557 (defcap set-lr-margin string 368)
558 (defcap set-tb-margin string 369)
559 (defcap bit-image-repeat string 370)
560 (defcap bit-image-newline string 371)
561 (defcap bit-image-carriage-return string 372)
562 (defcap color-names string 373)
563 (defcap define-bit-image-region string 374)
564 (defcap end-bit-image-region string 375)
565 (defcap set-color-band string 376)
566 (defcap set-page-length string 377)
567 (defcap display-pc-char string 378)
568 (defcap enter-pc-charset-mode string 379)
569 (defcap exit-pc-charset-mode string 380)
570 (defcap enter-scancode-mode string 381)
571 (defcap exit-scancode-mode string 382)
572 (defcap pc-term-options string 383)
573 (defcap scancode-escape string 384)
574 (defcap alt-scancode-esc string 385)
575 (defcap enter-horizontal-hl-mode string 386)
576 (defcap enter-left-hl-mode string 387)
577 (defcap enter-low-hl-mode string 388)
578 (defcap enter-right-hl-mode string 389)
579 (defcap enter-top-hl-mode string 390)
580 (defcap enter-vertical-hl-mode string 391)
581 (defcap set-a-attributes string 392)
582 (defcap set-pglen-inch string 393)
583
584 ;;#+INTERNAL-CAPS-VISIBLE
585 (progn
586 (defcap termcap-init2 string 394)
587 (defcap termcap-reset string 395)
588 (defcap magic-cookie-glitch-ul integer 33)
589 (defcap backspaces-with-bs boolean 37)
590 (defcap crt-no-scrolling boolean 38)
591 (defcap no-correctly-working-cr boolean 39)
592 (defcap carriage-return-delay integer 34)
593 (defcap new-line-delay integer 35)
594 (defcap linefeed-if-not-lf string 396)
595 (defcap backspace-if-not-bs string 397)
596 (defcap gnu-has-meta-key boolean 40)
597 (defcap linefeed-is-newline boolean 41)
598 (defcap backspace-delay integer 36)
599 (defcap horizontal-tab-delay integer 37)
600 (defcap number-of-function-keys integer 38)
601 (defcap other-non-function-keys string 398)
602 (defcap arrow-key-map string 399)
603 (defcap has-hardware-tabs boolean 42)
604 (defcap return-does-clr-eol boolean 43)
605 (defcap acs-ulcorner string 400)
606 (defcap acs-llcorner string 401)
607 (defcap acs-urcorner string 402)
608 (defcap acs-lrcorner string 403)
609 (defcap acs-ltee string 404)
610 (defcap acs-rtee string 405)
611 (defcap acs-btee string 406)
612 (defcap acs-ttee string 407)
613 (defcap acs-hline string 408)
614 (defcap acs-vline string 409)
615 (defcap acs-plus string 410)
616 (defcap memory-lock string 411)
617 (defcap memory-unlock string 412)
618 (defcap box-chars-1 string 413))
619
620 (defun load-terminfo (name)
621 (flet ((stringify-first-char (name)
622 #+darwin (format nil "~X" (char-code (char name 0)))
623 #-darwin (string (char name 0))))
624 (let ((name (concatenate 'string (stringify-first-char name) "/" name)))
625 (dolist (path (list* #+CMU "home:.terminfo/"
626 #+Allegro "~/.terminfo/"
627 #-(or CMU Allegro)
628 (merge-pathnames ".terminfo/" (user-homedir-pathname))
629 *terminfo-directories*))
630 (with-open-file (stream (merge-pathnames name path)
631 :direction :input
632 :element-type '(unsigned-byte 8)
633 :if-does-not-exist nil)
634 (when stream
635 (flet ((read-short (stream)
636 (let ((n (+ (read-byte stream) (* 256 (read-byte stream)))))
637 (if (> n 32767)
638 (- n 65536)
639 n)))
640 (read-string (stream)
641 (do ((c (read-byte stream) (read-byte stream))
642 (s '()))
643 ((zerop c) (coerce (nreverse s) 'string))
644 (push (code-char c) s))))
645 (let* ((magic (read-short stream))
646 (sznames (read-short stream))
647 (szbooleans (read-short stream))
648 (sznumbers (read-short stream))
649 (szstrings (read-short stream))
650 (szstringtable (read-short stream))
651 (names (let ((string (read-string stream)))
652 (loop for i = 0 then (1+ j)
653 as j = (position #\| string :start i)
654 collect (subseq string i j) while j)))
655 (booleans (make-array szbooleans
656 :element-type '(or t nil)
657 :initial-element nil))
658 (numbers (make-array sznumbers
659 :element-type '(signed-byte 16)
660 :initial-element -1))
661 (strings (make-array szstrings
662 :element-type '(signed-byte 16)
663 :initial-element -1))
664 (stringtable (make-string szstringtable))
665 (count 0))
666 (unless (= magic #o432)
667 (error "Invalid file format"))
668 (dotimes (i szbooleans)
669 (setf (aref booleans i) (not (zerop (read-byte stream)))))
670 (when (oddp (+ sznames szbooleans))
671 (read-byte stream))
672 (dotimes (i sznumbers)
673 (setf (aref numbers i) (read-short stream)))
674 (dotimes (i szstrings)
675 (unless (minusp (setf (aref strings i) (read-short stream)))
676 (incf count)))
677 (dotimes (i szstringtable)
678 (setf (char stringtable i) (code-char (read-byte stream))))
679 (let ((xtrings (make-array szstrings :initial-element nil)))
680 (dotimes (i szstrings)
681 (unless (minusp (aref strings i))
682 (setf (aref xtrings i)
683 (subseq stringtable (aref strings i)
684 (position #\Null stringtable
685 :start (aref strings i))))))
686 (setq strings xtrings))
687 (return (make-terminfo :names names :booleans booleans
688 :numbers numbers :strings strings))))))))))
689
690 (defun tparm (string &rest args)
691 (when (null string) (return-from tparm ""))
692 (with-output-to-string (out)
693 (with-input-from-string (in string)
694 (do ((stack '()) (flags 0) (width 0) (precision 0) (number 0)
695 (dvars (make-array 26 :element-type '(unsigned-byte 8)
696 :initial-element 0))
697 (svars (load-time-value
698 (make-array 26 :element-type '(unsigned-byte 8)
699 :initial-element 0)))
700 (c (read-char in nil) (read-char in nil)))
701 ((null c))
702 (cond ((char= c #\%)
703 (setq c (read-char in) flags 0 width 0 precision 0)
704 (tagbody
705 state0
706 (case c
707 (#\% (princ c out) (go terminal))
708 (#\: (setq c (read-char in)) (go state2))
709 (#\+ (go state1))
710 (#\- (go state1))
711 (#\# (go state2))
712 (#\Space (go state2))
713 ((#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9) (go state3))
714 (#\d (go state5))
715 (#\o (go state6))
716 ((#\X #\x) (go state7))
717 (#\s (go state8))
718 (#\c (princ (code-char (pop stack)) out) (go terminal))
719 (#\p (go state9))
720 (#\P (go state10))
721 (#\g (go state11))
722 (#\' (go state12))
723 (#\{ (go state13))
724 (#\l (push (length (pop stack)) stack) (go terminal))
725 (#\* (push (* (pop stack) (pop stack)) stack)
726 (go terminal))
727 (#\/ (push (/ (pop stack) (pop stack)) stack)
728 (go terminal))
729 (#\m (push (mod (pop stack) (pop stack)) stack)
730 (go terminal))
731 (#\& (push (logand (pop stack) (pop stack)) stack)
732 (go terminal))
733 (#\| (push (logior (pop stack) (pop stack)) stack)
734 (go terminal))
735 (#\^ (push (logxor (pop stack) (pop stack)) stack)
736 (go terminal))
737 (#\= (push (if (= (pop stack) (pop stack)) 1 0) stack)
738 (go terminal))
739 (#\> (push (if (> (pop stack) (pop stack)) 1 0) stack)
740 (go terminal))
741 (#\< (push (if (< (pop stack) (pop stack)) 1 0) stack)
742 (go terminal))
743 (#\A (push (if (and (pop stack) (pop stack)) 1 0) stack)
744 (go terminal))
745 (#\O (push (if (or (pop stack) (pop stack)) 1 0) stack)
746 (go terminal))
747 (#\! (push (if (zerop (pop stack)) 1 0) stack)
748 (go terminal))
749 (#\~ (push (logand #xFF (lognot (pop stack))) stack)
750 (go terminal))
751 (#\i (when args
752 (incf (first args))
753 (when (cdr args)
754 (incf (second args))))
755 (go terminal))
756 (#\? (go state14))
757 (otherwise (error "Unknown %-control character: ~C" c)))
758 state1
759 (let ((next (peek-char nil in nil)))
760 (when (position next "0123456789# +-doXxs")
761 (go state2)))
762 (if (char= c #\+)
763 (push (+ (pop stack) (pop stack)) stack)
764 (push (- (pop stack) (pop stack)) stack))
765 (go terminal)
766 state2
767 (case c
768 (#\# (setf flags (logior flags 1)))
769 (#\+ (setf flags (logior flags 2)))
770 (#\Space (setf flags (logior flags 4)))
771 (#\- (setf flags (logior flags 8)))
772 ((#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
773 (go state3))
774 (t (go blah)))
775 (setf c (read-char in))
776 (go state2)
777 state3
778 (setf width (digit-char-p c))
779 state3-loop
780 (setf c (read-char in))
781 (case c
782 ((#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
783 (setf width (+ (* width 10) (digit-char-p c)))
784 (go state3-loop))
785 (#\. (setf c (read-char in)) (go state4)))
786 (go blah)
787 state4
788 (setf precision (digit-char-p c))
789 state4-loop
790 (setf c (read-char in))
791 (case c
792 ((#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
793 (setf precision (+ (* precision 10) (digit-char-p c)))
794 (go state4-loop)))
795 (go blah)
796 blah
797 (case c
798 (#\d (go state5))
799 (#\o (go state6))
800 ((#\X #\x) (go state7))
801 (#\s (go state8))
802 (otherwise (error "Unknown %-control character: ~C" c)))
803 state5
804 (let ((value (pop stack)))
805 (format out (if (logbitp 3 flags)
806 "~@v<~:[~*~;~C~]~v,'0D~>"
807 "~v<~:[~*~;~C~]~v,'0D~>")
808 width
809 (or (minusp value) (logbitp 1 flags)
810 (logbitp 2 flags))
811 (if (minusp value)
812 #\-
813 (if (logbitp 1 flags)
814 #\+
815 #\Space))
816 precision
817 (abs value)))
818 (go terminal)
819 state6
820 (format out (if (logbitp 3 flags)
821 "~@v<~@[0~*~]~v,'0O~>"
822 "~v<~@[0~*~]~v,'0O~>")
823 width (logbitp 0 flags) precision
824 (pop stack))
825 (go terminal)
826 state7
827 (format out (if (logbitp 3 flags)
828 "~@v<~:[~*~;0~C~]~v,'0X~>"
829 "~v<~:[~*~;0~C~]~v,'0X~>")
830 width (logbitp 0 flags) c precision
831 (pop stack))
832 (go terminal)
833 state8
834 (format t "~&;; Width ~D, Precision ~D, flags=#x~X: string"
835 width precision flags)
836 (go terminal)
837 state9
838 (let* ((i (digit-char-p (read-char in)))
839 (a (nth (1- i) args)))
840 (etypecase a
841 (character (push (char-code a) stack))
842 (integer (push a stack))))
843 (go terminal)
844 state10
845 (let ((var (read-char in)))
846 (cond ((char<= #\a var #\z)
847 (setf (aref dvars (- (char-code var)
848 (char-code #\a)))
849 (pop stack)))
850 ((char<= #\A var #\Z)
851 (setf (aref svars (- (char-code var)
852 (char-code #\A)))
853 (pop stack)))
854 (t (error "Illegal variable name: ~C" var))))
855 (go terminal)
856 state11
857 (let ((var (read-char in)))
858 (cond ((char<= #\a var #\z)
859 (push (aref dvars (- (char-code var)
860 (char-code #\a)))
861 stack))
862 ((char<= #\A var #\Z)
863 (push (aref svars (- (char-code var)
864 (char-code #\A)))
865 stack))
866 (t (error "Illegal variable name: ~C" var))))
867 (go terminal)
868 state12
869 (push (char-code (read-char in)) stack)
870 (unless (char= (read-char in) #\')
871 (error "Invalid character constant"))
872 (go terminal)
873 state13
874 (setq number 0)
875 state13-loop
876 (setq c (read-char in))
877 (let ((n (digit-char-p c)))
878 (cond (n (setq number (+ (* 10 number) n))
879 (go state13-loop))
880 ((char= c #\})
881 (push number stack)
882 (go terminal))))
883 (error "Invalid integer constant")
884 state14
885 (error "Conditional expression parser not yet written.")
886
887 terminal
888 #| that's all, folks |#))
889 (t (princ c out)))))))
890
891 (defun stream-fileno (stream)
892 (typecase stream
893 #+CMU
894 (sys:fd-stream
895 (sys:fd-stream-fd stream))
896 (two-way-stream
897 (stream-fileno (two-way-stream-output-stream stream)))
898 (synonym-stream
899 (stream-fileno (symbol-value (synonym-stream-symbol stream))))
900 (echo-stream
901 (stream-fileno (echo-stream-output-stream stream)))
902 (broadcast-stream
903 (stream-fileno (first (broadcast-stream-streams stream))))
904 (otherwise nil)))
905
906 (defun stream-baud-rate (stream)
907 #+CMU
908 (alien:with-alien ((termios (alien:struct unix:termios)))
909 (declare (optimize (ext:inhibit-warnings 3)))
910 (when (unix:unix-tcgetattr (stream-fileno stream) termios)
911 (let ((baud (logand unix:tty-cbaud
912 (alien:slot termios 'unix:c-cflag))))
913 (if (< baud unix::tty-cbaudex)
914 (aref #(0 50 75 110 134 150 200 300 600 1200
915 1800 2400 4800 9600 19200 38400)
916 baud)
917 (aref #(57600 115200 230400 460800 500000 576000
918 921600 1000000 1152000 1500000 2000000
919 2500000 3000000 3500000 4000000)
920 (logxor baud unix::tty-cbaudex)))))))
921
922 (defun tputs (string &rest args)
923 (when string
924 (let* ((stream (if (streamp (first args)) (pop args) *terminal-io*))
925 (terminfo (if (terminfo-p (first args)) (pop args) *terminfo*)))
926 (with-input-from-string (string (apply #'tparm string args))
927 (do ((c (read-char string nil) (read-char string nil)))
928 ((null c))
929 (cond ((and (char= c #\$)
930 (eql (peek-char nil string nil) #\<))
931 (let ((time 0) (force nil) (rate nil) (pad #\Null))
932
933 ;; Find out how long to pad for:
934 (read-char string) ; eat the #\<
935 (loop
936 (setq c (read-char string))
937 (let ((n (digit-char-p c)))
938 (if n
939 (setq time (+ (* time 10) n))
940 (return))))
941 (if (char= c #\.)
942 (setq time (+ (* time 10)
943 (digit-char-p (read-char string)))
944 c (read-char string))
945 (setq time (* time 10)))
946 (when (char= c #\*)
947 ;; multiply time by "number of lines affected"
948 ;; but how do I know that??
949 (setq c (read-char string)))
950 (when (char= c #\/)
951 (setq force t c (read-char string)))
952 (unless (char= c #\>)
953 (error "Invalid padding specification."))
954
955 ;; Decide whether to apply padding:
956 (when (or force (not (capability :xon-xoff terminfo)))
957 (setq rate (stream-baud-rate stream))
958 (when (let ((pb (capability :padding-baud-rate terminfo)))
959 (and rate (or (null pb) (> rate pb))))
960 (cond ((capability :no-pad-char terminfo)
961 (finish-output stream)
962 (sleep (/ time 10000.0)))
963 (t
964 (let ((tmp (capability :pad-char terminfo)))
965 (when tmp (setf pad (schar tmp 0))))
966 (dotimes (i (ceiling (* rate time) 100000))
967 (princ pad stream))))))))
968
969 (t
970 (princ c stream))))))
971 t))
972
973 (defun set-terminal (&optional name)
974 (setf *terminfo* (load-terminfo (or name
975 #+CMU
976 (cdr (assoc "TERM" ext:*environment-list*
977 :test #'string=))
978 #+Allegro
979 (sys:getenv "TERM")
980 #+SBCL
981 (sb-ext:posix-getenv "TERM")
982 #+Lispworks
983 (lispworks:environment-variable "TERM")
984 #| if all else fails |#
985 "dumb"))))
986
987 ;;(if (null *terminfo*)
988 ;; (set-terminal))
989
990 (provide :terminfo)

  ViewVC Help
Powered by ViewVC 1.1.5