Author: sebor Date: Thu Mar 30 18:03:09 2006 New Revision: 390299 URL: http://svn.apache.org/viewcvs?rev=390299&view=rev Log: 2006-03-30 Martin Sebor * fmt_defs.h: New header. * printf.cpp (Buffer, FmtSpec): Moved definitions to fmt_defs.h. (_rw_fmterrno, _rw_fmtlc, _rw_fmtmask, _rw_fmtiostate, _rw_fmtflags, _rw_fmtopenmode, _rw_fmtseekdir, _rw_fmtevent, _rw_fmtmonpat, _rw_fmtsignal): Moved definitions to fmt_bits.cpp. (_rw_quotechar, _rw_fmtarray): Prepended underscore according to the naming convention. (_rw_fmtspec): Corrected the handling of $ syntax. (_rw_fmtexpr): New function to format expressions involving environment variables. (_rw_vasnprintf_ext): Called _rw_fmtexpr(). Avoided aborting on malformed directives. * fmt_bits.cpp (_rw_fmterrno, _rw_fmtlc, ...): Moved definitions from printf.cpp. * test/printf.cpp (test_envvar): Exercised $. (test_malformed_directives): Exercised malformed directives. (test_tm): Used a power of 2 (sizeof(int)) to create a bad (misaligned) address. Added: incubator/stdcxx/trunk/tests/src/fmt_bits.cpp (with props) incubator/stdcxx/trunk/tests/src/fmt_defs.h (with props) Modified: incubator/stdcxx/trunk/tests/self/0.printf.cpp incubator/stdcxx/trunk/tests/src/printf.cpp Modified: incubator/stdcxx/trunk/tests/self/0.printf.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/self/0.printf.cpp?rev=390299&r1=390298&r2=390299&view=diff ============================================================================== --- incubator/stdcxx/trunk/tests/self/0.printf.cpp (original) +++ incubator/stdcxx/trunk/tests/self/0.printf.cpp Thu Mar 30 18:03:09 2006 @@ -26,6 +26,7 @@ **************************************************************************/ #include +#include // for rw_putenv() #include // for ios::openmode, ios::seekdir #include // for string @@ -140,7 +141,7 @@ /***********************************************************************/ -// returns an invalid or unaligned address (when 1 < size) +// returns an invalid or misaligned address (when 1 < size) const void* bad_address (size_t size) { const char *addr; @@ -168,20 +169,20 @@ } // returns the expected string corresponding to an invalid -// or unaligned address +// or misaligned address const char* format_bad_address (const void *ptr, bool valid) { static char buf [80]; #if 4 == _RWSTD_PTR_SIZE sprintf (buf, "(%s address %#010" _RWSTD_PRIz "x)", - valid ? "unaligned" : "invalid", (size_t)ptr); + valid ? "misaligned" : "invalid", (size_t)ptr); #elif 8 == _RWSTD_PTR_SIZE sprintf (buf, "(%s address %#018" _RWSTD_PRIz "x)", - valid ? "unaligned" : "invalid", (size_t)ptr); + valid ? "misaligned" : "invalid", (size_t)ptr); #else sprintf (buf, "(%s address %#0" _RWSTD_PRIz "x)", - valid ? "unaligned" : "invalid", (size_t)ptr); + valid ? "misaligned" : "invalid", (size_t)ptr); #endif return buf; @@ -1773,7 +1774,175 @@ { printf ("%s\n", "extension: \"%{$string}\": environment variable"); - fprintf (stderr, "Warning: %s\n", "\"%{$string} not exercised"); + rw_putenv ("FOO=bar"); + TEST ("[%{$FOO}]", 0, 0, 0, "[bar]"); + TEST ("[%{$*}]", "FOO", 0, 0, "[bar]"); + TEST ("[%{$*}][%1$s]", "FOO", 0, 0, "[bar][bar]"); + + // +--------------------+-------------+-------------+-------------+ + // | | parameter | parameter | parameter | + // | +-------------+-------------+-------------+ + // | |Set, Not Null| Set, Null | Unset | + // +--------------------+-------------+-------------+-------------+ + // | ${parameter:-word} | parameter | word | word | + // | ${parameter-word} | parameter | null | word | + // | ${parameter:=word} | parameter | assign word | assign word | + // | ${parameter=word} | parameter | null | assign word | + // | ${parameter:?word} | parameter | error | error | + // | ${parameter?word} | parameter | null | error | + // | ${parameter:+word} | word | null | null | + // | ${parameter+word} | word | word | null | + // +--------------------+-------------+-------------+-------------+ + + rw_putenv ("NOT_NULL=FOO"); + rw_putenv ("NULL="); // define to null (empty string) + rw_putenv ("UNSET"); // undefine if defined + + // ":-" use parameter if not null, otherwise word + TEST ("[%{$NOT_NULL:-word}]", 0, 0, 0, "[FOO]"); + TEST ("[%{$NULL:-word}]", 0, 0, 0, "[word]"); + TEST ("[%{$UNSET:-word}]", 0, 0, 0, "[word]"); + + // "-" use parameter if not null, word when unset, otherwise null + TEST ("[%{$NOT_NULL-word}]", 0, 0, 0, "[FOO]"); + TEST ("[%{$NULL-word}]", 0, 0, 0, "[]"); + TEST ("[%{$UNSET-word}]", 0, 0, 0, "[word]"); + + // ":=" use parameter if not null, otherwise assign word + TEST ("[%{$NOT_NULL:=word}]", 0, 0, 0, "[FOO]"); + TEST ("[%{$NULL:=word}]", 0, 0, 0, "[word]"); + TEST ("[%{$NULL}]", 0, 0, 0, "[word]"); + TEST ("[%{$UNSET:=word}]", 0, 0, 0, "[word]"); + TEST ("[%{$UNSET}]", 0, 0, 0, "[word]"); + + // restore variables assigned above + rw_putenv ("NULL="); + rw_putenv ("UNSET"); + + // "=" use parameter if not null, assign word when unset, otherwise null + TEST ("[%{$NOT_NULL=word}]", 0, 0, 0, "[FOO]"); + TEST ("[%{$NULL=word}]", 0, 0, 0, "[]"); + TEST ("[%{$UNSET=word}]", 0, 0, 0, "[word]"); + TEST ("[%{$UNSET}]", 0, 0, 0, "[word]"); + + // restore variables assigned above + rw_putenv ("NULL="); + rw_putenv ("UNSET"); + + // ":?" use parameter if not null, otherwise error + TEST ("[%{$NOT_NULL:?word}]", 0, 0, 0, "[FOO]"); + TEST ("[%{$NULL:?word}]", 0, 0, 0, "[%{$NULL:?word}]"); + TEST ("[%{$UNSET:?word}]", 0, 0, 0, "[%{$UNSET:?word}]"); + + // "?" use parameter if not null, null when unset, otherwise error + TEST ("[%{$NOT_NULL?word}]", 0, 0, 0, "[FOO]"); + TEST ("[%{$NULL?word}]", 0, 0, 0, "[]"); + TEST ("[%{$UNSET?word}]", 0, 0, 0, "[%{$UNSET?word}]"); + + // ":+" use word if parameter is not null, otherwise null + TEST ("[%{$NOT_NULL:+word}]", 0, 0, 0, "[word]"); + TEST ("[%{$NULL:+word}]", 0, 0, 0, "[]"); + TEST ("[%{$UNSET:+word}]", 0, 0, 0, "[]"); + + // "+" use word if parameter is set, otherwise null + TEST ("[%{$NOT_NULL+word}]", 0, 0, 0, "[word]"); + TEST ("[%{$NULL+word}]", 0, 0, 0, "[word]"); + TEST ("[%{$UNSET+word}]", 0, 0, 0, "[]"); + + ////////////////////////////////////////////////////////////////// + + rw_putenv ("NOT_NULL=bar"); + rw_putenv ("NULL="); // define to null (empty string) + rw_putenv ("UNSET"); // undefine if defined + + TEST ("[%{$*:-WORD}]", "NOT_NULL", 0, 0, "[bar]"); + TEST ("[%{$*:-WORD}]", "NULL", 0, 0, "[WORD]"); + TEST ("[%{$*:-WORD}]", "UNSET", 0, 0, "[WORD]"); + + TEST ("[%{$*-WORD}]", "NOT_NULL", 0, 0, "[bar]"); + TEST ("[%{$*-WORD}]", "NULL", 0, 0, "[]"); + TEST ("[%{$*-WORD}]", "UNSET", 0, 0, "[WORD]"); + + TEST ("[%{$*:=WORD}]", "NOT_NULL", 0, 0, "[bar]"); + TEST ("[%{$*:=WORD}]", "NULL", 0, 0, "[WORD]"); + TEST ("[%{$*}]", "NULL", 0, 0, "[WORD]"); + TEST ("[%{$*:=WORD}]", "UNSET", 0, 0, "[WORD]"); + TEST ("[%{$*}]", "UNSET", 0, 0, "[WORD]"); + + // restore variables assigned above + rw_putenv ("NULL="); + rw_putenv ("UNSET"); + + TEST ("[%{$*=WORD}]", "NOT_NULL", 0, 0, "[bar]"); + TEST ("[%{$*=WORD}]", "NULL", 0, 0, "[]"); + TEST ("[%{$*=WORD}]", "UNSET", 0, 0, "[WORD]"); + TEST ("[%{$*}]", "UNSET", 0, 0, "[WORD]"); + + // restore variables assigned above + rw_putenv ("NULL="); + rw_putenv ("UNSET"); + + TEST ("[%{$*:?WORD}]", "NOT_NULL", 0, 0, "[bar]"); + TEST ("[%{$*:?WORD}]", "NULL", 0, 0, "[%{$*:?WORD}]"); + TEST ("[%{$*:?WORD}]", "UNSET", 0, 0, "[%{$*:?WORD}]"); + + TEST ("[%{$*?WORD}]", "NOT_NULL", 0, 0, "[bar]"); + TEST ("[%{$*?WORD}]", "NULL", 0, 0, "[]"); + TEST ("[%{$*?WORD}]", "UNSET", 0, 0, "[%{$*?WORD}]"); + + TEST ("[%{$*:+WORD}]", "NOT_NULL", 0, 0, "[WORD]"); + TEST ("[%{$*:+WORD}]", "NULL", 0, 0, "[]"); + TEST ("[%{$*:+WORD}]", "UNSET", 0, 0, "[]"); + + TEST ("[%{$*+WORD}]", "NOT_NULL", 0, 0, "[WORD]"); + TEST ("[%{$*+WORD}]", "NULL", 0, 0, "[WORD]"); + TEST ("[%{$*+WORD}]", "UNSET", 0, 0, "[]"); + + ////////////////////////////////////////////////////////////////// + + TEST ("[%{$*:-*}]", "NOT_NULL", "WORD", 0, "[bar]"); + TEST ("[%{$*:-*}]", "NULL", "WORD", 0, "[WORD]"); + TEST ("[%{$*:-*}]", "UNSET", "WORD", 0, "[WORD]"); + + TEST ("[%{$*-*}]", "NOT_NULL", "WORD", 0, "[bar]"); + TEST ("[%{$*-*}]", "NULL", "WORD", 0, "[]"); + TEST ("[%{$*-*}]", "UNSET", "WORD", 0, "[WORD]"); + + TEST ("[%{$*:=*}]", "NOT_NULL", "WORD", 0, "[bar]"); + TEST ("[%{$*:=*}]", "NULL", "WORD", 0, "[WORD]"); + TEST ("[%{$*}]", "NULL", 0, 0, "[WORD]"); + TEST ("[%{$*:=*}]", "UNSET", "WORD", 0, "[WORD]"); + TEST ("[%{$*}]", "UNSET", 0, 0, "[WORD]"); + + // restore variables assigned above + rw_putenv ("NULL="); + rw_putenv ("UNSET"); + + TEST ("[%{$*=*}]", "NOT_NULL", "WORD", 0, "[bar]"); + TEST ("[%{$*=*}]", "NULL", "WORD", 0, "[]"); + TEST ("[%{$*=*}]", "UNSET", "WORD", 0, "[WORD]"); + TEST ("[%{$*}]", "UNSET", 0, 0, "[WORD]"); + + // restore variables assigned above + rw_putenv ("NULL="); + rw_putenv ("UNSET"); + + TEST ("[%{$*:?*}]", "NOT_NULL", "WORD", 0, "[bar]"); + TEST ("[%{$*:?*}]", "NULL", "WORD", 0, "[%{$*:?*}]"); + TEST ("[%{$*:?*}]", "UNSET", "WORD", 0, "[%{$*:?*}]"); + + TEST ("[%{$*?*}]", "NOT_NULL", "WORD", 0, "[bar]"); + TEST ("[%{$*?*}]", "NULL", "WORD", 0, "[]"); + TEST ("[%{$*?*}]", "UNSET", "WORD", 0, "[%{$*?*}]"); + + TEST ("[%{$*:+*}]", "NOT_NULL", "WORD", 0, "[WORD]"); + TEST ("[%{$*:+*}]", "NULL", "WORD", 0, "[]"); + TEST ("[%{$*:+*}]", "UNSET", "WORD", 0, "[]"); + + TEST ("[%{$*+*}]", "NOT_NULL", "WORD", 0, "[WORD]"); + TEST ("[%{$*+*}]", "NULL", "WORD", 0, "[WORD]"); + TEST ("[%{$*+*}]", "UNSET", "WORD", 0, "[]"); + } /***********************************************************************/ @@ -1953,7 +2122,7 @@ const void* addr = bad_address (0); TEST ("%{t}", addr, 0, 0, format_bad_address (addr, false)); - addr = bad_address (sizeof (tm)); + addr = bad_address (sizeof (int)); TEST ("%{t}", addr, 0, 0, format_bad_address (addr, true)); // exercise human readable format @@ -2376,6 +2545,19 @@ /***********************************************************************/ +void test_malformed_directives () +{ + ////////////////////////////////////////////////////////////////// + printf ("%s\n", "malformed directives"); + + TEST ("%{", 0, 0, 0, "%{"); + TEST ("%{%", 0, 0, 0, "%{%"); + TEST ("%{%{", 0, 0, 0, "%{%{"); + TEST ("%{}", 0, 0, 0, "%{}"); +} + +/***********************************************************************/ + int main () { test_percent (); @@ -2411,6 +2593,8 @@ test_user_defined_formatting (); test_bufsize (); + + test_malformed_directives (); ////////////////////////////////////////////////////////////////// if (nfailures) { Added: incubator/stdcxx/trunk/tests/src/fmt_bits.cpp URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/fmt_bits.cpp?rev=390299&view=auto ============================================================================== --- incubator/stdcxx/trunk/tests/src/fmt_bits.cpp (added) +++ incubator/stdcxx/trunk/tests/src/fmt_bits.cpp Thu Mar 30 18:03:09 2006 @@ -0,0 +1,1090 @@ +/************************************************************************ + * + * fmt_bits.cpp - definitions of snprintfa helpers + * + * $Id$ + * + ************************************************************************ + * + * Copyright 2006 The Apache Software Foundation or its licensors, + * as applicable. + * + * Copyright 2005-2006 Rogue Wave Software. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + **************************************************************************/ + +// expand _TEST_EXPORT macros +#define _RWSTD_TEST_SRC +#include "fmt_defs.h" +#include + +#include // for errno, errno constants +#include +#include // for signal constant +#include +#include +#include +#include // memcpy(), memmove(), strcat(), ... + +#ifndef _RWSTD_NO_WCHAR_H +# include +#endif // _RWSTD_NO_WCHAR_H + +#ifndef _RWSTD_NO_WCTYPE_H +# include // for iswalpha(), ... +#endif // _RWSTD_NO_WCTYPE_H + +#include +#include +#include + +/**************************************************************************/ + +struct Bitnames +{ + const char *longname; + const char *name; + int bits; +}; + +#define BITNAME(qual, name) { #qual "::" #name, #name, qual::name } + +static int +_rw_bmpfmt (const FmtSpec &spec, Buffer &buf, + const Bitnames bmap[], + size_t size, + int bits) +{ + RW_ASSERT (0 != buf.pbuf); + + char buffer [1024]; + *buffer = '\0'; + + // string to use when no bits are set + const char* all_clear = "0"; + + for (size_t i = 0; i != size; ++i) { + if (bmap [i].bits) { + if ((bits & bmap [i].bits) == bmap [i].bits) { + + const char* const name = spec.fl_pound ? + bmap [i].longname : bmap [i].name; + + strcat (*buffer ? strcat (buffer, " | ") : buffer, name); + + bits &= ~bmap [i].bits; + } + } + else { + // save the name of the constant to use for 0 + all_clear = spec.fl_pound ? bmap [i].longname : bmap [i].name; + } + } + + size_t buffersize; + + if ('\0' == *buffer) { + // no constant matched, format teh value either as a number + // or, when 0, using the all_clear name (see above) + if (bits) + sprintf (buffer, "%#x", bits); + else + strcpy (buffer, all_clear); + + buffersize = strlen (buffer); + } + else if (bits) { + buffersize = strlen (buffer); + + // verify that buffer wasn't overflowed + RW_ASSERT (buffersize <= sizeof buffer); + + char bitstr [32]; + const int n = sprintf (bitstr, "%#x | ", bits); + + RW_ASSERT (0 < n); + + memmove (buffer + n, buffer, buffersize); + memcpy (buffer, bitstr, size_t (n)); + + buffersize += n; + } + else { + buffersize = strlen (buffer); + } + + // verify that buffer wasn't overflowed + RW_ASSERT (buffersize <= sizeof buffer); + + FmtSpec newspec (spec); + newspec.fl_pound = 0; + + return _rw_fmtstr (newspec, buf, buffer, buffersize); +} + +/********************************************************************/ + +/* extern */ int +_rw_fmtflags (const FmtSpec &spec, Buffer &buf, int bits) +{ + static const Bitnames names [] = { + BITNAME (std::ios, adjustfield), + BITNAME (std::ios, basefield), + BITNAME (std::ios, boolalpha), + BITNAME (std::ios, dec), + BITNAME (std::ios, fixed), + BITNAME (std::ios, hex), + BITNAME (std::ios, internal), + BITNAME (std::ios, left), + BITNAME (std::ios, oct), + BITNAME (std::ios, right), + BITNAME (std::ios, scientific), + BITNAME (std::ios, showbase), + BITNAME (std::ios, showpoint), + BITNAME (std::ios, showpos), + BITNAME (std::ios, skipws), + BITNAME (std::ios, unitbuf), + BITNAME (std::ios, uppercase), + +#ifndef _RWSTD_NO_EXT_BIN_IO + + // extension: produce binary output (similar to oct, dec, and hex) + BITNAME (std::ios, bin), + +#endif // _RWSTD_NO_EXT_BIN_IO + +#ifndef _RWSTD_NO_EXT_REENTRANT_IO + + // extension: allow unsychronized access to stream and/or its buffer + BITNAME (std::ios, nolock), + BITNAME (std::ios, nolockbuf), + +#endif // _RWSTD_NO_EXT_REENTRANT_IO + + { "std::ios::iostate(0)", "iostate(0)", std::ios::iostate () } + + }; + + static const size_t count = sizeof names / sizeof *names; + + const int base = (bits >> _RWSTD_IOS_BASEOFF) & _RWSTD_IOS_BASEMASK; + + // zero out bits representingthe numeric base + bits &= ~(_RWSTD_IOS_BASEMASK << _RWSTD_IOS_BASEOFF); + + int len = _rw_bmpfmt (spec, buf, names, count, bits); + + if (base && base != 8 && base != 10 && base != 16) { + + // for numeric bases other than those required by the standard, + // use the text "base (%d)" to show the extended numeric base + +#ifndef _RWSTD_NO_EXT_BIN_IO + + if (bits & std::ios::bin) + return len; + +#endif // _RWSTD_NO_EXT_BIN_IO + + len = rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+} | std::ios::base(%d)", base); + } + + return len; +} + +/********************************************************************/ + +/* extern */ int +_rw_fmtiostate (const FmtSpec &spec, Buffer &buf, int bits) +{ + static const Bitnames names [] = { + BITNAME (std::ios, goodbit), + BITNAME (std::ios, badbit), + BITNAME (std::ios, eofbit), + BITNAME (std::ios, failbit) + }; + + static const size_t count = sizeof names / sizeof *names; + + return _rw_bmpfmt (spec, buf, names, count, bits); +} + +/********************************************************************/ + +/* extern */ int +_rw_fmtopenmode (const FmtSpec &spec, Buffer &buf, int bits) +{ + static const Bitnames names [] = { + +#ifndef _RWSTD_NO_EXTENSIONS + + { "std::ios::nocreate", "nocreate", std::ios::nocreate }, + { "std::ios::noreplace", "noreplace", std::ios::noreplace }, + +#else // if defined (_RWSTD_NO_EXTENSIONS) + + { "__rw:::__rw_nocreate", "__rw_nocreate", _RW::__rw_nocreate }, + { "__rw::__rw_noreplace", "__rw_noreplace", _RW::__rw_noreplace }, + +#endif // _RWSTD_NO_EXTENSIONS + +#ifndef _RWSTD_NO_EXT_STDIO + + { "std::ios::stdio", "stdio", std::ios::stdio }, + { "std::ios::native", "native", std::ios::native }, + +#else // if defined (_RWSTD_NO_EXT_STDIO) + + { "__rw::__rw_stdio", "__rw_stdio", _RW::__rw_stdio }, + { "__rw::__rw_native", "__rw_native", _RW::__rw_native }, + +#endif // _RWSTD_NO_EXT_STDIO + + BITNAME (std::ios, app), + BITNAME (std::ios, binary), + BITNAME (std::ios, in), + BITNAME (std::ios, out), + BITNAME (std::ios, trunc), + BITNAME (std::ios, ate), + + { "std::ios::openmode(0)", "openmode(0)", std::ios::openmode () } + }; + + static const size_t count = sizeof names / sizeof *names; + + return _rw_bmpfmt (spec, buf, names, count, bits); +} + +/********************************************************************/ + +/* extern */ int +_rw_fmtseekdir (const FmtSpec &spec, Buffer &buf, int bits) +{ + static const Bitnames names [] = { + + BITNAME (std::ios, beg), + BITNAME (std::ios, cur), + BITNAME (std::ios, end) + }; + + static const size_t count = sizeof names / sizeof *names; + + return _rw_bmpfmt (spec, buf, names, count, bits); +} + +/********************************************************************/ + +/* extern */ int +_rw_fmtevent (const FmtSpec &spec, Buffer &buf, int event) +{ + const char* const str = + std::ios::copyfmt_event == event ? "copyfmt_event" + : std::ios::imbue_event == event ? "imbue_event" + : std::ios::erase_event == event ? "erase_event" + : 0; + + return rw_asnprintf (buf.pbuf, buf.pbufsize, + "%{+}%{?}%s%{:}copyfmt_event(%d)%{;}", + 0 != str, str, event); +} + +/********************************************************************/ + +/* extern */ int +_rw_fmtlc (const FmtSpec &spec, Buffer &buf, int val) +{ + const char *str = 0; + + switch (val) { + case LC_ALL: str = "LC_ALL"; break; + case LC_COLLATE: str = "LC_COLLATE"; break; + case LC_CTYPE: str = "LC_CTYPE"; break; + case LC_MONETARY: str = "LC_MONETARY"; break; + case LC_NUMERIC: str = "LC_NUMERIC"; break; + case LC_TIME: str = "LC_TIME"; break; + +#ifdef LC_MESSAGES + case LC_MESSAGES: str = "LC_MESSAGES"; break; +#endif // LC_MESSAGES + + } + + if (str) + return rw_asnprintf (buf.pbuf, buf.pbufsize, "%{+}%s", str); + + static const Bitnames names [] = { + BITNAME (std::locale, all), + BITNAME (std::locale, none), + BITNAME (std::locale, collate), + BITNAME (std::locale, ctype), + BITNAME (std::locale, monetary), + BITNAME (std::locale, numeric), + BITNAME (std::locale, messages), + BITNAME (std::locale, time) + }; + + static const size_t count = sizeof names / sizeof *names; + + return _rw_bmpfmt (spec, buf, names, count, val); +} + +/********************************************************************/ + +/* extern */ int +_rw_fmtmonpat (const FmtSpec &spec, Buffer &buf, const char pat [4]) +{ + static const char qual[] = "std::money_base::"; + + char buffer [256]; + + buffer [0] = '\0'; + + for (int i = 0; i != 4; ++i) { + switch (pat [i]) { + case std::money_base::symbol: + if (spec.fl_pound) + strcat (buffer, qual); + strcat (buffer, "symbol "); + break; + + case std::money_base::sign: + if (spec.fl_pound) + strcat (buffer, qual); + strcat (buffer, "sign "); + break; + + case std::money_base::none: + if (spec.fl_pound) + strcat (buffer, qual); + strcat (buffer, "none "); + break; + + case std::money_base::value: + if (spec.fl_pound) + strcat (buffer, qual); + strcat (buffer, "value "); + break; + + case std::money_base::space: + if (spec.fl_pound) + strcat (buffer, qual); + strcat (buffer, "space "); + break; + + default: + sprintf (buffer + strlen (buffer), "\\%03o", pat [i]); + break; + } + } + + FmtSpec newspec (spec); + newspec.fl_pound = 0; + + return _rw_fmtstr (newspec, buf, buffer, _RWSTD_SIZE_MAX); +} + +/********************************************************************/ + +/* extern */ int +_rw_fmtsignal (const FmtSpec &spec, Buffer &buf, int val) +{ + static const struct { + int val; + const char* str; + } names[] = { + +#undef SIGNAL +#define SIGNAL(val) { val, #val } + +#ifdef SIGABRT + SIGNAL (SIGABRT), +#endif // SIGABRT +#ifdef SIGALRM + SIGNAL (SIGALRM), +#endif // SIGALRM +#ifdef SIGBUS + SIGNAL (SIGBUS), +#endif // SIGBUS +#ifdef SIGCANCEL + SIGNAL (SIGCANCEL), +#endif // SIGCANCEL +#ifdef SIGCHLD + SIGNAL (SIGCHLD), +#endif // SIGCHLD +#ifdef SIGCKPT + SIGNAL (SIGCKPT), +#endif // SIGCKPT +#ifdef SIGCLD + SIGNAL (SIGCLD), +#endif // SIGCLD +#ifdef SIGCONT + SIGNAL (SIGCONT), +#endif // SIGCONT +#ifdef SIGDIL + SIGNAL (SIGDIL), +#endif // SIGDIL +#ifdef SIGEMT + SIGNAL (SIGEMT), +#endif // SIGEMT +#ifdef SIGFPE + SIGNAL (SIGFPE), +#endif // SIGFPE +#ifdef SIGFREEZE + SIGNAL (SIGFREEZE), +#endif // SIGFREEZE +#ifdef SIGGFAULT + SIGNAL (SIGGFAULT), +#endif // SIGGFAULT +#ifdef SIGHUP + SIGNAL (SIGHUP), +#endif // SIGHUP +#ifdef SIGILL + SIGNAL (SIGILL), +#endif // SIGILL +#ifdef SIGINFO + SIGNAL (SIGINFO), +#endif // SIGINFO +#ifdef SIGINT + SIGNAL (SIGINT), +#endif // SIGINT +#ifdef SIGIO + SIGNAL (SIGIO), +#endif // SIGIO +#ifdef SIGIOT + SIGNAL (SIGIOT), +#endif // SIGIOT +#ifdef SIGK32 + SIGNAL (SIGK32), +#endif // SIGK32 +#ifdef SIGKILL + SIGNAL (SIGKILL), +#endif // SIGKILL +#ifdef SIGLOST + SIGNAL (SIGLOST), +#endif // SIGLOST +#ifdef SIGLWP + SIGNAL (SIGLWP), +#endif // SIGLWP +#ifdef SIGPIPE + SIGNAL (SIGPIPE), +#endif // SIGPIPE +#ifdef SIGPOLL + SIGNAL (SIGPOLL), +#endif // SIGPOLL +#ifdef SIGPROF + SIGNAL (SIGPROF), +#endif // SIGPROF +#ifdef SIGPTINTR + SIGNAL (SIGPTINTR), +#endif // SIGPTINTR +#ifdef SIGPTRESCHED + SIGNAL (SIGPTRESCHED), +#endif // SIGPTRESCHED +#ifdef SIGPWR + SIGNAL (SIGPWR), +#endif // SIGPWR +#ifdef SIGQUIT + SIGNAL (SIGQUIT), +#endif // SIGQUIT +#ifdef SIGRESTART + SIGNAL (SIGRESTART), +#endif // SIGRESTART +#ifdef SIGRESV + SIGNAL (SIGRESV), +#endif // SIGRESV +#ifdef SIGSEGV + SIGNAL (SIGSEGV), +#endif // SIGSEGV +#ifdef SIGSTKFLT + SIGNAL (SIGSTKFLT), +#endif // SIGSTKFLT +#ifdef SIGSTOP + SIGNAL (SIGSTOP), +#endif // SIGSTOP +#ifdef SIGSYS + SIGNAL (SIGSYS), +#endif // SIGSYS +#ifdef SIGTERM + SIGNAL (SIGTERM), +#endif // SIGTERM +#ifdef SIGTHAW + SIGNAL (SIGTHAW), +#endif // SIGTHAW +#ifdef SIGTRAP + SIGNAL (SIGTRAP), +#endif // SIGTRAP +#ifdef SIGTSTP + SIGNAL (SIGTSTP), +#endif // SIGTSTP +#ifdef SIGTTIN + SIGNAL (SIGTTIN), +#endif // SIGTTIN +#ifdef SIGTTOU + SIGNAL (SIGTTOU), +#endif // SIGTTOU +#ifdef SIGUNUSED + SIGNAL (SIGUNUSED), +#endif // SIGUNUSED +#ifdef SIGURG + SIGNAL (SIGURG), +#endif // SIGURG +#ifdef SIGUSR1 + SIGNAL (SIGUSR1), +#endif // SIGUSR1 +#ifdef SIGUSR2 + SIGNAL (SIGUSR2), +#endif // SIGUSR2 +#ifdef SIGVTALRM + SIGNAL (SIGVTALRM), +#endif // SIGVTALRM +#ifdef SIGWAITING + SIGNAL (SIGWAITING), +#endif // SIGWAITING +#ifdef SIGWINCH + SIGNAL (SIGWINCH), +#endif // SIGWINCH +#ifdef SIGWINDOW + SIGNAL (SIGWINDOW), +#endif // SIGWINDOW +#ifdef SIGXCPU + SIGNAL (SIGXCPU), +#endif // SIGXCPU +#ifdef SIGXFSZ + SIGNAL (SIGXFSZ), +#endif // SIGXFSZ +#ifdef SIGXRES + SIGNAL (SIGXRES), +#endif // SIGXRES + { -1, 0 } + }; + + const char *name = 0; + + for (size_t i = 0; i != sizeof names / sizeof *names; ++i) { + if (names [i].val == val) { + name = names [i].str; + break; + } + } + + char smallbuf [32]; + if (0 == name) { + sprintf (smallbuf, "SIG#%d", val); + name = smallbuf; + } + + FmtSpec newspec (spec); + newspec.fl_pound = 0; + + return _rw_fmtstr (newspec, buf, name, _RWSTD_SIZE_MAX); +} + +/********************************************************************/ + +/* extern */ int +_rw_fmterrno (const FmtSpec &spec, Buffer &buf, int val) +{ + static const struct { + int val; + const char* str; + } names[] = { + +#undef ERRNO +#define ERRNO(val) { val, #val } + +#ifdef EPERM + ERRNO (EPERM), +#endif // EPERM +#ifdef ENOENT + ERRNO (ENOENT), +#endif // ENOENT +#ifdef ESRCH + ERRNO (ESRCH), +#endif // ESRCH +#ifdef EINTR + ERRNO (EINTR), +#endif // EINTR +#ifdef EIO + ERRNO (EIO), +#endif // EIO +#ifdef ENXIO + ERRNO (ENXIO), +#endif // ENXIO +#ifdef E2BIG + ERRNO (E2BIG), +#endif // E2BIG +#ifdef ENOEXEC + ERRNO (ENOEXEC), +#endif // ENOEXEC +#ifdef EBADF + ERRNO (EBADF), +#endif // EBADF +#ifdef ECHILD + ERRNO (ECHILD), +#endif // ECHILD +#ifdef EAGAIN + ERRNO (EAGAIN), +#endif // EAGAIN +#ifdef ENOMEM + ERRNO (ENOMEM), +#endif // ENOMEM +#ifdef EACCES + ERRNO (EACCES), +#endif // EACCES +#ifdef EFAULT + ERRNO (EFAULT), +#endif // EFAULT +#ifdef ENOTBLK + ERRNO (ENOTBLK), +#endif // ENOTBLK +#ifdef EBUSY + ERRNO (EBUSY), +#endif // EBUSY +#ifdef EEXIST + ERRNO (EEXIST), +#endif // EEXIST +#ifdef EXDEV + ERRNO (EXDEV), +#endif // EXDEV +#ifdef ENODEV + ERRNO (ENODEV), +#endif // ENODEV +#ifdef ENOTDIR + ERRNO (ENOTDIR), +#endif // ENOTDIR +#ifdef EISDIR + ERRNO (EISDIR), +#endif // EISDIR +#ifdef EINVAL + ERRNO (EINVAL), +#endif // EINVAL +#ifdef ENFILE + ERRNO (ENFILE), +#endif // ENFILE +#ifdef EMFILE + ERRNO (EMFILE), +#endif // EMFILE +#ifdef ENOTTY + ERRNO (ENOTTY), +#endif // ENOTTY +#ifdef ETXTBSY + ERRNO (ETXTBSY), +#endif // ETXTBSY +#ifdef EFBIG + ERRNO (EFBIG), +#endif // EFBIG +#ifdef ENOSPC + ERRNO (ENOSPC), +#endif // ENOSPC +#ifdef ESPIPE + ERRNO (ESPIPE), +#endif // ESPIPE +#ifdef EROFS + ERRNO (EROFS), +#endif // EROFS +#ifdef EMLINK + ERRNO (EMLINK), +#endif // EMLINK +#ifdef EPIPE + ERRNO (EPIPE), +#endif // EPIPE +#ifdef EDOM + ERRNO (EDOM), +#endif // EDOM +#ifdef ERANGE + ERRNO (ERANGE), +#endif // ERANGE +#ifdef ENOMSG + ERRNO (ENOMSG), +#endif // ENOMSG +#ifdef EIDRM + ERRNO (EIDRM), +#endif // EIDRM +#ifdef ECHRNG + ERRNO (ECHRNG), +#endif // ECHRNG +#ifdef EL2NSYNC + ERRNO (EL2NSYNC), +#endif // EL2NSYNC +#ifdef EL3HLT + ERRNO (EL3HLT), +#endif // EL3HLT +#ifdef EL3RST + ERRNO (EL3RST), +#endif // EL3RST +#ifdef ELNRNG + ERRNO (ELNRNG), +#endif // ELNRNG +#ifdef EUNATCH + ERRNO (EUNATCH), +#endif // EUNATCH +#ifdef ENOCSI + ERRNO (ENOCSI), +#endif // ENOCSI +#ifdef EL2HLT + ERRNO (EL2HLT), +#endif // EL2HLT +#ifdef EDEADLK + ERRNO (EDEADLK), +#endif // EDEADLK +#ifdef ENOLCK + ERRNO (ENOLCK), +#endif // ENOLCK +#ifdef ECANCELED + ERRNO (ECANCELED), +#endif // ECANCELED +#ifdef ENOTSUP + ERRNO (ENOTSUP), +#endif // ENOTSUP +#ifdef EDQUOT + ERRNO (EDQUOT), +#endif // EDQUOT +#ifdef EBADE + ERRNO (EBADE), +#endif // EBADE +#ifdef EBADR + ERRNO (EBADR), +#endif // EBADR +#ifdef EXFULL + ERRNO (EXFULL), +#endif // EXFULL +#ifdef ENOANO + ERRNO (ENOANO), +#endif // ENOANO +#ifdef EBADRQC + ERRNO (EBADRQC), +#endif // EBADRQC +#ifdef EBADSLT + ERRNO (EBADSLT), +#endif // EBADSLT +#ifdef EDEADLOCK + ERRNO (EDEADLOCK), +#endif // EDEADLOCK +#ifdef EBFONT + ERRNO (EBFONT), +#endif // EBFONT +#ifdef EOWNERDEAD + ERRNO (EOWNERDEAD), +#endif // EOWNERDEAD +#ifdef ENOTRECOVERABLE + ERRNO (ENOTRECOVERABLE), +#endif // ENOTRECOVERABLE +#ifdef ENOSTR + ERRNO (ENOSTR), +#endif // ENOSTR +#ifdef ENODATA + ERRNO (ENODATA), +#endif // ENODATA +#ifdef ETIME + ERRNO (ETIME), +#endif // ETIME +#ifdef ENOSR + ERRNO (ENOSR), +#endif // ENOSR +#ifdef ENONET + ERRNO (ENONET), +#endif // ENONET +#ifdef ENOPKG + ERRNO (ENOPKG), +#endif // ENOPKG +#ifdef EREMOTE + ERRNO (EREMOTE), +#endif // EREMOTE +#ifdef ENOLINK + ERRNO (ENOLINK), +#endif // ENOLINK +#ifdef EADV + ERRNO (EADV), +#endif // EADV +#ifdef ESRMNT + ERRNO (ESRMNT), +#endif // ESRMNT +#ifdef ECOMM + ERRNO (ECOMM), +#endif // ECOMM +#ifdef ELOCKUNMAPPED + ERRNO (ELOCKUNMAPPED), +#endif // ELOCKUNMAPPED +#ifdef ENOTACTIVE + ERRNO (ENOTACTIVE), +#endif // ENOTACTIVE +#ifdef EMULTIHOP + ERRNO (EMULTIHOP), +#endif // EMULTIHOP +#ifdef EBADMSG + ERRNO (EBADMSG), +#endif // EBADMSG +#ifdef ENAMETOOLONG + ERRNO (ENAMETOOLONG), +#endif // ENAMETOOLONG +#ifdef EOVERFLOW + ERRNO (EOVERFLOW), +#endif // EOVERFLOW +#ifdef ENOTUNIQ + ERRNO (ENOTUNIQ), +#endif // ENOTUNIQ +#ifdef EBADFD + ERRNO (EBADFD), +#endif // EBADFD +#ifdef EREMCHG + ERRNO (EREMCHG), +#endif // EREMCHG +#ifdef ELIBACC + ERRNO (ELIBACC), +#endif // ELIBACC +#ifdef ELIBBAD + ERRNO (ELIBBAD), +#endif // ELIBBAD +#ifdef ELIBSCN + ERRNO (ELIBSCN), +#endif // ELIBSCN +#ifdef ELIBMAX + ERRNO (ELIBMAX), +#endif // ELIBMAX +#ifdef ELIBEXEC + ERRNO (ELIBEXEC), +#endif // ELIBEXEC +#ifdef EILSEQ + ERRNO (EILSEQ), +#endif // EILSEQ +#ifdef ENOSYS + ERRNO (ENOSYS), +#endif // ENOSYS +#ifdef ELOOP + ERRNO (ELOOP), +#endif // ELOOP +#ifdef ERESTART + ERRNO (ERESTART), +#endif // ERESTART +#ifdef ESTRPIPE + ERRNO (ESTRPIPE), +#endif // ESTRPIPE +#ifdef ENOTEMPTY + ERRNO (ENOTEMPTY), +#endif // ENOTEMPTY +#ifdef EUSERS + ERRNO (EUSERS), +#endif // EUSERS +#ifdef ENOTSOCK + ERRNO (ENOTSOCK), +#endif // ENOTSOCK +#ifdef EDESTADDRREQ + ERRNO (EDESTADDRREQ), +#endif // EDESTADDRREQ +#ifdef EMSGSIZE + ERRNO (EMSGSIZE), +#endif // EMSGSIZE +#ifdef EPROTOTYPE + ERRNO (EPROTOTYPE), +#endif // EPROTOTYPE +#ifdef ENOPROTOOPT + ERRNO (ENOPROTOOPT), +#endif // ENOPROTOOPT +#ifdef EPROTONOSUPPORT + ERRNO (EPROTONOSUPPORT), +#endif // EPROTONOSUPPORT +#ifdef ESOCKTNOSUPPORT + ERRNO (ESOCKTNOSUPPORT), +#endif // ESOCKTNOSUPPORT +#ifdef EOPNOTSUPP + ERRNO (EOPNOTSUPP), +#endif // EOPNOTSUPP +#ifdef EPFNOSUPPORT + ERRNO (EPFNOSUPPORT), +#endif // EPFNOSUPPORT +#ifdef EAFNOSUPPORT + ERRNO (EAFNOSUPPORT), +#endif // EAFNOSUPPORT +#ifdef EADDRINUSE + ERRNO (EADDRINUSE), +#endif // EADDRINUSE +#ifdef EADDRNOTAVAIL + ERRNO (EADDRNOTAVAIL), +#endif // EADDRNOTAVAIL +#ifdef ENETDOWN + ERRNO (ENETDOWN), +#endif // ENETDOWN +#ifdef ENETUNREACH + ERRNO (ENETUNREACH), +#endif // ENETUNREACH +#ifdef ENETRESET + ERRNO (ENETRESET), +#endif // ENETRESET +#ifdef ECONNABORTED + ERRNO (ECONNABORTED), +#endif // ECONNABORTED +#ifdef ECONNRESET + ERRNO (ECONNRESET), +#endif // ECONNRESET +#ifdef ENOBUFS + ERRNO (ENOBUFS), +#endif // ENOBUFS +#ifdef EISCONN + ERRNO (EISCONN), +#endif // EISCONN +#ifdef ENOTCONN + ERRNO (ENOTCONN), +#endif // ENOTCONN +#ifdef ESHUTDOWN + ERRNO (ESHUTDOWN), +#endif // ESHUTDOWN +#ifdef ETOOMANYREFS + ERRNO (ETOOMANYREFS), +#endif // ETOOMANYREFS +#ifdef ETIMEDOUT + ERRNO (ETIMEDOUT), +#endif // ETIMEDOUT +#ifdef ECONNREFUSED + ERRNO (ECONNREFUSED), +#endif // ECONNREFUSED +#ifdef EHOSTDOWN + ERRNO (EHOSTDOWN), +#endif // EHOSTDOWN +#ifdef EHOSTUNREACH + ERRNO (EHOSTUNREACH), +#endif // EHOSTUNREACH +#ifdef EWOULDBLOCK + ERRNO (EWOULDBLOCK), +#endif // EWOULDBLOCK +#ifdef EALREADY + ERRNO (EALREADY), +#endif // EALREADY +#ifdef EINPROGRESS + ERRNO (EINPROGRESS), +#endif // EINPROGRESS +#ifdef ESTALE + ERRNO (ESTALE), +#endif // ESTALE + { -1, 0 } + }; + + const char* str = strerror (val); + + char smallbuf [32]; + + if (spec.fl_pound || 0 == str) { + + const char *name = 0; + + for (size_t i = 0; i != sizeof names / sizeof *names; ++i) { + if (names [i].val == val) { + name = names [i].str; + break; + } + } + + if (0 == name) { + sprintf (smallbuf, "E#%d", val); + str = smallbuf; + } + else + str = name; + } + + FmtSpec newspec (spec); + newspec.width = 0; + newspec.fl_pound = 0; + + return _rw_fmtstr (newspec, buf, str, _RWSTD_SIZE_MAX); +} + +/********************************************************************/ + +/* extern */ int +_rw_fmtmask (const FmtSpec &spec, Buffer &buf, int c) +{ + enum { + bit_alnum = 1, + bit_alpha = 1 << 1, + bit_cntrl = 1 << 2, + bit_digit = 1 << 3, + bit_graph = 1 << 4, + bit_lower = 1 << 5, + bit_print = 1 << 6, + bit_punct = 1 << 7, + bit_space = 1 << 8, + bit_upper = 1 << 9, + bit_xdigit = 1 << 10 + }; + + int mask = 0; + + if (spec.fl_pound) { + +#ifndef _RWSTD_NO_WCHAR_H + + mask |= iswalnum (c) ? bit_alnum : 0; + mask |= iswalpha (c) ? bit_alpha : 0; + mask |= iswcntrl (c) ? bit_cntrl : 0; + mask |= iswdigit (c) ? bit_digit : 0; + mask |= iswgraph (c) ? bit_graph : 0; + mask |= iswlower (c) ? bit_lower : 0; + mask |= iswprint (c) ? bit_print : 0; + mask |= iswpunct (c) ? bit_punct : 0; + mask |= iswspace (c) ? bit_space : 0; + mask |= iswupper (c) ? bit_upper : 0; + mask |= iswxdigit (c) ? bit_xdigit : 0; + +#endif // _RWSTD_NO_WCHAR_H + + } + else { + const unsigned char uc = c; + + mask |= isalnum (uc) ? bit_alnum : 0; + mask |= isalpha (uc) ? bit_alpha : 0; + mask |= iscntrl (uc) ? bit_cntrl : 0; + mask |= isdigit (uc) ? bit_digit : 0; + mask |= isgraph (uc) ? bit_graph : 0; + mask |= islower (uc) ? bit_lower : 0; + mask |= isprint (uc) ? bit_print : 0; + mask |= ispunct (uc) ? bit_punct : 0; + mask |= isspace (uc) ? bit_space : 0; + mask |= isupper (uc) ? bit_upper : 0; + mask |= isxdigit (uc) ? bit_xdigit : 0; + } + + char mask_str [80]; + char *str = mask_str; + + str [0] = '\0'; + +#define APPEND(bit) \ + if (mask & bit_ ## bit) \ + strcat (strcat (str, #bit), "|"); \ + else (void)0 + + APPEND (alnum); + APPEND (alpha); + APPEND (cntrl); + APPEND (digit); + APPEND (graph); + APPEND (lower); + APPEND (print); + APPEND (punct); + APPEND (space); + APPEND (upper); + APPEND (xdigit); + + if (str == mask_str) + *str = '\0'; + else + str [-1] = '\0'; + + FmtSpec newspec (spec); + newspec.fl_pound = 0; + + return _rw_fmtstr (newspec, buf, str, _RWSTD_SIZE_MAX); +} Propchange: incubator/stdcxx/trunk/tests/src/fmt_bits.cpp ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/stdcxx/trunk/tests/src/fmt_bits.cpp ------------------------------------------------------------------------------ svn:keywords = Id Added: incubator/stdcxx/trunk/tests/src/fmt_defs.h URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/fmt_defs.h?rev=390299&view=auto ============================================================================== --- incubator/stdcxx/trunk/tests/src/fmt_defs.h (added) +++ incubator/stdcxx/trunk/tests/src/fmt_defs.h Thu Mar 30 18:03:09 2006 @@ -0,0 +1,224 @@ +/************************************************************************ + * + * fmt_defs.h - declarations and definitions of types and functions + * used to implement the snprintfa helper functions + * + * $Id$ + * + ************************************************************************ + * + * Copyright 2006 The Apache Software Foundation or its licensors, + * as applicable. + * + * Copyright 2005-2006 Rogue Wave Software. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + **************************************************************************/ + +#ifndef RW_FMT_DEFS_H_INCLUDED +#define RW_FMT_DEFS_H_INCLUDED + +#include // for ptrdiff_t, size_t + +/********************************************************************/ + +// convenience typedefs +typedef unsigned char UChar; +typedef unsigned short UShrt; +typedef unsigned int UInt; +typedef unsigned long ULong; + +#ifdef _RWSTD_LONG_LONG + +typedef unsigned _RWSTD_LONG_LONG ULLong; + +#endif // _RWSTD_LONG_LONG + +typedef void (*funptr_t)(); + +struct DummyStruct; +typedef void (DummyStruct::*memptr_t)() const; + +/********************************************************************/ + +struct Buffer { + char **pbuf; // pointer to the output buffer + size_t *pbufsize; // pointer to the size of the buffer + size_t maxsize; // maximum not-to-exceed size + size_t endoff; // offset of the last character +}; + +/********************************************************************/ + +struct FmtSpec +{ + // optional flags + unsigned fl_minus : 1; + unsigned fl_plus : 1; + unsigned fl_pound : 1; + unsigned fl_space : 1; + unsigned fl_zero : 1; + + // optional length modifier + enum Modifier { + mod_none = 0, + mod_h, // short modifier + mod_hh, // char modifier + mod_l, // long modifier + mod_ll, // long long modifier + mod_j, // intmax_t modifier + mod_z, // size_t modifier + mod_t, // ptrdiff_t modifier + mod_L, // long double modifier + mod_ext_A, // extension: arrays + mod_ext_I // extension: int as ios::iostate + }; + + Modifier mod : 5; + + unsigned cond : 1; // have an if/else clause + unsigned cond_true : 1; // if/else clause is active (true) + unsigned cond_begin : 1; // beginning of an if/else clause + unsigned cond_end : 1; // end of an if/else clause + + // note that the signedness of a bitfield is implementation-defined + // unless explicitly declared signed or unsigned + + // extension: 8, 16, 32, and 64 bit integer width modifier + signed int iwidth : 4; + + // extension: optional numerical base 2 - 36 + signed int base : 7; + + // extension: optional parameter number + long paramno; + + // optional field width and precision + int width; + int prec; + + // extension: string argument + char *strarg; + + // required conversion specifier + int cvtspec; + + // extension: fill character + int fill; + +#ifndef _RWSTD_NO_LONG_DOUBLE + typedef long double ldbl_t; +#else + typedef double ldbl_t; // bogus (for convenience) +#endif // _RWSTD_NO_LONG_DOUBLE + +#ifdef _RWSTD_LONG_LONG + typedef _RWSTD_LONG_LONG llong_t; +#else + typedef long llong_t; // bogus (for convenience) +#endif // _RWSTD_LONG_LONG + +#ifdef _RWSTD_INT64_T + typedef _RWSTD_INT64_T i64_t; +#else + typedef int i64_t; // for convenience +#endif // _RWSTD_INT64_T + +#ifdef _RWSTD_INT32_T + typedef _RWSTD_INT32_T i32_t; +#else + typedef int i64_t; +#endif // _RWSTD_INT64_T + +#ifdef _RWSTD_WINT_T + typedef _RWSTD_WINT_T wint_t; +#else + typedef int wint_t; +#endif + + typedef ::size_t size_t; + typedef ptrdiff_t diff_t; + typedef ::funptr_t funptr_t; + typedef ::memptr_t memptr_t; + + typedef int int_t; + typedef long long_t; + typedef void* ptr_t; + typedef double dbl_t; + + union { + ldbl_t ldbl_; + llong_t llong_; + i64_t i64_; + ptr_t ptr_; + long_t long_; + i32_t i32_; + int_t int_; + diff_t diff_; + size_t size_; + wint_t wint_; + + dbl_t dbl_; + memptr_t memptr_; + funptr_t funptr_; + } param; +}; + +/********************************************************************/ + +// format a character string +extern int +_rw_fmtstr (const FmtSpec&, Buffer&, const char*, size_t); + +// format errno value/name +extern int +_rw_fmterrno (const FmtSpec&, Buffer&, int); + +// format the name/value of an LC_XXX constant/environment variable +extern int +_rw_fmtlc (const FmtSpec&, Buffer&, int); + +// format a character mask (alpha|alnum|...|xdigit) +extern int +_rw_fmtmask (const FmtSpec&, Buffer&, int); + +// format ios_base::iostate +extern int +_rw_fmtiostate (const FmtSpec&, Buffer&, int); + +// format ios_base::fmtflags +extern int +_rw_fmtflags (const FmtSpec&, Buffer&, int); + +// format ios_base::openmode +extern int +_rw_fmtopenmode (const FmtSpec&, Buffer&, int); + +// format ios_base::seekdir +extern int +_rw_fmtseekdir (const FmtSpec&, Buffer&, int); + +// format ios_base::event +extern int +_rw_fmtevent (const FmtSpec&, Buffer&, int); + +extern int +_rw_fmtmonpat (const FmtSpec&, Buffer&, const char [4]); + +// format a signal value/name +extern int +_rw_fmtsignal (const FmtSpec&, Buffer&, int); + + +#endif // RW_FMT_DEFS_H_INCLUDED Propchange: incubator/stdcxx/trunk/tests/src/fmt_defs.h ------------------------------------------------------------------------------ svn:eol-style = native Propchange: incubator/stdcxx/trunk/tests/src/fmt_defs.h ------------------------------------------------------------------------------ svn:keywords = Id