X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftrace%2Flib_tracebits.c;h=de2394c39225353c2f43fb91c7fb43a65922eb2e;hp=6dbb2f793ad0d1bbea81ace51c09edc9d110c0a7;hb=7c4bc0fa99a1be37a14aa19a5943a549570954c4;hpb=b1f61d9f3aa244512045a6b02e759825d7049d34 diff --git a/ncurses/trace/lib_tracebits.c b/ncurses/trace/lib_tracebits.c index 6dbb2f79..de2394c3 100644 --- a/ncurses/trace/lib_tracebits.c +++ b/ncurses/trace/lib_tracebits.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998,1999,2000 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 * @@ -29,14 +29,15 @@ /**************************************************************************** * Author: Zeyd M. Ben-Halim 1992,1995 * * and: Eric S. Raymond * + * and: Thomas E. Dickey 1996-on * ****************************************************************************/ #include #include /* cur_term */ -MODULE_ID("$Id: lib_tracebits.c,v 1.5 2000/02/13 01:01:55 tom Exp $") +MODULE_ID("$Id: lib_tracebits.c,v 1.15 2007/06/30 16:14:20 tom Exp $") -#if defined(SVR4_TERMIO) && !defined(_POSIX_SOURCE) +#if SVR4_TERMIO && !defined(_POSIX_SOURCE) #define _POSIX_SOURCE #endif @@ -52,10 +53,27 @@ MODULE_ID("$Id: lib_tracebits.c,v 1.5 2000/02/13 01:01:55 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 { @@ -81,8 +99,8 @@ lookup_bits(char *buf, const BITNAMES * table, const char *label, unsigned int v (void) strcat(buf, "} "); } -char * -_nc_tracebits(void) +NCURSES_EXPORT(char *) +_nc_trace_ttymode(TTY * tty) /* describe the state of the terminal control bits exactly */ { char *buf; @@ -106,8 +124,13 @@ _nc_tracebits(void) }, oflags[] = { {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"}, @@ -137,51 +160,62 @@ _nc_tracebits(void) }; buf = _nc_trace_buf(0, - 8 + sizeof(iflags) + - 8 + sizeof(oflags) + - 8 + sizeof(cflags) + - 8 + sizeof(lflags) + - 8); + 8 + sizeof(iflags) + + 8 + sizeof(oflags) + + 8 + sizeof(cflags) + + 8 + sizeof(lflags) + + 8); - if (cur_term->Nttyb.c_iflag & ALLIN) - lookup_bits(buf, iflags, "iflags", cur_term->Nttyb.c_iflag); + if (tty->c_iflag & ALLIN) + lookup_bits(buf, iflags, "iflags", tty->c_iflag); - if (cur_term->Nttyb.c_oflag & ALLOUT) - lookup_bits(buf, oflags, "oflags", cur_term->Nttyb.c_oflag); + if (tty->c_oflag & ALLOUT) + lookup_bits(buf, oflags, "oflags", tty->c_oflag); - if (cur_term->Nttyb.c_cflag & ALLCTRL) - lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.c_cflag); + if (tty->c_cflag & ALLCTRL) + lookup_bits(buf, cflags, "cflags", tty->c_cflag); #if defined(CS5) && defined(CS8) - switch (cur_term->Nttyb.c_cflag & CSIZE) { -#if defined(CS5) && (CS5 != 0) - case CS5: - strcat(buf, "CS5 "); - break; -#endif -#if defined(CS6) && (CS6 != 0) - case CS6: - strcat(buf, "CS6 "); - break; -#endif -#if defined(CS7) && (CS7 != 0) - case CS7: - strcat(buf, "CS7 "); - break; -#endif -#if defined(CS8) && (CS8 != 0) - case CS8: - strcat(buf, "CS8 "); - break; -#endif - default: - strcat(buf, "CSIZE? "); - break; + { + static struct { + const char *name; + int value; + } csizes[] = { + { + "CS5 ", CS5 + }, +#ifdef CS6 + { + "CS6 ", 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; + } + } + } + strcat(buf, result); } #endif - if (cur_term->Nttyb.c_lflag & ALLLOCAL) - lookup_bits(buf, lflags, "lflags", cur_term->Nttyb.c_lflag); + if (tty->c_lflag & ALLLOCAL) + lookup_bits(buf, lflags, "lflags", tty->c_lflag); #else /* reference: ttcompat(4M) on SunOS 4.1 */ @@ -218,19 +252,20 @@ _nc_tracebits(void) }; buf = _nc_trace_buf(0, - 8 + sizeof(cflags)); + 8 + sizeof(cflags)); - if (cur_term->Nttyb.sg_flags & ALLCTRL) { - lookup_bits(buf, cflags, "cflags", cur_term->Nttyb.sg_flags); + if (tty->sg_flags & ALLCTRL) { + lookup_bits(buf, cflags, "cflags", tty->sg_flags); } #endif return (buf); } -#else -char * + +NCURSES_EXPORT(char *) _nc_tracebits(void) { - static char tmp[] = ""; - return tmp; + return _nc_trace_ttymode(&(cur_term->Nttyb)); } +#else +empty_module(_nc_tracebits) #endif /* TRACE */