Add $ and ` for escaping and reorder it according to the ascii values
[midnight-commander.git] / slang / sltermin.c
blob4ecf7baa8e11e260d7eeda645a266967e5ed7eb4
1 /* This file contains enough terminfo reading capabilities sufficient for
2 * the slang SLtt interface.
3 */
5 /*
6 Copyright (C) 2004, 2005, 2006 John E. Davis
8 This file is part of the S-Lang Library.
10 The S-Lang Library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License as
12 published by the Free Software Foundation; either version 2 of the
13 License, or (at your option) any later version.
15 The S-Lang Library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 General Public License for more details.
20 You should have received a copy of the GNU General Public License
21 along with this library; if not, write to the Free Software
22 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
23 USA.
26 #include "slinclud.h"
28 #include "slang.h"
29 #include "_slang.h"
32 * The majority of the comments found in the file were taken from the
33 * term(4) man page on an SGI.
36 /* Short integers are stored in two 8-bit bytes. The first byte contains
37 * the least significant 8 bits of the value, and the second byte contains
38 * the most significant 8 bits. (Thus, the value represented is
39 * 256*second+first.) The value -1 is represented by 0377,0377, and the
40 * value -2 is represented by 0376,0377; other negative values are illegal.
41 * The -1 generally means that a capability is missing from this terminal.
42 * The -2 means that the capability has been cancelled in the terminfo
43 * source and also is to be considered missing.
46 static int make_integer (unsigned char *buf)
48 register int lo, hi;
49 lo = (int) *buf++; hi = (int) *buf;
50 if (hi == 0377)
52 if (lo == 0377) return -1;
53 if (lo == 0376) return -2;
55 return lo + 256 * hi;
59 * The compiled file is created from the source file descriptions of the
60 * terminals (see the -I option of infocmp) by using the terminfo compiler,
61 * tic, and read by the routine setupterm [see curses(3X).] The file is
62 * divided into six parts in the following order: the header, terminal
63 * names, boolean flags, numbers, strings, and string table.
65 * The header section begins the file. This section contains six short
66 * integers in the format described below. These integers are (1) the magic
67 * number (octal 0432); (2) the size, in bytes, of the names section; (3)
68 * the number of bytes in the boolean section; (4) the number of short
69 * integers in the numbers section; (5) the number of offsets (short
70 * integers) in the strings section; (6) the size, in bytes, of the string
71 * table.
74 #define MAGIC 0432
76 /* In this structure, all char * fields are malloced EXCEPT if the
77 * structure is SLTERMCAP. In that case, only terminal_names is malloced
78 * and the other fields are pointers into it.
80 struct _pSLterminfo_Type
82 #define SLTERMINFO 1
83 #define SLTERMCAP 2
84 unsigned int flags;
86 unsigned int name_section_size;
87 char *terminal_names;
89 unsigned int boolean_section_size;
90 unsigned char *boolean_flags;
92 unsigned int num_numbers;
93 unsigned char *numbers;
95 unsigned int num_string_offsets;
96 unsigned char *string_offsets;
98 unsigned int string_table_size;
99 char *string_table;
103 static char *tcap_getstr (char *, SLterminfo_Type *);
104 static int tcap_getnum (char *, SLterminfo_Type *);
105 static int tcap_getflag (char *, SLterminfo_Type *);
106 static int tcap_getent (char *, SLterminfo_Type *);
108 static FILE *open_terminfo (char *file, SLterminfo_Type *h)
110 FILE *fp;
111 unsigned char buf[12];
113 /* Alan Cox reported a security problem here if the application using the
114 * library is setuid. So, I need to make sure open the file as a normal
115 * user. Unfortunately, there does not appear to be a portable way of
116 * doing this, so I am going to use 'setfsgid' and 'setfsuid', which
117 * are not portable.
119 * I will also look into the use of setreuid, seteuid and setregid, setegid.
120 * FIXME: Priority=medium
122 fp = fopen (file, "rb");
123 if (fp == NULL) return NULL;
125 if ((12 == fread ((char *) buf, 1, 12, fp) && (MAGIC == make_integer (buf))))
127 h->name_section_size = make_integer (buf + 2);
128 h->boolean_section_size = make_integer (buf + 4);
129 h->num_numbers = make_integer (buf + 6);
130 h->num_string_offsets = make_integer (buf + 8);
131 h->string_table_size = make_integer (buf + 10);
133 else
135 fclose (fp);
136 fp = NULL;
138 return fp;
142 * The terminal names section comes next. It contains the first line of the
143 * terminfo description, listing the various names for the terminal,
144 * separated by the bar ( | ) character (see term(5)). The section is
145 * terminated with an ASCII NUL character.
148 /* returns pointer to malloced space */
149 static unsigned char *read_terminfo_section (FILE *fp, unsigned int size)
151 char *s;
153 if (NULL == (s = (char *) SLmalloc (size))) return NULL;
154 if (size != fread (s, 1, size, fp))
156 SLfree (s);
157 return NULL;
159 return (unsigned char *) s;
162 static char *read_terminal_names (FILE *fp, SLterminfo_Type *t)
164 return t->terminal_names = (char *) read_terminfo_section (fp, t->name_section_size);
168 * The boolean flags have one byte for each flag. This byte is either 0 or
169 * 1 as the flag is present or absent. The value of 2 means that the flag
170 * has been cancelled. The capabilities are in the same order as the file
171 * <term.h>.
174 static unsigned char *read_boolean_flags (FILE *fp, SLterminfo_Type *t)
176 /* Between the boolean section and the number section, a null byte is
177 * inserted, if necessary, to ensure that the number section begins on an
178 * even byte offset. All short integers are aligned on a short word
179 * boundary.
182 unsigned int size = (t->name_section_size + t->boolean_section_size) % 2;
183 size += t->boolean_section_size;
185 return t->boolean_flags = read_terminfo_section (fp, size);
189 * The numbers section is similar to the boolean flags section. Each
190 * capability takes up two bytes, and is stored as a short integer. If the
191 * value represented is -1 or -2, the capability is taken to be missing.
194 static unsigned char *read_numbers (FILE *fp, SLterminfo_Type *t)
196 return t->numbers = read_terminfo_section (fp, 2 * t->num_numbers);
199 /* The strings section is also similar. Each capability is stored as a
200 * short integer, in the format above. A value of -1 or -2 means the
201 * capability is missing. Otherwise, the value is taken as an offset from
202 * the beginning of the string table. Special characters in ^X or \c
203 * notation are stored in their interpreted form, not the printing
204 * representation. Padding information ($<nn>) and parameter information
205 * (%x) are stored intact in uninterpreted form.
208 static unsigned char *read_string_offsets (FILE *fp, SLterminfo_Type *t)
210 return t->string_offsets = (unsigned char *) read_terminfo_section (fp, 2 * t->num_string_offsets);
213 /* The final section is the string table. It contains all the values of
214 * string capabilities referenced in the string section. Each string is
215 * null terminated.
218 static char *read_string_table (FILE *fp, SLterminfo_Type *t)
220 return t->string_table = (char *) read_terminfo_section (fp, t->string_table_size);
224 * Compiled terminfo(4) descriptions are placed under the directory
225 * /usr/share/lib/terminfo. In order to avoid a linear search of a huge
226 * UNIX system directory, a two-level scheme is used:
227 * /usr/share/lib/terminfo/c/name where name is the name of the terminal,
228 * and c is the first character of name. Thus, att4425 can be found in the
229 * file /usr/share/lib/terminfo/a/att4425. Synonyms for the same terminal
230 * are implemented by multiple links to the same compiled file.
233 static char *Terminfo_Dirs [] =
235 NULL, /* $HOME/.terminfo */
236 NULL, /* $TERMINFO */
237 "/usr/share/terminfo",
238 "/usr/lib/terminfo",
239 "/usr/share/lib/terminfo",
240 "/etc/terminfo",
241 "/usr/local/lib/terminfo",
242 #ifdef MISC_TERMINFO_DIRS
243 MISC_TERMINFO_DIRS,
244 #endif
248 SLterminfo_Type *_pSLtt_tigetent (char *term)
250 char *tidir;
251 int i;
252 FILE *fp = NULL;
253 char file[1024];
254 static char home_ti [1024];
255 char *home;
256 SLterminfo_Type *ti;
258 if (
259 (term == NULL)
260 #ifdef SLANG_UNTIC
261 && (SLang_Untic_Terminfo_File == NULL)
262 #endif
264 return NULL;
266 if (_pSLsecure_issetugid ()
267 && ((term[0] == '.') || (NULL != strchr (term, '/'))))
268 return NULL;
270 if (NULL == (ti = (SLterminfo_Type *) SLmalloc (sizeof (SLterminfo_Type))))
272 return NULL;
275 #ifdef SLANG_UNTIC
276 if (SLang_Untic_Terminfo_File != NULL)
278 fp = open_terminfo (SLang_Untic_Terminfo_File, ti);
279 goto fp_open_label;
281 else
282 #endif
283 /* If we are on a termcap based system, use termcap */
284 if (0 == tcap_getent (term, ti)) return ti;
286 if (NULL != (home = _pSLsecure_getenv ("HOME")))
288 size_t len = strlen (home);
290 if (len > sizeof (home_ti) - sizeof ("/.terminfo"))
291 len = sizeof (home_ti) - sizeof ("/.terminfo");
292 memcpy (home_ti, home, len);
293 memcpy (home_ti + len, "/.terminfo", sizeof ("/.terminfo"));
294 Terminfo_Dirs [0] = home_ti;
297 Terminfo_Dirs[1] = _pSLsecure_getenv ("TERMINFO");
298 i = 0;
299 while (1)
301 tidir = Terminfo_Dirs[i];
302 if (tidir != NULL)
304 if (*tidir == 0)
305 break; /* last one */
307 if (sizeof (file) >= strlen (tidir) + 4 + strlen (term))
309 sprintf (file, "%s/%c/%s", tidir, *term, term);
310 if (NULL != (fp = open_terminfo (file, ti)))
311 break;
314 i++;
317 #ifdef SLANG_UNTIC
318 fp_open_label:
319 #endif
321 if (fp != NULL)
323 if (NULL != read_terminal_names (fp, ti))
325 if (NULL != read_boolean_flags (fp, ti))
327 if (NULL != read_numbers (fp, ti))
329 if (NULL != read_string_offsets (fp, ti))
331 if (NULL != read_string_table (fp, ti))
333 /* success */
334 fclose (fp);
335 ti->flags = SLTERMINFO;
336 return ti;
338 SLfree ((char *)ti->string_offsets);
340 SLfree ((char *)ti->numbers);
342 SLfree ((char *)ti->boolean_flags);
344 SLfree ((char *)ti->terminal_names);
346 fclose (fp);
349 SLfree ((char *)ti);
350 return NULL;
353 #ifdef SLANG_UNTIC
354 # define UNTIC_COMMENT(x) ,x
355 #else
356 # define UNTIC_COMMENT(x)
357 #endif
359 typedef SLCONST struct
361 char name[3];
362 int offset;
363 #ifdef SLANG_UNTIC
364 char *comment;
365 #endif
367 Tgetstr_Map_Type;
369 /* I need to add: K1-5, %0-5(not important), @8, &8... */
370 static Tgetstr_Map_Type Tgetstr_Map [] =
372 {"!1", 212 UNTIC_COMMENT("shifted key")},
373 {"!2", 213 UNTIC_COMMENT("shifted key")},
374 {"!3", 214 UNTIC_COMMENT("shifted key")},
375 {"#1", 198 UNTIC_COMMENT("shifted key")},
376 {"#2", 199 UNTIC_COMMENT("Key S-Home")},
377 {"#3", 200 UNTIC_COMMENT("Key S-Insert")},
378 {"#4", 201 UNTIC_COMMENT("Key S-Left")},
379 {"%0", 177 UNTIC_COMMENT("redo key")},
380 {"%1", 168 UNTIC_COMMENT("help key")},
381 {"%2", 169 UNTIC_COMMENT("mark key")},
382 {"%3", 170 UNTIC_COMMENT("message key")},
383 {"%4", 171 UNTIC_COMMENT("move key")},
384 {"%5", 172 UNTIC_COMMENT("next key")},
385 {"%6", 173 UNTIC_COMMENT("open key")},
386 {"%7", 174 UNTIC_COMMENT("options key")},
387 {"%8", 175 UNTIC_COMMENT("previous key")},
388 {"%9", 176 UNTIC_COMMENT("print key")},
389 {"%a", 202 UNTIC_COMMENT("shifted key")},
390 {"%b", 203 UNTIC_COMMENT("shifted key")},
391 {"%c", 204 UNTIC_COMMENT("Key S-Next")},
392 {"%d", 205 UNTIC_COMMENT("shifted key")},
393 {"%e", 206 UNTIC_COMMENT("Key S-Previous")},
394 {"%f", 207 UNTIC_COMMENT("shifted key")},
395 {"%g", 208 UNTIC_COMMENT("shifted key")},
396 {"%h", 209 UNTIC_COMMENT("shifted key")},
397 {"%i", 210 UNTIC_COMMENT("Key S-Right")},
398 {"%j", 211 UNTIC_COMMENT("shifted key")},
399 {"&0", 187 UNTIC_COMMENT("shifted key")},
400 {"&1", 178 UNTIC_COMMENT("reference key")},
401 {"&2", 179 UNTIC_COMMENT("refresh key")},
402 {"&3", 180 UNTIC_COMMENT("replace key")},
403 {"&4", 181 UNTIC_COMMENT("restart key")},
404 {"&5", 182 UNTIC_COMMENT("resume key")},
405 {"&6", 183 UNTIC_COMMENT("save key")},
406 {"&7", 184 UNTIC_COMMENT("suspend key")},
407 {"&8", 185 UNTIC_COMMENT("undo key")},
408 {"&9", 186 UNTIC_COMMENT("shifted key")},
409 {"*0", 197 UNTIC_COMMENT("shifted key")},
410 {"*1", 188 UNTIC_COMMENT("shifted key")},
411 {"*2", 189 UNTIC_COMMENT("shifted key")},
412 {"*3", 190 UNTIC_COMMENT("shifted key")},
413 {"*4", 191 UNTIC_COMMENT("Key S-Delete")},
414 {"*5", 192 UNTIC_COMMENT("shifted key")},
415 {"*6", 193 UNTIC_COMMENT("select key")},
416 {"*7", 194 UNTIC_COMMENT("Key S-End")},
417 {"*8", 195 UNTIC_COMMENT("shifted key")},
418 {"*9", 196 UNTIC_COMMENT("shifted key")},
419 {"@0", 167 UNTIC_COMMENT("find key")},
420 {"@1", 158 UNTIC_COMMENT("begin key")},
421 {"@2", 159 UNTIC_COMMENT("cancel key")},
422 {"@3", 160 UNTIC_COMMENT("close key")},
423 {"@4", 161 UNTIC_COMMENT("command key")},
424 {"@5", 162 UNTIC_COMMENT("copy key")},
425 {"@6", 163 UNTIC_COMMENT("create key")},
426 {"@7", 164 UNTIC_COMMENT("Key End")},
427 {"@8", 165 UNTIC_COMMENT("enter/send key")},
428 {"@9", 166 UNTIC_COMMENT("exit key")},
429 {"AB", 360 UNTIC_COMMENT("set ANSI color background")},
430 {"AF", 359 UNTIC_COMMENT("set ANSI color foreground")},
431 {"AL", 110 UNTIC_COMMENT("parm_insert_line")},
432 {"CC", 9 UNTIC_COMMENT("terminal settable cmd character in prototype !?")},
433 {"CM", 15 UNTIC_COMMENT("memory relative cursor addressing")},
434 {"CW", 277 UNTIC_COMMENT("define a window #1 from #2, #3 to #4, #5")},
435 {"DC", 105 UNTIC_COMMENT("delete #1 chars")},
436 {"DI", 280 UNTIC_COMMENT("dial number #1")},
437 {"DK", 275 UNTIC_COMMENT("display clock at (#1,#2)")},
438 {"DL", 106 UNTIC_COMMENT("parm_delete_line")},
439 {"DO", 107 UNTIC_COMMENT("down #1 lines")},
440 {"F1", 216 UNTIC_COMMENT("key_f11")},
441 {"F2", 217 UNTIC_COMMENT("key_f12")},
442 {"F3", 218 UNTIC_COMMENT("key_f13")},
443 {"F4", 219 UNTIC_COMMENT("key_f14")},
444 {"F5", 220 UNTIC_COMMENT("key_f15")},
445 {"F6", 221 UNTIC_COMMENT("key_f16")},
446 {"F7", 222 UNTIC_COMMENT("key_f17")},
447 {"F8", 223 UNTIC_COMMENT("key_f18")},
448 {"F9", 224 UNTIC_COMMENT("key_f19")},
449 {"FA", 225 UNTIC_COMMENT("key_f20")},
450 {"FB", 226 UNTIC_COMMENT("F21 function key")},
451 {"FC", 227 UNTIC_COMMENT("F22 function key")},
452 {"FD", 228 UNTIC_COMMENT("F23 function key")},
453 {"FE", 229 UNTIC_COMMENT("F24 function key")},
454 {"FF", 230 UNTIC_COMMENT("F25 function key")},
455 {"FG", 231 UNTIC_COMMENT("F26 function key")},
456 {"FH", 232 UNTIC_COMMENT("F27 function key")},
457 {"FI", 233 UNTIC_COMMENT("F28 function key")},
458 {"FJ", 234 UNTIC_COMMENT("F29 function key")},
459 {"FK", 235 UNTIC_COMMENT("F30 function key")},
460 {"FL", 236 UNTIC_COMMENT("F31 function key")},
461 {"FM", 237 UNTIC_COMMENT("F32 function key")},
462 {"FN", 238 UNTIC_COMMENT("F33 function key")},
463 {"FO", 239 UNTIC_COMMENT("F34 function key")},
464 {"FP", 240 UNTIC_COMMENT("F35 function key")},
465 {"FQ", 241 UNTIC_COMMENT("F36 function key")},
466 {"FR", 242 UNTIC_COMMENT("F37 function key")},
467 {"FS", 243 UNTIC_COMMENT("F38 function key")},
468 {"FT", 244 UNTIC_COMMENT("F39 function key")},
469 {"FU", 245 UNTIC_COMMENT("F40 function key")},
470 {"FV", 246 UNTIC_COMMENT("F41 function key")},
471 {"FW", 247 UNTIC_COMMENT("F42 function key")},
472 {"FX", 248 UNTIC_COMMENT("F43 function key")},
473 {"FY", 249 UNTIC_COMMENT("F44 function key")},
474 {"FZ", 250 UNTIC_COMMENT("F45 function key")},
475 {"Fa", 251 UNTIC_COMMENT("F46 function key")},
476 {"Fb", 252 UNTIC_COMMENT("F47 function key")},
477 {"Fc", 253 UNTIC_COMMENT("F48 function key")},
478 {"Fd", 254 UNTIC_COMMENT("F49 function key")},
479 {"Fe", 255 UNTIC_COMMENT("F50 function key")},
480 {"Ff", 256 UNTIC_COMMENT("F51 function key")},
481 {"Fg", 257 UNTIC_COMMENT("F52 function key")},
482 {"Fh", 258 UNTIC_COMMENT("F53 function key")},
483 {"Fi", 259 UNTIC_COMMENT("F54 function key")},
484 {"Fj", 260 UNTIC_COMMENT("F55 function key")},
485 {"Fk", 261 UNTIC_COMMENT("F56 function key")},
486 {"Fl", 262 UNTIC_COMMENT("F57 function key")},
487 {"Fm", 263 UNTIC_COMMENT("F58 function key")},
488 {"Fn", 264 UNTIC_COMMENT("F59 function key")},
489 {"Fo", 265 UNTIC_COMMENT("F60 function key")},
490 {"Fp", 266 UNTIC_COMMENT("F61 function key")},
491 {"Fq", 267 UNTIC_COMMENT("F62 function key")},
492 {"Fr", 268 UNTIC_COMMENT("F63 function key")},
493 {"G1", 400 UNTIC_COMMENT("single upper right")},
494 {"G2", 398 UNTIC_COMMENT("single upper left")},
495 {"G3", 399 UNTIC_COMMENT("single lower left")},
496 {"G4", 401 UNTIC_COMMENT("single lower right")},
497 {"GC", 408 UNTIC_COMMENT("single intersection")},
498 {"GD", 405 UNTIC_COMMENT("tee pointing down")},
499 {"GH", 406 UNTIC_COMMENT("single horizontal line")},
500 {"GL", 403 UNTIC_COMMENT("tee pointing left")},
501 {"GR", 402 UNTIC_COMMENT("tee pointing right")},
502 {"GU", 404 UNTIC_COMMENT("tee pointing up")},
503 {"GV", 407 UNTIC_COMMENT("single vertical line")},
504 {"Gm", 358 UNTIC_COMMENT("Curses should get button events")},
505 {"HU", 279 UNTIC_COMMENT("hang-up phone")},
506 {"IC", 108 UNTIC_COMMENT("insert #1 chars")},
507 {"Ic", 299 UNTIC_COMMENT("initialize color #1 to (#2,#3,#4)")},
508 {"Ip", 300 UNTIC_COMMENT("Initialize color pair #1 to fg=(#2,#3,#4), bg=(#5,#6,#7)")},
509 {"K1", 139 UNTIC_COMMENT("upper left of keypad")},
510 {"K2", 141 UNTIC_COMMENT("center of keypad")},
511 {"K3", 140 UNTIC_COMMENT("upper right of keypad")},
512 {"K4", 142 UNTIC_COMMENT("lower left of keypad")},
513 {"K5", 143 UNTIC_COMMENT("lower right of keypad")},
514 {"Km", 355 UNTIC_COMMENT("Mouse event has occurred")},
515 {"LE", 111 UNTIC_COMMENT("move #1 chars to the left")},
516 {"LF", 157 UNTIC_COMMENT("turn off soft labels")},
517 {"LO", 156 UNTIC_COMMENT("turn on soft labels")},
518 {"Lf", 273 UNTIC_COMMENT("label format")},
519 {"MC", 270 UNTIC_COMMENT("clear right and left soft margins")},
520 {"ML", 271 UNTIC_COMMENT("set left soft margin")},
521 {"ML", 368 UNTIC_COMMENT("Set both left and right margins to #1, #2")},
522 {"MR", 272 UNTIC_COMMENT("set right soft margin")},
523 {"MT", 369 UNTIC_COMMENT("Sets both top and bottom margins to #1, #2")},
524 {"Mi", 356 UNTIC_COMMENT("Mouse status information")},
525 {"PA", 285 UNTIC_COMMENT("pause for 2-3 seconds")},
526 {"PU", 283 UNTIC_COMMENT("select pulse dialling")},
527 {"QD", 281 UNTIC_COMMENT("dial number #1 without checking")},
528 {"RA", 152 UNTIC_COMMENT("turn off automatic margins")},
529 {"RC", 276 UNTIC_COMMENT("remove clock")},
530 {"RF", 215 UNTIC_COMMENT("send next input char (for ptys)")},
531 {"RI", 112 UNTIC_COMMENT("parm_right_cursor")},
532 {"RQ", 357 UNTIC_COMMENT("Request mouse position")},
533 {"RX", 150 UNTIC_COMMENT("turn off xon/xoff handshaking")},
534 {"S1", 378 UNTIC_COMMENT("Display PC character")},
535 {"S2", 379 UNTIC_COMMENT("Enter PC character display mode")},
536 {"S3", 380 UNTIC_COMMENT("Exit PC character display mode")},
537 {"S4", 381 UNTIC_COMMENT("Enter PC scancode mode")},
538 {"S5", 382 UNTIC_COMMENT("Exit PC scancode mode")},
539 {"S6", 383 UNTIC_COMMENT("PC terminal options")},
540 {"S7", 384 UNTIC_COMMENT("Escape for scancode emulation")},
541 {"S8", 385 UNTIC_COMMENT("Alternate escape for scancode emulation")},
542 {"SA", 151 UNTIC_COMMENT("turn on automatic margins")},
543 {"SC", 274 UNTIC_COMMENT("set clock, #1 hrs #2 mins #3 secs")},
544 {"SF", 109 UNTIC_COMMENT("scroll forward #1 lines")},
545 {"SR", 113 UNTIC_COMMENT("scroll back #1 lines")},
546 {"SX", 149 UNTIC_COMMENT("turn on xon/xoff handshaking")},
547 {"Sb", 303 UNTIC_COMMENT("set background (color)")},
548 {"Sf", 302 UNTIC_COMMENT("set foreground (color)")},
549 {"TO", 282 UNTIC_COMMENT("select touch tone dialing")},
550 {"UP", 114 UNTIC_COMMENT("up #1 lines")},
551 {"WA", 286 UNTIC_COMMENT("wait for dial-tone")},
552 {"WG", 278 UNTIC_COMMENT("go to window #1")},
553 {"XF", 154 UNTIC_COMMENT("XOFF character")},
554 {"XN", 153 UNTIC_COMMENT("XON character")},
555 {"Xh", 386 UNTIC_COMMENT("Enter horizontal highlight mode")},
556 {"Xl", 387 UNTIC_COMMENT("Enter left highlight mode")},
557 {"Xo", 388 UNTIC_COMMENT("Enter low highlight mode")},
558 {"Xr", 389 UNTIC_COMMENT("Enter right highlight mode")},
559 {"Xt", 390 UNTIC_COMMENT("Enter top highlight mode")},
560 {"Xv", 391 UNTIC_COMMENT("Enter vertical highlight mode")},
561 {"Xy", 370 UNTIC_COMMENT("Repeat bit image cell #1 #2 times")},
562 {"YZ", 377 UNTIC_COMMENT("Set page length to #1 lines")},
563 {"Yv", 372 UNTIC_COMMENT("Move to beginning of same row")},
564 {"Yw", 373 UNTIC_COMMENT("Give name for color #1")},
565 {"Yx", 374 UNTIC_COMMENT("Define rectangualar bit image region")},
566 {"Yy", 375 UNTIC_COMMENT("End a bit-image region")},
567 {"Yz", 376 UNTIC_COMMENT("Change to ribbon color #1")},
568 {"ZA", 304 UNTIC_COMMENT("Change number of characters per inch")},
569 {"ZB", 305 UNTIC_COMMENT("Change number of lines per inch")},
570 {"ZC", 306 UNTIC_COMMENT("Change horizontal resolution")},
571 {"ZD", 307 UNTIC_COMMENT("Change vertical resolution")},
572 {"ZE", 308 UNTIC_COMMENT("Define a character")},
573 {"ZF", 309 UNTIC_COMMENT("Enter double-wide mode")},
574 {"ZG", 310 UNTIC_COMMENT("Enter draft-quality mode")},
575 {"ZH", 311 UNTIC_COMMENT("Enter italic mode")},
576 {"ZI", 312 UNTIC_COMMENT("Start leftward carriage motion")},
577 {"ZJ", 313 UNTIC_COMMENT("Start micro-motion mode")},
578 {"ZK", 314 UNTIC_COMMENT("Enter NLQ mode")},
579 {"ZL", 315 UNTIC_COMMENT("Wnter normal-quality mode")},
580 {"ZM", 316 UNTIC_COMMENT("Enter shadow-print mode")},
581 {"ZN", 317 UNTIC_COMMENT("Enter subscript mode")},
582 {"ZO", 318 UNTIC_COMMENT("Enter superscript mode")},
583 {"ZP", 319 UNTIC_COMMENT("Start upward carriage motion")},
584 {"ZQ", 320 UNTIC_COMMENT("End double-wide mode")},
585 {"ZR", 321 UNTIC_COMMENT("End italic mode")},
586 {"ZS", 322 UNTIC_COMMENT("End left-motion mode")},
587 {"ZT", 323 UNTIC_COMMENT("End micro-motion mode")},
588 {"ZU", 324 UNTIC_COMMENT("End shadow-print mode")},
589 {"ZV", 325 UNTIC_COMMENT("End subscript mode")},
590 {"ZW", 326 UNTIC_COMMENT("End superscript mode")},
591 {"ZX", 327 UNTIC_COMMENT("End reverse character motion")},
592 {"ZY", 328 UNTIC_COMMENT("Like column_address in micro mode")},
593 {"ZZ", 329 UNTIC_COMMENT("Like cursor_down in micro mode")},
594 {"Za", 330 UNTIC_COMMENT("Like cursor_left in micro mode")},
595 {"Zb", 331 UNTIC_COMMENT("Like cursor_right in micro mode")},
596 {"Zc", 332 UNTIC_COMMENT("Like row_address in micro mode")},
597 {"Zd", 333 UNTIC_COMMENT("Like cursor_up in micro mode")},
598 {"Ze", 334 UNTIC_COMMENT("Match software bits to print-head pins")},
599 {"Zf", 335 UNTIC_COMMENT("Like parm_down_cursor in micro mode")},
600 {"Zg", 336 UNTIC_COMMENT("Like parm_left_cursor in micro mode")},
601 {"Zh", 337 UNTIC_COMMENT("Like parm_right_cursor in micro mode")},
602 {"Zi", 338 UNTIC_COMMENT("Like parm_up_cursor in micro mode")},
603 {"Zj", 339 UNTIC_COMMENT("Select character set")},
604 {"Zk", 340 UNTIC_COMMENT("Set bottom margin at current line")},
605 {"Zl", 341 UNTIC_COMMENT("Set bottom margin at line #1 or #2 lines from bottom")},
606 {"Zm", 342 UNTIC_COMMENT("Set left (right) margin at column #1 (#2)")},
607 {"Zn", 343 UNTIC_COMMENT("Set right margin at column #1")},
608 {"Zo", 344 UNTIC_COMMENT("Set top margin at current line")},
609 {"Zp", 345 UNTIC_COMMENT("Set top (bottom) margin at row #1 (#2)")},
610 {"Zq", 346 UNTIC_COMMENT("Start printing bit image braphics")},
611 {"Zr", 347 UNTIC_COMMENT("Start character set definition")},
612 {"Zs", 348 UNTIC_COMMENT("Stop printing bit image graphics")},
613 {"Zt", 349 UNTIC_COMMENT("End definition of character aet")},
614 {"Zu", 350 UNTIC_COMMENT("List of subscriptable characters")},
615 {"Zv", 351 UNTIC_COMMENT("List of superscriptable characters")},
616 {"Zw", 352 UNTIC_COMMENT("Printing any of these chars causes CR")},
617 {"Zx", 353 UNTIC_COMMENT("No motion for subsequent character")},
618 {"Zy", 354 UNTIC_COMMENT("List of character set names")},
619 {"Zz", 371 UNTIC_COMMENT("Move to next row of the bit image")},
620 {"ac", 146 UNTIC_COMMENT("acs_chars")},
621 {"ae", 38 UNTIC_COMMENT("exit_alt_charset_mode")},
622 {"al", 53 UNTIC_COMMENT("insert line")},
623 {"as", 25 UNTIC_COMMENT("enter_alt_charset_mode")},
624 {"bc", 395 UNTIC_COMMENT("move left, if not ^H")},
625 {"bl", 1 UNTIC_COMMENT("audible signal (bell)")},
626 {"bt", 0 UNTIC_COMMENT("back tab")},
627 {"bx", 411 UNTIC_COMMENT("box chars primary set")},
628 {"cb", 269 UNTIC_COMMENT("Clear to beginning of line")},
629 {"cd", 7 UNTIC_COMMENT("clear to end of screen")},
630 {"ce", 6 UNTIC_COMMENT("clr_eol")},
631 {"ch", 8 UNTIC_COMMENT("horizontal position #1, absolute")},
632 {"ci", 363 UNTIC_COMMENT("Init sequence for multiple codesets")},
633 {"cl", 5 UNTIC_COMMENT("clear screen and home cursor")},
634 {"cm", 10 UNTIC_COMMENT("move to row #1 columns #2")},
635 {"cr", 2 UNTIC_COMMENT("carriage return")},
636 {"cs", 3 UNTIC_COMMENT("change region to line #1 to line #2")},
637 {"ct", 4 UNTIC_COMMENT("clear all tab stops")},
638 {"cv", 127 UNTIC_COMMENT("vertical position #1 absolute")},
639 {"dc", 21 UNTIC_COMMENT("delete character")},
640 {"dl", 22 UNTIC_COMMENT("delete line")},
641 {"dm", 29 UNTIC_COMMENT("enter delete mode")},
642 {"do", 11 UNTIC_COMMENT("down one line")},
643 {"ds", 23 UNTIC_COMMENT("disable status line")},
644 {"dv", 362 UNTIC_COMMENT("Indicate language/codeset support")},
645 {"eA", 155 UNTIC_COMMENT("enable alternate char set")},
646 {"ec", 37 UNTIC_COMMENT("erase #1 characters")},
647 {"ed", 41 UNTIC_COMMENT("end delete mode")},
648 {"ei", 42 UNTIC_COMMENT("exit insert mode")},
649 {"ff", 46 UNTIC_COMMENT("hardcopy terminal page eject")},
650 {"fh", 284 UNTIC_COMMENT("flash switch hook")},
651 {"fs", 47 UNTIC_COMMENT("return from status line")},
652 {"hd", 24 UNTIC_COMMENT("half a line down")},
653 {"ho", 12 UNTIC_COMMENT("home cursor (if no cup)")},
654 {"hu", 137 UNTIC_COMMENT("half a line up")},
655 {"i1", 48 UNTIC_COMMENT("initialization string")},
656 {"i2", 392 UNTIC_COMMENT("secondary initialization string")},
657 {"i3", 50 UNTIC_COMMENT("initialization string")},
658 {"iP", 138 UNTIC_COMMENT("path name of program for initialization")},
659 {"ic", 52 UNTIC_COMMENT("insert character")},
660 {"if", 51 UNTIC_COMMENT("name of initialization file")},
661 {"im", 31 UNTIC_COMMENT("enter insert mode")},
662 {"ip", 54 UNTIC_COMMENT("insert padding after inserted character")},
663 {"is", 49 UNTIC_COMMENT("initialization string")},
664 {"k0", 65 UNTIC_COMMENT("F0 function key")},
665 {"k1", 66 UNTIC_COMMENT("F1 function key")},
666 {"k2", 68 UNTIC_COMMENT("F2 function key")},
667 {"k3", 69 UNTIC_COMMENT("F3 function key")},
668 {"k4", 70 UNTIC_COMMENT("F4 function key")},
669 {"k5", 71 UNTIC_COMMENT("F5 function key")},
670 {"k6", 72 UNTIC_COMMENT("F6 function key")},
671 {"k7", 73 UNTIC_COMMENT("F7 function key")},
672 {"k8", 74 UNTIC_COMMENT("F8 fucntion key")},
673 {"k9", 75 UNTIC_COMMENT("F9 function key")},
674 {"k;", 67 UNTIC_COMMENT("F10 function key")},
675 {"kA", 78 UNTIC_COMMENT("insert-line key")},
676 {"kB", 148 UNTIC_COMMENT("back-tab key")},
677 {"kC", 57 UNTIC_COMMENT("clear-screen or erase key")},
678 {"kD", 59 UNTIC_COMMENT("delete-character key")},
679 {"kE", 63 UNTIC_COMMENT("clear-to-end-of-line key")},
680 {"kF", 84 UNTIC_COMMENT("scroll-forward key")},
681 {"kH", 80 UNTIC_COMMENT("last-line key")},
682 {"kI", 77 UNTIC_COMMENT("insert-character key")},
683 {"kL", 60 UNTIC_COMMENT("delete-line key")},
684 {"kM", 62 UNTIC_COMMENT("sent by rmir or smir in insert mode")},
685 {"kN", 81 UNTIC_COMMENT("next-page key")},
686 {"kP", 82 UNTIC_COMMENT("prev-page key")},
687 {"kR", 85 UNTIC_COMMENT("scroll-backward key")},
688 {"kS", 64 UNTIC_COMMENT("clear-to-end-of-screen key")},
689 {"kT", 86 UNTIC_COMMENT("set-tab key")},
690 {"ka", 56 UNTIC_COMMENT("clear-all-tabs key")},
691 {"kb", 55 UNTIC_COMMENT("backspace key")},
692 {"kd", 61 UNTIC_COMMENT("down-arrow key")},
693 {"ke", 88 UNTIC_COMMENT("leave 'keyboard_transmit' mode")},
694 {"kh", 76 UNTIC_COMMENT("home key")},
695 {"kl", 79 UNTIC_COMMENT("left-arrow key")},
696 {"ko", 396 UNTIC_COMMENT("list of self-mapped keycaps")},
697 {"kr", 83 UNTIC_COMMENT("right-arrow key")},
698 {"ks", 89 UNTIC_COMMENT("enter 'keyboard_transmit' mode")},
699 {"kt", 58 UNTIC_COMMENT("clear-tab key")},
700 {"ku", 87 UNTIC_COMMENT("up-arrow key")},
701 {"l0", 90 UNTIC_COMMENT("label on function key f0 if not f0")},
702 {"l1", 91 UNTIC_COMMENT("label on function key f1 if not f1")},
703 {"l2", 93 UNTIC_COMMENT("label on function key f2 if not f2")},
704 {"l3", 94 UNTIC_COMMENT("label on function key f3 if not f3")},
705 {"l4", 95 UNTIC_COMMENT("label on function key f4 if not f4")},
706 {"l5", 96 UNTIC_COMMENT("lable on function key f5 if not f5")},
707 {"l6", 97 UNTIC_COMMENT("label on function key f6 if not f6")},
708 {"l7", 98 UNTIC_COMMENT("label on function key f7 if not f7")},
709 {"l8", 99 UNTIC_COMMENT("label on function key f8 if not f8")},
710 {"l9", 100 UNTIC_COMMENT("label on function key f9 if not f9")},
711 {"la", 92 UNTIC_COMMENT("label on function key f10 if not f10")},
712 {"le", 14 UNTIC_COMMENT("move left one space")},
713 {"ll", 18 UNTIC_COMMENT("last line, first column (if no cup)")},
714 {"ma", 397 UNTIC_COMMENT("map arrow keys rogue(1) motion keys")},
715 {"mb", 26 UNTIC_COMMENT("turn on blinking")},
716 {"md", 27 UNTIC_COMMENT("turn on bold (extra bright) mode")},
717 {"me", 39 UNTIC_COMMENT("turn off all attributes")},
718 {"mh", 30 UNTIC_COMMENT("turn on half-bright mode")},
719 {"mk", 32 UNTIC_COMMENT("turn on blank mode (characters invisible)")},
720 {"ml", 409 UNTIC_COMMENT("memory lock above")},
721 {"mm", 102 UNTIC_COMMENT("turn on meta mode (8th-bit on)")},
722 {"mo", 101 UNTIC_COMMENT("turn off meta mode")},
723 {"mp", 33 UNTIC_COMMENT("turn on protected mode")},
724 {"mr", 34 UNTIC_COMMENT("turn on reverse video mode")},
725 {"mu", 410 UNTIC_COMMENT("memory unlock")},
726 {"nd", 17 UNTIC_COMMENT("move right one space")},
727 {"nl", 394 UNTIC_COMMENT("use to move down")},
728 {"nw", 103 UNTIC_COMMENT("newline (behave like cr followed by lf)")},
729 {"oc", 298 UNTIC_COMMENT("Set all color pairs to the original ones")},
730 {"op", 297 UNTIC_COMMENT("Set default pair to its original value")},
731 {"pO", 144 UNTIC_COMMENT("turn on printer for #1 bytes")},
732 {"pc", 104 UNTIC_COMMENT("padding char (instead of null)")},
733 {"pf", 119 UNTIC_COMMENT("turn off printer")},
734 {"pk", 115 UNTIC_COMMENT("program function key #1 to type string #2")},
735 {"pl", 116 UNTIC_COMMENT("program function key #1 to execute string #2")},
736 {"pn", 147 UNTIC_COMMENT("program label #1 to show string #2")},
737 {"po", 120 UNTIC_COMMENT("turn on printer")},
738 {"ps", 118 UNTIC_COMMENT("print contents of screen")},
739 {"px", 117 UNTIC_COMMENT("program function key #1 to transmit string #2")},
740 {"r1", 122 UNTIC_COMMENT("reset string")},
741 {"r2", 123 UNTIC_COMMENT("reset string")},
742 {"r3", 124 UNTIC_COMMENT("reset string")},
743 {"rP", 145 UNTIC_COMMENT("like ip but when in insert mode")},
744 {"rc", 126 UNTIC_COMMENT("restore cursor to last position of sc")},
745 {"rf", 125 UNTIC_COMMENT("name of reset file")},
746 {"rp", 121 UNTIC_COMMENT("repeat char #1 #2 times")},
747 {"rs", 393 UNTIC_COMMENT("terminal reset string")},
748 {"s0", 364 UNTIC_COMMENT("Shift to code set 0 (EUC set 0, ASCII)")},
749 {"s1", 365 UNTIC_COMMENT("Shift to code set 1")},
750 {"s2", 366 UNTIC_COMMENT("Shift to code set 2")},
751 {"s3", 367 UNTIC_COMMENT("Shift to code set 3")},
752 {"sa", 131 UNTIC_COMMENT("define video attributes #1-#9 (PG9)")},
753 {"sc", 128 UNTIC_COMMENT("save current cursor position")},
754 {"se", 43 UNTIC_COMMENT("exit standout mode")},
755 {"sf", 129 UNTIC_COMMENT("scroll text up")},
756 {"so", 35 UNTIC_COMMENT("begin standout mode")},
757 {"sp", 301 UNTIC_COMMENT("Set current color pair to #1")},
758 {"sr", 130 UNTIC_COMMENT("scroll text down")},
759 {"st", 132 UNTIC_COMMENT("set a tab in every row, current columns")},
760 {"ta", 134 UNTIC_COMMENT("tab to next 8-space hardware tab stop")},
761 {"te", 40 UNTIC_COMMENT("strings to end programs using cup")},
762 {"ti", 28 UNTIC_COMMENT("string to start programs using cup")},
763 {"ts", 135 UNTIC_COMMENT("move to status line")},
764 {"u0", 287 UNTIC_COMMENT("User string #0")},
765 {"u1", 288 UNTIC_COMMENT("User string #1")},
766 {"u2", 289 UNTIC_COMMENT("User string #2")},
767 {"u3", 290 UNTIC_COMMENT("User string #3")},
768 {"u4", 291 UNTIC_COMMENT("User string #4")},
769 {"u5", 292 UNTIC_COMMENT("User string #5")},
770 {"u6", 293 UNTIC_COMMENT("User string #6")},
771 {"u7", 294 UNTIC_COMMENT("User string #7")},
772 {"u8", 295 UNTIC_COMMENT("User string #8")},
773 {"u9", 296 UNTIC_COMMENT("User string #9")},
774 {"uc", 136 UNTIC_COMMENT("underline char and move past it")},
775 {"ue", 44 UNTIC_COMMENT("exit underline mode")},
776 {"up", 19 UNTIC_COMMENT("up one line")},
777 {"us", 36 UNTIC_COMMENT("begin underline mode")},
778 {"vb", 45 UNTIC_COMMENT("visible bell (may not move cursor)")},
779 {"ve", 16 UNTIC_COMMENT("make cursor appear normal (undo civis/cvvis)")},
780 {"vi", 13 UNTIC_COMMENT("make cursor invisible")},
781 {"vs", 20 UNTIC_COMMENT("make cursor very visible")},
782 {"wi", 133 UNTIC_COMMENT("current window is lines #1-#2 cols #3-#4")},
783 {"xl", 361 UNTIC_COMMENT("Program function key #1 to type string #2 and show string #3")},
784 {"", -1 UNTIC_COMMENT(NULL)}
787 static int compute_cap_offset (char *cap, SLterminfo_Type *t, Tgetstr_Map_Type *map, unsigned int max_ofs)
789 char cha, chb;
791 (void) t;
792 cha = *cap++; chb = *cap;
794 while (*map->name != 0)
796 if ((cha == *map->name) && (chb == *(map->name + 1)))
798 if (map->offset >= (int) max_ofs) return -1;
799 return map->offset;
801 map++;
803 return -1;
806 char *_pSLtt_tigetstr (SLterminfo_Type *t, char *cap)
808 int offset;
810 if (t == NULL)
811 return NULL;
813 if (t->flags == SLTERMCAP) return tcap_getstr (cap, t);
815 offset = compute_cap_offset (cap, t, Tgetstr_Map, t->num_string_offsets);
816 if (offset < 0) return NULL;
817 offset = make_integer (t->string_offsets + 2 * offset);
818 if (offset < 0) return NULL;
819 return t->string_table + offset;
822 static Tgetstr_Map_Type Tgetnum_Map[] =
824 {"BT", 30 UNTIC_COMMENT("number of buttons on mouse")},
825 {"Co", 13 UNTIC_COMMENT("maximum numbers of colors on screen")},
826 {"MW", 12 UNTIC_COMMENT("maxumum number of defineable windows")},
827 {"NC", 15 UNTIC_COMMENT("video attributes that can't be used with colors")},
828 {"Nl", 8 UNTIC_COMMENT("number of labels on screen")},
829 {"Ya", 16 UNTIC_COMMENT("numbers of bytes buffered before printing")},
830 {"Yb", 17 UNTIC_COMMENT("spacing of pins vertically in pins per inch")},
831 {"Yc", 18 UNTIC_COMMENT("spacing of dots horizontally in dots per inch")},
832 {"Yd", 19 UNTIC_COMMENT("maximum value in micro_..._address")},
833 {"Ye", 20 UNTIC_COMMENT("maximum value in parm_..._micro")},
834 {"Yf", 21 UNTIC_COMMENT("character size when in micro mode")},
835 {"Yg", 22 UNTIC_COMMENT("line size when in micro mode")},
836 {"Yh", 23 UNTIC_COMMENT("numbers of pins in print-head")},
837 {"Yi", 24 UNTIC_COMMENT("horizontal resolution in units per line")},
838 {"Yj", 25 UNTIC_COMMENT("vertical resolution in units per line")},
839 {"Yk", 26 UNTIC_COMMENT("horizontal resolution in units per inch")},
840 {"Yl", 27 UNTIC_COMMENT("vertical resolution in units per inch")},
841 {"Ym", 28 UNTIC_COMMENT("print rate in chars per second")},
842 {"Yn", 29 UNTIC_COMMENT("character step size when in double wide mode")},
843 {"Yo", 31 UNTIC_COMMENT("number of passed for each bit-image row")},
844 {"Yp", 32 UNTIC_COMMENT("type of bit-image device")},
845 {"co", 0 UNTIC_COMMENT("number of columns in aline")},
846 {"dB", 36 UNTIC_COMMENT("padding required for ^H")},
847 {"dC", 34 UNTIC_COMMENT("pad needed for CR")},
848 {"dN", 35 UNTIC_COMMENT("pad needed for LF")},
849 {"dT", 37 UNTIC_COMMENT("padding required for ^I")},
850 {"it", 1 UNTIC_COMMENT("tabs initially every # spaces")},
851 {"kn", 38 UNTIC_COMMENT("count of function keys")},
852 {"lh", 9 UNTIC_COMMENT("rows in each label")},
853 {"li", 2 UNTIC_COMMENT("number of lines on screen or page")},
854 {"lm", 3 UNTIC_COMMENT("lines of memory if > line. 0 => varies")},
855 {"lw", 10 UNTIC_COMMENT("columns in each label")},
856 {"ma", 11 UNTIC_COMMENT("maximum combined attributes terminal can handle")},
857 {"pa", 14 UNTIC_COMMENT("maximum number of color-pairs on the screen")},
858 {"pb", 5 UNTIC_COMMENT("lowest baud rate where padding needed")},
859 {"sg", 4 UNTIC_COMMENT("number of blank chars left by smso or rmso")},
860 {"ug", 33 UNTIC_COMMENT("number of blanks left by ul")},
861 {"vt", 6 UNTIC_COMMENT("virtual terminal number (CB/unix)")},
862 {"ws", 7 UNTIC_COMMENT("columns in status line")},
863 {"", -1 UNTIC_COMMENT(NULL)}
866 int _pSLtt_tigetnum (SLterminfo_Type *t, char *cap)
868 int offset;
870 if (t == NULL)
871 return -1;
873 if (t->flags == SLTERMCAP) return tcap_getnum (cap, t);
875 offset = compute_cap_offset (cap, t, Tgetnum_Map, t->num_numbers);
876 if (offset < 0) return -1;
877 return make_integer (t->numbers + 2 * offset);
880 static Tgetstr_Map_Type Tgetflag_Map[] =
882 {"5i", 22 UNTIC_COMMENT("printer won't echo on screen")},
883 {"HC", 23 UNTIC_COMMENT("cursor is hard to see")},
884 {"MT", 40 UNTIC_COMMENT("has meta key")},
885 {"ND", 26 UNTIC_COMMENT("scrolling region is non-destructive")},
886 {"NL", 41 UNTIC_COMMENT("move down with \n")},
887 {"NP", 25 UNTIC_COMMENT("pad character does not exist")},
888 {"NR", 24 UNTIC_COMMENT("smcup does not reverse rmcup")},
889 {"YA", 30 UNTIC_COMMENT("only positive motion for hpa/mhpa caps")},
890 {"YB", 31 UNTIC_COMMENT("using cr turns off micro mode")},
891 {"YC", 32 UNTIC_COMMENT("printer needs operator to change character set")},
892 {"YD", 33 UNTIC_COMMENT("only positive motion for vpa/mvpa caps")},
893 {"YE", 34 UNTIC_COMMENT("printing in last column causes cr")},
894 {"YF", 35 UNTIC_COMMENT("changing character pitch changes resolution")},
895 {"YG", 36 UNTIC_COMMENT("changing line pitch changes resolution")},
896 {"am", 1 UNTIC_COMMENT("terminal has automatic margins")},
897 {"bs", 37 UNTIC_COMMENT("uses ^H to move left")},
898 {"bw", 0 UNTIC_COMMENT("cub1 wraps from column 0 to last column")},
899 {"cc", 27 UNTIC_COMMENT("terminal can re-define existing colors")},
900 {"da", 11 UNTIC_COMMENT("display may be retained above the screen")},
901 {"db", 12 UNTIC_COMMENT("display may be retained below the screen")},
902 {"eo", 5 UNTIC_COMMENT("can erase overstrikes with a blank")},
903 {"es", 16 UNTIC_COMMENT("escape can be used on the status line")},
904 {"gn", 6 UNTIC_COMMENT("generic line type")},
905 {"hc", 7 UNTIC_COMMENT("hardcopy terminal")},
906 {"hl", 29 UNTIC_COMMENT("terminal uses only HLS color notation (tektronix)")},
907 {"hs", 9 UNTIC_COMMENT("has extra status line")},
908 {"hz", 18 UNTIC_COMMENT("can't print ~'s (hazeltine)")},
909 {"in", 10 UNTIC_COMMENT("insert mode distinguishes nulls")},
910 {"km", 8 UNTIC_COMMENT("Has a meta key, sets msb high")},
911 {"mi", 13 UNTIC_COMMENT("safe to move while in insert mode")},
912 {"ms", 14 UNTIC_COMMENT("safe to move while in standout mode")},
913 {"nc", 39 UNTIC_COMMENT("no way to go to start of line")},
914 {"ns", 38 UNTIC_COMMENT("crt cannot scroll")},
915 {"nx", 21 UNTIC_COMMENT("padding won't work, xon/xoff required")},
916 {"os", 15 UNTIC_COMMENT("terminal can overstrike")},
917 {"pt", 42 UNTIC_COMMENT("has 8-char tabs invoked with ^I")},
918 {"ul", 19 UNTIC_COMMENT("underline character overstrikes")},
919 {"ut", 28 UNTIC_COMMENT("screen erased with background color")},
920 {"xb", 2 UNTIC_COMMENT("beehive (f1=escape, f2=ctrl C)")},
921 {"xn", 4 UNTIC_COMMENT("newline ignored after 80 cols (concept)")},
922 {"xo", 20 UNTIC_COMMENT("terminal uses xon/xoff handshaking")},
923 {"xr", 43 UNTIC_COMMENT("return clears the line")},
924 {"xs", 3 UNTIC_COMMENT("standout not erased by overwriting (hp)")},
925 {"xt", 17 UNTIC_COMMENT("tabs destructive, magic so char (t1061)")},
926 {"", -1 UNTIC_COMMENT(NULL)}
929 int _pSLtt_tigetflag (SLterminfo_Type *t, char *cap)
931 int offset;
933 if (t == NULL) return -1;
935 if (t->flags == SLTERMCAP) return tcap_getflag (cap, t);
937 offset = compute_cap_offset (cap, t, Tgetflag_Map, t->boolean_section_size);
939 if (offset < 0) return -1;
940 return (int) *(t->boolean_flags + offset);
943 /* These are my termcap routines. They only work with the TERMCAP environment
944 * variable. This variable must contain the termcap entry and NOT the file.
947 static int tcap_getflag (char *cap, SLterminfo_Type *t)
949 char a, b;
950 char *f = (char *) t->boolean_flags;
951 char *fmax;
953 if (f == NULL) return 0;
954 fmax = f + t->boolean_section_size;
956 a = *cap;
957 b = *(cap + 1);
958 while (f < fmax)
960 if ((a == f[0]) && (b == f[1]))
961 return 1;
962 f += 2;
964 return 0;
967 static char *tcap_get_cap (unsigned char *cap, unsigned char *caps, unsigned int len)
969 unsigned char c0, c1;
970 unsigned char *caps_max;
972 c0 = cap[0];
973 c1 = cap[1];
975 if (caps == NULL) return NULL;
976 caps_max = caps + len;
977 while (caps < caps_max)
979 if ((c0 == caps[0]) && (c1 == caps[1]))
981 return (char *) caps + 3;
983 caps += (int) caps[2];
985 return NULL;
988 static int tcap_getnum (char *cap, SLterminfo_Type *t)
990 cap = tcap_get_cap ((unsigned char *) cap, t->numbers, t->num_numbers);
991 if (cap == NULL) return -1;
992 return atoi (cap);
995 static char *tcap_getstr (char *cap, SLterminfo_Type *t)
997 return tcap_get_cap ((unsigned char *) cap, (unsigned char *) t->string_table, t->string_table_size);
1000 static int tcap_extract_field (unsigned char *t0)
1002 register unsigned char ch, *t = t0;
1003 while (((ch = *t) != 0) && (ch != ':')) t++;
1004 if (ch == ':') return (int) (t - t0);
1005 return -1;
1008 int SLtt_Try_Termcap = 1;
1009 static int tcap_getent (char *term, SLterminfo_Type *ti)
1011 unsigned char *termcap, ch;
1012 unsigned char *buf, *b;
1013 unsigned char *t;
1014 int len;
1016 if (SLtt_Try_Termcap == 0) return -1;
1017 #if 1
1018 /* XFREE86 xterm sets the TERMCAP environment variable to an invalid
1019 * value. Specifically, it lacks the tc= string.
1021 if (!strncmp (term, "xterm", 5))
1022 return -1;
1023 #endif
1024 termcap = (unsigned char *) getenv ("TERMCAP");
1025 if ((termcap == NULL) || (*termcap == '/')) return -1;
1027 /* SUN Solaris 7&8 have bug in tset program under tcsh,
1028 * eval `tset -s -A -Q` sets value of TERMCAP to ":",
1029 * under other shells it works fine.
1030 * SUN was informed, they marked it as duplicate of bug 4086585
1031 * but didn't care to fix it... <mikkopa@cs.tut.fi>
1033 if ((termcap[0] == ':') && (termcap[1] == 0))
1034 return -1;
1037 /* We have a termcap so lets use it provided it does not have a reference
1038 * to another terminal via tc=. In that case, use terminfo. The alternative
1039 * would be to parse the termcap file which I do not want to do right now.
1040 * Besides, this is a terminfo based system and if the termcap were parsed
1041 * terminfo would almost never get a chance to run. In addition, the tc=
1042 * thing should not occur if tset is used to set the termcap entry.
1044 t = termcap;
1045 while ((len = tcap_extract_field (t)) != -1)
1047 if ((len > 3) && (t[0] == 't') && (t[1] == 'c') && (t[2] == '='))
1048 return -1;
1049 t += (len + 1);
1052 /* malloc some extra space just in case it is needed. */
1053 len = strlen ((char *) termcap) + 256;
1054 if (NULL == (buf = (unsigned char *) SLmalloc ((unsigned int) len)))
1055 return -1;
1057 b = buf;
1059 /* The beginning of the termcap entry contains the names of the entry.
1060 * It is terminated by a colon.
1063 ti->terminal_names = (char *) b;
1064 t = termcap;
1065 len = tcap_extract_field (t);
1066 if (len < 0)
1068 SLfree ((char *)buf);
1069 return -1;
1071 strncpy ((char *) b, (char *) t, (unsigned int) len);
1072 b[len] = 0;
1073 b += len + 1;
1074 ti->name_section_size = len;
1076 /* Now, we are really at the start of the termcap entries. Point the
1077 * termcap variable here since we want to refer to this a number of times.
1079 termcap = t + (len + 1);
1081 /* Process strings first. */
1082 ti->string_table = (char *) b;
1083 t = termcap;
1084 while (-1 != (len = tcap_extract_field (t)))
1086 unsigned char *b1;
1087 unsigned char *tmax;
1089 /* We are looking for: XX=something */
1090 if ((len < 4) || (t[2] != '=') || (*t == '.'))
1092 t += len + 1;
1093 continue;
1095 tmax = t + len;
1096 b1 = b;
1098 while (t < tmax)
1100 ch = *t++;
1101 if ((ch == '\\') && (t < tmax))
1103 SLwchar_Type wch;
1105 t = (unsigned char *) _pSLexpand_escaped_char ((char *) t, &wch, NULL);
1106 if (t == NULL)
1108 SLfree ((char *)buf);
1109 return -1;
1111 ch = (char) wch;
1113 else if ((ch == '^') && (t < tmax))
1115 ch = *t++;
1116 if (ch == '?') ch = 127;
1117 else ch = (ch | 0x20) - ('a' - 1);
1119 *b++ = ch;
1121 /* Null terminate it. */
1122 *b++ = 0;
1123 len = (int) (b - b1);
1124 b1[2] = (unsigned char) len; /* replace the = by the length */
1125 /* skip colon to next field. */
1126 t++;
1128 ti->string_table_size = (int) (b - (unsigned char *) ti->string_table);
1130 /* Now process the numbers. */
1132 t = termcap;
1133 ti->numbers = b;
1134 while (-1 != (len = tcap_extract_field (t)))
1136 unsigned char *b1;
1137 unsigned char *tmax;
1139 /* We are looking for: XX#NUMBER */
1140 if ((len < 4) || (t[2] != '#') || (*t == '.'))
1142 t += len + 1;
1143 continue;
1145 tmax = t + len;
1146 b1 = b;
1148 while (t < tmax)
1150 *b++ = *t++;
1152 /* Null terminate it. */
1153 *b++ = 0;
1154 len = (int) (b - b1);
1155 b1[2] = (unsigned char) len; /* replace the # by the length */
1156 t++;
1158 ti->num_numbers = (int) (b - ti->numbers);
1160 /* Now process the flags. */
1161 t = termcap;
1162 ti->boolean_flags = b;
1163 while (-1 != (len = tcap_extract_field (t)))
1165 /* We are looking for: XX#NUMBER */
1166 if ((len != 2) || (*t == '.') || (*t <= ' '))
1168 t += len + 1;
1169 continue;
1171 b[0] = t[0];
1172 b[1] = t[1];
1173 t += 3;
1174 b += 2;
1176 ti->boolean_section_size = (int) (b - ti->boolean_flags);
1177 ti->flags = SLTERMCAP;
1178 return 0;
1182 /* These routines are provided only for backward binary compatability.
1183 * They will vanish in V2.x
1185 char *SLtt_tigetent (char *s)
1187 return (char *) _pSLtt_tigetent (s);
1190 extern char *SLtt_tigetstr (char *s, char **p)
1192 if (p == NULL)
1193 return NULL;
1194 return _pSLtt_tigetstr ((SLterminfo_Type *) *p, s);
1197 extern int SLtt_tigetnum (char *s, char **p)
1199 if (p == NULL)
1200 return -1;
1201 return _pSLtt_tigetnum ((SLterminfo_Type *) *p, s);