X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Fcombine-files.c;h=e09b36ecad9dde80b16e521ef21cfe22c9bbc01a;hb=aea57010adca9f26dd3abef66a3f7a5c169964ec;hp=82c36945a2fd803de74a0ea3239c3918440c4ed3;hpb=81579d9e9f994fb2908f50af41c3eb033d216e58;p=pspp diff --git a/src/language/data-io/combine-files.c b/src/language/data-io/combine-files.c index 82c36945a2..e09b36ecad 100644 --- a/src/language/data-io/combine-files.c +++ b/src/language/data-io/combine-files.c @@ -23,9 +23,9 @@ #include "data/case.h" #include "data/casereader.h" #include "data/casewriter.h" +#include "data/dataset.h" #include "data/dictionary.h" #include "data/format.h" -#include "data/procedure.h" #include "data/subcase.h" #include "data/variable.h" #include "language/command.h" @@ -35,7 +35,9 @@ #include "language/lexer/variable-parser.h" #include "language/stats/sort-criteria.h" #include "libpspp/assertion.h" +#include "libpspp/i18n.h" #include "libpspp/message.h" +#include "libpspp/string-array.h" #include "libpspp/taint.h" #include "math/sort.h" @@ -159,7 +161,7 @@ combine_files (enum comb_command_type command, proc.files = NULL; proc.n_files = 0; - proc.dict = dict_create (); + proc.dict = dict_create (get_default_encoding ()); proc.output = NULL; proc.matcher = NULL; subcase_init_empty (&proc.by_vars); @@ -205,23 +207,23 @@ combine_files (enum comb_command_type command, if (lex_match (lexer, T_ASTERISK)) { - if (!proc_has_active_file (ds)) + if (!dataset_has_source (ds)) { - msg (SE, _("Cannot specify the active file since no active " - "file has been defined.")); + msg (SE, _("Cannot specify the active dataset since none " + "has been defined.")); goto error; } if (proc_make_temporary_transformations_permanent (ds)) msg (SE, _("This command may not be used after TEMPORARY when " - "the active file is an input source. " + "the active dataset is an input source. " "Temporary transformations will be made permanent.")); file->dict = dict_clone (dataset_dict (ds)); } else { - file->handle = fh_parse (lexer, FH_REF_FILE | FH_REF_SCRATCH); + file->handle = fh_parse (lexer, FH_REF_FILE, dataset_session (ds)); if (file->handle == NULL) goto error; @@ -302,7 +304,8 @@ combine_files (enum comb_command_type command, msg (SE, _("File %s lacks BY variable %s."), fh_get_name (file->handle), name); else - msg (SE, _("Active file lacks BY variable %s."), name); + msg (SE, _("Active dataset lacks BY variable %s."), + name); ok = false; } } @@ -465,7 +468,8 @@ combine_files (enum comb_command_type command, if (active_file != NULL) proc_commit (ds); - proc_set_active_file (ds, casewriter_make_reader (proc.output), proc.dict); + dataset_set_dict (ds, proc.dict); + dataset_set_source (ds, casewriter_make_reader (proc.output)); proc.dict = NULL; proc.output = NULL; @@ -491,9 +495,8 @@ static bool merge_dictionary (struct dictionary *const m, struct comb_file *f) { struct dictionary *d = f->dict; - const char *d_docs, *m_docs; + const struct string_array *d_docs, *m_docs; int i; - const char *file_encoding; if (dict_get_label (m) == NULL) dict_set_label (m, dict_get_label (d)); @@ -507,17 +510,9 @@ merge_dictionary (struct dictionary *const m, struct comb_file *f) The correct thing to do would be to convert to an encoding which can cope with all the input files (eg UTF-8). */ - file_encoding = dict_get_encoding (f->dict); - if ( file_encoding != NULL) - { - if ( dict_get_encoding (m) == NULL) - dict_set_encoding (m, file_encoding); - else if ( 0 != strcmp (file_encoding, dict_get_encoding (m))) - { - msg (MW, - _("Combining files with incompatible encodings. String data may not be represented correctly.")); - } - } + if ( 0 != strcmp (dict_get_encoding (f->dict), dict_get_encoding (m))) + msg (MW, _("Combining files with incompatible encodings. String data may " + "not be represented correctly.")); if (d_docs != NULL) { @@ -525,9 +520,19 @@ merge_dictionary (struct dictionary *const m, struct comb_file *f) dict_set_documents (m, d_docs); else { - char *new_docs = xasprintf ("%s%s", m_docs, d_docs); - dict_set_documents (m, new_docs); - free (new_docs); + struct string_array new_docs; + size_t i; + + new_docs.n = m_docs->n + d_docs->n; + new_docs.strings = xmalloc (new_docs.n * sizeof *new_docs.strings); + for (i = 0; i < m_docs->n; i++) + new_docs.strings[i] = m_docs->strings[i]; + for (i = 0; i < d_docs->n; i++) + new_docs.strings[m_docs->n + i] = d_docs->strings[i]; + + dict_set_documents (m, &new_docs); + + free (new_docs.strings); } } @@ -577,7 +582,7 @@ merge_dictionary (struct dictionary *const m, struct comb_file *f) if (var_has_missing_values (dv) && !var_has_missing_values (mv)) var_set_missing_values (mv, var_get_missing_values (dv)); if (var_get_label (dv) && !var_get_label (mv)) - var_set_label (mv, var_get_label (dv)); + var_set_label (mv, var_get_label (dv), false); } else mv = dict_clone_var_assert (m, dv);