projects
/
pspp-builds.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
lexer: Reimplement for better testability and internationalization.
[pspp-builds.git]
/
src
/
language
/
dictionary
/
mrsets.c
diff --git
a/src/language/dictionary/mrsets.c
b/src/language/dictionary/mrsets.c
index 6e8a050849e3290c095cbdca36ef1d187f7d70f8..3af5d033370e9b05703580eecc4a2a64cf20e63e 100644
(file)
--- a/
src/language/dictionary/mrsets.c
+++ b/
src/language/dictionary/mrsets.c
@@
-1,5
+1,5
@@
/* PSPP - a program for statistical analysis.
/* PSPP - a program for statistical analysis.
- Copyright (C) 2010 Free Software Foundation, Inc.
+ Copyright (C) 2010
, 2011
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
@@
-27,6
+27,7
@@
#include "language/lexer/variable-parser.h"
#include "libpspp/assertion.h"
#include "libpspp/hmap.h"
#include "language/lexer/variable-parser.h"
#include "libpspp/assertion.h"
#include "libpspp/hmap.h"
+#include "libpspp/i18n.h"
#include "libpspp/message.h"
#include "libpspp/str.h"
#include "libpspp/stringi-map.h"
#include "libpspp/message.h"
#include "libpspp/str.h"
#include "libpspp/stringi-map.h"
@@
-47,7
+48,7
@@
cmd_mrsets (struct lexer *lexer, struct dataset *ds)
{
struct dictionary *dict = dataset_dict (ds);
{
struct dictionary *dict = dataset_dict (ds);
- while (lex_match (lexer,
'/'
))
+ while (lex_match (lexer,
T_SLASH
))
{
bool ok;
{
bool ok;
@@
-69,7
+70,7
@@
cmd_mrsets (struct lexer *lexer, struct dataset *ds)
return CMD_FAILURE;
}
return CMD_FAILURE;
}
- return
lex_end_of_command (lexer)
;
+ return
CMD_SUCCESS
;
}
static bool
}
static bool
@@
-87,27
+88,22
@@
parse_group (struct lexer *lexer, struct dictionary *dict,
labelsource_varlabel = false;
has_value = false;
labelsource_varlabel = false;
has_value = false;
- while (lex_token (lexer) !=
'/' && lex_token (lexer) != '.'
)
+ while (lex_token (lexer) !=
T_SLASH && lex_token (lexer) != T_ENDCMD
)
{
if (lex_match_id (lexer, "NAME"))
{
{
if (lex_match_id (lexer, "NAME"))
{
- if (!lex_force_match (lexer, '=') || !lex_force_id (lexer))
+ if (!lex_force_match (lexer, T_EQUALS) || !lex_force_id (lexer)
+ || !mrset_is_valid_name (lex_tokcstr (lexer),
+ dict_get_encoding (dict), true))
goto error;
goto error;
- if (lex_tokid (lexer)[0] != '$')
- {
- msg (SE, _("%s is not a valid name for a multiple response "
- "set. Multiple response set names must begin with "
- "`$'."), lex_tokid (lexer));
- goto error;
- }
free (mrset->name);
free (mrset->name);
- mrset->name = xstrdup (lex_tok
id
(lexer));
+ mrset->name = xstrdup (lex_tok
cstr
(lexer));
lex_get (lexer);
}
else if (lex_match_id (lexer, "VARIABLES"))
{
lex_get (lexer);
}
else if (lex_match_id (lexer, "VARIABLES"))
{
- if (!lex_force_match (lexer,
'='
))
+ if (!lex_force_match (lexer,
T_EQUALS
))
goto error;
free (mrset->vars);
goto error;
free (mrset->vars);
@@
-125,16
+121,16
@@
parse_group (struct lexer *lexer, struct dictionary *dict,
}
else if (lex_match_id (lexer, "LABEL"))
{
}
else if (lex_match_id (lexer, "LABEL"))
{
- if (!lex_force_match (lexer,
'='
) || !lex_force_string (lexer))
+ if (!lex_force_match (lexer,
T_EQUALS
) || !lex_force_string (lexer))
goto error;
free (mrset->label);
goto error;
free (mrset->label);
- mrset->label =
ds_xstrdup (lex_tokstr
(lexer));
+ mrset->label =
ss_xstrdup (lex_tokss
(lexer));
lex_get (lexer);
}
else if (type == MRSET_MD && lex_match_id (lexer, "LABELSOURCE"))
{
lex_get (lexer);
}
else if (type == MRSET_MD && lex_match_id (lexer, "LABELSOURCE"))
{
- if (!lex_force_match (lexer,
'='
)
+ if (!lex_force_match (lexer,
T_EQUALS
)
|| !lex_force_match_id (lexer, "VARLABEL"))
goto error;
|| !lex_force_match_id (lexer, "VARLABEL"))
goto error;
@@
-142,7
+138,7
@@
parse_group (struct lexer *lexer, struct dictionary *dict,
}
else if (type == MRSET_MD && lex_match_id (lexer, "VALUE"))
{
}
else if (type == MRSET_MD && lex_match_id (lexer, "VALUE"))
{
- if (!lex_force_match (lexer,
'='
))
+ if (!lex_force_match (lexer,
T_EQUALS
))
goto error;
has_value = true;
goto error;
has_value = true;
@@
-159,12
+155,15
@@
parse_group (struct lexer *lexer, struct dictionary *dict,
}
else if (lex_is_string (lexer))
{
}
else if (lex_is_string (lexer))
{
- const char *s = ds_cstr (lex_tokstr (lexer));
- int width;
+ size_t width;
+ char *s;
+
+ s = recode_string (dict_get_encoding (dict), "UTF-8",
+ lex_tokcstr (lexer), -1);
+ width = strlen (s);
/* Trim off trailing spaces, but don't trim the string until
it's empty because a width of 0 is a numeric type. */
/* Trim off trailing spaces, but don't trim the string until
it's empty because a width of 0 is a numeric type. */
- width = strlen (s);
while (width > 1 && s[width - 1] == ' ')
width--;
while (width > 1 && s[width - 1] == ' ')
width--;
@@
-172,6
+171,8
@@
parse_group (struct lexer *lexer, struct dictionary *dict,
value_init (&mrset->counted, width);
memcpy (value_str_rw (&mrset->counted, width), s, width);
mrset->width = width;
value_init (&mrset->counted, width);
memcpy (value_str_rw (&mrset->counted, width), s, width);
mrset->width = width;
+
+ free (s);
}
else
{
}
else
{
@@
-182,7
+183,7
@@
parse_group (struct lexer *lexer, struct dictionary *dict,
}
else if (type == MRSET_MD && lex_match_id (lexer, "CATEGORYLABELS"))
{
}
else if (type == MRSET_MD && lex_match_id (lexer, "CATEGORYLABELS"))
{
- if (!lex_force_match (lexer,
'='
))
+ if (!lex_force_match (lexer,
T_EQUALS
))
goto error;
if (lex_match_id (lexer, "VARLABELS"))
goto error;
if (lex_match_id (lexer, "VARLABELS"))
@@
-469,24
+470,25
@@
static bool
parse_mrset_names (struct lexer *lexer, struct dictionary *dict,
struct stringi_set *mrset_names)
{
parse_mrset_names (struct lexer *lexer, struct dictionary *dict,
struct stringi_set *mrset_names)
{
- if (!lex_force_match_id (lexer, "NAME") || !lex_force_match (lexer, '='))
+ if (!lex_force_match_id (lexer, "NAME")
+ || !lex_force_match (lexer, T_EQUALS))
return false;
stringi_set_init (mrset_names);
return false;
stringi_set_init (mrset_names);
- if (lex_match (lexer,
'['
))
+ if (lex_match (lexer,
T_LBRACK
))
{
{
- while (!lex_match (lexer,
']'
))
+ while (!lex_match (lexer,
T_RBRACK
))
{
if (!lex_force_id (lexer))
return false;
{
if (!lex_force_id (lexer))
return false;
- if (dict_lookup_mrset (dict, lex_tok
id
(lexer)) == NULL)
+ if (dict_lookup_mrset (dict, lex_tok
cstr
(lexer)) == NULL)
{
msg (SE, _("No multiple response set named %s."),
{
msg (SE, _("No multiple response set named %s."),
- lex_tok
id
(lexer));
+ lex_tok
cstr
(lexer));
stringi_set_destroy (mrset_names);
return false;
}
stringi_set_destroy (mrset_names);
return false;
}
- stringi_set_insert (mrset_names, lex_tok
id
(lexer));
+ stringi_set_insert (mrset_names, lex_tok
cstr
(lexer));
lex_get (lexer);
}
}
lex_get (lexer);
}
}
@@
-577,7
+579,7
@@
parse_display (struct lexer *lexer, struct dictionary *dict)
if (mrset->width == 0)
ds_put_format (&details, "%.0f\n", mrset->counted.f);
else
if (mrset->width == 0)
ds_put_format (&details, "%.0f\n", mrset->counted.f);
else
- ds_put_format (&details, "
\"%.*s\"
\n", mrset->width,
+ ds_put_format (&details, "
`%.*s'
\n", mrset->width,
value_str (&mrset->counted, mrset->width));
ds_put_format (&details, "%s: %s\n", _("Category label source"),
(mrset->cat_source == MRSET_VARLABELS
value_str (&mrset->counted, mrset->width));
ds_put_format (&details, "%s: %s\n", _("Category label source"),
(mrset->cat_source == MRSET_VARLABELS