diff --git a/NEWS b/NEWS index c4b4f665..cf97f163 100644 --- a/NEWS +++ b/NEWS @@ -25,7 +25,7 @@ -- sale, use or other dealings in this Software without prior written -- -- authorization. -- ------------------------------------------------------------------------------- --- $Id: NEWS,v 1.1168 2007/09/15 21:33:37 tom Exp $ +-- $Id: NEWS,v 1.1171 2007/09/29 21:53:42 tom Exp $ ------------------------------------------------------------------------------- This is a log of changes that ncurses has gone through since Zeyd started @@ -45,6 +45,14 @@ 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. +20070929 + + add new functions to lib_trace.c to setup mutex's for the _tracef() + calls within the ncurses library. + + for the reentrant model, move _nc_tputs_trace and _nc_outchars into + the SCREEN. + + start modifying test/worm.c to provide threading demo (incomplete). + + separated ifdef's for some BSD-related symbols in tset.c, to make + it compile on LynxOS (report by Greg Gemmer). 20070915 + modify Ada95/gen/Makefile to use shlib script, to simplify building shared-library configuration on platforms lacking rpath support. diff --git a/dist.mk b/dist.mk index 5c3eba16..397e43c0 100644 --- 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.610 2007/09/15 14:29:36 tom Exp $ +# $Id: dist.mk,v 1.611 2007/09/29 15:48:09 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 = 6 -NCURSES_PATCH = 20070915 +NCURSES_PATCH = 20070929 # We don't append the patch to the version, since this only applies to releases VERSION = $(NCURSES_MAJOR).$(NCURSES_MINOR) diff --git a/ncurses/base/lib_getch.c b/ncurses/base/lib_getch.c index d8906dae..64566ccc 100644 --- a/ncurses/base/lib_getch.c +++ b/ncurses/base/lib_getch.c @@ -41,7 +41,7 @@ #include -MODULE_ID("$Id: lib_getch.c,v 1.79 2007/04/19 20:57:49 tom Exp $") +MODULE_ID("$Id: lib_getch.c,v 1.80 2007/09/29 20:39:34 tom Exp $") #include @@ -112,8 +112,10 @@ fifo_pull(void) h_inc(); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) + if (USE_TRACEF(TRACE_IEVENT)) { _nc_fifo_dump(); + _nc_unlock_global(tracef); + } #endif return ch; } @@ -208,8 +210,10 @@ fifo_push(EVENTLIST_0th(_nc_eventlist * evl)) t_inc(); TR(TRACE_IEVENT, ("pushed %s at %d", _tracechar(ch), tail)); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) + if (USE_TRACEF(TRACE_IEVENT)) { _nc_fifo_dump(); + _nc_unlock_global(tracef); + } #endif return ch; } diff --git a/ncurses/base/lib_mouse.c b/ncurses/base/lib_mouse.c index 7ea35e82..aace7deb 100644 --- a/ncurses/base/lib_mouse.c +++ b/ncurses/base/lib_mouse.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2005,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2007 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 * @@ -79,7 +79,7 @@ #include -MODULE_ID("$Id: lib_mouse.c,v 1.87 2006/12/30 16:30:06 tom Exp $") +MODULE_ID("$Id: lib_mouse.c,v 1.88 2007/09/29 21:50:04 tom Exp $") #include #include @@ -985,12 +985,13 @@ _nc_mouse_parse(int runcount) } #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) { + if (USE_TRACEF(TRACE_IEVENT)) { _trace_slot("before mouse press/release merge:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", (long) (runp - SP->_mouse_events), (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX, runcount); + _nc_unlock_global(tracef); } #endif /* TRACE */ @@ -1028,12 +1029,13 @@ _nc_mouse_parse(int runcount) (merge); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) { + if (USE_TRACEF(TRACE_IEVENT)) { _trace_slot("before mouse click merge:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", (long) (runp - SP->_mouse_events), (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX, runcount); + _nc_unlock_global(tracef); } #endif /* TRACE */ @@ -1099,12 +1101,13 @@ _nc_mouse_parse(int runcount) (merge); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) { + if (USE_TRACEF(TRACE_IEVENT)) { _trace_slot("before mouse event queue compaction:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", (long) (runp - SP->_mouse_events), (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX, runcount); + _nc_unlock_global(tracef); } #endif /* TRACE */ @@ -1117,12 +1120,13 @@ _nc_mouse_parse(int runcount) SP->_mouse_eventp = eventp = prev; } #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) { + if (USE_TRACEF(TRACE_IEVENT)) { _trace_slot("after mouse event queue compaction:"); _tracef("_nc_mouse_parse: run starts at %ld, ends at %ld, count %d", (long) (runp - SP->_mouse_events), (long) ((eventp - SP->_mouse_events) + (EV_MAX - 1)) % EV_MAX, runcount); + _nc_unlock_global(tracef); } for (ep = runp; ep != eventp; ep = NEXT(ep)) if (ep->id != INVALID_EVENT) diff --git a/ncurses/base/lib_refresh.c b/ncurses/base/lib_refresh.c index bc4d21e8..2a9cafb7 100644 --- a/ncurses/base/lib_refresh.c +++ b/ncurses/base/lib_refresh.c @@ -41,7 +41,7 @@ #include -MODULE_ID("$Id: lib_refresh.c,v 1.40 2007/07/07 22:08:38 tom Exp $") +MODULE_ID("$Id: lib_refresh.c,v 1.41 2007/09/29 20:39:34 tom Exp $") NCURSES_EXPORT(int) wrefresh(WINDOW *win) @@ -84,8 +84,10 @@ wnoutrefresh(WINDOW *win) T((T_CALLED("wnoutrefresh(%p)"), win)); #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) + if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("...win", win); + _nc_unlock_global(tracef); + } #endif /* TRACE */ /* @@ -277,8 +279,10 @@ wnoutrefresh(WINDOW *win) newscr->_leaveok = win->_leaveok; #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) + if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("newscr", newscr); + _nc_unlock_global(tracef); + } #endif /* TRACE */ returnCode(OK); } diff --git a/ncurses/base/lib_ungetch.c b/ncurses/base/lib_ungetch.c index a6164df5..9570a33e 100644 --- a/ncurses/base/lib_ungetch.c +++ b/ncurses/base/lib_ungetch.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * Copyright (c) 1998-2002,2007 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 * @@ -40,7 +40,7 @@ #include -MODULE_ID("$Id: lib_ungetch.c,v 1.8 2002/08/24 22:08:48 tom Exp $") +MODULE_ID("$Id: lib_ungetch.c,v 1.9 2007/09/29 21:49:56 tom Exp $") #include @@ -72,8 +72,10 @@ ungetch(int ch) SP->_fifo[head] = ch; T(("ungetch %s ok", _tracechar(ch))); #ifdef TRACE - if (_nc_tracing & TRACE_IEVENT) + if (USE_TRACEF(TRACE_IEVENT)) { _nc_fifo_dump(); + _nc_unlock_global(tracef); + } #endif returnCode(OK); } diff --git a/ncurses/base/resizeterm.c b/ncurses/base/resizeterm.c index 01b5cb60..61761bfa 100644 --- a/ncurses/base/resizeterm.c +++ b/ncurses/base/resizeterm.c @@ -41,7 +41,7 @@ #include #include -MODULE_ID("$Id: resizeterm.c,v 1.21 2007/03/10 23:45:14 tom Exp $") +MODULE_ID("$Id: resizeterm.c,v 1.22 2007/09/29 20:37:13 tom Exp $") #define stolen_lines (screen_lines - SP->_lines_avail) @@ -261,8 +261,10 @@ resize_term(int ToLines, int ToCols) int myCols = CurCols = screen_columns; #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) + if (USE_TRACEF(TRACE_UPDATE)) { show_window_sizes("before"); + _nc_unlock_global(tracef); + } #endif if (ToLines > screen_lines) { increase_size(myLines = ToLines, myCols, was_stolen EXTRA_ARGS); @@ -293,10 +295,11 @@ resize_term(int ToLines, int ToCols) FreeAndNull(SP->newhash); } #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) { + if (USE_TRACEF(TRACE_UPDATE)) { SET_LINES(ToLines - was_stolen); SET_COLS(ToCols); show_window_sizes("after"); + _nc_unlock_global(tracef); } #endif } diff --git a/ncurses/base/tries.c b/ncurses/base/tries.c index c00ef20b..983a75ae 100644 --- a/ncurses/base/tries.c +++ b/ncurses/base/tries.c @@ -39,7 +39,7 @@ #include -MODULE_ID("$Id: tries.c,v 1.24 2007/04/07 17:14:27 tom Exp $") +MODULE_ID("$Id: tries.c,v 1.25 2007/09/29 20:37:13 tom Exp $") /* * Expand a keycode into the string that it corresponds to, returning null if @@ -71,8 +71,10 @@ _nc_expand_try(TRIES * tree, unsigned code, int *count, size_t len) if (ptr != 0 && (result[len] = ptr->ch) == 0) *((unsigned char *) (result + len)) = 128; #ifdef TRACE - if (len == 0 && _nc_tracing != 0) + if (len == 0 && USE_TRACEF(TRACE_MAXIMUM)) { _tracef("expand_key %s %s", _tracechar(code), _nc_visbuf(result)); + _nc_unlock_global(tracef); + } #endif } return result; diff --git a/ncurses/base/wresize.c b/ncurses/base/wresize.c index 604f7f9a..ae62806e 100644 --- a/ncurses/base/wresize.c +++ b/ncurses/base/wresize.c @@ -32,7 +32,7 @@ #include -MODULE_ID("$Id: wresize.c,v 1.25 2007/04/07 17:13:42 tom Exp $") +MODULE_ID("$Id: wresize.c,v 1.26 2007/09/29 20:37:13 tom Exp $") static int cleanup_lines(struct ldat *data, int length) @@ -96,8 +96,10 @@ wresize(WINDOW *win, int ToLines, int ToCols) (long) win->_begy, (long) win->_begx, (long) win->_maxy, (long) win->_maxx, (long) win->_regtop, (long) win->_regbottom)); - if (_nc_tracing & TRACE_UPDATE) + if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("...before", win); + _nc_unlock_global(tracef); + } } #endif @@ -232,8 +234,10 @@ wresize(WINDOW *win, int ToLines, int ToCols) (long) win->_begy, (long) win->_begx, (long) win->_maxy, (long) win->_maxx, (long) win->_regtop, (long) win->_regbottom)); - if (_nc_tracing & TRACE_UPDATE) + if (USE_TRACEF(TRACE_UPDATE)) { _tracedump("...after:", win); + _nc_unlock_global(tracef); + } #endif returnCode(OK); } diff --git a/ncurses/curses.priv.h b/ncurses/curses.priv.h index 973eb998..0aa19fe2 100644 --- a/ncurses/curses.priv.h +++ b/ncurses/curses.priv.h @@ -34,7 +34,7 @@ /* - * $Id: curses.priv.h,v 1.340 2007/09/08 21:44:40 tom Exp $ + * $Id: curses.priv.h,v 1.343 2007/09/29 21:33:24 tom Exp $ * * curses.priv.h * @@ -560,6 +560,9 @@ typedef struct { pthread_mutex_t mutex_set_SP; pthread_mutex_t mutex_use_screen; pthread_mutex_t mutex_windowlist; + pthread_mutex_t mutex_tst_tracef; + pthread_mutex_t mutex_tracef; + int nested_tracef; #endif } NCURSES_GLOBALS; @@ -583,6 +586,10 @@ typedef struct { chtype *real_acs_map; int _LINES; int _COLS; +#ifdef TRACE + long _outchars; + const char *_tputs_trace; +#endif #endif } NCURSES_PRESCREEN; @@ -805,6 +812,10 @@ struct screen { int _TABSIZE; int _LINES; int _COLS; +#ifdef TRACE + int _outchars; + const char *_tputs_trace; +#endif #endif /* * ncurses/ncursesw are the same up to this point. @@ -895,10 +906,16 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; #endif #ifdef TRACE -#define TRACE_OUTCHARS(n) _nc_outchars += (n); +#if USE_REENTRANT +#define COUNT_OUTCHARS(n) _nc_count_outchars(n); #else -#define TRACE_OUTCHARS(n) /* nothing */ +#define COUNT_OUTCHARS(n) _nc_outchars += (n); #endif +#else +#define COUNT_OUTCHARS(n) /* nothing */ +#endif + +#define RESET_OUTCHARS() COUNT_OUTCHARS(-_nc_outchars) #define UChar(c) ((unsigned char)(c)) #define ChCharOf(c) ((c) & (chtype)A_CHARTEXT) @@ -945,7 +962,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; #define PUTC(ch,b) do { if(!isWidecExt(ch)) { \ if (Charable(ch)) { \ fputc(CharOf(ch), b); \ - TRACE_OUTCHARS(1); \ + COUNT_OUTCHARS(1); \ } else { \ PUTC_INIT; \ for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { \ @@ -961,7 +978,7 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; } \ fwrite(PUTC_buf, (unsigned) PUTC_n, 1, b); \ } \ - TRACE_OUTCHARS(PUTC_i); \ + COUNT_OUTCHARS(PUTC_i); \ } } } while (0) #define BLANK { WA_NORMAL, {' '} NulColor } @@ -1091,6 +1108,12 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; #ifdef TRACE +#if USE_REENTRANT +#define TPUTS_TRACE(s) _nc_set_tputs_trace(s); +#else +#define TPUTS_TRACE(s) _nc_tputs_trace = s; +#endif + #define START_TRACE() \ if ((_nc_tracing & TRACE_MAXIMUM) == 0) { \ int t = _nc_getenv_num("NCURSES_TRACE"); \ @@ -1098,9 +1121,21 @@ extern NCURSES_EXPORT_VAR(SIG_ATOMIC_T) _nc_have_sigwinch; trace((unsigned) t); \ } -#define TR(n, a) if (_nc_tracing & (n)) _tracef a +/* + * Many of the _tracef() calls use static buffers; lock the trace state before + * trying to fill them. + */ +#if USE_REENTRANT +#define USE_TRACEF(mask) _nc_use_tracef(mask) +extern NCURSES_EXPORT(int) _nc_use_tracef (unsigned); +extern NCURSES_EXPORT(void) _nc_locked_tracef (const char *, ...) GCC_PRINTFLIKE(1,2); +#else +#define USE_TRACEF(mask) (_nc_tracing & (mask)) +#define _nc_locked_tracef _tracef +#endif + +#define TR(n, a) if (USE_TRACEF(n)) _nc_locked_tracef a #define T(a) TR(TRACE_CALLS, a) -#define TPUTS_TRACE(s) _nc_tputs_trace = s; #define TRACE_RETURN(value,type) return _nc_retrace_##type(value) #define returnAttr(code) TRACE_RETURN(code,attr_t) @@ -1131,8 +1166,19 @@ extern NCURSES_EXPORT(int) _nc_retrace_int (int); extern NCURSES_EXPORT(unsigned) _nc_retrace_unsigned (unsigned); extern NCURSES_EXPORT(void *) _nc_retrace_void_ptr (void *); extern NCURSES_EXPORT(void) _nc_fifo_dump (void); + +#if USE_REENTRANT +NCURSES_WRAPPED_VAR(long, _nc_outchars); +NCURSES_WRAPPED_VAR(const char *, _nc_tputs_trace); +#define _nc_outchars NCURSES_PUBLIC_VAR(_nc_outchars()) +#define _nc_tputs_trace NCURSES_PUBLIC_VAR(_nc_tputs_trace()) +extern NCURSES_EXPORT(void) _nc_set_tputs_trace (const char *); +extern NCURSES_EXPORT(void) _nc_count_outchars (long); +#else extern NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace; extern NCURSES_EXPORT_VAR(long) _nc_outchars; +#endif + extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; #if USE_WIDEC_SUPPORT diff --git a/ncurses/tinfo/lib_acs.c b/ncurses/tinfo/lib_acs.c index b7909f05..6a242854 100644 --- a/ncurses/tinfo/lib_acs.c +++ b/ncurses/tinfo/lib_acs.c @@ -35,7 +35,7 @@ #include #include /* ena_acs, acs_chars */ -MODULE_ID("$Id: lib_acs.c,v 1.33 2007/04/21 23:31:24 tom Exp $") +MODULE_ID("$Id: lib_acs.c,v 1.34 2007/09/29 20:37:13 tom Exp $") #if BROKEN_LINKER || USE_REENTRANT #define MyBuffer _nc_prescreen.real_acs_map @@ -166,7 +166,7 @@ _nc_init_acs(void) /* Show the equivalent mapping, noting if it does not match the * given attribute, whether by re-ordering or duplication. */ - if (_nc_tracing & TRACE_CALLS) { + if (USE_TRACEF(TRACE_CALLS)) { size_t n, m; char show[ACS_LEN * 2 + 1]; for (n = 1, m = 0; n < ACS_LEN; n++) { @@ -187,6 +187,7 @@ _nc_init_acs(void) ? "DIFF" : "SAME"), _nc_visbuf(show)); + _nc_unlock_global(tracef); } #endif /* TRACE */ } diff --git a/ncurses/tinfo/lib_data.c b/ncurses/tinfo/lib_data.c index 063a566f..65fb7db2 100644 --- a/ncurses/tinfo/lib_data.c +++ b/ncurses/tinfo/lib_data.c @@ -41,7 +41,7 @@ #include -MODULE_ID("$Id: lib_data.c,v 1.30 2007/09/08 21:59:56 tom Exp $") +MODULE_ID("$Id: lib_data.c,v 1.32 2007/09/29 21:34:21 tom Exp $") /* * OS/2's native linker complains if we don't initialize public data when @@ -180,6 +180,9 @@ NCURSES_EXPORT_VAR(NCURSES_GLOBALS) _nc_globals = { PTHREAD_MUTEX_INITIALIZER, /* mutex_set_SP */ PTHREAD_MUTEX_INITIALIZER, /* mutex_use_screen */ PTHREAD_MUTEX_INITIALIZER, /* mutex_windowlist */ + PTHREAD_MUTEX_INITIALIZER, /* mutex_tst_tracef */ + PTHREAD_MUTEX_INITIALIZER, /* mutex_tracef */ + 0, /* nested_tracef */ #endif }; @@ -220,6 +223,10 @@ NCURSES_EXPORT_VAR(NCURSES_PRESCREEN) _nc_prescreen = { NULL, /* real_acs_map */ 0, /* LINES */ 0, /* COLS */ +#ifdef TRACE + 0L, /* _outchars */ + NULL, /* _tputs_trace */ +#endif #endif }; /* *INDENT-ON* */ diff --git a/ncurses/tinfo/lib_raw.c b/ncurses/tinfo/lib_raw.c index aa09f52c..58e71889 100644 --- a/ncurses/tinfo/lib_raw.c +++ b/ncurses/tinfo/lib_raw.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2001,2002 Free Software Foundation, Inc. * + * Copyright (c) 1998-2002,2007 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 * @@ -49,7 +49,7 @@ #include #include /* cur_term */ -MODULE_ID("$Id: lib_raw.c,v 1.13 2002/07/06 22:00:45 tom Exp $") +MODULE_ID("$Id: lib_raw.c,v 1.14 2007/09/29 21:50:22 tom Exp $") #if SVR4_TERMIO && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE @@ -69,8 +69,8 @@ MODULE_ID("$Id: lib_raw.c,v 1.13 2002/07/06 22:00:45 tom Exp $") #define COOKED_INPUT (IXON|BRKINT|PARMRK) #ifdef TRACE -#define BEFORE(N) if (_nc_tracing&TRACE_BITS) _tracef("%s before bits: %s", N, _nc_tracebits()) -#define AFTER(N) if (_nc_tracing&TRACE_BITS) _tracef("%s after bits: %s", N, _nc_tracebits()) +#define BEFORE(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s before bits: %s", N, _nc_tracebits()) +#define AFTER(N) if (USE_TRACEF(TRACE_BITS)) _nc_locked_tracef("%s after bits: %s", N, _nc_tracebits()) #else #define BEFORE(s) #define AFTER(s) diff --git a/ncurses/tinfo/lib_tparm.c b/ncurses/tinfo/lib_tparm.c index 6a19ab9f..d11fcf80 100644 --- a/ncurses/tinfo/lib_tparm.c +++ b/ncurses/tinfo/lib_tparm.c @@ -43,7 +43,7 @@ #include #include -MODULE_ID("$Id: lib_tparm.c,v 1.73 2007/04/21 20:43:19 tom Exp $") +MODULE_ID("$Id: lib_tparm.c,v 1.74 2007/09/29 20:37:13 tom Exp $") /* * char * @@ -508,7 +508,7 @@ tparam_internal(const char *string, va_list ap) npush(param[i]); } #ifdef TRACE - if (_nc_tracing & TRACE_CALLS) { + if (USE_TRACEF(TRACE_CALLS)) { for (i = 0; i < popcount; i++) { if (p_is_s[i] != 0) save_text(", %s", _nc_visbuf(p_is_s[i]), 0); @@ -517,6 +517,7 @@ tparam_internal(const char *string, va_list ap) } _tracef(T_CALLED("%s(%s%s)"), TPS(tname), _nc_visbuf(cp), TPS(out_buff)); TPS(out_used) = 0; + _nc_unlock_global(tracef); } #endif /* TRACE */ diff --git a/ncurses/tinfo/lib_tputs.c b/ncurses/tinfo/lib_tputs.c index 3a18ffd7..aab33519 100644 --- a/ncurses/tinfo/lib_tputs.c +++ b/ncurses/tinfo/lib_tputs.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2002,2003 Free Software Foundation, Inc. * + * Copyright (c) 1998-2003,2007 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 * @@ -45,12 +45,12 @@ #include /* ospeed */ #include -MODULE_ID("$Id: lib_tputs.c,v 1.62 2003/08/23 21:39:20 tom Exp $") +MODULE_ID("$Id: lib_tputs.c,v 1.64 2007/09/29 20:37:13 tom Exp $") -NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */ -NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */ +NCURSES_EXPORT_VAR(char) PC = 0; /* used by termcap library */ +NCURSES_EXPORT_VAR(NCURSES_OSPEED) ospeed = 0; /* used by termcap library */ -NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */ +NCURSES_EXPORT_VAR(int) _nc_nulls_sent = 0; /* used by 'tack' program */ static int (*my_outch) (int c) = _nc_outch; @@ -84,7 +84,7 @@ _nc_flush(void) NCURSES_EXPORT(int) _nc_outch(int ch) { - TRACE_OUTCHARS(1); + COUNT_OUTCHARS(1); if (SP != 0 && SP->_cleanup) { @@ -119,7 +119,7 @@ tputs(const char *string, int affcnt, int (*outc) (int)) #ifdef TRACE char addrbuf[32]; - if (_nc_tracing & TRACE_TPUTS) { + if (USE_TRACEF(TRACE_TPUTS)) { if (outc == _nc_outch) (void) strcpy(addrbuf, "_nc_outch"); else @@ -130,7 +130,8 @@ tputs(const char *string, int affcnt, int (*outc) (int)) } else { _tracef("tputs(%s, %d, %s) called", _nc_visbuf(string), affcnt, addrbuf); } - _nc_tputs_trace = (char *) NULL; + TPUTS_TRACE(NULL); + _nc_unlock_global(tracef); } #endif /* TRACE */ diff --git a/ncurses/trace/lib_trace.c b/ncurses/trace/lib_trace.c index 34973daa..d634438a 100644 --- a/ncurses/trace/lib_trace.c +++ b/ncurses/trace/lib_trace.c @@ -46,13 +46,43 @@ #include -MODULE_ID("$Id: lib_trace.c,v 1.62 2007/07/14 19:32:54 tom Exp $") +MODULE_ID("$Id: lib_trace.c,v 1.65 2007/09/29 21:47:46 tom Exp $") NCURSES_EXPORT_VAR(unsigned) _nc_tracing = 0; /* always define this */ #ifdef TRACE + +#if USE_REENTRANT +NCURSES_EXPORT(const char *) +NCURSES_PUBLIC_VAR(_nc_tputs_trace) (void) +{ + return SP ? SP->_tputs_trace : _nc_prescreen._tputs_trace; +} +NCURSES_EXPORT(long) +NCURSES_PUBLIC_VAR(_nc_outchars) (void) +{ + return SP ? SP->_outchars : _nc_prescreen._outchars; +} +NCURSES_EXPORT(void) +_nc_set_tputs_trace(const char *s) +{ + if (SP) + SP->_tputs_trace = s; + else + _nc_prescreen._tputs_trace = s; +} +NCURSES_EXPORT(void) +_nc_count_outchars(long increment) +{ + if (SP) + SP->_outchars += increment; + else + _nc_prescreen._outchars += increment; +} +#else NCURSES_EXPORT_VAR(const char *) _nc_tputs_trace = ""; NCURSES_EXPORT_VAR(long) _nc_outchars = 0; +#endif #define TraceFP _nc_globals.trace_fp #define TracePath _nc_globals.trace_fname @@ -107,12 +137,12 @@ trace(const unsigned int tracelevel) } } -NCURSES_EXPORT(void) -_tracef(const char *fmt,...) +static void +_nc_va_tracef(const char *fmt, va_list ap) { static const char Called[] = T_CALLED(""); static const char Return[] = T_RETURN(""); - va_list ap; + bool before = FALSE; bool after = FALSE; unsigned doit = _nc_tracing; @@ -142,18 +172,27 @@ _tracef(const char *fmt,...) for (n = 1; n < TraceLevel; n++) fputs("+ ", TraceFP); } - va_start(ap, fmt); vfprintf(TraceFP, fmt, ap); fputc('\n', TraceFP); - va_end(ap); fflush(TraceFP); } if (after && TraceLevel) TraceLevel--; + errno = save_err; } +NCURSES_EXPORT(void) +_tracef(const char *fmt,...) +{ + va_list ap; + + va_start(ap, fmt); + _nc_va_tracef(fmt, ap); + va_end(ap); +} + /* Trace 'bool' return-values */ NCURSES_EXPORT(NCURSES_BOOL) _nc_retrace_bool(NCURSES_BOOL code) @@ -225,4 +264,53 @@ _nc_retrace_win(WINDOW *code) T((T_RETURN("%p"), code)); return code; } + +#if USE_REENTRANT +/* + * Check if the given trace-mask is enabled. + * + * This function may be called from within one of the functions that fills + * in parameters for _tracef(), but in that case we do not want to lock the + * mutex, since it is already locked. + */ +NCURSES_EXPORT(int) +_nc_use_tracef(unsigned mask) +{ + bool result = FALSE; + + _nc_lock_global(tst_tracef); + if (!_nc_globals.nested_tracef++) { + if ((result = (_nc_tracing & (mask))) != 0) { + /* we will call _nc_locked_tracef(), no nesting so far */ + _nc_lock_global(tracef); + } else { + /* we will not call _nc_locked_tracef() */ + _nc_globals.nested_tracef = 0; + } + } else { + /* we may call _nc_locked_tracef(), but with nested_tracef > 0 */ + result = (_nc_tracing & (mask)); + } + _nc_unlock_global(tst_tracef); + return result; +} + +/* + * We call this if _nc_use_tracef() returns true, which means we must unlock + * the tracef mutex. + */ +NCURSES_EXPORT(void) +_nc_locked_tracef(const char *fmt,...) +{ + va_list ap; + + va_start(ap, fmt); + _nc_va_tracef(fmt, ap); + va_end(ap); + + if (--(_nc_globals.nested_tracef) == 0) + _nc_unlock_global(tracef); +} +#endif /* USE_REENTRANT */ + #endif /* TRACE */ diff --git a/ncurses/tty/hardscroll.c b/ncurses/tty/hardscroll.c index 0b227a10..7d8979a4 100644 --- a/ncurses/tty/hardscroll.c +++ b/ncurses/tty/hardscroll.c @@ -145,7 +145,7 @@ AUTHOR #include -MODULE_ID("$Id: hardscroll.c,v 1.40 2007/06/30 21:11:01 tom Exp $") +MODULE_ID("$Id: hardscroll.c,v 1.41 2007/09/29 21:48:36 tom Exp $") #if defined(SCROLLDEBUG) || defined(HASHDEBUG) @@ -158,7 +158,7 @@ oldnums[MAXLINES]; # undef TR # define TR(n, a) if (_nc_tracing & (n)) { _tracef a ; putchar('\n'); } -extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; +extern NCURSES_EXPORT_VAR(unsigned) _nc_tracing; #else /* no debug */ @@ -204,8 +204,10 @@ _nc_scroll_optimize(void) #endif /* !defined(SCROLLDEBUG) && !defined(HASHDEBUG) */ #ifdef TRACE - if (_nc_tracing & (TRACE_UPDATE | TRACE_MOVE)) + if (USE_TRACEF(TRACE_UPDATE | TRACE_MOVE)) { _nc_linedump(); + _nc_unlock_global(tracef); + } #endif /* TRACE */ /* pass 1 - from top to bottom scrolling up */ diff --git a/ncurses/tty/tty_update.c b/ncurses/tty/tty_update.c index 15510ce4..33c79c7c 100644 --- a/ncurses/tty/tty_update.c +++ b/ncurses/tty/tty_update.c @@ -74,7 +74,7 @@ #include #include -MODULE_ID("$Id: tty_update.c,v 1.240 2007/06/30 21:07:51 tom Exp $") +MODULE_ID("$Id: tty_update.c,v 1.242 2007/09/29 20:37:13 tom Exp $") /* * This define controls the line-breakout optimization. Every once in a @@ -289,7 +289,7 @@ PutAttrChar(CARG_CH_T ch) #endif { PUTC(CHDEREF(ch), SP->_ofp); /* macro's fastest... */ - TRACE_OUTCHARS(1); + COUNT_OUTCHARS(1); } SP->_curscol += chlen; if (char_padding) { @@ -625,12 +625,13 @@ doupdate(void) T((T_CALLED("doupdate()"))); #ifdef TRACE - if (_nc_tracing & TRACE_UPDATE) { + if (USE_TRACEF(TRACE_UPDATE)) { if (curscr->_clear) _tracef("curscr is clear"); else _tracedump("curscr", curscr); _tracedump("newscr", newscr); + _nc_unlock_global(tracef); } #endif /* TRACE */ @@ -666,7 +667,7 @@ doupdate(void) } #if USE_TRACE_TIMES /* zero the metering machinery */ - _nc_outchars = 0; + RESET_OUTCHARS(); (void) times(&before); #endif /* USE_TRACE_TIMES */ @@ -826,9 +827,10 @@ doupdate(void) #ifdef TRACE /* show altered highlights after magic-cookie check */ - if (_nc_tracing & TRACE_UPDATE) { + if (USE_TRACEF(TRACE_UPDATE)) { _tracef("After magic-cookie check..."); _tracedump("newscr", newscr); + _nc_unlock_global(tracef); } #endif /* TRACE */ } diff --git a/progs/tset.c b/progs/tset.c index b34e47e3..20679c5e 100644 --- a/progs/tset.c +++ b/progs/tset.c @@ -103,7 +103,7 @@ char *ttyname(int fd); #include #include -MODULE_ID("$Id: tset.c,v 1.68 2007/07/21 17:46:24 tom Exp $") +MODULE_ID("$Id: tset.c,v 1.69 2007/09/29 15:51:35 tom Exp $") extern char **environ; @@ -777,7 +777,22 @@ reset_mode(void) | OFDEL #endif #ifdef NLDLY - | NLDLY | CRDLY | TABDLY | BSDLY | VTDLY | FFDLY + | NLDLY +#endif +#ifdef CRDLY + | CRDLY +#endif +#ifdef TABDLY + | TABDLY +#endif +#ifdef BSDLY + | BSDLY +#endif +#ifdef VTDLY + | VTDLY +#endif +#ifdef FFDLY + | FFDLY #endif ); diff --git a/test/worm.c b/test/worm.c index 4692668b..534e626e 100644 --- a/test/worm.c +++ b/test/worm.c @@ -61,11 +61,15 @@ Options: traces will be dumped. The program stops and waits for one character of input at the beginning and end of the interval. - $Id: worm.c,v 1.48 2007/09/15 21:42:16 tom Exp $ + $Id: worm.c,v 1.49 2007/09/29 17:35:57 tom Exp $ */ #include +#ifdef USE_PTHREADS +#include +#endif + static chtype flavor[] = { 'O', '*', '#', '$', '%', '0', '@', @@ -84,6 +88,9 @@ typedef struct worm { short *xpos; short *ypos; chtype attrs; +#ifdef USE_PTHREADS + pthread_t thread; +#endif } WORM; static WORM worm[40]; @@ -299,12 +306,49 @@ draw_worm(WINDOW *win, void *data) #if !defined(NCURSES_VERSION_PATCH) || (NCURSES_VERSION_PATCH < 20070915) static int -use_window(WINDOW *win, int (*func)(WINDOW *, void *), void *data) +use_window(WINDOW *win, int (*func) (WINDOW *, void *), void *data) { return func(win, data); } #endif +#ifdef USE_PTHREADS +static void * +start_worm(void *arg) +{ + for (;;) { + napms(20); + use_window(stdscr, draw_worm, arg); + } + return NULL; +} +#endif + +static bool +draw_all_worms(void) +{ + bool done = FALSE; + int n; + struct worm *w; + +#ifdef USE_PTHREADS + static bool first = TRUE; + if (first) { + first = FALSE; + for (n = 0, w = &worm[0]; n < number; n++, w++) { + int rc; + rc = pthread_create(&(w->thread), NULL, start_worm, w); + } + } +#else + for (n = 0, w = &worm[0]; n < number; n++, w++) { + if (use_window(stdscr, draw_worm, w)) + done = TRUE; + } +#endif + return done; +} + int main(int argc, char *argv[]) { @@ -498,10 +542,7 @@ main(int argc, char *argv[]) } } - for (n = 0, w = &worm[0]; n < number; n++, w++) { - if (use_window(stdscr, draw_worm, w)) - done = TRUE; - } + done = draw_all_worms(); napms(10); refresh(); }