X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=ncurses%2Ftrace%2Flib_traceatr.c;h=07424222ec00c8814d95b285421e11552bbd1c69;hp=368ecd7967278525c53635057a807c8d0d655a8f;hb=ba78eb501a2ed01647123dbe7279ca0f38782e04;hpb=7a6bbc8cf41c5186d46accc3d08622dc86526b34 diff --git a/ncurses/trace/lib_traceatr.c b/ncurses/trace/lib_traceatr.c index 368ecd79..07424222 100644 --- a/ncurses/trace/lib_traceatr.c +++ b/ncurses/trace/lib_traceatr.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2008,2009 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 * @@ -39,10 +39,17 @@ #include -MODULE_ID("$Id: lib_traceatr.c,v 1.65 2009/04/18 18:06:31 tom Exp $") +#ifndef CUR +#define CUR SP_TERMTYPE +#endif + +MODULE_ID("$Id: lib_traceatr.c,v 1.79 2012/02/22 22:40:24 tom Exp $") #define COLOR_OF(c) ((c < 0) ? "default" : (c > 7 ? color_of(c) : colors[c].name)) +#define TRACE_BUF_SIZE(num) (_nc_globals.tracebuf_ptr[num].size) +#define COLOR_BUF_SIZE(num) (sizeof(my_buffer[num])) + #ifdef TRACE static const char l_brace[] = StringOf(L_BRACE); @@ -61,9 +68,12 @@ color_of(int c) my_cached = c; my_select = !my_select; if (c == COLOR_DEFAULT) - strcpy(my_buffer[my_select], "default"); + _nc_STRCPY(my_buffer[my_select], "default", + COLOR_BUF_SIZE(my_select)); else - sprintf(my_buffer[my_select], "color%d", c); + _nc_SPRINTF(my_buffer[my_select], + _nc_SLIMIT(COLOR_BUF_SIZE(my_select)) + "color%d", c); } return my_buffer[my_select]; } @@ -116,37 +126,39 @@ _traceattr2(int bufnum, chtype newmode) ; size_t n; char temp[80]; - char *result = _nc_trace_buf(bufnum, BUFSIZ); + char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ); if (result != 0) { unsigned save_nc_tracing = _nc_tracing; _nc_tracing = 0; - strcpy(result, l_brace); + _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum)); for (n = 0; n < SIZEOF(names); n++) { if ((newmode & names[n].val) != 0) { if (result[1] != '\0') - result = _nc_trace_bufcat(bufnum, "|"); + (void) _nc_trace_bufcat(bufnum, "|"); result = _nc_trace_bufcat(bufnum, names[n].name); if (names[n].val == A_COLOR) { - short pairnum = PAIR_NUMBER(newmode); + short pairnum = (short) PairNumber(newmode); #ifdef USE_TERMLIB /* pair_content lives in libncurses */ - (void) sprintf(temp, "{%d}", pairnum); + _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) + "{%d}", pairnum); #else short fg, bg; if (pair_content(pairnum, &fg, &bg) == OK) { - (void) sprintf(temp, - "{%d = {%s, %s}}", - pairnum, - COLOR_OF(fg), - COLOR_OF(bg)); + _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) + "{%d = {%s, %s}}", + pairnum, + COLOR_OF(fg), + COLOR_OF(bg)); } else { - (void) sprintf(temp, "{%d}", pairnum); + _nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp)) + "{%d}", pairnum); } #endif result = _nc_trace_bufcat(bufnum, temp); @@ -172,6 +184,14 @@ _traceattr(attr_t newmode) } /* Trace 'int' return-values */ +NCURSES_EXPORT(int) +_nc_retrace_int_attr_t(attr_t code) +{ + T((T_RETURN("%s"), _traceattr(code))); + return (int) code; +} + +/* Trace 'attr_t' return-values */ NCURSES_EXPORT(attr_t) _nc_retrace_attr_t(attr_t code) { @@ -228,20 +248,23 @@ _nc_altcharset_name(attr_t attr, chtype ch) const char *result = 0; - if ((attr & A_ALTCHARSET) && (acs_chars != 0)) { +#if NCURSES_SP_FUNCS + (void) sp; +#endif + if (SP_PARM != 0 && (attr & A_ALTCHARSET) && (acs_chars != 0)) { char *cp; char *found = 0; const ALT_NAMES *strp; for (cp = acs_chars; cp[0] && cp[1]; cp += 2) { - if (ChCharOf(cp[1]) == ChCharOf(ch)) { + if (ChCharOf(UChar(cp[1])) == ChCharOf(ch)) { found = cp; /* don't exit from loop - there may be redefinitions */ } } if (found != 0) { - ch = ChCharOf(*found); + ch = ChCharOf(UChar(*found)); for (strp = names; strp->val; strp++) if (strp->val == ch) { result = strp->name; @@ -256,10 +279,10 @@ NCURSES_EXPORT(char *) _tracechtype2(int bufnum, chtype ch) { const char *found; - char *result = _nc_trace_buf(bufnum, BUFSIZ); + char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ); if (result != 0) { - strcpy(result, l_brace); + _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum)); if ((found = _nc_altcharset_name(ChAttrOf(ch), ch)) != 0) { (void) _nc_trace_bufcat(bufnum, found); } else @@ -296,12 +319,12 @@ _nc_retrace_chtype(chtype code) NCURSES_EXPORT(char *) _tracecchar_t2(int bufnum, const cchar_t *ch) { - char *result = _nc_trace_buf(bufnum, BUFSIZ); + char *result = _nc_trace_buf(bufnum, (size_t) BUFSIZ); attr_t attr; const char *found; if (result != 0) { - strcpy(result, l_brace); + _nc_STRCPY(result, l_brace, TRACE_BUF_SIZE(bufnum)); if (ch != 0) { attr = AttrOfD(ch); if ((found = _nc_altcharset_name(attr, (chtype) CharOfD(ch))) != 0) { @@ -318,9 +341,12 @@ _tracecchar_t2(int bufnum, const cchar_t *ch) (void) _nc_trace_bufcat(bufnum, "{ "); for (PUTC_i = 0; PUTC_i < CCHARW_MAX; ++PUTC_i) { PUTC_ch = ch->chars[PUTC_i]; - if (PUTC_ch == L'\0') + if (PUTC_ch == L'\0') { + if (PUTC_i == 0) + (void) _nc_trace_bufcat(bufnum, "\\000"); break; - PUTC_n = wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); + } + PUTC_n = (int) wcrtomb(PUTC_buf, ch->chars[PUTC_i], &PUT_st); if (PUTC_n <= 0) { if (PUTC_ch != L'\0') { /* it could not be a multibyte sequence */