projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
render: Add comment.
[pspp]
/
src
/
language
/
data-io
/
save.c
diff --git
a/src/language/data-io/save.c
b/src/language/data-io/save.c
index e01a8c941edd24f3989c11db9c9bb7588850e99e..f43aba7a46abc986d6f335a053d9b811e37ef7de 100644
(file)
--- a/
src/language/data-io/save.c
+++ b/
src/language/data-io/save.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 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
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
@@
-25,6
+25,7
@@
#include "data/casewriter.h"
#include "data/dataset.h"
#include "data/dictionary.h"
#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"
#include "data/por-file-writer.h"
#include "data/sys-file-writer.h"
#include "data/transformations.h"
@@
-35,6
+36,7
@@
#include "language/lexer/lexer.h"
#include "libpspp/assertion.h"
#include "libpspp/compiler.h"
#include "language/lexer/lexer.h"
#include "libpspp/assertion.h"
#include "libpspp/compiler.h"
+#include "libpspp/message.h"
#include "gl/xalloc.h"
#include "gl/xalloc.h"
@@
-68,6
+70,12
@@
cmd_save (struct lexer *lexer, struct dataset *ds)
return parse_output_proc (lexer, ds, SYSFILE_WRITER);
}
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)
{
int
cmd_export (struct lexer *lexer, struct dataset *ds)
{
@@
-154,10
+162,12
@@
parse_write_command (struct lexer *lexer, struct dataset *ds,
{
/* Common data. */
struct file_handle *handle; /* Output file. */
{
/* 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. */
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. */
+ const char *sav_name = "";
/* Common options. */
struct sfm_write_options sysfile_opts;
/* Common options. */
struct sfm_write_options sysfile_opts;
@@
-171,6
+181,7
@@
parse_write_command (struct lexer *lexer, struct dataset *ds,
*retain_unselected = true;
handle = NULL;
*retain_unselected = true;
handle = NULL;
+ metadata = NULL;
dict = dict_clone (dataset_dict (ds));
writer = NULL;
stage = NULL;
dict = dict_clone (dataset_dict (ds));
writer = NULL;
stage = NULL;
@@
-198,6
+209,20
@@
parse_write_command (struct lexer *lexer, struct dataset *ds,
if (handle == NULL)
goto error;
}
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"))
{
/* Not yet implemented. */
else if (lex_match_id (lexer, "NAMES"))
{
/* Not yet implemented. */
@@
-213,8
+238,7
@@
parse_write_command (struct lexer *lexer, struct dataset *ds,
cw = true;
else
{
cw = true;
else
{
- lex_error_expecting (lexer, "READONLY", "WRITEABLE",
- NULL_SENTINEL);
+ lex_error_expecting (lexer, "READONLY", "WRITEABLE");
goto error;
}
sysfile_opts.create_writeable = porfile_opts.create_writeable = cw;
goto error;
}
sysfile_opts.create_writeable = porfile_opts.create_writeable = cw;
@@
-228,16
+252,19
@@
parse_write_command (struct lexer *lexer, struct dataset *ds,
*retain_unselected = false;
else
{
*retain_unselected = false;
else
{
- lex_error_expecting (lexer, "RETAIN", "DELETE"
, NULL_SENTINEL
);
+ lex_error_expecting (lexer, "RETAIN", "DELETE");
goto error;
}
}
else if (writer_type == SYSFILE_WRITER
&& lex_match_id (lexer, "COMPRESSED"))
goto error;
}
}
else if (writer_type == SYSFILE_WRITER
&& lex_match_id (lexer, "COMPRESSED"))
- sysfile_opts.compress
= true
;
+ sysfile_opts.compress
ion = ANY_COMP_SIMPLE
;
else if (writer_type == SYSFILE_WRITER
&& lex_match_id (lexer, "UNCOMPRESSED"))
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"))
{
else if (writer_type == SYSFILE_WRITER
&& lex_match_id (lexer, "VERSION"))
{
@@
-256,7
+283,7
@@
parse_write_command (struct lexer *lexer, struct dataset *ds,
porfile_opts.type = PFM_TAPE;
else
{
porfile_opts.type = PFM_TAPE;
else
{
- lex_error_expecting (lexer, "COMM", "TAPE"
, NULL_SENTINEL
);
+ lex_error_expecting (lexer, "COMM", "TAPE");
goto error;
}
}
goto error;
}
}
@@
-268,7
+295,7
@@
parse_write_command (struct lexer *lexer, struct dataset *ds,
porfile_opts.digits = lex_integer (lexer);
lex_get (lexer);
}
porfile_opts.digits = lex_integer (lexer);
lex_get (lexer);
}
- else if (!parse_dict_trim (lexer, dict))
+ else if (!parse_dict_trim (lexer, dict
, false
))
goto error;
if (!lex_match (lexer, T_SLASH))
goto error;
if (!lex_match (lexer, T_SLASH))
@@
-277,46
+304,61
@@
parse_write_command (struct lexer *lexer, struct dataset *ds,
if (lex_end_of_command (lexer) != CMD_SUCCESS)
goto error;
if (lex_end_of_command (lexer) != CMD_SUCCESS)
goto error;
- if (
handle == NULL
)
+ if (
!handle && !metadata
)
{
{
-
lex_sbc_missing ("OUTFILE"
);
+
msg (SE, _("The OUTFILE or METADATA subcommand is required.")
);
goto error;
}
dict_delete_scratch_vars (dict);
dict_compact_values (dict);
goto error;
}
dict_delete_scratch_vars (dict);
dict_compact_values (dict);
- if (
fh_get_referent (handle) == FH_REF_FILE
)
+ if (
handle
)
{
{
- switch (writer_type)
+ if (metadata)
+ sav_name = (fh_get_referent (handle) == FH_REF_FILE
+ ? fh_get_file_name (handle)
+ : fh_get_name (handle));
+ if (fh_get_referent (handle) == FH_REF_FILE)
{
{
- case SYSFILE_WRITER:
- writer = sfm_open_writer (handle, dict, sysfile_opts);
- break;
- case PORFILE_WRITER:
- writer = pfm_open_writer (handle, dict, porfile_opts);
- break;
+ switch (writer_type)
+ {
+ case SYSFILE_WRITER:
+ writer = sfm_open_writer (handle, dict, sysfile_opts);
+ break;
+ case PORFILE_WRITER:
+ writer = pfm_open_writer (handle, dict, porfile_opts);
+ break;
+ }
}
}
+ else
+ writer = any_writer_open (handle, dict);
+ if (writer == NULL)
+ goto error;
+ }
+
+ if (metadata)
+ {
+ if (!mdd_write (metadata, dict, sav_name))
+ goto error;
}
}
- else
- writer = any_writer_open (handle, dict);
- if (writer == NULL)
- 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);
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 (handle);
+ fh_unref (metadata);
return writer;
error:
case_map_stage_destroy (stage);
fh_unref (handle);
return writer;
error:
case_map_stage_destroy (stage);
fh_unref (handle);
+ fh_unref (metadata);
casewriter_destroy (writer);
casewriter_destroy (writer);
- dict_
destroy
(dict);
+ dict_
unref
(dict);
case_map_destroy (map);
return NULL;
}
case_map_destroy (map);
return NULL;
}