X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Flanguage%2Fexpressions%2Fparse.c;h=5054b6932105e9e8358065968e70efb9d78829b0;hb=facb4a1ad3c9e8b2cdf55824680eed2afb91aebe;hp=b311c4865a4e1e0c7788a0257a709af0ddc23835;hpb=4f382354b6bdc90dd9fe8e1a80e285fb831b6771;p=pspp diff --git a/src/language/expressions/parse.c b/src/language/expressions/parse.c index b311c4865a..5054b69321 100644 --- a/src/language/expressions/parse.c +++ b/src/language/expressions/parse.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2010 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2010, 2011, 2012, 2014 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 @@ -23,22 +23,24 @@ #include #include -#include "helpers.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "xalloc.h" +#include "data/case.h" +#include "data/dictionary.h" +#include "data/settings.h" +#include "data/variable.h" +#include "language/expressions/helpers.h" +#include "language/lexer/format-parser.h" +#include "language/lexer/lexer.h" +#include "language/lexer/variable-parser.h" +#include "libpspp/array.h" +#include "libpspp/assertion.h" +#include "libpspp/i18n.h" +#include "libpspp/message.h" +#include "libpspp/misc.h" +#include "libpspp/pool.h" +#include "libpspp/str.h" + +#include "gl/c-strcase.h" +#include "gl/xalloc.h" /* Declarations. */ @@ -261,8 +263,9 @@ type_check (struct expression *e, atom_type_name (actual_type)); return false; } - if (actual_type == OP_number && expected_type == OP_boolean) - *n = expr_allocate_unary (e, OP_NUM_TO_BOOLEAN, *n); + if (actual_type == OP_number && expected_type == EXPR_BOOLEAN) + *n = expr_allocate_binary (e, OP_NUM_TO_BOOLEAN, *n, + expr_allocate_string (e, ss_empty ())); break; case EXPR_STRING: @@ -785,12 +788,14 @@ parse_sysvar (struct lexer *lexer, struct expression *e) time_t last_proc_time = time_of_last_procedure (e->ds); struct tm *time; char temp_buf[10]; + struct substring s; time = localtime (&last_proc_time); sprintf (temp_buf, "%02d %s %02d", abs (time->tm_mday) % 100, months[abs (time->tm_mon) % 12], abs (time->tm_year) % 100); - return expr_allocate_string_buffer (e, temp_buf, strlen (temp_buf)); + ss_alloc_substring (&s, ss_cstr (temp_buf)); + return expr_allocate_string (e, s); } else if (lex_match_id (lexer, "$TRUE")) return expr_allocate_boolean (e, 1.0); @@ -836,7 +841,7 @@ parse_primary (struct lexer *lexer, struct expression *e) switch (lex_token (lexer)) { case T_ID: - if (lex_look_ahead (lexer) == T_LPAREN) + if (lex_next_token (lexer, 1) == T_LPAREN) { /* An identifier followed by a left parenthesis may be a vector element reference. If not, it's a function @@ -887,8 +892,17 @@ parse_primary (struct lexer *lexer, struct expression *e) case T_STRING: { - union any_node *node = expr_allocate_string_buffer ( - e, lex_tokcstr (lexer), ss_length (lex_tokss (lexer))); + const char *dict_encoding; + union any_node *node; + char *s; + + dict_encoding = (e->ds != NULL + ? dict_get_encoding (dataset_dict (e->ds)) + : "UTF-8"); + s = recode_string_pool (dict_encoding, "UTF-8", lex_tokcstr (lexer), + ss_length (lex_tokss (lexer)), e->expr_pool); + node = expr_allocate_string (e, ss_cstr (s)); + lex_get (lexer); return node; } @@ -993,7 +1007,7 @@ compare_names (const char *test, const char *name, bool abbrev_ok) static int compare_strings (const char *test, const char *name, bool abbrev_ok UNUSED) { - return strcasecmp (test, name); + return c_strcasecmp (test, name); } static bool @@ -1231,7 +1245,7 @@ parse_function (struct lexer *lexer, struct expression *e) for (;;) { if (lex_token (lexer) == T_ID - && toupper (lex_look_ahead (lexer)) == T_ID) + && lex_next_token (lexer, 1) == T_TO) { const struct variable **vars; size_t var_cnt; @@ -1256,8 +1270,7 @@ parse_function (struct lexer *lexer, struct expression *e) break; else if (!lex_match (lexer, T_COMMA)) { - lex_error (lexer, _("expecting `,' or `)' invoking %s function"), - first->name); + lex_error_expecting (lexer, "`,'", "`)'"); goto fail; } } @@ -1279,13 +1292,14 @@ parse_function (struct lexer *lexer, struct expression *e) msg (SW, _("%s is a PSPP extension."), f->prototype); if (f->flags & OPF_UNIMPLEMENTED) { - msg (SE, _("%s is not yet implemented."), f->prototype); + msg (SE, _("%s is not available in this version of PSPP."), + f->prototype); goto fail; } if ((f->flags & OPF_PERM_ONLY) && proc_in_temporary_transformations (e->ds)) { - msg (SE, _("%s may not appear after TEMPORARY."), f->prototype); + msg (SE, _("%s may not appear after %s."), f->prototype, "TEMPORARY"); goto fail; } @@ -1473,18 +1487,6 @@ expr_allocate_vector (struct expression *e, const struct vector *vector) return n; } -union any_node * -expr_allocate_string_buffer (struct expression *e, - const char *string, size_t length) -{ - union any_node *n = pool_alloc (e->expr_pool, sizeof n->string); - n->type = OP_string; - if (length > MAX_STRING) - length = MAX_STRING; - n->string.s = copy_string (e, string, length); - return n; -} - union any_node * expr_allocate_string (struct expression *e, struct substring s) {