sltermin.c 46 KB

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