* configure.in: Add --enable-libssp and --disable-libssp.
[official-gcc.git] / libgfortran / io / list_read.c
blob3d62d8c845ec90d3cf746c1adcf396758deba777
1 /* Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
2 Contributed by Andy Vaught
3 Namelist input contributed by Paul Thomas
5 This file is part of the GNU Fortran 95 runtime library (libgfortran).
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.
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.)
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.
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, 59 Temple Place - Suite 330,
29 Boston, MA 02111-1307, USA. */
32 #include "config.h"
33 #include <string.h>
34 #include <ctype.h>
35 #include "libgfortran.h"
36 #include "io.h"
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. */
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. Data is buffered in scratch[] until it becomes too
52 large, after which we start allocating memory on the heap. */
54 static int repeat_count, saved_length, saved_used;
55 static int input_complete, at_eol, comma_flag;
56 static char last_char, *saved_string;
57 static bt saved_type;
59 /* A namelist specific flag used in the list directed library
60 to flag that calls are being made from namelist read (eg. to ignore
61 comments or to treat '/' as a terminator) */
63 static int namelist_mode;
65 /* A namelist specific flag used in the list directed library to flag
66 read errors and return, so that an attempt can be made to read a
67 new object name. */
69 static int nml_read_error;
71 /* Storage area for values except for strings. Must be large enough
72 to hold a complex value (two reals) of the largest kind. */
74 static char value[20];
76 #define CASE_DIGITS case '0': case '1': case '2': case '3': case '4': \
77 case '5': case '6': case '7': case '8': case '9'
79 #define CASE_SEPARATORS case ' ': case ',': case '/': case '\n': case '\t': \
80 case '\r'
82 /* This macro assumes that we're operating on a variable. */
84 #define is_separator(c) (c == '/' || c == ',' || c == '\n' || c == ' ' \
85 || c == '\t' || c == '\r')
87 /* Maximum repeat count. Less than ten times the maximum signed int32. */
89 #define MAX_REPEAT 200000000
92 /* Save a character to a string buffer, enlarging it as necessary. */
94 static void
95 push_char (char c)
97 char *new;
99 if (saved_string == NULL)
101 saved_string = scratch;
102 memset (saved_string,0,SCRATCH_SIZE);
103 saved_length = SCRATCH_SIZE;
104 saved_used = 0;
107 if (saved_used >= saved_length)
109 saved_length = 2 * saved_length;
110 new = get_mem (2 * saved_length);
112 memset (new,0,2 * saved_length);
114 memcpy (new, saved_string, saved_used);
115 if (saved_string != scratch)
116 free_mem (saved_string);
118 saved_string = new;
121 saved_string[saved_used++] = c;
125 /* Free the input buffer if necessary. */
127 static void
128 free_saved (void)
130 if (saved_string == NULL)
131 return;
133 if (saved_string != scratch)
134 free_mem (saved_string);
136 saved_string = NULL;
140 static char
141 next_char (void)
143 int length;
144 char c, *p;
146 if (last_char != '\0')
148 at_eol = 0;
149 c = last_char;
150 last_char = '\0';
151 goto done;
154 length = 1;
156 p = salloc_r (current_unit->s, &length);
157 if (p == NULL)
159 generate_error (ERROR_OS, NULL);
160 return '\0';
163 if (length == 0)
165 /* For internal files return a newline instead of signalling EOF. */
166 /* ??? This isn't quite right, but we don't handle internal files
167 with multiple records. */
168 if (is_internal_unit ())
169 c = '\n';
170 else
171 longjmp (g.eof_jump, 1);
173 else
174 c = *p;
176 done:
177 at_eol = (c == '\n' || c == '\r');
178 return c;
182 /* Push a character back onto the input. */
184 static void
185 unget_char (char c)
187 last_char = c;
191 /* Skip over spaces in the input. Returns the nonspace character that
192 terminated the eating and also places it back on the input. */
194 static char
195 eat_spaces (void)
197 char c;
201 c = next_char ();
203 while (c == ' ' || c == '\t');
205 unget_char (c);
206 return c;
210 /* Skip over a separator. Technically, we don't always eat the whole
211 separator. This is because if we've processed the last input item,
212 then a separator is unnecessary. Plus the fact that operating
213 systems usually deliver console input on a line basis.
215 The upshot is that if we see a newline as part of reading a
216 separator, we stop reading. If there are more input items, we
217 continue reading the separator with finish_separator() which takes
218 care of the fact that we may or may not have seen a comma as part
219 of the separator. */
221 static void
222 eat_separator (void)
224 char c;
226 eat_spaces ();
227 comma_flag = 0;
229 c = next_char ();
230 switch (c)
232 case ',':
233 comma_flag = 1;
234 eat_spaces ();
235 break;
237 case '/':
238 input_complete = 1;
239 break;
241 case '\n':
242 case '\r':
243 at_eol = 1;
244 break;
246 case '!':
247 if (namelist_mode)
248 { /* Eat a namelist comment. */
250 c = next_char ();
251 while (c != '\n');
253 break;
256 /* Fall Through... */
258 default:
259 unget_char (c);
260 break;
265 /* Finish processing a separator that was interrupted by a newline.
266 If we're here, then another data item is present, so we finish what
267 we started on the previous line. */
269 static void
270 finish_separator (void)
272 char c;
274 restart:
275 eat_spaces ();
277 c = next_char ();
278 switch (c)
280 case ',':
281 if (comma_flag)
282 unget_char (c);
283 else
285 c = eat_spaces ();
286 if (c == '\n')
287 goto restart;
290 break;
292 case '/':
293 input_complete = 1;
294 if (!namelist_mode) next_record (0);
295 break;
297 case '\n':
298 case '\r':
299 goto restart;
301 case '!':
302 if (namelist_mode)
305 c = next_char ();
306 while (c != '\n');
308 goto restart;
311 default:
312 unget_char (c);
313 break;
317 /* This function is needed to catch bad conversions so that namelist can
318 attempt to see if saved_string contains a new object name rather than
319 a bad value. */
321 static int
322 nml_bad_return (char c)
324 if (namelist_mode)
326 nml_read_error = 1;
327 unget_char(c);
328 return 1;
330 return 0;
333 /* Convert an unsigned string to an integer. The length value is -1
334 if we are working on a repeat count. Returns nonzero if we have a
335 range problem. As a side effect, frees the saved_string. */
337 static int
338 convert_integer (int length, int negative)
340 char c, *buffer, message[100];
341 int m;
342 GFC_INTEGER_LARGEST v, max, max10;
344 buffer = saved_string;
345 v = 0;
347 max = (length == -1) ? MAX_REPEAT : max_value (length, 1);
348 max10 = max / 10;
350 for (;;)
352 c = *buffer++;
353 if (c == '\0')
354 break;
355 c -= '0';
357 if (v > max10)
358 goto overflow;
359 v = 10 * v;
361 if (v > max - c)
362 goto overflow;
363 v += c;
366 m = 0;
368 if (length != -1)
370 if (negative)
371 v = -v;
372 set_integer (value, v, length);
374 else
376 repeat_count = v;
378 if (repeat_count == 0)
380 st_sprintf (message, "Zero repeat count in item %d of list input",
381 g.item_count);
383 generate_error (ERROR_READ_VALUE, message);
384 m = 1;
388 free_saved ();
389 return m;
391 overflow:
392 if (length == -1)
393 st_sprintf (message, "Repeat count overflow in item %d of list input",
394 g.item_count);
395 else
396 st_sprintf (message, "Integer overflow while reading item %d",
397 g.item_count);
399 free_saved ();
400 generate_error (ERROR_READ_VALUE, message);
402 return 1;
406 /* Parse a repeat count for logical and complex values which cannot
407 begin with a digit. Returns nonzero if we are done, zero if we
408 should continue on. */
410 static int
411 parse_repeat (void)
413 char c, message[100];
414 int repeat;
416 c = next_char ();
417 switch (c)
419 CASE_DIGITS:
420 repeat = c - '0';
421 break;
423 CASE_SEPARATORS:
424 unget_char (c);
425 eat_separator ();
426 return 1;
428 default:
429 unget_char (c);
430 return 0;
433 for (;;)
435 c = next_char ();
436 switch (c)
438 CASE_DIGITS:
439 repeat = 10 * repeat + c - '0';
441 if (repeat > MAX_REPEAT)
443 st_sprintf (message,
444 "Repeat count overflow in item %d of list input",
445 g.item_count);
447 generate_error (ERROR_READ_VALUE, message);
448 return 1;
451 break;
453 case '*':
454 if (repeat == 0)
456 st_sprintf (message,
457 "Zero repeat count in item %d of list input",
458 g.item_count);
460 generate_error (ERROR_READ_VALUE, message);
461 return 1;
464 goto done;
466 default:
467 goto bad_repeat;
471 done:
472 repeat_count = repeat;
473 return 0;
475 bad_repeat:
476 st_sprintf (message, "Bad repeat count in item %d of list input",
477 g.item_count);
479 generate_error (ERROR_READ_VALUE, message);
480 return 1;
484 /* Read a logical character on the input. */
486 static void
487 read_logical (int length)
489 char c, message[100];
490 int v;
492 if (parse_repeat ())
493 return;
495 c = next_char ();
496 switch (c)
498 case 't':
499 case 'T':
500 v = 1;
501 break;
502 case 'f':
503 case 'F':
504 v = 0;
505 break;
507 case '.':
508 c = next_char ();
509 switch (c)
511 case 't':
512 case 'T':
513 v = 1;
514 break;
515 case 'f':
516 case 'F':
517 v = 0;
518 break;
519 default:
520 goto bad_logical;
523 break;
525 CASE_SEPARATORS:
526 unget_char (c);
527 eat_separator ();
528 return; /* Null value. */
530 default:
531 goto bad_logical;
534 saved_type = BT_LOGICAL;
535 saved_length = length;
537 /* Eat trailing garbage. */
540 c = next_char ();
542 while (!is_separator (c));
544 unget_char (c);
545 eat_separator ();
546 free_saved ();
547 set_integer ((int *) value, v, length);
549 return;
551 bad_logical:
553 if (nml_bad_return (c))
554 return;
556 st_sprintf (message, "Bad logical value while reading item %d",
557 g.item_count);
559 generate_error (ERROR_READ_VALUE, message);
563 /* Reading integers is tricky because we can actually be reading a
564 repeat count. We have to store the characters in a buffer because
565 we could be reading an integer that is larger than the default int
566 used for repeat counts. */
568 static void
569 read_integer (int length)
571 char c, message[100];
572 int negative;
574 negative = 0;
576 c = next_char ();
577 switch (c)
579 case '-':
580 negative = 1;
581 /* Fall through... */
583 case '+':
584 c = next_char ();
585 goto get_integer;
587 CASE_SEPARATORS: /* Single null. */
588 unget_char (c);
589 eat_separator ();
590 return;
592 CASE_DIGITS:
593 push_char (c);
594 break;
596 default:
597 goto bad_integer;
600 /* Take care of what may be a repeat count. */
602 for (;;)
604 c = next_char ();
605 switch (c)
607 CASE_DIGITS:
608 push_char (c);
609 break;
611 case '*':
612 push_char ('\0');
613 goto repeat;
615 CASE_SEPARATORS: /* Not a repeat count. */
616 goto done;
618 default:
619 goto bad_integer;
623 repeat:
624 if (convert_integer (-1, 0))
625 return;
627 /* Get the real integer. */
629 c = next_char ();
630 switch (c)
632 CASE_DIGITS:
633 break;
635 CASE_SEPARATORS:
636 unget_char (c);
637 eat_separator ();
638 return;
640 case '-':
641 negative = 1;
642 /* Fall through... */
644 case '+':
645 c = next_char ();
646 break;
649 get_integer:
650 if (!isdigit (c))
651 goto bad_integer;
652 push_char (c);
654 for (;;)
656 c = next_char ();
657 switch (c)
659 CASE_DIGITS:
660 push_char (c);
661 break;
663 CASE_SEPARATORS:
664 goto done;
666 default:
667 goto bad_integer;
671 bad_integer:
673 if (nml_bad_return (c))
674 return;
676 free_saved ();
678 st_sprintf (message, "Bad integer for item %d in list input", g.item_count);
679 generate_error (ERROR_READ_VALUE, message);
681 return;
683 done:
684 unget_char (c);
685 eat_separator ();
687 push_char ('\0');
688 if (convert_integer (length, negative))
690 free_saved ();
691 return;
694 free_saved ();
695 saved_type = BT_INTEGER;
699 /* Read a character variable. */
701 static void
702 read_character (int length __attribute__ ((unused)))
704 char c, quote, message[100];
706 quote = ' '; /* Space means no quote character. */
708 c = next_char ();
709 switch (c)
711 CASE_DIGITS:
712 push_char (c);
713 break;
715 CASE_SEPARATORS:
716 unget_char (c); /* NULL value. */
717 eat_separator ();
718 return;
720 case '"':
721 case '\'':
722 quote = c;
723 goto get_string;
725 default:
726 push_char (c);
727 goto get_string;
730 /* Deal with a possible repeat count. */
732 for (;;)
734 c = next_char ();
735 switch (c)
737 CASE_DIGITS:
738 push_char (c);
739 break;
741 CASE_SEPARATORS:
742 unget_char (c);
743 goto done; /* String was only digits! */
745 case '*':
746 push_char ('\0');
747 goto got_repeat;
749 default:
750 push_char (c);
751 goto get_string; /* Not a repeat count after all. */
755 got_repeat:
756 if (convert_integer (-1, 0))
757 return;
759 /* Now get the real string. */
761 c = next_char ();
762 switch (c)
764 CASE_SEPARATORS:
765 unget_char (c); /* Repeated NULL values. */
766 eat_separator ();
767 return;
769 case '"':
770 case '\'':
771 quote = c;
772 break;
774 default:
775 push_char (c);
776 break;
779 get_string:
780 for (;;)
782 c = next_char ();
783 switch (c)
785 case '"':
786 case '\'':
787 if (c != quote)
789 push_char (c);
790 break;
793 /* See if we have a doubled quote character or the end of
794 the string. */
796 c = next_char ();
797 if (c == quote)
799 push_char (quote);
800 break;
803 unget_char (c);
804 goto done;
806 CASE_SEPARATORS:
807 if (quote == ' ')
809 unget_char (c);
810 goto done;
813 if (c != '\n')
814 push_char (c);
815 break;
817 default:
818 push_char (c);
819 break;
823 /* At this point, we have to have a separator, or else the string is
824 invalid. */
825 done:
826 c = next_char ();
827 if (is_separator (c))
829 unget_char (c);
830 eat_separator ();
831 saved_type = BT_CHARACTER;
833 else
835 free_saved ();
836 st_sprintf (message, "Invalid string input in item %d", g.item_count);
837 generate_error (ERROR_READ_VALUE, message);
842 /* Parse a component of a complex constant or a real number that we
843 are sure is already there. This is a straight real number parser. */
845 static int
846 parse_real (void *buffer, int length)
848 char c, message[100];
849 int m, seen_dp;
851 c = next_char ();
852 if (c == '-' || c == '+')
854 push_char (c);
855 c = next_char ();
858 if (!isdigit (c) && c != '.')
859 goto bad;
861 push_char (c);
863 seen_dp = (c == '.') ? 1 : 0;
865 for (;;)
867 c = next_char ();
868 switch (c)
870 CASE_DIGITS:
871 push_char (c);
872 break;
874 case '.':
875 if (seen_dp)
876 goto bad;
878 seen_dp = 1;
879 push_char (c);
880 break;
882 case 'e':
883 case 'E':
884 case 'd':
885 case 'D':
886 push_char ('e');
887 goto exp1;
889 case '-':
890 case '+':
891 push_char ('e');
892 push_char (c);
893 c = next_char ();
894 goto exp2;
896 CASE_SEPARATORS:
897 unget_char (c);
898 goto done;
900 default:
901 goto done;
905 exp1:
906 c = next_char ();
907 if (c != '-' && c != '+')
908 push_char ('+');
909 else
911 push_char (c);
912 c = next_char ();
915 exp2:
916 if (!isdigit (c))
917 goto bad;
918 push_char (c);
920 for (;;)
922 c = next_char ();
923 switch (c)
925 CASE_DIGITS:
926 push_char (c);
927 break;
929 CASE_SEPARATORS:
930 unget_char (c);
931 goto done;
933 default:
934 goto done;
938 done:
939 unget_char (c);
940 push_char ('\0');
942 m = convert_real (buffer, saved_string, length);
943 free_saved ();
945 return m;
947 bad:
948 free_saved ();
949 st_sprintf (message, "Bad floating point number for item %d", g.item_count);
950 generate_error (ERROR_READ_VALUE, message);
952 return 1;
956 /* Reading a complex number is straightforward because we can tell
957 what it is right away. */
959 static void
960 read_complex (int length)
962 char message[100];
963 char c;
965 if (parse_repeat ())
966 return;
968 c = next_char ();
969 switch (c)
971 case '(':
972 break;
974 CASE_SEPARATORS:
975 unget_char (c);
976 eat_separator ();
977 return;
979 default:
980 goto bad_complex;
983 eat_spaces ();
984 if (parse_real (value, length))
985 return;
987 eat_spaces ();
988 if (next_char () != ',')
989 goto bad_complex;
991 eat_spaces ();
992 if (parse_real (value + length, length))
993 return;
995 eat_spaces ();
996 if (next_char () != ')')
997 goto bad_complex;
999 c = next_char ();
1000 if (!is_separator (c))
1001 goto bad_complex;
1003 unget_char (c);
1004 eat_separator ();
1006 free_saved ();
1007 saved_type = BT_COMPLEX;
1008 return;
1010 bad_complex:
1012 if (nml_bad_return (c))
1013 return;
1015 st_sprintf (message, "Bad complex value in item %d of list input",
1016 g.item_count);
1018 generate_error (ERROR_READ_VALUE, message);
1022 /* Parse a real number with a possible repeat count. */
1024 static void
1025 read_real (int length)
1027 char c, message[100];
1028 int seen_dp;
1030 seen_dp = 0;
1032 c = next_char ();
1033 switch (c)
1035 CASE_DIGITS:
1036 push_char (c);
1037 break;
1039 case '.':
1040 push_char (c);
1041 seen_dp = 1;
1042 break;
1044 case '+':
1045 case '-':
1046 goto got_sign;
1048 CASE_SEPARATORS:
1049 unget_char (c); /* Single null. */
1050 eat_separator ();
1051 return;
1053 default:
1054 goto bad_real;
1057 /* Get the digit string that might be a repeat count. */
1059 for (;;)
1061 c = next_char ();
1062 switch (c)
1064 CASE_DIGITS:
1065 push_char (c);
1066 break;
1068 case '.':
1069 if (seen_dp)
1070 goto bad_real;
1072 seen_dp = 1;
1073 push_char (c);
1074 goto real_loop;
1076 case 'E':
1077 case 'e':
1078 case 'D':
1079 case 'd':
1080 goto exp1;
1082 case '+':
1083 case '-':
1084 push_char ('e');
1085 push_char (c);
1086 c = next_char ();
1087 goto exp2;
1089 case '*':
1090 push_char ('\0');
1091 goto got_repeat;
1093 CASE_SEPARATORS:
1094 if (c != '\n' && c != ',' && c != '\r')
1095 unget_char (c);
1096 goto done;
1098 default:
1099 goto bad_real;
1103 got_repeat:
1104 if (convert_integer (-1, 0))
1105 return;
1107 /* Now get the number itself. */
1109 c = next_char ();
1110 if (is_separator (c))
1111 { /* Repeated null value. */
1112 unget_char (c);
1113 eat_separator ();
1114 return;
1117 if (c != '-' && c != '+')
1118 push_char ('+');
1119 else
1121 got_sign:
1122 push_char (c);
1123 c = next_char ();
1126 if (!isdigit (c) && c != '.')
1127 goto bad_real;
1129 if (c == '.')
1131 if (seen_dp)
1132 goto bad_real;
1133 else
1134 seen_dp = 1;
1137 push_char (c);
1139 real_loop:
1140 for (;;)
1142 c = next_char ();
1143 switch (c)
1145 CASE_DIGITS:
1146 push_char (c);
1147 break;
1149 CASE_SEPARATORS:
1150 goto done;
1152 case '.':
1153 if (seen_dp)
1154 goto bad_real;
1156 seen_dp = 1;
1157 push_char (c);
1158 break;
1160 case 'E':
1161 case 'e':
1162 case 'D':
1163 case 'd':
1164 goto exp1;
1166 case '+':
1167 case '-':
1168 push_char ('e');
1169 push_char (c);
1170 c = next_char ();
1171 goto exp2;
1173 default:
1174 goto bad_real;
1178 exp1:
1179 push_char ('e');
1181 c = next_char ();
1182 if (c != '+' && c != '-')
1183 push_char ('+');
1184 else
1186 push_char (c);
1187 c = next_char ();
1190 exp2:
1191 if (!isdigit (c))
1192 goto bad_real;
1193 push_char (c);
1195 for (;;)
1197 c = next_char ();
1199 switch (c)
1201 CASE_DIGITS:
1202 push_char (c);
1203 break;
1205 CASE_SEPARATORS:
1206 goto done;
1208 default:
1209 goto bad_real;
1213 done:
1214 unget_char (c);
1215 eat_separator ();
1216 push_char ('\0');
1217 if (convert_real (value, saved_string, length))
1218 return;
1220 free_saved ();
1221 saved_type = BT_REAL;
1222 return;
1224 bad_real:
1226 if (nml_bad_return (c))
1227 return;
1229 st_sprintf (message, "Bad real number in item %d of list input",
1230 g.item_count);
1232 generate_error (ERROR_READ_VALUE, message);
1236 /* Check the current type against the saved type to make sure they are
1237 compatible. Returns nonzero if incompatible. */
1239 static int
1240 check_type (bt type, int len)
1242 char message[100];
1244 if (saved_type != BT_NULL && saved_type != type)
1246 st_sprintf (message, "Read type %s where %s was expected for item %d",
1247 type_name (saved_type), type_name (type), g.item_count);
1249 generate_error (ERROR_READ_VALUE, message);
1250 return 1;
1253 if (saved_type == BT_NULL || saved_type == BT_CHARACTER)
1254 return 0;
1256 if (saved_length != len)
1258 st_sprintf (message,
1259 "Read kind %d %s where kind %d is required for item %d",
1260 saved_length, type_name (saved_type), len, g.item_count);
1261 generate_error (ERROR_READ_VALUE, message);
1262 return 1;
1265 return 0;
1269 /* Top level data transfer subroutine for list reads. Because we have
1270 to deal with repeat counts, the data item is always saved after
1271 reading, usually in the value[] array. If a repeat count is
1272 greater than one, we copy the data item multiple times. */
1274 void
1275 list_formatted_read (bt type, void *p, int len)
1277 char c;
1278 int m;
1280 namelist_mode = 0;
1282 if (setjmp (g.eof_jump))
1284 generate_error (ERROR_END, NULL);
1285 return;
1288 if (g.first_item)
1290 g.first_item = 0;
1291 input_complete = 0;
1292 repeat_count = 1;
1293 at_eol = 0;
1295 c = eat_spaces ();
1296 if (is_separator (c))
1297 { /* Found a null value. */
1298 eat_separator ();
1299 repeat_count = 0;
1300 if (at_eol)
1301 finish_separator ();
1302 else
1303 return;
1307 else
1309 if (input_complete)
1310 return;
1312 if (repeat_count > 0)
1314 if (check_type (type, len))
1315 return;
1316 goto set_value;
1319 if (at_eol)
1320 finish_separator ();
1321 else
1323 eat_spaces ();
1324 /* trailing spaces prior to end of line */
1325 if (at_eol)
1326 finish_separator ();
1329 saved_type = BT_NULL;
1330 repeat_count = 1;
1333 switch (type)
1335 case BT_INTEGER:
1336 read_integer (len);
1337 break;
1338 case BT_LOGICAL:
1339 read_logical (len);
1340 break;
1341 case BT_CHARACTER:
1342 read_character (len);
1343 break;
1344 case BT_REAL:
1345 read_real (len);
1346 break;
1347 case BT_COMPLEX:
1348 read_complex (len);
1349 break;
1350 default:
1351 internal_error ("Bad type for list read");
1354 if (saved_type != BT_CHARACTER && saved_type != BT_NULL)
1355 saved_length = len;
1357 if (ioparm.library_return != LIBRARY_OK)
1358 return;
1360 set_value:
1361 switch (saved_type)
1363 case BT_COMPLEX:
1364 len = 2 * len;
1365 /* Fall through. */
1367 case BT_INTEGER:
1368 case BT_REAL:
1369 case BT_LOGICAL:
1370 memcpy (p, value, len);
1371 break;
1373 case BT_CHARACTER:
1374 if (saved_string)
1376 m = (len < saved_used) ? len : saved_used;
1377 memcpy (p, saved_string, m);
1379 else
1380 /* Just delimiters encountered, nothing to copy but SPACE. */
1381 m = 0;
1383 if (m < len)
1384 memset (((char *) p) + m, ' ', len - m);
1385 break;
1387 case BT_NULL:
1388 break;
1391 if (--repeat_count <= 0)
1392 free_saved ();
1395 void
1396 init_at_eol(void)
1398 at_eol = 0;
1401 /* Finish a list read. */
1403 void
1404 finish_list_read (void)
1406 char c;
1408 free_saved ();
1410 if (at_eol)
1412 at_eol = 0;
1413 return;
1418 c = next_char ();
1420 while (c != '\n');
1423 /* NAMELIST INPUT
1425 void namelist_read (void)
1426 calls:
1427 static void nml_match_name (char *name, int len)
1428 static int nml_query (void)
1429 static int nml_get_obj_data (void)
1430 calls:
1431 static void nml_untouch_nodes (void)
1432 static namelist_info * find_nml_node (char * var_name)
1433 static int nml_parse_qualifier(descriptor_dimension * ad,
1434 nml_loop_spec * ls, int rank)
1435 static void nml_touch_nodes (namelist_info * nl)
1436 static int nml_read_obj (namelist_info * nl, index_type offset)
1437 calls:
1438 -itself- */
1440 /* Carries error messages from the qualifier parser. */
1441 static char parse_err_msg[30];
1443 /* Carries error messages for error returns. */
1444 static char nml_err_msg[100];
1446 /* Pointer to the previously read object, in case attempt is made to read
1447 new object name. Should this fail, error message can give previous
1448 name. */
1450 static namelist_info * prev_nl;
1452 /* Lower index for substring qualifier. */
1454 static index_type clow;
1456 /* Upper index for substring qualifier. */
1458 static index_type chigh;
1460 /* Inputs a rank-dimensional qualifier, which can contain
1461 singlets, doublets, triplets or ':' with the standard meanings. */
1463 static try
1464 nml_parse_qualifier(descriptor_dimension * ad,
1465 nml_loop_spec * ls, int rank)
1467 int dim;
1468 int indx;
1469 int neg;
1470 int null_flag;
1471 char c;
1473 /* The next character in the stream should be the '('. */
1475 c = next_char ();
1477 /* Process the qualifier, by dimension and triplet. */
1479 for (dim=0; dim < rank; dim++ )
1481 for (indx=0; indx<3; indx++)
1483 free_saved ();
1484 eat_spaces ();
1485 neg = 0;
1487 /*process a potential sign. */
1489 c = next_char ();
1490 switch (c)
1492 case '-':
1493 neg = 1;
1494 break;
1496 case '+':
1497 break;
1499 default:
1500 unget_char (c);
1501 break;
1504 /*process characters up to the next ':' , ',' or ')' */
1506 for (;;)
1508 c = next_char ();
1510 switch (c)
1512 case ':':
1513 break;
1515 case ',': case ')':
1516 if ( (c==',' && dim == rank -1)
1517 || (c==')' && dim < rank -1))
1519 st_sprintf (parse_err_msg,
1520 "Bad number of index fields");
1521 goto err_ret;
1523 break;
1525 CASE_DIGITS:
1526 push_char (c);
1527 continue;
1529 case ' ': case '\t':
1530 eat_spaces ();
1531 c = next_char ();
1532 break;
1534 default:
1535 st_sprintf (parse_err_msg, "Bad character in index");
1536 goto err_ret;
1539 if (( c==',' || c==')') && indx==0 && saved_string == 0 )
1541 st_sprintf (parse_err_msg, "Null index field");
1542 goto err_ret;
1545 if ( ( c==':' && indx==1 && saved_string == 0)
1546 || (indx==2 && saved_string == 0))
1548 st_sprintf(parse_err_msg, "Bad index triplet");
1549 goto err_ret;
1552 /* If '( : ? )' or '( ? : )' break and flag read failure. */
1553 null_flag = 0;
1554 if ( (c==':' && indx==0 && saved_string == 0)
1555 || (indx==1 && saved_string == 0))
1557 null_flag = 1;
1558 break;
1561 /* Now read the index. */
1563 if (convert_integer (sizeof(int),neg))
1565 st_sprintf (parse_err_msg, "Bad integer in index");
1566 goto err_ret;
1568 break;
1571 /*feed the index values to the triplet arrays. */
1573 if (!null_flag)
1575 if (indx == 0)
1576 ls[dim].start = *(int *)value;
1577 if (indx == 1)
1578 ls[dim].end = *(int *)value;
1579 if (indx == 2)
1580 ls[dim].step = *(int *)value;
1583 /*singlet or doublet indices */
1585 if (c==',' || c==')')
1587 if (indx == 0)
1589 ls[dim].start = *(int *)value;
1590 ls[dim].end = *(int *)value;
1592 break;
1596 /*Check the values of the triplet indices. */
1598 if ( (ls[dim].start > (ssize_t)ad[dim].ubound)
1599 || (ls[dim].start < (ssize_t)ad[dim].lbound)
1600 || (ls[dim].end > (ssize_t)ad[dim].ubound)
1601 || (ls[dim].end < (ssize_t)ad[dim].lbound))
1603 st_sprintf (parse_err_msg, "Index %d out of range", dim + 1);
1604 goto err_ret;
1606 if (((ls[dim].end - ls[dim].start ) * ls[dim].step < 0)
1607 || (ls[dim].step == 0))
1609 st_sprintf (parse_err_msg, "Bad range in index %d", dim + 1);
1610 goto err_ret;
1613 /* Initialise the loop index counter. */
1615 ls[dim].idx = ls[dim].start;
1618 eat_spaces ();
1619 return SUCCESS;
1621 err_ret:
1623 return FAILURE;
1626 static namelist_info *
1627 find_nml_node (char * var_name)
1629 namelist_info * t = ionml;
1630 while (t != NULL)
1632 if (strcmp (var_name,t->var_name) == 0)
1634 t->touched = 1;
1635 return t;
1637 t = t->next;
1639 return NULL;
1642 /* Visits all the components of a derived type that have
1643 not explicitly been identified in the namelist input.
1644 touched is set and the loop specification initialised
1645 to default values */
1647 static void
1648 nml_touch_nodes (namelist_info * nl)
1650 index_type len = strlen (nl->var_name) + 1;
1651 int dim;
1652 char * ext_name = (char*)get_mem (len + 1);
1653 strcpy (ext_name, nl->var_name);
1654 strcat (ext_name, "%");
1655 for (nl = nl->next; nl; nl = nl->next)
1657 if (strncmp (nl->var_name, ext_name, len) == 0)
1659 nl->touched = 1;
1660 for (dim=0; dim < nl->var_rank; dim++)
1662 nl->ls[dim].step = 1;
1663 nl->ls[dim].end = nl->dim[dim].ubound;
1664 nl->ls[dim].start = nl->dim[dim].lbound;
1665 nl->ls[dim].idx = nl->ls[dim].start;
1668 else
1669 break;
1671 free_mem (ext_name);
1672 return;
1675 /* Resets touched for the entire list of nml_nodes, ready for a
1676 new object. */
1678 static void
1679 nml_untouch_nodes (void)
1681 namelist_info * t;
1682 for (t = ionml; t; t = t->next)
1683 t->touched = 0;
1684 return;
1687 /* Attempts to input name to namelist name. Returns nml_read_error = 1
1688 on no match. */
1690 static void
1691 nml_match_name (const char *name, index_type len)
1693 index_type i;
1694 char c;
1695 nml_read_error = 0;
1696 for (i = 0; i < len; i++)
1698 c = next_char ();
1699 if (tolower (c) != tolower (name[i]))
1701 nml_read_error = 1;
1702 break;
1707 /* If the namelist read is from stdin, output the current state of the
1708 namelist to stdout. This is used to implement the non-standard query
1709 features, ? and =?. If c == '=' the full namelist is printed. Otherwise
1710 the names alone are printed. */
1712 static void
1713 nml_query (char c)
1715 gfc_unit * temp_unit;
1716 namelist_info * nl;
1717 index_type len;
1718 char * p;
1720 if (current_unit->unit_number != options.stdin_unit)
1721 return;
1723 /* Store the current unit and transfer to stdout. */
1725 temp_unit = current_unit;
1726 current_unit = find_unit (options.stdout_unit);
1728 if (current_unit)
1730 g.mode =WRITING;
1731 next_record (0);
1733 /* Write the namelist in its entirety. */
1735 if (c == '=')
1736 namelist_write ();
1738 /* Or write the list of names. */
1740 else
1743 /* "&namelist_name\n" */
1745 len = ioparm.namelist_name_len;
1746 p = write_block (len + 2);
1747 if (!p)
1748 goto query_return;
1749 memcpy (p, "&", 1);
1750 memcpy ((char*)(p + 1), ioparm.namelist_name, len);
1751 memcpy ((char*)(p + len + 1), "\n", 1);
1752 for (nl =ionml; nl; nl = nl->next)
1755 /* " var_name\n" */
1757 len = strlen (nl->var_name);
1758 p = write_block (len + 2);
1759 if (!p)
1760 goto query_return;
1761 memcpy (p, " ", 1);
1762 memcpy ((char*)(p + 1), nl->var_name, len);
1763 memcpy ((char*)(p + len + 1), "\n", 1);
1766 /* "&end\n" */
1768 p = write_block (5);
1769 if (!p)
1770 goto query_return;
1771 memcpy (p, "&end\n", 5);
1774 /* Flush the stream to force immediate output. */
1776 flush (current_unit->s);
1779 query_return:
1781 /* Restore the current unit. */
1783 current_unit = temp_unit;
1784 g.mode = READING;
1785 return;
1788 /* Reads and stores the input for the namelist object nl. For an array,
1789 the function loops over the ranges defined by the loop specification.
1790 This default to all the data or to the specification from a qualifier.
1791 nml_read_obj recursively calls itself to read derived types. It visits
1792 all its own components but only reads data for those that were touched
1793 when the name was parsed. If a read error is encountered, an attempt is
1794 made to return to read a new object name because the standard allows too
1795 little data to be available. On the other hand, too much data is an
1796 error. */
1798 static try
1799 nml_read_obj (namelist_info * nl, index_type offset)
1802 namelist_info * cmp;
1803 char * obj_name;
1804 int nml_carry;
1805 int len;
1806 int dim;
1807 index_type dlen;
1808 index_type m;
1809 index_type obj_name_len;
1810 void * pdata ;
1812 /* This object not touched in name parsing. */
1814 if (!nl->touched)
1815 return SUCCESS;
1817 repeat_count = 0;
1818 eat_spaces();
1820 len = nl->len;
1821 switch (nl->type)
1824 case GFC_DTYPE_INTEGER:
1825 case GFC_DTYPE_LOGICAL:
1826 case GFC_DTYPE_REAL:
1827 dlen = len;
1828 break;
1830 case GFC_DTYPE_COMPLEX:
1831 dlen = 2* len;
1832 break;
1834 case GFC_DTYPE_CHARACTER:
1835 dlen = chigh ? (chigh - clow + 1) : nl->string_length;
1836 break;
1838 default:
1839 dlen = 0;
1845 /* Update the pointer to the data, using the current index vector */
1847 pdata = (void*)(nl->mem_pos + offset);
1848 for (dim = 0; dim < nl->var_rank; dim++)
1849 pdata = (void*)(pdata + (nl->ls[dim].idx - nl->dim[dim].lbound) *
1850 nl->dim[dim].stride * nl->size);
1852 /* Reset the error flag and try to read next value, if
1853 repeat_count=0 */
1855 nml_read_error = 0;
1856 nml_carry = 0;
1857 if (--repeat_count <= 0)
1859 if (input_complete)
1860 return SUCCESS;
1861 if (at_eol)
1862 finish_separator ();
1863 if (input_complete)
1864 return SUCCESS;
1866 /* GFC_TYPE_UNKNOWN through for nulls and is detected
1867 after the switch block. */
1869 saved_type = GFC_DTYPE_UNKNOWN;
1870 free_saved ();
1872 switch (nl->type)
1874 case GFC_DTYPE_INTEGER:
1875 read_integer (len);
1876 break;
1878 case GFC_DTYPE_LOGICAL:
1879 read_logical (len);
1880 break;
1882 case GFC_DTYPE_CHARACTER:
1883 read_character (len);
1884 break;
1886 case GFC_DTYPE_REAL:
1887 read_real (len);
1888 break;
1890 case GFC_DTYPE_COMPLEX:
1891 read_complex (len);
1892 break;
1894 case GFC_DTYPE_DERIVED:
1895 obj_name_len = strlen (nl->var_name) + 1;
1896 obj_name = get_mem (obj_name_len+1);
1897 strcpy (obj_name, nl->var_name);
1898 strcat (obj_name, "%");
1900 /* Now loop over the components. Update the component pointer
1901 with the return value from nml_write_obj. This loop jumps
1902 past nested derived types by testing if the potential
1903 component name contains '%'. */
1905 for (cmp = nl->next;
1906 cmp &&
1907 !strncmp (cmp->var_name, obj_name, obj_name_len) &&
1908 !strchr (cmp->var_name + obj_name_len, '%');
1909 cmp = cmp->next)
1912 if (nml_read_obj (cmp, (index_type)(pdata - nl->mem_pos)) == FAILURE)
1914 free_mem (obj_name);
1915 return FAILURE;
1918 if (input_complete)
1920 free_mem (obj_name);
1921 return SUCCESS;
1925 free_mem (obj_name);
1926 goto incr_idx;
1928 default:
1929 st_sprintf (nml_err_msg, "Bad type for namelist object %s",
1930 nl->var_name );
1931 internal_error (nml_err_msg);
1932 goto nml_err_ret;
1936 /* The standard permits array data to stop short of the number of
1937 elements specified in the loop specification. In this case, we
1938 should be here with nml_read_error != 0. Control returns to
1939 nml_get_obj_data and an attempt is made to read object name. */
1941 prev_nl = nl;
1942 if (nml_read_error)
1943 return SUCCESS;
1945 if (saved_type == GFC_DTYPE_UNKNOWN)
1946 goto incr_idx;
1949 /* Note the switch from GFC_DTYPE_type to BT_type at this point.
1950 This comes about because the read functions return BT_types. */
1952 switch (saved_type)
1955 case BT_COMPLEX:
1956 case BT_REAL:
1957 case BT_INTEGER:
1958 case BT_LOGICAL:
1959 memcpy (pdata, value, dlen);
1960 break;
1962 case BT_CHARACTER:
1963 m = (dlen < saved_used) ? dlen : saved_used;
1964 pdata = (void*)( pdata + clow - 1 );
1965 memcpy (pdata, saved_string, m);
1966 if (m < dlen)
1967 memset ((void*)( pdata + m ), ' ', dlen - m);
1968 break;
1970 default:
1971 break;
1974 /* Break out of loop if scalar. */
1976 if (!nl->var_rank)
1977 break;
1979 /* Now increment the index vector. */
1981 incr_idx:
1983 nml_carry = 1;
1984 for (dim = 0; dim < nl->var_rank; dim++)
1986 nl->ls[dim].idx += nml_carry * nl->ls[dim].step;
1987 nml_carry = 0;
1988 if (((nl->ls[dim].step > 0) && (nl->ls[dim].idx > nl->ls[dim].end))
1990 ((nl->ls[dim].step < 0) && (nl->ls[dim].idx < nl->ls[dim].end)))
1992 nl->ls[dim].idx = nl->ls[dim].start;
1993 nml_carry = 1;
1996 } while (!nml_carry);
1998 if (repeat_count > 1)
2000 st_sprintf (nml_err_msg, "Repeat count too large for namelist object %s" ,
2001 nl->var_name );
2002 goto nml_err_ret;
2004 return SUCCESS;
2006 nml_err_ret:
2008 return FAILURE;
2011 /* Parses the object name, including array and substring qualifiers. It
2012 iterates over derived type components, touching those components and
2013 setting their loop specifications, if there is a qualifier. If the
2014 object is itself a derived type, its components and subcomponents are
2015 touched. nml_read_obj is called at the end and this reads the data in
2016 the manner specified by the object name. */
2018 static try
2019 nml_get_obj_data (void)
2021 char c;
2022 char * ext_name;
2023 namelist_info * nl;
2024 namelist_info * first_nl = NULL;
2025 namelist_info * root_nl = NULL;
2026 int dim;
2027 int component_flag;
2029 /* Look for end of input or object name. If '?' or '=?' are encountered
2030 in stdin, print the node names or the namelist to stdout. */
2032 eat_separator ();
2033 if (input_complete)
2034 return SUCCESS;
2036 if ( at_eol )
2037 finish_separator ();
2038 if (input_complete)
2039 return SUCCESS;
2041 c = next_char ();
2042 switch (c)
2044 case '=':
2045 c = next_char ();
2046 if (c != '?')
2048 st_sprintf (nml_err_msg, "namelist read: missplaced = sign");
2049 goto nml_err_ret;
2051 nml_query ('=');
2052 return SUCCESS;
2054 case '?':
2055 nml_query ('?');
2056 return SUCCESS;
2058 case '$':
2059 case '&':
2060 nml_match_name ("end", 3);
2061 if (nml_read_error)
2063 st_sprintf (nml_err_msg, "namelist not terminated with / or &end");
2064 goto nml_err_ret;
2066 case '/':
2067 input_complete = 1;
2068 return SUCCESS;
2070 default :
2071 break;
2074 /* Untouch all nodes of the namelist and reset the flag that is set for
2075 derived type components. */
2077 nml_untouch_nodes();
2078 component_flag = 0;
2080 /* Get the object name - should '!' and '\n' be permitted separators? */
2082 get_name:
2084 free_saved ();
2088 push_char(tolower(c));
2089 c = next_char ();
2090 } while (!( c=='=' || c==' ' || c=='\t' || c =='(' || c =='%' ));
2092 unget_char (c);
2094 /* Check that the name is in the namelist and get pointer to object.
2095 Three error conditions exist: (i) An attempt is being made to
2096 identify a non-existent object, following a failed data read or
2097 (ii) The object name does not exist or (iii) Too many data items
2098 are present for an object. (iii) gives the same error message
2099 as (i) */
2101 push_char ('\0');
2103 if (component_flag)
2105 ext_name = (char*)get_mem (strlen (root_nl->var_name)
2106 + (saved_string ? strlen (saved_string) : 0)
2107 + 1);
2108 strcpy (ext_name, root_nl->var_name);
2109 strcat (ext_name, saved_string);
2110 nl = find_nml_node (ext_name);
2111 free_mem (ext_name);
2113 else
2114 nl = find_nml_node (saved_string);
2116 if (nl == NULL)
2118 if (nml_read_error && prev_nl)
2119 st_sprintf (nml_err_msg, "Bad data for namelist object %s",
2120 prev_nl->var_name);
2122 else
2123 st_sprintf (nml_err_msg, "Cannot match namelist object name %s",
2124 saved_string);
2126 goto nml_err_ret;
2129 /* Get the length, data length, base pointer and rank of the variable.
2130 Set the default loop specification first. */
2132 for (dim=0; dim < nl->var_rank; dim++)
2134 nl->ls[dim].step = 1;
2135 nl->ls[dim].end = nl->dim[dim].ubound;
2136 nl->ls[dim].start = nl->dim[dim].lbound;
2137 nl->ls[dim].idx = nl->ls[dim].start;
2140 /* Check to see if there is a qualifier: if so, parse it.*/
2142 if (c == '(' && nl->var_rank)
2144 if (nml_parse_qualifier (nl->dim, nl->ls, nl->var_rank) == FAILURE)
2146 st_sprintf (nml_err_msg, "%s for namelist variable %s",
2147 parse_err_msg, nl->var_name);
2148 goto nml_err_ret;
2150 c = next_char ();
2151 unget_char (c);
2154 /* Now parse a derived type component. The root namelist_info address
2155 is backed up, as is the previous component level. The component flag
2156 is set and the iteration is made by jumping back to get_name. */
2158 if (c == '%')
2161 if (nl->type != GFC_DTYPE_DERIVED)
2163 st_sprintf (nml_err_msg, "Attempt to get derived component for %s",
2164 nl->var_name);
2165 goto nml_err_ret;
2168 if (!component_flag)
2169 first_nl = nl;
2171 root_nl = nl;
2172 component_flag = 1;
2173 c = next_char ();
2174 goto get_name;
2178 /* Parse a character qualifier, if present. chigh = 0 is a default
2179 that signals that the string length = string_length. */
2181 clow = 1;
2182 chigh = 0;
2184 if (c == '(' && nl->type == GFC_DTYPE_CHARACTER)
2186 descriptor_dimension chd[1] = { {1, clow, nl->string_length} };
2187 nml_loop_spec ind[1] = { {1, clow, nl->string_length, 1} };
2189 if (nml_parse_qualifier (chd, ind, 1) == FAILURE)
2191 st_sprintf (nml_err_msg, "%s for namelist variable %s",
2192 parse_err_msg, nl->var_name);
2193 goto nml_err_ret;
2196 clow = ind[0].start;
2197 chigh = ind[0].end;
2199 if (ind[0].step != 1)
2201 st_sprintf (nml_err_msg,
2202 "Bad step in substring for namelist object %s",
2203 nl->var_name);
2204 goto nml_err_ret;
2207 c = next_char ();
2208 unget_char (c);
2211 /* If a derived type touch its components and restore the root
2212 namelist_info if we have parsed a qualified derived type
2213 component. */
2215 if (nl->type == GFC_DTYPE_DERIVED)
2216 nml_touch_nodes (nl);
2217 if (component_flag)
2218 nl = first_nl;
2220 /*make sure no extraneous qualifiers are there.*/
2222 if (c == '(')
2224 st_sprintf (nml_err_msg, "Qualifier for a scalar or non-character"
2225 " namelist object %s", nl->var_name);
2226 goto nml_err_ret;
2229 /* According to the standard, an equal sign MUST follow an object name. The
2230 following is possibly lax - it allows comments, blank lines and so on to
2231 intervene. eat_spaces (); c = next_char (); would be compliant*/
2233 free_saved ();
2235 eat_separator ();
2236 if (input_complete)
2237 return SUCCESS;
2239 if (at_eol)
2240 finish_separator ();
2241 if (input_complete)
2242 return SUCCESS;
2244 c = next_char ();
2246 if (c != '=')
2248 st_sprintf (nml_err_msg, "Equal sign must follow namelist object name %s",
2249 nl->var_name);
2250 goto nml_err_ret;
2253 if (nml_read_obj (nl, 0) == FAILURE)
2254 goto nml_err_ret;
2256 return SUCCESS;
2258 nml_err_ret:
2260 return FAILURE;
2263 /* Entry point for namelist input. Goes through input until namelist name
2264 is matched. Then cycles through nml_get_obj_data until the input is
2265 completed or there is an error. */
2267 void
2268 namelist_read (void)
2270 char c;
2272 namelist_mode = 1;
2273 input_complete = 0;
2275 if (setjmp (g.eof_jump))
2277 generate_error (ERROR_END, NULL);
2278 return;
2281 /* Look for &namelist_name . Skip all characters, testing for $nmlname.
2282 Exit on success or EOF. If '?' or '=?' encountered in stdin, print
2283 node names or namelist on stdout. */
2285 find_nml_name:
2286 switch (c = next_char ())
2288 case '$':
2289 case '&':
2290 break;
2292 case '=':
2293 c = next_char ();
2294 if (c == '?')
2295 nml_query ('=');
2296 else
2297 unget_char (c);
2298 goto find_nml_name;
2300 case '?':
2301 nml_query ('?');
2303 default:
2304 goto find_nml_name;
2307 /* Match the name of the namelist. */
2309 nml_match_name (ioparm.namelist_name, ioparm.namelist_name_len);
2311 if (nml_read_error)
2312 goto find_nml_name;
2314 /* Ready to read namelist objects. If there is an error in input
2315 from stdin, output the error message and continue. */
2317 while (!input_complete)
2319 if (nml_get_obj_data () == FAILURE)
2321 if (current_unit->unit_number != options.stdin_unit)
2322 goto nml_err_ret;
2324 st_printf ("%s\n", nml_err_msg);
2325 flush (find_unit (options.stderr_unit)->s);
2330 return;
2332 /* All namelist error calls return from here */
2334 nml_err_ret:
2336 generate_error (ERROR_READ_VALUE , nml_err_msg);
2337 return;