sltermin.c 45 KB

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