version 1.4, 2009/08/02 20:47:35 |
version 1.5, 2009/08/03 14:10:54 |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
|
|
#include <curses.h> |
#include <curses.h> |
|
#include <fnmatch.h> |
|
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
#include <term.h> |
#include <term.h> |
|
#include <vis.h> |
|
|
#include "tmux.h" |
#include "tmux.h" |
|
|
void tty_term_quirks(struct tty_term *); |
void tty_term_override(struct tty_term *, const char *); |
char *tty_term_strip(const char *); |
char *tty_term_strip(const char *); |
|
|
struct tty_terms tty_terms = SLIST_HEAD_INITIALIZER(tty_terms); |
struct tty_terms tty_terms = SLIST_HEAD_INITIALIZER(tty_terms); |
|
|
} |
} |
|
|
void |
void |
tty_term_quirks(struct tty_term *term) |
tty_term_override(struct tty_term *term, const char *overrides) |
{ |
{ |
if (strncmp(term->name, "rxvt", 4) == 0) { |
struct tty_term_code_entry *ent; |
/* rxvt supports dch1 but some termcap files do not have it. */ |
struct tty_code *code; |
if (!tty_term_has(term, TTYC_DCH1)) { |
char *termnext, *termstr, *entnext, *entstr; |
term->codes[TTYC_DCH1].type = TTYCODE_STRING; |
char *s, *ptr, *val; |
term->codes[TTYC_DCH1].value.string = xstrdup("\033[P"); |
const char *errstr; |
} |
u_int i; |
} |
int n, removeflag; |
|
|
if (strncmp(term->name, "xterm", 5) == 0) { |
s = xstrdup(overrides); |
/* xterm supports ich1 but some termcaps omit it. */ |
|
if (!tty_term_has(term, TTYC_ICH1)) { |
termnext = s; |
term->codes[TTYC_ICH1].type = TTYCODE_STRING; |
while ((termstr = strsep(&termnext, ",")) != NULL) { |
term->codes[TTYC_ICH1].value.string = xstrdup("\033[@"); |
entnext = termstr; |
|
|
|
entstr = strsep(&entnext, ":"); |
|
if (entstr == NULL || entnext == NULL) |
|
continue; |
|
if (fnmatch(entstr, term->name, 0) != 0) |
|
continue; |
|
while ((entstr = strsep(&entnext, ":")) != NULL) { |
|
if (*entstr == '\0') |
|
continue; |
|
|
|
val = NULL; |
|
removeflag = 0; |
|
if ((ptr = strchr(entstr, '=')) != NULL) { |
|
*ptr++ = '\0'; |
|
val = xstrdup(ptr); |
|
if (strunvis(val, ptr) == NULL) { |
|
xfree(val); |
|
val = xstrdup(ptr); |
|
} |
|
} else if (entstr[strlen(entstr) - 1] == '@') { |
|
entstr[strlen(entstr) - 1] = '\0'; |
|
removeflag = 1; |
|
} |
|
|
|
for (i = 0; i < NTTYCODE; i++) { |
|
ent = &tty_term_codes[i]; |
|
if (strcmp(entstr, ent->name) != 0) |
|
continue; |
|
code = &term->codes[ent->code]; |
|
|
|
if (removeflag) { |
|
code->type = TTYCODE_NONE; |
|
continue; |
|
} |
|
switch (ent->type) { |
|
case TTYCODE_NONE: |
|
break; |
|
case TTYCODE_STRING: |
|
xfree(code->value.string); |
|
code->value.string = xstrdup(val); |
|
code->type = ent->type; |
|
break; |
|
case TTYCODE_NUMBER: |
|
n = strtonum(val, 0, INT_MAX, &errstr); |
|
if (errstr != NULL) |
|
break; |
|
code->value.number = n; |
|
code->type = ent->type; |
|
break; |
|
case TTYCODE_FLAG: |
|
code->value.flag = 1; |
|
code->type = ent->type; |
|
break; |
|
} |
|
} |
|
|
|
if (val != NULL) |
|
xfree(val); |
} |
} |
} |
} |
|
|
|
xfree(s); |
} |
} |
|
|
struct tty_term * |
struct tty_term * |
tty_term_find(char *name, int fd, char **cause) |
tty_term_find(char *name, int fd, const char *overrides, char **cause) |
{ |
{ |
struct tty_term *term; |
struct tty_term *term; |
struct tty_term_code_entry *ent; |
struct tty_term_code_entry *ent; |
|
|
break; |
break; |
} |
} |
} |
} |
tty_term_quirks(term); |
tty_term_override(term, overrides); |
|
|
/* Delete curses data. */ |
/* Delete curses data. */ |
del_curterm(cur_term); |
del_curterm(cur_term); |
|
|
*/ |
*/ |
if (tty_term_number(term, TTYC_COLORS) == 256) |
if (tty_term_number(term, TTYC_COLORS) == 256) |
term->flags |= TERM_256COLOURS; |
term->flags |= TERM_256COLOURS; |
if (strstr(name, "256col") != NULL) /* XXX HACK */ |
|
term->flags |= TERM_256COLOURS; |
|
if (tty_term_number(term, TTYC_COLORS) == 88) |
if (tty_term_number(term, TTYC_COLORS) == 88) |
term->flags |= TERM_88COLOURS; |
|
if (strstr(name, "88col") != NULL) /* XXX HACK */ |
|
term->flags |= TERM_88COLOURS; |
term->flags |= TERM_88COLOURS; |
|
|
/* |
/* |