X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata-list.c;h=f4ed8d874d7c2986e530b8dec777225a09fce73f;hb=18febf84744dc7ab4248542c2f88d91c01ef3fa1;hp=b5d72f4ed3772395654b5d616292801bb51c3c02;hpb=30ef6754efa1df7b8f3e30b63e81d739a3a50171;p=pspp-builds.git diff --git a/src/data-list.c b/src/data-list.c index b5d72f4e..f4ed8d87 100644 --- a/src/data-list.c +++ b/src/data-list.c @@ -18,6 +18,7 @@ 02111-1307, USA. */ #include +#include "data-list.h" #include #include #include @@ -162,10 +163,7 @@ cmd_data_list (void) return CMD_FAILURE; dls.end = dict_lookup_var (default_dict, tokid); if (!dls.end) - { - dls.end = dict_create_var (default_dict, tokid, 0); - assert (dls.end != NULL); - } + dls.end = dict_create_var_assert (default_dict, tokid, 0); lex_get (); } else if (token == T_ID) @@ -518,11 +516,13 @@ fixed_parse_compatible (void) { convert_fmt_ItoO (&fx.spec.input, &v->print); v->write = v->print; + if (vfm_source != &input_program_source + && vfm_source != &file_type_source) + v->init = 0; } else { - v = dict_lookup_var (default_dict, fx.name[i]); - assert (v != NULL); + v = dict_lookup_var_assert (default_dict, fx.name[i]); if (!vfm_source) { msg (SE, _("%s is a duplicate variable name."), fx.name[i]); @@ -626,6 +626,10 @@ dump_fmt_list (struct fmt_list *f) return 0; } + if (vfm_source != &input_program_source + && vfm_source != &file_type_source) + v->init = 0; + fx.spec.input = f->f; convert_fmt_ItoO (&fx.spec.input, &v->print); v->write = v->print; @@ -828,6 +832,10 @@ parse_free (void) v->print = v->write = out; + if (vfm_source != &input_program_source + && vfm_source != &file_type_source) + v->init = 0; + strcpy (spec.name, name[i]); spec.fv = v->fv; spec.width = width; @@ -967,14 +975,13 @@ cut_field (char **ret_cp, int *ret_len) static int read_from_data_list_fixed (void); static int read_from_data_list_free (void); static int read_from_data_list_list (void); -static int do_reading (int flag); /* FLAG==0: reads any number of cases into temp_case and calls write_case() for each one, returns garbage. FLAG!=0: reads one case into temp_case and returns -2 on eof, -1 otherwise. Uses dlsp as the relevant parsing description. */ static int -do_reading (int flag) +do_reading (int flag, write_case_func *write_case, write_case_data wc_data) { int (*func) (void); @@ -1030,7 +1037,7 @@ do_reading (int flag) else { while (func () != -2) - if (!write_case ()) + if (!write_case (wc_data)) { debug_printf ((_("abort in write_case()\n"))); break; @@ -1199,19 +1206,19 @@ destroy_dls (struct trns_header *pgm) /* Note that since this is exclusively an input program, C is guaranteed to be temp_case. */ static int -read_one_case (struct trns_header *t, struct ccase *c unused) +read_one_case (struct trns_header *t, struct ccase *c UNUSED) { dlsp = (struct data_list_pgm *) t; - return do_reading (1); + return do_reading (1, NULL, NULL); } /* Reads all the records from the data file and passes them to write_case(). */ static void -data_list_source_read (void) +data_list_source_read (write_case_func *write_case, write_case_data wc_data) { dlsp = &dls; - do_reading (0); + do_reading (0, write_case, wc_data); } /* Destroys the source's internal data. */ @@ -1258,12 +1265,14 @@ struct repeating_data_trns int id_beg, id_end; /* ID subcommand, beginning & end columns. */ struct variable *id_var; /* ID subcommand, DATA LIST variable. */ struct fmt_spec id_spec; /* ID subcommand, input format spec. */ + write_case_func *write_case; + write_case_data wc_data; }; /* Information about the transformation being parsed. */ static struct repeating_data_trns rpd; -static int read_one_set_of_repetitions (struct trns_header *, struct ccase *); +int repeating_data_trns_proc (struct trns_header *, struct ccase *); static int parse_num_or_var (struct rpd_num_or_var *, const char *); static int parse_repeating_data (void); static void find_variable_input_spec (struct variable *v, @@ -1523,7 +1532,7 @@ cmd_repeating_data (void) { struct repeating_data_trns *new_trns; - rpd.h.proc = read_one_set_of_repetitions; + rpd.h.proc = repeating_data_trns_proc; rpd.h.free = destroy_dls; new_trns = xmalloc (sizeof *new_trns); @@ -1787,7 +1796,7 @@ rpd_parse_record (int beg, int end, int ofs, struct ccase *c, cur += ofs; - if (!write_case ()) + if (!t->write_case (t->wc_data)) return 0; } } @@ -1798,8 +1807,8 @@ rpd_parse_record (int beg, int end, int ofs, struct ccase *c, /* Analogous to read_one_case; reads one set of repetitions of the elements in the REPEATING DATA structure. Returns -1 on success, -2 on end of file or on failure. */ -static int -read_one_set_of_repetitions (struct trns_header *trns, struct ccase *c) +int +repeating_data_trns_proc (struct trns_header *trns, struct ccase *c) { dfm_push (dlsp->handle); @@ -1932,3 +1941,19 @@ read_one_set_of_repetitions (struct trns_header *trns, struct ccase *c) transformations. */ return -3; } + +/* This is a kluge. It is only here until I have more time + tocome up with something better. It lets + repeating_data_trns_proc() know how to write the cases that it + composes. */ +void +repeating_data_set_write_case (struct trns_header *trns, + write_case_func *write_case, + write_case_data wc_data) +{ + struct repeating_data_trns *t = (struct repeating_data_trns *) trns; + + assert (trns->proc == repeating_data_trns_proc); + t->write_case = write_case; + t->wc_data = wc_data; +}