/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2007, 2008, 2009, 2010, 2011 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
#include "data/casewriter.h"
#include "data/dataset.h"
#include "data/dictionary.h"
+#include "data/mdd-writer.h"
#include "data/por-file-writer.h"
#include "data/sys-file-writer.h"
#include "data/transformations.h"
return parse_output_proc (lexer, ds, SYSFILE_WRITER);
}
+int
+cmd_save_data_collection (struct lexer *lexer, struct dataset *ds)
+{
+ return parse_output_proc (lexer, ds, SYSFILE_WRITER);
+}
+
int
cmd_export (struct lexer *lexer, struct dataset *ds)
{
{
/* Common data. */
struct file_handle *handle; /* Output file. */
+ struct file_handle *metadata; /* MDD 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;
*retain_unselected = true;
handle = NULL;
+ metadata = 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, T_SLASH);
if (handle == NULL)
goto error;
}
+ else if (lex_match_id (lexer, "METADATA"))
+ {
+ if (metadata != NULL)
+ {
+ lex_sbc_only_once ("METADATA");
+ goto error;
+ }
+
+ lex_match (lexer, T_EQUALS);
+
+ metadata = fh_parse (lexer, FH_REF_FILE, NULL);
+ if (metadata == 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;
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;
*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"))
{
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;
}
}
if (handle == NULL)
{
- lex_sbc_missing (lexer, "OUTFILE");
+ lex_sbc_missing ("OUTFILE");
goto error;
}
if (writer == NULL)
goto error;
- map = case_map_from_dict (dict);
+ if (metadata)
+ {
+ const char *sav_name = (fh_get_referent (handle) == FH_REF_FILE
+ ? fh_get_file_name (handle)
+ : fh_get_name (handle));
+ if (!mdd_write (metadata, dict, sav_name))
+ goto error;
+ }
+
+ 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);
+ dict_unref (dict);
fh_unref (handle);
+ fh_unref (metadata);
return writer;
error:
+ case_map_stage_destroy (stage);
fh_unref (handle);
+ fh_unref (metadata);
casewriter_destroy (writer);
- dict_destroy (dict);
+ dict_unref (dict);
case_map_destroy (map);
return NULL;
}