=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/tmux/tty-term.c,v retrieving revision 1.48 retrieving revision 1.49 diff -c -r1.48 -r1.49 *** src/usr.bin/tmux/tty-term.c 2017/01/13 11:56:43 1.48 --- src/usr.bin/tmux/tty-term.c 2017/01/24 20:05:15 1.49 *************** *** 1,4 **** ! /* $OpenBSD: tty-term.c,v 1.48 2017/01/13 11:56:43 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott --- 1,4 ---- ! /* $OpenBSD: tty-term.c,v 1.49 2017/01/24 20:05:15 nicm Exp $ */ /* * Copyright (c) 2008 Nicholas Marriott *************** *** 294,379 **** } static void ! tty_term_override(struct tty_term *term, const char *overrides) { const struct tty_term_code_entry *ent; struct tty_code *code; ! char *termnext, *termstr; ! char *entnext, *entstr; ! char *s, *ptr, *val; const char *errstr; u_int i; ! int n, removeflag; ! s = xstrdup(overrides); ! termnext = s; ! while ((termstr = strsep(&termnext, ",")) != NULL) { ! 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) == -1) { ! free(val); ! val = xstrdup(ptr); ! } ! } else if (entstr[strlen(entstr) - 1] == '@') { ! entstr[strlen(entstr) - 1] = '\0'; ! removeflag = 1; ! } else ! val = xstrdup(""); ! log_debug("%s override: %s %s", ! term->name, entstr, removeflag ? "@" : val); ! for (i = 0; i < tty_term_ncodes(); i++) { ! ent = &tty_term_codes[i]; ! if (strcmp(entstr, ent->name) != 0) ! continue; ! code = &term->codes[i]; ! if (removeflag) { ! code->type = TTYCODE_NONE; ! continue; ! } ! switch (ent->type) { ! case TTYCODE_NONE: break; ! case TTYCODE_STRING: ! if (code->type == TTYCODE_STRING) ! free(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; ! } } - - free(val); } - } free(s); } --- 294,375 ---- } static void ! tty_term_override(struct tty_term *term, const char *override) { const struct tty_term_code_entry *ent; struct tty_code *code; ! char *next, *s, *copy, *cp, *value; const char *errstr; u_int i; ! int n, remove; ! copy = next = xstrdup(override); ! s = strsep(&next, ":"); ! if (s == NULL || next == NULL || fnmatch(s, term->name, 0) != 0) { ! free(copy); ! return; ! } ! while ((s = strsep(&next, ":")) != NULL) { ! if (*s == '\0') continue; ! value = NULL; ! remove = 0; ! if ((cp = strchr(s, '=')) != NULL) { ! *cp++ = '\0'; ! value = xstrdup(cp); ! if (strunvis(value, cp) == -1) { ! free(value); ! value = xstrdup(cp); ! } ! } else if (s[strlen(s) - 1] == '@') { ! s[strlen(s) - 1] = '\0'; ! remove = 1; ! } else ! value = xstrdup(""); ! if (remove) ! log_debug("%s override: %s@", term->name, s); ! else ! log_debug("%s override: %s=%s", term->name, s, value); ! for (i = 0; i < tty_term_ncodes(); i++) { ! ent = &tty_term_codes[i]; ! if (strcmp(s, ent->name) != 0) ! continue; ! code = &term->codes[i]; ! ! if (remove) { ! code->type = TTYCODE_NONE; ! continue; ! } ! switch (ent->type) { ! case TTYCODE_NONE: ! break; ! case TTYCODE_STRING: ! if (code->type == TTYCODE_STRING) ! free(code->value.string); ! code->value.string = xstrdup(value); ! code->type = ent->type; ! break; ! case TTYCODE_NUMBER: ! n = strtonum(value, 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; } } + free(value); + } free(s); } *************** *** 383,389 **** struct tty_term *term; const struct tty_term_code_entry *ent; struct tty_code *code; ! u_int i; int n, error; const char *s, *acs; --- 379,386 ---- struct tty_term *term; const struct tty_term_code_entry *ent; struct tty_code *code; ! struct options_entry *o; ! u_int size, i; int n, error; const char *s, *acs; *************** *** 457,464 **** } /* Apply terminal overrides. */ ! s = options_get_string(global_options, "terminal-overrides"); ! tty_term_override(term, s); /* Delete curses data. */ del_curterm(cur_term); --- 454,467 ---- } /* Apply terminal overrides. */ ! o = options_get_only(global_options, "terminal-overrides"); ! if (options_array_size(o, &size) != -1) { ! for (i = 0; i < size; i++) { ! s = options_array_get(o, i); ! if (s != NULL) ! tty_term_override(term, s); ! } ! } /* Delete curses data. */ del_curterm(cur_term);