Annotation of src/usr.bin/tmux/tty-term.c, Revision 1.24
1.24 ! nicm 1: /* $OpenBSD: tty-term.c,v 1.23 2011/05/18 20:24:29 nicm Exp $ */
1.1 nicm 2:
3: /*
4: * Copyright (c) 2008 Nicholas Marriott <nicm@users.sourceforge.net>
5: *
6: * Permission to use, copy, modify, and distribute this software for any
7: * purpose with or without fee is hereby granted, provided that the above
8: * copyright notice and this permission notice appear in all copies.
9: *
10: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14: * WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
15: * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
16: * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17: */
18:
19: #include <sys/types.h>
20:
1.3 nicm 21: #include <curses.h>
1.5 nicm 22: #include <fnmatch.h>
23: #include <stdlib.h>
1.1 nicm 24: #include <string.h>
25: #include <term.h>
1.5 nicm 26: #include <vis.h>
1.1 nicm 27:
28: #include "tmux.h"
29:
1.5 nicm 30: void tty_term_override(struct tty_term *, const char *);
1.1 nicm 31: char *tty_term_strip(const char *);
32:
1.20 nicm 33: struct tty_terms tty_terms = LIST_HEAD_INITIALIZER(tty_terms);
1.1 nicm 34:
1.19 nicm 35: const struct tty_term_code_entry tty_term_codes[NTTYCODE] = {
1.13 nicm 36: { TTYC_ACSC, TTYCODE_STRING, "acsc" },
1.1 nicm 37: { TTYC_AX, TTYCODE_FLAG, "AX" },
38: { TTYC_BEL, TTYCODE_STRING, "bel" },
39: { TTYC_BLINK, TTYCODE_STRING, "blink" },
40: { TTYC_BOLD, TTYCODE_STRING, "bold" },
1.24 ! nicm 41: { TTYC_CC, TTYCODE_STRING, "Cc" },
1.1 nicm 42: { TTYC_CIVIS, TTYCODE_STRING, "civis" },
43: { TTYC_CLEAR, TTYCODE_STRING, "clear" },
44: { TTYC_CNORM, TTYCODE_STRING, "cnorm" },
45: { TTYC_COLORS, TTYCODE_NUMBER, "colors" },
1.24 ! nicm 46: { TTYC_CR, TTYCODE_STRING, "Cr" },
1.1 nicm 47: { TTYC_CSR, TTYCODE_STRING, "csr" },
1.10 nicm 48: { TTYC_CUB, TTYCODE_STRING, "cub" },
49: { TTYC_CUB1, TTYCODE_STRING, "cub1" },
1.1 nicm 50: { TTYC_CUD, TTYCODE_STRING, "cud" },
51: { TTYC_CUD1, TTYCODE_STRING, "cud1" },
1.10 nicm 52: { TTYC_CUF, TTYCODE_STRING, "cuf" },
53: { TTYC_CUF1, TTYCODE_STRING, "cuf1" },
1.1 nicm 54: { TTYC_CUP, TTYCODE_STRING, "cup" },
1.10 nicm 55: { TTYC_CUU, TTYCODE_STRING, "cuu" },
56: { TTYC_CUU1, TTYCODE_STRING, "cuu1" },
1.1 nicm 57: { TTYC_DCH, TTYCODE_STRING, "dch" },
58: { TTYC_DCH1, TTYCODE_STRING, "dch1" },
59: { TTYC_DIM, TTYCODE_STRING, "dim" },
60: { TTYC_DL, TTYCODE_STRING, "dl" },
61: { TTYC_DL1, TTYCODE_STRING, "dl1" },
62: { TTYC_EL, TTYCODE_STRING, "el" },
63: { TTYC_EL1, TTYCODE_STRING, "el1" },
64: { TTYC_ENACS, TTYCODE_STRING, "enacs" },
1.22 nicm 65: { TTYC_FSL, TTYCODE_STRING, "fsl" },
1.10 nicm 66: { TTYC_HOME, TTYCODE_STRING, "home" },
67: { TTYC_HPA, TTYCODE_STRING, "hpa" },
1.1 nicm 68: { TTYC_ICH, TTYCODE_STRING, "ich" },
69: { TTYC_ICH1, TTYCODE_STRING, "ich1" },
70: { TTYC_IL, TTYCODE_STRING, "il" },
71: { TTYC_IL1, TTYCODE_STRING, "il1" },
72: { TTYC_INVIS, TTYCODE_STRING, "invis" },
73: { TTYC_IS1, TTYCODE_STRING, "is1" },
74: { TTYC_IS2, TTYCODE_STRING, "is2" },
75: { TTYC_IS3, TTYCODE_STRING, "is3" },
76: { TTYC_KCBT, TTYCODE_STRING, "kcbt" },
77: { TTYC_KCUB1, TTYCODE_STRING, "kcub1" },
78: { TTYC_KCUD1, TTYCODE_STRING, "kcud1" },
79: { TTYC_KCUF1, TTYCODE_STRING, "kcuf1" },
80: { TTYC_KCUU1, TTYCODE_STRING, "kcuu1" },
1.13 nicm 81: { TTYC_KDC2, TTYCODE_STRING, "kDC" },
82: { TTYC_KDC3, TTYCODE_STRING, "kDC3" },
83: { TTYC_KDC4, TTYCODE_STRING, "kDC4" },
84: { TTYC_KDC5, TTYCODE_STRING, "kDC5" },
85: { TTYC_KDC6, TTYCODE_STRING, "kDC6" },
86: { TTYC_KDC7, TTYCODE_STRING, "kDC7" },
1.1 nicm 87: { TTYC_KDCH1, TTYCODE_STRING, "kdch1" },
1.13 nicm 88: { TTYC_KDN2, TTYCODE_STRING, "kDN" },
89: { TTYC_KDN3, TTYCODE_STRING, "kDN3" },
90: { TTYC_KDN4, TTYCODE_STRING, "kDN4" },
91: { TTYC_KDN5, TTYCODE_STRING, "kDN5" },
92: { TTYC_KDN6, TTYCODE_STRING, "kDN6" },
93: { TTYC_KDN7, TTYCODE_STRING, "kDN7" },
1.1 nicm 94: { TTYC_KEND, TTYCODE_STRING, "kend" },
1.13 nicm 95: { TTYC_KEND2, TTYCODE_STRING, "kEND" },
96: { TTYC_KEND3, TTYCODE_STRING, "kEND3" },
97: { TTYC_KEND4, TTYCODE_STRING, "kEND4" },
98: { TTYC_KEND5, TTYCODE_STRING, "kEND5" },
99: { TTYC_KEND6, TTYCODE_STRING, "kEND6" },
100: { TTYC_KEND7, TTYCODE_STRING, "kEND7" },
1.1 nicm 101: { TTYC_KF1, TTYCODE_STRING, "kf1" },
102: { TTYC_KF10, TTYCODE_STRING, "kf10" },
103: { TTYC_KF11, TTYCODE_STRING, "kf11" },
104: { TTYC_KF12, TTYCODE_STRING, "kf12" },
105: { TTYC_KF13, TTYCODE_STRING, "kf13" },
106: { TTYC_KF14, TTYCODE_STRING, "kf14" },
107: { TTYC_KF15, TTYCODE_STRING, "kf15" },
108: { TTYC_KF16, TTYCODE_STRING, "kf16" },
109: { TTYC_KF17, TTYCODE_STRING, "kf17" },
110: { TTYC_KF18, TTYCODE_STRING, "kf18" },
111: { TTYC_KF19, TTYCODE_STRING, "kf19" },
1.10 nicm 112: { TTYC_KF2, TTYCODE_STRING, "kf2" },
1.1 nicm 113: { TTYC_KF20, TTYCODE_STRING, "kf20" },
114: { TTYC_KF3, TTYCODE_STRING, "kf3" },
115: { TTYC_KF4, TTYCODE_STRING, "kf4" },
116: { TTYC_KF5, TTYCODE_STRING, "kf5" },
117: { TTYC_KF6, TTYCODE_STRING, "kf6" },
118: { TTYC_KF7, TTYCODE_STRING, "kf7" },
119: { TTYC_KF8, TTYCODE_STRING, "kf8" },
120: { TTYC_KF9, TTYCODE_STRING, "kf9" },
1.13 nicm 121: { TTYC_KHOM2, TTYCODE_STRING, "kHOM" },
122: { TTYC_KHOM3, TTYCODE_STRING, "kHOM3" },
123: { TTYC_KHOM4, TTYCODE_STRING, "kHOM4" },
124: { TTYC_KHOM5, TTYCODE_STRING, "kHOM5" },
125: { TTYC_KHOM6, TTYCODE_STRING, "kHOM6" },
126: { TTYC_KHOM7, TTYCODE_STRING, "kHOM7" },
1.1 nicm 127: { TTYC_KHOME, TTYCODE_STRING, "khome" },
1.13 nicm 128: { TTYC_KIC2, TTYCODE_STRING, "kIC" },
129: { TTYC_KIC3, TTYCODE_STRING, "kIC3" },
130: { TTYC_KIC4, TTYCODE_STRING, "kIC4" },
131: { TTYC_KIC5, TTYCODE_STRING, "kIC5" },
132: { TTYC_KIC6, TTYCODE_STRING, "kIC6" },
133: { TTYC_KIC7, TTYCODE_STRING, "kIC7" },
1.1 nicm 134: { TTYC_KICH1, TTYCODE_STRING, "kich1" },
1.13 nicm 135: { TTYC_KLFT2, TTYCODE_STRING, "kLFT" },
136: { TTYC_KLFT3, TTYCODE_STRING, "kLFT3" },
137: { TTYC_KLFT4, TTYCODE_STRING, "kLFT4" },
138: { TTYC_KLFT5, TTYCODE_STRING, "kLFT5" },
139: { TTYC_KLFT6, TTYCODE_STRING, "kLFT6" },
140: { TTYC_KLFT7, TTYCODE_STRING, "kLFT7" },
1.1 nicm 141: { TTYC_KMOUS, TTYCODE_STRING, "kmous" },
142: { TTYC_KNP, TTYCODE_STRING, "knp" },
1.13 nicm 143: { TTYC_KNXT2, TTYCODE_STRING, "kNXT" },
144: { TTYC_KNXT3, TTYCODE_STRING, "kNXT3" },
145: { TTYC_KNXT4, TTYCODE_STRING, "kNXT4" },
146: { TTYC_KNXT5, TTYCODE_STRING, "kNXT5" },
147: { TTYC_KNXT6, TTYCODE_STRING, "kNXT6" },
148: { TTYC_KNXT7, TTYCODE_STRING, "kNXT7" },
1.1 nicm 149: { TTYC_KPP, TTYCODE_STRING, "kpp" },
1.13 nicm 150: { TTYC_KPRV2, TTYCODE_STRING, "kPRV" },
151: { TTYC_KPRV3, TTYCODE_STRING, "kPRV3" },
152: { TTYC_KPRV4, TTYCODE_STRING, "kPRV4" },
153: { TTYC_KPRV5, TTYCODE_STRING, "kPRV5" },
154: { TTYC_KPRV6, TTYCODE_STRING, "kPRV6" },
155: { TTYC_KPRV7, TTYCODE_STRING, "kPRV7" },
156: { TTYC_KRIT2, TTYCODE_STRING, "kRIT" },
157: { TTYC_KRIT3, TTYCODE_STRING, "kRIT3" },
158: { TTYC_KRIT4, TTYCODE_STRING, "kRIT4" },
159: { TTYC_KRIT5, TTYCODE_STRING, "kRIT5" },
160: { TTYC_KRIT6, TTYCODE_STRING, "kRIT6" },
161: { TTYC_KRIT7, TTYCODE_STRING, "kRIT7" },
162: { TTYC_KUP2, TTYCODE_STRING, "kUP" },
163: { TTYC_KUP3, TTYCODE_STRING, "kUP3" },
164: { TTYC_KUP4, TTYCODE_STRING, "kUP4" },
165: { TTYC_KUP5, TTYCODE_STRING, "kUP5" },
166: { TTYC_KUP6, TTYCODE_STRING, "kUP6" },
167: { TTYC_KUP7, TTYCODE_STRING, "kUP7" },
1.23 nicm 168: { TTYC_MS, TTYCODE_STRING, "Ms" },
1.1 nicm 169: { TTYC_OP, TTYCODE_STRING, "op" },
170: { TTYC_REV, TTYCODE_STRING, "rev" },
171: { TTYC_RI, TTYCODE_STRING, "ri" },
172: { TTYC_RMACS, TTYCODE_STRING, "rmacs" },
173: { TTYC_RMCUP, TTYCODE_STRING, "rmcup" },
174: { TTYC_RMIR, TTYCODE_STRING, "rmir" },
175: { TTYC_RMKX, TTYCODE_STRING, "rmkx" },
176: { TTYC_SETAB, TTYCODE_STRING, "setab" },
177: { TTYC_SETAF, TTYCODE_STRING, "setaf" },
178: { TTYC_SGR0, TTYCODE_STRING, "sgr0" },
1.22 nicm 179: { TTYC_SITM, TTYCODE_STRING, "sitm" },
1.1 nicm 180: { TTYC_SMACS, TTYCODE_STRING, "smacs" },
181: { TTYC_SMCUP, TTYCODE_STRING, "smcup" },
182: { TTYC_SMIR, TTYCODE_STRING, "smir" },
183: { TTYC_SMKX, TTYCODE_STRING, "smkx" },
184: { TTYC_SMSO, TTYCODE_STRING, "smso" },
185: { TTYC_SMUL, TTYCODE_STRING, "smul" },
1.22 nicm 186: { TTYC_TSL, TTYCODE_STRING, "tsl" },
1.10 nicm 187: { TTYC_VPA, TTYCODE_STRING, "vpa" },
1.1 nicm 188: { TTYC_XENL, TTYCODE_FLAG, "xenl" },
1.22 nicm 189: { TTYC_XT, TTYCODE_FLAG, "XT" },
1.1 nicm 190: };
191:
192: char *
193: tty_term_strip(const char *s)
194: {
195: const char *ptr;
196: static char buf[BUFSIZ];
197: size_t len;
198:
199: /* Ignore strings with no padding. */
200: if (strchr(s, '$') == NULL)
201: return (xstrdup(s));
202:
203: len = 0;
204: for (ptr = s; *ptr != '\0'; ptr++) {
205: if (*ptr == '$' && *(ptr + 1) == '<') {
206: while (*ptr != '\0' && *ptr != '>')
207: ptr++;
208: if (*ptr == '>')
209: ptr++;
210: }
211:
212: buf[len++] = *ptr;
213: if (len == (sizeof buf) - 1)
214: break;
215: }
216: buf[len] = '\0';
217:
218: return (xstrdup(buf));
219: }
220:
221: void
1.5 nicm 222: tty_term_override(struct tty_term *term, const char *overrides)
1.1 nicm 223: {
1.19 nicm 224: const struct tty_term_code_entry *ent;
225: struct tty_code *code;
226: char *termnext, *termstr;
227: char *entnext, *entstr;
228: char *s, *ptr, *val;
229: const char *errstr;
230: u_int i;
231: int n, removeflag;
1.5 nicm 232:
233: s = xstrdup(overrides);
234:
235: termnext = s;
236: while ((termstr = strsep(&termnext, ",")) != NULL) {
237: entnext = termstr;
1.16 nicm 238:
1.5 nicm 239: entstr = strsep(&entnext, ":");
240: if (entstr == NULL || entnext == NULL)
241: continue;
242: if (fnmatch(entstr, term->name, 0) != 0)
243: continue;
244: while ((entstr = strsep(&entnext, ":")) != NULL) {
245: if (*entstr == '\0')
246: continue;
247:
248: val = NULL;
249: removeflag = 0;
1.16 nicm 250: if ((ptr = strchr(entstr, '=')) != NULL) {
1.5 nicm 251: *ptr++ = '\0';
252: val = xstrdup(ptr);
1.9 nicm 253: if (strunvis(val, ptr) == -1) {
1.5 nicm 254: xfree(val);
255: val = xstrdup(ptr);
256: }
257: } else if (entstr[strlen(entstr) - 1] == '@') {
258: entstr[strlen(entstr) - 1] = '\0';
259: removeflag = 1;
1.17 nicm 260: } else
1.22 nicm 261: val = xstrdup("");
1.5 nicm 262:
263: for (i = 0; i < NTTYCODE; i++) {
264: ent = &tty_term_codes[i];
265: if (strcmp(entstr, ent->name) != 0)
266: continue;
267: code = &term->codes[ent->code];
268:
269: if (removeflag) {
270: code->type = TTYCODE_NONE;
271: continue;
272: }
273: switch (ent->type) {
274: case TTYCODE_NONE:
275: break;
276: case TTYCODE_STRING:
1.6 nicm 277: if (code->type == TTYCODE_STRING)
278: xfree(code->value.string);
1.5 nicm 279: code->value.string = xstrdup(val);
280: code->type = ent->type;
281: break;
282: case TTYCODE_NUMBER:
283: n = strtonum(val, 0, INT_MAX, &errstr);
284: if (errstr != NULL)
285: break;
286: code->value.number = n;
287: code->type = ent->type;
288: break;
289: case TTYCODE_FLAG:
290: code->value.flag = 1;
291: code->type = ent->type;
292: break;
293: }
294: }
295:
296: if (val != NULL)
297: xfree(val);
1.1 nicm 298: }
299: }
300:
1.5 nicm 301: xfree(s);
1.1 nicm 302: }
303:
304: struct tty_term *
1.5 nicm 305: tty_term_find(char *name, int fd, const char *overrides, char **cause)
1.1 nicm 306: {
1.19 nicm 307: struct tty_term *term;
308: const struct tty_term_code_entry *ent;
309: struct tty_code *code;
310: u_int i;
311: int n, error;
312: char *s;
313: const char *acs;
1.1 nicm 314:
1.20 nicm 315: LIST_FOREACH(term, &tty_terms, entry) {
1.1 nicm 316: if (strcmp(term->name, name) == 0) {
317: term->references++;
318: return (term);
319: }
320: }
321:
322: log_debug("new term: %s", name);
323: term = xmalloc(sizeof *term);
324: term->name = xstrdup(name);
325: term->references = 1;
326: term->flags = 0;
1.18 nicm 327: memset(term->codes, 0, sizeof term->codes);
1.20 nicm 328: LIST_INSERT_HEAD(&tty_terms, term, entry);
1.1 nicm 329:
1.3 nicm 330: /* Set up curses terminal. */
1.1 nicm 331: if (setupterm(name, fd, &error) != OK) {
332: switch (error) {
1.4 matthieu 333: case 1:
1.16 nicm 334: xasprintf(
335: cause, "can't use hardcopy terminal: %s", name);
1.4 matthieu 336: break;
1.1 nicm 337: case 0:
1.16 nicm 338: xasprintf(
339: cause, "missing or unsuitable terminal: %s", name);
1.1 nicm 340: break;
1.4 matthieu 341: case -1:
1.1 nicm 342: xasprintf(cause, "can't find terminfo database");
343: break;
344: default:
345: xasprintf(cause, "unknown error");
346: break;
347: }
348: goto error;
349: }
350:
351: /* Fill in codes. */
352: for (i = 0; i < NTTYCODE; i++) {
353: ent = &tty_term_codes[i];
354:
355: code = &term->codes[ent->code];
356: code->type = TTYCODE_NONE;
357: switch (ent->type) {
358: case TTYCODE_NONE:
359: break;
360: case TTYCODE_STRING:
361: s = tigetstr((char *) ent->name);
362: if (s == NULL || s == (char *) -1)
363: break;
364: code->type = TTYCODE_STRING;
365: code->value.string = tty_term_strip(s);
366: break;
367: case TTYCODE_NUMBER:
368: n = tigetnum((char *) ent->name);
369: if (n == -1 || n == -2)
370: break;
371: code->type = TTYCODE_NUMBER;
372: code->value.number = n;
373: break;
374: case TTYCODE_FLAG:
375: n = tigetflag((char *) ent->name);
376: if (n == -1)
377: break;
378: code->type = TTYCODE_FLAG;
379: code->value.number = n;
380: break;
381: }
382: }
1.5 nicm 383: tty_term_override(term, overrides);
1.1 nicm 384:
1.3 nicm 385: /* Delete curses data. */
1.1 nicm 386: del_curterm(cur_term);
387:
388: /* These are always required. */
389: if (!tty_term_has(term, TTYC_CLEAR)) {
390: xasprintf(cause, "terminal does not support clear");
391: goto error;
392: }
393: if (!tty_term_has(term, TTYC_CUP)) {
394: xasprintf(cause, "terminal does not support cup");
395: goto error;
396: }
397:
398: /* These can be emulated so one of the two is required. */
399: if (!tty_term_has(term, TTYC_CUD1) && !tty_term_has(term, TTYC_CUD)) {
400: xasprintf(cause, "terminal does not support cud1 or cud");
401: goto error;
402: }
403:
1.11 nicm 404: /* Figure out if we have 256 or 88 colours. */
1.1 nicm 405: if (tty_term_number(term, TTYC_COLORS) == 256)
406: term->flags |= TERM_256COLOURS;
407: if (tty_term_number(term, TTYC_COLORS) == 88)
408: term->flags |= TERM_88COLOURS;
409:
410: /*
411: * Terminals without xenl (eat newline glitch) wrap at at $COLUMNS - 1
412: * rather than $COLUMNS (the cursor can never be beyond $COLUMNS - 1).
413: *
414: * This is irritating, most notably because it is impossible to write
415: * to the very bottom-right of the screen without scrolling.
416: *
417: * Flag the terminal here and apply some workarounds in other places to
418: * do the best possible.
419: */
420: if (!tty_term_flag(term, TTYC_XENL))
421: term->flags |= TERM_EARLYWRAP;
1.18 nicm 422:
423: /* Generate ACS table. If none is present, use nearest ASCII. */
424: memset(term->acs, 0, sizeof term->acs);
425: if (tty_term_has(term, TTYC_ACSC))
426: acs = tty_term_string(term, TTYC_ACSC);
427: else
428: acs = "a#j+k+l+m+n+o-p-q-r-s-t+u+v+w+x|y<z>~.";
429: for (; acs[0] != '\0' && acs[1] != '\0'; acs += 2)
430: term->acs[(u_char) acs[0]][0] = acs[1];
1.22 nicm 431:
432: /* On terminals with xterm titles (XT), fill in tsl and fsl. */
433: if (tty_term_flag(term, TTYC_XT) &&
434: !tty_term_has(term, TTYC_TSL) &&
435: !tty_term_has(term, TTYC_FSL)) {
436: code = &term->codes[TTYC_TSL];
437: code->value.string = xstrdup("\033]0;");
438: code->type = TTYCODE_STRING;
439: code = &term->codes[TTYC_FSL];
440: code->value.string = xstrdup("\007");
441: code->type = TTYCODE_STRING;
442: }
1.1 nicm 443:
444: return (term);
445:
446: error:
447: tty_term_free(term);
448: return (NULL);
449: }
450:
451: void
452: tty_term_free(struct tty_term *term)
453: {
454: u_int i;
455:
456: if (--term->references != 0)
457: return;
458:
1.20 nicm 459: LIST_REMOVE(term, entry);
1.1 nicm 460:
461: for (i = 0; i < NTTYCODE; i++) {
462: if (term->codes[i].type == TTYCODE_STRING)
463: xfree(term->codes[i].value.string);
464: }
465: xfree(term->name);
466: xfree(term);
467: }
468:
469: int
470: tty_term_has(struct tty_term *term, enum tty_code_code code)
471: {
472: return (term->codes[code].type != TTYCODE_NONE);
473: }
474:
475: const char *
476: tty_term_string(struct tty_term *term, enum tty_code_code code)
477: {
478: if (!tty_term_has(term, code))
479: return ("");
480: if (term->codes[code].type != TTYCODE_STRING)
481: log_fatalx("not a string: %d", code);
482: return (term->codes[code].value.string);
483: }
484:
1.3 nicm 485: /* No vtparm. Fucking curses. */
1.1 nicm 486: const char *
487: tty_term_string1(struct tty_term *term, enum tty_code_code code, int a)
488: {
489: return (tparm((char *) tty_term_string(term, code), a));
490: }
491:
492: const char *
493: tty_term_string2(struct tty_term *term, enum tty_code_code code, int a, int b)
1.23 nicm 494: {
495: return (tparm((char *) tty_term_string(term, code), a, b));
1.24 ! nicm 496: }
! 497:
! 498: const char *
! 499: tty_term_ptr1(struct tty_term *term, enum tty_code_code code, const void *a)
! 500: {
! 501: return (tparm((char *) tty_term_string(term, code), a));
1.23 nicm 502: }
503:
504: const char *
505: tty_term_ptr2(struct tty_term *term, enum tty_code_code code, const void *a, const void *b)
1.1 nicm 506: {
507: return (tparm((char *) tty_term_string(term, code), a, b));
508: }
509:
510: int
511: tty_term_number(struct tty_term *term, enum tty_code_code code)
512: {
513: if (!tty_term_has(term, code))
514: return (0);
515: if (term->codes[code].type != TTYCODE_NUMBER)
516: log_fatalx("not a number: %d", code);
517: return (term->codes[code].value.number);
518: }
519:
520: int
521: tty_term_flag(struct tty_term *term, enum tty_code_code code)
522: {
523: if (!tty_term_has(term, code))
524: return (0);
525: if (term->codes[code].type != TTYCODE_FLAG)
526: log_fatalx("not a flag: %d", code);
527: return (term->codes[code].value.flag);
528: }