OSDN Git Service

* runtime/string.c (find_option): Change 3rd argument to
[pf3gnuchains/gcc-fork.git] / libgfortran / io / format.c
index 0be913c..e714e3b 100644 (file)
@@ -1,4 +1,5 @@
-/* Copyright (C) 2002, 2003, 2004 Free Software Foundation, Inc.
+/* Copyright (C) 2002, 2003, 2004, 2005
+   Free Software Foundation, Inc.
    Contributed by Andy Vaught
 
 This file is part of the GNU Fortran 95 runtime library (libgfortran).
@@ -8,6 +9,15 @@ it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2, or (at your option)
 any later version.
 
+In addition to the permissions in the GNU General Public License, the
+Free Software Foundation gives you unlimited permission to link the
+compiled version of this file into combinations with other programs,
+and to distribute those combinations without any restriction coming
+from the use of this file.  (The General Public License restrictions
+do apply in other respects; for example, they cover modification of
+the file, and distribution when not linked into a combine
+executable.)
+
 Libgfortran is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -15,8 +25,8 @@ GNU General Public License for more details.
 
 You should have received a copy of the GNU General Public License
 along with Libgfortran; see the file COPYING.  If not, write to
-the Free Software Foundation, 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA.  */
+the Free Software Foundation, 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA.  */
 
 
 /* format.c-- parse a FORMAT string into a binary format suitable for
@@ -45,11 +55,13 @@ static const char *error;
 static format_token saved_token;
 static int value, format_string_len, reversion_ok;
 
-static fnode *saved_format, colon_node = { FMT_COLON };
+static fnode *saved_format;
+static fnode colon_node = { FMT_COLON, 0, NULL, NULL, {{ 0, 0, 0 }}, 0,
+                           NULL };
 
 /* Error messages */
 
-static char posint_required[] = "Positive width required in format",
+static const char posint_required[] = "Positive width required in format",
   period_required[] = "Period required in format",
   nonneg_required[] = "Nonnegative width required in format",
   unexpected_element[] = "Unexpected element in format",
@@ -146,7 +158,6 @@ free_fnode (fnode * f)
 void
 free_fnodes (void)
 {
-
   if (avail - array >= FARRAY_SIZE)
     free_fnode (&array[0]);
 
@@ -164,7 +175,8 @@ format_lex (void)
 {
   format_token token;
   int negative_flag;
-  char c, delim;
+  int c;
+  char delim;
 
   if (saved_token != FMT_NONE)
     {
@@ -440,10 +452,10 @@ parse_format_list (void)
 
   head = tail = NULL;
 
-/* Get the next format item */
-
-format_item:
+  /* Get the next format item */
+ format_item:
   t = format_lex ();
+ format_item_1:
   switch (t)
     {
     case FMT_POSINT:
@@ -500,6 +512,7 @@ format_item:
     p_descriptor:
       get_fnode (&head, &tail, FMT_P);
       tail->u.k = value;
+      tail->repeat = 1;
 
       t = format_lex ();
       if (t == FMT_F || t == FMT_EN || t == FMT_ES || t == FMT_D
@@ -542,7 +555,7 @@ format_item:
       tail->u.string.p = string;
       tail->u.string.length = value;
       tail->repeat = 1;
-      goto between_desc;
+      goto optional_comma;
 
     case FMT_S:
     case FMT_SS:
@@ -550,10 +563,12 @@ format_item:
     case FMT_BN:
     case FMT_BZ:
       get_fnode (&head, &tail, t);
+      tail->repeat = 1;
       goto between_desc;
 
     case FMT_COLON:
       get_fnode (&head, &tail, FMT_COLON);
+      tail->repeat = 1;
       goto optional_comma;
 
     case FMT_SLASH:
@@ -564,6 +579,8 @@ format_item:
 
     case FMT_DOLLAR:
       get_fnode (&head, &tail, FMT_DOLLAR);
+      tail->repeat = 1;
+      notify_std (GFC_STD_GNU, "Extension: $ descriptor");
       goto between_desc;
 
     case FMT_T:
@@ -628,10 +645,9 @@ format_item:
       goto finished;
     }
 
-/* In this state, t must currently be a data descriptor.  Deal with
- * things that can/must follow the descriptor */
-
-data_desc:
+  /* In this state, t must currently be a data descriptor.  Deal with
+     things that can/must follow the descriptor */
+ data_desc:
   switch (t)
     {
     case FMT_P:
@@ -723,8 +739,7 @@ data_desc:
 
       tail->u.real.e = -1;
 
-/* Look for optional exponent */
-
+      /* Look for optional exponent */
       t = format_lex ();
       if (t != FMT_E)
        saved_token = t;
@@ -819,8 +834,8 @@ data_desc:
       goto finished;
     }
 
-/* Between a descriptor and what comes next */
-between_desc:
+  /* Between a descriptor and what comes next */
+ between_desc:
   t = format_lex ();
   switch (t)
     {
@@ -844,14 +859,13 @@ between_desc:
       goto finished;
 
     default:
-      error = "Missing comma in format";
-      goto finished;
+      /* Assume a missing comma, this is a GNU extension */
+      goto format_item_1;
     }
 
-/* Optional comma is a weird between state where we've just finished
- * reading a colon, slash or P descriptor. */
-
-optional_comma:
+  /* Optional comma is a weird between state where we've just finished
+     reading a colon, slash or P descriptor. */
+ optional_comma:
   t = format_lex ();
   switch (t)
     {
@@ -868,7 +882,7 @@ optional_comma:
 
   goto format_item;
 
-finished:
+ finished:
   return head;
 }
 
@@ -932,20 +946,19 @@ format_error (fnode * f, const char *message)
 void
 parse_format (void)
 {
-
   format_string = ioparm.format;
   format_string_len = ioparm.format_len;
 
   saved_token = FMT_NONE;
   error = NULL;
 
-/* Initialize variables used during traversal of the tree */
+  /* Initialize variables used during traversal of the tree */
 
   reversion_ok = 0;
   g.reversion_flag = 0;
   saved_format = NULL;
 
-/* Allocate the first format node as the root of the tree */
+  /* Allocate the first format node as the root of the tree */
 
   avail = array;
 
@@ -1079,8 +1092,7 @@ next_format (void)
     }
 
   /* If this is a data edit descriptor, then reversion has become OK. */
-
-done:
+ done:
   t = f->format;
 
   if (!reversion_ok &&
@@ -1102,7 +1114,6 @@ done:
 void
 unget_format (fnode * f)
 {
-
   saved_format = f;
 }
 
@@ -1245,7 +1256,6 @@ dump_format0 (fnode * f)
 static void
 dump_format1 (fnode * f)
 {
-
   for (; f; f = f->next)
     dump_format1 (f);
 }
@@ -1255,7 +1265,6 @@ dump_format1 (fnode * f)
 void
 dump_format (void)
 {
-
   st_printf ("format = ");
   dump_format0 (&array[0]);
   st_printf ("\n");