Encapsulated the static data of procedure.[ch] into a single object, to be
[pspp-builds.git] / src / language / expressions / evaluate.c
index 4283af25184ea858e42c617c48773a1ca550823b..fd12a04b059de0b2972f8f86c8e43a5d3c9ea4c8 100644 (file)
@@ -22,6 +22,7 @@
 
 #include <ctype.h>
 #include <libpspp/alloc.h>
+#include <libpspp/assertion.h>
 #include <libpspp/message.h>
 #include "helpers.h"
 #include "evaluate.h"
@@ -34,7 +35,7 @@ expr_evaluate (struct expression *e, const struct ccase *c, int case_idx,
   union operation_data *op = e->ops;
 
   double *ns = e->number_stack;
-  struct fixed_string *ss = e->string_stack;
+  struct substring *ss = e->string_stack;
 
   assert ((c != NULL) == (e->dict != NULL));
   pool_clear (e->eval_pool);
@@ -51,7 +52,7 @@ expr_evaluate (struct expression *e, const struct ccase *c, int case_idx,
 
         case OP_string:
           {
-            const struct fixed_string *s = &op++->string;
+            const struct substring *s = &op++->string;
             *ss++ = copy_string (e, s->string, s->length);
           }
           break;
@@ -61,13 +62,13 @@ expr_evaluate (struct expression *e, const struct ccase *c, int case_idx,
           return;
 
         case OP_return_string:
-          *(struct fixed_string *) result = ss[-1];
+          *(struct substring *) result = ss[-1];
           return;
 
 #include "evaluate.inc"
           
        default:
-         abort ();
+         NOT_REACHED ();
        }
     }
 }
@@ -88,13 +89,13 @@ void
 expr_evaluate_str (struct expression *e, const struct ccase *c, int case_idx,
                    char *dst, size_t dst_size) 
 {
-  struct fixed_string s;
+  struct substring s;
 
   assert (e->type == OP_string);
   assert ((dst == NULL) == (dst_size == 0));
   expr_evaluate (e, c, case_idx, &s);
   
-  copy_mangle (dst, dst_size, s.string, s.length);
+  buf_copy_rpad (dst, dst_size, s.string, s.length);
 }
 \f
 #include <language/lexer/lexer.h>
@@ -140,7 +141,7 @@ cmd_debug_evaluate (void)
           else if (token == T_STRING) 
             {
               width = ds_length (&tokstr);
-              fprintf (stderr, "(%s = \"%.2s\")", name, ds_c_str (&tokstr)); 
+              fprintf (stderr, "(%s = \"%.2s\")", name, ds_cstr (&tokstr)); 
             }
           else
             {
@@ -162,9 +163,10 @@ cmd_debug_evaluate (void)
           if (c == NULL) 
             {
               c = xmalloc (sizeof *c);
-              case_nullify (c);
+              case_create (c, dict_get_next_value_idx (d));
             }
-          case_resize (c, old_value_cnt, dict_get_next_value_idx (d));
+          else
+            case_resize (c, old_value_cnt, dict_get_next_value_idx (d));
 
           if (lex_is_number ())
             case_data_rw (c, v->fv)->f = tokval;
@@ -223,7 +225,7 @@ cmd_debug_evaluate (void)
 
       case OP_string: 
         {
-          struct fixed_string s;
+          struct substring s;
           expr_evaluate (expr, c, 0, &s);
 
           fputc ('"', stderr);
@@ -233,7 +235,7 @@ cmd_debug_evaluate (void)
         }
 
       default:
-        assert (0);
+        NOT_REACHED ();
       }
 
   expr_free (expr);
@@ -299,7 +301,7 @@ expr_debug_print_postfix (const struct expression *e)
           fprintf (stderr, "i<%d>", op->integer);
           break;
         default:
-          abort ();
+          NOT_REACHED ();
         } 
     }
   fprintf (stderr, "\n");