}
-static char
+static int
next_char (st_parameter_dt *dtp)
{
ssize_t length;
gfc_offset record;
- char c;
- int cc;
+ int c;
- if (dtp->u.p.last_char != '\0')
+ if (dtp->u.p.last_char != EOF - 1)
{
dtp->u.p.at_eol = 0;
c = dtp->u.p.last_char;
- dtp->u.p.last_char = '\0';
+ dtp->u.p.last_char = EOF - 1;
goto done;
}
if (is_array_io (dtp))
{
if (dtp->u.p.at_eof)
- longjmp (*dtp->u.p.eof_jump, 1);
+ return EOF;
/* Check for "end-of-record" condition. */
if (dtp->u.p.current_unit->bytes_left == 0)
record *= dtp->u.p.current_unit->recl;
if (sseek (dtp->u.p.current_unit->s, record, SEEK_SET) < 0)
- longjmp (*dtp->u.p.eof_jump, 1);
+ return EOF;
dtp->u.p.current_unit->bytes_left = dtp->u.p.current_unit->recl;
goto done;
if (is_internal_unit (dtp))
{
- length = sread (dtp->u.p.current_unit->s, &c, 1);
+ char cc;
+ length = sread (dtp->u.p.current_unit->s, &cc, 1);
+ c = cc;
if (length < 0)
{
generate_error (&dtp->common, LIBERROR_OS, NULL);
else
{
if (dtp->u.p.at_eof)
- longjmp (*dtp->u.p.eof_jump, 1);
+ return EOF;
if (length == 0)
{
c = '\n';
}
else
{
- cc = fbuf_getc (dtp->u.p.current_unit);
-
- if (cc == EOF)
- {
- if (dtp->u.p.current_unit->endfile == AT_ENDFILE)
- longjmp (*dtp->u.p.eof_jump, 1);
- dtp->u.p.current_unit->endfile = AT_ENDFILE;
- c = '\n';
- }
- else
- c = (char) cc;
- if (is_stream_io (dtp) && cc != EOF)
+ c = fbuf_getc (dtp->u.p.current_unit);
+ if (c != EOF && is_stream_io (dtp))
dtp->u.p.current_unit->strm_pos++;
-
}
done:
- dtp->u.p.at_eol = (c == '\n' || c == '\r');
+ dtp->u.p.at_eol = (c == '\n' || c == '\r' || c == EOF);
return c;
}
/* Push a character back onto the input. */
static void
-unget_char (st_parameter_dt *dtp, char c)
+unget_char (st_parameter_dt *dtp, int c)
{
dtp->u.p.last_char = c;
}
/* Skip over spaces in the input. Returns the nonspace character that
terminated the eating and also places it back on the input. */
-static char
+static int
eat_spaces (st_parameter_dt *dtp)
{
- char c;
+ int c;
do
- {
- c = next_char (dtp);
- }
- while (c == ' ' || c == '\t');
+ c = next_char (dtp);
+ while (c != EOF && (c == ' ' || c == '\t'));
unget_char (dtp, c);
return c;
}
-/* This function reads characters through to the end of the current line and
- just ignores them. */
+/* This function reads characters through to the end of the current
+ line and just ignores them. Returns 0 for success and LIBERROR_END
+ if it hit EOF. */
-static void
+static int
eat_line (st_parameter_dt *dtp)
{
- char c;
+ int c;
do
c = next_char (dtp);
- while (c != '\n');
+ while (c != EOF && c != '\n');
+ if (c == EOF)
+ return LIBERROR_END;
+ return 0;
}
separator, we stop reading. If there are more input items, we
continue reading the separator with finish_separator() which takes
care of the fact that we may or may not have seen a comma as part
- of the separator. */
+ of the separator.
-static void
+ Returns 0 for success, and non-zero error code otherwise. */
+
+static int
eat_separator (st_parameter_dt *dtp)
{
- char c, n;
+ int c, n;
+ int err = 0;
eat_spaces (dtp);
dtp->u.p.comma_flag = 0;
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return LIBERROR_END;
switch (c)
{
case ',':
case '\r':
dtp->u.p.at_eol = 1;
- n = next_char(dtp);
+ if ((n = next_char(dtp)) == EOF)
+ return LIBERROR_END;
if (n != '\n')
{
unget_char (dtp, n);
{
do
{
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return LIBERROR_END;
if (c == '!')
{
- eat_line (dtp);
- c = next_char (dtp);
+ err = eat_line (dtp);
+ if (err)
+ return err;
+ if ((c = next_char (dtp)) == EOF)
+ return LIBERROR_END;
if (c == '!')
{
- eat_line (dtp);
- c = next_char (dtp);
+ err = eat_line (dtp);
+ if (err)
+ return err;
+ if ((c = next_char (dtp)) == EOF)
+ return LIBERROR_END;
}
}
}
case '!':
if (dtp->u.p.namelist_mode)
{ /* Eat a namelist comment. */
- do
- c = next_char (dtp);
- while (c != '\n');
+ err = eat_line (dtp);
+ if (err)
+ return err;
break;
}
unget_char (dtp, c);
break;
}
+ return err;
}
/* Finish processing a separator that was interrupted by a newline.
If we're here, then another data item is present, so we finish what
- we started on the previous line. */
+ we started on the previous line. Return 0 on success, error code
+ on failure. */
-static void
+static int
finish_separator (st_parameter_dt *dtp)
{
- char c;
+ int c;
+ int err;
restart:
eat_spaces (dtp);
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return LIBERROR_END;
switch (c)
{
case ',':
unget_char (dtp, c);
else
{
- c = eat_spaces (dtp);
+ if ((c = eat_spaces (dtp)) == EOF)
+ return LIBERROR_END;
if (c == '\n' || c == '\r')
goto restart;
}
case '/':
dtp->u.p.input_complete = 1;
if (!dtp->u.p.namelist_mode)
- return;
+ return err;
break;
case '\n':
case '!':
if (dtp->u.p.namelist_mode)
{
- do
- c = next_char (dtp);
- while (c != '\n');
-
+ err = eat_line (dtp);
+ if (err)
+ return err;
goto restart;
}
unget_char (dtp, c);
break;
}
+ return err;
}
static int
parse_repeat (st_parameter_dt *dtp)
{
- char c, message[100];
- int repeat;
+ char message[100];
+ int c, repeat;
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad_repeat;
switch (c)
{
CASE_DIGITS:
bad_repeat:
- eat_line (dtp);
free_saved (dtp);
+ if (c == EOF)
+ {
+ hit_eof (dtp);
+ return 1;
+ }
+ else
+ eat_line (dtp);
sprintf (message, "Bad repeat count in item %d of list input",
dtp->u.p.item_count);
generate_error (&dtp->common, LIBERROR_READ_VALUE, message);
static void
read_logical (st_parameter_dt *dtp, int length)
{
- char c, message[100];
- int i, v;
+ char message[100];
+ int c, i, v;
if (parse_repeat (dtp))
return;
{
case 't':
v = 1;
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad_logical;
l_push_char (dtp, c);
if (!is_separator(c))
break;
case 'f':
v = 0;
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad_logical;
l_push_char (dtp, c);
if (!is_separator(c))
/* Eat trailing garbage. */
do
- {
- c = next_char (dtp);
- }
- while (!is_separator (c));
+ c = next_char (dtp);
+ while (c != EOF && !is_separator (c));
unget_char (dtp, c);
eat_separator (dtp);
if (nml_bad_return (dtp, c))
return;
- eat_line (dtp);
free_saved (dtp);
+ if (c == EOF)
+ {
+ hit_eof (dtp);
+ return;
+ }
+ else
+ eat_line (dtp);
sprintf (message, "Bad logical value while reading item %d",
dtp->u.p.item_count);
generate_error (&dtp->common, LIBERROR_READ_VALUE, message);
static void
read_integer (st_parameter_dt *dtp, int length)
{
- char c, message[100];
- int negative;
+ char message[100];
+ int c, negative;
negative = 0;
/* Fall through... */
case '+':
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad_integer;
goto get_integer;
CASE_SEPARATORS: /* Single null. */
/* Get the real integer. */
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad_integer;
switch (c)
{
CASE_DIGITS:
if (nml_bad_return (dtp, c))
return;
-
- eat_line (dtp);
- free_saved (dtp);
+
+ free_saved (dtp);
+ if (c == EOF)
+ {
+ hit_eof (dtp);
+ return;
+ }
+ else
+ eat_line (dtp);
sprintf (message, "Bad integer for item %d in list input",
dtp->u.p.item_count);
generate_error (&dtp->common, LIBERROR_READ_VALUE, message);
static void
read_character (st_parameter_dt *dtp, int length __attribute__ ((unused)))
{
- char c, quote, message[100];
+ char quote, message[100];
+ int c;
quote = ' '; /* Space means no quote character. */
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto eof;
switch (c)
{
CASE_DIGITS:
for (;;)
{
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto eof;
switch (c)
{
CASE_DIGITS:
/* Now get the real string. */
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto eof;
switch (c)
{
CASE_SEPARATORS:
get_string:
for (;;)
{
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto eof;
switch (c)
{
case '"':
/* See if we have a doubled quote character or the end of
the string. */
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto eof;
if (c == quote)
{
push_char (dtp, quote);
invalid. */
done:
c = next_char (dtp);
+ eof:
if (is_separator (c) || c == '!')
{
unget_char (dtp, c);
else
{
free_saved (dtp);
+ if (c == EOF)
+ {
+ hit_eof (dtp);
+ return;
+ }
sprintf (message, "Invalid string input in item %d",
dtp->u.p.item_count);
generate_error (&dtp->common, LIBERROR_READ_VALUE, message);
static int
parse_real (st_parameter_dt *dtp, void *buffer, int length)
{
- char c, message[100];
- int m, seen_dp;
+ char message[100];
+ int c, m, seen_dp;
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad;
if (c == '-' || c == '+')
{
push_char (dtp, c);
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad;
}
if (c == ',' && dtp->u.p.current_unit->decimal_status == DECIMAL_COMMA)
for (;;)
{
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad;
if (c == ',' && dtp->u.p.current_unit->decimal_status == DECIMAL_COMMA)
c = '.';
switch (c)
case '+':
push_char (dtp, 'e');
push_char (dtp, c);
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad;
goto exp2;
CASE_SEPARATORS:
}
exp1:
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad;
if (c != '-' && c != '+')
push_char (dtp, '+');
else
for (;;)
{
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad;
switch (c)
{
CASE_DIGITS:
if (nml_bad_return (dtp, c))
return 0;
- eat_line (dtp);
free_saved (dtp);
+ if (c == EOF)
+ {
+ hit_eof (dtp);
+ return 1;
+ }
+ else
+ eat_line (dtp);
sprintf (message, "Bad floating point number for item %d",
dtp->u.p.item_count);
generate_error (&dtp->common, LIBERROR_READ_VALUE, message);
read_complex (st_parameter_dt *dtp, void * dest, int kind, size_t size)
{
char message[100];
- char c;
+ int c;
if (parse_repeat (dtp))
return;
if (nml_bad_return (dtp, c))
return;
- eat_line (dtp);
free_saved (dtp);
+ if (c == EOF)
+ {
+ hit_eof (dtp);
+ return;
+ }
+ else
+ eat_line (dtp);
sprintf (message, "Bad complex value in item %d of list input",
dtp->u.p.item_count);
generate_error (&dtp->common, LIBERROR_READ_VALUE, message);
static void
read_real (st_parameter_dt *dtp, void * dest, int length)
{
- char c, message[100];
+ char message[100];
+ int c;
int seen_dp;
int is_inf;
/* Now get the number itself. */
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad_real;
if (is_separator (c))
{ /* Repeated null value. */
unget_char (dtp, c);
{
got_sign:
push_char (dtp, c);
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad_real;
}
if (c == ',' && dtp->u.p.current_unit->decimal_status == DECIMAL_COMMA)
break;
CASE_SEPARATORS:
+ case EOF:
goto done;
case '.':
exp1:
push_char (dtp, 'e');
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto bad_real;
if (c != '+' && c != '-')
push_char (dtp, '+');
else
if (c == ' ' || c =='\n' || c == '\r')
{
do
- c = next_char (dtp);
+ {
+ if ((c = next_char (dtp)) == EOF)
+ goto bad_real;
+ }
while (c == ' ' || c =='\n' || c == '\r');
l_push_char (dtp, c);
if (nml_bad_return (dtp, c))
return;
- eat_line (dtp);
free_saved (dtp);
+ if (c == EOF)
+ {
+ hit_eof (dtp);
+ return;
+ }
+ else
+ eat_line (dtp);
sprintf (message, "Bad real number in item %d of list input",
dtp->u.p.item_count);
generate_error (&dtp->common, LIBERROR_READ_VALUE, message);
reading, usually in the dtp->u.p.value[] array. If a repeat count is
greater than one, we copy the data item multiple times. */
-static void
-list_formatted_read_scalar (st_parameter_dt *dtp, volatile bt type, void *p,
+static int
+list_formatted_read_scalar (st_parameter_dt *dtp, bt type, void *p,
int kind, size_t size)
{
- char c;
gfc_char4_t *q;
- int i, m;
- jmp_buf eof_jump;
+ int c, i, m;
+ int err = 0;
dtp->u.p.namelist_mode = 0;
- dtp->u.p.eof_jump = &eof_jump;
- if (setjmp (eof_jump))
- {
- generate_error (&dtp->common, LIBERROR_END, NULL);
- if (!is_internal_unit (dtp))
- {
- dtp->u.p.current_unit->endfile = AFTER_ENDFILE;
- dtp->u.p.current_unit->current_record = 0;
- }
- goto cleanup;
- }
-
if (dtp->u.p.first_item)
{
dtp->u.p.first_item = 0;
dtp->u.p.repeat_count = 1;
dtp->u.p.at_eol = 0;
- c = eat_spaces (dtp);
+ if ((c = eat_spaces (dtp)) == EOF)
+ {
+ err = LIBERROR_END;
+ goto cleanup;
+ }
if (is_separator (c))
{
/* Found a null value. */
if (dtp->u.p.repeat_count > 0)
{
if (check_type (dtp, type, kind))
- return;
+ return err;
goto set_value;
}
free_saved (dtp);
cleanup:
- dtp->u.p.eof_jump = NULL;
+ if (err == LIBERROR_END)
+ hit_eof (dtp);
+ return err;
}
char *tmp;
size_t stride = type == BT_CHARACTER ?
size * GFC_SIZE_OF_CHAR_KIND(kind) : size;
+ int err;
tmp = (char *) p;
for (elem = 0; elem < nelems; elem++)
{
dtp->u.p.item_count++;
- list_formatted_read_scalar (dtp, type, tmp + stride*elem, kind, size);
+ err = list_formatted_read_scalar (dtp, type, tmp + stride*elem,
+ kind, size);
+ if (err)
+ break;
}
}
void
finish_list_read (st_parameter_dt *dtp)
{
- char c;
+ int err;
free_saved (dtp);
return;
}
- do
- {
- c = next_char (dtp);
- }
- while (c != '\n');
-
- if (dtp->u.p.current_unit->endfile != NO_ENDFILE)
- {
- generate_error (&dtp->common, LIBERROR_END, NULL);
- dtp->u.p.current_unit->endfile = AFTER_ENDFILE;
- dtp->u.p.current_unit->current_record = 0;
- }
+ err = eat_line (dtp);
+ if (err == LIBERROR_END)
+ hit_eof (dtp);
}
/* NAMELIST INPUT
int neg;
int null_flag;
int is_array_section, is_char;
- char c;
+ int c;
is_char = 0;
is_array_section = 0;
/* The next character in the stream should be the '('. */
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
/* Process the qualifier, by dimension and triplet. */
neg = 0;
/* Process a potential sign. */
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
switch (c)
{
case '-':
/* Process characters up to the next ':' , ',' or ')'. */
for (;;)
{
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
switch (c)
{
case ' ': case '\t':
eat_spaces (dtp);
- c = next_char (dtp);
+ if ((c = next_char (dtp) == EOF))
+ return FAILURE;
break;
default:
nml_match_name (st_parameter_dt *dtp, const char *name, index_type len)
{
index_type i;
- char c;
+ int c;
+
dtp->u.p.nml_read_error = 0;
for (i = 0; i < len; i++)
{
c = next_char (dtp);
- if (tolower (c) != tolower (name[i]))
+ if (c == EOF || (tolower (c) != tolower (name[i])))
{
dtp->u.p.nml_read_error = 1;
break;
nml_get_obj_data (st_parameter_dt *dtp, namelist_info **pprev_nl,
char *nml_err_msg, size_t nml_err_msg_size)
{
- char c;
+ int c;
namelist_info * nl;
namelist_info * first_nl = NULL;
namelist_info * root_nl = NULL;
if (dtp->u.p.input_complete)
return SUCCESS;
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
switch (c)
{
case '=':
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
if (c != '?')
{
sprintf (nml_err_msg, "namelist read: misplaced = sign");
{
if (!is_separator (c))
push_char (dtp, tolower(c));
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
} while (!( c=='=' || c==' ' || c=='\t' || c =='(' || c =='%' ));
unget_char (dtp, c);
qualifier_flag = 1;
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
unget_char (dtp, c);
}
else if (nl->var_rank > 0)
root_nl = nl;
component_flag = 1;
-
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
goto get_name;
}
goto nml_err_ret;
}
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
unget_char (dtp, c);
}
if (dtp->u.p.input_complete)
return SUCCESS;
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ return FAILURE;
if (c != '=')
{
void
namelist_read (st_parameter_dt *dtp)
{
- char c;
- jmp_buf eof_jump;
+ int c;
char nml_err_msg[200];
/* Pointer to the previously read object, in case attempt is made to read
new object name. Should this fail, error message can give previous
dtp->u.p.input_complete = 0;
dtp->u.p.expanded_read = 0;
- dtp->u.p.eof_jump = &eof_jump;
- if (setjmp (eof_jump))
- {
- dtp->u.p.eof_jump = NULL;
- generate_error (&dtp->common, LIBERROR_END, NULL);
- return;
- }
-
/* Look for &namelist_name . Skip all characters, testing for $nmlname.
Exit on success or EOF. If '?' or '=?' encountered in stdin, print
node names or namelist on stdout. */
find_nml_name:
- switch (c = next_char (dtp))
+ if ((c = next_char (dtp)) == EOF)
+ goto nml_err_eof;
+ switch (c)
{
case '$':
case '&':
break;
case '!':
- eat_line (dtp);
+ if (eat_line (dtp))
+ goto nml_err_eof;
goto find_nml_name;
case '=':
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto nml_err_eof;
if (c == '?')
nml_query (dtp, '=');
else
goto find_nml_name;
/* A trailing space is required, we give a little lattitude here, 10.9.1. */
- c = next_char (dtp);
+ if ((c = next_char (dtp)) == EOF)
+ goto nml_err_eof;
if (!is_separator(c) && c != '!')
{
unget_char (dtp, c);
}
}
- dtp->u.p.eof_jump = NULL;
free_saved (dtp);
free_line (dtp);
return;
/* All namelist error calls return from here */
+nml_err_eof:
+ hit_eof (dtp);
+
nml_err_ret:
- dtp->u.p.eof_jump = NULL;
free_saved (dtp);
free_line (dtp);
generate_error (&dtp->common, LIBERROR_READ_VALUE, nml_err_msg);