CTABLES strings work
[pspp] / src / language / stats / ctables.c
index 3b7dc24d1051daded14b47a9fc25fc6f6c42263f..a69e8d56593a035aad6e6fba5c249681a8c45387 100644 (file)
@@ -4261,7 +4261,6 @@ ctables_pcexpr_evaluate (const struct ctables_pcexpr_evaluate_ctx *ctx,
       }
 
     case CTPO_CAT_NUMBER:
-    case CTPO_CAT_STRING:
     case CTPO_CAT_MISSING:
     case CTPO_CAT_OTHERNM:
     case CTPO_CAT_SUBTOTAL:
@@ -4275,6 +4274,25 @@ ctables_pcexpr_evaluate (const struct ctables_pcexpr_evaluate_ctx *ctx,
         return ctables_pcexpr_evaluate_category (ctx, &cv);
       }
 
+    case CTPO_CAT_STRING:
+      {
+        int width = var_get_width (ctx->section->nests[ctx->pc_a]->vars[ctx->pc_a_idx]);
+        char *s = NULL;
+        if (width > e->string.length)
+          {
+            s = xmalloc (width);
+            buf_copy_rpad (s, width, e->string.string, e->string.length, ' ');
+          }
+        struct ctables_cell_value cv = {
+          .category = ctables_find_category_for_postcompute (ctx->section->table->ctables->dict, ctx->cats, ctx->parse_format, e),
+          .value = { .s = CHAR_CAST (uint8_t *, s ? s : e->string.string) },
+        };
+        assert (cv.category != NULL);
+        double retval = ctables_pcexpr_evaluate_category (ctx, &cv);
+        free (s);
+        return retval;
+      }
+
     case CTPO_ADD:
       return ctables_pcexpr_evaluate_nonterminal (ctx, e, 2, ctpo_add);