X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Ffile-type.c;h=fee9ee5abd473f20348d184a9f49a9d161b38ef4;hb=d8528fd919d1cebe194121ba267faa0f4ee48c94;hp=e5e3d81e9fde266feb938c8637abadcc4b598bb8;hpb=37597beca4a11edba50b847932fdfeca3a648fa2;p=pspp diff --git a/src/file-type.c b/src/file-type.c index e5e3d81e9f..fee9ee5abd 100644 --- a/src/file-type.c +++ b/src/file-type.c @@ -18,12 +18,14 @@ 02111-1307, USA. */ #include -#include #include #include "alloc.h" +#include "case.h" #include "command.h" #include "data-in.h" -#include "dfm.h" +#include "dfm-read.h" +#include "dictionary.h" +#include "error.h" #include "file-handle.h" #include "format.h" #include "lexer.h" @@ -74,7 +76,7 @@ struct record_type struct file_type_pgm { int type; /* One of the FTY_* constants. */ - struct file_handle *handle; /* File handle of input file. */ + struct dfm_reader *reader; /* Data file to read. */ struct col_spec record; /* RECORD subcommand. */ struct col_spec case_sbc; /* CASE subcommand. */ int wild; /* 0=NOWARN, 1=WARN. */ @@ -96,20 +98,20 @@ static void create_col_var (struct col_spec *c); int cmd_file_type (void) { - static struct file_type_pgm *fty; + static struct file_type_pgm *fty; /* FIXME: static? WTF? */ + struct file_handle *fh = NULL; /* Initialize. */ discard_variables (); fty = xmalloc (sizeof *fty); - fty->handle = inline_file; + fty->reader = NULL; fty->record.name[0] = 0; fty->case_sbc.name[0] = 0; fty->wild = fty->duplicate = fty->missing = fty->ordered = 0; 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")) @@ -133,8 +135,8 @@ cmd_file_type (void) if (lex_match_id ("FILE")) { lex_match ('='); - fty->handle = fh_parse_file_handle (); - if (!fty->handle) + fh = fh_parse (); + if (fh == NULL) goto error; } else if (lex_match_id ("RECORD")) @@ -270,7 +272,10 @@ cmd_file_type (void) } } - default_handle = fty->handle; + fty->reader = dfm_open_reader (fh); + if (fty->reader == NULL) + goto error; + default_handle = fh; create_col_var (&fty->record); if (fty->case_sbc.name[0]) @@ -423,9 +428,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; @@ -446,7 +448,7 @@ cmd_record_type (void) 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 @@ -582,8 +584,6 @@ cmd_end_file_type (void) fty = vfm_source->aux; fty->case_size = dict_get_case_size (default_dict); - lex_match_id ("TYPE"); - if (fty->recs_tail) { fty->recs_tail->lt = n_trns - 1; @@ -627,29 +627,29 @@ file_type_source_read (struct case_source *source, 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); + dfm_push (fty->reader); 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->reader)) { + struct len_string line; struct record_type *iter; union value v; int i; + dfm_expand_tabs (fty->reader); + dfm_get_record (fty->reader, &line); if (formats[fty->record.fmt].cat & FCAT_STRING) { struct data_in di; - v.c = c->data[fty->record.v->fv].s; + v.c = case_data_rw (c, fty->record.v->fv)->s; - data_in_finite_line (&di, line, len, + data_in_finite_line (&di, ls_c_str (&line), ls_length (&line), fty->record.fc, fty->record.fc + fty->record.nc); di.v = (union value *) v.c; di.flags = 0; @@ -672,7 +672,7 @@ file_type_source_read (struct case_source *source, { struct data_in di; - data_in_finite_line (&di, line, len, + data_in_finite_line (&di, ls_c_str (&line), ls_length (&line), fty->record.fc, fty->record.fc + fty->record.nc); di.v = &v; di.flags = 0; @@ -680,7 +680,7 @@ file_type_source_read (struct case_source *source, di.format = format; data_in (&di); - memcpy (&c->data[fty->record.v->fv].f, &v.f, sizeof v.f); + case_data_rw (c, fty->record.v->fv)->f = v.f; for (iter = fty->recs_head; iter; iter = iter->next) { if (iter->flags & RCT_OTHER) @@ -692,13 +692,13 @@ file_type_source_read (struct case_source *source, if (fty->wild) msg (SW, _("Unknown record type %g."), v.f); } - dfm_fwd_record (fty->handle); + dfm_forward_record (fty->reader); continue; found: /* Arrive here if there is a matching record_type, which is in iter. */ - dfm_fwd_record (fty->handle); + dfm_forward_record (fty->reader); } /* switch(fty->type) @@ -709,7 +709,7 @@ file_type_source_read (struct case_source *source, default: assert(0); } */ - dfm_pop (fty->handle); + dfm_pop (fty->reader); } static void @@ -719,6 +719,7 @@ file_type_source_destroy (struct case_source *source) struct record_type *iter, *next; cancel_transformations (); + dfm_close_reader (fty->reader); for (iter = fty->recs_head; iter; iter = next) { next = iter->next;