stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r287304 [1/2] - in /incubator/stdcxx/trunk/tests: include/driver.h src/cmdopt.cpp src/driver.cpp src/opt_diags.cpp src/opt_diags.h src/opt_lines.cpp src/opt_lines.h src/opt_trace.cpp src/opt_trace.h src/opt_types.cpp src/opt_types.h
Date Thu, 15 Sep 2005 00:41:26 GMT
Author: sebor
Date: Wed Sep 14 17:41:16 2005
New Revision: 287304

URL: http://svn.apache.org/viewcvs?rev=287304&view=rev
Log:
2005-09-14  Martin Sebor  <sebor@roguewave.com>

	STDCXX-3
	* opt_diags.h: New.
	* opt_diags.cpp: New. Definitions of functions for the processing
	of the --diags command line option.
	* opt_lines.h: New.
	* opt_lines.cpp: New. Definitions of functions for the processing
	of the --enable-line and --no-line command line options.
	* opt_trace.h: New.
	* opt_trace.cpp: New. Definitions of functions for the processing
	of the --trace and --severity command line options.
	* opt_types.h: New.
	* opt_types.cpp: New. Definitions of functions for the processing
	of the --enable-type and --no-type command line options.
	* cmdopt.cpp: Refactored. Moved the processing of specific command
	line options to separate files for better encapsulation.
	Eliminated memory corruption when the cmdopts array is reallocated.
	Replaced bool with int for better portability.
	* driver.h: Removed declarations and adjusted severities (see below).
	* driver.cpp: Refactored (see above).
	Introduced the concept of expected diagnostics (i.e., those expected
	to be active, such as expected assertion failures) and added a command
	line option (--expect=, see opt_lines.cpp) to make it possible to
	easily mark them as such. Reassigned severities to diagnostics.
	Introduced a new naming convention for symbols internal to the driver
	(regardless of linkage) to more easily distinguish them from public
	names with external linkage: _rw_xxx.
	(rw_trace): Removed.
	(rw_debug): Removed.
	(_rw_vdiag): Enabled verbose mode as the default formatting mode.

Added:
    incubator/stdcxx/trunk/tests/src/opt_diags.cpp   (with props)
    incubator/stdcxx/trunk/tests/src/opt_diags.h   (with props)
    incubator/stdcxx/trunk/tests/src/opt_lines.cpp   (with props)
    incubator/stdcxx/trunk/tests/src/opt_lines.h   (with props)
    incubator/stdcxx/trunk/tests/src/opt_trace.cpp   (with props)
    incubator/stdcxx/trunk/tests/src/opt_trace.h   (with props)
    incubator/stdcxx/trunk/tests/src/opt_types.cpp   (with props)
    incubator/stdcxx/trunk/tests/src/opt_types.h   (with props)
Modified:
    incubator/stdcxx/trunk/tests/include/driver.h
    incubator/stdcxx/trunk/tests/src/cmdopt.cpp
    incubator/stdcxx/trunk/tests/src/driver.cpp

Modified: incubator/stdcxx/trunk/tests/include/driver.h
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/include/driver.h?rev=287304&r1=287303&r2=287304&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/include/driver.h (original)
+++ incubator/stdcxx/trunk/tests/include/driver.h Wed Sep 14 17:41:16 2005
@@ -128,28 +128,12 @@
 rw_assert (int, const char*, int, const char*, ...);
 
 /**
- * Records and optionally issues a diagnostic of severity 6.
- *
- * @see #rw_fatal
- */
-_TEST_EXPORT int
-rw_warn (int, const char*, int, const char*, ...);
-
-/**
  * Records and optionally issues a diagnostic of severity 5.
  *
  * @see #rw_fatal
  */
 _TEST_EXPORT int
-rw_note (int, const char*, int, const char*, ...);
-
-/**
- * Records and optionally issues a diagnostic of severity 4.
- *
- * @see #rw_fatal
- */
-_TEST_EXPORT int
-rw_info (int, const char*, int, const char*, ...);
+rw_warn (int, const char*, int, const char*, ...);
 
 /**
  * Records and optionally issues a diagnostic of severity 2.
@@ -157,7 +141,7 @@
  * @see #rw_fatal
  */
 _TEST_EXPORT int
-rw_debug (int, const char*, int, const char*, ...);
+rw_note (int, const char*, int, const char*, ...);
 
 /**
  * Records and optionally issues a diagnostic of severity 1.
@@ -165,7 +149,6 @@
  * @see #rw_fatal
  */
 _TEST_EXPORT int
-rw_trace (int, const char*, int, const char*, ...);
-
+rw_info (int, const char*, int, const char*, ...);
 
 #endif   // RW_DRIVER_H_INCLUDED

Modified: incubator/stdcxx/trunk/tests/src/cmdopt.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/cmdopt.cpp?rev=287304&r1=287303&r2=287304&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/cmdopt.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/cmdopt.cpp Wed Sep 14 17:41:16 2005
@@ -17,14 +17,17 @@
  * 
  **************************************************************************/
 
+// expand _TEST_EXPORT macros
+#define _RWSTD_TEST_SRC
+
 #include <cmdopt.h>
 
-#include <assert.h>
-#include <errno.h>
-#include <stdarg.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
+#include <assert.h>   // for assert
+#include <errno.h>    // for errno
+#include <stdarg.h>   // for va_arg, ...
+#include <stdio.h>    // for fprintf
+#include <stdlib.h>   // for atexit, free, malloc
+#include <string.h>   // for memcpy, strcpy, strcmp, ...
 
 #ifndef EINVAL
 #  define EINVAL   22   /* e.g., HP-UX, Linux, Solaris */
@@ -46,10 +49,9 @@
     size_t         maxcalls_;       // how many times option can be invoked
     size_t         ncalls_;         // how many times it has been invoked
 
-    bool           arg_ : 1;        // option takes an argument?
-    bool           inv_ : 1;        // callback invocation inverted
-    bool           envseen_ : 1;    // environment option already processed
-
+    unsigned       arg_ : 1;        // option takes an argument?
+    unsigned       inv_ : 1;        // callback invocation inverted
+    unsigned       envseen_ : 1;    // environment option already processed
 };
 
 
@@ -62,24 +64,6 @@
 static cmdopts_t *cmdopts = cmdoptbuf;
 static size_t optbufsize = sizeof cmdoptbuf / sizeof *cmdoptbuf;
 
-enum {
-    rw_bool, rw_char, rw_uchar, rw_schar, rw_ushrt, rw_shrt,
-    rw_uint, rw_int, rw_ulong, rw_long, rw_ullong, rw_llong,
-    rw_flt, rw_dbl, rw_ldbl, rw_wchar, rw_pvoid
-};
-
-static int rw_disabled_types = 0;
-static int rw_enabled_types  = 0;
-
-struct linerange_t {
-    int first;
-    int last;
-};
-
-static size_t nlineranges;
-static linerange_t *lineranges;
-static size_t rangebufsize;
-
 /**************************************************************************/
 
 static int
@@ -116,11 +100,14 @@
 
     for (size_t i = 0; i != ncmdopts; ++i) {
 
+        // get a pointer to the name of the long option, if any
+        const char* const lopt =
+            cmdopts [i].lopt_ ? cmdopts [i].lopt_ : cmdopts [i].loptbuf_;
+
         if (opthelp && *opthelp) {
 
             if (   cmdopts [i].sopt_ == opthelp [0] && '\0' == opthelp [1]
-                || cmdopts [i].lopt_
-                && 0 == strcmp (cmdopts [i].lopt_ + 1, opthelp)) {
+                || *lopt && 0 == strcmp (lopt + 1, opthelp)) {
 
                 // remember that we found the option whose (short
                 // or long) name we're to give help on; after printing
@@ -140,17 +127,17 @@
         if (cmdopts [i].sopt_) {
             printf ("-%c", cmdopts [i].sopt_);
 
-            if (cmdopts [i].lopt_)
+            if (lopt)
                 printf (" | ");
         }
 
         const char *pfx = "";
         const char *sfx = pfx;
 
-        if (cmdopts [i].lopt_) {
-            printf ("-%s", cmdopts [i].lopt_);
+        if (lopt) {
+            printf ("-%s", lopt);
             if (   cmdopts [i].arg_
-                && '=' != cmdopts [i].lopt_ [strlen (cmdopts [i].lopt_) - 1]) {
+                && '=' != lopt [strlen (lopt) - 1]) {
                 pfx = " [ ";
                 sfx = " ]";
             }
@@ -197,6 +184,7 @@
     return 0;
 }
 
+/**************************************************************************/
 
 static int
 rw_set_ignenv (int argc, char *argv[])
@@ -222,278 +210,64 @@
     return 0;
 }
 
-static int rw_enable_type (int bit, bool enable)
-{
-    const int set_mask = 1 << bit;
-
-    if (enable)
-        rw_enabled_types |= set_mask;
-    else
-        rw_disabled_types |= set_mask;
-
-    return 0;
-}
-
-#define DEFINE_HANDLERS(T)                               \
-        static int rw_no_ ## T (int, char *[]) {         \
-            return rw_enable_type (rw_ ## T, false);     \
-        }                                                \
-        static int rw_en_ ## T (int, char *[]) {         \
-            return rw_enable_type (rw_ ## T, true);      \
-        }                                                \
-        typedef void unused_type /* allow a semicolon */
-
-
-DEFINE_HANDLERS (bool);
-DEFINE_HANDLERS (char);
-DEFINE_HANDLERS (schar);
-DEFINE_HANDLERS (uchar);
-DEFINE_HANDLERS (shrt);
-DEFINE_HANDLERS (ushrt);
-DEFINE_HANDLERS (int);
-DEFINE_HANDLERS (uint);
-DEFINE_HANDLERS (long);
-DEFINE_HANDLERS (ulong);
-DEFINE_HANDLERS (llong);
-DEFINE_HANDLERS (ullong);
-DEFINE_HANDLERS (flt);
-DEFINE_HANDLERS (dbl);
-DEFINE_HANDLERS (ldbl);
-DEFINE_HANDLERS (wchar);
-DEFINE_HANDLERS (pvoid);
+extern "C" {
 
-static int
-rw_enable_lines (int first, int last, bool enable)
+static void
+rw_clear_opts ()
 {
-    if (nlineranges == rangebufsize) {
-        const size_t newbufsize = 2 * nlineranges + 1;
-            
-        linerange_t* const newranges =
-            (linerange_t*)malloc (newbufsize * sizeof (linerange_t));
-
-        if (0 == newranges) {
-            abort ();
-        }
-
-        memcpy (newranges, lineranges, nlineranges * sizeof (linerange_t));
+    // reset all options, deallocating dynamically allocated storage
 
-        free (lineranges);
+    for (size_t i = 0; i != ncmdopts; ++i) {
 
-        lineranges   = newranges;
-        rangebufsize = newbufsize;
+        // free any storage allocated for the option name
+        free (cmdopts [i].lopt_);
     }
 
-    if (enable) {
-        lineranges [nlineranges].first = first;
-        lineranges [nlineranges].last  = last;
-    }
-    else {
-        lineranges [nlineranges].first = -first;
-        lineranges [nlineranges].last  = -last;
+    if (cmdopts != cmdoptbuf) {
+        // free the storage allocated for all the options
+        free (cmdopts);
     }
 
-    ++nlineranges;
-
-    return 0;
+    // reset the options pointer to point at the statically
+    // allocated buffer and the count back to 0
+    ncmdopts   = 0;
+    cmdopts    = cmdoptbuf;
+    optbufsize = sizeof cmdoptbuf / sizeof *cmdoptbuf;
 }
 
-
-static int
-rw_enable_line (int argc, char *argv[], bool enable)
-{
-    if (1 == argc && argv && 0 == argv [0]) {
-
-        static const char helpstr[] = {
-            "Enables or disables the lines specified by <arg>.\n"
-            "The syntax of <arg> is as follows: \n"
-            "<arg>   ::= <range> [ , <range> ]\n"
-            "<range> ::= [ - ] <number> | <number> - [ <number> ]\n"
-        };
-
-        argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
-
-        return 0;
-    }
-
-    char *parg = strchr (argv [0], '=');
-    assert (0 != parg);
-
-    const char* const argbeg = ++parg;
-
-    // the lower bound of a range of lines to be enabled or disabled
-    // negative values are not valid and denote an implicit lower bound
-    // of 1 (such as in "-3" which is a shorthand for "1-3")
-    long first = -1;
-
-    for ( ; '\0' != *parg ; ) {
-
-        printf ("%s (%ld)\n", parg, first);
-
-        // skip any leading whitespace
-        for ( ; ' ' == *parg; ++parg);
-
-        if ('-' == *parg) {
-            if (first < 0) {
-                first = 0;
-                ++parg;
-            }
-            else {
-                fprintf (stderr,
-                         "invalid character '%c' at position %d: \"%s\"\n",
-                         *parg, int (parg - argbeg), argv [0]);
-                return 2;
-            }
-        }
-
-        // parse a numeric argument
-        char *end;
-        long line = strtol (parg, &end, 0);
-
-        // skip any trailing whitespace
-        for ( ; ' ' == *end; ++end);
-
-        if (end == parg || '-' != *end && ',' != *end && '\0' != *end) {
-            fprintf (stderr,
-                     "invalid character '%c' at position %d: \"%s\"\n",
-                     *end, int (parg - argbeg), argv [0]);
-            return 2;
-        }
-
-        if (0 <= first) {
-            if (line < 0) {
-                fprintf (stderr,
-                         "invalid value %ld at position %d: \"%s\"\n",
-                         line, int (parg - argbeg), argv [0]);
-                return 2;
-            }
-
-            ++line;
-
-            if ((',' == *end || '-' == *end) && end [1])
-                ++end;
-        }
-        else if (',' == *end) {
-            first = line++;
-            if ('\0' == end [1]) {
-                fprintf (stderr,
-                         "invalid character '%c' at position %d: \"%s\"\n",
-                         *end, int (parg - argbeg), argv [0]);
-                return 2;
-            }
-
-            ++end;
-        }
-        else if ('-' == *end) {
-            first = line;
-            while (' ' == *++end);
-            if ('\0' == *end) {
-                line = _RWSTD_INT_MAX;
-            }
-            else if  (',' == *end) {
-                line = _RWSTD_INT_MAX;
-                ++end;
-            }
-            else
-                line = -1;
-        }
-        else if ('\0' == *end) {
-            first = line++;
-        }
-        else {
-            fprintf (stderr,
-                     "invalid character '%c' at position %d: \"%s\"\n",
-                     *end, int (parg - argbeg), argv [0]);
-            return 2;
-        }
-
-        parg = end;
-
-        if (0 <= first && first < line) {
-            printf ("  [%ld, %ld)\n", first, line);
-            rw_enable_lines (first, line, enable);
-            first = -1;
-        }
-    }
-
-    for (size_t i = 0; i != nlineranges; ++i) {
-        printf ("[%d, %d)\n", lineranges [i].first, lineranges [i].last);
-    }
-
-    return 0;
 }
 
-static int rw_en_line (int argc, char *argv[])
+static void
+rw_set_myopts ()
 {
-    return rw_enable_line (argc, argv, true);
-}
+    static int cleanup_handler_registered;
 
-static int rw_no_line (int argc, char *argv[])
-{
-    return rw_enable_line (argc, argv, false);
-}
+    if (0 == cleanup_handler_registered) {
+        atexit (rw_clear_opts);
+        cleanup_handler_registered = 1;
+    }
 
-static void rw_set_myopts ()
-{
     if (0 != ncmdopts)
         return;
 
-    static bool recursive;
+    static int recursive;
 
     if (recursive)
         return;
 
-    recursive = true;
+    ++recursive;
 
     rw_setopts ("|-help: "   // argument optional
-                "|-ignenv "
-                // options to disable fundamental types
-                "|-no-bool |-no-char |-no-schar |-no-uchar "
-                "|-no-shrt |-no-ushrt "
-                "|-no-int |-no-uint "
-                "|-no-long |-no-ulong "
-                "|-no-llong |-no-ullong "
-                "|-no-flt |-no-dbl |-no-ldbl "
-                "|-no-wchar |-no-pvoid "
-                // option to disable ranges of lines
-                "|-no-line= "
-                // options to enable fundamental types
-                "|-enable-bool |-enable-char |-enable-schar |-enable-uchar "
-                "|-enable-shrt |-enable-ushrt "
-                "|-enable-int |-enable-uint "
-                "|-enable-long |-enable-ulong "
-                "|-enable-llong |-enable-ullong "
-                "|-enable-flt |-enable-dbl |-enable-ldbl "
-                "|-enable-wchar |-enable-pvoid "
-                // option to enable ranges of lines
-                "|-enable-line= ",
-                //
+                "|-ignenv ",
                 rw_print_help,
-                rw_set_ignenv,
-                // handlers to disable fundamental types
-                rw_no_bool, rw_no_char, rw_no_schar, rw_no_uchar,
-                rw_no_shrt, rw_no_ushrt,
-                rw_no_int, rw_no_uint,
-                rw_no_long, rw_no_ulong,
-                rw_no_llong, rw_no_ullong,
-                rw_no_flt, rw_no_dbl, rw_no_ldbl,
-                rw_no_wchar, rw_no_pvoid,
-                rw_no_line,
-                // handlers to enable fundamental types
-                rw_en_bool, rw_en_char, rw_en_schar, rw_en_uchar,
-                rw_en_shrt, rw_en_ushrt,
-                rw_en_int, rw_en_uint,
-                rw_en_long, rw_en_ulong,
-                rw_en_llong, rw_en_ullong,
-                rw_en_flt, rw_en_dbl, rw_en_ldbl,
-                rw_en_wchar, rw_en_pvoid,
-                rw_en_line,
-                (optcallback_t*)0);
+                rw_set_ignenv);
 
     ndefopts = ncmdopts;
 
-    recursive = false;
+    recursive = 0;
 }
 
+/**************************************************************************/
 
 //////////////////////////////////////////////////////////////////////
 // syntax of the option description string:
@@ -503,27 +277,14 @@
 //      ::= '|' <lopt>
 // sopt ::= char
 // lopt ::= char char*
-// char ::= any character other than a space (' '), bar ('|'),
-//          colon (':') and the equals sign ('=')
+// char ::= A-Z a-z _ 0-9
 
 _TEST_EXPORT int
 rw_vsetopts (const char *opts, va_list va)
 {
     if (0 == opts) {
 
-        // reset to 0
-
-        for (size_t i = 0; i != ncmdopts; ++i) {
-            if (cmdopts [i].lopt_ != cmdopts [i].loptbuf_)
-                free (cmdopts [i].lopt_);
-        }
-
-        if (cmdopts != cmdoptbuf)
-            free (cmdopts);
-
-        cmdopts  = cmdoptbuf;
-        ncmdopts = 0;
-
+        rw_clear_opts ();
         return 0;
     }
 
@@ -548,6 +309,8 @@
                 (cmdopts_t*)malloc (newbufsize * sizeof (cmdopts_t));
 
             if (0 == newopts) {
+                fprintf (stderr, "%s%d: failed to allocate memory\n",
+                         __FILE__, __LINE__);
                 abort ();
             }
 
@@ -560,6 +323,7 @@
             optbufsize = newbufsize;
         }
 
+        // clear the next option info
         memset (cmdopts + ncmdopts, 0, sizeof *cmdopts);
 
         if ('|' != *next)
@@ -575,13 +339,17 @@
             // becomes the last character of the option name
             const size_t optlen = size_t (end - next) + ('=' == *end);
 
+            char *lopt = 0;
+
             if (optlen < sizeof cmdopts [ncmdopts].loptbuf_)
-                cmdopts [ncmdopts].lopt_ = cmdopts [ncmdopts].loptbuf_;
-            else
-                cmdopts [ncmdopts].lopt_ = (char*)malloc (optlen + 1);
+                lopt = cmdopts [ncmdopts].loptbuf_;
+            else {
+                lopt = (char*)malloc (optlen + 1);
+                cmdopts [ncmdopts].lopt_ = lopt;
+            }
 
-            memcpy (cmdopts [ncmdopts].lopt_, next, optlen);
-            cmdopts [ncmdopts].lopt_ [optlen] = '\0';
+            memcpy (lopt, next, optlen);
+            lopt [optlen] = '\0';
 
             next = end;
         }
@@ -591,7 +359,7 @@
         // ones will be ignored by default
         cmdopts [ncmdopts].maxcalls_ = 1;
 
-        bool arg_is_callback = true;
+        int arg_is_callback = true;
 
         if (':' == *next || '=' == *next) {
             // ':' : argument optional
@@ -651,9 +419,12 @@
             && 0 == cmdopts [ncmdopts].callback_
             && 0 == cmdopts [ncmdopts].pcntr_) {
 
-            if (cmdopts [ncmdopts].lopt_)
-                fprintf (stderr, "null handler for option -%s\n",
-                         cmdopts [ncmdopts].lopt_);
+            // get a pointer to the long option name
+            const char* const lopt = cmdopts [ncmdopts].lopt_
+                ? cmdopts [ncmdopts].lopt_ : cmdopts [ncmdopts].loptbuf_;
+
+            if (*lopt)
+                fprintf (stderr, "null handler for option -%s\n", lopt);
             else
                 fprintf (stderr, "null handler for option -%c\n",
                          cmdopts [ncmdopts].sopt_);
@@ -665,6 +436,7 @@
     return int (ncmdopts - ndefopts);
 }
 
+/**************************************************************************/
 
 _TEST_EXPORT int
 rw_setopts (const char *opts, ...)
@@ -676,16 +448,17 @@
     return result;
 }
 
+/**************************************************************************/
 
 _TEST_EXPORT int
 rw_runopts (int argc, char *argv[])
 {
     rw_set_myopts ();
 
-    static bool recursive = false;
+    static int recursive = false;
 
     // ignore options set in the environment?
-    bool ignenv = recursive;
+    int ignenv = recursive;
 
     // return status
     int status = 0;
@@ -714,7 +487,7 @@
             break;
         }
 
-        bool found = false;
+        int found = false;
 
         // look up each command line option (i.e., a string that starts
         // with a dash ('-')) and invoke the callback associated with it
@@ -736,11 +509,15 @@
                 const size_t optlen =
                     eq ? size_t (eq - optname + 1) : strlen (optname);
 
+                // get a pointer to the (possibly empty) name
+                // of the long option
+                const char* const lopt = cmdopts [j].lopt_ ? 
+                    cmdopts [j].lopt_ : cmdopts [j].loptbuf_;
+
                 // try to match the long option first, and only if it
                 // doesn't match try the short single-character option
-                if (   cmdopts [j].lopt_
-                    && optlen == strlen (cmdopts [j].lopt_)
-                    && 0 == memcmp (optname, cmdopts [j].lopt_, optlen)
+                if (   optlen == strlen (lopt)
+                    && 0 == memcmp (optname, lopt, optlen)
                     || cmdopts [j].sopt_
                     && optname [0] == cmdopts [j].sopt_
                     && (1 == optlen || cmdopts [j].arg_)) {
@@ -855,6 +632,7 @@
     return status;
 }
 
+/**************************************************************************/
 
 _TEST_EXPORT int
 rw_runopts (const char *str)
@@ -944,110 +722,4 @@
         free (pbuf);
 
     return status;
-
-}
-
-
-_TEST_EXPORT int
-rw_enabled (const char *name)
-{
-    int enabled = -1;
-
-    static const struct {
-        int bit;
-        const char *name;
-    } types[] = {
-        { rw_bool, "bool" },
-
-        { rw_char, "char" },
-
-        { rw_schar, "schar" },
-        { rw_schar, "signed char" },
-        { rw_uchar, "uchar" },
-        { rw_uchar, "unsigned char" },
-
-        { rw_shrt, "shrt" },
-        { rw_shrt, "short" },
-        { rw_shrt, "signed short" },
-        { rw_ushrt, "ushrt" },
-        { rw_ushrt, "unsigned short" },
-
-        { rw_int, "int" },
-        { rw_int, "signed int" },
-        { rw_uint, "uint" },
-        { rw_uint, "unsigned int" },
-
-        { rw_long, "long" },
-        { rw_long, "signed long" },
-        { rw_ulong, "ulong" },
-        { rw_ulong, "unsigned long" },
-
-        { rw_llong, "llong" },
-        { rw_llong, "long long" },
-        { rw_llong, "signed long long" },
-        { rw_ullong, "ullong" },
-        { rw_ullong, "unsigned long long" },
-
-        { rw_flt, "flt" },
-        { rw_flt, "float" },
-
-        { rw_dbl, "dbl" },
-        { rw_dbl, "double" },
-
-        { rw_ldbl, "ldbl" },
-        { rw_ldbl, "long double" },
-
-        { rw_wchar, "wchar" },
-        { rw_wchar, "wchar_t" },
-
-        { rw_pvoid, "pvoid" },
-        { rw_pvoid, "void*" }
-    };
-
-    for (size_t i = 0; i != sizeof types / sizeof *types; ++i) {
-        if (0 == strcmp (types [i].name, name)) {
-            const int mask = 1 << types [i].bit;
-
-            enabled = !(rw_disabled_types & mask);
-
-            if (rw_enabled_types)
-                enabled = enabled && (rw_enabled_types & mask);
-
-            break;
-        }
-    }
-
-    return enabled;
-}
-
-
-_TEST_EXPORT int
-rw_enabled (int line)
-{
-    int nenabled = 0;
-    int ndisabled = 0;
-
-    int line_enabled = -1;
-
-    for (size_t i = 0; i != nlineranges; ++i) {
-
-        const int first = lineranges [i].first;
-        const int last  = lineranges [i].last;
-
-        if (first < 0) {
-            line = -line;
-            ++ndisabled;
-        }
-        else {
-            ++nenabled;
-        }
-
-        if (lineranges [i].first <= line && line < lineranges [i].last)
-            line_enabled = 0 < line;
-    }
-
-    if (nenabled && -1 == line_enabled)
-        line_enabled = 0;
-
-    return line_enabled;
 }

Modified: incubator/stdcxx/trunk/tests/src/driver.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/driver.cpp?rev=287304&r1=287303&r2=287304&view=diff
==============================================================================
--- incubator/stdcxx/trunk/tests/src/driver.cpp (original)
+++ incubator/stdcxx/trunk/tests/src/driver.cpp Wed Sep 14 17:41:16 2005
@@ -19,12 +19,16 @@
  *
  **************************************************************************/
 
-
 // expand _TEST_EXPORT macros
 #define _RWSTD_TEST_SRC
 
+#include "opt_diags.h"
+#include "opt_lines.h"
+#include "opt_trace.h"
+#include "opt_types.h"
+
 #include <cmdopt.h>    // for rw_setopts()
-#include <printf.h>    // for rw_sprintfa()
+#include <printf.h>    // for rw_snprintfa()
 
 #include <assert.h>    // for assert
 #include <setjmp.h>    // for longjmp, setjmp, ...
@@ -307,112 +311,14 @@
 
 /************************************************************************/
 
-enum diag_t {
-    diag_trace_0 =  0,   // trace statements of inactive diagnostics
-    diag_trace_1 =  1,   // active trace statements (lots of noise)
-    diag_debug   =  2,   // debugging statements (less noise)
-    diag_info    =  3,   // informational messages (e.g., indicating progress)
-    diag_note    =  4,   // noteworthy events
-    diag_warn    =  5,   // warnings
-    diag_assert  =  6,   // assertions
-    diag_error   =  8,   // test logic errors (do not terminate the test)
-    diag_fatal   =  9,   // fatal errors (the first will terminate the test)
-
-    N_DIAG_TYPES = diag_fatal + 1,
-
-    diag_default_mask =
-      (1 << diag_info)
-    | (1 << diag_note)
-    | (1 << diag_warn)
-    | (1 << diag_assert)
-    | (1 << diag_error)
-    | (1 << diag_fatal)
-};
-
-#define ESC "\x1b"
-#define ESC_CODE(fg, bg, attr)   ESC "[" fg bg attr "m"
-
-// ANSI VT100 terminal codes:
-#define AT_OFF   "0;"   // all attributes off
-#define AT_BLD   "1;"   // bright/bold
-#define AT_DIM   "2;"   // dim
-// #define AT_???   "3;"   // ???
-#define AT_UND   "4;"   // underscore
-#define AT_BLI   "5;"   // blink
-// #define AT_???   "6;"   // ???
-#define AT_RVS   "7;"   // reverse video
-#define AT_HID   "8;"   // hidden
-
-#define FG_BLK   "30;"   // foreground black
-#define FG_RED   "31;"   // foreground red
-#define FG_GRN   "32;"   // foreground green
-#define FG_YLW   "33;"   // foreground yellow
-#define FG_BLU   "34;"   // foreground blue
-#define FG_MAG   "35;"   // foreground magenta
-#define FG_CYN   "36;"   // foreground cyan
-#define FG_WHT   "37;"   // foreground white
-
-#define BG_BLK   "40;"   // background black
-#define BG_RED   "41;"   // background red
-#define BG_GRN   "42;"   // background green
-#define BG_YLW   "43;"   // background yellow
-#define BG_BLU   "44;"   // background blue
-#define BG_MAG   "45;"   // background magenta
-#define BG_CYN   "46;"   // background cyan
-#define BG_WHT   "47;"   // background white
-
-
-struct esc_text_t {
-    char esc  [16];
-    char text [16];
-};
-
-static esc_text_t diag_msgs[] = {
-    { ESC_CODE (FG_CYN, "", AT_DIM),     "ITRACE" },
-    { ESC_CODE (FG_BLU, "", ""),         "TRACE" },
-    { ESC_CODE (FG_GRN, "", AT_BLI),     "DEBUG" },
-    { ESC_CODE ("", "", ""),             "INFO" },
-    { ESC_CODE (FG_BLU, BG_YLW, AT_BLI), "NOTE" },
-    { ESC_CODE (FG_MAG, "", ""),         "WARNING" },
-    { ESC_CODE (FG_RED, "", AT_UND),     "ASSERTION" },
-    { ESC_CODE ("", "", ""),             "UNUSED" },   // unused
-    { ESC_CODE (FG_WHT, BG_RED, AT_BLD), "ERROR" },
-    { ESC_CODE (FG_YLW, BG_RED, AT_BLD), "FATAL" }
-};
-
-static const esc_text_t vt100_colors[] = {
-    { FG_BLK, "black" },
-    { FG_RED, "red" },
-    { FG_GRN, "green" },
-    { FG_YLW, "yellow" },
-    { FG_BLU, "blue" },
-    { FG_MAG, "magenta" },
-    { FG_CYN, "cyan" },
-    { FG_WHT, "white" } 
-};
-
-static const esc_text_t vt100_attribs[] = {
-    { AT_OFF, "off" },
-    { AT_BLD, "bold" },
-    { AT_DIM, "dim" },
-    { AT_UND, "underscore" },
-    { AT_BLI, "blink" },
-    { AT_RVS, "reverse" },
-    { AT_HID, "hidden" }
-};
-
-static char escape_end[] = ESC "[30;30;0m";
-
 // array to store the number of each type of diagnostic
-static int ndiags [N_DIAG_TYPES][2] /* = { { failed, attempted }, ... }*/;
+static int
+ndiags [N_DIAG_TYPES][2] /* = { { total, active }, ... }*/;
 
 static FILE *ftestout;
 
 static jmp_buf test_env;
 
-// diagnostics enabled by defaults
-static int trace_mask = diag_default_mask;
-
 // set to 1 after the driver has been initialized
 static int driver_initialized = 0;
 
@@ -435,25 +341,25 @@
 #endif
 
 /// option: use of stdout disabled
-static int opt_no_stdout = 0;
+static int _rw_opt_no_stdout = 0;
 
 // option: verbose diagnostic output
-static int opt_verbose = 0;
+static int _rw_opt_verbose = 0;
 
 // option: use CSV format (comma separated values)
-static int opt_csv = 0;
+static int _rw_opt_csv = 0;
 
 // option: use RWTest compatibility format
-static int opt_compat = 0;
+static int _rw_opt_compat = 0;
 
 static char clause_id [80];
 
 /************************************************************************/
 
-#define CHECK_INIT(init, func)   rw_check_init (init, __LINE__, func)
+#define CHECK_INIT(init, func)   _rw_check_init (init, __LINE__, func)
 
 static inline void
-rw_check_init (bool init, int line, const char *func)
+_rw_check_init (bool init, int line, const char *func)
 {
     if (init && !driver_initialized) {
         fprintf (stderr, "%s:%d: %s: test driver already initialized\n",
@@ -476,7 +382,7 @@
 /************************************************************************/
 
 static int
-rw_set_verbose (int argc, char *argv[])
+_rw_setopt_verbose (int argc, char *argv[])
 {
     if (1 == argc && argv && 0 == argv [0]) {
         static const char helpstr[] = {
@@ -488,14 +394,14 @@
         return 0;
     }
 
-    opt_verbose = 1;
+    _rw_opt_verbose = 1;
     return 0;
 }
 
 /************************************************************************/
 
 static int
-rw_set_csv (int argc, char *argv[])
+_rw_setopt_csv (int argc, char *argv[])
 {
     if (1 == argc && argv && 0 == argv [0]) {
         static const char helpstr[] = {
@@ -507,14 +413,14 @@
         return 0;
     }
 
-    opt_csv = 1;
+    _rw_opt_csv = 1;
     return 0;
 }
 
 /************************************************************************/
 
 static int
-rw_set_compat (int argc, char *argv[])
+_rw_setopt_compat (int argc, char *argv[])
 {
     if (1 == argc && argv && 0 == argv [0]) {
         static const char helpstr[] = {
@@ -526,14 +432,14 @@
         return 0;
     }
 
-    opt_compat = 1;
+    _rw_opt_compat = 1;
     return 0;
 }
 
 /************************************************************************/
 
 static int
-rw_set_stdout (int argc, char *argv[])
+_rw_setopt_stdout (int argc, char *argv[])
 {
     if (1 == argc && argv && 0 == argv [0]) {
         static const char helpstr[] = {
@@ -551,398 +457,14 @@
         return 0;
     }
     
-    opt_no_stdout = 1;
-    return 0;
-}
-
-/************************************************************************/
-
-static int
-match_name (const esc_text_t *text, size_t nelems,
-            const char *first, const char *last)
-{
-    assert (0 != text);
-    assert (0 != first);
-    assert (first <= last);
-
-    const size_t len = size_t (last - first);
-
-    if (0 == len)
-        return int (nelems);
-
-    for (size_t i = 0; i != nelems; ++i) {
-        if (   0 == strncmp (text [i].text, first, len)
-            && '\0' == text [i].text [len])
-            return int (i);
-    }
-
-    return -1;
-}
-
-
-static int
-rw_set_diags (int argc, char *argv[])
-{
-    if (1 == argc && argv && 0 == argv [0]) {
-        static const char helpstr[] = {
-            "Sets the colors and names of the diagnostic messages issued by\n"
-            "the program.\n"
-            "There are 10 different types of diagnostic messages, each with\n"
-            "a unique severity level between 0 (the lowest) and 9. Each\n"
-            "diagnostic message can either be active or inactive. Each\n"
-            "message can have a name of up to 15 characters associated with\n"
-            "it, foreground color, background color, and a video attribute.\n"
-            "These parameters are controlled by the argument to this option.\n"
-            "\nThe syntax of <arg> is as follows:\n"
-            "<arg>        ::= <color-list>\n"
-            "<color-list> ::= <color-txt> [ ,<color-list> ]\n"
-            "<color-text> ::= <sev>:[<color>][:[<color>][:[<attr>][:[<text>]]]]"
-            "\n<sev>        ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n"
-            "<color>      ::=   black | red | green | yellow\n"
-            "                 | blue | magenta | cyan | white\n"
-            "<attr>       ::=   off | bold | dim | underscore\n"
-            "                 | blink | reverse | hidden\n"
-            "<text>       ::= A-Z a-z 0-9 _\n\n"
-            "The first <color> component specifies the foreground color\n"
-            "while the second (optional) <color> component specifies\n"
-            "the background color for the diagnostic of the severity <sev>.\n"
-            "Empty arguments are permitted and denote the default system\n"
-            "color set for the terminal.\n"
-        };
-
-        argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
-
-        return 0;
-    }
-
-    char *parg = strchr (argv [0], '=');
-
-    if (0 == parg || '\0' == parg [1]) {
-        fprintf (stderr, "%s:%d: missing argument in %s\n",
-                 __FILE__, __LINE__, argv [0]);
-        return 1;
-    }
-
-    ++parg;
-
-    // argument syntax:
-    //
-    // <sev-color-list> := <sev-color-text> [ ,<sev-color-list> ]
-    // <sev-color-text> := <sev>:[<color>][:[<color>][:[<attr>][:[<text>]]]]
-    // <sev>            := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
-    // <color>          :=   black | red | green | yellow
-    //                     | blue | magenta | cyan | white
-    // <attr>           :=   off | bold | dim | underscore
-    //                     | blink | reverse | hidden
-    // <text>           := A-Z a-z 0-9 _
-
-
-    int ret = 0;
-
-    while (*parg) {
-
-        int severity = -1;
-        int fgcol    = -1;
-        int bgcol    = -1;
-        int attr     = -1;
-
-        char diag_text [sizeof diag_msgs [0].text];
-        *diag_text = '\0';
-
-        if ('0' <= *parg && *parg <= '9') {
-            severity = *parg++ - '0';
-        }
-        else {
-            // digit expected
-            fprintf (stderr, "%s:%d: digit expected at position %d: %s\n",
-                 __FILE__, __LINE__, int (parg - argv [0]), argv [0]);
-
-            ret = 1;
-            break;
-        }
-
-        if (':' == *parg) {
-            ++parg;
-        }
-        else {
-            // colon expected
-            fprintf (stderr, "%s:%d: colon expected at position %d: %s\n",
-                 __FILE__, __LINE__, int (parg - argv [0]), argv [0]);
-
-            ret = 1;
-            break;
-        }
-
-        char *end = strpbrk (parg, ":,");
-        if (0 == end)
-            end = parg + strlen (parg);
-
-        fgcol = match_name (vt100_colors, 8, parg, end);
-        if (fgcol < 0 || 8 < fgcol) {
-            // invalid color
-            fprintf (stderr, "%s:%d: unknown color at position %d: %s\n",
-                 __FILE__, __LINE__, int (parg - argv [0]), argv [0]);
-
-            ret = 1;
-            break;
-        }
-
-        if (':' == *end || '\0' == *end) {
-            parg = end + (0 != *end);
-            end  = strpbrk (parg, ":,");
-            if (0 == end)
-                end = parg + strlen (parg);
-
-            bgcol = match_name (vt100_colors, 8, parg, end);
-
-            if (bgcol < 0 || 8 < bgcol) {
-                // invalid color
-                fprintf (stderr, "%s:%d: unknown color at position %d: %s\n",
-                         __FILE__, __LINE__, int (parg - argv [0]), argv [0]);
-
-                ret = 1;
-                break;
-            }
-
-            if (':' == *end || '\0' == *end) {
-                parg = end + ('\0' != *end);
-                end  = strpbrk (parg, ":,");
-                if (0 == end)
-                    end = parg + strlen (parg);
-
-                attr = match_name (vt100_attribs, 8, parg, end);
-                if (attr < 0 || 8 < attr) {
-                    // invalid attribute
-                    fprintf (stderr,
-                             "%s:%d: unknown attribute at position %d: %s\n",
-                             __FILE__, __LINE__, int (parg - argv [0]),
-                             argv [0]);
-
-                    ret = 1;
-                    break;
-                }
-
-                if (':' == *end || '\0' == *end) {
-                    parg = end + (0 != *end);
-                    end  = strpbrk (parg, ":,");
-                    if (0 == end)
-                        end = parg + strlen (parg);
-
-                    size_t len = size_t (end - parg);
-
-                    if (sizeof diag_msgs [severity].text < len) {
-                        
-                        // name too long
-                        fprintf (stderr,
-                                 "%s:%d: name too long at position %d: %s\n",
-                                 __FILE__, __LINE__, int (parg - argv [0]),
-                                 argv [0]);
-
-                        len = sizeof diag_msgs [severity].text;
-                    }
-
-                    memcpy (diag_text, parg, len);
-                    diag_text [len] = '\0';
-                }
-            }
-        }
-
-        strcpy (diag_msgs [severity].esc, ESC "[");
-
-        if (fgcol < 8)
-            strcat (diag_msgs [severity].esc, vt100_colors [fgcol].esc);
-
-        if (bgcol < 8) {
-            strcat (diag_msgs [severity].esc, vt100_colors [bgcol].esc);
-
-            const size_t bgdiginx = strlen (diag_msgs [severity].esc) - 3;
-
-            assert ('3' == diag_msgs [severity].esc [bgdiginx]);
-            diag_msgs [severity].esc [bgdiginx] = '4';
-        }
-
-        if (attr < 8)
-            strcat (diag_msgs [severity].esc, vt100_attribs [attr].esc);
-
-        if (diag_msgs [severity].esc [2])
-            strcat (diag_msgs [severity].esc, "m");
-        else
-            diag_msgs [severity].esc [0] = '\0';
-
-        if (*diag_text)
-            strcpy (diag_msgs [severity].text, diag_text);
-
-        parg = end + ('\0' != *end);
-    }
-
-    return ret;
-}
-
-/************************************************************************/
-
-static int
-rw_set_trace_mask (int argc, char *argv[])
-{
-    if (1 == argc && argv && 0 == argv [0]) {
-        static const char helpstr[] = {
-            "Specifies the severity of diagnostic messages to be issued when\n"
-            "active. By default, diagnostics with severity of 3 and and above\n"
-            "are issued, all others are suppressed. The severity of an inactive"
-            "\ndiagnostic is always zero, regardless of what the severity would"
-            "\nbe if it were active.\n\n"
-            "The syntax of <arg> is as follows:\n"
-            "<arg>   ::= <range> [ , <range> ]\n"
-            "<range> ::= [ - ] <digit> | <digit> - [ <digit> ]\n"
-            "<digit> ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n"
-            "\n"
-            "The default names of the diagnostic messages arranged in order\n"
-            "of increasing severity are as follows:\n"
-            "ITRACE, TRACE, DEBUG, INFO, NOTE, WARNING, ASSERTION, UNUSED,\n"
-            "ERROR, and FATAL.\n"
-            "The name of each inactive diagnostic is preceded by the name\n"
-            "of the severity-0 diagnostic (ITRACE_ by default). The severity\n"
-            "of an inactive diagnostic is always zero, regardless of what\n"
-            "the severity would be if it were active.\n"
-        };
-
-        argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
-
-        return 0;
-    }
-
-    char *parg = strchr (argv [0], '=');
-
-    if (0 == parg) {
-        trace_mask = -1;
-        return 0;
-    }
-        
-    int new_mask = 0;
-
-    const char* const argbeg = ++parg;
-
-    // the lower bound of a range of severities to be enabled or disabled
-    // negative values are not valid and denote an implicit lower bound
-    // of 1 (such as in "-3" which is a shorthand for "1-3")
-    long first = -1;
-
-    for ( ; '\0' != *parg ; ) {
-
-        // skip any leading whitespace
-        for ( ; ' ' == *parg; ++parg);
-
-        if ('-' == *parg) {
-            if (first < 0) {
-                first = 0;
-                ++parg;
-            }
-            else {
-                fprintf (stderr,
-                         "invalid character '%c' at position %d: \"%s\"\n",
-                         *parg, int (parg - argbeg), argv [0]);
-                return 2;
-            }
-        }
-
-        // parse a numeric argument
-        char *end;
-        long severity = strtol (parg, &end, 0);
-
-        // skip any trailing whitespace
-        for ( ; ' ' == *end; ++end);
-
-        if (end == parg || '-' != *end && ',' != *end && '\0' != *end) {
-            fprintf (stderr,
-                     "invalid character '%c' at position %d: \"%s\"\n",
-                     *end, int (parg - argbeg), argv [0]);
-            return 2;
-        }
-
-        if (0 <= first) {
-            if (severity < 0 || N_DIAG_TYPES < severity) {
-                fprintf (stderr,
-                         "invalid value %ld at position %d: \"%s\"\n",
-                         severity, int (parg - argbeg), argv [0]);
-                return 2;
-            }
-
-            ++severity;
-
-            if ((',' == *end || '-' == *end) && end [1])
-                ++end;
-        }
-        else if (',' == *end) {
-            first = severity++;
-            if ('\0' == end [1]) {
-                fprintf (stderr,
-                         "invalid character '%c' at position %d: \"%s\"\n",
-                         *end, int (parg - argbeg), argv [0]);
-                return 2;
-            }
-
-            ++end;
-        }
-        else if ('-' == *end) {
-            first = severity;
-            while (' ' == *++end);
-            if ('\0' == *end) {
-                severity = N_DIAG_TYPES;
-            }
-            else if  (',' == *end) {
-                severity = N_DIAG_TYPES;
-                ++end;
-            }
-            else
-                severity = -1;
-        }
-        else if ('\0' == *end) {
-            first = severity++;
-        }
-        else {
-            fprintf (stderr,
-                     "invalid character '%c' at position %d: \"%s\"\n",
-                     *end, int (parg - argbeg), argv [0]);
-            return 2;
-        }
-
-        parg = end;
-
-        if (0 <= first && first < severity) {
-            for (int i = first; i != severity; ++i)
-                new_mask |= 1 << i;
-            severity = -1;
-        }
-    }
-
-    trace_mask = new_mask;
-
+    _rw_opt_no_stdout = 1;
     return 0;
 }
 
 /************************************************************************/
 
 static int
-rw_set_trace (int argc, char *argv[])
-{
-    if (1 == argc && argv && 0 == argv [0]) {
-        static const char helpstr[] = {
-            "Specifies that diagnostic messages of all severities be issued\n"
-            "regardless of whether they are active or not. See the --severity\n"
-            "option for details.\n"
-        };
-
-        argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
-
-        return 0;
-    }
-
-    return rw_set_trace_mask (argc, argv);
-}
-
-/************************************************************************/
-
-static int
-rw_set_output_file (int argc, char *argv[])
+_rw_setopt_output_file (int argc, char *argv[])
 {
     if (1 == argc && argv && 0 == argv [0]) {
         static const char helpstr[] = {
@@ -982,8 +504,6 @@
     return !(ftestout != 0);
 }
 
-/************************************************************************/
-
 _TEST_EXPORT int
 rw_vsetopts (const char *opts, va_list va);
 
@@ -1005,23 +525,26 @@
         return 1;
     }
 
-    if (3 > rw_setopts ("|-no-stdout "
-                        "|-diags= "      // argument required
-                        "|-trace "
-                        "|-severity= "   // argument required
-                        "|-csv "
-                        "|-compat "
-                        "o|-output:"     // argument optional
-                        "v|-verbose",
-                        rw_set_stdout,
-                        rw_set_diags,
-                        rw_set_trace,
-                        rw_set_trace_mask,
-                        rw_set_csv,
-                        rw_set_compat,
-                        rw_set_output_file,
-                        rw_set_verbose,
-                        0)) {
+    const int nopts =
+        rw_setopts ("|-no-stdout "
+                    "|-diags= "      // argument required
+                    "|-trace "
+                    "|-severity= "   // argument required
+                    "|-csv "
+                    "|-compat "
+                    "o|-output:"     // argument optional
+                    "v|-verbose",
+                    _rw_setopt_stdout,
+                    _rw_setopt_diags,
+                    _rw_setopt_trace,
+                    _rw_setopt_trace_mask,
+                    _rw_setopt_csv,
+                    _rw_setopt_compat,
+                    _rw_setopt_output_file,
+                    _rw_setopt_verbose,
+                    0);
+
+    if (3 > nopts) {
         fprintf (stderr, "%s:%d: rw_setopts() failed\n", __FILE__, __LINE__);
         abort ();
         return 1;
@@ -1030,13 +553,17 @@
 #ifndef _RWSTD_USE_CONFIG
 
     // enable RWTest compatibility mode
-    rw_set_compat (0, 0);
+    _rw_setopt_compat (0, 0);
 
     // disable output to stdout
-    rw_set_stdout (0, 0);
+    _rw_setopt_stdout (0, 0);
 
 #endif   // _RWSTD_USE_CONFIG
 
+    _rw_setopts_types ();
+
+    _rw_setopts_lines ();
+
     int status = rw_runopts (argc, argv);
 
     if (status)
@@ -1044,7 +571,7 @@
 
     if (0 == ftestout) {
 
-        if (opt_no_stdout && file_name) {
+        if (_rw_opt_no_stdout && file_name) {
             char fname [256];
 
             const char* const slash = strrchr (file_name, _RWSTD_PATH_SEP);
@@ -1096,15 +623,19 @@
 
     driver_finished = 1;
 
+    static const char tblrow[] =
+        "+-----------------------+--------+--------+--------+";
+
     fprintf (ftestout,
-             "# +-----------------------+--------+--------+--------+\n"
+             "# %s\n"
              "# | DIAGNOSTIC            | ACTIVE |  TOTAL |   PASS |\n"
-             "# +-----------------------+--------+--------+--------+\n");
+             "# %s\n",
+             tblrow, tblrow);
 
     int nlines = 0;
 
     for (int i = 0; i != N_DIAG_TYPES; ++i) {
-        if (ndiags [i][0] || trace_mask & (diag_debug | diag_trace_1)) {
+        if (ndiags [i][0] || !(_rw_diag_mask & (1 << diag_trace))) {
 
             // print out details for any non-zero totals
             // or for all totals when debugging or tracing
@@ -1119,7 +650,7 @@
 
             fprintf (ftestout,
                      "# | (S%d) %-*s | %6d | %6d | %5ld%% |\n",
-                     i, sizeof diag_msgs [i].text, diag_msgs [i].text,
+                     i, int (sizeof diag_msgs [i].code), diag_msgs [i].code,
                      ndiags [i][1], ndiags [i][0], pct);
         }
     }
@@ -1127,10 +658,9 @@
     if (0 == nlines)
         fprintf (ftestout, "# no diagnostics\n");
 
-    fprintf (ftestout,
-             "# +-----------------------+--------+--------+--------+\n");
+    fprintf (ftestout, "# %s\n", tblrow);
 
-    if (opt_compat) {
+    if (_rw_opt_compat) {
 
         // TO DO: get rid of this
 
@@ -1141,9 +671,9 @@
                  "## Warnings = %d\n"
                  "## Assertions = %d\n"
                  "## FailedAssertions = %d\n",
-                 ndiags [diag_warn][1],
+                 ndiags [diag_warn][1] + ndiags [diag_xwarn][1],
                  ndiags [diag_assert][0],
-                 ndiags [diag_assert][1]);
+                 ndiags [diag_assert][1] + ndiags [diag_xassert][1]);
     }
 
     fclose (ftestout);
@@ -1186,7 +716,7 @@
 // buffer, otherwise the original value of buf and leaves *pbufsize
 // unchanged
 static char*
-rw_escape (char *buf, size_t bufsize, char esc)
+_rw_escape (char *buf, size_t bufsize, char esc)
 {
     // handle null buffer
     if (0 == buf)
@@ -1266,35 +796,66 @@
 /************************************************************************/
 
 static void
-rw_vdiag (diag_t diag, int severity, const char *file, int line,
-          const char *fmt, va_list va)
+_rw_vdiag (diag_t diag, int severity, const char *file, int line,
+           const char *fmt, va_list va)
 {
-    CHECK_INIT (true, "rw_vdiag()");
+    CHECK_INIT (true, "_rw_vdiag()");
+
+    if (0 == fmt)
+        fmt = "";
+
+    // check if the diagnostic is expected
+    const int expected = 0 != _rw_expected (line);
+
+    if (expected) {
+        if (severity) {
+            // if the diagnostic is expected to be active,
+            // adjust its type and severity
+            if (diag_assert == diag)
+                diag = diag_xassert;
+            else if (diag_warn == diag)
+                diag = diag_xwarn;
+
+            severity = diag * severity;
+        }
+        else {
+            // if the diagnostic is expected to be active but isn't,
+            // adjust its type to an unexpectdly inactive one
+            if (diag_assert == diag || diag_warn == diag)
+                diag = diag_expect;
 
-    // normalize the severity
-    if (diag)
+            severity = diag;
+        }
+    }
+    else if (diag) {
+        // normalize the severity
         severity = diag * severity;
+    }
 
     if (severity < 0)
         severity = 0;
     else if (N_DIAG_TYPES <= severity)
         severity = N_DIAG_TYPES - 1;
 
-    // increment the appropriate diagnostic counter
+    // increment the diagnostic counter
     ++ndiags [diag][0];
 
-    if (severity)
+    if (severity) {
+
         ++ndiags [diag][1];
+    }
 
-    if ((1 << severity) & trace_mask) {
+    if (0 == ((1 << severity) & _rw_diag_mask)) {
 
         assert (0 != fmt);
 
+        static char fmterr[] = "*** formatting error ***";
+
         char *usrbuf = 0;
         const int nchars = rw_vasnprintf (&usrbuf, 0, fmt, va);
 
-        if (nchars < 0)
-            usrbuf = _RWSTD_CONST_CAST (char*, "*error formatting string*");
+        if (nchars < 0 || 0 == usrbuf)
+            usrbuf = fmterr;
 
         // compute the number of newline characters in the text
         int nlines = 0;
@@ -1315,13 +876,15 @@
 #endif   // _RWSTD_NO_ISATTY
 
         const char* const diagstr[] = {
-            tty ? diag_msgs [severity].esc : "",
-            *diag_msgs [severity].text ? diag_msgs [severity].text : "UNKNOWN",
-            tty && *diag_msgs [severity].esc ? escape_end : ""
+            tty ? diag_msgs [severity].esc_pfx : "",
+            *diag_msgs [severity].code ? diag_msgs [severity].code : "UNKNOWN",
+            tty ? diag_msgs [severity].esc_sfx : "",
+            _rw_opt_verbose && *diag_msgs [severity].desc ?
+            diag_msgs [severity].desc : 0
         };
 
         const char* const traced_diag =
-            0 == severity && diag_msgs [diag].text ? diag_msgs [diag].text : 0;
+            0 == severity && diag_msgs [diag].code ? diag_msgs [diag].code : 0;
 
         const char* const slash = file ? strrchr (file, _RWSTD_PATH_SEP) : 0;
         if (slash)
@@ -1329,7 +892,7 @@
 
         char *mybuf = 0;
 
-        if (opt_csv) {
+        if (_rw_opt_csv) {
 
             // format all fields as comma separated values (CSV):
             // -- a field containing the quote character, the comma,
@@ -1341,7 +904,7 @@
 
             // escape all double quotes by prepending the double
             // quote character to each according to the CSV format
-            char* const newbuf = rw_escape (usrbuf, 0, '"');
+            char* const newbuf = _rw_escape (usrbuf, 0, '"');
             if (newbuf != usrbuf) {
                 free (usrbuf);
                 usrbuf = newbuf;
@@ -1363,28 +926,35 @@
                              line,
                              usrbuf);
         }
-        else if (opt_verbose) {
+        else {
 
             nlines += 2 + ('\0' != *clause_id) + (0 != file) + (0 < line);
 
             mybuf =
-                rw_sprintfa ("# %s%s"                    // diagnostic
-                             "%{?}_%s%{;}%s "            // traced diagnostic
-                             "(S%d) "                    // severity
+                rw_sprintfa ("# %s"                      // escape prefix
+                             "%s"                        // diagnostic
+                             "%{?}_%s%{;}"               // traced diagnostic
+                             "%s "                       // escape suffix
+                             "(S%d)"                     // severity
+                             "%{?}, %s%{;} "             // description
                              "(%d lines):\n"             // number of lines
                              "# TEXT: %s\n"              // user text
                              "%{?}# CLAUSE: %s\n%{;}"    // clause if not empty
                              "%{?}# FILE: %s\n%{;}"      // file if not null
                              "%{?}# LINE: %d\n%{;}",     // line if positive
-                             diagstr [0], diagstr [1],
-                             0 != traced_diag, traced_diag, diagstr [2],
+                             diagstr [0],
+                             diagstr [1],
+                             0 != traced_diag, traced_diag,
+                             diagstr [2],
                              severity,
+                             0 != diagstr [3], diagstr [3],
                              nlines,
                              usrbuf,
                              '\0' != *clause_id, clause_id,
                              0 != file, file,
                              0 < line, line);
         }
+#if 0
         else {
 
             mybuf =
@@ -1409,11 +979,15 @@
                              0 < line, line,
                              usrbuf);
         }
+#endif   // 0/1
 
         fprintf (ftestout, "%s\n", mybuf);
 
-        free (mybuf);
-        free (usrbuf);
+        if (mybuf != fmterr)
+            free (mybuf);
+
+        if (usrbuf != fmterr)
+            free (usrbuf);
     }
 
     if (diag_fatal == diag && severity) {
@@ -1432,7 +1006,7 @@
     va_list va;
     va_start (va, fmt);
 
-    rw_vdiag (diag_fatal, 0 == success, file, line, fmt, va);
+    _rw_vdiag (diag_fatal, 0 == success, file, line, fmt, va);
 
     va_end (va);
 
@@ -1449,7 +1023,7 @@
     va_list va;
     va_start (va, fmt);
 
-    rw_vdiag (diag_error, 0 == success, file, line, fmt, va);
+    _rw_vdiag (diag_error, 0 == success, file, line, fmt, va);
 
     va_end (va);
 
@@ -1466,7 +1040,7 @@
     va_list va;
     va_start (va, fmt);
 
-    rw_vdiag (diag_assert, 0 == success, file, line, fmt, va);
+    _rw_vdiag (diag_assert, 0 == success, file, line, fmt, va);
 
     va_end (va);
 
@@ -1483,7 +1057,7 @@
     va_list va;
     va_start (va, fmt);
 
-    rw_vdiag (diag_warn, 0 == success, file, line, fmt, va);
+    _rw_vdiag (diag_warn, 0 == success, file, line, fmt, va);
 
     va_end (va);
 
@@ -1500,7 +1074,7 @@
     va_list va;
     va_start (va, fmt);
 
-    rw_vdiag (diag_note, 0 == success, file, line, fmt, va);
+    _rw_vdiag (diag_note, 0 == success, file, line, fmt, va);
 
     va_end (va);
 
@@ -1517,41 +1091,7 @@
     va_list va;
     va_start (va, fmt);
 
-    rw_vdiag (diag_info, 0 == success, file, line, fmt, va);
-
-    va_end (va);
-
-    return success;
-}
-
-/************************************************************************/
-
-_TEST_EXPORT int
-rw_debug (int success, const char *file, int line, const char *fmt, ...)
-{
-    CHECK_INIT (true, "rw_debug()");
-
-    va_list va;
-    va_start (va, fmt);
-
-    rw_vdiag (diag_debug, 0 == success, file, line, fmt, va);
-
-    va_end (va);
-
-    return success;
-}
-
-/************************************************************************/
-
-_TEST_EXPORT int
-rw_trace (int success, const char *file, int line, const char *fmt, ...)
-{
-    CHECK_INIT (true, "rw_trace()");
-
-    va_list va;
-    va_start (va, fmt);
-
-    rw_vdiag (diag_trace_1, 0 == success, file, line, fmt, va);
+    _rw_vdiag (diag_info, 0 == success, file, line, fmt, va);
 
     va_end (va);
 

Added: incubator/stdcxx/trunk/tests/src/opt_diags.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/opt_diags.cpp?rev=287304&view=auto
==============================================================================
--- incubator/stdcxx/trunk/tests/src/opt_diags.cpp (added)
+++ incubator/stdcxx/trunk/tests/src/opt_diags.cpp Wed Sep 14 17:41:16 2005
@@ -0,0 +1,381 @@
+/************************************************************************
+ *
+ * opt_diags.cpp - definitions of diagnostic option handlers
+ *
+ * $Id:$
+ *
+ ************************************************************************
+ *
+ * Copyright (c) 1994-2005 Quovadx, Inc. All Rights Reserved.
+ * 
+ * This computer software  is owned by Quovadx, Inc.  and is protected by
+ * U.S.  copyright laws  and other  laws and  by  international treaties.
+ * This computer  software is furnished  by Quovadx, Inc., pursuant  to a
+ * written license  agreement and may  be used, copied,  transmitted, and
+ * stored only in accordance with the terms of such license agreement and
+ * with  the inclusion  of  the above  copyright  notice.  This  computer
+ * software or any other copies  thereof may not be provided or otherwise
+ * made available to any other person.
+ * 
+ * 
+ * U.S. Government Restricted Rights.
+ * 
+ * This computer software: (a) was developed at private expense and is in
+ * all respects the proprietary information of Quovadx, Inc.; (b) was not
+ * developed with  government funds;  (c) is a  trade secret  of Quovadx,
+ * Inc. for all purposes of the  Freedom of Information Act; and (d) is a
+ * commercial item  and thus, pursuant  to Section 12.212 of  the Federal
+ * Acquisition  Regulations (FAR) and  DFAR Supplement  Section 227.7202,
+ * Government's use,  duplication or disclosure of  the computer software
+ * is subject to the restrictions set forth by Quovadx, Inc.
+ *
+ **************************************************************************/
+
+// expand _TEST_EXPORT macros
+#define _RWSTD_TEST_SRC
+
+#include "opt_diags.h"
+
+#include <assert.h>   // for assert()
+#include <stdio.h>    // for fprintf()
+#include <string.h>   // for strlen(), strncmp(), ...
+
+
+#define ESC "\x1b"
+#define ESC_END ESC "[30;30;0m"
+#define ESC_CODE(fg, bg, attr)   ESC "[" fg bg attr "m", ESC_END
+
+
+// ANSI VT100 terminal codes:
+#define AT_OFF   "0;"   // all attributes off
+#define AT_BLD   "1;"   // bright/bold
+#define AT_DIM   "2;"   // dim
+// #define AT_???   "3;"   // ???
+#define AT_UND   "4;"   // underscore
+#define AT_BLI   "5;"   // blink
+// #define AT_???   "6;"   // ???
+#define AT_RVS   "7;"   // reverse video
+#define AT_HID   "8;"   // hidden
+
+#define FG_BLK   "30;"   // foreground black
+#define FG_RED   "31;"   // foreground red
+#define FG_GRN   "32;"   // foreground green
+#define FG_YLW   "33;"   // foreground yellow
+#define FG_BLU   "34;"   // foreground blue
+#define FG_MAG   "35;"   // foreground magenta
+#define FG_CYN   "36;"   // foreground cyan
+#define FG_WHT   "37;"   // foreground white
+
+#define BG_BLK   "40;"   // background black
+#define BG_RED   "41;"   // background red
+#define BG_GRN   "42;"   // background green
+#define BG_YLW   "43;"   // background yellow
+#define BG_BLU   "44;"   // background blue
+#define BG_MAG   "45;"   // background magenta
+#define BG_CYN   "46;"   // background cyan
+#define BG_WHT   "47;"   // background white
+
+
+esc_text_t diag_msgs[] = {
+    /* severity 0 */ {
+        ESC_CODE (FG_CYN, "", AT_DIM),
+        "ITRACE",
+        "inactive diagnostic trace"
+    },
+    /* severity 1 */ {
+        ESC_CODE (FG_BLK, "",     ""),
+        "INFO",
+        "information"
+    },
+    /* severity 2 */ {
+        ESC_CODE (FG_GRN, "", AT_BLI),
+        "NOTE",
+        "noteworthy event"
+    },
+    /* severity 3 */ {
+        ESC_CODE (FG_WHT, BG_GRN, AT_BLD),
+        "EXPECT",
+        "expected diagnostic inactive"
+    },
+    /* severity 4 */ {
+        ESC_CODE (FG_MAG, "", ""),
+        "XWARN",
+        "expected warning"
+    },
+    /* severity 5 */ {
+        ESC_CODE (FG_MAG, "", AT_BLD AT_UND),
+        "WARNING",
+        ""
+    },
+    /* severity 6 */ {
+        ESC_CODE (FG_RED, "", ""),
+        "XASSERT",
+        "expected assertion"
+    },
+    /* severity 7 */ {
+        ESC_CODE (FG_RED, "", AT_BLD AT_UND),
+        "ASSERTION",
+        ""
+    },
+    /* severity 8 */ {
+        ESC_CODE (FG_WHT, BG_RED, AT_BLD),
+        "ERROR",
+        "test error"
+    },
+    /* severity 9 */ {
+        ESC_CODE (FG_YLW, BG_RED, AT_BLD),
+        "FATAL",
+        "fatal test error, abort imminent"
+    }
+};
+
+
+static const esc_text_t
+_rw_vt100_colors[] = {
+    { FG_BLK, "black" },
+    { FG_RED, "red" },
+    { FG_GRN, "green" },
+    { FG_YLW, "yellow" },
+    { FG_BLU, "blue" },
+    { FG_MAG, "magenta" },
+    { FG_CYN, "cyan" },
+    { FG_WHT, "white" } 
+};
+
+
+static const esc_text_t
+_rw_vt100_attribs[] = {
+    { AT_OFF, "off" },
+    { AT_BLD, "bold" },
+    { AT_DIM, "dim" },
+    { AT_UND, "underscore" },
+    { AT_BLI, "blink" },
+    { AT_RVS, "reverse" },
+    { AT_HID, "hidden" }
+};
+
+
+static int
+_rw_match_name (const esc_text_t *text, size_t nelems,
+                const char *first, const char *last)
+{
+    assert (0 != text);
+    assert (0 != first);
+    assert (first <= last);
+
+    const size_t len = size_t (last - first);
+
+    if (0 == len)
+        return int (nelems);
+
+    for (size_t i = 0; i != nelems; ++i) {
+        if (   0 == strncmp (text [i].code, first, len)
+            && '\0' == text [i].code [len])
+            return int (i);
+    }
+
+    return -1;
+}
+
+
+/* extern */ int
+_rw_setopt_diags (int argc, char *argv[])
+{
+    if (1 == argc && argv && 0 == argv [0]) {
+        static const char helpstr[] = {
+            "Sets the colors and names of the diagnostic messages issued by\n"
+            "the program.\n"
+            "There are 10 different types of diagnostic messages, each with\n"
+            "a unique severity level between 0 (the lowest) and 9. Each\n"
+            "diagnostic message can either be active or inactive. Each\n"
+            "message can have a name of up to 15 characters associated with\n"
+            "it, foreground color, background color, and a video attribute.\n"
+            "These parameters are controlled by the argument to this option.\n"
+            "\nThe syntax of <arg> is as follows:\n"
+            "<arg>        ::= <color-list>\n"
+            "<color-list> ::= <color-txt> [ ,<color-list> ]\n"
+            "<color-text> ::= <sev>:[<color>][:[<color>][:[<attr>][:[<text>]]]]"
+            "\n<sev>        ::= 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9\n"
+            "<color>      ::=   black | red | green | yellow\n"
+            "                 | blue | magenta | cyan | white\n"
+            "<attr>       ::=   off | bold | dim | underscore\n"
+            "                 | blink | reverse | hidden\n"
+            "<text>       ::= A-Z a-z 0-9 _\n\n"
+            "The first <color> component specifies the foreground color\n"
+            "while the second (optional) <color> component specifies\n"
+            "the background color for the diagnostic of the severity <sev>.\n"
+            "Empty arguments are permitted and denote the default system\n"
+            "color set for the terminal.\n"
+        };
+
+        argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
+
+        return 0;
+    }
+
+    char *parg = strchr (argv [0], '=');
+
+    if (0 == parg || '\0' == parg [1]) {
+        fprintf (stderr, "%s:%d: missing argument in %s\n",
+                 __FILE__, __LINE__, argv [0]);
+        return 1;
+    }
+
+    ++parg;
+
+    // argument syntax:
+    //
+    // <sev-color-list> := <sev-color-text> [ ,<sev-color-list> ]
+    // <sev-color-text> := <sev>:[<color>][:[<color>][:[<attr>][:[<text>]]]]
+    // <sev>            := 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9
+    // <color>          :=   black | red | green | yellow
+    //                     | blue | magenta | cyan | white
+    // <attr>           :=   off | bold | dim | underscore
+    //                     | blink | reverse | hidden
+    // <text>           := A-Z a-z 0-9 _
+
+
+    int ret = 0;
+
+    while (*parg) {
+
+        int sev = -1;
+        int fgcol    = -1;
+        int bgcol    = -1;
+        int attr     = -1;
+
+        char diag_code [sizeof diag_msgs [0].code];
+        *diag_code = '\0';
+
+        if ('0' <= *parg && *parg <= '9') {
+            sev = *parg++ - '0';
+        }
+        else {
+            // digit expected
+            fprintf (stderr, "%s:%d: digit expected at position %d: %s\n",
+                 __FILE__, __LINE__, int (parg - argv [0]), argv [0]);
+
+            ret = 1;
+            break;
+        }
+
+        if (':' == *parg) {
+            ++parg;
+        }
+        else {
+            // colon expected
+            fprintf (stderr, "%s:%d: colon expected at position %d: %s\n",
+                 __FILE__, __LINE__, int (parg - argv [0]), argv [0]);
+
+            ret = 1;
+            break;
+        }
+
+        char *end = strpbrk (parg, ":,");
+        if (0 == end)
+            end = parg + strlen (parg);
+
+        fgcol = _rw_match_name (_rw_vt100_colors, 8, parg, end);
+        if (fgcol < 0 || 8 < fgcol) {
+            // invalid color
+            fprintf (stderr, "%s:%d: unknown color at position %d: %s\n",
+                 __FILE__, __LINE__, int (parg - argv [0]), argv [0]);
+
+            ret = 1;
+            break;
+        }
+
+        if (':' == *end || '\0' == *end) {
+            parg = end + (0 != *end);
+            end  = strpbrk (parg, ":,");
+            if (0 == end)
+                end = parg + strlen (parg);
+
+            bgcol = _rw_match_name (_rw_vt100_colors, 8, parg, end);
+
+            if (bgcol < 0 || 8 < bgcol) {
+                // invalid color
+                fprintf (stderr, "%s:%d: unknown color at position %d: %s\n",
+                         __FILE__, __LINE__, int (parg - argv [0]), argv [0]);
+
+                ret = 1;
+                break;
+            }
+
+            if (':' == *end || '\0' == *end) {
+                parg = end + ('\0' != *end);
+                end  = strpbrk (parg, ":,");
+                if (0 == end)
+                    end = parg + strlen (parg);
+
+                attr = _rw_match_name (_rw_vt100_attribs, 8, parg, end);
+                if (attr < 0 || 8 < attr) {
+                    // invalid attribute
+                    fprintf (stderr,
+                             "%s:%d: unknown attribute at position %d: %s\n",
+                             __FILE__, __LINE__, int (parg - argv [0]),
+                             argv [0]);
+
+                    ret = 1;
+                    break;
+                }
+
+                if (':' == *end || '\0' == *end) {
+                    parg = end + (0 != *end);
+                    end  = strpbrk (parg, ":,");
+                    if (0 == end)
+                        end = parg + strlen (parg);
+
+                    size_t len = size_t (end - parg);
+
+                    if (sizeof diag_msgs [sev].code < len) {
+                        
+                        // name too long
+                        fprintf (stderr,
+                                 "%s:%d: name too long at position %d: %s\n",
+                                 __FILE__, __LINE__, int (parg - argv [0]),
+                                 argv [0]);
+
+                        len = sizeof diag_msgs [sev].code;
+                    }
+
+                    memcpy (diag_code, parg, len);
+                    diag_code [len] = '\0';
+                }
+            }
+        }
+
+        strcpy (diag_msgs [sev].esc_pfx, ESC "[");
+
+        if (fgcol < 8)
+            strcat (diag_msgs [sev].esc_pfx, _rw_vt100_colors [fgcol].esc_pfx);
+
+        if (bgcol < 8) {
+            strcat (diag_msgs [sev].esc_pfx, _rw_vt100_colors [bgcol].esc_pfx);
+
+            const size_t bgdiginx = strlen (diag_msgs [sev].esc_pfx) - 3;
+
+            assert ('3' == diag_msgs [sev].esc_pfx [bgdiginx]);
+            diag_msgs [sev].esc_pfx [bgdiginx] = '4';
+        }
+
+        if (attr < 8)
+            strcat (diag_msgs [sev].esc_pfx, _rw_vt100_attribs [attr].esc_pfx);
+
+        if (diag_msgs [sev].esc_pfx [2]) {
+            strcat (diag_msgs [sev].esc_pfx, "m");
+            strcpy (diag_msgs [sev].esc_sfx, ESC_END);
+        }
+        else {
+            diag_msgs [sev].esc_pfx [0] = '\0';
+            diag_msgs [sev].esc_sfx [0] = '\0';
+        }
+
+        if (*diag_code)
+            strcpy (diag_msgs [sev].code, diag_code);
+
+        parg = end + ('\0' != *end);
+    }
+
+    return ret;
+}

Propchange: incubator/stdcxx/trunk/tests/src/opt_diags.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/stdcxx/trunk/tests/src/opt_diags.h
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/opt_diags.h?rev=287304&view=auto
==============================================================================
--- incubator/stdcxx/trunk/tests/src/opt_diags.h (added)
+++ incubator/stdcxx/trunk/tests/src/opt_diags.h Wed Sep 14 17:41:16 2005
@@ -0,0 +1,74 @@
+/************************************************************************
+ *
+ * opt_diags.h - declarations of diagnostic option handlers
+ *
+ * $Id:$
+ *
+ ************************************************************************
+ *
+ * Copyright (c) 1994-2005 Quovadx, Inc. All Rights Reserved.
+ * 
+ * This computer software  is owned by Quovadx, Inc.  and is protected by
+ * U.S.  copyright laws  and other  laws and  by  international treaties.
+ * This computer  software is furnished  by Quovadx, Inc., pursuant  to a
+ * written license  agreement and may  be used, copied,  transmitted, and
+ * stored only in accordance with the terms of such license agreement and
+ * with  the inclusion  of  the above  copyright  notice.  This  computer
+ * software or any other copies  thereof may not be provided or otherwise
+ * made available to any other person.
+ * 
+ * 
+ * U.S. Government Restricted Rights.
+ * 
+ * This computer software: (a) was developed at private expense and is in
+ * all respects the proprietary information of Quovadx, Inc.; (b) was not
+ * developed with  government funds;  (c) is a  trade secret  of Quovadx,
+ * Inc. for all purposes of the  Freedom of Information Act; and (d) is a
+ * commercial item  and thus, pursuant  to Section 12.212 of  the Federal
+ * Acquisition  Regulations (FAR) and  DFAR Supplement  Section 227.7202,
+ * Government's use,  duplication or disclosure of  the computer software
+ * is subject to the restrictions set forth by Quovadx, Inc.
+ *
+ **************************************************************************/
+
+#ifndef RW_OPT_DIAGS_H_INCLUDED
+#define RW_OPT_DIAGS_H_INCLUDED
+
+
+#include <testdefs.h>
+
+
+enum diag_t {
+    diag_trace   =  0,   // trace statements of inactive diagnostics
+    diag_info    =  1,   // informational messages (e.g., indicating progress)
+    diag_note    =  2,   // noteworthy events
+    diag_expect  =  3,   // unexpected diagnostic inactive
+    diag_xwarn   =  4,   // expected warning
+    diag_warn    =  5,   // warning
+    diag_xassert =  6,   // expected assertion failure
+    diag_assert  =  7,   // assertion failure
+    diag_error   =  8,   // test logic errors (do not terminate the test)
+    diag_fatal   =  9,   // fatal errors (the first will terminate the test)
+
+    N_DIAG_TYPES = diag_fatal + 1
+};
+
+
+struct esc_text_t
+{
+    char esc_pfx [16];   // escape prefix
+    char esc_sfx [16];   // escape suffix
+    char code    [16];   // short code
+    char desc    [40];   // verbose description
+};
+
+
+extern esc_text_t
+diag_msgs [N_DIAG_TYPES];
+
+
+int
+_rw_setopt_diags (int argc, char *argv[]);
+
+
+#endif   // RW_OPT_DIAGS_H_INCLUDED

Propchange: incubator/stdcxx/trunk/tests/src/opt_diags.h
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/stdcxx/trunk/tests/src/opt_lines.cpp
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/opt_lines.cpp?rev=287304&view=auto
==============================================================================
--- incubator/stdcxx/trunk/tests/src/opt_lines.cpp (added)
+++ incubator/stdcxx/trunk/tests/src/opt_lines.cpp Wed Sep 14 17:41:16 2005
@@ -0,0 +1,340 @@
+/************************************************************************
+ *
+ * opt_lines.cpp - definitions of line option handlers
+ *
+ * $Id:$
+ *
+ ************************************************************************
+ *
+ * Copyright (c) 1994-2005 Quovadx, Inc. All Rights Reserved.
+ * 
+ * This computer software  is owned by Quovadx, Inc.  and is protected by
+ * U.S.  copyright laws  and other  laws and  by  international treaties.
+ * This computer  software is furnished  by Quovadx, Inc., pursuant  to a
+ * written license  agreement and may  be used, copied,  transmitted, and
+ * stored only in accordance with the terms of such license agreement and
+ * with  the inclusion  of  the above  copyright  notice.  This  computer
+ * software or any other copies  thereof may not be provided or otherwise
+ * made available to any other person.
+ * 
+ * 
+ * U.S. Government Restricted Rights.
+ * 
+ * This computer software: (a) was developed at private expense and is in
+ * all respects the proprietary information of Quovadx, Inc.; (b) was not
+ * developed with  government funds;  (c) is a  trade secret  of Quovadx,
+ * Inc. for all purposes of the  Freedom of Information Act; and (d) is a
+ * commercial item  and thus, pursuant  to Section 12.212 of  the Federal
+ * Acquisition  Regulations (FAR) and  DFAR Supplement  Section 227.7202,
+ * Government's use,  duplication or disclosure of  the computer software
+ * is subject to the restrictions set forth by Quovadx, Inc.
+ *
+ **************************************************************************/
+
+// expand _TEST_EXPORT macros
+#define _RWSTD_TEST_SRC
+
+#include "opt_lines.h"
+
+#include <cmdopt.h>
+
+#include <assert.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+
+enum {
+    l_enabled  = 1,   // line is enabled
+    l_disabled = 2,   // line is disabled
+    l_expected = 4    // diagnostic on line is expected to be active
+};
+
+struct linerange_t {
+    int      first;
+    int      last;
+    unsigned flags: 8;
+    char     id [80];
+};
+
+static size_t nlineranges;
+static linerange_t *lineranges;
+static size_t rangebufsize;
+
+/**************************************************************************/
+
+static int
+_rw_enable_lines (int first, int last, int flags)
+{
+    if (nlineranges == rangebufsize) {
+        const size_t newbufsize = 2 * nlineranges + 1;
+            
+        linerange_t* const newranges =
+            (linerange_t*)malloc (newbufsize * sizeof (linerange_t));
+
+        if (0 == newranges) {
+            abort ();
+        }
+
+        memcpy (newranges, lineranges, nlineranges * sizeof (linerange_t));
+
+        free (lineranges);
+
+        lineranges   = newranges;
+        rangebufsize = newbufsize;
+    }
+
+    lineranges [nlineranges].first = first;
+    lineranges [nlineranges].last  = last;
+
+    lineranges [nlineranges].flags = flags;
+
+    ++nlineranges;
+
+    return 0;
+}
+
+
+static int
+_rw_enable_line (int argc, char *argv[], int flags)
+{
+    char *parg = strchr (argv [0], '=');
+    assert (0 != parg);
+
+    const char* const argbeg = ++parg;
+
+    // the lower bound of a range of lines to be enabled or disabled
+    // negative values are not valid and denote an implicit lower bound
+    // of 1 (such as in "-3" which is a shorthand for "1-3")
+    long first = -1;
+
+    for ( ; '\0' != *parg ; ) {
+
+        // skip any leading whitespace
+        for ( ; ' ' == *parg; ++parg);
+
+        if ('-' == *parg) {
+            if (first < 0) {
+                first = 0;
+                ++parg;
+            }
+            else {
+                fprintf (stderr,
+                         "invalid character '%c' at position %d: \"%s\"\n",
+                         *parg, int (parg - argbeg), argv [0]);
+                return 2;
+            }
+        }
+
+        // parse a numeric argument
+        char *end;
+        long line = strtol (parg, &end, 0);
+
+        // skip any trailing whitespace
+        for ( ; ' ' == *end; ++end);
+
+        if (end == parg || '-' != *end && ',' != *end && '\0' != *end) {
+            fprintf (stderr,
+                     "invalid character '%c' at position %d: \"%s\"\n",
+                     *end, int (parg - argbeg), argv [0]);
+            return 2;
+        }
+
+        if (0 <= first) {
+            if (line < 0) {
+                fprintf (stderr,
+                         "invalid value %ld at position %d: \"%s\"\n",
+                         line, int (parg - argbeg), argv [0]);
+                return 2;
+            }
+
+            ++line;
+
+            if ((',' == *end || '-' == *end) && end [1])
+                ++end;
+        }
+        else if (',' == *end) {
+            first = line++;
+            if ('\0' == end [1]) {
+                fprintf (stderr,
+                         "invalid character '%c' at position %d: \"%s\"\n",
+                         *end, int (parg - argbeg), argv [0]);
+                return 2;
+            }
+
+            ++end;
+        }
+        else if ('-' == *end) {
+            first = line;
+            while (' ' == *++end);
+            if ('\0' == *end) {
+                line = _RWSTD_INT_MAX;
+            }
+            else if  (',' == *end) {
+                line = _RWSTD_INT_MAX;
+                ++end;
+            }
+            else
+                line = -1;
+        }
+        else if ('\0' == *end) {
+            first = line++;
+        }
+        else {
+            fprintf (stderr,
+                     "invalid character '%c' at position %d: \"%s\"\n",
+                     *end, int (parg - argbeg), argv [0]);
+            return 2;
+        }
+
+        parg = end;
+
+        if (0 <= first && first < line) {
+            _rw_enable_lines (first, line, flags);
+            first = -1;
+        }
+    }
+
+    return 0;
+}
+
+/**************************************************************************/
+
+static int
+_rw_opt_enable_line (int argc, char *argv[])
+{
+    if (1 == argc && argv && 0 == argv [0]) {
+
+        static const char helpstr[] = {
+            "Enables the line or lines specified by <arg>.\n"
+            "The syntax of <arg> is as follows: \n"
+            "<arg>   ::= <range> [ , <range> ]\n"
+            "<range> ::= [ - ] <number> | <number> - [ <number> ]\n"
+        };
+
+        argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
+
+        return 0;
+    }
+
+    return _rw_enable_line (argc, argv, l_enabled);
+}
+
+/**************************************************************************/
+
+static int
+_rw_opt_no_line (int argc, char *argv[])
+{
+    if (1 == argc && argv && 0 == argv [0]) {
+
+        static const char helpstr[] = {
+            "Disables the line or lines specified by <arg>.\n"
+            "The syntax of <arg> is as follows: \n"
+            "<arg>   ::= <range> [ , <range> ]\n"
+            "<range> ::= [ - ] <number> | <number> - [ <number> ]\n"
+        };
+
+        argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
+
+        return 0;
+    }
+
+    return _rw_enable_line (argc, argv, l_disabled);
+}
+
+/**************************************************************************/
+
+static int
+_rw_opt_expect_line (int argc, char *argv[])
+{
+    if (1 == argc && argv && 0 == argv [0]) {
+
+        static const char helpstr[] = {
+            "Marks the line or lines specified by <arg> as \"expected\".\n"
+            "Inactive diagnostics on such lines will be issued as unexpected.\n"
+            "The syntax of <arg> is as follows: \n"
+            "<arg>   ::= <range> [ , <range> ]\n"
+            "<range> ::= [ - ] <number> | <number> - [ <number> ]\n"
+        };
+
+        argv [0] = _RWSTD_CONST_CAST (char*, helpstr);
+
+        return 0;
+    }
+
+    return _rw_enable_line (argc, argv, l_expected);
+}
+
+/************************************************************************/
+
+/* extern */ int
+_rw_setopts_lines ()
+{
+    const int result =
+        rw_setopts ("|-enable-line="   // argument required
+                    "|-expect= "       // argument required
+                    "|-no-line= ",     // argument required
+                    _rw_opt_enable_line,
+                    _rw_opt_expect_line,
+                    _rw_opt_no_line);
+
+    return result;
+}
+
+/************************************************************************/
+
+/* extern */ int
+_rw_expected (int line)
+{
+    int line_expected = 0;
+
+    for (size_t i = 0; i != nlineranges; ++i) {
+
+        const int first = lineranges [i].first;
+        const int last  = lineranges [i].last;
+
+        if (lineranges [i].flags & (l_disabled | l_enabled)) {
+            continue;
+        }
+
+        if (first <= line && line < last)
+            line_expected = 0 != (lineranges [i].flags & l_expected);
+    }
+
+    return line_expected;
+}
+
+/************************************************************************/
+
+_TEST_EXPORT int
+rw_enabled (int line)
+{
+    int nenabled = 0;
+    int ndisabled = 0;
+
+    int line_enabled = -1;
+
+    for (size_t i = 0; i != nlineranges; ++i) {
+
+        const int first = lineranges [i].first;
+        const int last  = lineranges [i].last;
+
+        if (lineranges [i].flags & l_disabled) {
+            ++ndisabled;
+        }
+        else if (lineranges [i].flags & l_enabled) {
+            ++nenabled;
+        }
+        else {
+            continue;
+        }
+
+        if (first <= line && line < last)
+            line_enabled = 0 != (lineranges [i].flags & l_enabled);
+    }
+
+    if (nenabled && -1 == line_enabled)
+        line_enabled = 0;
+
+    return line_enabled;
+}

Propchange: incubator/stdcxx/trunk/tests/src/opt_lines.cpp
------------------------------------------------------------------------------
    svn:eol-style = native

Added: incubator/stdcxx/trunk/tests/src/opt_lines.h
URL: http://svn.apache.org/viewcvs/incubator/stdcxx/trunk/tests/src/opt_lines.h?rev=287304&view=auto
==============================================================================
--- incubator/stdcxx/trunk/tests/src/opt_lines.h (added)
+++ incubator/stdcxx/trunk/tests/src/opt_lines.h Wed Sep 14 17:41:16 2005
@@ -0,0 +1,49 @@
+/************************************************************************
+ *
+ * opt_lines.h - declarations of line option handlers
+ *
+ * $Id:$
+ *
+ ************************************************************************
+ *
+ * Copyright (c) 1994-2005 Quovadx, Inc. All Rights Reserved.
+ * 
+ * This computer software  is owned by Quovadx, Inc.  and is protected by
+ * U.S.  copyright laws  and other  laws and  by  international treaties.
+ * This computer  software is furnished  by Quovadx, Inc., pursuant  to a
+ * written license  agreement and may  be used, copied,  transmitted, and
+ * stored only in accordance with the terms of such license agreement and
+ * with  the inclusion  of  the above  copyright  notice.  This  computer
+ * software or any other copies  thereof may not be provided or otherwise
+ * made available to any other person.
+ * 
+ * 
+ * U.S. Government Restricted Rights.
+ * 
+ * This computer software: (a) was developed at private expense and is in
+ * all respects the proprietary information of Quovadx, Inc.; (b) was not
+ * developed with  government funds;  (c) is a  trade secret  of Quovadx,
+ * Inc. for all purposes of the  Freedom of Information Act; and (d) is a
+ * commercial item  and thus, pursuant  to Section 12.212 of  the Federal
+ * Acquisition  Regulations (FAR) and  DFAR Supplement  Section 227.7202,
+ * Government's use,  duplication or disclosure of  the computer software
+ * is subject to the restrictions set forth by Quovadx, Inc.
+ *
+ **************************************************************************/
+
+#ifndef RW_OPT_LINES_H_INCLUDED
+#define RW_OPT_LINES_H_INCLUDED
+
+
+#include <testdefs.h>
+
+
+extern int
+_rw_setopts_lines ();
+
+
+extern int
+_rw_expected (int line);
+
+
+#endif   // RW_OPT_LINES_H_INCLUDED

Propchange: incubator/stdcxx/trunk/tests/src/opt_lines.h
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message