X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Fget-data.c;h=789300015e8243ce2170224ecb8c3762d64bf835;hb=f481fd69631024bcdc7dc2369bbc1592d7a43ac7;hp=4274f959d26048de21d79797d3eed879da6766fd;hpb=92e42986429596633f71457a585b3266209822dd;p=pspp diff --git a/src/language/data-io/get-data.c b/src/language/data-io/get-data.c index 4274f959d2..789300015e 100644 --- a/src/language/data-io/get-data.c +++ b/src/language/data-io/get-data.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2008, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 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 @@ -65,10 +65,12 @@ cmd_get_data (struct lexer *lexer, struct dataset *ds) tok = strdup (lex_tokcstr (lexer)); if (lex_match_id (lexer, "TXT")) { + free (tok); return parse_get_txt (lexer, ds); } else if (lex_match_id (lexer, "PSQL")) { + free (tok); return parse_get_psql (lexer, ds); } else if (lex_match_id (lexer, "GNM") || @@ -307,6 +309,7 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds) struct dictionary *dict = dict_create (get_default_encoding ()); struct file_handle *fh = NULL; struct dfm_reader *reader = NULL; + char *encoding = NULL; char *name = NULL; int record; @@ -334,7 +337,18 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds) if (!lex_force_match (lexer, T_SLASH)) goto error; - if (lex_match_id (lexer, "ARRANGEMENT")) + if (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 (lex_match_id (lexer, "ARRANGEMENT")) { bool ok; @@ -606,12 +620,13 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds) } while (lex_token (lexer) != T_ENDCMD); - reader = dfm_open_reader (fh, lexer); + reader = dfm_open_reader (fh, lexer, encoding); if (reader == NULL) goto error; data_parser_make_active_file (parser, ds, reader, dict); fh_unref (fh); + free (encoding); return CMD_SUCCESS; error: @@ -619,6 +634,7 @@ parse_get_txt (struct lexer *lexer, struct dataset *ds) dict_destroy (dict); fh_unref (fh); free (name); + free (encoding); return CMD_CASCADING_FAILURE; }