OSDN Git Service

* intrinsic.texi (IAND): Clarify argument specifications.
[pf3gnuchains/gcc-fork.git] / libgfortran / io / list_read.c
1 /* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2    Contributed by Andy Vaught
3    Namelist input contributed by Paul Thomas
4
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
6
7 Libgfortran is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
11
12 In addition to the permissions in the GNU General Public License, the
13 Free Software Foundation gives you unlimited permission to link the
14 compiled version of this file into combinations with other programs,
15 and to distribute those combinations without any restriction coming
16 from the use of this file.  (The General Public License restrictions
17 do apply in other respects; for example, they cover modification of
18 the file, and distribution when not linked into a combine
19 executable.)
20
21 Libgfortran is distributed in the hope that it will be useful,
22 but WITHOUT ANY WARRANTY; without even the implied warranty of
23 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24 GNU General Public License for more details.
25
26 You should have received a copy of the GNU General Public License
27 along with Libgfortran; see the file COPYING.  If not, write to
28 the Free Software Foundation, 51 Franklin Street, Fifth Floor,
29 Boston, MA 02110-1301, USA.  */
30
31
32 #include "config.h"
33 #include <string.h>
34 #include <ctype.h>
35 #include "libgfortran.h"
36 #include "io.h"
37
38
39 /* List directed input.  Several parsing subroutines are practically
40    reimplemented from formatted input, the reason being that there are
41    all kinds of small differences between formatted and list directed
42    parsing.  */
43
44
45 /* Subroutines for reading characters from the input.  Because a
46    repeat count is ambiguous with an integer, we have to read the
47    whole digit string before seeing if there is a '*' which signals
48    the repeat count.  Since we can have a lot of potential leading
49    zeros, we have to be able to back up by arbitrary amount.  Because
50    the input might not be seekable, we have to buffer the data
51    ourselves.  */
52
53 #define CASE_DIGITS   case '0': case '1': case '2': case '3': case '4': \
54                       case '5': case '6': case '7': case '8': case '9'
55
56 #define CASE_SEPARATORS  case ' ': case ',': case '/': case '\n': case '\t': \
57                          case '\r'
58
59 /* This macro assumes that we're operating on a variable.  */
60
61 #define is_separator(c) (c == '/' ||  c == ',' || c == '\n' || c == ' ' \
62                          || c == '\t' || c == '\r')
63
64 /* Maximum repeat count.  Less than ten times the maximum signed int32.  */
65
66 #define MAX_REPEAT 200000000
67
68
69 /* Save a character to a string buffer, enlarging it as necessary.  */
70
71 static void
72 push_char (st_parameter_dt *dtp, char c)
73 {
74   char *new;
75
76   if (dtp->u.p.saved_string == NULL)
77     {
78       if (dtp->u.p.scratch == NULL)
79         dtp->u.p.scratch = get_mem (SCRATCH_SIZE);
80       dtp->u.p.saved_string = dtp->u.p.scratch;
81       memset (dtp->u.p.saved_string, 0, SCRATCH_SIZE);
82       dtp->u.p.saved_length = SCRATCH_SIZE;
83       dtp->u.p.saved_used = 0;
84     }
85
86   if (dtp->u.p.saved_used >= dtp->u.p.saved_length)
87     {
88       dtp->u.p.saved_length = 2 * dtp->u.p.saved_length;
89       new = get_mem (2 * dtp->u.p.saved_length);
90
91       memset (new, 0, 2 * dtp->u.p.saved_length);
92
93       memcpy (new, dtp->u.p.saved_string, dtp->u.p.saved_used);
94       if (dtp->u.p.saved_string != dtp->u.p.scratch)
95         free_mem (dtp->u.p.saved_string);
96
97       dtp->u.p.saved_string = new;
98     }
99
100   dtp->u.p.saved_string[dtp->u.p.saved_used++] = c;
101 }
102
103
104 /* Free the input buffer if necessary.  */
105
106 static void
107 free_saved (st_parameter_dt *dtp)
108 {
109   if (dtp->u.p.saved_string == NULL)
110     return;
111
112   if (dtp->u.p.saved_string != dtp->u.p.scratch)
113     free_mem (dtp->u.p.saved_string);
114
115   dtp->u.p.saved_string = NULL;
116   dtp->u.p.saved_used = 0;
117 }
118
119
120 /* Free the line buffer if necessary.  */
121
122 static void
123 free_line (st_parameter_dt *dtp)
124 {
125   if (dtp->u.p.line_buffer == NULL)
126     return;
127
128   free_mem (dtp->u.p.line_buffer);
129   dtp->u.p.line_buffer = NULL;
130 }
131
132
133 static char
134 next_char (st_parameter_dt *dtp)
135 {
136   int length;
137   gfc_offset record;
138   char c, *p;
139
140   if (dtp->u.p.last_char != '\0')
141     {
142       dtp->u.p.at_eol = 0;
143       c = dtp->u.p.last_char;
144       dtp->u.p.last_char = '\0';
145       goto done;
146     }
147
148   /* Read from line_buffer if enabled.  */
149
150   if (dtp->u.p.line_buffer_enabled)
151     {
152       dtp->u.p.at_eol = 0;
153
154       c = dtp->u.p.line_buffer[dtp->u.p.item_count];
155       if (c != '\0' && dtp->u.p.item_count < 64)
156         {
157           dtp->u.p.line_buffer[dtp->u.p.item_count] = '\0';
158           dtp->u.p.item_count++;
159           goto done;
160         }
161
162         dtp->u.p.item_count = 0;
163         dtp->u.p.line_buffer_enabled = 0;
164     }    
165
166   /* Handle the end-of-record and end-of-file conditions for
167      internal array unit.  */
168   if (is_array_io(dtp))
169     {
170       if (dtp->u.p.at_eof)
171         longjmp (*dtp->u.p.eof_jump, 1);
172
173       /* Check for "end-of-record" condition.  */
174       if (dtp->u.p.current_unit->bytes_left == 0)
175         {
176           c = '\n';
177           record = next_array_record (dtp, dtp->u.p.current_unit->ls);
178
179           /* Check for "end-of-file" condition.  */      
180           if (record == 0)
181             {
182               dtp->u.p.at_eof = 1;
183               goto done;
184             }
185
186           record *= dtp->u.p.current_unit->recl;
187           if (sseek (dtp->u.p.current_unit->s, record) == FAILURE)
188             longjmp (*dtp->u.p.eof_jump, 1);
189
190           dtp->u.p.current_unit->bytes_left = dtp->u.p.current_unit->recl;
191           goto done;
192         }
193     }
194
195   /* Get the next character and handle end-of-record conditions.  */
196
197   length = 1;
198
199   p = salloc_r (dtp->u.p.current_unit->s, &length);
200   
201   if (is_stream_io (dtp))
202     dtp->u.p.current_unit->strm_pos++;
203
204   if (is_internal_unit(dtp))
205     {
206       if (is_array_io(dtp))
207         {
208           /* End of record is handled in the next pass through, above.  The
209              check for NULL here is cautionary.  */
210           if (p == NULL)
211             {
212               generate_error (&dtp->common, ERROR_INTERNAL_UNIT, NULL);
213               return '\0';
214             }
215
216           dtp->u.p.current_unit->bytes_left--;
217           c = *p;
218         }
219       else
220         {
221           if (p == NULL)
222             longjmp (*dtp->u.p.eof_jump, 1);
223           if (length == 0)
224             c = '\n';
225           else
226             c = *p;
227         }
228     }
229   else
230     {
231       if (p == NULL)
232         {
233           generate_error (&dtp->common, ERROR_OS, NULL);
234           return '\0';
235         }
236       if (length == 0)
237         longjmp (*dtp->u.p.eof_jump, 1);
238       c = *p;
239     }
240 done:
241   dtp->u.p.at_eol = (c == '\n' || c == '\r');
242   return c;
243 }
244
245
246 /* Push a character back onto the input.  */
247
248 static void
249 unget_char (st_parameter_dt *dtp, char c)
250 {
251   dtp->u.p.last_char = c;
252 }
253
254
255 /* Skip over spaces in the input.  Returns the nonspace character that
256    terminated the eating and also places it back on the input.  */
257
258 static char
259 eat_spaces (st_parameter_dt *dtp)
260 {
261   char c;
262
263   do
264     {
265       c = next_char (dtp);
266     }
267   while (c == ' ' || c == '\t');
268
269   unget_char (dtp, c);
270   return c;
271 }
272
273
274 /* Skip over a separator.  Technically, we don't always eat the whole
275    separator.  This is because if we've processed the last input item,
276    then a separator is unnecessary.  Plus the fact that operating
277    systems usually deliver console input on a line basis.
278
279    The upshot is that if we see a newline as part of reading a
280    separator, we stop reading.  If there are more input items, we
281    continue reading the separator with finish_separator() which takes
282    care of the fact that we may or may not have seen a comma as part
283    of the separator.  */
284
285 static void
286 eat_separator (st_parameter_dt *dtp)
287 {
288   char c, n;
289
290   eat_spaces (dtp);
291   dtp->u.p.comma_flag = 0;
292
293   c = next_char (dtp);
294   switch (c)
295     {
296     case ',':
297       dtp->u.p.comma_flag = 1;
298       eat_spaces (dtp);
299       break;
300
301     case '/':
302       dtp->u.p.input_complete = 1;
303       break;
304
305     case '\r':
306       n = next_char(dtp);
307       if (n == '\n')
308         dtp->u.p.at_eol = 1;
309       else
310         unget_char (dtp, n);
311       break;
312
313     case '\n':
314       dtp->u.p.at_eol = 1;
315       break;
316
317     case '!':
318       if (dtp->u.p.namelist_mode)
319         {                       /* Eat a namelist comment.  */
320           do
321             c = next_char (dtp);
322           while (c != '\n');
323
324           break;
325         }
326
327       /* Fall Through...  */
328
329     default:
330       unget_char (dtp, c);
331       break;
332     }
333 }
334
335
336 /* Finish processing a separator that was interrupted by a newline.
337    If we're here, then another data item is present, so we finish what
338    we started on the previous line.  */
339
340 static void
341 finish_separator (st_parameter_dt *dtp)
342 {
343   char c;
344
345  restart:
346   eat_spaces (dtp);
347
348   c = next_char (dtp);
349   switch (c)
350     {
351     case ',':
352       if (dtp->u.p.comma_flag)
353         unget_char (dtp, c);
354       else
355         {
356           c = eat_spaces (dtp);
357           if (c == '\n' || c == '\r')
358             goto restart;
359         }
360
361       break;
362
363     case '/':
364       dtp->u.p.input_complete = 1;
365       if (!dtp->u.p.namelist_mode) next_record (dtp, 0);
366       break;
367
368     case '\n':
369     case '\r':
370       goto restart;
371
372     case '!':
373       if (dtp->u.p.namelist_mode)
374         {
375           do
376             c = next_char (dtp);
377           while (c != '\n');
378
379           goto restart;
380         }
381
382     default:
383       unget_char (dtp, c);
384       break;
385     }
386 }
387
388
389 /* This function reads characters through to the end of the current line and
390    just ignores them.  */
391
392 static void
393 eat_line (st_parameter_dt *dtp)
394 {
395   char c;
396   if (!is_internal_unit (dtp))
397     do
398       c = next_char (dtp);
399     while (c != '\n');
400 }
401
402
403 /* This function is needed to catch bad conversions so that namelist can
404    attempt to see if dtp->u.p.saved_string contains a new object name rather
405    than a bad value.  */
406
407 static int
408 nml_bad_return (st_parameter_dt *dtp, char c)
409 {
410   if (dtp->u.p.namelist_mode)
411     {
412       dtp->u.p.nml_read_error = 1;
413       unget_char (dtp, c);
414       return 1;
415     }
416   return 0;
417 }
418
419 /* Convert an unsigned string to an integer.  The length value is -1
420    if we are working on a repeat count.  Returns nonzero if we have a
421    range problem.  As a side effect, frees the dtp->u.p.saved_string.  */
422
423 static int
424 convert_integer (st_parameter_dt *dtp, int length, int negative)
425 {
426   char c, *buffer, message[100];
427   int m;
428   GFC_INTEGER_LARGEST v, max, max10;
429
430   buffer = dtp->u.p.saved_string;
431   v = 0;
432
433   max = (length == -1) ? MAX_REPEAT : max_value (length, 1);
434   max10 = max / 10;
435
436   for (;;)
437     {
438       c = *buffer++;
439       if (c == '\0')
440         break;
441       c -= '0';
442
443       if (v > max10)
444         goto overflow;
445       v = 10 * v;
446
447       if (v > max - c)
448         goto overflow;
449       v += c;
450     }
451
452   m = 0;
453
454   if (length != -1)
455     {
456       if (negative)
457         v = -v;
458       set_integer (dtp->u.p.value, v, length);
459     }
460   else
461     {
462       dtp->u.p.repeat_count = v;
463
464       if (dtp->u.p.repeat_count == 0)
465         {
466           st_sprintf (message, "Zero repeat count in item %d of list input",
467                       dtp->u.p.item_count);
468
469           generate_error (&dtp->common, ERROR_READ_VALUE, message);
470           m = 1;
471         }
472     }
473
474   free_saved (dtp);
475   return m;
476
477  overflow:
478   if (length == -1)
479     st_sprintf (message, "Repeat count overflow in item %d of list input",
480                 dtp->u.p.item_count);
481   else
482     st_sprintf (message, "Integer overflow while reading item %d",
483                 dtp->u.p.item_count);
484
485   free_saved (dtp);
486   generate_error (&dtp->common, ERROR_READ_VALUE, message);
487
488   return 1;
489 }
490
491
492 /* Parse a repeat count for logical and complex values which cannot
493    begin with a digit.  Returns nonzero if we are done, zero if we
494    should continue on.  */
495
496 static int
497 parse_repeat (st_parameter_dt *dtp)
498 {
499   char c, message[100];
500   int repeat;
501
502   c = next_char (dtp);
503   switch (c)
504     {
505     CASE_DIGITS:
506       repeat = c - '0';
507       break;
508
509     CASE_SEPARATORS:
510       unget_char (dtp, c);
511       eat_separator (dtp);
512       return 1;
513
514     default:
515       unget_char (dtp, c);
516       return 0;
517     }
518
519   for (;;)
520     {
521       c = next_char (dtp);
522       switch (c)
523         {
524         CASE_DIGITS:
525           repeat = 10 * repeat + c - '0';
526
527           if (repeat > MAX_REPEAT)
528             {
529               st_sprintf (message,
530                           "Repeat count overflow in item %d of list input",
531                           dtp->u.p.item_count);
532
533               generate_error (&dtp->common, ERROR_READ_VALUE, message);
534               return 1;
535             }
536
537           break;
538
539         case '*':
540           if (repeat == 0)
541             {
542               st_sprintf (message,
543                           "Zero repeat count in item %d of list input",
544                           dtp->u.p.item_count);
545
546               generate_error (&dtp->common, ERROR_READ_VALUE, message);
547               return 1;
548             }
549
550           goto done;
551
552         default:
553           goto bad_repeat;
554         }
555     }
556
557  done:
558   dtp->u.p.repeat_count = repeat;
559   return 0;
560
561  bad_repeat:
562
563   eat_line (dtp);
564   free_saved (dtp);
565   st_sprintf (message, "Bad repeat count in item %d of list input",
566               dtp->u.p.item_count);
567   generate_error (&dtp->common, ERROR_READ_VALUE, message);
568   return 1;
569 }
570
571
572 /* To read a logical we have to look ahead in the input stream to make sure
573     there is not an equal sign indicating a variable name.  To do this we use 
574     line_buffer to point to a temporary buffer, pushing characters there for
575     possible later reading. */
576
577 static void
578 l_push_char (st_parameter_dt *dtp, char c)
579 {
580   if (dtp->u.p.line_buffer == NULL)
581     {
582       dtp->u.p.line_buffer = get_mem (SCRATCH_SIZE);
583       memset (dtp->u.p.line_buffer, 0, SCRATCH_SIZE);
584     }
585
586   dtp->u.p.line_buffer[dtp->u.p.item_count++] = c;
587 }
588
589
590 /* Read a logical character on the input.  */
591
592 static void
593 read_logical (st_parameter_dt *dtp, int length)
594 {
595   char c, message[100];
596   int i, v;
597
598   if (parse_repeat (dtp))
599     return;
600
601   c = tolower (next_char (dtp));
602   l_push_char (dtp, c);
603   switch (c)
604     {
605     case 't':
606       v = 1;
607       c = next_char (dtp);
608       l_push_char (dtp, c);
609
610       if (!is_separator(c))
611         goto possible_name;
612
613       unget_char (dtp, c);
614       break;
615     case 'f':
616       v = 0;
617       c = next_char (dtp);
618       l_push_char (dtp, c);
619
620       if (!is_separator(c))
621         goto possible_name;
622
623       unget_char (dtp, c);
624       break;
625     case '.':
626       c = tolower (next_char (dtp));
627       switch (c)
628         {
629           case 't':
630             v = 1;
631             break;
632           case 'f':
633             v = 0;
634             break;
635           default:
636             goto bad_logical;
637         }
638
639       break;
640
641     CASE_SEPARATORS:
642       unget_char (dtp, c);
643       eat_separator (dtp);
644       return;                   /* Null value.  */
645
646     default:
647       goto bad_logical;
648     }
649
650   dtp->u.p.saved_type = BT_LOGICAL;
651   dtp->u.p.saved_length = length;
652
653   /* Eat trailing garbage.  */
654   do
655     {
656       c = next_char (dtp);
657     }
658   while (!is_separator (c));
659
660   unget_char (dtp, c);
661   eat_separator (dtp);
662   dtp->u.p.item_count = 0;
663   dtp->u.p.line_buffer_enabled = 0;
664   set_integer ((int *) dtp->u.p.value, v, length);
665   free_line (dtp);
666
667   return;
668
669  possible_name:
670
671   for(i = 0; i < 63; i++)
672     {
673       c = next_char (dtp);
674       if (is_separator(c))
675         {
676           /* All done if this is not a namelist read.  */
677           if (!dtp->u.p.namelist_mode)
678             goto logical_done;
679
680           unget_char (dtp, c);
681           eat_separator (dtp);
682           c = next_char (dtp);
683           if (c != '=')
684             {
685               unget_char (dtp, c);
686               goto logical_done;
687             }
688         }
689  
690       l_push_char (dtp, c);
691       if (c == '=')
692         {
693           dtp->u.p.nml_read_error = 1;
694           dtp->u.p.line_buffer_enabled = 1;
695           dtp->u.p.item_count = 0;
696           return;
697         }
698       
699     }
700
701  bad_logical:
702
703   free_line (dtp);
704
705   if (nml_bad_return (dtp, c))
706     return;
707
708   eat_line (dtp);
709   free_saved (dtp);
710   st_sprintf (message, "Bad logical value while reading item %d",
711               dtp->u.p.item_count);
712   generate_error (&dtp->common, ERROR_READ_VALUE, message);
713   return;
714
715  logical_done:
716
717   dtp->u.p.item_count = 0;
718   dtp->u.p.line_buffer_enabled = 0;
719   dtp->u.p.saved_type = BT_LOGICAL;
720   dtp->u.p.saved_length = length;
721   set_integer ((int *) dtp->u.p.value, v, length);
722   free_saved (dtp);
723   free_line (dtp);
724 }
725
726
727 /* Reading integers is tricky because we can actually be reading a
728    repeat count.  We have to store the characters in a buffer because
729    we could be reading an integer that is larger than the default int
730    used for repeat counts.  */
731
732 static void
733 read_integer (st_parameter_dt *dtp, int length)
734 {
735   char c, message[100];
736   int negative;
737
738   negative = 0;
739
740   c = next_char (dtp);
741   switch (c)
742     {
743     case '-':
744       negative = 1;
745       /* Fall through...  */
746
747     case '+':
748       c = next_char (dtp);
749       goto get_integer;
750
751     CASE_SEPARATORS:            /* Single null.  */
752       unget_char (dtp, c);
753       eat_separator (dtp);
754       return;
755
756     CASE_DIGITS:
757       push_char (dtp, c);
758       break;
759
760     default:
761       goto bad_integer;
762     }
763
764   /* Take care of what may be a repeat count.  */
765
766   for (;;)
767     {
768       c = next_char (dtp);
769       switch (c)
770         {
771         CASE_DIGITS:
772           push_char (dtp, c);
773           break;
774
775         case '*':
776           push_char (dtp, '\0');
777           goto repeat;
778
779         CASE_SEPARATORS:        /* Not a repeat count.  */
780           goto done;
781
782         default:
783           goto bad_integer;
784         }
785     }
786
787  repeat:
788   if (convert_integer (dtp, -1, 0))
789     return;
790
791   /* Get the real integer.  */
792
793   c = next_char (dtp);
794   switch (c)
795     {
796     CASE_DIGITS:
797       break;
798
799     CASE_SEPARATORS:
800       unget_char (dtp, c);
801       eat_separator (dtp);
802       return;
803
804     case '-':
805       negative = 1;
806       /* Fall through...  */
807
808     case '+':
809       c = next_char (dtp);
810       break;
811     }
812
813  get_integer:
814   if (!isdigit (c))
815     goto bad_integer;
816   push_char (dtp, c);
817
818   for (;;)
819     {
820       c = next_char (dtp);
821       switch (c)
822         {
823         CASE_DIGITS:
824           push_char (dtp, c);
825           break;
826
827         CASE_SEPARATORS:
828           goto done;
829
830         default:
831           goto bad_integer;
832         }
833     }
834
835  bad_integer:
836
837   if (nml_bad_return (dtp, c))
838     return;
839   
840   eat_line (dtp);
841   free_saved (dtp);
842   st_sprintf (message, "Bad integer for item %d in list input",
843               dtp->u.p.item_count);
844   generate_error (&dtp->common, ERROR_READ_VALUE, message);
845
846   return;
847
848  done:
849   unget_char (dtp, c);
850   eat_separator (dtp);
851
852   push_char (dtp, '\0');
853   if (convert_integer (dtp, length, negative))
854     {
855        free_saved (dtp);
856        return;
857     }
858
859   free_saved (dtp);
860   dtp->u.p.saved_type = BT_INTEGER;
861 }
862
863
864 /* Read a character variable.  */
865
866 static void
867 read_character (st_parameter_dt *dtp, int length __attribute__ ((unused)))
868 {
869   char c, quote, message[100];
870
871   quote = ' ';                  /* Space means no quote character.  */
872
873   c = next_char (dtp);
874   switch (c)
875     {
876     CASE_DIGITS:
877       push_char (dtp, c);
878       break;
879
880     CASE_SEPARATORS:
881       unget_char (dtp, c);              /* NULL value.  */
882       eat_separator (dtp);
883       return;
884
885     case '"':
886     case '\'':
887       quote = c;
888       goto get_string;
889
890     default:
891       if (dtp->u.p.namelist_mode)
892         {
893           unget_char (dtp,c);
894           return;
895         }
896       push_char (dtp, c);
897       goto get_string;
898     }
899
900   /* Deal with a possible repeat count.  */
901
902   for (;;)
903     {
904       c = next_char (dtp);
905       switch (c)
906         {
907         CASE_DIGITS:
908           push_char (dtp, c);
909           break;
910
911         CASE_SEPARATORS:
912           unget_char (dtp, c);
913           goto done;            /* String was only digits!  */
914
915         case '*':
916           push_char (dtp, '\0');
917           goto got_repeat;
918
919         default:
920           push_char (dtp, c);
921           goto get_string;      /* Not a repeat count after all.  */
922         }
923     }
924
925  got_repeat:
926   if (convert_integer (dtp, -1, 0))
927     return;
928
929   /* Now get the real string.  */
930
931   c = next_char (dtp);
932   switch (c)
933     {
934     CASE_SEPARATORS:
935       unget_char (dtp, c);              /* Repeated NULL values.  */
936       eat_separator (dtp);
937       return;
938
939     case '"':
940     case '\'':
941       quote = c;
942       break;
943
944     default:
945       push_char (dtp, c);
946       break;
947     }
948
949  get_string:
950   for (;;)
951     {
952       c = next_char (dtp);
953       switch (c)
954         {
955         case '"':
956         case '\'':
957           if (c != quote)
958             {
959               push_char (dtp, c);
960               break;
961             }
962
963           /* See if we have a doubled quote character or the end of
964              the string.  */
965
966           c = next_char (dtp);
967           if (c == quote)
968             {
969               push_char (dtp, quote);
970               break;
971             }
972
973           unget_char (dtp, c);
974           goto done;
975
976         CASE_SEPARATORS:
977           if (quote == ' ')
978             {
979               unget_char (dtp, c);
980               goto done;
981             }
982
983           if (c != '\n' && c != '\r')
984             push_char (dtp, c);
985           break;
986
987         default:
988           push_char (dtp, c);
989           break;
990         }
991     }
992
993   /* At this point, we have to have a separator, or else the string is
994      invalid.  */
995  done:
996   c = next_char (dtp);
997   if (is_separator (c))
998     {
999       unget_char (dtp, c);
1000       eat_separator (dtp);
1001       dtp->u.p.saved_type = BT_CHARACTER;
1002     }
1003   else
1004     {
1005       free_saved (dtp);
1006       st_sprintf (message, "Invalid string input in item %d",
1007                   dtp->u.p.item_count);
1008       generate_error (&dtp->common, ERROR_READ_VALUE, message);
1009     }
1010 }
1011
1012
1013 /* Parse a component of a complex constant or a real number that we
1014    are sure is already there.  This is a straight real number parser.  */
1015
1016 static int
1017 parse_real (st_parameter_dt *dtp, void *buffer, int length)
1018 {
1019   char c, message[100];
1020   int m, seen_dp;
1021
1022   c = next_char (dtp);
1023   if (c == '-' || c == '+')
1024     {
1025       push_char (dtp, c);
1026       c = next_char (dtp);
1027     }
1028
1029   if (!isdigit (c) && c != '.')
1030     goto bad;
1031
1032   push_char (dtp, c);
1033
1034   seen_dp = (c == '.') ? 1 : 0;
1035
1036   for (;;)
1037     {
1038       c = next_char (dtp);
1039       switch (c)
1040         {
1041         CASE_DIGITS:
1042           push_char (dtp, c);
1043           break;
1044
1045         case '.':
1046           if (seen_dp)
1047             goto bad;
1048
1049           seen_dp = 1;
1050           push_char (dtp, c);
1051           break;
1052
1053         case 'e':
1054         case 'E':
1055         case 'd':
1056         case 'D':
1057           push_char (dtp, 'e');
1058           goto exp1;
1059
1060         case '-':
1061         case '+':
1062           push_char (dtp, 'e');
1063           push_char (dtp, c);
1064           c = next_char (dtp);
1065           goto exp2;
1066
1067         CASE_SEPARATORS:
1068           unget_char (dtp, c);
1069           goto done;
1070
1071         default:
1072           goto done;
1073         }
1074     }
1075
1076  exp1:
1077   c = next_char (dtp);
1078   if (c != '-' && c != '+')
1079     push_char (dtp, '+');
1080   else
1081     {
1082       push_char (dtp, c);
1083       c = next_char (dtp);
1084     }
1085
1086  exp2:
1087   if (!isdigit (c))
1088     goto bad;
1089   push_char (dtp, c);
1090
1091   for (;;)
1092     {
1093       c = next_char (dtp);
1094       switch (c)
1095         {
1096         CASE_DIGITS:
1097           push_char (dtp, c);
1098           break;
1099
1100         CASE_SEPARATORS:
1101           unget_char (dtp, c);
1102           goto done;
1103
1104         default:
1105           goto done;
1106         }
1107     }
1108
1109  done:
1110   unget_char (dtp, c);
1111   push_char (dtp, '\0');
1112
1113   m = convert_real (dtp, buffer, dtp->u.p.saved_string, length);
1114   free_saved (dtp);
1115
1116   return m;
1117
1118  bad:
1119
1120   if (nml_bad_return (dtp, c))
1121     return 0;
1122
1123   eat_line (dtp);
1124   free_saved (dtp);
1125   st_sprintf (message, "Bad floating point number for item %d",
1126               dtp->u.p.item_count);
1127   generate_error (&dtp->common, ERROR_READ_VALUE, message);
1128
1129   return 1;
1130 }
1131
1132
1133 /* Reading a complex number is straightforward because we can tell
1134    what it is right away.  */
1135
1136 static void
1137 read_complex (st_parameter_dt *dtp, int kind, size_t size)
1138 {
1139   char message[100];
1140   char c;
1141
1142   if (parse_repeat (dtp))
1143     return;
1144
1145   c = next_char (dtp);
1146   switch (c)
1147     {
1148     case '(':
1149       break;
1150
1151     CASE_SEPARATORS:
1152       unget_char (dtp, c);
1153       eat_separator (dtp);
1154       return;
1155
1156     default:
1157       goto bad_complex;
1158     }
1159
1160   eat_spaces (dtp);
1161   if (parse_real (dtp, dtp->u.p.value, kind))
1162     return;
1163
1164 eol_1:
1165   eat_spaces (dtp);
1166   c = next_char (dtp);
1167   if (c == '\n' || c== '\r')
1168     goto eol_1;
1169   else
1170     unget_char (dtp, c);
1171
1172   if (next_char (dtp) != ',')
1173     goto bad_complex;
1174
1175 eol_2:
1176   eat_spaces (dtp);
1177   c = next_char (dtp);
1178   if (c == '\n' || c== '\r')
1179     goto eol_2;
1180   else
1181     unget_char (dtp, c);
1182
1183   if (parse_real (dtp, dtp->u.p.value + size / 2, kind))
1184     return;
1185
1186   eat_spaces (dtp);
1187   if (next_char (dtp) != ')')
1188     goto bad_complex;
1189
1190   c = next_char (dtp);
1191   if (!is_separator (c))
1192     goto bad_complex;
1193
1194   unget_char (dtp, c);
1195   eat_separator (dtp);
1196
1197   free_saved (dtp);
1198   dtp->u.p.saved_type = BT_COMPLEX;
1199   return;
1200
1201  bad_complex:
1202
1203   if (nml_bad_return (dtp, c))
1204     return;
1205
1206   eat_line (dtp);
1207   free_saved (dtp);
1208   st_sprintf (message, "Bad complex value in item %d of list input",
1209               dtp->u.p.item_count);
1210   generate_error (&dtp->common, ERROR_READ_VALUE, message);
1211 }
1212
1213
1214 /* Parse a real number with a possible repeat count.  */
1215
1216 static void
1217 read_real (st_parameter_dt *dtp, int length)
1218 {
1219   char c, message[100];
1220   int seen_dp;
1221
1222   seen_dp = 0;
1223
1224   c = next_char (dtp);
1225   switch (c)
1226     {
1227     CASE_DIGITS:
1228       push_char (dtp, c);
1229       break;
1230
1231     case '.':
1232       push_char (dtp, c);
1233       seen_dp = 1;
1234       break;
1235
1236     case '+':
1237     case '-':
1238       goto got_sign;
1239
1240     CASE_SEPARATORS:
1241       unget_char (dtp, c);              /* Single null.  */
1242       eat_separator (dtp);
1243       return;
1244
1245     default:
1246       goto bad_real;
1247     }
1248
1249   /* Get the digit string that might be a repeat count.  */
1250
1251   for (;;)
1252     {
1253       c = next_char (dtp);
1254       switch (c)
1255         {
1256         CASE_DIGITS:
1257           push_char (dtp, c);
1258           break;
1259
1260         case '.':
1261           if (seen_dp)
1262             goto bad_real;
1263
1264           seen_dp = 1;
1265           push_char (dtp, c);
1266           goto real_loop;
1267
1268         case 'E':
1269         case 'e':
1270         case 'D':
1271         case 'd':
1272           goto exp1;
1273
1274         case '+':
1275         case '-':
1276           push_char (dtp, 'e');
1277           push_char (dtp, c);
1278           c = next_char (dtp);
1279           goto exp2;
1280
1281         case '*':
1282           push_char (dtp, '\0');
1283           goto got_repeat;
1284
1285         CASE_SEPARATORS:
1286           if (c != '\n' &&  c != ',' && c != '\r')
1287             unget_char (dtp, c);
1288           goto done;
1289
1290         default:
1291           goto bad_real;
1292         }
1293     }
1294
1295  got_repeat:
1296   if (convert_integer (dtp, -1, 0))
1297     return;
1298
1299   /* Now get the number itself.  */
1300
1301   c = next_char (dtp);
1302   if (is_separator (c))
1303     {                           /* Repeated null value.  */
1304       unget_char (dtp, c);
1305       eat_separator (dtp);
1306       return;
1307     }
1308
1309   if (c != '-' && c != '+')
1310     push_char (dtp, '+');
1311   else
1312     {
1313     got_sign:
1314       push_char (dtp, c);
1315       c = next_char (dtp);
1316     }
1317
1318   if (!isdigit (c) && c != '.')
1319     goto bad_real;
1320
1321   if (c == '.')
1322     {
1323       if (seen_dp)
1324         goto bad_real;
1325       else
1326         seen_dp = 1;
1327     }
1328
1329   push_char (dtp, c);
1330
1331  real_loop:
1332   for (;;)
1333     {
1334       c = next_char (dtp);
1335       switch (c)
1336         {
1337         CASE_DIGITS:
1338           push_char (dtp, c);
1339           break;
1340
1341         CASE_SEPARATORS:
1342           goto done;
1343
1344         case '.':
1345           if (seen_dp)
1346             goto bad_real;
1347
1348           seen_dp = 1;
1349           push_char (dtp, c);
1350           break;
1351
1352         case 'E':
1353         case 'e':
1354         case 'D':
1355         case 'd':
1356           goto exp1;
1357
1358         case '+':
1359         case '-':
1360           push_char (dtp, 'e');
1361           push_char (dtp, c);
1362           c = next_char (dtp);
1363           goto exp2;
1364
1365         default:
1366           goto bad_real;
1367         }
1368     }
1369
1370  exp1:
1371   push_char (dtp, 'e');
1372
1373   c = next_char (dtp);
1374   if (c != '+' && c != '-')
1375     push_char (dtp, '+');
1376   else
1377     {
1378       push_char (dtp, c);
1379       c = next_char (dtp);
1380     }
1381
1382  exp2:
1383   if (!isdigit (c))
1384     goto bad_real;
1385   push_char (dtp, c);
1386
1387   for (;;)
1388     {
1389       c = next_char (dtp);
1390
1391       switch (c)
1392         {
1393         CASE_DIGITS:
1394           push_char (dtp, c);
1395           break;
1396
1397         CASE_SEPARATORS:
1398           goto done;
1399
1400         default:
1401           goto bad_real;
1402         }
1403     }
1404
1405  done:
1406   unget_char (dtp, c);
1407   eat_separator (dtp);
1408   push_char (dtp, '\0');
1409   if (convert_real (dtp, dtp->u.p.value, dtp->u.p.saved_string, length))
1410     return;
1411
1412   free_saved (dtp);
1413   dtp->u.p.saved_type = BT_REAL;
1414   return;
1415
1416  bad_real:
1417
1418   if (nml_bad_return (dtp, c))
1419     return;
1420
1421   eat_line (dtp);
1422   free_saved (dtp);
1423   st_sprintf (message, "Bad real number in item %d of list input",
1424               dtp->u.p.item_count);
1425   generate_error (&dtp->common, ERROR_READ_VALUE, message);
1426 }
1427
1428
1429 /* Check the current type against the saved type to make sure they are
1430    compatible.  Returns nonzero if incompatible.  */
1431
1432 static int
1433 check_type (st_parameter_dt *dtp, bt type, int len)
1434 {
1435   char message[100];
1436
1437   if (dtp->u.p.saved_type != BT_NULL && dtp->u.p.saved_type != type)
1438     {
1439       st_sprintf (message, "Read type %s where %s was expected for item %d",
1440                   type_name (dtp->u.p.saved_type), type_name (type),
1441                   dtp->u.p.item_count);
1442
1443       generate_error (&dtp->common, ERROR_READ_VALUE, message);
1444       return 1;
1445     }
1446
1447   if (dtp->u.p.saved_type == BT_NULL || dtp->u.p.saved_type == BT_CHARACTER)
1448     return 0;
1449
1450   if (dtp->u.p.saved_length != len)
1451     {
1452       st_sprintf (message,
1453                   "Read kind %d %s where kind %d is required for item %d",
1454                   dtp->u.p.saved_length, type_name (dtp->u.p.saved_type), len,
1455                   dtp->u.p.item_count);
1456       generate_error (&dtp->common, ERROR_READ_VALUE, message);
1457       return 1;
1458     }
1459
1460   return 0;
1461 }
1462
1463
1464 /* Top level data transfer subroutine for list reads.  Because we have
1465    to deal with repeat counts, the data item is always saved after
1466    reading, usually in the dtp->u.p.value[] array.  If a repeat count is
1467    greater than one, we copy the data item multiple times.  */
1468
1469 static void
1470 list_formatted_read_scalar (st_parameter_dt *dtp, bt type, void *p, int kind,
1471                             size_t size)
1472 {
1473   char c;
1474   int m;
1475   jmp_buf eof_jump;
1476
1477   dtp->u.p.namelist_mode = 0;
1478
1479   dtp->u.p.eof_jump = &eof_jump;
1480   if (setjmp (eof_jump))
1481     {
1482       generate_error (&dtp->common, ERROR_END, NULL);
1483       goto cleanup;
1484     }
1485
1486   if (dtp->u.p.first_item)
1487     {
1488       dtp->u.p.first_item = 0;
1489       dtp->u.p.input_complete = 0;
1490       dtp->u.p.repeat_count = 1;
1491       dtp->u.p.at_eol = 0;
1492
1493       c = eat_spaces (dtp);
1494       if (is_separator (c))
1495         {                       /* Found a null value.  */
1496           eat_separator (dtp);
1497           dtp->u.p.repeat_count = 0;
1498
1499           /* eat_separator sets this flag if the separator was a comma */
1500           if (dtp->u.p.comma_flag)
1501             goto cleanup;
1502
1503           /* eat_separator sets this flag if the separator was a \n or \r */
1504           if (dtp->u.p.at_eol)
1505             finish_separator (dtp);
1506           else
1507             goto cleanup;
1508         }
1509
1510     }
1511   else
1512     {
1513       if (dtp->u.p.input_complete)
1514         goto cleanup;
1515
1516       if (dtp->u.p.repeat_count > 0)
1517         {
1518           if (check_type (dtp, type, kind))
1519             return;
1520           goto set_value;
1521         }
1522
1523       if (dtp->u.p.at_eol)
1524         finish_separator (dtp);
1525       else
1526         {
1527           eat_spaces (dtp);
1528           /* trailing spaces prior to end of line */
1529           if (dtp->u.p.at_eol)
1530             finish_separator (dtp);
1531         }
1532
1533       dtp->u.p.saved_type = BT_NULL;
1534       dtp->u.p.repeat_count = 1;
1535     }
1536
1537   switch (type)
1538     {
1539     case BT_INTEGER:
1540       read_integer (dtp, kind);
1541       break;
1542     case BT_LOGICAL:
1543       read_logical (dtp, kind);
1544       break;
1545     case BT_CHARACTER:
1546       read_character (dtp, kind);
1547       break;
1548     case BT_REAL:
1549       read_real (dtp, kind);
1550       break;
1551     case BT_COMPLEX:
1552       read_complex (dtp, kind, size);
1553       break;
1554     default:
1555       internal_error (&dtp->common, "Bad type for list read");
1556     }
1557
1558   if (dtp->u.p.saved_type != BT_CHARACTER && dtp->u.p.saved_type != BT_NULL)
1559     dtp->u.p.saved_length = size;
1560
1561   if ((dtp->common.flags & IOPARM_LIBRETURN_MASK) != IOPARM_LIBRETURN_OK)
1562     goto cleanup;
1563
1564  set_value:
1565   switch (dtp->u.p.saved_type)
1566     {
1567     case BT_COMPLEX:
1568     case BT_INTEGER:
1569     case BT_REAL:
1570     case BT_LOGICAL:
1571       memcpy (p, dtp->u.p.value, size);
1572       break;
1573
1574     case BT_CHARACTER:
1575       if (dtp->u.p.saved_string)
1576        {
1577           m = ((int) size < dtp->u.p.saved_used)
1578               ? (int) size : dtp->u.p.saved_used;
1579           memcpy (p, dtp->u.p.saved_string, m);
1580        }
1581       else
1582         /* Just delimiters encountered, nothing to copy but SPACE.  */
1583         m = 0;
1584
1585       if (m < (int) size)
1586         memset (((char *) p) + m, ' ', size - m);
1587       break;
1588
1589     case BT_NULL:
1590       break;
1591     }
1592
1593   if (--dtp->u.p.repeat_count <= 0)
1594     free_saved (dtp);
1595
1596 cleanup:
1597   dtp->u.p.eof_jump = NULL;
1598 }
1599
1600
1601 void
1602 list_formatted_read (st_parameter_dt *dtp, bt type, void *p, int kind,
1603                      size_t size, size_t nelems)
1604 {
1605   size_t elem;
1606   char *tmp;
1607
1608   tmp = (char *) p;
1609
1610   /* Big loop over all the elements.  */
1611   for (elem = 0; elem < nelems; elem++)
1612     {
1613       dtp->u.p.item_count++;
1614       list_formatted_read_scalar (dtp, type, tmp + size*elem, kind, size);
1615     }
1616 }
1617
1618
1619 /* Finish a list read.  */
1620
1621 void
1622 finish_list_read (st_parameter_dt *dtp)
1623 {
1624   char c;
1625
1626   free_saved (dtp);
1627
1628   if (dtp->u.p.at_eol)
1629     {
1630       dtp->u.p.at_eol = 0;
1631       return;
1632     }
1633
1634   do
1635     {
1636       c = next_char (dtp);
1637     }
1638   while (c != '\n');
1639 }
1640
1641 /*                      NAMELIST INPUT
1642
1643 void namelist_read (st_parameter_dt *dtp)
1644 calls:
1645    static void nml_match_name (char *name, int len)
1646    static int nml_query (st_parameter_dt *dtp)
1647    static int nml_get_obj_data (st_parameter_dt *dtp,
1648                                 namelist_info **prev_nl, char *)
1649 calls:
1650       static void nml_untouch_nodes (st_parameter_dt *dtp)
1651       static namelist_info * find_nml_node (st_parameter_dt *dtp,
1652                                             char * var_name)
1653       static int nml_parse_qualifier(descriptor_dimension * ad,
1654                                      array_loop_spec * ls, int rank, char *)
1655       static void nml_touch_nodes (namelist_info * nl)
1656       static int nml_read_obj (namelist_info *nl, index_type offset,
1657                                namelist_info **prev_nl, char *,
1658                                index_type clow, index_type chigh)
1659 calls:
1660       -itself-  */
1661
1662 /* Inputs a rank-dimensional qualifier, which can contain
1663    singlets, doublets, triplets or ':' with the standard meanings.  */
1664
1665 static try
1666 nml_parse_qualifier (st_parameter_dt *dtp, descriptor_dimension *ad,
1667                      array_loop_spec *ls, int rank, char *parse_err_msg)
1668 {
1669   int dim;
1670   int indx;
1671   int neg;
1672   int null_flag;
1673   int is_array_section;
1674   char c;
1675
1676   is_array_section = 0;
1677   dtp->u.p.expanded_read = 0;
1678
1679   /* The next character in the stream should be the '('.  */
1680
1681   c = next_char (dtp);
1682
1683   /* Process the qualifier, by dimension and triplet.  */
1684
1685   for (dim=0; dim < rank; dim++ )
1686     {
1687       for (indx=0; indx<3; indx++)
1688         {
1689           free_saved (dtp);
1690           eat_spaces (dtp);
1691           neg = 0;
1692
1693           /* Process a potential sign.  */
1694           c = next_char (dtp);
1695           switch (c)
1696             {
1697             case '-':
1698               neg = 1;
1699               break;
1700
1701             case '+':
1702               break;
1703
1704             default:
1705               unget_char (dtp, c);
1706               break;
1707             }
1708
1709           /* Process characters up to the next ':' , ',' or ')'.  */
1710           for (;;)
1711             {
1712               c = next_char (dtp);
1713
1714               switch (c)
1715                 {
1716                 case ':':
1717                   is_array_section = 1;
1718                   break;
1719
1720                 case ',': case ')':
1721                   if ((c==',' && dim == rank -1)
1722                       || (c==')' && dim < rank -1))
1723                     {
1724                       st_sprintf (parse_err_msg,
1725                                   "Bad number of index fields");
1726                       goto err_ret;
1727                     }
1728                   break;
1729
1730                 CASE_DIGITS:
1731                   push_char (dtp, c);
1732                   continue;
1733
1734                 case ' ': case '\t':
1735                   eat_spaces (dtp);
1736                   c = next_char (dtp);
1737                   break;
1738
1739                 default:
1740                   st_sprintf (parse_err_msg, "Bad character in index");
1741                   goto err_ret;
1742                 }
1743
1744               if ((c == ',' || c == ')') && indx == 0
1745                   && dtp->u.p.saved_string == 0)
1746                 {
1747                   st_sprintf (parse_err_msg, "Null index field");
1748                   goto err_ret;
1749                 }
1750
1751               if ((c == ':' && indx == 1 && dtp->u.p.saved_string == 0)
1752                   || (indx == 2 && dtp->u.p.saved_string == 0))
1753                 {
1754                   st_sprintf(parse_err_msg, "Bad index triplet");
1755                   goto err_ret;
1756                 }
1757
1758               /* If '( : ? )' or '( ? : )' break and flag read failure.  */
1759               null_flag = 0;
1760               if ((c == ':' && indx == 0 && dtp->u.p.saved_string == 0)
1761                   || (indx==1 && dtp->u.p.saved_string == 0))
1762                 {
1763                   null_flag = 1;
1764                   break;
1765                 }
1766
1767               /* Now read the index.  */
1768               if (convert_integer (dtp, sizeof(ssize_t), neg))
1769                 {
1770                   st_sprintf (parse_err_msg, "Bad integer in index");
1771                   goto err_ret;
1772                 }
1773               break;
1774             }
1775
1776           /* Feed the index values to the triplet arrays.  */
1777           if (!null_flag)
1778             {
1779               if (indx == 0)
1780                 memcpy (&ls[dim].start, dtp->u.p.value, sizeof(ssize_t));
1781               if (indx == 1)
1782                 memcpy (&ls[dim].end, dtp->u.p.value, sizeof(ssize_t));
1783               if (indx == 2)
1784                 memcpy (&ls[dim].step, dtp->u.p.value, sizeof(ssize_t));
1785             }
1786
1787           /* Singlet or doublet indices.  */
1788           if (c==',' || c==')')
1789             {
1790               if (indx == 0)
1791                 {
1792                   memcpy (&ls[dim].start, dtp->u.p.value, sizeof(ssize_t));
1793
1794                   /*  If -std=f95/2003 or an array section is specified,
1795                       do not allow excess data to be processed.  */
1796                   if (is_array_section == 1
1797                       || compile_options.allow_std < GFC_STD_GNU)
1798                     ls[dim].end = ls[dim].start;
1799                   else
1800                     dtp->u.p.expanded_read = 1;
1801                 }
1802               break;
1803             }
1804         }
1805
1806       /* Check the values of the triplet indices.  */
1807       if ((ls[dim].start > (ssize_t)ad[dim].ubound)
1808           || (ls[dim].start < (ssize_t)ad[dim].lbound)
1809           || (ls[dim].end > (ssize_t)ad[dim].ubound)
1810           || (ls[dim].end < (ssize_t)ad[dim].lbound))
1811         {
1812           st_sprintf (parse_err_msg, "Index %d out of range", dim + 1);
1813           goto err_ret;
1814         }
1815       if (((ls[dim].end - ls[dim].start ) * ls[dim].step < 0)
1816           || (ls[dim].step == 0))
1817         {
1818           st_sprintf (parse_err_msg, "Bad range in index %d", dim + 1);
1819           goto err_ret;
1820         }
1821
1822       /* Initialise the loop index counter.  */
1823       ls[dim].idx = ls[dim].start;
1824     }
1825   eat_spaces (dtp);
1826   return SUCCESS;
1827
1828 err_ret:
1829
1830   return FAILURE;
1831 }
1832
1833 static namelist_info *
1834 find_nml_node (st_parameter_dt *dtp, char * var_name)
1835 {
1836   namelist_info * t = dtp->u.p.ionml;
1837   while (t != NULL)
1838     {
1839       if (strcmp (var_name, t->var_name) == 0)
1840         {
1841           t->touched = 1;
1842           return t;
1843         }
1844       t = t->next;
1845     }
1846   return NULL;
1847 }
1848
1849 /* Visits all the components of a derived type that have
1850    not explicitly been identified in the namelist input.
1851    touched is set and the loop specification initialised
1852    to default values  */
1853
1854 static void
1855 nml_touch_nodes (namelist_info * nl)
1856 {
1857   index_type len = strlen (nl->var_name) + 1;
1858   int dim;
1859   char * ext_name = (char*)get_mem (len + 1);
1860   strcpy (ext_name, nl->var_name);
1861   strcat (ext_name, "%");
1862   for (nl = nl->next; nl; nl = nl->next)
1863     {
1864       if (strncmp (nl->var_name, ext_name, len) == 0)
1865         {
1866           nl->touched = 1;
1867           for (dim=0; dim < nl->var_rank; dim++)
1868             {
1869               nl->ls[dim].step = 1;
1870               nl->ls[dim].end = nl->dim[dim].ubound;
1871               nl->ls[dim].start = nl->dim[dim].lbound;
1872               nl->ls[dim].idx = nl->ls[dim].start;
1873             }
1874         }
1875       else
1876         break;
1877     }
1878   free_mem (ext_name);
1879   return;
1880 }
1881
1882 /* Resets touched for the entire list of nml_nodes, ready for a
1883    new object.  */
1884
1885 static void
1886 nml_untouch_nodes (st_parameter_dt *dtp)
1887 {
1888   namelist_info * t;
1889   for (t = dtp->u.p.ionml; t; t = t->next)
1890     t->touched = 0;
1891   return;
1892 }
1893
1894 /* Attempts to input name to namelist name.  Returns
1895    dtp->u.p.nml_read_error = 1 on no match.  */
1896
1897 static void
1898 nml_match_name (st_parameter_dt *dtp, const char *name, index_type len)
1899 {
1900   index_type i;
1901   char c;
1902   dtp->u.p.nml_read_error = 0;
1903   for (i = 0; i < len; i++)
1904     {
1905       c = next_char (dtp);
1906       if (tolower (c) != tolower (name[i]))
1907         {
1908           dtp->u.p.nml_read_error = 1;
1909           break;
1910         }
1911     }
1912 }
1913
1914 /* If the namelist read is from stdin, output the current state of the
1915    namelist to stdout.  This is used to implement the non-standard query
1916    features, ? and =?. If c == '=' the full namelist is printed. Otherwise
1917    the names alone are printed.  */
1918
1919 static void
1920 nml_query (st_parameter_dt *dtp, char c)
1921 {
1922   gfc_unit * temp_unit;
1923   namelist_info * nl;
1924   index_type len;
1925   char * p;
1926
1927   if (dtp->u.p.current_unit->unit_number != options.stdin_unit)
1928     return;
1929
1930   /* Store the current unit and transfer to stdout.  */
1931
1932   temp_unit = dtp->u.p.current_unit;
1933   dtp->u.p.current_unit = find_unit (options.stdout_unit);
1934
1935   if (dtp->u.p.current_unit)
1936     {
1937       dtp->u.p.mode = WRITING;
1938       next_record (dtp, 0);
1939
1940       /* Write the namelist in its entirety.  */
1941
1942       if (c == '=')
1943         namelist_write (dtp);
1944
1945       /* Or write the list of names.  */
1946
1947       else
1948         {
1949
1950           /* "&namelist_name\n"  */
1951
1952           len = dtp->namelist_name_len;
1953 #ifdef HAVE_CRLF
1954           p = write_block (dtp, len + 3);
1955 #else
1956           p = write_block (dtp, len + 2);
1957 #endif
1958           if (!p)
1959             goto query_return;
1960           memcpy (p, "&", 1);
1961           memcpy ((char*)(p + 1), dtp->namelist_name, len);
1962 #ifdef HAVE_CRLF
1963           memcpy ((char*)(p + len + 1), "\r\n", 2);
1964 #else
1965           memcpy ((char*)(p + len + 1), "\n", 1);
1966 #endif
1967           for (nl = dtp->u.p.ionml; nl; nl = nl->next)
1968             {
1969
1970               /* " var_name\n"  */
1971
1972               len = strlen (nl->var_name);
1973 #ifdef HAVE_CRLF
1974               p = write_block (dtp, len + 3);
1975 #else
1976               p = write_block (dtp, len + 2);
1977 #endif
1978               if (!p)
1979                 goto query_return;
1980               memcpy (p, " ", 1);
1981               memcpy ((char*)(p + 1), nl->var_name, len);
1982 #ifdef HAVE_CRLF
1983               memcpy ((char*)(p + len + 1), "\r\n", 2);
1984 #else
1985               memcpy ((char*)(p + len + 1), "\n", 1);
1986 #endif
1987             }
1988
1989           /* "&end\n"  */
1990
1991 #ifdef HAVE_CRLF
1992           p = write_block (dtp, 6);
1993 #else
1994           p = write_block (dtp, 5);
1995 #endif
1996           if (!p)
1997             goto query_return;
1998 #ifdef HAVE_CRLF
1999           memcpy (p, "&end\r\n", 6);
2000 #else
2001           memcpy (p, "&end\n", 5);
2002 #endif
2003         }
2004
2005       /* Flush the stream to force immediate output.  */
2006
2007       flush (dtp->u.p.current_unit->s);
2008       unlock_unit (dtp->u.p.current_unit);
2009     }
2010
2011 query_return:
2012
2013   /* Restore the current unit.  */
2014
2015   dtp->u.p.current_unit = temp_unit;
2016   dtp->u.p.mode = READING;
2017   return;
2018 }
2019
2020 /* Reads and stores the input for the namelist object nl.  For an array,
2021    the function loops over the ranges defined by the loop specification.
2022    This default to all the data or to the specification from a qualifier.
2023    nml_read_obj recursively calls itself to read derived types. It visits
2024    all its own components but only reads data for those that were touched
2025    when the name was parsed.  If a read error is encountered, an attempt is
2026    made to return to read a new object name because the standard allows too
2027    little data to be available.  On the other hand, too much data is an
2028    error.  */
2029
2030 static try
2031 nml_read_obj (st_parameter_dt *dtp, namelist_info * nl, index_type offset,
2032               namelist_info **pprev_nl, char *nml_err_msg,
2033               index_type clow, index_type chigh)
2034 {
2035
2036   namelist_info * cmp;
2037   char * obj_name;
2038   int nml_carry;
2039   int len;
2040   int dim;
2041   index_type dlen;
2042   index_type m;
2043   index_type obj_name_len;
2044   void * pdata ;
2045
2046   /* This object not touched in name parsing.  */
2047
2048   if (!nl->touched)
2049     return SUCCESS;
2050
2051   dtp->u.p.repeat_count = 0;
2052   eat_spaces (dtp);
2053
2054   len = nl->len;
2055   switch (nl->type)
2056   {
2057
2058     case GFC_DTYPE_INTEGER:
2059     case GFC_DTYPE_LOGICAL:
2060       dlen = len;
2061       break;
2062
2063     case GFC_DTYPE_REAL:
2064       dlen = size_from_real_kind (len);
2065       break;
2066
2067     case GFC_DTYPE_COMPLEX:
2068       dlen = size_from_complex_kind (len);
2069       break;
2070
2071     case GFC_DTYPE_CHARACTER:
2072       dlen = chigh ? (chigh - clow + 1) : nl->string_length;
2073       break;
2074
2075     default:
2076       dlen = 0;
2077     }
2078
2079   do
2080     {
2081
2082       /* Update the pointer to the data, using the current index vector  */
2083
2084       pdata = (void*)(nl->mem_pos + offset);
2085       for (dim = 0; dim < nl->var_rank; dim++)
2086         pdata = (void*)(pdata + (nl->ls[dim].idx - nl->dim[dim].lbound) *
2087                  nl->dim[dim].stride * nl->size);
2088
2089       /* Reset the error flag and try to read next value, if
2090          dtp->u.p.repeat_count=0  */
2091
2092       dtp->u.p.nml_read_error = 0;
2093       nml_carry = 0;
2094       if (--dtp->u.p.repeat_count <= 0)
2095         {
2096           if (dtp->u.p.input_complete)
2097             return SUCCESS;
2098           if (dtp->u.p.at_eol)
2099             finish_separator (dtp);
2100           if (dtp->u.p.input_complete)
2101             return SUCCESS;
2102
2103           /* GFC_TYPE_UNKNOWN through for nulls and is detected
2104              after the switch block.  */
2105
2106           dtp->u.p.saved_type = GFC_DTYPE_UNKNOWN;
2107           free_saved (dtp);
2108
2109           switch (nl->type)
2110           {
2111           case GFC_DTYPE_INTEGER:
2112               read_integer (dtp, len);
2113               break;
2114
2115           case GFC_DTYPE_LOGICAL:
2116               read_logical (dtp, len);
2117               break;
2118
2119           case GFC_DTYPE_CHARACTER:
2120               read_character (dtp, len);
2121               break;
2122
2123           case GFC_DTYPE_REAL:
2124               read_real (dtp, len);
2125               break;
2126
2127           case GFC_DTYPE_COMPLEX:
2128               read_complex (dtp, len, dlen);
2129               break;
2130
2131           case GFC_DTYPE_DERIVED:
2132             obj_name_len = strlen (nl->var_name) + 1;
2133             obj_name = get_mem (obj_name_len+1);
2134             strcpy (obj_name, nl->var_name);
2135             strcat (obj_name, "%");
2136
2137             /* If reading a derived type, disable the expanded read warning
2138                since a single object can have multiple reads.  */
2139             dtp->u.p.expanded_read = 0;
2140
2141             /* Now loop over the components. Update the component pointer
2142                with the return value from nml_write_obj.  This loop jumps
2143                past nested derived types by testing if the potential
2144                component name contains '%'.  */
2145
2146             for (cmp = nl->next;
2147                  cmp &&
2148                    !strncmp (cmp->var_name, obj_name, obj_name_len) &&
2149                    !strchr (cmp->var_name + obj_name_len, '%');
2150                  cmp = cmp->next)
2151               {
2152
2153                 if (nml_read_obj (dtp, cmp, (index_type)(pdata - nl->mem_pos),
2154                                   pprev_nl, nml_err_msg, clow, chigh)
2155                     == FAILURE)
2156                   {
2157                     free_mem (obj_name);
2158                     return FAILURE;
2159                   }
2160
2161                 if (dtp->u.p.input_complete)
2162                   {
2163                     free_mem (obj_name);
2164                     return SUCCESS;
2165                   }
2166               }
2167
2168             free_mem (obj_name);
2169             goto incr_idx;
2170
2171           default:
2172             st_sprintf (nml_err_msg, "Bad type for namelist object %s",
2173                         nl->var_name);
2174             internal_error (&dtp->common, nml_err_msg);
2175             goto nml_err_ret;
2176           }
2177         }
2178
2179       /* The standard permits array data to stop short of the number of
2180          elements specified in the loop specification.  In this case, we
2181          should be here with dtp->u.p.nml_read_error != 0.  Control returns to
2182          nml_get_obj_data and an attempt is made to read object name.  */
2183
2184       *pprev_nl = nl;
2185       if (dtp->u.p.nml_read_error)
2186         {
2187           dtp->u.p.expanded_read = 0;
2188           return SUCCESS;
2189         }
2190
2191       if (dtp->u.p.saved_type == GFC_DTYPE_UNKNOWN)
2192         {
2193           dtp->u.p.expanded_read = 0;
2194           goto incr_idx;
2195         }
2196
2197       /* Note the switch from GFC_DTYPE_type to BT_type at this point.
2198          This comes about because the read functions return BT_types.  */
2199
2200       switch (dtp->u.p.saved_type)
2201       {
2202
2203         case BT_COMPLEX:
2204         case BT_REAL:
2205         case BT_INTEGER:
2206         case BT_LOGICAL:
2207           memcpy (pdata, dtp->u.p.value, dlen);
2208           break;
2209
2210         case BT_CHARACTER:
2211           m = (dlen < dtp->u.p.saved_used) ? dlen : dtp->u.p.saved_used;
2212           pdata = (void*)( pdata + clow - 1 );
2213           memcpy (pdata, dtp->u.p.saved_string, m);
2214           if (m < dlen)
2215             memset ((void*)( pdata + m ), ' ', dlen - m);
2216           break;
2217
2218         default:
2219           break;
2220       }
2221
2222       /* Warn if a non-standard expanded read occurs. A single read of a
2223          single object is acceptable.  If a second read occurs, issue a warning
2224          and set the flag to zero to prevent further warnings.  */
2225       if (dtp->u.p.expanded_read == 2)
2226         {
2227           notify_std (&dtp->common, GFC_STD_GNU, "Non-standard expanded namelist read.");
2228           dtp->u.p.expanded_read = 0;
2229         }
2230
2231       /* If the expanded read warning flag is set, increment it,
2232          indicating that a single read has occurred.  */
2233       if (dtp->u.p.expanded_read >= 1)
2234         dtp->u.p.expanded_read++;
2235
2236       /* Break out of loop if scalar.  */
2237       if (!nl->var_rank)
2238         break;
2239
2240       /* Now increment the index vector.  */
2241
2242 incr_idx:
2243
2244       nml_carry = 1;
2245       for (dim = 0; dim < nl->var_rank; dim++)
2246         {
2247           nl->ls[dim].idx += nml_carry * nl->ls[dim].step;
2248           nml_carry = 0;
2249           if (((nl->ls[dim].step > 0) && (nl->ls[dim].idx > nl->ls[dim].end))
2250               ||
2251               ((nl->ls[dim].step < 0) && (nl->ls[dim].idx < nl->ls[dim].end)))
2252             {
2253               nl->ls[dim].idx = nl->ls[dim].start;
2254               nml_carry = 1;
2255             }
2256         }
2257     } while (!nml_carry);
2258
2259   if (dtp->u.p.repeat_count > 1)
2260     {
2261        st_sprintf (nml_err_msg, "Repeat count too large for namelist object %s" ,
2262                    nl->var_name );
2263        goto nml_err_ret;
2264     }
2265   return SUCCESS;
2266
2267 nml_err_ret:
2268
2269   return FAILURE;
2270 }
2271
2272 /* Parses the object name, including array and substring qualifiers.  It
2273    iterates over derived type components, touching those components and
2274    setting their loop specifications, if there is a qualifier.  If the
2275    object is itself a derived type, its components and subcomponents are
2276    touched.  nml_read_obj is called at the end and this reads the data in
2277    the manner specified by the object name.  */
2278
2279 static try
2280 nml_get_obj_data (st_parameter_dt *dtp, namelist_info **pprev_nl,
2281                   char *nml_err_msg)
2282 {
2283   char c;
2284   namelist_info * nl;
2285   namelist_info * first_nl = NULL;
2286   namelist_info * root_nl = NULL;
2287   int dim;
2288   int component_flag;
2289   char parse_err_msg[30];
2290   index_type clow, chigh;
2291
2292   /* Look for end of input or object name.  If '?' or '=?' are encountered
2293      in stdin, print the node names or the namelist to stdout.  */
2294
2295   eat_separator (dtp);
2296   if (dtp->u.p.input_complete)
2297     return SUCCESS;
2298
2299   if (dtp->u.p.at_eol)
2300     finish_separator (dtp);
2301   if (dtp->u.p.input_complete)
2302     return SUCCESS;
2303
2304   c = next_char (dtp);
2305   switch (c)
2306     {
2307     case '=':
2308       c = next_char (dtp);
2309       if (c != '?')
2310         {
2311           st_sprintf (nml_err_msg, "namelist read: misplaced = sign");
2312           goto nml_err_ret;
2313         }
2314       nml_query (dtp, '=');
2315       return SUCCESS;
2316
2317     case '?':
2318       nml_query (dtp, '?');
2319       return SUCCESS;
2320
2321     case '$':
2322     case '&':
2323       nml_match_name (dtp, "end", 3);
2324       if (dtp->u.p.nml_read_error)
2325         {
2326           st_sprintf (nml_err_msg, "namelist not terminated with / or &end");
2327           goto nml_err_ret;
2328         }
2329     case '/':
2330       dtp->u.p.input_complete = 1;
2331       return SUCCESS;
2332
2333     default :
2334       break;
2335     }
2336
2337   /* Untouch all nodes of the namelist and reset the flag that is set for
2338      derived type components.  */
2339
2340   nml_untouch_nodes (dtp);
2341   component_flag = 0;
2342
2343   /* Get the object name - should '!' and '\n' be permitted separators?  */
2344
2345 get_name:
2346
2347   free_saved (dtp);
2348
2349   do
2350     {
2351       push_char (dtp, tolower(c));
2352       c = next_char (dtp);
2353     } while (!( c=='=' || c==' ' || c=='\t' || c =='(' || c =='%' ));
2354
2355   unget_char (dtp, c);
2356
2357   /* Check that the name is in the namelist and get pointer to object.
2358      Three error conditions exist: (i) An attempt is being made to
2359      identify a non-existent object, following a failed data read or
2360      (ii) The object name does not exist or (iii) Too many data items
2361      are present for an object.  (iii) gives the same error message
2362      as (i)  */
2363
2364   push_char (dtp, '\0');
2365
2366   if (component_flag)
2367     {
2368       size_t var_len = strlen (root_nl->var_name);
2369       size_t saved_len
2370         = dtp->u.p.saved_string ? strlen (dtp->u.p.saved_string) : 0;
2371       char ext_name[var_len + saved_len + 1];
2372
2373       memcpy (ext_name, root_nl->var_name, var_len);
2374       if (dtp->u.p.saved_string)
2375         memcpy (ext_name + var_len, dtp->u.p.saved_string, saved_len);
2376       ext_name[var_len + saved_len] = '\0';
2377       nl = find_nml_node (dtp, ext_name);
2378     }
2379   else
2380     nl = find_nml_node (dtp, dtp->u.p.saved_string);
2381
2382   if (nl == NULL)
2383     {
2384       if (dtp->u.p.nml_read_error && *pprev_nl)
2385         st_sprintf (nml_err_msg, "Bad data for namelist object %s",
2386                     (*pprev_nl)->var_name);
2387
2388       else
2389         st_sprintf (nml_err_msg, "Cannot match namelist object name %s",
2390                     dtp->u.p.saved_string);
2391
2392       goto nml_err_ret;
2393     }
2394
2395   /* Get the length, data length, base pointer and rank of the variable.
2396      Set the default loop specification first.  */
2397
2398   for (dim=0; dim < nl->var_rank; dim++)
2399     {
2400       nl->ls[dim].step = 1;
2401       nl->ls[dim].end = nl->dim[dim].ubound;
2402       nl->ls[dim].start = nl->dim[dim].lbound;
2403       nl->ls[dim].idx = nl->ls[dim].start;
2404     }
2405
2406 /* Check to see if there is a qualifier: if so, parse it.*/
2407
2408   if (c == '(' && nl->var_rank)
2409     {
2410       if (nml_parse_qualifier (dtp, nl->dim, nl->ls, nl->var_rank,
2411                                parse_err_msg) == FAILURE)
2412         {
2413           st_sprintf (nml_err_msg, "%s for namelist variable %s",
2414                       parse_err_msg, nl->var_name);
2415           goto nml_err_ret;
2416         }
2417       c = next_char (dtp);
2418       unget_char (dtp, c);
2419     }
2420
2421   /* Now parse a derived type component. The root namelist_info address
2422      is backed up, as is the previous component level.  The  component flag
2423      is set and the iteration is made by jumping back to get_name.  */
2424
2425   if (c == '%')
2426     {
2427
2428       if (nl->type != GFC_DTYPE_DERIVED)
2429         {
2430           st_sprintf (nml_err_msg, "Attempt to get derived component for %s",
2431                       nl->var_name);
2432           goto nml_err_ret;
2433         }
2434
2435       if (!component_flag)
2436         first_nl = nl;
2437
2438       root_nl = nl;
2439       component_flag = 1;
2440       c = next_char (dtp);
2441       goto get_name;
2442
2443     }
2444
2445   /* Parse a character qualifier, if present.  chigh = 0 is a default
2446      that signals that the string length = string_length.  */
2447
2448   clow = 1;
2449   chigh = 0;
2450
2451   if (c == '(' && nl->type == GFC_DTYPE_CHARACTER)
2452     {
2453       descriptor_dimension chd[1] = { {1, clow, nl->string_length} };
2454       array_loop_spec ind[1] = { {1, clow, nl->string_length, 1} };
2455
2456       if (nml_parse_qualifier (dtp, chd, ind, 1, parse_err_msg) == FAILURE)
2457         {
2458           st_sprintf (nml_err_msg, "%s for namelist variable %s",
2459                       parse_err_msg, nl->var_name);
2460           goto nml_err_ret;
2461         }
2462
2463       clow = ind[0].start;
2464       chigh = ind[0].end;
2465
2466       if (ind[0].step != 1)
2467         {
2468           st_sprintf (nml_err_msg,
2469                       "Bad step in substring for namelist object %s",
2470                       nl->var_name);
2471           goto nml_err_ret;
2472         }
2473
2474       c = next_char (dtp);
2475       unget_char (dtp, c);
2476     }
2477
2478   /* If a derived type touch its components and restore the root
2479      namelist_info if we have parsed a qualified derived type
2480      component.  */
2481
2482   if (nl->type == GFC_DTYPE_DERIVED)
2483     nml_touch_nodes (nl);
2484   if (component_flag)
2485     nl = first_nl;
2486
2487   /*make sure no extraneous qualifiers are there.*/
2488
2489   if (c == '(')
2490     {
2491       st_sprintf (nml_err_msg, "Qualifier for a scalar or non-character"
2492                   " namelist object %s", nl->var_name);
2493       goto nml_err_ret;
2494     }
2495
2496 /* According to the standard, an equal sign MUST follow an object name. The
2497    following is possibly lax - it allows comments, blank lines and so on to
2498    intervene.  eat_spaces (dtp); c = next_char (dtp); would be compliant*/
2499
2500   free_saved (dtp);
2501
2502   eat_separator (dtp);
2503   if (dtp->u.p.input_complete)
2504     return SUCCESS;
2505
2506   if (dtp->u.p.at_eol)
2507     finish_separator (dtp);
2508   if (dtp->u.p.input_complete)
2509     return SUCCESS;
2510
2511   c = next_char (dtp);
2512
2513   if (c != '=')
2514     {
2515       st_sprintf (nml_err_msg, "Equal sign must follow namelist object name %s",
2516                   nl->var_name);
2517       goto nml_err_ret;
2518     }
2519
2520   if (nml_read_obj (dtp, nl, 0, pprev_nl, nml_err_msg, clow, chigh) == FAILURE)
2521     goto nml_err_ret;
2522
2523   return SUCCESS;
2524
2525 nml_err_ret:
2526
2527   return FAILURE;
2528 }
2529
2530 /* Entry point for namelist input.  Goes through input until namelist name
2531   is matched.  Then cycles through nml_get_obj_data until the input is
2532   completed or there is an error.  */
2533
2534 void
2535 namelist_read (st_parameter_dt *dtp)
2536 {
2537   char c;
2538   jmp_buf eof_jump;
2539   char nml_err_msg[100];
2540   /* Pointer to the previously read object, in case attempt is made to read
2541      new object name.  Should this fail, error message can give previous
2542      name.  */
2543   namelist_info *prev_nl = NULL;
2544
2545   dtp->u.p.namelist_mode = 1;
2546   dtp->u.p.input_complete = 0;
2547   dtp->u.p.expanded_read = 0;
2548
2549   dtp->u.p.eof_jump = &eof_jump;
2550   if (setjmp (eof_jump))
2551     {
2552       dtp->u.p.eof_jump = NULL;
2553       generate_error (&dtp->common, ERROR_END, NULL);
2554       return;
2555     }
2556
2557   /* Look for &namelist_name .  Skip all characters, testing for $nmlname.
2558      Exit on success or EOF. If '?' or '=?' encountered in stdin, print
2559      node names or namelist on stdout.  */
2560
2561 find_nml_name:
2562   switch (c = next_char (dtp))
2563     {
2564     case '$':
2565     case '&':
2566           break;
2567
2568     case '=':
2569       c = next_char (dtp);
2570       if (c == '?')
2571         nml_query (dtp, '=');
2572       else
2573         unget_char (dtp, c);
2574       goto find_nml_name;
2575
2576     case '?':
2577       nml_query (dtp, '?');
2578
2579     default:
2580       goto find_nml_name;
2581     }
2582
2583   /* Match the name of the namelist.  */
2584
2585   nml_match_name (dtp, dtp->namelist_name, dtp->namelist_name_len);
2586
2587   if (dtp->u.p.nml_read_error)
2588     goto find_nml_name;
2589
2590   /* Ready to read namelist objects.  If there is an error in input
2591      from stdin, output the error message and continue.  */
2592
2593   while (!dtp->u.p.input_complete)
2594     {
2595       if (nml_get_obj_data (dtp, &prev_nl, nml_err_msg) == FAILURE)
2596         {
2597           gfc_unit *u;
2598
2599           if (dtp->u.p.current_unit->unit_number != options.stdin_unit)
2600             goto nml_err_ret;
2601
2602           u = find_unit (options.stderr_unit);
2603           st_printf ("%s\n", nml_err_msg);
2604           if (u != NULL)
2605             {
2606               flush (u->s);
2607               unlock_unit (u);
2608             }
2609         }
2610
2611    }
2612
2613   dtp->u.p.eof_jump = NULL;
2614   free_saved (dtp);
2615   free_line (dtp);
2616   return;
2617
2618   /* All namelist error calls return from here */
2619
2620 nml_err_ret:
2621
2622   dtp->u.p.eof_jump = NULL;
2623   free_saved (dtp);
2624   free_line (dtp);
2625   generate_error (&dtp->common, ERROR_READ_VALUE, nml_err_msg);
2626   return;
2627 }