From patchwork Tue May 17 22:52:50 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Paul E. Murphy" X-Patchwork-Id: 12329 X-Patchwork-Delegate: joseph@codesourcery.com Received: (qmail 57733 invoked by alias); 17 May 2016 22:53:13 -0000 Mailing-List: contact libc-alpha-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: libc-alpha-owner@sourceware.org Delivered-To: mailing list libc-alpha@sourceware.org Received: (qmail 57607 invoked by uid 89); 17 May 2016 22:53:12 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-2.2 required=5.0 tests=AWL, BAYES_00, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: e19.ny.us.ibm.com X-IBM-Helo: d01dlp02.pok.ibm.com X-IBM-MailFrom: murphyp@linux.vnet.ibm.com X-IBM-RcptTo: libc-alpha@sourceware.org From: "Paul E. Murphy" To: libc-alpha@sourceware.org Subject: [PATCHv2 4/6] Refactor tst-strtod-round.c Date: Tue, 17 May 2016 17:52:50 -0500 Message-Id: In-Reply-To: References: In-Reply-To: References: X-TM-AS-GCONF: 00 X-Content-Scanned: Fidelis XPS MAILER x-cbid: 16051722-0057-0000-0000-000004583525 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused 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 . */ +/* 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 #include #include #include +#include #include /* 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; }