This is the mail archive of the libc-alpha@sourceware.org mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCHv2 4/6] Refactor tst-strtod-round.c


This file is partially generated.  To make updates a little
simpler, I have moved the generated code into a partially
contained header to simplify regeneration.

gen-tst-strtod-round.c now takes a single, mandatory argument.
The argument is a file specifying the data to convert into
a test data structure.  In addition, the output file is
the input file name with .h appended with a few extra
lines to simplify usage.

NOTE: reviewers, I've manually removed the changes to
move the "test" structure into the new file.  Please
run the gen-tst-strtod-round.h as suggested in the
newly added comment, and replace the large struct
with:

/* Include the generated test data.  */
#include "tst-strtod-round-data.h"

	* stdlib/gen-tst-strtod-round.c (main):
	  Change usage to more closely match the generated
	  output.
	* stdlib/tst-strtod-round.c (tests): Move into
	* stdlib/tst-strtod-round-data.h: New file.
---
 stdlib/gen-tst-strtod-round.c                      |    53 +-
 ...{tst-strtod-round.c => tst-strtod-round-data.h} |   230 +-
 stdlib/tst-strtod-round.c                          | 12338 +------------------
 3 files changed, 53 insertions(+), 12568 deletions(-)
 copy stdlib/{tst-strtod-round.c => tst-strtod-round-data.h} (98%)

diff --git a/stdlib/gen-tst-strtod-round.c b/stdlib/gen-tst-strtod-round.c
index 3ef4506..5410507 100644
--- a/stdlib/gen-tst-strtod-round.c
+++ b/stdlib/gen-tst-strtod-round.c
@@ -17,11 +17,25 @@
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+/* Compile this program as:
+
+   gcc -std=gnu11 -O2 -Wall -Wextra gen-tst-strtod-round.c -lmpfr
+     -o gen-tst-strtod-round
+
+   (use of current MPFR version recommended) and run it as:
+
+   gen-tst-strtod-round tst-strtod-round-data
+
+   The output file will be generated as tst-strtod-round-data.h
+*/
+
+
 #define _GNU_SOURCE
 #include <assert.h>
 #include <stdbool.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <string.h>
 #include <mpfr.h>
 
 /* Work around incorrect ternary value from mpfr_strtofr
@@ -130,12 +144,43 @@ round_for_all (const char *s)
 }
 
 int
-main (void)
+main (int argc, char **argv)
 {
   char *p = NULL;
   size_t len;
   ssize_t nbytes;
-  while ((nbytes = getline (&p, &len, stdin)) != -1)
+  FILE *fin;
+  char *fout_name;
+  char *fin_name = argv[1];
+
+  if (argc < 2)
+    {
+      fprintf (stderr, "Usage: %s [input]\n", basename (argv[0]));
+      return EXIT_FAILURE;
+    }
+
+  fin = fopen (fin_name, "r");
+  if (fin == NULL)
+    {
+      perror ("Could not open input for reading");
+      return EXIT_FAILURE;
+    }
+
+  /* Append .h to the name.  */
+  fout_name = malloc (strlen (fin_name) + 3);
+  strcpy (fout_name, fin_name);
+  strcat (fout_name, ".h");
+
+  if (freopen (fout_name, "w", stdout) == NULL)
+    {
+      perror ("Could not open output for writing");
+      return EXIT_FAILURE;
+    }
+
+  printf ("/* This file was generated by %s from %s.  */\n",
+	  __FILE__, fin_name);
+  puts ("static const struct test tests[] = {");
+  while ((nbytes = getline (&p, &len, fin)) != -1)
     {
       if (p[nbytes - 1] == '\n')
 	p[nbytes - 1] = 0;
@@ -143,5 +188,7 @@ main (void)
       free (p);
       p = NULL;
     }
-  return 0;
+  puts ("};");
+
+  return EXIT_SUCCESS;
 }
-- 
2.4.11


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]