X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Ftic.c;h=cfcbc359152653a5f315400f86d91c1c1b362425;hp=e559d1b35c283d61c3b6c0010764b4b13caf987a;hb=d62b54c082a8564aa0c715cddadb1160498b057f;hpb=646aa4040ea415c39a376991d2d9658eff0fce77 diff --git a/progs/tic.c b/progs/tic.c index e559d1b3..cfcbc359 100644 --- a/progs/tic.c +++ b/progs/tic.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2015,2016 Free Software Foundation, Inc. * + * Copyright (c) 1998-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -48,7 +48,7 @@ #include #include -MODULE_ID("$Id: tic.c,v 1.224 2016/10/01 12:46:54 tom Exp $") +MODULE_ID("$Id: tic.c,v 1.232 2017/04/13 09:12:05 tom Exp $") #define STDIN_NAME "" @@ -62,8 +62,8 @@ static bool showsummary = FALSE; static char **namelst = 0; static const char *to_remove; -static void (*save_check_termtype) (TERMTYPE *, bool); -static void check_termtype(TERMTYPE *tt, bool); +static void (*save_check_termtype) (TERMTYPE2 *, bool); +static void check_termtype(TERMTYPE2 *tt, bool); static const char usage_string[] = "\ [-e names] \ @@ -114,6 +114,7 @@ cleanup(void) #if NO_LEAKS free_namelist(namelst); + _nc_leaks_dump_entry(); #endif if (tmp_fp != 0) fclose(tmp_fp); @@ -1088,7 +1089,7 @@ main(int argc, char *argv[]) * Check if the alternate character-set capabilities are consistent. */ static void -check_acs(TERMTYPE *tp) +check_acs(TERMTYPE2 *tp) { if (VALID_STRING(acs_chars)) { const char *boxes = "lmkjtuvwqxn"; @@ -1128,7 +1129,7 @@ check_acs(TERMTYPE *tp) * Check if the color capabilities are consistent */ static void -check_colors(TERMTYPE *tp) +check_colors(TERMTYPE2 *tp) { if ((max_colors > 0) != (max_pairs > 0) || ((max_colors > max_pairs) && (initialize_pair == 0))) @@ -1172,6 +1173,19 @@ check_colors(TERMTYPE *tp) } } +static int +csi_length(const char *value) +{ + int result = 0; + + if (value[0] == '\033' && value[1] == '[') { + result = 2; + } else if (UChar(value[0]) == 0x9a) { + result = 1; + } + return result; +} + static char keypad_final(const char *string) { @@ -1214,7 +1228,6 @@ check_ansi_cursor(char *list[4]) { int j, k; int want; - size_t prefix = 0; size_t suffix; bool skip[4]; bool repeated = FALSE; @@ -1232,16 +1245,8 @@ check_ansi_cursor(char *list[4]) } if (!repeated) { char *up = list[1]; + size_t prefix = (size_t) csi_length(up); - if (UChar(up[0]) == '\033') { - if (up[1] == '[') { - prefix = 2; - } else { - prefix = 1; - } - } else if (UChar(up[0]) == UChar('\233')) { - prefix = 1; - } if (prefix) { suffix = prefix; while (up[suffix] && isdigit(UChar(up[suffix]))) @@ -1283,7 +1288,7 @@ check_ansi_cursor(char *list[4]) #define UNEXPECTED(name) if (PRESENT(name)) _nc_warning("unexpected " #name ", for %s", why) static void -check_noaddress(TERMTYPE *tp, const char *why) +check_noaddress(TERMTYPE2 *tp, const char *why) { UNEXPECTED(column_address); UNEXPECTED(cursor_address); @@ -1295,7 +1300,7 @@ check_noaddress(TERMTYPE *tp, const char *why) } static void -check_cursor(TERMTYPE *tp) +check_cursor(TERMTYPE2 *tp) { int count; char *list[4]; @@ -1414,7 +1419,7 @@ check_cursor(TERMTYPE *tp) * is mapped inconsistently. */ static void -check_keypad(TERMTYPE *tp) +check_keypad(TERMTYPE2 *tp) { char show[80]; @@ -1524,7 +1529,7 @@ check_keypad(TERMTYPE *tp) } static void -check_printer(TERMTYPE *tp) +check_printer(TERMTYPE2 *tp) { PAIRED(enter_doublewide_mode, exit_doublewide_mode); PAIRED(enter_italics_mode, exit_italics_mode); @@ -1560,7 +1565,7 @@ uses_SGR_39_49(const char *value) * Check consistency of termcap extensions related to "screen". */ static void -check_screen(TERMTYPE *tp) +check_screen(TERMTYPE2 *tp) { #if NCURSES_XNAMES if (_nc_user_definable) { @@ -1717,7 +1722,7 @@ expected_params(const char *name) * markers. */ static void -check_params(TERMTYPE *tp, const char *name, char *value) +check_params(TERMTYPE2 *tp, const char *name, char *value) { int expected = expected_params(name); int actual = 0; @@ -1769,6 +1774,158 @@ check_params(TERMTYPE *tp, const char *name, char *value) } } +static bool +line_capability(const char *name) +{ + bool result = FALSE; + static const char *table[] = + { + "csr", /* change_scroll_region */ + "clear", /* clear_screen */ + "ed", /* clr_eos */ + "cwin", /* create_window */ + "cup", /* cursor_address */ + "cud1", /* cursor_down */ + "home", /* cursor_home */ + "mrcup", /* cursor_mem_address */ + "ll", /* cursor_to_ll */ + "cuu1", /* cursor_up */ + "dl1", /* delete_line */ + "hd", /* down_half_line */ + "flash", /* flash_screen */ + "ff", /* form_feed */ + "il1", /* insert_line */ + "nel", /* newline */ + "dl", /* parm_delete_line */ + "cud", /* parm_down_cursor */ + "indn", /* parm_index */ + "il", /* parm_insert_line */ + "rin", /* parm_rindex */ + "cuu", /* parm_up_cursor */ + "mc0", /* print_screen */ + "vpa", /* row_address */ + "ind", /* scroll_forward */ + "ri", /* scroll_reverse */ + "hu", /* up_half_line */ + }; + size_t n; + for (n = 0; n < SIZEOF(table); ++n) { + if (!strcmp(name, table[n])) { + result = TRUE; + break; + } + } + return result; +} + +/* + * Check for DEC VT100 private mode for reverse video. + */ +static const char * +skip_DECSCNM(const char *value, int *flag) +{ + *flag = -1; + if (value != 0) { + int skip = csi_length(value); + if (skip > 0 && + value[skip++] == '?' && + value[skip++] == '5') { + if (value[skip] == 'h') { + *flag = 1; + } else if (value[skip] == 'l') { + *flag = 0; + } + value += skip + 1; + } + } + return value; +} + +static void +check_delays(const char *name, const char *value) +{ + const char *p, *q; + const char *first = 0; + const char *last = 0; + + for (p = value; *p != '\0'; ++p) { + if (p[0] == '$' && p[1] == '<') { + const char *base = p + 2; + const char *mark = 0; + bool maybe = TRUE; + bool mixed = FALSE; + int proportional = 0; + int mandatory = 0; + + first = p; + + for (q = base; *q != '\0'; ++q) { + if (*q == '>') { + if (mark == 0) + mark = q; + break; + } else if (*q == '*' || *q == '/') { + if (*q == '*') + ++proportional; + if (*q == '/') + ++mandatory; + if (mark == 0) + mark = q; + } else if (!(isalnum(UChar(*q)) || strchr("+-.", *q) != 0)) { + maybe = FALSE; + break; + } else if (proportional || mandatory) { + mixed = TRUE; + } + } + last = *q ? (q + 1) : q; + if (*q == '\0') { + maybe = FALSE; /* just an isolated "$<" */ + } else if (maybe) { + float check_f; + char check_c; + int rc = sscanf(base, "%f%c", &check_f, &check_c); + if ((rc != 2) || (check_c != *mark) || mixed) { + _nc_warning("syntax error in %s delay '%.*s'", name, + (int) (q - base), base); + } else if (*name == 'k') { + _nc_warning("function-key %s has delay", name); + } else if (proportional && !line_capability(name)) { + _nc_warning("non-line capability using proportional delay: %s", name); + } + } else { + p = q - 1; /* restart scan */ + } + } + } + + if (!strcmp(name, "flash") || + !strcmp(name, "beep")) { + + if (first != 0) { + if (first == value || *last == 0) { + /* + * Delay is on one end or the other. + */ + _nc_warning("expected delay embedded within %s", name); + } + } else { + int flag; + + /* + * Check for missing delay when using VT100 reverse-video. + * A real VT100 might not need this, but terminal emulators do. + */ + if ((p = skip_DECSCNM(value, &flag)) != 0 && + flag > 0 && + (q = skip_DECSCNM(p, &flag)) != 0 && + flag == 0) { + _nc_warning("expected a delay in %s", name); + } + } + } +} + static char * check_1_infotocap(const char *name, NCURSES_CONST char *value, int count) { @@ -1785,7 +1942,7 @@ check_1_infotocap(const char *name, NCURSES_CONST char *value, int count) for (k = 1; k <= NUM_PARM; k++) { numbers[k] = count; _nc_SPRINTF(next, - _nc_SLIMIT(sizeof(blob) - (next - blob)) + _nc_SLIMIT(sizeof(blob) - (size_t) (next - blob)) "XYZ%d", count); strings[k] = next; next += strlen(next) + 1; @@ -1939,7 +2096,7 @@ same_ti_tc(const char *ti, const char *tc, bool * embedded) * Check terminfo to termcap translation. */ static void -check_infotocap(TERMTYPE *tp, int i, const char *value) +check_infotocap(TERMTYPE2 *tp, int i, const char *value) { const char *name = ExtStrname(tp, i, strnames); int params = (((i < (int) SIZEOF(parametrized)) && @@ -2114,7 +2271,7 @@ similar_sgr(int num, char *a, char *b) } static char * -check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name) +check_sgr(TERMTYPE2 *tp, char *zero, int num, char *cap, const char *name) { char *test; @@ -2180,7 +2337,7 @@ typedef struct { } NAME_VALUE; static NAME_VALUE * -get_fkey_list(TERMTYPE *tp) +get_fkey_list(TERMTYPE2 *tp) { NAME_VALUE *result = typeMalloc(NAME_VALUE, NUM_STRINGS(tp) + 1); const struct tinfo_fkeys *all_fkeys = _nc_tinfo_fkeys; @@ -2231,7 +2388,7 @@ show_fkey_name(NAME_VALUE * data) * last one assigned). */ static void -check_conflict(TERMTYPE *tp) +check_conflict(TERMTYPE2 *tp) { bool conflict = FALSE; unsigned j, k; @@ -2301,15 +2458,13 @@ is_sgr_string(char *value) bool result = FALSE; if (VALID_STRING(value)) { - if (value[0] == '\033' && value[1] == '[') { - result = TRUE; - value += 2; - } else if (UChar(value[0]) == 0x9a) { - result = TRUE; - value += 1; - } - if (result) { + int skip = csi_length(value); + + if (skip) { int ch; + + result = TRUE; + value += skip; while ((ch = UChar(*value++)) != '\0') { if (isdigit(ch) || ch == ';') { ; @@ -2329,7 +2484,7 @@ is_sgr_string(char *value) * Check if the given capability contains a given SGR attribute. */ static void -check_sgr_param(TERMTYPE *tp, int code, const char *name, char *value) +check_sgr_param(TERMTYPE2 *tp, int code, const char *name, char *value) { if (VALID_STRING(value)) { int ncv = ((code != 0) ? (1 << (code - 1)) : 0); @@ -2378,7 +2533,7 @@ check_sgr_param(TERMTYPE *tp, int code, const char *name, char *value) * logic that reads a terminfo entry) */ static void -check_termtype(TERMTYPE *tp, bool literal) +check_termtype(TERMTYPE2 *tp, bool literal) { unsigned j; @@ -2388,6 +2543,7 @@ check_termtype(TERMTYPE *tp, bool literal) char *a = tp->Strings[j]; if (VALID_STRING(a)) { check_params(tp, ExtStrname(tp, (int) j, strnames), a); + check_delays(ExtStrname(tp, (int) j, strnames), a); if (capdump) { check_infotocap(tp, (int) j, a); }