X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=progs%2Ftic.c;h=84781026e51c66b40385c61442e06304eafecc88;hp=a918efd7538dc9d279b9512c7d9d431ff558bce4;hb=25358bc041a5566ce2de4c9c792837e552b35671;hpb=55ccd2b959766810cf7db8d1c4462f338ce0afc8 diff --git a/progs/tic.c b/progs/tic.c index a918efd7..84781026 100644 --- a/progs/tic.c +++ b/progs/tic.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2004,2005 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 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 * @@ -44,7 +44,7 @@ #include #include -MODULE_ID("$Id: tic.c,v 1.125 2005/09/25 00:39:43 tom Exp $") +MODULE_ID("$Id: tic.c,v 1.133 2007/07/21 17:45:59 tom Exp $") const char *_nc_progname = "tic"; @@ -353,11 +353,24 @@ 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 const char ** +static char ** make_namelist(char *src) { - const char **dst = 0; + char **dst = 0; char *s, *base; unsigned pass, n, nn; @@ -374,11 +387,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 +416,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 +428,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 +483,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; @@ -495,7 +510,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': @@ -731,18 +746,18 @@ main(int argc, char *argv[]) _nc_set_type(_nc_first_name(qp->tterm.term_names)); (void) fseek(tmp_fp, qp->cstart, SEEK_SET); - while (j--) { + while (j-- > 0) { if (infodump) (void) putchar(fgetc(tmp_fp)); else put_translate(fgetc(tmp_fp)); } - len = dump_entry(&qp->tterm, suppress_untranslatable, - limited, 0, numbers, NULL); + dump_entry(&qp->tterm, suppress_untranslatable, + limited, numbers, NULL); for (j = 0; j < qp->nuses; j++) - len += dump_uses(qp->uses[j].name, !capdump); - (void) putchar('\n'); + dump_uses(qp->uses[j].name, !capdump); + len = show_entry(); if (debug_level != 0 && !limited) printf("# length=%d\n", len); } @@ -784,6 +799,9 @@ main(int argc, char *argv[]) else fprintf(log_fp, "No entries written\n"); } +#if NO_LEAKS + free_namelist(namelst); +#endif cleanup(); ExitProgram(EXIT_SUCCESS); } @@ -793,9 +811,6 @@ main(int argc, char *argv[]) * references to locations in the arrays Booleans, Numbers, and Strings --- * precisely what's needed (see comp_parse.c). */ - -TERMINAL *cur_term; /* tweak to avoid linking lib_cur_term.c */ - #undef CUR #define CUR tp-> @@ -1276,16 +1291,16 @@ check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name) char *test; _nc_tparm_err = 0; - test = tparm(set_attributes, - num == 1, - num == 2, - num == 3, - num == 4, - num == 5, - num == 6, - num == 7, - num == 8, - num == 9); + test = TPARM_9(set_attributes, + num == 1, + num == 2, + num == 3, + num == 4, + num == 5, + num == 6, + num == 7, + num == 8, + num == 9); if (test != 0) { if (PRESENT(cap)) { if (!similar_sgr(num, test, cap)) { @@ -1317,7 +1332,7 @@ check_sgr(TERMTYPE *tp, char *zero, int num, char *cap, const char *name) static void show_where(unsigned level) { - if (_nc_tracing >= level) { + if (_nc_tracing >= DEBUG_LEVEL(level)) { char my_name[256]; _nc_get_type(my_name); fprintf(stderr, "\"%s\", line %d, '%s' ", @@ -1327,7 +1342,7 @@ show_where(unsigned level) } #else -#define show_where(level) /* nothing */ +#define show_where(level) /* nothing */ #endif /* other sanity-checks (things that we don't want in the normal @@ -1416,7 +1431,7 @@ check_termtype(TERMTYPE *tp, bool literal) if (PRESENT(exit_attribute_mode)) { zero = strdup(CHECK_SGR(0, exit_attribute_mode)); } else { - zero = strdup(tparm(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0)); + zero = strdup(TPARM_9(set_attributes, 0, 0, 0, 0, 0, 0, 0, 0, 0)); } if (_nc_tparm_err) _nc_warning("stack error in sgr(0) string");