X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Finpt-pgm.c;h=004fe2c4820b3b7e74b01118e161e8d9070ac02f;hb=4255c7e5a693e09a97dc7a3cca0634bb2adaba2d;hp=dc08f346a9704b7d4dc60f593aa40f1195f5a417;hpb=37597beca4a11edba50b847932fdfeca3a648fa2;p=pspp diff --git a/src/inpt-pgm.c b/src/inpt-pgm.c index dc08f346a9..004fe2c482 100644 --- a/src/inpt-pgm.c +++ b/src/inpt-pgm.c @@ -18,15 +18,17 @@ 02111-1307, USA. */ #include -#include +#include "error.h" #include #include #include "alloc.h" +#include "case.h" #include "command.h" #include "data-list.h" -#include "dfm.h" +#include "dfm-read.h" +#include "dictionary.h" #include "error.h" -#include "expr.h" +#include "expressions/public.h" #include "file-handle.h" #include "lexer.h" #include "misc.h" @@ -59,8 +61,6 @@ static trns_free_func reread_trns_free; int cmd_input_program (void) { - lex_match_id ("INPUT"); - lex_match_id ("PROGRAM"); discard_variables (); /* FIXME: we shouldn't do this here, but I'm afraid that other @@ -77,10 +77,6 @@ cmd_end_input_program (void) struct input_program_pgm *inp; size_t i; - lex_match_id ("END"); - lex_match_id ("INPUT"); - lex_match_id ("PROGRAM"); - if (!case_source_is_class (vfm_source, &input_program_source_class)) { msg (SE, _("No matching INPUT PROGRAM command.")); @@ -136,14 +132,14 @@ init_case (const struct input_program_pgm *inp, struct ccase *c) switch (inp->init[i]) { case INP_NUMERIC | INP_INIT_ONCE: - c->data[i].f = 0.0; + case_data_rw (c, i)->f = 0.0; break; case INP_NUMERIC | INP_REINIT: - c->data[i].f = SYSMIS; + case_data_rw (c, i)->f = SYSMIS; break; case INP_STRING | INP_INIT_ONCE: case INP_STRING | INP_REINIT: - memset (c->data[i].s, ' ', sizeof c->data[i].s); + memset (case_data_rw (c, i)->s, ' ', sizeof case_data_rw (c, i)->s); break; default: assert (0); @@ -162,12 +158,12 @@ clear_case (const struct input_program_pgm *inp, struct ccase *c) case INP_NUMERIC | INP_INIT_ONCE: break; case INP_NUMERIC | INP_REINIT: - c->data[i].f = SYSMIS; + case_data_rw (c, i)->f = SYSMIS; break; case INP_STRING | INP_INIT_ONCE: break; case INP_STRING | INP_REINIT: - memset (c->data[i].s, ' ', sizeof c->data[i].s); + memset (case_data_rw (c, i)->s, ' ', sizeof case_data_rw (c, i)->s); break; default: assert (0); @@ -287,9 +283,6 @@ cmd_end_case (void) { struct trns_header *t; - lex_match_id ("END"); - lex_match_id ("CASE"); - if (!case_source_is_class (vfm_source, &input_program_source_class)) { msg (SE, _("This command may only be executed between INPUT PROGRAM " @@ -312,6 +305,7 @@ end_case_trns_proc (struct trns_header *t UNUSED, struct ccase * c UNUSED, int case_num UNUSED) { assert (0); + abort (); } /* REREAD transformation. */ @@ -319,7 +313,7 @@ struct reread_trns { struct trns_header h; - struct file_handle *handle; /* File to move file pointer back on. */ + struct dfm_reader *reader; /* File to move file pointer back on. */ struct expression *column; /* Column to reset file pointer to. */ }; @@ -327,18 +321,11 @@ struct reread_trns int cmd_reread (void) { - /* File to be re-read. */ - struct file_handle *h; - - /* Expression for column to set file pointer to. */ - struct expression *e; - - /* Created transformation. */ - struct reread_trns *t; - - lex_match_id ("REREAD"); + struct file_handle *fh; /* File to be re-read. */ + struct expression *e; /* Expression for column to set. */ + struct reread_trns *t; /* Created transformation. */ - h = default_handle; + fh = default_handle; e = NULL; while (token != '.') { @@ -353,21 +340,15 @@ cmd_reread (void) return CMD_FAILURE; } - e = expr_parse (PXP_NUMERIC); + e = expr_parse (default_dict, EXPR_NUMBER); if (!e) return CMD_FAILURE; } else if (lex_match_id ("FILE")) { lex_match ('='); - if (token != T_ID) - { - lex_error (_("expecting file handle name")); - expr_free (e); - return CMD_FAILURE; - } - h = fh_get_handle_by_name (tokid); - if (!h) + fh = fh_parse (); + if (fh == NULL) { expr_free (e); return CMD_FAILURE; @@ -384,7 +365,7 @@ cmd_reread (void) t = xmalloc (sizeof *t); t->h.proc = reread_trns_proc; t->h.free = reread_trns_free; - t->handle = h; + t->reader = dfm_open_reader (fh); t->column = e; add_transformation ((struct trns_header *) t); @@ -399,29 +380,29 @@ reread_trns_proc (struct trns_header * pt, struct ccase * c, struct reread_trns *t = (struct reread_trns *) pt; if (t->column == NULL) - dfm_bkwd_record (t->handle, 1); + dfm_reread_record (t->reader, 1); else { - union value column; - - expr_evaluate (t->column, c, case_num, &column); - if (!finite (column.f) || column.f < 1) + double column = expr_evaluate_num (t->column, c, case_num); + if (!finite (column) || column < 1) { msg (SE, _("REREAD: Column numbers must be positive finite " "numbers. Column set to 1.")); - dfm_bkwd_record (t->handle, 1); + dfm_reread_record (t->reader, 1); } else - dfm_bkwd_record (t->handle, column.f); + dfm_reread_record (t->reader, column); } return -1; } /* Frees a REREAD transformation. */ static void -reread_trns_free (struct trns_header * t) +reread_trns_free (struct trns_header *t_) { - expr_free (((struct reread_trns *) t)->column); + struct reread_trns *t = (struct reread_trns *) t_; + expr_free (t->column); + dfm_close_reader (t->reader); } /* Parses END FILE command. */ @@ -430,9 +411,6 @@ cmd_end_file (void) { struct trns_header *t; - lex_match_id ("END"); - lex_match_id ("FILE"); - if (!case_source_is_class (vfm_source, &input_program_source_class)) { msg (SE, _("This command may only be executed between INPUT PROGRAM "