sltermin.c 45 KB

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