summaryrefslogtreecommitdiffstats
path: root/contrib/ncurses/progs/tic.c
diff options
context:
space:
mode:
Diffstat (limited to 'contrib/ncurses/progs/tic.c')
-rw-r--r--contrib/ncurses/progs/tic.c86
1 files changed, 47 insertions, 39 deletions
diff --git a/contrib/ncurses/progs/tic.c b/contrib/ncurses/progs/tic.c
index 8478102..82bc3ea 100644
--- a/contrib/ncurses/progs/tic.c
+++ b/contrib/ncurses/progs/tic.c
@@ -1,5 +1,5 @@
/****************************************************************************
- * Copyright (c) 1998-2006,2007 Free Software Foundation, Inc. *
+ * Copyright (c) 1998-2007,2008 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 <zmbenhal@netcom.com> 1992,1995 *
* and: Eric S. Raymond <esr@snark.thyrsus.com> *
- * and: Thomas E. Dickey 1996 on *
+ * and: Thomas E. Dickey 1996 on *
****************************************************************************/
/*
@@ -44,7 +44,7 @@
#include <dump_entry.h>
#include <transform.h>
-MODULE_ID("$Id: tic.c,v 1.133 2007/07/21 17:45:59 tom Exp $")
+MODULE_ID("$Id: tic.c,v 1.137 2008/09/13 16:59:24 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;
@@ -353,19 +369,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)
@@ -558,7 +561,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 +632,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 +675,7 @@ main(int argc, char *argv[])
_nc_progname,
_nc_progname,
usage_string);
- cleanup();
+ cleanup(namelst);
ExitProgram(EXIT_FAILURE);
}
}
@@ -705,7 +709,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 +759,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 +803,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 +836,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 +892,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 +923,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 +938,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 +953,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 +964,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 +988,7 @@ check_keypad(TERMTYPE *tp)
}
}
last = test;
+ assert(strlen(show) < (MAX_KP * 4));
switch (kk) {
case 0:
strcat(show, " ka1");
OpenPOWER on IntegriCloud