enum dfm_reader_flags flags; /* Zero or more of DFM_*. */
FILE *file; /* Associated file. */
size_t pos; /* Offset in line of current character. */
- unsigned eof_cnt; /* # of attempts to advance past EOF. */
+ unsigned n_eofs; /* # of attempts to advance past EOF. */
struct lexer *lexer; /* The lexer reading the file */
char *encoding; /* Current encoding. */
ds_init_empty (&r->line);
ds_init_empty (&r->scratch);
r->flags = DFM_ADVANCE;
- r->eof_cnt = 0;
+ r->n_eofs = 0;
r->block_left = 0;
if (fh_get_referent (fh) != FH_REF_INLINE)
{
{
r->flags &= ~DFM_ADVANCE;
- if (r->eof_cnt == 0 && read_record (r) )
+ if (r->n_eofs == 0 && read_record (r))
{
r->pos = 0;
return 0;
}
- r->eof_cnt++;
- if (r->eof_cnt == 2)
+ r->n_eofs++;
+ if (r->n_eofs == 2)
{
if (r->fh != fh_inline_file ())
msg (ME, _("Attempt to read beyond end-of-file on file %s."),
}
}
- return r->eof_cnt;
+ return r->n_eofs;
}
/* Returns the current record in the file corresponding to
dfm_get_record (struct dfm_reader *r)
{
assert ((r->flags & DFM_ADVANCE) == 0);
- assert (r->eof_cnt == 0);
+ assert (r->n_eofs == 0);
return ds_substr (&r->line, r->pos, SIZE_MAX);
}
size_t ofs, new_pos, tab_width;
assert ((r->flags & DFM_ADVANCE) == 0);
- assert (r->eof_cnt == 0);
+ assert (r->n_eofs == 0);
if (r->flags & DFM_TABS_EXPANDED)
return;
const char *
dfm_get_file_name (const struct dfm_reader *r)
{
- return (fh_get_referent (r->fh) == FH_REF_FILE
- ? fh_get_file_name (r->fh)
+ enum fh_referent referent = fh_get_referent (r->fh);
+ return (referent == FH_REF_FILE ? fh_get_file_name (r->fh)
+ : referent == FH_REF_INLINE ? lex_get_file_name (r->lexer)
: NULL);
}
int
dfm_get_line_number (const struct dfm_reader *r)
{
- return fh_get_referent (r->fh) == FH_REF_FILE ? r->line_number : -1;
+ switch (fh_get_referent (r->fh))
+ {
+ case FH_REF_FILE:
+ return r->line_number;
+
+ case FH_REF_INLINE:
+ return lex_ofs_start_point (r->lexer, lex_ofs (r->lexer)).line;
+
+ case FH_REF_DATASET:
+ default:
+ return -1;
+ }
}
\f
/* BEGIN DATA...END DATA procedure. */