projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
totals can go first as well as last
[pspp]
/
src
/
language
/
data-io
/
data-reader.c
diff --git
a/src/language/data-io/data-reader.c
b/src/language/data-io/data-reader.c
index 1e06d287735db834a3527893bbba298fea2de282..70ff2756dfaf8449d9a91f1c80f9cec9bbf66645 100644
(file)
--- a/
src/language/data-io/data-reader.c
+++ b/
src/language/data-io/data-reader.c
@@
-67,7
+67,7
@@
struct dfm_reader
enum dfm_reader_flags flags; /* Zero or more of DFM_*. */
FILE *file; /* Associated file. */
size_t pos; /* Offset in line of current character. */
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. */
struct lexer *lexer; /* The lexer reading the file */
char *encoding; /* Current encoding. */
@@
-149,7
+149,7
@@
dfm_open_reader (struct file_handle *fh, struct lexer *lexer,
ds_init_empty (&r->line);
ds_init_empty (&r->scratch);
r->flags = DFM_ADVANCE;
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->block_left = 0;
if (fh_get_referent (fh) != FH_REF_INLINE)
{
@@
-554,14
+554,14
@@
dfm_eof (struct dfm_reader *r)
{
r->flags &= ~DFM_ADVANCE;
{
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->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."),
{
if (r->fh != fh_inline_file ())
msg (ME, _("Attempt to read beyond end-of-file on file %s."),
@@
-571,7
+571,7
@@
dfm_eof (struct dfm_reader *r)
}
}
}
}
- return r->
eof_cnt
;
+ return r->
n_eofs
;
}
/* Returns the current record in the file corresponding to
}
/* Returns the current record in the file corresponding to
@@
-581,7
+581,7
@@
struct substring
dfm_get_record (struct dfm_reader *r)
{
assert ((r->flags & DFM_ADVANCE) == 0);
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);
}
return ds_substr (&r->line, r->pos, SIZE_MAX);
}
@@
-596,7
+596,7
@@
dfm_expand_tabs (struct dfm_reader *r)
size_t ofs, new_pos, tab_width;
assert ((r->flags & DFM_ADVANCE) == 0);
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;
if (r->flags & DFM_TABS_EXPANDED)
return;
@@
-708,15
+708,27
@@
dfm_get_column (const struct dfm_reader *r, const char *p)
const char *
dfm_get_file_name (const struct dfm_reader *r)
{
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)
{
: 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. */
}
\f
/* BEGIN DATA...END DATA procedure. */