projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Reference count struct dictionary.
[pspp]
/
src
/
language
/
data-io
/
get.c
diff --git
a/src/language/data-io/get.c
b/src/language/data-io/get.c
index d32f25567a25dcfd28cf7b3dad7189cc2bee29f6..6e99187ba11c5a311d137b2f6be1dbc0990ae3ed 100644
(file)
--- a/
src/language/data-io/get.c
+++ b/
src/language/data-io/get.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 1997-9, 2000, 2006
, 2007, 2010, 2011
Free Software Foundation, Inc.
+ Copyright (C) 1997-9, 2000, 2006
-2007, 2010-15
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
@@
-31,6
+31,7
@@
#include "language/lexer/lexer.h"
#include "libpspp/compiler.h"
#include "libpspp/misc.h"
#include "language/lexer/lexer.h"
#include "libpspp/compiler.h"
#include "libpspp/misc.h"
+#include "libpspp/message.h"
#include "libpspp/str.h"
#include "gl/xalloc.h"
#include "libpspp/str.h"
#include "gl/xalloc.h"
@@
-73,6
+74,8
@@
parse_read_command (struct lexer *lexer, struct dataset *ds,
struct file_handle *fh = NULL;
struct dictionary *dict = NULL;
struct case_map *map = NULL;
struct file_handle *fh = NULL;
struct dictionary *dict = NULL;
struct case_map *map = NULL;
+ struct case_map_stage *stage = NULL;
+ char *encoding = NULL;
for (;;)
{
for (;;)
{
@@
-87,6
+90,18
@@
parse_read_command (struct lexer *lexer, struct dataset *ds,
if (fh == NULL)
goto error;
}
if (fh == NULL)
goto error;
}
+ else if (command == GET_CMD && lex_match_id (lexer, "ENCODING"))
+ {
+ lex_match (lexer, T_EQUALS);
+
+ if (!lex_force_string (lexer))
+ goto error;
+
+ free (encoding);
+ encoding = ss_xstrdup (lex_tokss (lexer));
+
+ lex_get (lexer);
+ }
else if (command == IMPORT_CMD && lex_match_id (lexer, "TYPE"))
{
lex_match (lexer, T_EQUALS);
else if (command == IMPORT_CMD && lex_match_id (lexer, "TYPE"))
{
lex_match (lexer, T_EQUALS);
@@
-108,11
+123,18
@@
parse_read_command (struct lexer *lexer, struct dataset *ds,
goto error;
}
goto error;
}
- reader = any_reader_open
(fh, &dict
);
+ reader = any_reader_open
_and_decode (fh, encoding, &dict, NULL
);
if (reader == NULL)
goto error;
if (reader == NULL)
goto error;
- case_map_prepare_dict (dict);
+ if (dict_get_var_cnt (dict) == 0)
+ {
+ msg (SE, _("%s: Data file dictionary has no variables."),
+ fh_get_name (fh));
+ goto error;
+ }
+
+ stage = case_map_stage_create (dict);
while (lex_token (lexer) != T_ENDCMD)
{
while (lex_token (lexer) != T_ENDCMD)
{
@@
-122,7
+144,8
@@
parse_read_command (struct lexer *lexer, struct dataset *ds,
}
dict_compact_values (dict);
}
dict_compact_values (dict);
- map = case_map_from_dict (dict);
+ map = case_map_stage_get_case_map (stage);
+ case_map_stage_destroy (stage);
if (map != NULL)
reader = case_map_create_input_translator (map, reader);
if (map != NULL)
reader = case_map_create_input_translator (map, reader);
@@
-130,12
+153,15
@@
parse_read_command (struct lexer *lexer, struct dataset *ds,
dataset_set_source (ds, reader);
fh_unref (fh);
dataset_set_source (ds, reader);
fh_unref (fh);
+ free (encoding);
return CMD_SUCCESS;
error:
return CMD_SUCCESS;
error:
+ case_map_stage_destroy (stage);
fh_unref (fh);
casereader_destroy (reader);
if (dict != NULL)
fh_unref (fh);
casereader_destroy (reader);
if (dict != NULL)
- dict_destroy (dict);
+ dict_unref (dict);
+ free (encoding);
return CMD_CASCADING_FAILURE;
}
return CMD_CASCADING_FAILURE;
}