X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Finpt-pgm.c;h=a500df4117130f4ae0ce808b3a1ccd6a209f8b28;hb=3b07fccffef73bba4bb1839fced20554df75901e;hp=ccd53be04e4199913635d1568aa4af774459e36f;hpb=e943de7a3e0645852c3b659889ff3ccf38dd43ec;p=pspp diff --git a/src/language/data-io/inpt-pgm.c b/src/language/data-io/inpt-pgm.c index ccd53be04e..a500df4117 100644 --- a/src/language/data-io/inpt-pgm.c +++ b/src/language/data-io/inpt-pgm.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -24,6 +24,7 @@ #include "data/casereader-provider.h" #include "data/dataset.h" #include "data/dictionary.h" +#include "data/session.h" #include "data/transformations.h" #include "data/variable.h" #include "language/command.h" @@ -43,15 +44,11 @@ #include "gettext.h" #define _(msgid) gettext (msgid) -/* Private result codes for use within INPUT PROGRAM. */ -enum cmd_result_extensions - { - CMD_END_CASE = CMD_PRIVATE_FIRST - }; - /* Indicates how a `union value' should be initialized. */ struct input_program_pgm { + struct session *session; + struct dataset *ds; struct trns_chain *trns_chain; enum trns_result restart; @@ -91,12 +88,15 @@ cmd_input_program (struct lexer *lexer, struct dataset *ds) { struct input_program_pgm *inp; bool saw_END_CASE = false; + bool saw_END_FILE = false; + bool saw_DATA_LIST = false; - dataset_clear (ds); if (!lex_match (lexer, T_ENDCMD)) return lex_end_of_command (lexer); inp = xmalloc (sizeof *inp); + inp->session = session_create (dataset_session (ds)); + inp->ds = dataset_create (inp->session, "INPUT PROGRAM"); inp->trns_chain = NULL; inp->init = NULL; inp->proto = NULL; @@ -106,44 +106,65 @@ cmd_input_program (struct lexer *lexer, struct dataset *ds) { enum cmd_result result; - result = cmd_parse_in_state (lexer, ds, CMD_STATE_INPUT_PROGRAM); - if (result == (enum cmd_result) CMD_END_CASE) + result = cmd_parse_in_state (lexer, inp->ds, CMD_STATE_INPUT_PROGRAM); + switch (result) { - emit_END_CASE (ds, inp); + case CMD_DATA_LIST: + saw_DATA_LIST = true; + break; + + case CMD_END_CASE: + emit_END_CASE (inp->ds, inp); saw_END_CASE = true; - } - else if (cmd_result_is_failure (result) && result != CMD_FAILURE) - { - if (result == CMD_EOF) - msg (SE, _("Unexpected end-of-file within INPUT PROGRAM.")); - inside_input_program = false; - dataset_clear (ds); - destroy_input_program (inp); - return result; + break; + + case CMD_END_FILE: + saw_END_FILE = true; + break; + + case CMD_FAILURE: + break; + + default: + if (cmd_result_is_failure (result) + && lex_get_error_mode (lexer) != LEX_ERROR_INTERACTIVE) + { + if (result == CMD_EOF) + msg (SE, _("Unexpected end-of-file within INPUT PROGRAM.")); + inside_input_program = false; + destroy_input_program (inp); + return result; + } } } if (!saw_END_CASE) - emit_END_CASE (ds, inp); + emit_END_CASE (inp->ds, inp); inside_input_program = false; - if (dict_get_next_value_idx (dataset_dict (ds)) == 0) + if (!saw_DATA_LIST && !saw_END_FILE) + { + msg (SE, _("Input program must contain DATA LIST or END FILE.")); + destroy_input_program (inp); + return CMD_FAILURE; + } + if (dict_get_next_value_idx (dataset_dict (inp->ds)) == 0) { msg (SE, _("Input program did not create any variables.")); - dataset_clear (ds); destroy_input_program (inp); return CMD_FAILURE; } - inp->trns_chain = proc_capture_transformations (ds); + inp->trns_chain = proc_capture_transformations (inp->ds); trns_chain_finalize (inp->trns_chain); inp->restart = TRNS_CONTINUE; /* Figure out how to initialize each input case. */ inp->init = caseinit_create (); - caseinit_mark_for_init (inp->init, dataset_dict (ds)); - inp->proto = caseproto_ref (dict_get_proto (dataset_dict (ds))); + caseinit_mark_for_init (inp->init, dataset_dict (inp->ds)); + inp->proto = caseproto_ref (dict_get_proto (dataset_dict (inp->ds))); + dataset_set_dict (ds, dict_clone (dataset_dict (inp->ds))); dataset_set_source ( ds, casereader_create_sequential (NULL, inp->proto, CASENUMBER_MAX, &input_program_casereader_class, inp)); @@ -208,6 +229,7 @@ destroy_input_program (struct input_program_pgm *pgm) { if (pgm != NULL) { + session_destroy (pgm->session); trns_chain_destroy (pgm->trns_chain); caseinit_destroy (pgm->init); caseproto_unref (pgm->proto); @@ -369,7 +391,7 @@ cmd_end_file (struct lexer *lexer UNUSED, struct dataset *ds) add_transformation (ds, end_file_trns_proc, NULL, NULL); - return CMD_SUCCESS; + return CMD_END_FILE; } /* Executes an END FILE transformation. */