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