X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fdata-io%2Fget.c;h=35b894a75037868ba3119b437e7a01e0bfd7b4c5;hb=ec950d9ec3a216424fd190a319d49cd2e9578b47;hp=aa2b91fe6a92d3a8259c6475c597869c007ca12b;hpb=81579d9e9f994fb2908f50af41c3eb033d216e58;p=pspp diff --git a/src/language/data-io/get.c b/src/language/data-io/get.c index aa2b91fe6a..35b894a750 100644 --- a/src/language/data-io/get.c +++ b/src/language/data-io/get.c @@ -1,5 +1,5 @@ /* 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, 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 @@ -22,9 +22,9 @@ #include "data/case-map.h" #include "data/case.h" #include "data/casereader.h" +#include "data/dataset.h" #include "data/dictionary.h" #include "data/por-file-writer.h" -#include "data/procedure.h" #include "language/command.h" #include "language/data-io/file-handle.h" #include "language/data-io/trim.h" @@ -66,12 +66,14 @@ cmd_import (struct lexer *lexer, struct dataset *ds) /* Parses a GET or IMPORT command. */ static int -parse_read_command (struct lexer *lexer, struct dataset *ds, enum reader_command type) +parse_read_command (struct lexer *lexer, struct dataset *ds, + enum reader_command command) { struct casereader *reader = NULL; struct file_handle *fh = NULL; struct dictionary *dict = NULL; struct case_map *map = NULL; + char *encoding = NULL; for (;;) { @@ -82,21 +84,30 @@ parse_read_command (struct lexer *lexer, struct dataset *ds, enum reader_command lex_match (lexer, T_EQUALS); fh_unref (fh); - fh = fh_parse (lexer, FH_REF_FILE | FH_REF_SCRATCH); + fh = fh_parse (lexer, FH_REF_FILE, NULL); if (fh == NULL) goto error; } - else if (type == IMPORT_CMD && lex_match_id (lexer, "TYPE")) + 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); - if (lex_match_id (lexer, "COMM")) - type = PFM_COMM; - else if (lex_match_id (lexer, "TAPE")) - type = PFM_TAPE; - else + if (!lex_match_id (lexer, "COMM") + && !lex_match_id (lexer, "TAPE")) { - lex_error (lexer, _("expecting %s or %s"), "COMM", "TAPE"); + lex_error_expecting (lexer, "COMM", "TAPE", NULL_SENTINEL); goto error; } } @@ -106,11 +117,11 @@ parse_read_command (struct lexer *lexer, struct dataset *ds, enum reader_command if (fh == NULL) { - lex_sbc_missing (lexer, "FILE"); + lex_sbc_missing ("FILE"); goto error; } - reader = any_reader_open (fh, &dict); + reader = any_reader_open (fh, encoding, &dict); if (reader == NULL) goto error; @@ -128,9 +139,11 @@ parse_read_command (struct lexer *lexer, struct dataset *ds, enum reader_command if (map != NULL) reader = case_map_create_input_translator (map, reader); - proc_set_active_file (ds, reader, dict); + dataset_set_dict (ds, dict); + dataset_set_source (ds, reader); fh_unref (fh); + free (encoding); return CMD_SUCCESS; error: @@ -138,5 +151,6 @@ parse_read_command (struct lexer *lexer, struct dataset *ds, enum reader_command casereader_destroy (reader); if (dict != NULL) dict_destroy (dict); + free (encoding); return CMD_CASCADING_FAILURE; }