------------------------------------------------------------------------------
-- Author: Juergen Pfeifer, 1996
-- Version Control:
--- $Revision: 1.16 $
+-- $Revision: 1.17 $
-- Binding Version 01.00
------------------------------------------------------------------------------
with Interfaces.C;
./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
-- 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
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
# 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
# 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)
<!--
- $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. *
* *
</head>
<body>
- <hr>
-
<ul>
<li>Programs:
# 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
# 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,
# 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!
/****************************************************************************
- * 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 *
#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
/*
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 */
dst->ext_Names = 0;
}
#endif
-
}
#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;
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);
#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 $")
/****************************************************************************
*
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
#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;
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)) {
}
#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)) {
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)) {
}
#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)) {
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)) {
}
#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)) {
/****************************************************************************
- * 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 *
#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
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));
}
#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)) {
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));
}
#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)) {
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));
}
#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)) {
-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
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
#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 "}"
* 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:
#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>"
static void
check_screen(TERMTYPE *tp)
{
+#if NCURSES_XNAMES
if (_nc_user_definable) {
int have_XT = tigetflag("XT");
int have_XM = tigetflag("XM");
_nc_warning("Expected XT to be set, given kmous");
}
}
+#endif
}
/*
/****************************************************************************
- * 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 *
* 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
#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);
* 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
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);
}
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");
}
{
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);
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;
{
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)"
}
}
+ while (optind < argc) {
+ read_data(argv[optind++]);
+ }
initscr();
cbreak();
--- /dev/null
+# $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
+.
/****************************************************************************
- * 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 *
* 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
item_opts_off -
item_opts_on -
item_term -
-item_userptr -
item_visible -
menu_back -
menu_fore -
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 -
#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
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)
{
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;
}
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
/*****************************************************************************/
+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) {
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",
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;
}
}
}
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);
/*****************************************************************************/
#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
}
};
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);
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)
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;
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);
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
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();
}
#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)
{
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();
/*
* 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.
*/
#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)
{
{
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);
+ }
}
}
}
case 's':
s_opt = TRUE;
break;
-#ifdef NCURSES_VERSION
+#if NCURSES_XNAMES
case 'y':
use_extended_names(FALSE);
break;
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 */
/*
* 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.
*/
}
}
-#ifdef NCURSES_VERSION
+#if NCURSES_XNAMES
use_extended_names(xy_opt);
#endif
--- /dev/null
+/****************************************************************************
+ * 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
* 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.
*/
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
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);
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) {
< MIN_FORM_COMMAND)
++length;
- sprintf(lengths, "%d", length);
- set_field_buffer(before, 1, lengths);
+ set_buffer_length(before, length);
}
if (current_field(form) != before)
* 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);
-# $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. #
# #
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)
-# $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. #
# #
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