X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Fsave.c;h=b97da69b00eff3a278aeb18762820f7c76ac15c2;hb=refs%2Fheads%2Fpivot-table2;hp=c34d446225bd250a76687ef736aeed697d7027be;hpb=7fbfc32fc3c636959b0a25b3e76609f86519e84a;p=pspp diff --git a/src/language/data-io/save.c b/src/language/data-io/save.c index c34d446225..b97da69b00 100644 --- a/src/language/data-io/save.c +++ b/src/language/data-io/save.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 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 @@ -18,25 +18,25 @@ #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "xalloc.h" +#include "data/any-writer.h" +#include "data/case-map.h" +#include "data/case.h" +#include "data/casereader.h" +#include "data/casewriter.h" +#include "data/dataset.h" +#include "data/dictionary.h" +#include "data/por-file-writer.h" +#include "data/sys-file-writer.h" +#include "data/transformations.h" +#include "data/variable.h" +#include "language/command.h" +#include "language/data-io/file-handle.h" +#include "language/data-io/trim.h" +#include "language/lexer/lexer.h" +#include "libpspp/assertion.h" +#include "libpspp/compiler.h" + +#include "gl/xalloc.h" #include "gettext.h" #define _(msgid) gettext (msgid) @@ -105,7 +105,6 @@ parse_output_proc (struct lexer *lexer, struct dataset *ds, enum writer_type writer_type) { bool retain_unselected; - struct variable *saved_filter_variable; struct casewriter *output; bool ok; @@ -114,16 +113,10 @@ parse_output_proc (struct lexer *lexer, struct dataset *ds, if (output == NULL) return CMD_CASCADING_FAILURE; - saved_filter_variable = dict_get_filter (dataset_dict (ds)); - if (retain_unselected) - dict_set_filter (dataset_dict (ds), NULL); - - casereader_transfer (proc_open (ds), output); + casereader_transfer (proc_open_filtering (ds, !retain_unselected), output); ok = casewriter_destroy (output); ok = proc_commit (ds) && ok; - dict_set_filter (dataset_dict (ds), saved_filter_variable); - return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE; } @@ -163,11 +156,10 @@ parse_write_command (struct lexer *lexer, struct dataset *ds, struct file_handle *handle; /* Output file. */ struct dictionary *dict; /* Dictionary for output file. */ struct casewriter *writer; /* Writer. */ + struct case_map_stage *stage; /* Preparation for 'map'. */ struct case_map *map; /* Map from input data to data for writer. */ /* Common options. */ - bool print_map; /* Print map? TODO. */ - bool print_short_names; /* Print long-to-short name map. TODO. */ struct sfm_write_options sysfile_opts; struct pfm_write_options porfile_opts; @@ -181,16 +173,15 @@ parse_write_command (struct lexer *lexer, struct dataset *ds, handle = NULL; dict = dict_clone (dataset_dict (ds)); writer = NULL; + stage = NULL; map = NULL; - print_map = false; - print_short_names = false; sysfile_opts = sfm_writer_default_options (); porfile_opts = pfm_writer_default_options (); - case_map_prepare_dict (dict); + stage = case_map_stage_create (dict); dict_delete_scratch_vars (dict); - lex_match (lexer, '/'); + lex_match (lexer, T_SLASH); for (;;) { if (lex_match_id (lexer, "OUTFILE")) @@ -201,54 +192,59 @@ parse_write_command (struct lexer *lexer, struct dataset *ds, goto error; } - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); - handle = fh_parse (lexer, FH_REF_FILE | FH_REF_SCRATCH); + handle = fh_parse (lexer, FH_REF_FILE, NULL); if (handle == NULL) goto error; } else if (lex_match_id (lexer, "NAMES")) - print_short_names = true; + { + /* Not yet implemented. */ + } else if (lex_match_id (lexer, "PERMISSIONS")) { bool cw; - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (lex_match_id (lexer, "READONLY")) cw = false; else if (lex_match_id (lexer, "WRITEABLE")) cw = true; else { - lex_error (lexer, _("expecting %s or %s"), - "READONLY", "WRITEABLE"); + lex_error_expecting (lexer, "READONLY", "WRITEABLE", + NULL_SENTINEL); goto error; } sysfile_opts.create_writeable = porfile_opts.create_writeable = cw; } else if (command_type == PROC_CMD && lex_match_id (lexer, "UNSELECTED")) { - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (lex_match_id (lexer, "RETAIN")) *retain_unselected = true; else if (lex_match_id (lexer, "DELETE")) *retain_unselected = false; else { - lex_error (lexer, _("expecting %s or %s"), "RETAIN", "DELETE"); + lex_error_expecting (lexer, "RETAIN", "DELETE", NULL_SENTINEL); goto error; } } else if (writer_type == SYSFILE_WRITER && lex_match_id (lexer, "COMPRESSED")) - sysfile_opts.compress = true; + sysfile_opts.compression = ANY_COMP_SIMPLE; else if (writer_type == SYSFILE_WRITER && lex_match_id (lexer, "UNCOMPRESSED")) - sysfile_opts.compress = false; + sysfile_opts.compression = ANY_COMP_NONE; + else if (writer_type == SYSFILE_WRITER + && lex_match_id (lexer, "ZCOMPRESSED")) + sysfile_opts.compression = ANY_COMP_ZLIB; else if (writer_type == SYSFILE_WRITER && lex_match_id (lexer, "VERSION")) { - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (!lex_force_int (lexer)) goto error; sysfile_opts.version = lex_integer (lexer); @@ -256,20 +252,20 @@ parse_write_command (struct lexer *lexer, struct dataset *ds, } else if (writer_type == PORFILE_WRITER && lex_match_id (lexer, "TYPE")) { - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (lex_match_id (lexer, "COMMUNICATIONS")) porfile_opts.type = PFM_COMM; else if (lex_match_id (lexer, "TAPE")) porfile_opts.type = PFM_TAPE; else { - lex_error (lexer, _("expecting %s or %s"), "COMM", "TAPE"); + lex_error_expecting (lexer, "COMM", "TAPE", NULL_SENTINEL); goto error; } } else if (writer_type == PORFILE_WRITER && lex_match_id (lexer, "DIGITS")) { - lex_match (lexer, '='); + lex_match (lexer, T_EQUALS); if (!lex_force_int (lexer)) goto error; porfile_opts.digits = lex_integer (lexer); @@ -278,7 +274,7 @@ parse_write_command (struct lexer *lexer, struct dataset *ds, else if (!parse_dict_trim (lexer, dict)) goto error; - if (!lex_match (lexer, '/')) + if (!lex_match (lexer, T_SLASH)) break; } if (lex_end_of_command (lexer) != CMD_SUCCESS) @@ -286,7 +282,7 @@ parse_write_command (struct lexer *lexer, struct dataset *ds, if (handle == NULL) { - lex_sbc_missing (lexer, "OUTFILE"); + lex_sbc_missing ("OUTFILE"); goto error; } @@ -310,7 +306,8 @@ parse_write_command (struct lexer *lexer, struct dataset *ds, if (writer == NULL) goto error; - map = case_map_from_dict (dict); + map = case_map_stage_get_case_map (stage); + case_map_stage_destroy (stage); if (map != NULL) writer = case_map_create_output_translator (map, writer); dict_destroy (dict); @@ -319,6 +316,7 @@ parse_write_command (struct lexer *lexer, struct dataset *ds, return writer; error: + case_map_stage_destroy (stage); fh_unref (handle); casewriter_destroy (writer); dict_destroy (dict);