X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Ftic.c;h=3d894acd2d406b850c465268400a2b6c2933c31b;hp=1b03f380725e589a181cb623a20daaa96f9f1424;hb=2debf76e0c23a2b3d1333f0853317a7b2ae1777f;hpb=027ae42953e3186daed8f3882da73de48291b606 diff --git a/progs/tic.c b/progs/tic.c index 1b03f380..3d894acd 100644 --- a/progs/tic.c +++ b/progs/tic.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2008,2009 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.131 2006/12/02 22:13:17 tom Exp $") +MODULE_ID("$Id: tic.c,v 1.139 2009/12/12 17:30:12 Nicholas.Marriott Exp $") const char *_nc_progname = "tic"; @@ -85,9 +85,25 @@ x\ ] \ source-file\n"; +#if NO_LEAKS static void -cleanup(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(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,12 @@ 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"); + len = strlen(dst); while (--len != 0 && isspace(UChar(dst[len]))) dst[len] = '\0'; return dst; @@ -354,10 +374,10 @@ open_input(const char *filename) } /* Parse the "-e" option-value into a list of names */ -static const char ** +static char ** make_namelist(char *src) { - const char **dst = 0; + char **dst = 0; char *s, *base; unsigned pass, n, nn; @@ -374,11 +394,13 @@ make_namelist(char *src) if ((s = stripped(buffer)) != 0) { if (dst != 0) dst[nn] = s; + else + free(s); nn++; } } if (pass == 1) { - dst = typeCalloc(const char *, nn + 1); + dst = typeCalloc(char *, nn + 1); rewind(fp); } } @@ -401,10 +423,10 @@ make_namelist(char *src) break; } if (pass == 1) - dst = typeCalloc(const char *, nn + 1); + dst = typeCalloc(char *, nn + 1); } } - if (showsummary) { + if (showsummary && (dst != 0)) { fprintf(log_fp, "Entries that will be compiled:\n"); for (n = 0; dst[n] != 0; n++) fprintf(log_fp, "%u:%s\n", n + 1, dst[n]); @@ -413,7 +435,7 @@ make_namelist(char *src) } static bool -matches(const char **needle, const char *haystack) +matches(char **needle, const char *haystack) /* does entry in needle list match |-separated field in haystack? */ { bool code = FALSE; @@ -468,7 +490,7 @@ main(int argc, char *argv[]) bool limited = TRUE; char *tversion = (char *) NULL; const char *source_file = "terminfo"; - const char **namelst = 0; + char **namelst = 0; char *outdir = (char *) NULL; bool check_only = FALSE; bool suppress_untranslatable = FALSE; @@ -477,11 +499,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; } @@ -495,7 +517,7 @@ main(int argc, char *argv[]) * be optional. */ while ((this_opt = getopt(argc, argv, - "0123456789CILNR:TUVace:fGgo:rstvwx")) != EOF) { + "0123456789CILNR:TUVace:fGgo:rstvwx")) != -1) { if (isdigit(this_opt)) { switch (last_opt) { case 'v': @@ -543,7 +565,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; @@ -613,7 +636,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 */ @@ -656,7 +679,7 @@ main(int argc, char *argv[]) _nc_progname, _nc_progname, usage_string); - cleanup(); + cleanup(namelst); ExitProgram(EXIT_FAILURE); } } @@ -690,7 +713,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); } } @@ -740,7 +763,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) @@ -784,7 +807,7 @@ main(int argc, char *argv[]) else fprintf(log_fp, "No entries written\n"); } - cleanup(); + cleanup(namelst); ExitProgram(EXIT_SUCCESS); } @@ -817,15 +840,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); } @@ -869,10 +896,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' @@ -900,6 +927,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. @@ -914,8 +942,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; @@ -929,6 +957,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; @@ -939,22 +968,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) { @@ -963,6 +992,7 @@ check_keypad(TERMTYPE *tp) } } last = test; + assert(strlen(show) < (MAX_KP * 4)); switch (kk) { case 0: strcat(show, " ka1");