X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Ftic.c;h=e6032c80989dd3779d3d062a0d6d0d07b65dd4f9;hp=84781026e51c66b40385c61442e06304eafecc88;hb=41677b308e138027b7e435f741ee7fe5651237b0;hpb=772f879d17117c5b766022f28099e341ebea825b diff --git a/progs/tic.c b/progs/tic.c index 84781026..e6032c80 100644 --- a/progs/tic.c +++ b/progs/tic.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. * + * Copyright (c) 1998-2009,2010 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 * @@ -29,7 +29,7 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * - * and: Thomas E. Dickey 1996 on * + * and: Thomas E. Dickey 1996 on * ****************************************************************************/ /* @@ -44,7 +44,7 @@ #include #include -MODULE_ID("$Id: tic.c,v 1.133 2007/07/21 17:45:59 tom Exp $") +MODULE_ID("$Id: tic.c,v 1.141 2010/05/01 21:17:23 tom Exp $") const char *_nc_progname = "tic"; @@ -85,9 +85,25 @@ x\ ] \ source-file\n"; +#if NO_LEAKS +static void +free_namelist(char **src) +{ + if (src != 0) { + int n; + for (n = 0; src[n] != 0; ++n) + free(src[n]); + free(src); + } +} +#endif + static void -cleanup(void) +cleanup(char **namelst GCC_UNUSED) { +#if NO_LEAKS + free_namelist(namelst); +#endif if (tmp_fp != 0) fclose(tmp_fp); if (to_remove != 0) { @@ -103,7 +119,7 @@ static void failed(const char *msg) { perror(msg); - cleanup(); + cleanup((char **) 0); ExitProgram(EXIT_FAILURE); } @@ -178,7 +194,7 @@ write_it(ENTRY * ep) d = result; t = s; while ((ch = *t++) != 0) { - *d++ = ch; + *d++ = (char) ch; if (ch == '\\') { *d++ = *t++; } else if ((ch == '%') @@ -192,7 +208,7 @@ write_it(ENTRY * ep) && value < 127 && isprint((int) value)) { *d++ = S_QUOTE; - *d++ = (int) value; + *d++ = (char) value; *d++ = S_QUOTE; t = (v + 1); } @@ -280,7 +296,7 @@ put_translate(int c) putchar(c); in_name = FALSE; } else if (c != '>') { - namebuf[used++] = c; + namebuf[used++] = (char) c; } else { /* ah! candidate name! */ char *up; NCURSES_CONST char *tp; @@ -326,8 +342,15 @@ stripped(char *src) while (isspace(UChar(*src))) src++; if (*src != '\0') { - char *dst = strcpy((char *) malloc(strlen(src) + 1), src); - size_t len = strlen(dst); + char *dst; + size_t len; + + if ((dst = strdup(src)) == NULL) + failed("strdup"); + + assert(dst != 0); + + len = strlen(dst); while (--len != 0 && isspace(UChar(dst[len]))) dst[len] = '\0'; return dst; @@ -353,19 +376,6 @@ open_input(const char *filename) return fp; } -#if NO_LEAKS -static void -free_namelist(char **src) -{ - if (src != 0) { - int n; - for (n = 0; src[n] != 0; ++n) - free(src[n]); - free(src); - } -} -#endif - /* Parse the "-e" option-value into a list of names */ static char ** make_namelist(char *src) @@ -492,11 +502,11 @@ main(int argc, char *argv[]) _nc_progname = _nc_rootname(argv[0]); - if ((infodump = (strcmp(_nc_progname, PROG_CAPTOINFO) == 0)) != FALSE) { + if ((infodump = same_program(_nc_progname, PROG_CAPTOINFO)) != FALSE) { outform = F_TERMINFO; sortmode = S_TERMINFO; } - if ((capdump = (strcmp(_nc_progname, PROG_INFOTOCAP) == 0)) != FALSE) { + if ((capdump = same_program(_nc_progname, PROG_INFOTOCAP)) != FALSE) { outform = F_TERMCAP; sortmode = S_TERMCAP; } @@ -558,7 +568,8 @@ main(int argc, char *argv[]) break; case 'V': puts(curses_version()); - return EXIT_SUCCESS; + cleanup(namelst); + ExitProgram(EXIT_SUCCESS); case 'c': check_only = TRUE; break; @@ -628,7 +639,7 @@ main(int argc, char *argv[]) if (namelst && (!infodump && !capdump)) { (void) fprintf(stderr, "Sorry, -e can't be used without -I or -C\n"); - cleanup(); + cleanup(namelst); ExitProgram(EXIT_FAILURE); } #endif /* HAVE_BIG_CORE */ @@ -671,7 +682,7 @@ main(int argc, char *argv[]) _nc_progname, _nc_progname, usage_string); - cleanup(); + cleanup(namelst); ExitProgram(EXIT_FAILURE); } } @@ -705,7 +716,7 @@ main(int argc, char *argv[]) /* do use resolution */ if (check_only || (!infodump && !capdump) || forceresolve) { if (!_nc_resolve_uses2(TRUE, literal) && !check_only) { - cleanup(); + cleanup(namelst); ExitProgram(EXIT_FAILURE); } } @@ -755,7 +766,7 @@ main(int argc, char *argv[]) dump_entry(&qp->tterm, suppress_untranslatable, limited, numbers, NULL); - for (j = 0; j < qp->nuses; j++) + for (j = 0; j < (int) qp->nuses; j++) dump_uses(qp->uses[j].name, !capdump); len = show_entry(); if (debug_level != 0 && !limited) @@ -799,10 +810,7 @@ main(int argc, char *argv[]) else fprintf(log_fp, "No entries written\n"); } -#if NO_LEAKS - free_namelist(namelst); -#endif - cleanup(); + cleanup(namelst); ExitProgram(EXIT_SUCCESS); } @@ -835,15 +843,19 @@ check_acs(TERMTYPE *tp) } mapped[UChar(p[0])] = p[1]; } + if (mapped[UChar('I')] && !mapped[UChar('i')]) { _nc_warning("acsc refers to 'I', which is probably an error"); } + for (p = boxes, q = missing; *p != '\0'; ++p) { if (!mapped[UChar(p[0])]) { *q++ = p[0]; } - *q = '\0'; } + *q = '\0'; + + assert(strlen(missing) <= strlen(boxes)); if (*missing != '\0' && strcmp(missing, boxes)) { _nc_warning("acsc is missing some line-drawing mapping: %s", missing); } @@ -887,10 +899,10 @@ check_colors(TERMTYPE *tp) } } -static int +static char keypad_final(const char *string) { - int result = '\0'; + char result = '\0'; if (VALID_STRING(string) && *string++ == '\033' @@ -918,6 +930,7 @@ keypad_index(const char *string) return result; } +#define MAX_KP 5 /* * Do a quick sanity-check for vt100-style keypads to see if the 5-key keypad * is mapped inconsistently. @@ -932,8 +945,8 @@ check_keypad(TERMTYPE *tp) VALID_STRING(key_b2) && VALID_STRING(key_c1) && VALID_STRING(key_c3)) { - char final[6]; - int list[5]; + char final[MAX_KP + 1]; + int list[MAX_KP]; int increase = 0; int j, k, kk; int last; @@ -947,6 +960,7 @@ check_keypad(TERMTYPE *tp) final[5] = '\0'; /* special case: legacy coding using 1,2,3,0,. on the bottom */ + assert(strlen(final) <= MAX_KP); if (!strcmp(final, "qsrpn")) return; @@ -957,22 +971,22 @@ check_keypad(TERMTYPE *tp) list[4] = keypad_index(key_c3); /* check that they're all vt100 keys */ - for (j = 0; j < 5; ++j) { + for (j = 0; j < MAX_KP; ++j) { if (list[j] < 0) { return; } } /* check if they're all in increasing order */ - for (j = 1; j < 5; ++j) { + for (j = 1; j < MAX_KP; ++j) { if (list[j] > list[j - 1]) { ++increase; } } - if (increase != 4) { + if (increase != (MAX_KP - 1)) { show[0] = '\0'; - for (j = 0, last = -1; j < 5; ++j) { + for (j = 0, last = -1; j < MAX_KP; ++j) { for (k = 0, kk = -1, test = 100; k < 5; ++k) { if (list[k] > last && list[k] < test) { @@ -981,6 +995,7 @@ check_keypad(TERMTYPE *tp) } } last = test; + assert(strlen(show) < (MAX_KP * 4)); switch (kk) { case 0: strcat(show, " ka1"); @@ -1260,6 +1275,8 @@ similar_sgr(int num, char *a, char *b) } else if (delaying) { a = skip_delay(a); b = skip_delay(b); + } else if ((*b == '0' || (*b == ';')) && *a == 'm') { + b++; } else { a++; }