Make the expression code a little nicer and fix bugs found
[pspp] / src / list.q
index 5e312f81e9eea28e620ffc9c4b42da608534a78d..56f45342be4005cf1c02d05e83c8fd7a480de558 100644 (file)
@@ -18,7 +18,7 @@
    02111-1307, USA. */
 
 #include <config.h>
-#include <assert.h>
+#include "error.h"
 #include <stdio.h>
 #include <stdlib.h>
 #include "alloc.h"
@@ -125,7 +125,6 @@ cmd_list (void)
 {
   struct variable casenum_var;
 
-  lex_match_id ("LIST");
   if (!parse_list (&cmd))
     return CMD_FAILURE;
   
@@ -227,7 +226,7 @@ cmd_list (void)
   determine_layout ();
 
   case_num = 0;
-  procedure (write_all_headers, list_cases, NULL, NULL);
+  procedure_with_splits (write_all_headers, list_cases, NULL, NULL);
   free (line_buf);
 
   clean_up ();
@@ -669,19 +668,15 @@ list_cases (struct ccase *c, void *aux UNUSED)
                memset(&line_buf[x], ' ', width - v->print.w);
                x += width - v->print.w;
              }
-         
-           {
-             union value value;
-           
-             if (formats[v->print.type].cat & FCAT_STRING)
-               value.c = c->data[v->fv].s;
-             else if (v->fv == -1)
-               value.f = case_num;
-             else
-               value.f = c->data[v->fv].f;
-               
-             data_out (&line_buf[x], &v->print, &value);
-           }
+
+            if ((formats[v->print.type].cat & FCAT_STRING) || v->fv != -1)
+             data_out (&line_buf[x], &v->print, &c->data[v->fv]);
+            else 
+              {
+                union value case_num_value;
+                case_num_value.f = case_num;
+                data_out (&line_buf[x], &v->print, &case_num_value); 
+              }
            x += v->print.w;
          
            line_buf[x++] = ' ';
@@ -706,17 +701,16 @@ list_cases (struct ccase *c, void *aux UNUSED)
        for (column = 0; column < cmd.n_variables; column++)
          {
            struct variable *v = cmd.v_variables[column];
-           union value value;
            char buf[41];
            
-           if (formats[v->print.type].cat & FCAT_STRING)
-             value.c = c->data[v->fv].s;
-           else if (v->fv == -1)
-             value.f = case_num;
-           else
-             value.f = c->data[v->fv].f;
-               
-           data_out (buf, &v->print, &value);
+            if ((formats[v->print.type].cat & FCAT_STRING) || v->fv != -1)
+             data_out (buf, &v->print, &c->data[v->fv]);
+            else 
+              {
+                union value case_num_value;
+                case_num_value.f = case_num;
+                data_out (buf, &v->print, &case_num_value); 
+              }
            buf[v->print.w] = 0;
 
            fprintf (x->file.file, "    <TD ALIGN=RIGHT>%s</TD>\n",