stdcxx-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From se...@apache.org
Subject svn commit: r562224 - in /incubator/stdcxx/trunk/util: display.cpp display.h exec.cpp runall.cpp target.h util.cpp util.h
Date Thu, 02 Aug 2007 19:04:28 GMT
Author: sebor
Date: Thu Aug  2 12:04:26 2007
New Revision: 562224

URL: http://svn.apache.org/viewvc?view=rev&rev=562224
Log:
2007-07-26  Martin Sebor  <sebor@roguewave.com>

	* display.h (print_footer): Added an argument for the total number
	of programs processed by the utility.
	* display.cpp (print_target_verbose): Print stdin, stdout, and stderr
	redirectiopn.
	(print_status_verbose): Justified output.
	(print_footer_plain): Printed the total number of programs processed
	by the utility and avoided printing assertion totals unless they're
	valid.
	(print_footer_verbose): Added an argument.
	* target.h (target_opts): Added infname and outfname members.
	* util.h (input_name): Declared.
	* util.cpp (input_name): Defined to parallel output_name().
	* exec.cpp (open_input): Removed.
	(exec_file): Used target_opts::infname and target_opts::outfname.
	* runall.cpp (run_target): Called input_name() and output_name()
	to set the names of files to redirect input and output from and
	to, respectively.
	Avoided printing out assertion totals when they're not valid.

Modified:
    incubator/stdcxx/trunk/util/display.cpp
    incubator/stdcxx/trunk/util/display.h
    incubator/stdcxx/trunk/util/exec.cpp
    incubator/stdcxx/trunk/util/runall.cpp
    incubator/stdcxx/trunk/util/target.h
    incubator/stdcxx/trunk/util/util.cpp
    incubator/stdcxx/trunk/util/util.h

Modified: incubator/stdcxx/trunk/util/display.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/display.cpp?view=diff&rev=562224&r1=562223&r2=562224
==============================================================================
--- incubator/stdcxx/trunk/util/display.cpp (original)
+++ incubator/stdcxx/trunk/util/display.cpp Thu Aug  2 12:04:26 2007
@@ -161,6 +161,14 @@
 
     printf ("%s ", "Executing \"");
     print_argv (defaults->argv, 0 /* no newline */);
+
+    /* print stdin, stdout, and stderr redirections */
+    if (defaults->infname && *defaults->infname)
+        printf (" <%s", defaults->infname);
+
+    if (defaults->outfname && *defaults->outfname)
+        printf (" >%s 2>&1", defaults->outfname);
+
     puts ("\"");
 
     /* flush to prevent killing a signal from not displaying the text */
@@ -238,7 +246,7 @@
     if (status->status) /* if status is set, print it */
         printf ("  Status: %s\n", verbose_st_name [status->status]);
     else if (status->signaled) /* if exit signal is non-zero, print it */
-        printf ("  Process signalled: %s", get_signame (status->exit));
+        printf ("  Process signalled:    %s\n", get_signame (status->exit));
     else {
         printf ("  Exit status:          %6d%s\n"
                 "  Compiler warnings:    %6u\n"
@@ -279,29 +287,36 @@
    viewing.
 */
 static void
-print_footer_plain (const struct target_status *summary)
+print_footer_plain (int count, const struct target_status *summary)
 {
     printf ("PROGRAM SUMMARY:\n"
+            "  Programs:             %6d\n"
             "  Non-zero exit status: %6d\n"
             "  Signalled:            %6d\n"
             "  Compiler warnings:    %6u\n"
             "  Linker warnings:      %6u\n"
-            "  Runtime warnings:     %6u\n"
-            "  Assertions:           %6u\n"
-            "  Failed assertions:    %6u\n",
+            "  Runtime warnings:     %6u\n",
+            count,
             summary->exit,
             summary->signaled,
             summary->c_warn,
             summary->l_warn,
-            summary->t_warn,
-            summary->assert,
-            summary->failed);
+            summary->t_warn);
+
+    if ((unsigned)-1 != summary->assert) {
+        /* print assertion counters only when they're valid */
+        printf ("  Assertions:           %6u\n"
+                "  Failed assertions:    %6u\n",
+                summary->assert,
+                summary->failed);
+    }
 }
 
+
 static void
-print_footer_verbose (const struct target_status *summary)
+print_footer_verbose (int count, const struct target_status *summary)
 {
-    print_footer_plain (summary);
+    print_footer_plain (count, summary);
 }
 
 
@@ -331,4 +346,4 @@
 void (*print_header) (const char* const[]) = print_header_plain;
 void (*print_target) (const struct target_opts*) = print_target_plain;
 void (*print_status) (const struct target_status*) = print_status_plain;
-void (*print_footer) (const struct target_status*) = print_footer_plain;
+void (*print_footer) (int, const struct target_status*) = print_footer_plain;

Modified: incubator/stdcxx/trunk/util/display.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/display.h?view=diff&rev=562224&r1=562223&r2=562224
==============================================================================
--- incubator/stdcxx/trunk/util/display.h (original)
+++ incubator/stdcxx/trunk/util/display.h Thu Aug  2 12:04:26 2007
@@ -89,7 +89,7 @@
 /**
    Prints the closing formatting for the table.
 */
-extern void (*print_footer) (const struct target_status* status);
+extern void (*print_footer) (int count, const struct target_status* status);
 
 
 #endif   /* RW_DISPLAY_H */

Modified: incubator/stdcxx/trunk/util/exec.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/exec.cpp?view=diff&rev=562224&r1=562223&r2=562224
==============================================================================
--- incubator/stdcxx/trunk/util/exec.cpp (original)
+++ incubator/stdcxx/trunk/util/exec.cpp Thu Aug  2 12:04:26 2007
@@ -620,79 +620,6 @@
     }
 }
 
-/**
-   Opens an input file, based on exec_name
-
-   Takes a data directory and an executable name, and tries to open an input 
-   file based on these variables.  If a file is found in neither of two 
-   locattions derived from these variables, this method tries to fall back on 
-   /dev/null.
-
-   Source file locations:
-     - [data_dir]/manual/in/[exec_name].in
-     - [data_dir]/tutorial/in/[exec_name].in
-     - /dev/null
-
-   @param data_dir the path of the reference data directory
-   @param exec_name the name of executable being run
-   @returns the file descriptor of the opened file
-*/
-static int
-open_input (const char* data_dir, const char* exec_name)
-{
-    int intermit = -1;
-
-    assert (0 != exec_name);
-
-    if (data_dir && data_dir) {
-        char* tmp_name;
-
-        /* Try data_dir/manual/in/exec_name.in */
-        tmp_name = reference_name (data_dir, "manual", "in");
-        intermit = open (tmp_name, O_RDONLY);
-    
-        /* If we opened the file, return the descriptor */
-        if (0 <= intermit) {
-            free (tmp_name);
-            return intermit;
-        }
-
-        /* If the file exists (errno isn't ENOENT), exit */
-        if (ENOENT != errno)
-            terminate (1, "open (%s) failed: %s\n", tmp_name, 
-                       strerror (errno));
-
-        /* Try data_dir/tutorial/in/exec_name.in */
-        free (tmp_name);
-        tmp_name = reference_name (data_dir, "tutorial", "in");
-        intermit = open (tmp_name, O_RDONLY);
-
-        /* If we opened the file, return the descriptor */
-        if (0 <= intermit) {
-            free (tmp_name);
-            return intermit;
-        }
-
-        /* If the file exists (errno isn't ENOENT), exit */
-        if (-1 == intermit && ENOENT != errno)
-            terminate (1, "open (%s) failed: %s\n", tmp_name, 
-                       strerror (errno));
-
-        free (tmp_name);
-    }
-
-    /* If we didn't find a source file, open /dev/null */
-
-    intermit = open ("/dev/null", O_RDONLY);
-
-    /* If we opened the file, return the descriptor */
-    if (0 <= intermit)
-        return intermit;
-
-    /* otherwise, print an error message and exit */
-    terminate (1, "open (/dev/null) failed: %s\n", strerror (errno));
-    return -1; /* silence a compiler warning */
-}
 
 /**
    Replaces one file descriptor with a second, closing second after replacing
@@ -874,25 +801,23 @@
 
         /* Redirect stdin */
         {
-            const int intermit = open_input (options->data_dir, target_name);
+            const int intermit = open (options->infname, O_RDONLY);
             replace_file (intermit, 0, "stdin");
         }
 
         /* Redirect stdout */
         {
-            char* const tmp_name = output_name (options->argv [0]);
             int intermit;
 
-            intermit = open (tmp_name, O_WRONLY | O_CREAT | O_TRUNC, 
+            intermit = open (options->outfname,
+                             O_WRONLY | O_CREAT | O_TRUNC, 
                              S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
 
             if (-1 == intermit)
                 terminate (1, "Error opening %s for output redirection: "
-                           "%s\n", tmp_name, strerror (errno));
+                           "%s\n", options->outfname, strerror (errno));
 
             replace_file (intermit, 1, "stdout");
-
-            free (tmp_name);
         }
 
         /* Redirect stderr */
@@ -953,69 +878,6 @@
 
 
 /**
-   Opens an input file, based on exec_name, using the child_sa security 
-   setting.
-
-   Takes a data directory, an executable name and security setting, and tries 
-   to open an input file based on these variables.
-   If a file is found in neither of two locations derived from these 
-   variables, or if data_dir is a null string, it returns null.
-   If a file system error occurs when opening a file, INVALID_HANDLE_VALUE
-   is returned (and should be checked for).
-
-   Source file locations:
-     - [data_dir]/manual/in/[exec_name].in
-     - [data_dir]/tutorial/in/[exec_name].in
-
-   @param data_dir the path of the reference data directory
-   @param exec_name the name of executable being run
-   @param child_sa pointer to a SECURITY_ATTRIBUTES    structure
-   @returns the file descriptor of the opened file
-*/
-static HANDLE
-open_input (const char* data_dir, const char* exec_name, 
-            SECURITY_ATTRIBUTES* child_sa)
-{
-    HANDLE intermit;
-    DWORD error;
-    char* tmp_name;
-
-    assert (0 != exec_name);
-    assert (0 != child_sa);
-
-    if (0 == data_dir || '\0' == *data_dir) 
-        return 0;
-
-    /* Try data_dir\manual\in\exec_name.in */
-    tmp_name = reference_name (data_dir, "manual", "in");
-
-    intermit = CreateFile (tmp_name, GENERIC_READ, FILE_SHARE_READ, child_sa, 
-        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-
-    error = GetLastError ();
-    /* If we found the file, return the descriptor */
-    if (INVALID_HANDLE_VALUE != intermit || (2 != error && 3 != error)) {
-        free (tmp_name);
-        return intermit;
-    }
-
-    /* Try data_dir\tutorial\in\exec_name.in */
-    free (tmp_name);
-    tmp_name = reference_name (data_dir, "tutorial", "in");
-    intermit = CreateFile (tmp_name, GENERIC_READ, FILE_SHARE_READ, child_sa, 
-        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
-
-    /* If we didn't find the file, null out the handle to return */
-    error = GetLastError ();
-    if (INVALID_HANDLE_VALUE == intermit && (2 == error || 3 == error)) {
-        intermit = 0;
-    }
-
-    free (tmp_name);
-    return intermit;
-}
-
-/**
    Convert an argv array into a string that can be passed to CreateProcess.
 
    This method allocates memory which the caller is responsible for free ()ing.
@@ -1170,9 +1032,8 @@
     /* Create I/O handles */
     {
         /* Output redirection */
-        char* const tmp_name = output_name (options->argv [0]);
 
-        context.hStdOutput = CreateFile (tmp_name, GENERIC_WRITE, 
+        context.hStdOutput = CreateFile (options->outfname, GENERIC_WRITE, 
                 FILE_SHARE_WRITE, &child_sa, CREATE_ALWAYS, 
                 FILE_ATTRIBUTE_NORMAL, NULL);
         if (INVALID_HANDLE_VALUE == context.hStdOutput) { 
@@ -1182,11 +1043,12 @@
         }
 
         context.hStdError = context.hStdOutput;
-        free (tmp_name);
 
         /* Input redirection */
-        context.hStdInput = open_input (options->data_dir, get_target (), 
-                                        &child_sa);
+        context.hStdInput =
+            CreateFile (tmp_name, GENERIC_READ, FILE_SHARE_READ, &child_sa, 
+                        OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
+
         if (INVALID_HANDLE_VALUE == context.hStdInput) { 
             CloseHandle (context.hStdOutput);
             result->status = ST_SYSTEM_ERROR;

Modified: incubator/stdcxx/trunk/util/runall.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/runall.cpp?view=diff&rev=562224&r1=562223&r2=562224
==============================================================================
--- incubator/stdcxx/trunk/util/runall.cpp (original)
+++ incubator/stdcxx/trunk/util/runall.cpp Thu Aug  2 12:04:26 2007
@@ -434,6 +434,7 @@
     memcpy (&options, target_template, sizeof options);
     memset (&results, 0, sizeof results);
 
+    /* create the argv array for this target */
     options.argv = merge_argv (target, options.argv);
 
     assert (0 != options.argv);
@@ -441,6 +442,10 @@
 
     target_name = rw_basename (options.argv [0]);
 
+    /* create the names of files to redirect stdin and stdout */
+    options.infname  = input_name (options.data_dir, target_name);
+    options.outfname = output_name (options.argv [0]);
+
     print_target (&options);
 
     if (check_target_ok (options.argv [0], &results)) {
@@ -452,7 +457,7 @@
     print_status (&results);
 
     if (summary) {
-        /* increment summary the counters */
+        /* increment summary counters */
         if (0 == results.signaled && results.exit)
             ++summary->exit;
 
@@ -460,12 +465,19 @@
         summary->c_warn   += results.c_warn;
         summary->l_warn   += results.l_warn;
         summary->t_warn   += results.t_warn;
-        summary->assert   += results.assert;
-        summary->failed   += results.failed;
+
+        if ((unsigned)-1 != results.assert) {
+            /* increment assertion counters only when they're valid */
+            summary->assert += results.assert;
+            summary->failed += results.failed;
+        }
     }
 
+    /* free data dynamically allocated for this target alone */
     free (options.argv [0]);
     free (options.argv);
+    free ((char*)options.infname);
+    free ((char*)options.outfname);
 }
 
 
@@ -529,7 +541,7 @@
             run_target (&summary, argv [i], &target_template);
         }
 
-        print_footer (&summary);
+        print_footer (argc, &summary);
 
         if (target_template.argv [0])
             free (target_template.argv [0]);

Modified: incubator/stdcxx/trunk/util/target.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/target.h?view=diff&rev=562224&r1=562223&r2=562224
==============================================================================
--- incubator/stdcxx/trunk/util/target.h (original)
+++ incubator/stdcxx/trunk/util/target.h Thu Aug  2 12:04:26 2007
@@ -78,6 +78,8 @@
     const char* data_dir; /**< Root dir for reference input/output files. */
     const char* c_warn; /**< Warning flag string when compiling. */
     const char* l_warn; /**< Warning flag string when linking. */
+    const char* infname; /**< Input file to redirect stdin from. */
+    const char* outfname; /**< Output file to redirect stdout to. */
     int compat; /**< Test suite compatability mode switch. */
     int verbose; /**< Verbose mode. */
     rw_rlimit* core;

Modified: incubator/stdcxx/trunk/util/util.cpp
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/util.cpp?view=diff&rev=562224&r1=562223&r2=562224
==============================================================================
--- incubator/stdcxx/trunk/util/util.cpp (original)
+++ incubator/stdcxx/trunk/util/util.cpp Thu Aug  2 12:04:26 2007
@@ -30,6 +30,8 @@
 #include <stdlib.h> /* for exit, malloc */
 #include <stdarg.h> /* for va_* */
 #include <string.h> /* for strerror */
+
+#include <sys/stat.h> /* for stat() */
 #include <sys/types.h> /* for size_t */
 
 #include "cmdopt.h" /* for exe_name, target_name */
@@ -149,6 +151,61 @@
 
     return ref_name;
 }
+
+
+/**
+   Composes the name of an input file, based on target
+
+   Takes a data directory and an executable name, and tries to open an input 
+   file based on these variables.  If a file is found in neither of two 
+   locattions derived from these variables, this method tries to fall back on 
+   /dev/null.
+
+   Source file locations:
+     - [data_dir]/manual/in/[target].in
+     - [data_dir]/tutorial/in/[target].in
+     - /dev/null
+
+   @param data_dir the path of the reference data directory
+   @param target the name of executable being run
+   @returns the name of the file
+*/
+char*
+input_name (const char* data_dir, const char* target)
+{
+    char* fname = 0;
+    int stat_result = 0;
+    struct stat sb;
+
+    assert (0 != target);
+
+    if (data_dir && *data_dir) {
+
+        /* Try data_dir/manual/in/target.in */
+        fname       = reference_name (data_dir, "manual", "in");
+        stat_result = stat (fname, &sb);
+    
+        if (0 == stat_result)
+            return fname;
+
+        free (fname);
+
+        /* Try data_dir/tutorial/in/target.in */
+        fname       = reference_name (data_dir, "tutorial", "in");
+        stat_result = stat (fname, &sb);
+
+        if (0 == stat_result)
+            return fname;
+
+        free (fname);
+    }
+
+    /* If we didn't find a source file, use /dev/null */
+    fname = (char*)RW_MALLOC (sizeof "/dev/null");
+    strcpy (fname, "/dev/null");
+    return fname;
+}
+
 
 char*
 output_name (const char* target)

Modified: incubator/stdcxx/trunk/util/util.h
URL: http://svn.apache.org/viewvc/incubator/stdcxx/trunk/util/util.h?view=diff&rev=562224&r1=562223&r2=562224
==============================================================================
--- incubator/stdcxx/trunk/util/util.h (original)
+++ incubator/stdcxx/trunk/util/util.h Thu Aug  2 12:04:26 2007
@@ -89,6 +89,26 @@
                       const char* mode);
 
 /**
+   Composes the name of an input file, based on exec_name
+
+   Takes a data directory and an executable name, and tries to open an input 
+   file based on these variables.  If a file is found in neither of two 
+   locattions derived from these variables, this method tries to fall back on 
+   /dev/null.
+
+   Source file locations:
+     - [data_dir]/manual/in/[exec_name].in
+     - [data_dir]/tutorial/in/[exec_name].in
+     - /dev/null
+
+   @param data_dir the path of the reference data directory
+   @param exec_name the name of executable being run
+   @returns the name of the file
+*/
+char* input_name (const char* data_dir, const char* target);
+
+
+/**
    Generates the name of the output file for the executable target.
 
    This function allocates memory which is to be freed by the caller.
@@ -97,4 +117,5 @@
    @return translation of 'target.out'
 */
 char* output_name (const char* target);
+
 #endif   /* RW_UTIL_H */



Mime
View raw message