Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libcurses Multiple fixes:
details: https://anonhg.NetBSD.org/src/rev/c8b865d42f33
branches: trunk
changeset: 485046:c8b865d42f33
user: blymn <blymn%NetBSD.org@localhost>
date: Mon Apr 17 12:25:45 2000 +0000
description:
Multiple fixes:
* Added Bill's fixes for errors when compiling with WARNS=1
* Incorporated fixes to make usage of unctrl consistent in debug and
made improvements to ctrace - it now timestamps it's output better.
* Reduced the number of mallocs done by __init_getch by allocating key
structs in bunches instead of singly.
* Removed the shadowing of global declarations in newwin and subwin
functions
diffstat:
lib/libcurses/addnstr.c | 27 ++--
lib/libcurses/color.c | 4 +-
lib/libcurses/ctrace.c | 20 +++-
lib/libcurses/curses.c | 6 +-
lib/libcurses/curses.h | 10 +-
lib/libcurses/getch.c | 256 ++++++++++++++++++++++++++++++-----------------
lib/libcurses/initscr.c | 6 +-
lib/libcurses/newwin.c | 70 ++++++------
lib/libcurses/setterm.c | 7 +-
lib/libcurses/tscroll.c | 6 +-
lib/libcurses/tty.c | 6 +-
11 files changed, 249 insertions(+), 169 deletions(-)
diffs (truncated from 852 to 300 lines):
diff -r b55864d619fb -r c8b865d42f33 lib/libcurses/addnstr.c
--- a/lib/libcurses/addnstr.c Mon Apr 17 12:01:20 2000 +0000
+++ b/lib/libcurses/addnstr.c Mon Apr 17 12:25:45 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: addnstr.c,v 1.8 2000/04/15 23:36:55 jdc Exp $ */
+/* $NetBSD: addnstr.c,v 1.9 2000/04/17 12:25:45 blymn Exp $ */
/*
* Copyright (c) 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)addnstr.c 8.2 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: addnstr.c,v 1.8 2000/04/15 23:36:55 jdc Exp $");
+__RCSID("$NetBSD: addnstr.c,v 1.9 2000/04/17 12:25:45 blymn Exp $");
#endif
#endif /* not lint */
@@ -54,13 +54,22 @@
* Add a string to stdscr starting at (_cury, _curx).
*/
int
-addstr(s)
- const char *s;
+addstr(const char *s)
{
return waddnstr(stdscr, s, -1);
}
/*
+ * waddstr --
+ * Add a string to the given window starting at (_cury, _curx).
+ */
+int
+waddstr(WINDOW *win, const char *s)
+{
+ return waddnstr(win, s, -1);
+}
+
+/*
* addnstr --
* Add a string (at most n characters) to stdscr starting
* at (_cury, _curx). If n is negative, add the entire string.
@@ -72,16 +81,6 @@
}
/*
- * mvwaddstr --
- * Add a string to the given window.
- */
-int
-waddstr(WINDOW *win, const char *str)
-{
- return waddnstr(win, str, -1);
-}
-
-/*
* mvaddstr --
* Add a string to stdscr starting at (y, x)
*/
diff -r b55864d619fb -r c8b865d42f33 lib/libcurses/color.c
--- a/lib/libcurses/color.c Mon Apr 17 12:01:20 2000 +0000
+++ b/lib/libcurses/color.c Mon Apr 17 12:25:45 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: color.c,v 1.4 2000/04/15 22:53:05 jdc Exp $ */
+/* $NetBSD: color.c,v 1.5 2000/04/17 12:25:45 blymn Exp $ */
/*
* Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -106,7 +106,7 @@
* Initialise colour support.
*/
int
-start_color()
+start_color(void)
{
int i;
attr_t temp_nc;
diff -r b55864d619fb -r c8b865d42f33 lib/libcurses/ctrace.c
--- a/lib/libcurses/ctrace.c Mon Apr 17 12:01:20 2000 +0000
+++ b/lib/libcurses/ctrace.c Mon Apr 17 12:25:45 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ctrace.c,v 1.8 2000/04/16 01:16:43 thorpej Exp $ */
+/* $NetBSD: ctrace.c,v 1.9 2000/04/17 12:25:45 blymn Exp $ */
/*-
* Copyright (c) 1992, 1993
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)ctrace.c 8.2 (Berkeley) 10/5/93";
#else
-__RCSID("$NetBSD: ctrace.c,v 1.8 2000/04/16 01:16:43 thorpej Exp $");
+__RCSID("$NetBSD: ctrace.c,v 1.9 2000/04/17 12:25:45 blymn Exp $");
#endif
#endif /* not lint */
@@ -51,6 +51,8 @@
#include <varargs.h>
#endif
+#include <sys/time.h>
+
#include "curses.h"
#ifndef TFILE
@@ -68,6 +70,8 @@
va_dcl
#endif
{
+ struct timeval tv;
+ static int seencr = 1;
va_list ap;
#ifdef __STDC__
va_start(ap, fmt);
@@ -78,13 +82,21 @@
tracefp = fopen(TFILE, "w");
if (tracefp == NULL)
return;
- (void) vfprintf(tracefp, fmt, ap);
+ gettimeofday(&tv, NULL);
+ if (seencr) {
+ gettimeofday(&tv, NULL);
+ (void) fprintf(tracefp, "%lu.%06lu: ", tv.tv_sec, tv.tv_usec);
+ }
+ (void) vfprintf(tracefp, fmt, ap);
+ seencr = (strchr(fmt, '\n') != NULL);
va_end(ap);
(void) fflush(tracefp);
}
#else
/* this kills the empty translation unit message from lint... */
-void __cursesi_make_lint_shut_up_if_debug_not_defined(void);
+void
+__cursesi_make_lint_shut_up_if_debug_not_defined(void);
+
void
__cursesi_make_lint_shut_up_if_debug_not_defined(void)
{
diff -r b55864d619fb -r c8b865d42f33 lib/libcurses/curses.c
--- a/lib/libcurses/curses.c Mon Apr 17 12:01:20 2000 +0000
+++ b/lib/libcurses/curses.c Mon Apr 17 12:25:45 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: curses.c,v 1.13 2000/04/12 21:46:49 jdc Exp $ */
+/* $NetBSD: curses.c,v 1.14 2000/04/17 12:25:45 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)curses.c 8.3 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: curses.c,v 1.13 2000/04/12 21:46:49 jdc Exp $");
+__RCSID("$NetBSD: curses.c,v 1.14 2000/04/17 12:25:45 blymn Exp $");
#endif
#endif /* not lint */
@@ -78,7 +78,7 @@
int COLORS; /* Maximum colors on the screen */
int COLOR_PAIRS; /* Maximum color pairs on the screen */
int My_term = 0; /* Use Def_term regardless. */
-char *Def_term = "unknown"; /* Default terminal type. */
+const char *Def_term = "unknown"; /* Default terminal type. */
char GT; /* Gtty indicates tabs. */
char NONL; /* Term can't hack LF doing a CR. */
char UPPERCASE; /* Terminal is uppercase only. */
diff -r b55864d619fb -r c8b865d42f33 lib/libcurses/curses.h
--- a/lib/libcurses/curses.h Mon Apr 17 12:01:20 2000 +0000
+++ b/lib/libcurses/curses.h Mon Apr 17 12:25:45 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: curses.h,v 1.36 2000/04/16 09:52:49 jdc Exp $ */
+/* $NetBSD: curses.h,v 1.37 2000/04/17 12:25:45 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -85,7 +85,7 @@
extern char UPPERCASE; /* Terminal is uppercase only. */
extern int My_term; /* Use Def_term regardless. */
-extern char *Def_term; /* Default terminal type. */
+extern const char *Def_term; /* Default terminal type. */
/* Termcap capabilities. */
extern char AM, BE, BS, CA, CC, DA, EO, HC, HL, IN, MI, MS, NC, NS,
@@ -523,7 +523,7 @@
int mvwin(WINDOW *win, int y, int x);
int mvwprintw(WINDOW *win, int y, int x, const char *fmt, ...);
int mvwscanw(WINDOW *win, int y, int x, const char *fmt, ...);
-WINDOW *newwin(int nl, int nc, int by, int bx);
+WINDOW *newwin(int nlines, int ncols, int by, int bx);
int nl(void);
int nocbreak(void);
void nodelay(WINDOW *win, bool bf);
@@ -544,8 +544,8 @@
int scroll(WINDOW *win);
int scrollok(WINDOW *win, bool bf);
int setterm(char *);
-int start_color(void);
-WINDOW *subwin(WINDOW *orig, int nl, int nc, int by, int bx);
+int start_color(void);
+WINDOW *subwin(WINDOW *orig, int nlines, int ncols, int by, int bx);
int touchline(WINDOW *win, int start, int count);
int touchoverlap(WINDOW *win1, WINDOW *win2);
int touchwin(WINDOW *win);
diff -r b55864d619fb -r c8b865d42f33 lib/libcurses/getch.c
--- a/lib/libcurses/getch.c Mon Apr 17 12:01:20 2000 +0000
+++ b/lib/libcurses/getch.c Mon Apr 17 12:25:45 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: getch.c,v 1.19 2000/04/15 22:59:05 jdc Exp $ */
+/* $NetBSD: getch.c,v 1.20 2000/04/17 12:25:46 blymn Exp $ */
/*
* Copyright (c) 1981, 1993, 1994
@@ -38,7 +38,7 @@
#if 0
static char sccsid[] = "@(#)getch.c 8.2 (Berkeley) 5/4/94";
#else
-__RCSID("$NetBSD: getch.c,v 1.19 2000/04/15 22:59:05 jdc Exp $");
+__RCSID("$NetBSD: getch.c,v 1.20 2000/04/17 12:25:46 blymn Exp $");
#endif
#endif /* not lint */
@@ -80,13 +80,19 @@
* it is the end of a multi-char sequence or a
* single char key that generates a symbol */
+/* allocate this many key_entry structs at once to speed start up must
+ * be a power of 2.
+ */
+#define KEYMAP_ALLOC_CHUNK 4
+
/* The max number of different chars we can receive */
#define MAX_CHAR 256
struct keymap {
int count; /* count of number of key structs allocated */
short mapping[MAX_CHAR]; /* mapping of key to allocated structs */
- key_entry_t **key; /* dynamic array of keys */};
+ key_entry_t **key; /* dynamic array of keys */
+};
/* Key buffer */
@@ -109,7 +115,7 @@
/* The termcap data we are interested in and the symbols they map to */
struct tcdata {
- char *name; /* name of termcap entry */
+ const char *name; /* name of termcap entry */
wchar_t symbol; /* the symbol associated with it */
};
@@ -159,9 +165,89 @@
static keymap_t *base_keymap;
/* prototypes for private functions */
+static key_entry_t *add_new_key(keymap_t *current, char chr, int key_type,
+ int symbol);
static keymap_t *new_keymap(void); /* create a new keymap */
static key_entry_t *new_key(void); /* create a new key entry */
-static wchar_t inkey(int, int);
+static wchar_t inkey(int to, int delay);
+
+/*
+ * Add a new key entry to the keymap pointed to by current. Entry
+ * contains the character to add to the keymap, type is the type of
+ * entry to add (either multikey or leaf) and symbol is the symbolic
+ * value for a leaf type entry. The function returns a pointer to the
+ * new keymap entry.
+ */
+static key_entry_t *
+add_new_key(keymap_t *current, char chr, int key_type, int symbol)
+{
+ key_entry_t *the_key;
+ int i;
+
+#ifdef DEBUG
+ __CTRACE("Adding character %s of type %d, symbol 0x%x\n", unctrl(chr),
+ key_type, symbol);
+#endif
+ if (current->mapping[(unsigned) chr] < 0) {
+ /* first time for this char */
+ current->mapping[(unsigned) chr] = current->count; /* map new entry */
+ /* make sure we have room in the key array first */
+ if ((current->count & (KEYMAP_ALLOC_CHUNK - 1)) == 0)
+ {
+ if ((current->key =
+ realloc(current->key,
+ (current->count) * sizeof(key_entry_t *)
+ + KEYMAP_ALLOC_CHUNK * sizeof(key_entry_t *))) == NULL) {
+ fprintf(stderr,
+ "Could not malloc for key entry\n");
+ exit(1);
+ }
+
+ the_key = new_key();
+ for (i = 0; i < KEYMAP_ALLOC_CHUNK; i++) {
+ current->key[current->count + i]
+ = &the_key[i];
+ }
+ }
Home |
Main Index |
Thread Index |
Old Index