X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftrace%2Flib_tracebits.c;h=7d8325a828f4e042635fb9d9374f781a4a21c77e;hp=d9defd0cc9d66d3502cd0b4b0a310af97776562e;hb=b0b1980be11bba618d84beb8b30ac94e2c820602;hpb=027ae42953e3186daed8f3882da73de48291b606 diff --git a/ncurses/trace/lib_tracebits.c b/ncurses/trace/lib_tracebits.c index d9defd0c..7d8325a8 100644 --- a/ncurses/trace/lib_tracebits.c +++ b/ncurses/trace/lib_tracebits.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2011,2012 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 * @@ -33,13 +33,8 @@ ****************************************************************************/ #include -#include /* cur_term */ -MODULE_ID("$Id: lib_tracebits.c,v 1.13 2006/12/10 01:33:00 tom Exp $") - -#if SVR4_TERMIO && !defined(_POSIX_SOURCE) -#define _POSIX_SOURCE -#endif +MODULE_ID("$Id: lib_tracebits.c,v 1.23 2012/06/09 19:55:46 tom Exp $") #if HAVE_SYS_TERMIO_H #include /* needed for ISC */ @@ -53,10 +48,27 @@ MODULE_ID("$Id: lib_tracebits.c,v 1.13 2006/12/10 01:33:00 tom Exp $") #ifndef TOSTOP #define TOSTOP 0 #endif + #ifndef IEXTEN #define IEXTEN 0 #endif +#ifndef ONLCR +#define ONLCR 0 +#endif + +#ifndef OCRNL +#define OCRNL 0 +#endif + +#ifndef ONOCR +#define ONOCR 0 +#endif + +#ifndef ONLRET +#define ONLRET 0 +#endif + #ifdef TRACE typedef struct { @@ -64,22 +76,24 @@ typedef struct { const char *name; } BITNAMES; +#define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size) + static void lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int val) { const BITNAMES *sp; - (void) strcat(buf, label); - (void) strcat(buf, ": {"); + _nc_STRCAT(buf, label, TRACE_BUF_SIZE(0)); + _nc_STRCAT(buf, ": {", TRACE_BUF_SIZE(0)); for (sp = table; sp->name; sp++) if (sp->val != 0 && (val & sp->val) == sp->val) { - (void) strcat(buf, sp->name); - (void) strcat(buf, ", "); + _nc_STRCAT(buf, sp->name, TRACE_BUF_SIZE(0)); + _nc_STRCAT(buf, ", ", TRACE_BUF_SIZE(0)); } if (buf[strlen(buf) - 2] == ',') buf[strlen(buf) - 2] = '\0'; - (void) strcat(buf, "} "); + _nc_STRCAT(buf, "} ", TRACE_BUF_SIZE(0)); } NCURSES_EXPORT(char *) @@ -108,8 +122,12 @@ _nc_trace_ttymode(TTY * tty) { {OPOST, "OPOST"}, {OFLAGS_TABS, "XTABS"}, + {ONLCR, "ONLCR"}, + {OCRNL, "OCRNL"}, + {ONOCR, "ONOCR"}, + {ONLRET, "ONLRET"}, {0, NULL} -#define ALLOUT (OPOST) +#define ALLOUT (OPOST|OFLAGS_TABS|ONLCR|OCRNL|ONOCR|ONLRET) }, cflags[] = { {CLOCAL, "CLOCAL"}, @@ -144,58 +162,52 @@ _nc_trace_ttymode(TTY * tty) 8 + sizeof(cflags) + 8 + sizeof(lflags) + 8); + if (buf != 0) { - if (tty->c_iflag & ALLIN) - lookup_bits(buf, iflags, "iflags", tty->c_iflag); + if (tty->c_iflag & ALLIN) + lookup_bits(buf, iflags, "iflags", tty->c_iflag); - if (tty->c_oflag & ALLOUT) - lookup_bits(buf, oflags, "oflags", tty->c_oflag); + if (tty->c_oflag & ALLOUT) + lookup_bits(buf, oflags, "oflags", tty->c_oflag); - if (tty->c_cflag & ALLCTRL) - lookup_bits(buf, cflags, "cflags", tty->c_cflag); + if (tty->c_cflag & ALLCTRL) + lookup_bits(buf, cflags, "cflags", tty->c_cflag); #if defined(CS5) && defined(CS8) - { - static struct { - const char *name; - int value; - } csizes[] = { - { - "CS5 ", CS5 - }, + { + static struct { + int value; + const char *name; + } csizes[] = { +#define CS_DATA(name) { name, #name " " } + CS_DATA(CS5), #ifdef CS6 - { - "CS6 ", CS6 - }, + CS_DATA(CS6), #endif #ifdef CS7 - { - "CS7 ", CS7 - }, -#endif - { - "CS8 ", CS8 - }, - }; - const char *result = "CSIZE? "; - int value = (tty->c_cflag & CSIZE); - unsigned n; - - if (value != 0) { - for (n = 0; n < SIZEOF(csizes); n++) { - if (csizes[n].value == value) { - result = csizes[n].name; - break; + CS_DATA(CS7), +#endif + CS_DATA(CS8), + }; + const char *result = "CSIZE? "; + int value = (int) (tty->c_cflag & CSIZE); + unsigned n; + + if (value != 0) { + for (n = 0; n < SIZEOF(csizes); n++) { + if (csizes[n].value == value) { + result = csizes[n].name; + break; + } } } + _nc_STRCAT(buf, result, TRACE_BUF_SIZE(0)); } - strcat(buf, result); - } #endif - if (tty->c_lflag & ALLLOCAL) - lookup_bits(buf, lflags, "lflags", tty->c_lflag); - + if (tty->c_lflag & ALLLOCAL) + lookup_bits(buf, lflags, "lflags", tty->c_lflag); + } #else /* reference: ttcompat(4M) on SunOS 4.1 */ #ifndef EVENP @@ -232,9 +244,10 @@ _nc_trace_ttymode(TTY * tty) buf = _nc_trace_buf(0, 8 + sizeof(cflags)); - - if (tty->sg_flags & ALLCTRL) { - lookup_bits(buf, cflags, "cflags", tty->sg_flags); + if (buf != 0) { + if (tty->sg_flags & ALLCTRL) { + lookup_bits(buf, cflags, "cflags", tty->sg_flags); + } } #endif return (buf); @@ -246,5 +259,5 @@ _nc_tracebits(void) return _nc_trace_ttymode(&(cur_term->Nttyb)); } #else -empty_module(_nc_tracebits) +EMPTY_MODULE(_nc_empty_lib_tracebits) #endif /* TRACE */