/* PSPP - a program for statistical analysis.
- Copyright (C) 2007, 2008 Free Software Foundation, Inc.
+ Copyright (C) 2007, 2008, 2009, 2010 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/dictionary.h>
#include <data/format.h>
#include <data/procedure.h>
+#include <data/settings.h>
#include <language/command.h>
#include <language/data-io/data-parser.h>
#include <language/data-io/data-reader.h>
#include <language/lexer/lexer.h>
#include <libpspp/message.h>
+#include "xalloc.h"
+
#include "gettext.h"
#define _(msgid) gettext (msgid)
#define N_(msgid) (msgid)
if (!lex_force_string (lexer))
goto error;
- psql.conninfo = strdup (ds_cstr (lex_tokstr (lexer)));
+ psql.conninfo = xstrdup (ds_cstr (lex_tokstr (lexer)));
lex_get (lexer);
if (!lex_force_string (lexer))
goto error;
- gri.file_name = strdup (ds_cstr (lex_tokstr (lexer)));
+ gri.file_name = xstrdup (ds_cstr (lex_tokstr (lexer)));
lex_get (lexer);
if ( ! lex_force_string (lexer) )
goto error;
- gri.sheet_name = strdup (ds_cstr (lex_tokstr (lexer)));
+ gri.sheet_name = xstrdup (ds_cstr (lex_tokstr (lexer)));
gri.sheet_index = -1;
}
else if (lex_match_id (lexer, "INDEX"))
if ( ! lex_force_string (lexer) )
goto error;
- gri.cell_range = strdup (ds_cstr (lex_tokstr (lexer)));
+ gri.cell_range = xstrdup (ds_cstr (lex_tokstr (lexer)));
}
else
goto error;
}
else
{
- printf ("Unknown data file type \"\%s\"\n", lex_tokid (lexer));
goto error;
}
lex_get (lexer);
parse_get_txt (struct lexer *lexer, struct dataset *ds)
{
struct data_parser *parser = NULL;
- struct dictionary *dict = NULL;
+ struct dictionary *dict = dict_create ();
struct file_handle *fh = NULL;
struct dfm_reader *reader = NULL;
if (fh == NULL)
goto error;
- parser = data_parser_create ();
+ parser = data_parser_create (dict);
has_type = false;
data_parser_set_type (parser, DP_DELIMITED);
data_parser_set_span (parser, false);
DP_DELIMITED, &has_type);
else
{
- lex_error (lexer, _("expecting FIXED or DELIMITED"));
+ lex_error (lexer, _("expecting %s or %s"), "FIXED", "DELIMITED");
goto error;
}
if (!ok)
}
else
{
- lex_error (lexer, _("expecting LINE or VARIABLES"));
+ lex_error (lexer, _("expecting %s or %s"), "LINE", "VARIABLES");
goto error;
}
}
ds_put_cstr (&hard_seps, "\t");
if (ss_match_string (&s, ss_cstr ("\\\\")))
ds_put_cstr (&hard_seps, "\\");
- while ((c = ss_get_char (&s)) != EOF)
+ while ((c = ss_get_byte (&s)) != EOF)
if (c == ' ')
soft_seps = " ";
else
- ds_put_char (&hard_seps, c);
+ ds_put_byte (&hard_seps, c);
data_parser_set_soft_delimiters (parser, ss_cstr (soft_seps));
data_parser_set_hard_delimiters (parser, ds_ss (&hard_seps));
ds_destroy (&hard_seps);
lex_get (lexer);
}
- else if (lex_match_id (lexer, "QUALIFIER"))
+ else if (lex_match_id (lexer, "QUALIFIERS"))
{
- if (!set_type (parser, "QUALIFIER", DP_DELIMITED, &has_type))
+ if (!set_type (parser, "QUALIFIERS", DP_DELIMITED, &has_type))
goto error;
lex_match (lexer, '=');
if (!lex_force_string (lexer))
goto error;
+ if (settings_get_syntax () == COMPATIBLE
+ && ds_length (lex_tokstr (lexer)) != 1)
+ {
+ msg (SE, _("In compatible syntax mode, the QUALIFIER string "
+ "must contain exactly one character."));
+ goto error;
+ }
+
data_parser_set_quotes (parser, ds_ss (lex_tokstr (lexer)));
lex_get (lexer);
}
+ else if (settings_get_syntax () == ENHANCED
+ && lex_match_id (lexer, "ESCAPE"))
+ data_parser_set_quote_escape (parser, true);
else if (lex_match_id (lexer, "VARIABLES"))
break;
else
{
- lex_error (lexer, _("expecting VARIABLES"));
+ lex_error (lexer, _("expecting %s"), "VARIABLES");
goto error;
}
}
lex_match (lexer, '=');
- dict = dict_create ();
+
record = 1;
type = data_parser_get_type (parser);
do