projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Fully implement arbitrary delimiters on DATA LIST, extending the half
[pspp]
/
src
/
file-type.c
diff --git
a/src/file-type.c
b/src/file-type.c
index ea0bb332d679040e1031ff84ebf2fd4ee1ddf86b..2b11a4abd21ce4deb551a893ad6d2e1a6c7efb41 100644
(file)
--- a/
src/file-type.c
+++ b/
src/file-type.c
@@
-18,7
+18,7
@@
02111-1307, USA. */
#include <config.h>
02111-1307, USA. */
#include <config.h>
-#include
<assert.h>
+#include
"error.h"
#include <stdlib.h>
#include "alloc.h"
#include "command.h"
#include <stdlib.h>
#include "alloc.h"
#include "command.h"
@@
-86,6
+86,7
@@
struct file_type_pgm
DATA LIST. */
struct record_type *recs_head; /* List of record types. */
struct record_type *recs_tail; /* Last in list of record types. */
DATA LIST. */
struct record_type *recs_head; /* List of record types. */
struct record_type *recs_tail; /* Last in list of record types. */
+ size_t case_size; /* Case size in bytes. */
};
static int parse_col_spec (struct col_spec *, const char *);
};
static int parse_col_spec (struct col_spec *, const char *);
@@
-108,7
+109,6
@@
cmd_file_type (void)
fty->had_rec_type = 0;
fty->recs_head = fty->recs_tail = NULL;
fty->had_rec_type = 0;
fty->recs_head = fty->recs_tail = NULL;
- lex_match_id ("TYPE");
if (lex_match_id ("MIXED"))
fty->type = FTY_MIXED;
else if (lex_match_id ("GROUPED"))
if (lex_match_id ("MIXED"))
fty->type = FTY_MIXED;
else if (lex_match_id ("GROUPED"))
@@
-269,12
+269,14
@@
cmd_file_type (void)
}
}
}
}
+ if (!dfm_open_for_reading (fty->handle))
+ goto error;
default_handle = fty->handle;
default_handle = fty->handle;
- vfm_source = create_case_source (&file_type_source_class, fty);
create_col_var (&fty->record);
if (fty->case_sbc.name[0])
create_col_var (&fty->case_sbc);
create_col_var (&fty->record);
if (fty->case_sbc.name[0])
create_col_var (&fty->case_sbc);
+ vfm_source = create_case_source (&file_type_source_class, default_dict, fty);
return CMD_SUCCESS;
return CMD_SUCCESS;
@@
-422,9
+424,6
@@
cmd_record_type (void)
}
}
}
}
- lex_match_id ("RECORD");
- lex_match_id ("TYPE");
-
/* Parse record type values. */
if (lex_match_id ("OTHER"))
rct->flags |= RCT_OTHER;
/* Parse record type values. */
if (lex_match_id ("OTHER"))
rct->flags |= RCT_OTHER;
@@
-445,7
+444,7
@@
cmd_record_type (void)
if (!lex_force_string ())
goto error;
rct->v[rct->nv].c = xmalloc (fty->record.nc + 1);
if (!lex_force_string ())
goto error;
rct->v[rct->nv].c = xmalloc (fty->record.nc + 1);
- st_bare_pad_copy (rct->v[rct->nv].c, ds_
value
(&tokstr),
+ st_bare_pad_copy (rct->v[rct->nv].c, ds_
c_str
(&tokstr),
fty->record.nc + 1);
}
else
fty->record.nc + 1);
}
else
@@
-579,8
+578,7
@@
cmd_end_file_type (void)
return CMD_FAILURE;
}
fty = vfm_source->aux;
return CMD_FAILURE;
}
fty = vfm_source->aux;
-
- lex_match_id ("TYPE");
+ fty->case_size = dict_get_case_size (default_dict);
if (fty->recs_tail)
{
if (fty->recs_tail)
{
@@
-616,17
+614,15
@@
cmd_end_file_type (void)
static void read_from_file_type_grouped(void);
static void read_from_file_type_nested(void); */
static void read_from_file_type_grouped(void);
static void read_from_file_type_nested(void); */
-/* Reads any number of cases into
temp_case and calls write_case() for
- each one. Compare data-list.c:read_from_data_list. */
+/* Reads any number of cases into
case C and calls write_case()
+
for
each one. Compare data-list.c:read_from_data_list. */
static void
file_type_source_read (struct case_source *source,
static void
file_type_source_read (struct case_source *source,
+ struct ccase *c,
write_case_func *write_case UNUSED,
write_case_data wc_data UNUSED)
{
struct file_type_pgm *fty = source->aux;
write_case_func *write_case UNUSED,
write_case_data wc_data UNUSED)
{
struct file_type_pgm *fty = source->aux;
- char *line;
- int len;
-
struct fmt_spec format;
dfm_push (fty->handle);
struct fmt_spec format;
dfm_push (fty->handle);
@@
-634,19
+630,22
@@
file_type_source_read (struct case_source *source,
format.type = fty->record.fmt;
format.w = fty->record.nc;
format.d = 0;
format.type = fty->record.fmt;
format.w = fty->record.nc;
format.d = 0;
- while (
NULL != (line = dfm_get_record (fty->handle, &len)
))
+ while (
!dfm_eof (fty->handle
))
{
{
+ struct len_string line;
struct record_type *iter;
union value v;
int i;
struct record_type *iter;
union value v;
int i;
+ dfm_expand_tabs (fty->handle);
+ dfm_get_record (fty->handle, &line);
if (formats[fty->record.fmt].cat & FCAT_STRING)
{
struct data_in di;
if (formats[fty->record.fmt].cat & FCAT_STRING)
{
struct data_in di;
- v.c =
temp_case
->data[fty->record.v->fv].s;
+ v.c =
c
->data[fty->record.v->fv].s;
- data_in_finite_line (&di, l
ine, len
,
+ data_in_finite_line (&di, l
s_c_str (&line), ls_length (&line)
,
fty->record.fc, fty->record.fc + fty->record.nc);
di.v = (union value *) v.c;
di.flags = 0;
fty->record.fc, fty->record.fc + fty->record.nc);
di.v = (union value *) v.c;
di.flags = 0;
@@
-669,7
+668,7
@@
file_type_source_read (struct case_source *source,
{
struct data_in di;
{
struct data_in di;
- data_in_finite_line (&di, l
ine, len
,
+ data_in_finite_line (&di, l
s_c_str (&line), ls_length (&line)
,
fty->record.fc, fty->record.fc + fty->record.nc);
di.v = &v;
di.flags = 0;
fty->record.fc, fty->record.fc + fty->record.nc);
di.v = &v;
di.flags = 0;
@@
-677,7
+676,7
@@
file_type_source_read (struct case_source *source,
di.format = format;
data_in (&di);
di.format = format;
data_in (&di);
- memcpy (&
temp_case
->data[fty->record.v->fv].f, &v.f, sizeof v.f);
+ memcpy (&
c
->data[fty->record.v->fv].f, &v.f, sizeof v.f);
for (iter = fty->recs_head; iter; iter = iter->next)
{
if (iter->flags & RCT_OTHER)
for (iter = fty->recs_head; iter; iter = iter->next)
{
if (iter->flags & RCT_OTHER)
@@
-689,13
+688,13
@@
file_type_source_read (struct case_source *source,
if (fty->wild)
msg (SW, _("Unknown record type %g."), v.f);
}
if (fty->wild)
msg (SW, _("Unknown record type %g."), v.f);
}
- dfm_f
w
d_record (fty->handle);
+ dfm_f
orwar
d_record (fty->handle);
continue;
found:
/* Arrive here if there is a matching record_type, which is in
iter. */
continue;
found:
/* Arrive here if there is a matching record_type, which is in
iter. */
- dfm_f
w
d_record (fty->handle);
+ dfm_f
orwar
d_record (fty->handle);
}
/* switch(fty->type)
}
/* switch(fty->type)