]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
re PR libfortran/25039 ([4.1 only] comma short-circuit field width)
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 9 Dec 2005 02:53:41 +0000 (02:53 +0000)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Fri, 9 Dec 2005 02:53:41 +0000 (02:53 +0000)
2005-12-08  Jerry DeLisle  <jvdelisle@gcc.gnu.org>

PR libgfortran/25039
* io/io.h: Create a new flag sf_read_comma to control comma
separators in numeric reads.
* io/transfer.c (formatted_transfer_scalar): Initialize the flag.
(read_sf): Check for commas coming in and if the flag is set,
shortcut the read.
* io/read.c (read_a) (read_x): Clear the flag for character reads and
reset it after the reads.

From-SVN: r108271

libgfortran/ChangeLog
libgfortran/io/io.h
libgfortran/io/read.c
libgfortran/io/transfer.c

index 0fee7984bd4dc2977b6f1f8a995c2d9ca595e0c8..1810d224bfa4e6c6a9431cc5b87cc89aeb72bf28 100644 (file)
@@ -1,3 +1,14 @@
+2005-12-08  Jerry DeLisle  <jvdelisle@gcc.gnu.org>
+
+       PR libgfortran/25039
+       * io/io.h: Create a new flag sf_read_comma to control comma
+       separators in numeric reads.
+       * io/transfer.c (formatted_transfer_scalar): Initialize the flag.
+       (read_sf): Check for commas coming in and if the flag is set,
+       shortcut the read.
+       * io/read.c (read_a) (read_x): Clear the flag for character reads and
+       reset it after the reads.
+
 2005-12-04  Francois-Xavier Coudert  <coudert@clipper.ens.fr>
 
        * io/format.c: Removing unused code.
index 9caf59fbd3e6344a67bdf0d523facadeaf2ca426..e7b0ac18d1e2e8d230a728b0d52b8bb6aa5243ce 100644 (file)
@@ -394,7 +394,11 @@ typedef struct st_parameter_dt
             to flag read errors and return, so that an attempt can be
             made to read a new object name.  */
          unsigned nml_read_error : 1;
-         /* 20 unused bits.  */
+         /* A sequential formatted read specific flag used to signal that a
+            character string is being read so don't use commas to shorten a
+            formatted field width.  */
+         unsigned sf_read_comma : 1;
+         /* 19 unused bits.  */
 
          char last_char;
          char nml_delim;
index 5f88a398f05d248b130aca4046e497863faee59b..e1e61ee30da5d3ab6a4c596fee44638c7545e701 100644 (file)
@@ -244,7 +244,9 @@ read_a (st_parameter_dt *dtp, const fnode *f, char *p, int length)
   if (w == -1) /* '(A)' edit descriptor  */
     w = length;
 
+  dtp->u.p.sf_read_comma = 0;
   source = read_block (dtp, &w);
+  dtp->u.p.sf_read_comma = 1;
   if (source == NULL)
     return;
   if (w > length)
@@ -843,6 +845,9 @@ read_x (st_parameter_dt *dtp, int n)
       && dtp->u.p.current_unit->bytes_left < n)
     n = dtp->u.p.current_unit->bytes_left;
 
+  dtp->u.p.sf_read_comma = 0;
   if (n > 0)
     read_block (dtp, &n);
+  dtp->u.p.sf_read_comma = 1;
+
 }
index 84d3532deac6f21e1a8d1d611716056639e11988..b2d26ac7be888e7eb92d304f2f2d965fb82de4bb 100644 (file)
@@ -210,6 +210,16 @@ read_sf (st_parameter_dt *dtp, int *length)
          dtp->u.p.sf_seen_eor = (crlf ? 2 : 1);
          break;
        }
+      /*  Short circuit the read if a comma is found during numeric input.
+         The flag is set to zero during character reads so that commas in
+         strings are not ignored  */
+      if (*q == ',')
+       if (dtp->u.p.sf_read_comma == 1)
+         {
+           notify_std (GFC_STD_GNU, "Comma in formatted numeric read.");
+           *length = n;
+           break;
+         }
 
       n++;
       *p++ = *q;
@@ -527,6 +537,11 @@ formatted_transfer_scalar (st_parameter_dt *dtp, bt type, void *p, int len,
   if (dtp->u.p.eor_condition)
     return;
 
+  /* Set this flag so that commas in reads cause the read to complete before
+     the entire field has been read.  The next read field will start right after
+     the comma in the stream.  (Set to 0 for character reads).  */
+  dtp->u.p.sf_read_comma = 1;
+
   dtp->u.p.line_buffer = scratch;
   for (;;)
     {