projects
/
pspp
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Clean up pref.h.orig and deal with the consequences.
[pspp]
/
src
/
expr-prs.c
diff --git
a/src/expr-prs.c
b/src/expr-prs.c
index d447afdf3bbb0190f58d1a4b76ddbe709ffe6986..d8e20853652b9a6d63fc7b92f8014706cdc85c48 100644
(file)
--- a/
src/expr-prs.c
+++ b/
src/expr-prs.c
@@
-18,19
+18,19
@@
02111-1307, USA. */
#include <config.h>
02111-1307, USA. */
#include <config.h>
+#include "expr.h"
+#include "exprP.h"
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <stdlib.h>
#include <assert.h>
#include <ctype.h>
#include <float.h>
#include <stdlib.h>
+#include "algorithm.h"
#include "alloc.h"
#include "error.h"
#include "alloc.h"
#include "error.h"
-#include "expr.h"
-#include "exprP.h"
#include "lexer.h"
#include "misc.h"
#include "str.h"
#include "var.h"
#include "lexer.h"
#include "misc.h"
#include "str.h"
#include "var.h"
-#include "vector.h"
#include "vfm.h"
\f
/* Declarations. */
#include "vfm.h"
\f
/* Declarations. */
@@
-57,8
+57,8
@@
static union any_node *append_nonterminal_arg (union any_node *,
union any_node *);
static int type_check (union any_node **n, int type, int flags);
union any_node *);
static int type_check (union any_node **n, int type, int flags);
+static algo_compare_func compare_functions;
static void init_func_tab (void);
static void init_func_tab (void);
-static int cmp_func (const void *a, const void *b);
#if DEBUGGING
static void debug_print_tree (union any_node *, int);
#if DEBUGGING
static void debug_print_tree (union any_node *, int);
@@
-81,7
+81,7
@@
expr_free (struct expression *e)
free (e->num);
free (e->str);
free (e->stack);
free (e->num);
free (e->str);
free (e->stack);
-
free (e->str_stack
);
+
pool_destroy (e->pool
);
free (e);
}
free (e);
}
@@
-623,7
+623,7
@@
parse_primary (union any_node **n)
}
/* Otherwise, it must be a user variable. */
}
/* Otherwise, it must be a user variable. */
- v =
find_variable (
tokid);
+ v =
dict_lookup_var (default_dict,
tokid);
lex_get ();
if (v == NULL)
{
lex_get ();
if (v == NULL)
{
@@
-690,7
+690,7
@@
static int func_count;
static int get_num_args (struct function *, int, union any_node **);
static int
static int get_num_args (struct function *, int, union any_node **);
static int
-unary_func (struct function * f, int x
unused
, union any_node ** n)
+unary_func (struct function * f, int x
UNUSED
, union any_node ** n)
{
double divisor;
struct nonterm_node *c;
{
double divisor;
struct nonterm_node *c;
@@
-738,7
+738,7
@@
multiply:
}
static int
}
static int
-binary_func (struct function * f, int x
unused
, union any_node ** n)
+binary_func (struct function * f, int x
UNUSED
, union any_node ** n)
{
if (!get_num_args (f, 2, n))
return EX_ERROR;
{
if (!get_num_args (f, 2, n))
return EX_ERROR;
@@
-746,7
+746,7
@@
binary_func (struct function * f, int x unused, union any_node ** n)
}
static int
}
static int
-ternary_func (struct function * f, int x
unused
, union any_node ** n)
+ternary_func (struct function * f, int x
UNUSED
, union any_node ** n)
{
if (!get_num_args (f, 3, n))
return EX_ERROR;
{
if (!get_num_args (f, 3, n))
return EX_ERROR;
@@
-754,9
+754,11
@@
ternary_func (struct function * f, int x unused, union any_node ** n)
}
static int
}
static int
-MISSING_func (struct function * f, int x
unused
, union any_node ** n)
+MISSING_func (struct function * f, int x
UNUSED
, union any_node ** n)
{
{
- if (token == T_ID && is_varname (tokid) && lex_look_ahead () == ')')
+ if (token == T_ID
+ && dict_lookup_var (default_dict, tokid) != NULL
+ && lex_look_ahead () == ')')
{
struct var_node *c = xmalloc (sizeof *c);
c->v = parse_variable ();
{
struct var_node *c = xmalloc (sizeof *c);
c->v = parse_variable ();
@@
-770,11
+772,13
@@
MISSING_func (struct function * f, int x unused, union any_node ** n)
}
static int
}
static int
-SYSMIS_func (struct function * f
unused, int x unused
, union any_node ** n)
+SYSMIS_func (struct function * f
UNUSED, int x UNUSED
, union any_node ** n)
{
int t;
{
int t;
- if (token == T_ID && is_varname (tokid) && lex_look_ahead () == ')')
+ if (token == T_ID
+ && dict_lookup_var (default_dict, tokid)
+ && lex_look_ahead () == ')')
{
struct variable *v;
v = parse_variable ();
{
struct variable *v;
v = parse_variable ();
@@
-814,7
+818,7
@@
SYSMIS_func (struct function * f unused, int x unused, union any_node ** n)
}
static int
}
static int
-VALUE_func (struct function *f
unused, int x unused
, union any_node **n)
+VALUE_func (struct function *f
UNUSED, int x UNUSED
, union any_node **n)
{
struct variable *v = parse_variable ();
{
struct variable *v = parse_variable ();
@@
-835,7
+839,7
@@
VALUE_func (struct function *f unused, int x unused, union any_node **n)
}
static int
}
static int
-LAG_func (struct function *f
unused, int x unused
, union any_node **n)
+LAG_func (struct function *f
UNUSED, int x UNUSED
, union any_node **n)
{
struct variable *v = parse_variable ();
int nlag = 1;
{
struct variable *v = parse_variable ();
int nlag = 1;
@@
-893,7
+897,7
@@
nary_num_func (struct function *f, int min_args, union any_node **n)
/* FIXME: Is this condition failsafe? Can we _ever_ have two
juxtaposed identifiers otherwise? */
/* FIXME: Is this condition failsafe? Can we _ever_ have two
juxtaposed identifiers otherwise? */
- if (token == T_ID &&
is_varname (tokid)
+ if (token == T_ID &&
dict_lookup_var (default_dict, tokid) != NULL
&& toupper (lex_look_ahead ()) == 'T')
{
struct variable **v;
&& toupper (lex_look_ahead ()) == 'T')
{
struct variable **v;
@@
-905,7
+909,7
@@
nary_num_func (struct function *f, int min_args, union any_node **n)
opts |= PV_NUMERIC;
else if (type == ALPHA)
opts |= PV_STRING;
opts |= PV_NUMERIC;
else if (type == ALPHA)
opts |= PV_STRING;
- if (!parse_variables (
NULL
, &v, &nv, opts))
+ if (!parse_variables (
default_dict
, &v, &nv, opts))
goto fail;
if (nv + (*n)->nonterm.n >= m)
{
goto fail;
if (nv + (*n)->nonterm.n >= m)
{
@@
-1036,7
+1040,7
@@
fail:
}
static int
}
static int
-CONCAT_func (struct function * f
unused, int x unused
, union any_node ** n)
+CONCAT_func (struct function * f
UNUSED, int x UNUSED
, union any_node ** n)
{
int m = 0;
{
int m = 0;
@@
-1084,7
+1088,7
@@
fail:
arg; and `f', format spec (this must be the last arg). If the
optional args are included, the type becomes f->t+1. */
static int
arg; and `f', format spec (this must be the last arg). If the
optional args are included, the type becomes f->t+1. */
static int
-generic_str_func (struct function *f, int x
unused
, union any_node ** n)
+generic_str_func (struct function *f, int x
UNUSED
, union any_node ** n)
{
int max_args = 0;
int type;
{
int max_args = 0;
int type;
@@
-1220,10
+1224,10
@@
parse_function (union any_node ** n)
char fname[32], *cp;
int t;
int min_args;
char fname[32], *cp;
int t;
int min_args;
- struct vector *v;
+
const
struct vector *v;
/* Check for a vector with this name. */
/* Check for a vector with this name. */
- v =
find_vector (
tokid);
+ v =
dict_lookup_vector (default_dict,
tokid);
if (v)
{
lex_get ();
if (v)
{
lex_get ();
@@
-1232,7
+1236,7
@@
parse_function (union any_node ** n)
*n = xmalloc (sizeof (struct nonterm_node)
+ sizeof (union any_node *[2]));
*n = xmalloc (sizeof (struct nonterm_node)
+ sizeof (union any_node *[2]));
- (*n)->nonterm.type = (v->v[0]->type == NUMERIC
+ (*n)->nonterm.type = (v->v
ar
[0]->type == NUMERIC
? OP_VEC_ELEM_NUM : OP_VEC_ELEM_STR);
(*n)->nonterm.n = 0;
? OP_VEC_ELEM_NUM : OP_VEC_ELEM_STR);
(*n)->nonterm.n = 0;
@@
-1251,9
+1255,9
@@
parse_function (union any_node ** n)
msg (SE, _("`)' expected after a vector index value."));
goto fail;
}
msg (SE, _("`)' expected after a vector index value."));
goto fail;
}
- ((*n)->nonterm.arg[1]) = (union any_node *) v->i
nde
x;
+ ((*n)->nonterm.arg[1]) = (union any_node *) v->i
d
x;
- return v->v[0]->type == NUMERIC ? EX_NUMERIC : EX_STRING;
+ return v->v
ar
[0]->type == NUMERIC ? EX_NUMERIC : EX_STRING;
}
ds_truncate (&tokstr, 31);
}
ds_truncate (&tokstr, 31);
@@
-1275,7
+1279,8
@@
parse_function (union any_node ** n)
struct function f;
f.s = fname;
struct function f;
f.s = fname;
- fp = bsearch (&f, func_tab, func_count, sizeof *func_tab, cmp_func);
+ fp = binary_search (func_tab, func_count, sizeof *func_tab, &f,
+ compare_functions, NULL);
}
if (!fp)
}
if (!fp)
@@
-1468,10
+1473,8
@@
expr_type_name (int type)
default:
assert (0);
default:
assert (0);
+ return 0;
}
}
-#if __GNUC__ || __BORLANDC__
- return 0;
-#endif
}
static const char *
}
static const char *
@@
-1485,10
+1488,8
@@
type_name (int type)
return _("string");
default:
assert (0);
return _("string");
default:
assert (0);
+ return 0;
}
}
-#if __GNUC__ || __BORLANDC__
- return 0;
-#endif
}
static void
}
static void
@@
-1622,10
+1623,15
@@
static struct function func_tab[] =
{"SUBSTR", OP_SUBSTR, generic_str_func, "ssn/n"},
};
{"SUBSTR", OP_SUBSTR, generic_str_func, "ssn/n"},
};
+/* An algo_compare_func that compares functions A and B based on
+ their names. */
static int
static int
-c
mp_func (const void *a, const void *b
)
+c
ompare_functions (const void *a_, const void *b_, void *aux UNUSED
)
{
{
- return strcmp (*(char **) a, *(char **) b);
+ const struct function *a = a_;
+ const struct function *b = b_;
+
+ return strcmp (a->s, b->s);
}
static void
}
static void
@@
-1640,7
+1646,7
@@
init_func_tab (void)
}
func_count = sizeof func_tab / sizeof *func_tab;
}
func_count = sizeof func_tab / sizeof *func_tab;
-
qsort (func_tab, func_count, sizeof *func_tab, cmp_func
);
+
sort (func_tab, func_count, sizeof *func_tab, compare_functions, NULL
);
}
\f
/* Debug output. */
}
\f
/* Debug output. */