X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fexpressions%2Fparse.c;h=b841953b7ea5125e3308975dab36efbda6d6d928;hb=db5df54124af56dc1dfce71f839d78da2b49e346;hp=0abfbb8a50389a161a4449127981a9f687b269de;hpb=12f1ba95a6eb660bf60b8e6a1bb09ecffee16630;p=pspp diff --git a/src/expressions/parse.c b/src/expressions/parse.c index 0abfbb8a50..b841953b7e 100644 --- a/src/expressions/parse.c +++ b/src/expressions/parse.c @@ -86,6 +86,19 @@ expr_parse (struct dictionary *dict, enum expr_type type) } } +/* Parses and returns an expression of the given TYPE, as + expr_parse(), and sets up so that destroying POOL will free + the expression as well. */ +struct expression * +expr_parse_pool (struct pool *pool, + struct dictionary *dict, enum expr_type type) +{ + struct expression *e = expr_parse (dict, type); + if (e != NULL) + pool_add_subpool (pool, e->expr_pool); + return e; +} + /* Free expression E. */ void expr_free (struct expression *e) @@ -881,14 +894,14 @@ word_matches (const char **test, const char **name) size_t name_len = strcspn (*name, "."); if (test_len == name_len) { - if (memcmp (*test, *name, test_len)) + if (buf_compare_case (*test, *name, test_len)) return false; } else if (test_len < 3 || test_len > name_len) return false; else { - if (memcmp (*test, *name, test_len)) + if (buf_compare_case (*test, *name, test_len)) return false; } @@ -917,6 +930,12 @@ compare_names (const char *test, const char *name) } } +static int +compare_strings (const char *test, const char *name) +{ + return strcasecmp (test, name); +} + static bool lookup_function_helper (const char *name, int (*compare) (const char *test, const char *name), @@ -947,7 +966,7 @@ lookup_function (const char *name, const struct operation **last) { *first = *last = NULL; - return (lookup_function_helper (name, strcmp, first, last) + return (lookup_function_helper (name, compare_strings, first, last) || lookup_function_helper (name, compare_names, first, last)); } @@ -1027,7 +1046,7 @@ validate_function_args (const struct operation *f, int arg_cnt, int min_valid) { assert ((f->flags & OPF_MIN_VALID) == 0); msg (SE, _("%s function does not accept a minimum valid " - "argument count.")); + "argument count."), f->prototype); return false; } else @@ -1036,7 +1055,7 @@ validate_function_args (const struct operation *f, int arg_cnt, int min_valid) if (array_arg_cnt < f->array_min_elems) { msg (SE, _("%s requires at least %d valid arguments in list."), - f->prototype); + f->prototype, f->array_min_elems); return false; } else if (min_valid > array_arg_cnt) @@ -1152,8 +1171,8 @@ parse_function (struct expression *e) if (token == T_ID && lex_look_ahead () == 'T') { struct variable **vars; - int var_cnt; - int i; + size_t var_cnt; + size_t i; if (!parse_variables (default_dict, &vars, &var_cnt, PV_SINGLE)) goto fail; @@ -1204,15 +1223,18 @@ parse_function (struct expression *e) n = expr_allocate_composite (e, f - operations, args, arg_cnt); n->composite.min_valid = min_valid != -1 ? min_valid : f->array_min_elems; - if (n->type == OP_LAG_Vn || n->type == OP_LAG_Vs) - n_lag = 1; + if (n->type == OP_LAG_Vn || n->type == OP_LAG_Vs) + { + if (n_lag < 1) + n_lag = 1; + } else if (n->type == OP_LAG_Vnn || n->type == OP_LAG_Vsn) { int n_before; assert (n->composite.arg_cnt == 2); assert (n->composite.args[1]->type == OP_pos_int); n_before = n->composite.args[1]->integer.i; - if (n_before > n_lag) + if (n_lag < n_before) n_lag = n_before; } @@ -1270,7 +1292,7 @@ expr_allocate_nullary (struct expression *e, operation_type op) union any_node * expr_allocate_unary (struct expression *e, operation_type op, -union any_node *arg0) + union any_node *arg0) { return expr_allocate_composite (e, op, &arg0, 1); }