X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Flanguage%2Fexpressions%2Fevaluate.c;h=6e3315c385a40ad45206ef2d6f5bc2880b2b795b;hb=0085c7edf6d3b9c9ee2ce880893023c567886101;hp=aeb374ced57d63a2bc52020257a70eab617a50f2;hpb=72147c12357446b304264b6944b8a1d92c45f53c;p=pspp
diff --git a/src/language/expressions/evaluate.c b/src/language/expressions/evaluate.c
index aeb374ced5..6e3315c385 100644
--- a/src/language/expressions/evaluate.c
+++ b/src/language/expressions/evaluate.c
@@ -1,20 +1,18 @@
-/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000, 2006 Free Software Foundation, Inc.
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 1997-9, 2000, 2006, 2007 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 the Free Software Foundation; either version 2 of the
- License, or (at your option) any later version.
+ 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
+ the Free Software Foundation, either version 3 of the License, or
+ (at your option) any later version.
- This program is distributed in the hope that it will be useful, but
- WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ along with this program. If not, see . */
#include
#include "private.h"
@@ -37,7 +35,7 @@ expr_evaluate (struct expression *e, const struct ccase *c, int case_idx,
double *ns = e->number_stack;
struct substring *ss = e->string_stack;
- /* Without a dictionary/dataset, the expression can't refer to variables,
+ /* Without a dictionary/dataset, the expression can't refer to variables,
and you don't need to specify a case when you evaluate the
expression. With a dictionary/dataset, the expression can refer
to variables, so you must specify a case when you evaluate the
@@ -72,7 +70,7 @@ expr_evaluate (struct expression *e, const struct ccase *c, int case_idx,
return;
#include "evaluate.inc"
-
+
default:
NOT_REACHED ();
}
@@ -91,14 +89,14 @@ expr_evaluate_num (struct expression *e, const struct ccase *c, int case_idx)
void
expr_evaluate_str (struct expression *e, const struct ccase *c, int case_idx,
- char *dst, size_t dst_size)
+ char *dst, size_t dst_size)
{
struct substring s;
assert (e->type == OP_string);
assert ((dst == NULL) == (dst_size == 0));
expr_evaluate (e, c, case_idx, &s);
-
+
buf_copy_rpad (dst, dst_size, s.string, s.length);
}
@@ -118,7 +116,7 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
struct expression *expr;
- for (;;)
+ for (;;)
{
struct dictionary *d = NULL;
if (lex_match_id (lexer, "NOOPTIMIZE"))
@@ -143,12 +141,12 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
if (lex_is_number (lexer))
{
width = 0;
- fprintf (stderr, "(%s = %.2f)", name, lex_tokval (lexer));
+ fprintf (stderr, "(%s = %.2f)", name, lex_tokval (lexer));
}
- else if (lex_token (lexer) == T_STRING)
+ else if (lex_token (lexer) == T_STRING)
{
width = ds_length (lex_tokstr (lexer));
- fprintf (stderr, "(%s = \"%.2s\")", name, ds_cstr (lex_tokstr (lexer)));
+ fprintf (stderr, "(%s = \"%.2s\")", name, ds_cstr (lex_tokstr (lexer)));
}
else
{
@@ -158,7 +156,7 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
if ( ds == NULL )
{
- ds = create_dataset ();
+ ds = create_dataset (NULL, NULL);
d = dataset_dict (ds);
}
@@ -170,13 +168,13 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
goto done;
}
- if (c == NULL)
+ if (c == NULL)
{
c = xmalloc (sizeof *c);
case_create (c, dict_get_next_value_idx (d));
}
else
- case_resize (c, old_value_cnt, dict_get_next_value_idx (d));
+ case_resize (c, dict_get_next_value_idx (d));
if (lex_is_number (lexer))
case_data_rw (c, v)->f = lex_tokval (lexer);
@@ -188,18 +186,18 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
if (!lex_force_match (lexer, ')'))
goto done;
}
- else
+ else
break;
}
- if (lex_token (lexer) != '/')
+ if (lex_token (lexer) != '/')
{
lex_force_match (lexer, '/');
goto done;
}
- if ( ds != NULL )
+ if ( ds != NULL )
fprintf(stderr, "; ");
- fprintf (stderr, "%s => ", lex_rest_of_line (lexer, NULL));
+ fprintf (stderr, "%s => ", lex_rest_of_line (lexer));
lex_get (lexer);
expr = expr_parse_any (lexer, ds, optimize);
@@ -211,30 +209,30 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
goto done;
}
- if (dump_postfix)
+ if (dump_postfix)
expr_debug_print_postfix (expr);
- else
- switch (expr->type)
+ else
+ switch (expr->type)
{
- case OP_number:
+ case OP_number:
{
double d = expr_evaluate_num (expr, c, 0);
if (d == SYSMIS)
fprintf (stderr, "sysmis\n");
else
- fprintf (stderr, "%.2f\n", d);
+ fprintf (stderr, "%.2f\n", d);
}
break;
-
- case OP_boolean:
+
+ case OP_boolean:
{
double b = expr_evaluate_num (expr, c, 0);
fprintf (stderr, "%s\n",
- b == SYSMIS ? "sysmis" : b == 0.0 ? "false" : "true");
+ b == SYSMIS ? "sysmis" : b == 0.0 ? "false" : "true");
}
break;
- case OP_string:
+ case OP_string:
{
struct substring s;
expr_evaluate (expr, c, 0, &s);
@@ -242,7 +240,7 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
fputc ('"', stderr);
fwrite (s.string, s.length, 1, stderr);
fputs ("\"\n", stderr);
- break;
+ break;
}
default:
@@ -256,35 +254,35 @@ cmd_debug_evaluate (struct lexer *lexer, struct dataset *dsother UNUSED)
if (ds)
destroy_dataset (ds);
- if (c != NULL)
+ if (c != NULL)
{
case_destroy (c);
- free (c);
+ free (c);
}
return retval;
}
void
-expr_debug_print_postfix (const struct expression *e)
+expr_debug_print_postfix (const struct expression *e)
{
size_t i;
- for (i = 0; i < e->op_cnt; i++)
+ for (i = 0; i < e->op_cnt; i++)
{
union operation_data *op = &e->ops[i];
if (i > 0)
putc (' ', stderr);
- switch (e->op_types[i])
+ switch (e->op_types[i])
{
case OP_operation:
if (op->operation == OP_return_number)
fprintf (stderr, "return_number");
else if (op->operation == OP_return_string)
fprintf (stderr, "return_string");
- else if (is_function (op->operation))
+ else if (is_function (op->operation))
fprintf (stderr, "%s", operations[op->operation].prototype);
- else if (is_composite (op->operation))
+ else if (is_composite (op->operation))
fprintf (stderr, "%s", operations[op->operation].name);
else
fprintf (stderr, "%s:", operations[op->operation].name);
@@ -304,7 +302,7 @@ expr_debug_print_postfix (const struct expression *e)
{
char str[FMT_STRING_LEN_MAX + 1];
fmt_to_string (op->format, str);
- fprintf (stderr, "f<%s>", str);
+ fprintf (stderr, "f<%s>", str);
}
break;
case OP_variable:
@@ -318,7 +316,7 @@ expr_debug_print_postfix (const struct expression *e)
break;
default:
NOT_REACHED ();
- }
+ }
}
fprintf (stderr, "\n");
}