X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Flexer%2Fvariable-parser.c;h=8c4f8fe8a61acff13b83aee122c76ed2b4140e6c;hb=083db3f94e6d84ce23e3680b2946e4398dd3c83c;hp=49d6a5deb900a6e63e8363b1fd020c685116f16c;hpb=2be9bee9da6a2ce27715e58128569594319abfa2;p=pspp diff --git a/src/language/lexer/variable-parser.c b/src/language/lexer/variable-parser.c index 49d6a5deb9..8c4f8fe8a6 100644 --- a/src/language/lexer/variable-parser.c +++ b/src/language/lexer/variable-parser.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009, 2010, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 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 @@ -30,6 +30,7 @@ #include "libpspp/assertion.h" #include "libpspp/cast.h" #include "libpspp/hash-functions.h" +#include "libpspp/i18n.h" #include "libpspp/hmapx.h" #include "libpspp/message.h" #include "libpspp/misc.h" @@ -37,6 +38,8 @@ #include "libpspp/str.h" #include "libpspp/stringi-set.h" +#include "math/interaction.h" + #include "gl/c-ctype.h" #include "gl/xalloc.h" @@ -817,9 +820,9 @@ array_var_set_lookup_var_idx (const struct var_set *vs, const char *name, struct hmapx_node *node; struct variable **varp; - HMAPX_FOR_EACH_WITH_HASH (varp, node, hash_case_string (name, 0), + HMAPX_FOR_EACH_WITH_HASH (varp, node, utf8_hash_case_string (name, 0), &avs->vars_by_name) - if (!strcasecmp (name, var_get_name (*varp))) + if (!utf8_strcasecmp (name, var_get_name (*varp))) { *idx = varp - avs->var; return true; @@ -867,9 +870,76 @@ var_set_create_from_array (struct variable *const *var, size_t var_cnt) return NULL; } hmapx_insert (&avs->vars_by_name, CONST_CAST (void *, &avs->var[i]), - hash_case_string (name, 0)); + utf8_hash_case_string (name, 0)); } return vs; } + +/* Match a variable. + If the match succeeds, the variable will be placed in VAR. + Returns true if successful */ +bool +lex_match_variable (struct lexer *lexer, const struct dictionary *dict, const struct variable **var) +{ + if (lex_token (lexer) != T_ID) + return false; + + *var = parse_variable_const (lexer, dict); + + if ( *var == NULL) + return false; + return true; +} + +/* An interaction is a variable followed by {*, BY} followed by an interaction */ +static bool +parse_internal_interaction (struct lexer *lexer, const struct dictionary *dict, struct interaction **iact, struct interaction **it) +{ + const struct variable *v = NULL; + assert (iact); + + switch (lex_next_token (lexer, 1)) + { + case T_ENDCMD: + case T_SLASH: + case T_COMMA: + case T_ID: + case T_BY: + case T_ASTERISK: + break; + default: + return false; + break; + } + + if (! lex_match_variable (lexer, dict, &v)) + { + if (it) + interaction_destroy (*it); + *iact = NULL; + return false; + } + + assert (v); + + if ( *iact == NULL) + *iact = interaction_create (v); + else + interaction_add_variable (*iact, v); + + if ( lex_match (lexer, T_ASTERISK) || lex_match (lexer, T_BY)) + { + return parse_internal_interaction (lexer, dict, iact, iact); + } + + return true; +} + +bool +parse_design_interaction (struct lexer *lexer, const struct dictionary *dict, struct interaction **iact) +{ + return parse_internal_interaction (lexer, dict, iact, NULL); +} +