X-Git-Url: http://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=tack%2Ffun.c;h=378887217ce91b3119e6b9e4eec93b5ce60607e3;hp=fd895c372f3bf16d1036168e54137e32f4fa7b94;hb=ca5fdd32fd43d84fe3d720cd5c07fba28fc506a4;hpb=b1f61d9f3aa244512045a6b02e759825d7049d34 diff --git a/tack/fun.c b/tack/fun.c index fd895c37..37888721 100644 --- a/tack/fun.c +++ b/tack/fun.c @@ -1,27 +1,27 @@ /* ** Copyright (C) 1991, 1997 Free Software Foundation, Inc. -** +** ** This file is part of TACK. -** +** ** TACK is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License as published by ** the Free Software Foundation; either version 2, or (at your option) ** any later version. -** +** ** TACK is distributed in the hope that it will be useful, ** but WITHOUT ANY WARRANTY; without even the implied warranty of ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ** GNU General Public License for more details. -** +** ** You should have received a copy of the GNU General Public License ** along with TACK; see the file COPYING. If not, write to -** the Free Software Foundation, Inc., 59 Temple Place - Suite 330, -** Boston, MA 02111-1307, USA. +** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, +** Boston, MA 02110-1301, USA */ #include -MODULE_ID("$Id: fun.c,v 1.3 2000/03/04 20:29:21 tom Exp $") +MODULE_ID("$Id: fun.c,v 1.9 2006/11/26 00:15:53 tom Exp $") /* * Test the function keys on the terminal. The code for echo tests @@ -56,18 +56,13 @@ struct test_list printer_test_list[] = { {MENU_LAST, 0, 0, 0, 0, 0, 0} }; -#define MAX_STRINGS STRCOUNT - -/* scan code externals */ -extern int scan_max; /* length of longest scan code */ -extern char **scan_up, **scan_down, **scan_name; -extern int *scan_tested, *scan_length; - /* local definitions */ -static const char *fk_name[MAX_STRINGS]; -static char *fkval[MAX_STRINGS]; -static char *fk_label[MAX_STRINGS]; /* function key labels (if any) */ -static int fk_tested[MAX_STRINGS]; +static const char **fk_name; +static char **fkval; +static char **fk_label; /* function key labels (if any) */ +static int *fk_tested; +static int num_strings = 0; + static int fkmax = 1; /* length of longest key */ static int got_labels = 0; /* true if we have some labels */ static int key_count = 0; @@ -79,6 +74,21 @@ static char *fk_unknown[MAX_FK_UNK]; static int fk_length[MAX_FK_UNK]; static int funk; +/* + * Initialize arrays that depend on the actual number of strings. + */ +static void +alloc_strings(void) +{ + if (num_strings != MAX_STRINGS) { + num_strings = MAX_STRINGS; + fk_name = (const char **)calloc(num_strings, sizeof(const char *)); + fkval = (char **)calloc(num_strings, sizeof(char *)); + fk_label = (char **)calloc(num_strings, sizeof(char *)); + fk_tested = (int *)calloc(num_strings, sizeof(int)); + } +} + /* ** keys_tested(first-time, show-help, hex-output) ** @@ -93,6 +103,7 @@ keys_tested( int i, l; char outbuf[256]; + alloc_strings(); put_clear(); tty_set(); flush_input(); @@ -102,7 +113,7 @@ keys_tested( if (fk_label[i]) { sprintf(outbuf, "%s %s", fk_name[i] ? fk_name[i] : "??", fk_label[i]); - put_columns(outbuf, strlen(outbuf), 16); + put_columns(outbuf, (int) strlen(outbuf), 16); } } put_newlines(2); @@ -193,6 +204,7 @@ enter_key( { int j; + alloc_strings(); if (value) { j = strlen(value); fkmax = fkmax > j ? fkmax : j; @@ -275,6 +287,7 @@ found_match(char *s, int hx, int cc) int j, f; char outbuf[256]; + alloc_strings(); if (!*s) { return 0; } @@ -571,7 +584,7 @@ funkey_label( for (i = 1; i <= num_labels; i++) { sprintf(outbuf, "L%d..............................", i); outbuf[label_width] = '\0'; - tc_putp(tparm(plab_norm, i, outbuf)); + tc_putp(TPARM_2(plab_norm, i, outbuf)); } if (label_off) { ptext("Hit any key to remove the labels: "); @@ -602,7 +615,7 @@ funkey_prog( sprintf(temp, "(pfx) Set function key %d to transmit abc\\n", fk); ptextln(temp); - tc_putp(tparm(pkey_xmit, fk, "abc\n")); + tc_putp(TPARM_2(pkey_xmit, fk, "abc\n")); sprintf(temp, "Hit function key %d\n", fk); ptextln(temp); for (i = 0; i < 4; ++i) @@ -617,7 +630,7 @@ funkey_prog( } flush_input(); if (key_f1) { - tc_putp(tparm(pkey_xmit, fk, key_f1)); + tc_putp(TPARM_2(pkey_xmit, fk, key_f1)); } } else { ptextln("Function key transmit (pfx), not present."); @@ -645,13 +658,13 @@ funkey_local( "(pfloc) Set function key %d to execute a clear and print \"Done!\"", fk); ptextln(temp); sprintf(temp, "%sDone!", liberated(clear_screen)); - tc_putp(tparm(pkey_local, fk, temp)); + tc_putp(TPARM_2(pkey_local, fk, temp)); sprintf(temp, "Hit function key %d. Then hit return.", fk); ptextln(temp); (void) wait_here(); flush_input(); if (key_f1 && pkey_xmit) { - tc_putp(tparm(pkey_xmit, fk, key_f1)); + tc_putp(TPARM_2(pkey_xmit, fk, key_f1)); } } else { ptextln("Function key execute local (pfloc), not present."); @@ -806,7 +819,7 @@ tools_report( ptextln("Begin echo test."); report_help(crx); } - txt[sizeof(txt) - 1] = '\0'; + memset(txt, 0, sizeof(txt)); save_scan_mode = scan_mode; tty_raw(1, char_mask); for (i = crp = high_bit = 0;;) {