]> ncurses.scripts.mit.edu Git - ncurses.git/commitdiff
ncurses 5.9 - patch 20130608
authorThomas E. Dickey <dickey@invisible-island.net>
Sun, 9 Jun 2013 01:17:29 +0000 (01:17 +0000)
committerThomas E. Dickey <dickey@invisible-island.net>
Sun, 9 Jun 2013 01:17:29 +0000 (01:17 +0000)
+ add to test/demo_forms.c examples of using the menu-hooks as well
  as showing how the menu item user-data can be used to pass a callback
  function pointer.
+ add test/dots_termcap.c
+ remove setupterm call from test/demo_termcap.c
+ build-fix if --disable-ext-funcs configure option is used.
+ modified test/edit_field.c and test/demo_forms.c to move the lengths
  into a user-data structure, keeping the original string for later
  expansion to free-format input/out demo.
+ modified test/demo_forms.c to load data from file.
+ added note to clarify Terminal.app's non-emulation of the various
  terminal types listed in the preferences dialog -TD
+ fix regression in error-reporting in lib_setup.c (Debian #711134,
  cf: 20121117).
+ build-fix for a case where --enable-broken_linker and
  --enable-reentrant options are combined (report by George R Goffe).

25 files changed:
Ada95/gen/terminal_interface-curses-forms-field_types.ads.m4
MANIFEST
NEWS
dist.mk
doc/html/man/index.html
misc/terminfo.src
ncurses/tinfo/alloc_ttype.c
ncurses/tinfo/comp_parse.c
ncurses/tinfo/lib_setup.c
ncurses/tinfo/lib_termcap.c
ncurses/tinfo/lib_ti.c
package/debian/changelog
package/ncurses.spec
progs/infocmp.c
progs/tic.c
test/demo_forms.c
test/demo_forms.txt [new file with mode: 0644]
test/demo_menus.c
test/demo_termcap.c
test/demo_terminfo.c
test/dots_termcap.c [new file with mode: 0644]
test/edit_field.c
test/edit_field.h
test/modules
test/programs

index b8481d59714db1be848447cb2238fe3a44e80213..f9784007f46147f8ec7508290c0f6e8c60922250 100644 (file)
@@ -38,7 +38,7 @@ include(M4MACRO)dnl
 ------------------------------------------------------------------------------
 --  Author:  Juergen Pfeifer, 1996
 --  Version Control:
---  $Revision: 1.16 $
+--  $Revision: 1.17 $
 --  Binding Version 01.00
 ------------------------------------------------------------------------------
 with Interfaces.C;
index c409e09b29f3e732f8dd8695fb2b42de0abd7e3d..b7eb016057762bb86d1a057c9f049b5156df7e72 100644 (file)
--- a/MANIFEST
+++ b/MANIFEST
 ./test/demo_altkeys.c
 ./test/demo_defkey.c
 ./test/demo_forms.c
+./test/demo_forms.txt
 ./test/demo_keyok.c
 ./test/demo_menus.c
 ./test/demo_panels.c
diff --git a/NEWS b/NEWS
index e607a6948b70749c930932a71ee055abcfa4d379..f38adef03296d07c7bcc9bd605a70cf541027f79 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -25,7 +25,7 @@
 -- sale, use or other dealings in this Software without prior written        --
 -- authorization.                                                            --
 -------------------------------------------------------------------------------
--- $Id: NEWS,v 1.2061 2013/05/26 00:08:21 tom Exp $
+-- $Id: NEWS,v 1.2069 2013/06/08 21:00:03 tom Exp $
 -------------------------------------------------------------------------------
 
 This is a log of changes that ncurses has gone through since Zeyd started
@@ -45,6 +45,24 @@ See the AUTHORS file for the corresponding full names.
 Changes through 1.9.9e did not credit all contributions;
 it is not possible to add this information.
 
+20130608
+       + add to test/demo_forms.c examples of using the menu-hooks as well
+         as showing how the menu item user-data can be used to pass a callback
+         function pointer.
+       + add test/dots_termcap.c
+       + remove setupterm call from test/demo_termcap.c
+       + build-fix if --disable-ext-funcs configure option is used.
+       + modified test/edit_field.c and test/demo_forms.c to move the lengths
+         into a user-data structure, keeping the original string for later
+         expansion to free-format input/out demo.
+       + modified test/demo_forms.c to load data from file.
+       + added note to clarify Terminal.app's non-emulation of the various
+         terminal types listed in the preferences dialog -TD
+       + fix regression in error-reporting in lib_setup.c (Debian #711134,
+         cf: 20121117).
+       + build-fix for a case where --enable-broken_linker and
+         --enable-reentrant options are combined (report by George R Goffe).
+
 20130525
        + modify mvcur() to distinguish between internal use by the ncurses
          library, and external callers, preventing it from reading the content
diff --git a/dist.mk b/dist.mk
index ca154a14c2f9930fec458c2b2a411b41b68a1dc0..d439d575edf5ec1c248e60af81788973728ff12e 100644 (file)
--- a/dist.mk
+++ b/dist.mk
@@ -25,7 +25,7 @@
 # use or other dealings in this Software without prior written               #
 # authorization.                                                             #
 ##############################################################################
-# $Id: dist.mk,v 1.930 2013/05/25 15:49:34 tom Exp $
+# $Id: dist.mk,v 1.932 2013/06/07 08:08:46 tom Exp $
 # Makefile for creating ncurses distributions.
 #
 # This only needs to be used directly as a makefile by developers, but
@@ -37,7 +37,7 @@ SHELL = /bin/sh
 # These define the major/minor/patch versions of ncurses.
 NCURSES_MAJOR = 5
 NCURSES_MINOR = 9
-NCURSES_PATCH = 20130525
+NCURSES_PATCH = 20130608
 
 # We don't append the patch to the version, since this only applies to releases
 VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR)
index 5a77fe296a05f32e6a0655e4880eb7b5f7958f6f..c93d1f84ccc42b5593d5d2d0be428fc10b28ccd4 100644 (file)
@@ -1,5 +1,5 @@
 <!--
-  $Id: index.html,v 1.6 2013/05/18 11:22:58 tom Exp $
+  $Id: index.html,v 1.7 2013/06/07 20:12:36 tom Exp $
   ****************************************************************************
   * Copyright (c) 1998-2010,2013 Free Software Foundation, Inc.              *
   *                                                                          *
@@ -42,8 +42,6 @@
 </head>
 
 <body>
-  <hr>
-
   <ul>
     <li>Programs:
 
index 8cdda291fd58afa4eac5330e4793b52a155c3388..52c0ec7ca84336944f8da64d1544eae8cba7ca27 100644 (file)
@@ -6,8 +6,8 @@
 # Report bugs and new terminal descriptions to
 #      bug-ncurses@gnu.org
 #
-#      $Revision: 1.477 $
-#      $Date: 2013/05/11 20:03:48 $
+#      $Revision: 1.478 $
+#      $Date: 2013/06/07 23:27:32 $
 #
 # The original header is preserved below for reference.  It is noted that there
 # is a "newer" version which differs in some cosmetic details (but actually
@@ -1210,6 +1210,21 @@ nsterm-16color|AppKit Terminal.app v240.2+ with Mac OS X version 10.5,
 #   xterm-256color.  However, it adds "nsterm", so it is possible to use the
 #   nsterm entry from this file to override the MacPorts (20110404) or
 #   system (20081102) copy of this file.
+# + In OS X 10.8 (Mountain Lion) the TERM which can be set in the preferences
+#   dialog defaults to xterm-256color.  Alternative selections are ansi,
+#   dtterm, rxvt, vt52, vt100, vt102, xterm and xterm-16color.  However,
+#   the menu says "Declare terminal as" without promising to actually emulate
+#   the corresponding terminals.  Indeed, changing TERM does not affect the
+#   emulation itself.  This means that
+#   + the function-keys do not match for dtterm for kf1-kf4 as well as
+#     khome/kend
+#   + the color model is the same for each setting of TERM (does not match
+#     ansi or dtterm).
+#   + the shift/control/meta key modifiers from rxvt and xterm variants are not
+#     recognised except for a few special cases, i.e., kRIT5 and kLFT5.
+#   + the vt52 emulation does not give a usable shell because screen-clearing
+#     does not work as expected.
+#   + selecting "xterm" or "xterm-16color" sets TERM to "xterm-256color".
 nsterm-bce|AppKit Terminal.app v71+/v100.1.8+ with Mac OS X version 10.3/10.4 (bce),
        bce, use=nsterm-16color,
 
@@ -23000,4 +23015,8 @@ v3220|LANPAR Vision II model 3220/3221/3222,
 #        plausible "ansi consoles" -TD
 #      * additional cleanup of table-of-contents by reordering -TD
 #
+# 2013-06-07
+#      * added note to clarify Terminal.app's non-emulation of the various
+#        terminal types listed in the preferences dialog -TD
+#
 ######## SHANTIH!  SHANTIH!  SHANTIH!
index 01e8b50c8aaaf643fef742365750911fd3560557..35c92dd8c2b911696b028ed7894a6c338095a4f4 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1999-2010,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 1999-2012,2013 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            *
@@ -42,7 +42,7 @@
 
 #include <tic.h>
 
-MODULE_ID("$Id: alloc_ttype.c,v 1.26 2012/10/27 21:23:17 tom Exp $")
+MODULE_ID("$Id: alloc_ttype.c,v 1.27 2013/06/08 16:54:50 tom Exp $")
 
 #if NCURSES_XNAMES
 /*
@@ -476,7 +476,9 @@ _nc_align_termtype(TERMTYPE *to, TERMTYPE *from)
 NCURSES_EXPORT(void)
 _nc_copy_termtype(TERMTYPE *dst, const TERMTYPE *src)
 {
+#if NCURSES_XNAMES
     unsigned i;
+#endif
 
     *dst = *src;               /* ...to copy the sizes and string-tables */
 
@@ -506,5 +508,4 @@ _nc_copy_termtype(TERMTYPE *dst, const TERMTYPE *src)
        dst->ext_Names = 0;
     }
 #endif
-
 }
index 9060886b55a23d3fe543667fb615497445b7d63b..653a37412648de6a43470ad0cc1b2ee72fd336de 100644 (file)
@@ -47,7 +47,7 @@
 
 #include <tic.h>
 
-MODULE_ID("$Id: comp_parse.c,v 1.87 2013/05/25 20:20:08 tom Exp $")
+MODULE_ID("$Id: comp_parse.c,v 1.88 2013/06/03 11:05:54 tom Exp $")
 
 static void sanity_check2(TERMTYPE *, bool);
 NCURSES_IMPEXP void NCURSES_API(*_nc_check_termtype2) (TERMTYPE *, bool) = sanity_check2;
@@ -486,12 +486,12 @@ _nc_resolve_uses2(bool fullresolve, bool literal)
                    memset(&fake_tm, 0, sizeof(fake_tm));
                    fake_sp._term = &fake_tm;
                    fake_tm.type = qp->tterm;
-                   SP = &fake_sp;
+                   _nc_set_screen(&fake_sp);
                    set_curterm(&fake_tm);
 
                    _nc_check_termtype2(&qp->tterm, literal);
 
-                   SP = save_SP;
+                   _nc_set_screen(save_SP);
                    set_curterm(save_tm);
                } else {
                    fixup_acsc(&qp->tterm, literal);
index 3e82a389eee001074e4398ebb2a78a77607cbe24..21ee98d201923e209ebea542a1f59dbfa39b562c 100644 (file)
@@ -48,7 +48,7 @@
 #include <locale.h>
 #endif
 
-MODULE_ID("$Id: lib_setup.c,v 1.156 2013/05/25 20:20:08 tom Exp $")
+MODULE_ID("$Id: lib_setup.c,v 1.157 2013/06/06 01:01:18 tom Exp $")
 
 /****************************************************************************
  *
@@ -783,14 +783,12 @@ TINFO_SETUP_TERM(TERMINAL ** tp,
        if ((VALID_STRING(cursor_address)
             || (VALID_STRING(cursor_down) && VALID_STRING(cursor_home)))
            && VALID_STRING(clear_screen)) {
-           free(termp);
            ret_error1(TGETENT_YES, "terminal is not really generic.\n", tname);
        } else {
-           free(termp);
+           del_curterm(termp);
            ret_error1(TGETENT_NO, "I need something more specific.\n", tname);
        }
     } else if (hard_copy) {
-       free(termp);
        ret_error1(TGETENT_YES, "I can't handle hardcopy terminals.\n", tname);
     }
 #endif
index f6a0048b15633b66dc4c207cbe4ae43d1ebd5902..fdfc4946ec721983e09f0518f83248ab878ce1eb 100644 (file)
@@ -48,7 +48,7 @@
 #define CUR SP_TERMTYPE
 #endif
 
-MODULE_ID("$Id: lib_termcap.c,v 1.79 2013/01/19 18:20:05 tom Exp $")
+MODULE_ID("$Id: lib_termcap.c,v 1.80 2013/06/08 16:48:47 tom Exp $")
 
 NCURSES_EXPORT_VAR(char *) UP = 0;
 NCURSES_EXPORT_VAR(char *) BC = 0;
@@ -233,7 +233,7 @@ NCURSES_EXPORT(int)
 NCURSES_SP_NAME(tgetflag) (NCURSES_SP_DCLx NCURSES_CONST char *id)
 {
     int result = 0;            /* Solaris returns zero for missing flag */
-    int i, j;
+    int j = -1;
 
     T((T_CALLED("tgetflag(%p, %s)"), (void *) SP_PARM, id));
     if (HasTInfoTerminal(SP_PARM) && ValidCap(id)) {
@@ -246,7 +246,7 @@ NCURSES_SP_NAME(tgetflag) (NCURSES_SP_DCLx NCURSES_CONST char *id)
        }
 #if NCURSES_XNAMES
        else {
-           j = -1;
+           int i;
            for_each_ext_boolean(i, tp) {
                const char *capname = ExtBoolname(tp, i, boolcodes);
                if (same_tcname(id, capname) && ValidExt(capname)) {
@@ -285,7 +285,7 @@ NCURSES_EXPORT(int)
 NCURSES_SP_NAME(tgetnum) (NCURSES_SP_DCLx NCURSES_CONST char *id)
 {
     int result = ABSENT_NUMERIC;
-    int i, j;
+    int j = -1;
 
     T((T_CALLED("tgetnum(%p, %s)"), (void *) SP_PARM, id));
     if (HasTInfoTerminal(SP_PARM) && ValidCap(id)) {
@@ -298,7 +298,7 @@ NCURSES_SP_NAME(tgetnum) (NCURSES_SP_DCLx NCURSES_CONST char *id)
        }
 #if NCURSES_XNAMES
        else {
-           j = -1;
+           int i;
            for_each_ext_number(i, tp) {
                const char *capname = ExtNumname(tp, i, numcodes);
                if (same_tcname(id, capname) && ValidExt(capname)) {
@@ -337,7 +337,7 @@ NCURSES_EXPORT(char *)
 NCURSES_SP_NAME(tgetstr) (NCURSES_SP_DCLx NCURSES_CONST char *id, char **area)
 {
     char *result = NULL;
-    int i, j;
+    int j = -1;
 
     T((T_CALLED("tgetstr(%s,%p)"), id, (void *) area));
     if (HasTInfoTerminal(SP_PARM) && ValidCap(id)) {
@@ -350,7 +350,7 @@ NCURSES_SP_NAME(tgetstr) (NCURSES_SP_DCLx NCURSES_CONST char *id, char **area)
        }
 #if NCURSES_XNAMES
        else {
-           j = -1;
+           int i;
            for_each_ext_string(i, tp) {
                const char *capname = ExtStrname(tp, i, strcodes);
                if (same_tcname(id, capname) && ValidExt(capname)) {
index e41234210c85de5993eabf088d26896654e599e1..e9ae74623cf50a2cb3082a4dc7758a93f697754b 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 1998-2009,2010 Free Software Foundation, Inc.              *
+ * Copyright (c) 1998-2010,2013 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            *
@@ -36,7 +36,7 @@
 
 #include <tic.h>
 
-MODULE_ID("$Id: lib_ti.c,v 1.29 2010/01/23 17:57:43 tom Exp $")
+MODULE_ID("$Id: lib_ti.c,v 1.30 2013/06/08 16:55:05 tom Exp $")
 
 #if 0
 static bool
@@ -53,7 +53,7 @@ NCURSES_EXPORT(int)
 NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str)
 {
     int result = ABSENT_BOOLEAN;
-    int i, j;
+    int j = -1;
 
     T((T_CALLED("tigetflag(%p, %s)"), (void *) SP_PARM, str));
 
@@ -67,7 +67,7 @@ NCURSES_SP_NAME(tigetflag) (NCURSES_SP_DCLx NCURSES_CONST char *str)
        }
 #if NCURSES_XNAMES
        else {
-           j = -1;
+           int i;
            for_each_ext_boolean(i, tp) {
                const char *capname = ExtBoolname(tp, i, boolnames);
                if (same_name(str, capname)) {
@@ -97,7 +97,7 @@ tigetflag(NCURSES_CONST char *str)
 NCURSES_EXPORT(int)
 NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str)
 {
-    int i, j;
+    int j = -1;
     int result = CANCELLED_NUMERIC;    /* Solaris returns a -1 on error */
 
     T((T_CALLED("tigetnum(%p, %s)"), (void *) SP_PARM, str));
@@ -112,7 +112,7 @@ NCURSES_SP_NAME(tigetnum) (NCURSES_SP_DCLx NCURSES_CONST char *str)
        }
 #if NCURSES_XNAMES
        else {
-           j = -1;
+           int i;
            for_each_ext_number(i, tp) {
                const char *capname = ExtNumname(tp, i, numnames);
                if (same_name(str, capname)) {
@@ -145,7 +145,7 @@ NCURSES_EXPORT(char *)
 NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
 {
     char *result = CANCELLED_STRING;
-    int i, j;
+    int j = -1;
 
     T((T_CALLED("tigetstr(%p, %s)"), (void *) SP_PARM, str));
 
@@ -159,7 +159,7 @@ NCURSES_SP_NAME(tigetstr) (NCURSES_SP_DCLx NCURSES_CONST char *str)
        }
 #if NCURSES_XNAMES
        else {
-           j = -1;
+           int i;
            for_each_ext_string(i, tp) {
                const char *capname = ExtStrname(tp, i, strnames);
                if (same_name(str, capname)) {
index 331052fecd86286d0861b1f279826dca25fc10ae..cbd95db45293115d0e6b82ee5daf2af34d945e3a 100644 (file)
@@ -1,8 +1,8 @@
-ncurses6 (5.9-20130525) unstable; urgency=low
+ncurses6 (5.9-20130608) unstable; urgency=low
 
   * latest weekly patch
 
- -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 25 May 2013 12:36:16 -0400
+ -- Thomas E. Dickey <dickey@invisible-island.net>  Sat, 01 Jun 2013 07:49:17 -0400
 
 ncurses6 (5.9-20120608) unstable; urgency=low
 
index a610275b2b8a0323baf3825cc6ccb4661f7e25ec..8a285ac07ea9f86626be788f2ce569e54e0195f8 100644 (file)
@@ -1,7 +1,7 @@
 Summary: shared libraries for terminal handling
 Name: ncurses6
 Release: 5.9
-Version: 20130525
+Version: 20130608
 License: X11
 Group: Development/Libraries
 Source: ncurses-%{release}-%{version}.tgz
index 449270efa96f16e092ac042a1adcf6f1f0a35c82..bcec57d9c75cd03f4dd573417c9362c02f09fb79 100644 (file)
@@ -42,7 +42,7 @@
 
 #include <dump_entry.h>
 
-MODULE_ID("$Id: infocmp.c,v 1.125 2013/05/25 20:13:24 tom Exp $")
+MODULE_ID("$Id: infocmp.c,v 1.126 2013/06/08 16:51:33 tom Exp $")
 
 #define L_CURL "{"
 #define R_CURL "}"
@@ -404,7 +404,11 @@ show_comparing(char **names)
  * macro is used for limit-checks against the symbols that tic uses to omit
  * the two types of non-standard entry.
  */
+#if NCURSES_XNAMES
 #define check_user_definable(n,limit) if (!_nc_user_definable && (n) > (limit)) break
+#else
+#define check_user_definable(n,limit) if ((n) > (limit)) break
+#endif
 
 /*
  * Use these macros to simplify loops on C_COMMON and C_NAND:
index 3c9a6049105d95febda50491955a1a60ac469a12..4d265eb1fed5a1ee55ce48ab6ba3338c232c30a8 100644 (file)
@@ -46,7 +46,7 @@
 #include <hashed_db.h>
 #include <transform.h>
 
-MODULE_ID("$Id: tic.c,v 1.185 2013/03/17 00:57:05 tom Exp $")
+MODULE_ID("$Id: tic.c,v 1.186 2013/06/08 16:50:47 tom Exp $")
 
 #define STDIN_NAME "<stdin>"
 
@@ -1456,6 +1456,7 @@ uses_SGR_39_49(const char *value)
 static void
 check_screen(TERMTYPE *tp)
 {
+#if NCURSES_XNAMES
     if (_nc_user_definable) {
        int have_XT = tigetflag("XT");
        int have_XM = tigetflag("XM");
@@ -1507,6 +1508,7 @@ check_screen(TERMTYPE *tp)
                _nc_warning("Expected XT to be set, given kmous");
        }
     }
+#endif
 }
 
 /*
index d20469460632ddeb2125ef6f73b6ca602f76fdc0..a1dd592381ff1b2454c1348951a187adc7adf7ff 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2003-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 2003-2012,2013 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            *
@@ -26,7 +26,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: demo_forms.c,v 1.40 2012/11/18 01:22:44 tom Exp $
+ * $Id: demo_forms.c,v 1.44 2013/06/08 15:21:26 tom Exp $
  *
  * Demonstrate a variety of functions from the form library.
  * Thomas Dickey - 2003/4/26
@@ -70,14 +70,115 @@ set_max_field                      -
 
 #include <edit_field.h>
 
+typedef struct {
+    char *name;
+    char *value;
+} MY_DATA;
+
+static MY_DATA *my_data;
+
 static int d_option = 0;
 static int j_value = 0;
 static int m_value = 0;
 static int o_value = 0;
 static char *t_value = 0;
 
+static void
+failed(const char *s)
+{
+    perror(s);
+    ExitProgram(EXIT_FAILURE);
+}
+
+static void
+chomp(char *value)
+{
+    size_t have = strlen(value);
+    while (have != 0 && (value[have - 1] == '\n' || value[have - 1] == '\r')) {
+       value[--have] = '\0';
+    }
+}
+
+static int
+trimmed(const char *value)
+{
+    int result = (int) strlen(value);
+    while (result > 0 && isspace(value[result - 1])) {
+       --result;
+    }
+    return result;
+}
+
+static char *
+get_data(const char *name)
+{
+    char *result = t_value;
+    if (my_data != 0) {
+       int n;
+       for (n = 0; my_data[n].name != 0; ++n) {
+           if (!strcmp(name, my_data[n].name)) {
+               result = my_data[n].value;
+               break;
+           }
+       }
+    }
+    return result;
+}
+
+/*
+ * Read (possibly) multi-line data with name+value pairs.
+ */
+static void
+read_data(const char *filename)
+{
+    FILE *fp = fopen(filename, "r");
+
+    if (fp != 0) {
+       char buffer[BUFSIZ];
+       char *colon;
+       int more = 0;
+       int item = 0;
+
+       my_data = typeCalloc(MY_DATA, 100);     /* FIXME */
+       while (fgets(buffer, sizeof(buffer), fp) != 0) {
+           chomp(buffer);
+           if (more) {
+               if (strcmp(buffer, ".")) {
+                   char *prior = my_data[more - 1].value;
+                   size_t need = strlen(buffer) + 2 + strlen(prior);
+                   char *value = typeRealloc(char, need, prior);
+                   if (value == 0)
+                       failed("realloc");
+                   strcat(value, "\n");
+                   strcat(value, buffer);
+                   my_data[more - 1].value = value;
+               } else {
+                   more = 0;
+               }
+           } else if (*buffer == '#') {
+               continue;
+           } else if ((colon = strchr(buffer, ':')) != 0) {
+               char *name;
+               char *value;
+               *colon++ = '\0';
+               name = strdup(buffer);
+               value = strdup(colon);
+               if (name == 0 || value == 0)
+                   failed("strdup");
+               my_data[item].name = name;
+               my_data[item].value = value;
+               more = ++item;
+           } else {
+               failed("expected a colon");
+           }
+       }
+    } else {
+       failed(filename);
+    }
+}
+
 static FIELD *
-make_label(int frow, int fcol, NCURSES_CONST char *label)
+make_label(const char *label, int frow, int fcol)
 {
     FIELD *f = new_field(1, (int) strlen(label), frow, fcol, 0, 0);
 
@@ -92,13 +193,11 @@ make_label(int frow, int fcol, NCURSES_CONST char *label)
  * Define each field with an extra one, for reflecting "actual" text.
  */
 static FIELD *
-make_field(int frow, int fcol, int rows, int cols)
+make_field(const char *label, int frow, int fcol, int rows, int cols)
 {
     FIELD *f = new_field(rows, cols, frow, fcol, o_value, 1);
 
     if (f) {
-       FieldAttrs *ptr;
-
        set_field_back(f, A_UNDERLINE);
        /*
         * If -j and -d options are combined, -j loses.  It is documented in
@@ -121,17 +220,7 @@ make_field(int frow, int fcol, int rows, int cols)
            set_max_field(f, m_value);
        }
 
-       /*
-        * The userptr is used in edit_field.c's inactive_field().
-        */
-       ptr = (FieldAttrs *) field_userptr(f);
-       if (ptr == 0) {
-           ptr = typeCalloc(FieldAttrs, 1);
-           ptr->background = field_back(f);
-       }
-       set_field_userptr(f, (void *) ptr);
-       if (t_value)
-           set_field_buffer(f, 0, t_value);
+       init_edit_field(f, get_data(label));
     }
     return (f);
 }
@@ -319,15 +408,18 @@ show_current_field(WINDOW *win, FORM * form)
        waddstr(win, "back");
        wattroff(win, (int) field_back(field));
 
-       wprintw(win, ", pad '%c'",
-               field_pad(field));
+       wprintw(win, ", pad '%c'", field_pad(field));
 
        waddstr(win, "\n");
        for (nbuf = 0; nbuf <= 2; ++nbuf) {
            if ((buffer = field_buffer(field, nbuf)) != 0) {
                wprintw(win, "buffer %d:", nbuf);
                (void) wattrset(win, A_REVERSE);
-               waddstr(win, buffer);
+               if (nbuf) {
+                   waddnstr(win, buffer, trimmed(buffer));
+               } else {
+                   waddstr(win, buffer);
+               }
                wattroff(win, A_REVERSE);
                waddstr(win, "\n");
            }
@@ -341,11 +433,12 @@ demo_forms(void)
 {
     WINDOW *w;
     FORM *form;
-    FIELD *f[100];             /* FIXME memset to zero */
+    FIELD *f[100];             /* will memset to zero */
     int finished = 0, c;
     unsigned n = 0;
     int pg;
     WINDOW *also;
+    const char *fname;
 
 #ifdef NCURSES_MOUSE_VERSION
     mousemask(ALL_MOUSE_EVENTS, (mmask_t *) 0);
@@ -363,66 +456,76 @@ demo_forms(void)
     for (pg = 0; pg < 4; ++pg) {
        char label[80];
        sprintf(label, "Sample Form Page %d", pg + 1);
-       f[n++] = make_label(0, 15, label);
+       f[n++] = make_label(label, 0, 15);
        set_new_page(f[n - 1], TRUE);
 
        switch (pg) {
        default:
-           f[n++] = make_label(2, 0, "Last Name");
-           f[n++] = make_field(3, 0, 1, 18);
+           fname = "Last Name";
+           f[n++] = make_label(fname, 2, 0);
+           f[n++] = make_field(fname, 3, 0, 1, 18);
            set_field_type(f[n - 1], TYPE_ALPHA, 1);
 
-           f[n++] = make_label(2, 20, "First Name");
-           f[n++] = make_field(3, 20, 1, 12);
+           fname = "First Name";
+           f[n++] = make_label(fname, 2, 20);
+           f[n++] = make_field(fname, 3, 20, 1, 12);
            set_field_type(f[n - 1], TYPE_ALPHA, 1);
 
-           f[n++] = make_label(2, 34, "Middle Name");
-           f[n++] = make_field(3, 34, 1, 12);
+           fname = "Middle Name";
+           f[n++] = make_label(fname, 2, 34);
+           f[n++] = make_field(fname, 3, 34, 1, 12);
            set_field_type(f[n - 1], TYPE_ALPHA, 1);
            break;
        case 1:
-           f[n++] = make_label(2, 0, "Last Name");
-           f[n++] = make_field(3, 0, 1, 18);
+           fname = "Last Name";
+           f[n++] = make_label(fname, 2, 0);
+           f[n++] = make_field(fname, 3, 0, 1, 18);
            set_field_type(f[n - 1], TYPE_ALPHA, 1);
 
-           f[n++] = make_label(2, 20, "First Name");
-           f[n++] = make_field(3, 20, 1, 12);
+           fname = "First Name";
+           f[n++] = make_label(fname, 2, 20);
+           f[n++] = make_field(fname, 3, 20, 1, 12);
            set_field_type(f[n - 1], TYPE_ALPHA, 1);
 
-           f[n++] = make_label(2, 34, "MI");
-           f[n++] = make_field(3, 34, 1, 1);
+           fname = "MI";
+           f[n++] = make_label(fname, 2, 34);
+           f[n++] = make_field(fname, 3, 34, 1, 1);
            set_field_pad(f[n - 1], '?');
            set_field_type(f[n - 1], TYPE_ALPHA, 1);
            break;
        case 2:
-           f[n++] = make_label(2, 0, "Host Name");
-           f[n++] = make_field(3, 0, 1, 18);
+           fname = "Host Name";
+           f[n++] = make_label(fname, 2, 0);
+           f[n++] = make_field(fname, 3, 0, 1, 24);
            set_field_type(f[n - 1], TYPE_ALNUM, 1);
 
 #ifdef NCURSES_VERSION
-           f[n++] = make_label(2, 20, "IP Address");
-           f[n++] = make_field(3, 20, 1, 12);
+           fname = "IP Address";
+           f[n++] = make_label(fname, 2, 26);
+           f[n++] = make_field(fname, 3, 26, 1, 16);
            set_field_type(f[n - 1], TYPE_IPV4, 1);
 #endif
 
            break;
 
        case 3:
-           f[n++] = make_label(2, 0, "Four digits");
-           f[n++] = make_field(3, 0, 1, 18);
+           fname = "Four digits";
+           f[n++] = make_label(fname, 2, 0);
+           f[n++] = make_field(fname, 3, 0, 1, 18);
            set_field_type(f[n - 1], TYPE_INTEGER, 4, 0, 0);
 
-           f[n++] = make_label(2, 20, "Numeric");
-           f[n++] = make_field(3, 20, 1, 12);
+           fname = "Numeric";
+           f[n++] = make_label(fname, 2, 20);
+           f[n++] = make_field(fname, 3, 20, 1, 12);
            set_field_type(f[n - 1], TYPE_NUMERIC, 3, -10000.0, 100000000.0);
 
            break;
        }
 
-       f[n++] = make_label(5, 0, "Comments");
-       f[n++] = make_field(6, 0, 4, 46);
-       set_field_buffer(f[n - 1], 0, "HELLO\nWORLD!");
-       set_field_buffer(f[n - 1], 1, "Hello\nWorld!");
+       fname = "Comments";
+       f[n++] = make_label(fname, 5, 0);
+       f[n++] = make_field(fname, 6, 0, 4, 46);
+       init_edit_field(f[n - 1], get_data(fname));
     }
 
     f[n] = (FIELD *) 0;
@@ -471,7 +574,7 @@ usage(void)
 {
     static const char *tbl[] =
     {
-       "Usage: demo_forms [options]"
+       "Usage: demo_forms [options] [data file]"
        ,""
        ," -d        make fields dynamic"
        ," -j value  justify (1=left, 2=center, 3=right)"
@@ -517,6 +620,9 @@ main(int argc, char *argv[])
 
        }
     }
+    while (optind < argc) {
+       read_data(argv[optind++]);
+    }
 
     initscr();
     cbreak();
diff --git a/test/demo_forms.txt b/test/demo_forms.txt
new file mode 100644 (file)
index 0000000..0763fc0
--- /dev/null
@@ -0,0 +1,20 @@
+# $Id: demo_forms.txt,v 1.3 2013/06/08 14:10:15 tom Exp $
+First Name:John
+.
+Middle Name:Don
+.
+MI:D
+.
+Last Name:Smith
+.
+Comments:Hello
+World!
+.
+Host Name:localhost@localdomain
+.
+IP Address:192.168.1.100
+.
+Four digits:1234
+.
+Numeric:32768
+.
index dd1bd4fcbc31c11e60535a6ec465e7121e9a9c6f..803482ecc70c9d153d7a73d95f3b9b8a55f3572f 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2005-2011,2012 Free Software Foundation, Inc.              *
+ * Copyright (c) 2005-2012,2013 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            *
@@ -26,7 +26,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: demo_menus.c,v 1.37 2012/11/18 00:18:54 tom Exp $
+ * $Id: demo_menus.c,v 1.50 2013/06/08 21:38:37 tom Exp $
  *
  * Demonstrate a variety of functions from the menu library.
  * Thomas Dickey - 2005/4/9
@@ -38,7 +38,6 @@ item_opts                     -
 item_opts_off                  -
 item_opts_on                   -
 item_term                      -
-item_userptr                   -
 item_visible                   -
 menu_back                      -
 menu_fore                      -
@@ -49,22 +48,16 @@ menu_opts                   -
 menu_pad                       -
 menu_request_by_name           -
 menu_request_name              -
-menu_sub                       -
 menu_term                      -
 menu_userptr                   -
 set_current_item               -
-set_item_init                  -
 set_item_opts                  -
-set_item_term                  -
-set_item_userptr               -
 set_menu_grey                  -
-set_menu_init                  -
 set_menu_items                 -
 set_menu_opts                  -
 set_menu_pad                   -
 set_menu_pattern               -
 set_menu_spacing               -
-set_menu_term                  -
 set_menu_userptr               -
 set_top_row                    -
 top_row                                -
@@ -103,10 +96,20 @@ typedef enum {
 
 #define MENU_Y 1
 
+typedef struct {
+    const char *name;
+    void (*func) (int);
+    unsigned mask;
+} MENU_DATA;
+
+static void call_files(int);
+
 static MENU *mpBanner;
 static MENU *mpFile;
 static MENU *mpSelect;
 
+static WINDOW *status;
+
 static bool loaded_file = FALSE;
 
 /* Common function to allow ^T to toggle trace-mode in the middle of a test
@@ -195,6 +198,48 @@ menu_offset(MenuNo number)
     return result;
 }
 
+static void
+my_menu_init(MENU * menu)
+{
+    Trace(("called MenuHook my_menu_init"));
+    mvwprintw(status, 2, 0, "menu_init %p", (void *) menu);
+    wclrtoeol(status);
+    wrefresh(status);
+}
+
+static void
+my_menu_term(MENU * menu)
+{
+    Trace(("called MenuHook my_menu_term"));
+    mvwprintw(status, 2, 0, "menu_term %p", (void *) menu);
+    wclrtoeol(status);
+    wrefresh(status);
+}
+
+static void
+my_item_init(MENU * menu)
+{
+    ITEM *item = current_item(menu);
+    const char *name = item_name(item);
+
+    Trace(("called MenuHook my_item_init (%s)", name));
+    mvwprintw(status, 2, 0, "item_init %s", name);
+    wclrtoeol(status);
+    wrefresh(status);
+}
+
+static void
+my_item_term(MENU * menu)
+{
+    ITEM *item = current_item(menu);
+    const char *name = item_name(item);
+
+    Trace(("called MenuHook my_item_term (%s)", name));
+    mvwprintw(status, 2, 0, "item_term %s", name);
+    wclrtoeol(status);
+    wrefresh(status);
+}
+
 static MENU *
 menu_create(ITEM ** items, int count, int ncols, MenuNo number)
 {
@@ -240,6 +285,10 @@ menu_create(ITEM ** items, int count, int ncols, MenuNo number)
 
     post_menu(result);
 
+    set_menu_init(result, my_menu_init);
+    set_menu_term(result, my_menu_term);
+    set_item_init(result, my_item_init);
+    set_item_term(result, my_item_term);
     return result;
 }
 
@@ -296,21 +345,24 @@ menu_display(MENU * m)
 static void
 build_file_menu(MenuNo number)
 {
-    static CONST_MENUS char *labels[] =
+    static MENU_DATA table[] =
     {
-       "Exit",
-       (char *) 0
+       {"Exit", call_files, 0},
+       {(char *) 0, 0, 0}
     };
-    static ITEM *items[SIZEOF(labels)];
+    static ITEM *items[SIZEOF(table)];
 
     ITEM **ip = items;
-    CONST_MENUS char **ap;
+    int n;
 
-    for (ap = labels; *ap; ap++)
-       *ip++ = new_item(*ap, "");
+    for (n = 0; table[n].name != 0; ++n) {
+       *ip = new_item(table[n].name, "");
+       set_item_userptr(*ip, &table[n]);
+       ++ip;
+    }
     *ip = (ITEM *) 0;
 
-    mpFile = menu_create(items, SIZEOF(labels) - 1, 1, number);
+    mpFile = menu_create(items, SIZEOF(table) - 1, 1, number);
 }
 
 static int
@@ -321,31 +373,40 @@ perform_file_menu(int cmd)
 
 /*****************************************************************************/
 
+static void
+call_select(int code)
+{
+    (void) code;
+    Trace(("Selected item %d", code));
+}
+
 static void
 build_select_menu(MenuNo number, char *filename)
 {
-    static CONST_MENUS char *labels[] =
+#define MY_DATA(name) { name, call_select, 0 }
+    static MENU_DATA table[] =
     {
-       "Lions",
-       "Tigers",
-       "Bears",
-       "(Oh my!)",
-       "Newts",
-       "Platypi",
-       "Lemurs",
-       "(Oh really?!)",
-       "Leopards",
-       "Panthers",
-       "Pumas",
-       "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
-       "Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs",
-       (char *) 0
+       MY_DATA("Lions"),
+       MY_DATA("Tigers"),
+       MY_DATA("Bears"),
+       MY_DATA("(Oh my!)"),
+       MY_DATA("Newts"),
+       MY_DATA("Platypi"),
+       MY_DATA("Lemurs"),
+       MY_DATA("(Oh really?!)"),
+       MY_DATA("Leopards"),
+       MY_DATA("Panthers"),
+       MY_DATA("Pumas"),
+       MY_DATA("Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs"),
+       MY_DATA("Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs, Lions, Tigers, Bears, (Oh my!), Newts, Platypi, Lemurs"),
+       {(char *) 0, 0, 0}
     };
     static ITEM **items;
 
     ITEM **ip;
-    CONST_MENUS char **ap = 0;
-    CONST_MENUS char **myList = 0;
+    MENU_DATA *ap = 0;
+    MENU_DATA *myList = 0;
+    int i;
     unsigned count = 0;
 
     if (filename != 0) {
@@ -356,7 +417,7 @@ build_select_menu(MenuNo number, char *filename)
            size_t size = (size_t) sb.st_size;
            unsigned j, k;
            char *blob = typeMalloc(char, size + 1);
-           CONST_MENUS char **list = typeCalloc(CONST_MENUS char *, size + 1);
+           MENU_DATA *list = typeCalloc(MENU_DATA, size + 1);
 
            items = typeCalloc(ITEM *, size + 1);
            Trace(("build_select_menu blob=%p, items=%p",
@@ -369,19 +430,19 @@ build_select_menu(MenuNo number, char *filename)
                        bool mark = TRUE;
                        for (j = k = 0; j < size; ++j) {
                            if (mark) {
-                               list[k++] = blob + j;
+                               list[k++].name = blob + j;
                                mark = FALSE;
                            }
                            if (blob[j] == '\n') {
                                blob[j] = '\0';
-                               if (k > 0 && *list[k - 1] == '\0')
+                               if (k > 0 && *list[k - 1].name == '\0')
                                    --k;
                                mark = TRUE;
                            } else if (blob[j] == '\t') {
                                blob[j] = ' ';  /* menu items are printable */
                            }
                        }
-                       list[k] = 0;
+                       list[k].name = 0;
                        count = k;
                        ap = myList = list;
                    }
@@ -394,14 +455,19 @@ build_select_menu(MenuNo number, char *filename)
        }
     }
     if (ap == 0) {
-       count = SIZEOF(labels) - 1;
+       count = SIZEOF(table) - 1;
        items = typeCalloc(ITEM *, count + 1);
-       ap = labels;
+       ap = table;
     }
 
     ip = items;
-    while (*ap != 0)
-       *ip++ = new_item(*ap++, "");
+    for (i = 0; ap[i].name != 0; ++i) {
+       ap[i].func = call_select;
+       ap[i].mask = (unsigned) i;
+       *ip = new_item(ap[i].name, "");
+       set_item_userptr(*ip, &table[i]);
+       ++ip;
+    }
     *ip = 0;
 
     mpSelect = menu_create(items, (int) count, 1, number);
@@ -418,30 +484,36 @@ perform_select_menu(int cmd)
 /*****************************************************************************/
 
 #ifdef TRACE
-#define T_TBL(name) { #name, name }
-static struct {
-    const char *name;
-    unsigned mask;
-} t_tbl[] = {
+
+static void
+call_trace(int code)
+{
+    (void) code;
+    Trace(("Updating trace mask %d", code));
+}
+
+#define T_TBL(name) { #name, call_trace, name }
+static MENU_DATA t_tbl[] =
+{
 
     T_TBL(TRACE_DISABLE),
-       T_TBL(TRACE_TIMES),
-       T_TBL(TRACE_TPUTS),
-       T_TBL(TRACE_UPDATE),
-       T_TBL(TRACE_MOVE),
-       T_TBL(TRACE_CHARPUT),
-       T_TBL(TRACE_ORDINARY),
-       T_TBL(TRACE_CALLS),
-       T_TBL(TRACE_VIRTPUT),
-       T_TBL(TRACE_IEVENT),
-       T_TBL(TRACE_BITS),
-       T_TBL(TRACE_ICALLS),
-       T_TBL(TRACE_CCALLS),
-       T_TBL(TRACE_DATABASE),
-       T_TBL(TRACE_ATTRS),
-       T_TBL(TRACE_MAXIMUM),
+    T_TBL(TRACE_TIMES),
+    T_TBL(TRACE_TPUTS),
+    T_TBL(TRACE_UPDATE),
+    T_TBL(TRACE_MOVE),
+    T_TBL(TRACE_CHARPUT),
+    T_TBL(TRACE_ORDINARY),
+    T_TBL(TRACE_CALLS),
+    T_TBL(TRACE_VIRTPUT),
+    T_TBL(TRACE_IEVENT),
+    T_TBL(TRACE_BITS),
+    T_TBL(TRACE_ICALLS),
+    T_TBL(TRACE_CCALLS),
+    T_TBL(TRACE_DATABASE),
+    T_TBL(TRACE_ATTRS),
+    T_TBL(TRACE_MAXIMUM),
     {
-       (char *) 0, 0
+       (char *) 0, 0, 0
     }
 };
 
@@ -453,8 +525,11 @@ build_trace_menu(MenuNo number)
     ITEM **ip = items;
     int n;
 
-    for (n = 0; t_tbl[n].name != 0; n++)
-       *ip++ = new_item(t_tbl[n].name, "");
+    for (n = 0; t_tbl[n].name != 0; n++) {
+       *ip = new_item(t_tbl[n].name, "");
+       set_item_userptr(*ip, &t_tbl[n]);
+       ++ip;
+    }
     *ip = (ITEM *) 0;
 
     mpTrace = menu_create(items, SIZEOF(t_tbl) - 1, 2, number);
@@ -520,7 +595,8 @@ perform_trace_menu(int cmd)
     int result;
 
     for (ip = menu_items(mpTrace); *ip; ip++) {
-       unsigned mask = t_tbl[item_index(*ip)].mask;
+       MENU_DATA *td = item_userptr(*ip);
+       unsigned mask = td->mask;
        if (mask == 0)
            set_item_value(*ip, _nc_tracing == 0);
        else if ((mask & _nc_tracing) == mask)
@@ -533,15 +609,17 @@ perform_trace_menu(int cmd)
        if (update_trace_menu(mpTrace) || cmd == REQ_TOGGLE_ITEM) {
            newtrace = 0;
            for (ip = menu_items(mpTrace); *ip; ip++) {
-               if (item_value(*ip))
-                   newtrace |= t_tbl[item_index(*ip)].mask;
+               if (item_value(*ip)) {
+                   MENU_DATA *td = item_userptr(*ip);
+                   newtrace |= td->mask;
+               }
            }
            trace(newtrace);
            Trace(("trace level interactively set to %s", tracetrace(_nc_tracing)));
 
-           MvPrintw(LINES - 2, 0,
-                    "Trace level is %s\n", tracetrace(_nc_tracing));
-           refresh();
+           MvWPrintw(status, 1, 0,
+                     "Trace level is %s\n", tracetrace(_nc_tracing));
+           wrefresh(status);
        }
     }
     return result;
@@ -580,28 +658,38 @@ current_menu(void)
     return result;
 }
 
+static void
+call_menus(int code)
+{
+    (void) code;
+    Trace(("Activated menu %d\n", code));
+}
+
 static void
 build_menus(char *filename)
 {
-    static CONST_MENUS char *labels[] =
+    static MENU_DATA table[] =
     {
-       "File",
-       "Select",
+       {"File", call_menus, 0},
+       {"Select", call_menus, 1},
 #ifdef TRACE
-       "Trace",
+       {"Trace", call_menus, 2},
 #endif
-       (char *) 0
+       {(char *) 0, 0, 0}
     };
-    static ITEM *items[SIZEOF(labels)];
+    static ITEM *items[SIZEOF(table)];
 
     ITEM **ip = items;
-    CONST_MENUS char **ap;
+    int n;
 
-    for (ap = labels; *ap; ap++)
-       *ip++ = new_item(*ap, "");
+    for (n = 0; table[n].name != 0; ++n) {
+       *ip = new_item(table[n].name, "");
+       set_item_userptr(*ip, &table[n]);
+       ++ip;
+    }
     *ip = (ITEM *) 0;
 
-    mpBanner = menu_create(items, SIZEOF(labels) - 1, SIZEOF(labels) - 1, eBanner);
+    mpBanner = menu_create(items, SIZEOF(table) - 1, SIZEOF(table) - 1, eBanner);
     set_menu_mark(mpBanner, ">");
 
     build_file_menu(eFile);
@@ -664,14 +752,14 @@ move_menus(MENU * current, int by_y, int by_x)
 static void
 show_status(int ch, MENU * menu)
 {
-    move(LINES - 1, 0);
-    printw("key %s, menu %d, mark %s, match %s",
-          keyname(ch),
-          menu_number(),
-          menu_mark(menu),
-          menu_pattern(menu));
-    clrtoeol();
-    refresh();
+    wmove(status, 0, 0);
+    wprintw(status, "key %s, menu %d, mark %s, match %s",
+           keyname(ch),
+           menu_number(),
+           menu_mark(menu),
+           menu_pattern(menu));
+    wclrtoeol(status);
+    wrefresh(status);
 }
 
 static void
@@ -770,9 +858,9 @@ perform_menus(void)
        wrefresh(menu_win(last_menu));
        if (code == E_UNKNOWN_COMMAND
            || code == E_NOT_POSTED) {
-           if (menu_number() == eFile)
-               break;
-           beep();
+           ITEM *item = current_item(last_menu);
+           MENU_DATA *td = item_userptr(item);
+           td->func((int) td->mask);
        }
        if (code == E_REQUEST_DENIED)
            beep();
@@ -819,6 +907,18 @@ rip_header(WINDOW *win, int cols)
 }
 #endif /* HAVE_RIPOFFLINE */
 
+static void
+call_files(int code)
+{
+    switch (code) {
+    case 0:
+       destroy_menus();
+       endwin();
+       printf("DONE!\n");
+       ExitProgram(EXIT_SUCCESS);
+    }
+}
+
 static void
 usage(void)
 {
@@ -878,6 +978,7 @@ main(int argc, char *argv[])
        init_pair(1, COLOR_RED, COLOR_BLACK);
        init_pair(2, COLOR_BLUE, COLOR_WHITE);
     }
+    status = newwin(3, COLS, LINES - 3, 0);
     build_menus(argc > 1 ? argv[1] : 0);
     perform_menus();
     destroy_menus();
index 50b56c5ac0b4233eeaa5c54921a81f394e882cd6..6f35c17a63afe80c158d951e32c1d35b395bdf62 100644 (file)
@@ -29,7 +29,7 @@
 /*
  * Author: Thomas E. Dickey
  *
- * $Id: demo_termcap.c,v 1.23 2013/01/19 19:30:52 tom Exp $
+ * $Id: demo_termcap.c,v 1.24 2013/06/08 16:58:49 tom Exp $
  *
  * A simple demo of the termcap interface.
  */
@@ -63,28 +63,6 @@ static long total_values;
 
 #define isCapName(c) (isgraph(c) && strchr("^#=:\\", c) == 0)
 
-#if NO_LEAKS && USE_CODE_LISTS
-
-#define MYSCR struct _myscr
-MYSCR {
-    MYSCR *next;
-    TERMINAL *term;
-};
-
-static MYSCR *my_screens;
-
-static void
-save_screen(void)
-{
-    MYSCR *obj = malloc(sizeof(MYSCR));
-    obj->next = my_screens;
-    obj->term = cur_term;
-    my_screens = obj;
-}
-#else
-#define save_screen()          /* nothing */
-#endif
-
 static char *
 make_dbitem(char *p, char *q)
 {
@@ -278,42 +256,39 @@ demo_termcap(NCURSES_CONST char *name)
 {
     unsigned n;
     NCURSES_CONST char *cap;
+    char buffer[1024];
 
     if (db_list) {
        putenv(next_dbitem());
     }
     printf("Terminal type \"%s\"\n", name);
-#if HAVE_SETUPTERM
-    setupterm(name, 1, (int *) 0);
-#else
-    setterm(name);
-#endif
-    save_screen();
-
-    if (b_opt) {
-       for (n = 0;; ++n) {
-           cap = boolcodes[n];
-           if (cap == 0)
-               break;
-           dumpit(cap);
+    if (tgetent(buffer, name) >= 0) {
+
+       if (b_opt) {
+           for (n = 0;; ++n) {
+               cap = boolcodes[n];
+               if (cap == 0)
+                   break;
+               dumpit(cap);
+           }
        }
-    }
 
-    if (n_opt) {
-       for (n = 0;; ++n) {
-           cap = numcodes[n];
-           if (cap == 0)
-               break;
-           dumpit(cap);
+       if (n_opt) {
+           for (n = 0;; ++n) {
+               cap = numcodes[n];
+               if (cap == 0)
+                   break;
+               dumpit(cap);
+           }
        }
-    }
 
-    if (s_opt) {
-       for (n = 0;; ++n) {
-           cap = strcodes[n];
-           if (cap == 0)
-               break;
-           dumpit(cap);
+       if (s_opt) {
+           for (n = 0;; ++n) {
+               cap = strcodes[n];
+               if (cap == 0)
+                   break;
+               dumpit(cap);
+           }
        }
     }
 }
@@ -387,7 +362,7 @@ main(int argc, char *argv[])
        case 's':
            s_opt = TRUE;
            break;
-#ifdef NCURSES_VERSION
+#if NCURSES_XNAMES
        case 'y':
            use_extended_names(FALSE);
            break;
@@ -435,20 +410,6 @@ main(int argc, char *argv[])
                demo_termcap(dumb);
            }
        }
-#if NO_LEAKS
-       /*
-        * ncurses' tgetent() interface caches some entries and its no-leaks
-        * code discards those.  The calls to setupterm() on the other hand
-        * are not cached, and each call allocates a chunk of memory, even
-        * if the same terminal type is requested repeatedly.
-        */
-       while (my_screens != 0) {
-           MYSCR *next = my_screens->next;
-           del_curterm(my_screens->term);
-           free(my_screens);
-           my_screens = next;
-       }
-#endif
     }
 #endif /* USE_CODE_LISTS */
 
index 28c79f964100abe2315aab08343879cd6ef19ff7..cc0fae900107648074d7b06b6ac3cc61d27d7883 100644 (file)
@@ -29,7 +29,7 @@
 /*
  * Author: Thomas E. Dickey
  *
- * $Id: demo_terminfo.c,v 1.16 2013/01/19 19:30:58 tom Exp $
+ * $Id: demo_terminfo.c,v 1.17 2013/06/08 16:52:47 tom Exp $
  *
  * A simple demo of the terminfo interface.
  */
@@ -388,7 +388,7 @@ main(int argc, char *argv[])
        }
     }
 
-#ifdef NCURSES_VERSION
+#if NCURSES_XNAMES
     use_extended_names(xy_opt);
 #endif
 
diff --git a/test/dots_termcap.c b/test/dots_termcap.c
new file mode 100644 (file)
index 0000000..9a8d24b
--- /dev/null
@@ -0,0 +1,250 @@
+/****************************************************************************
+ * Copyright (c) 2013 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            *
+ * "Software"), to deal in the Software without restriction, including      *
+ * without limitation the rights to use, copy, modify, merge, publish,      *
+ * distribute, distribute with modifications, sublicense, and/or sell       *
+ * copies of the Software, and to permit persons to whom the Software is    *
+ * furnished to do so, subject to the following conditions:                 *
+ *                                                                          *
+ * The above copyright notice and this permission notice shall be included  *
+ * in all copies or substantial portions of the Software.                   *
+ *                                                                          *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS  *
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF               *
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.   *
+ * IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,   *
+ * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR    *
+ * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR    *
+ * THE USE OR OTHER DEALINGS IN THE SOFTWARE.                               *
+ *                                                                          *
+ * Except as contained in this notice, the name(s) of the above copyright   *
+ * holders shall not be used in advertising or otherwise to promote the     *
+ * sale, use or other dealings in this Software without prior written       *
+ * authorization.                                                           *
+ ****************************************************************************/
+
+/*
+ * Author: Thomas E. Dickey
+ *
+ * $Id: dots_termcap.c,v 1.5 2013/06/09 00:09:46 tom Exp $
+ *
+ * A simple demo of the termcap interface.
+ */
+#define USE_TINFO
+#include <test.priv.h>
+
+#if HAVE_TGETENT
+
+#include <time.h>
+
+#define valid(s) ((s != 0) && s != (char *)-1)
+
+static bool interrupted = FALSE;
+static long total_chars = 0;
+static time_t started;
+
+static char *t_AB;
+static char *t_AF;
+static char *t_cl;
+static char *t_cm;
+static char *t_me;
+static char *t_mr;
+static char *t_oc;
+static char *t_op;
+static char *t_ve;
+static char *t_vi;
+
+static struct {
+    const char *name;
+    char **value;
+} my_caps[] = {
+
+    {
+       "AB", &t_AB
+    },
+    {
+       "AF", &t_AF
+    },
+    {
+       "cl", &t_cl
+    },
+    {
+       "cm", &t_cm
+    },
+    {
+       "me", &t_me
+    },
+    {
+       "mr", &t_mr
+    },
+    {
+       "oc", &t_oc
+    },
+    {
+       "op", &t_op
+    },
+    {
+       "ve", &t_ve
+    },
+    {
+       "vi", &t_vi
+    },
+};
+
+static
+TPUTS_PROTO(outc, c)
+{
+    int rc = c;
+
+    if (interrupted) {
+       char tmp = (char) c;
+       if (write(STDOUT_FILENO, &tmp, 1) == -1)
+           rc = EOF;
+    } else {
+       rc = putc(c, stdout);
+    }
+    TPUTS_RETURN(rc);
+}
+
+static bool
+outs(char *s)
+{
+    if (valid(s)) {
+       tputs(s, 1, outc);
+       return TRUE;
+    }
+    return FALSE;
+}
+
+static void
+cleanup(void)
+{
+    outs(t_me);
+    if (!outs(t_oc))
+       outs(t_op);
+    outs(t_cl);
+    outs(t_ve);
+
+    printf("\n\n%ld total chars, rate %.2f/sec\n",
+          total_chars,
+          ((double) (total_chars) / (double) (time((time_t *) 0) - started)));
+}
+
+static void
+onsig(int n GCC_UNUSED)
+{
+    interrupted = TRUE;
+}
+
+static double
+ranf(void)
+{
+    long r = (rand() & 077777);
+    return ((double) r / 32768.);
+}
+
+static void
+my_napms(int ms)
+{
+#if defined(__MINGW32__)
+    Sleep(ms);
+#else
+    struct timeval data;
+    data.tv_sec = 0;
+    data.tv_usec = ms * 1000;
+    select(0, NULL, NULL, NULL, &data);
+#endif
+}
+
+int
+main(int argc GCC_UNUSED,
+     char *argv[]GCC_UNUSED)
+{
+    int x, y, z, p;
+    int num_colors;
+    int num_lines;
+    int num_columns;
+    double r;
+    double c;
+    char buffer[1024];
+    char area[1024];
+    char *name;
+
+    CATCHALL(onsig);
+
+    srand((unsigned) time(0));
+
+    if ((name = getenv("TERM")) == 0) {
+       fprintf(stderr, "TERM is not set\n");
+       ExitProgram(EXIT_FAILURE);
+    } else if (tgetent(buffer, name) < 0) {
+       fprintf(stderr, "terminal description not found\n");
+       ExitProgram(EXIT_FAILURE);
+    } else {
+       size_t t;
+       char *ap = area;
+       for (t = 0; t < SIZEOF(my_caps); ++t) {
+           *(my_caps[t].value) = tgetstr((NCURSES_CONST char *)
+                                         my_caps[t].name, &ap);
+       }
+    }
+
+    num_colors = tgetnum("Co");
+    num_lines = tgetnum("li");
+    num_columns = tgetnum("co");
+
+    outs(t_cl);
+    outs(t_vi);
+    if (num_colors > 1) {
+       if (!valid(t_AF)
+           || !valid(t_AB)
+           || (!valid(t_oc) && !valid(t_op)))
+           num_colors = -1;
+    }
+
+    r = (double) (num_lines - 4);
+    c = (double) (num_columns - 4);
+    started = time((time_t *) 0);
+
+    while (!interrupted) {
+       x = (int) (c * ranf()) + 2;
+       y = (int) (r * ranf()) + 2;
+       p = (ranf() > 0.9) ? '*' : ' ';
+
+       tputs(tgoto(t_cm, x, y), 1, outc);
+       if (num_colors > 0) {
+           z = (int) (ranf() * num_colors);
+           if (ranf() > 0.01) {
+               tputs(tgoto(t_AF, 0, z), 1, outc);
+           } else {
+               tputs(tgoto(t_AB, 0, z), 1, outc);
+               my_napms(1);
+           }
+       } else if (valid(t_me)
+                  && valid(t_mr)) {
+           if (ranf() <= 0.01) {
+               outs((ranf() > 0.6)
+                    ? t_mr
+                    : t_me);
+               my_napms(1);
+           }
+       }
+       outc(p);
+       fflush(stdout);
+       ++total_chars;
+    }
+    cleanup();
+    ExitProgram(EXIT_SUCCESS);
+}
+#else
+int
+main(int argc GCC_UNUSED,
+     char *argv[]GCC_UNUSED)
+{
+    fprintf(stderr, "This program requires termcap\n");
+    exit(EXIT_FAILURE);
+}
+#endif
index 8a664e8ca9a47c84c1fd5a562d04dab9d6403c09..7b83bd2ae864e65cbd45905c398ffd8b95c57e66 100644 (file)
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: edit_field.c,v 1.17 2011/01/15 18:15:11 tom Exp $
+ * $Id: edit_field.c,v 1.21 2013/06/08 21:38:12 tom Exp $
  *
  * A wrapper for form_driver() which keeps track of the user's editing changes
- * for each field, and makes the result available as a null-terminated string
- * in field_buffer(field,1).
+ * for each field, and makes the resulting length available as a
+ * null-terminated string in field_buffer(field,1).
  *
  * Thomas Dickey - 2003/4/26.
  */
@@ -297,8 +297,49 @@ offset_in_field(FORM * form)
 static void
 inactive_field(FIELD * f)
 {
-    FieldAttrs *ptr = (FieldAttrs *) field_userptr(f);
-    set_field_back(f, ptr->background);
+    set_field_back(f, field_attrs(f)->background);
+}
+
+FieldAttrs *
+field_attrs(FIELD * f)
+{
+    return (FieldAttrs *) field_userptr(f);
+}
+
+static int
+buffer_length(FIELD * f)
+{
+    return field_attrs(f)->row_lengths[0];
+}
+
+static void
+set_buffer_length(FIELD * f, int length)
+{
+    field_attrs(f)->row_lengths[0] = length;
+}
+
+/*
+ * The userptr is used in edit_field.c's inactive_field(), as well as for
+ * keeping track of the actual lengths of lines in a multiline field.
+ */
+void
+init_edit_field(FIELD * f, char *value)
+{
+    FieldAttrs *ptr = field_attrs(f);
+    if (ptr == 0) {
+       int rows, cols, frow, fcol, nrow, nbuf;
+
+       ptr = typeCalloc(FieldAttrs, 1);
+       ptr->background = field_back(f);
+       if (field_info(f, &rows, &cols, &frow, &fcol, &nrow, &nbuf) == E_OK) {
+           ptr->row_count = nrow;
+           ptr->row_lengths = typeCalloc(int, (size_t) nrow + 1);
+       }
+    }
+    set_field_userptr(f, (void *) ptr);
+    set_field_buffer(f, 0, value);     /* will be formatted */
+    set_field_buffer(f, 1, value);     /* will be unformatted */
+    set_buffer_length(f, (int) strlen(value));
 }
 
 int
@@ -308,9 +349,7 @@ edit_field(FORM * form, int *result)
     int status;
     FIELD *before;
     unsigned n;
-    char lengths[80];
     int length;
-    char *buffer;
     int before_row;
     int before_col;
     int before_off = offset_in_field(form);
@@ -337,9 +376,7 @@ edit_field(FORM * form, int *result)
     if (status == E_OK) {
        bool modified = TRUE;
 
-       length = 0;
-       if ((buffer = field_buffer(before, 1)) != 0)
-           length = atoi(buffer);
+       length = buffer_length(before);
        if (length < before_off)
            length = before_off;
        switch (*result) {
@@ -445,8 +482,7 @@ edit_field(FORM * form, int *result)
            < MIN_FORM_COMMAND)
            ++length;
 
-       sprintf(lengths, "%d", length);
-       set_field_buffer(before, 1, lengths);
+       set_buffer_length(before, length);
     }
 
     if (current_field(form) != before)
index eacade37fb8d154ed3cbdc38982116fbae627c0d..701c4c81f52b938b1415a37cc38992c5bece8fd4 100644 (file)
@@ -26,7 +26,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: edit_field.h,v 1.6 2008/12/20 19:23:18 tom Exp $
+ * $Id: edit_field.h,v 1.8 2013/06/08 15:46:01 tom Exp $
  *
  * Interface of edit_field.c
  */
 
 typedef struct {
     chtype background;
+    int row_count;
+    int *row_lengths;
 } FieldAttrs;
 
+extern FieldAttrs *field_attrs(FIELD * field);
+extern void init_edit_field(FIELD * field, char *value);
 extern void help_edit_field(void);
 extern int edit_field(FORM * form, int *result);
 
index 997b5760cd36fd5b5460b28b6bed891310fc95d6..63e9636f6bf8d37a8cfbe36b263b53a7560c346a 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: modules,v 1.47 2013/01/12 22:50:55 tom Exp $
+# $Id: modules,v 1.48 2013/06/08 16:34:15 tom Exp $
 ##############################################################################
 # Copyright (c) 1998-2012,2013 Free Software Foundation, Inc.                #
 #                                                                            #
@@ -50,6 +50,7 @@ demo_terminfo progs           $(srcdir)       $(HEADER_DEPS)
 ditto          progs           $(srcdir)       $(HEADER_DEPS)
 dots           progs           $(srcdir)       $(HEADER_DEPS)
 dots_mvcur     progs           $(srcdir)       $(HEADER_DEPS)
+dots_termcap   progs           $(srcdir)       $(HEADER_DEPS)
 echochar       progs           $(srcdir)       $(HEADER_DEPS)
 edit_field     progs           $(srcdir)       $(HEADER_DEPS)  $(srcdir)/edit_field.h
 filter         progs           $(srcdir)       $(HEADER_DEPS)
index 477089164a7f035e3295f276b7ccfbc629b510cd..759541b15ccf5034a51814fde68f64f3538a1c5a 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: programs,v 1.21 2013/01/13 00:46:13 tom Exp $
+# $Id: programs,v 1.22 2013/06/08 16:34:31 tom Exp $
 ##############################################################################
 # Copyright (c) 2006-2009,2013 Free Software Foundation, Inc.                #
 #                                                                            #
@@ -48,6 +48,7 @@ demo_terminfo $(LDFLAGS_TINFO)        $(LOCAL_LIBS)   demo_terminfo
 ditto          $(LDFLAGS_THREADS)      $(LOCAL_LIBS)   ditto
 dots           $(LDFLAGS_TINFO)        $(LOCAL_LIBS)   dots
 dots_mvcur     $(LDFLAGS_CURSES)       $(LOCAL_LIBS)   dots_mvcur
+dots_termcap   $(LDFLAGS_TINFO)        $(LOCAL_LIBS)   dots_termcap
 echochar       $(LDFLAGS_CURSES)       $(LOCAL_LIBS)   echochar
 filter         $(LDFLAGS_CURSES)       $(LOCAL_LIBS)   filter
 firework       $(LDFLAGS_CURSES)       $(LOCAL_LIBS)   firework