Separate table functions that format their arguments from those that don't.
[pspp-builds.git] / src / language / stats / oneway.q
index 40107f77c877205af42c9555ac1c329f29b39d47..0f6b20a1db04cdf9503e4a21cd67cb2f22ecf6bf 100644 (file)
@@ -261,7 +261,7 @@ show_anova_table (void)
 
   t = tab_create (n_cols, n_rows, 0);
   tab_headers (t, 2, 0, 1, 0);
-  tab_dim (t, tab_natural_dimensions);
+  tab_dim (t, tab_natural_dimensions, NULL);
 
 
   tab_box (t,
@@ -372,7 +372,7 @@ show_descriptives (const struct dictionary *dict)
 
   t = tab_create (n_cols, n_rows, 0);
   tab_headers (t, 2, 0, 2, 0);
-  tab_dim (t, tab_natural_dimensions);
+  tab_dim (t, tab_natural_dimensions, NULL);
 
 
   /* Put a frame around the entire box, and vertical lines inside */
@@ -394,8 +394,9 @@ show_descriptives (const struct dictionary *dict)
 
   tab_vline (t, TAL_0, 7, 0, 0);
   tab_hline (t, TAL_1, 6, 7, 1);
-  tab_joint_text (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE | TAT_PRINTF,
-                 _("%g%% Confidence Interval for Mean"), confidence*100.0);
+  tab_joint_text_format (t, 6, 0, 7, 0, TAB_CENTER | TAT_TITLE,
+                         _("%g%% Confidence Interval for Mean"),
+                         confidence*100.0);
 
   tab_text (t, 6, 1, TAB_CENTER | TAT_TITLE, _("Lower Bound"));
   tab_text (t, 7, 1, TAB_CENTER | TAT_TITLE, _("Upper Bound"));
@@ -518,7 +519,7 @@ show_homogeneity (void)
 
   t = tab_create (n_cols, n_rows, 0);
   tab_headers (t, 1, 0, 1, 0);
-  tab_dim (t, tab_natural_dimensions);
+  tab_dim (t, tab_natural_dimensions, NULL);
 
   /* Put a frame around the entire box, and vertical lines inside */
   tab_box (t,
@@ -571,7 +572,6 @@ show_contrast_coeffs (short *bad_contrast)
 {
   int n_cols = 2 + ostensible_number_of_groups;
   int n_rows = 2 + cmd.sbc_contrast;
-  union value *group_value;
   int count = 0;
   void *const *group_values;
 
@@ -579,7 +579,7 @@ show_contrast_coeffs (short *bad_contrast)
 
   t = tab_create (n_cols, n_rows, 0);
   tab_headers (t, 2, 0, 2, 0);
-  tab_dim (t, tab_natural_dimensions);
+  tab_dim (t, tab_natural_dimensions, NULL);
 
   /* Put a frame around the entire box, and vertical lines inside */
   tab_box (t,
@@ -618,13 +618,16 @@ show_contrast_coeffs (short *bad_contrast)
        count < hsh_count (global_group_hash);
        ++count)
     {
+      double *group_value_p;
+      union value group_value;
       int i;
       struct string vstr;
-      group_value = group_values[count];
 
       ds_init_empty (&vstr);
 
-      var_append_value_name (indep_var, group_value, &vstr);
+      group_value_p = group_values[count];
+      group_value.f = *group_value_p;
+      var_append_value_name (indep_var, &group_value, &vstr);
 
       tab_text (t, count + 2, 1, TAB_CENTER | TAT_TITLE,
                ds_cstr (&vstr));
@@ -634,14 +637,13 @@ show_contrast_coeffs (short *bad_contrast)
 
       for (i = 0; i < cmd.sbc_contrast; ++i )
        {
-         tab_text (t, 1, i + 2, TAB_CENTER | TAT_PRINTF, "%d", i + 1);
+         tab_text_format (t, 1, i + 2, TAB_CENTER, "%d", i + 1);
 
          if ( bad_contrast[i] )
            tab_text (t, count + 2, i + 2, TAB_RIGHT, "?" );
          else
-           tab_text (t, count + 2, i + 2, TAB_RIGHT | TAT_PRINTF, "%g",
-                     subc_list_double_at (&cmd.dl_contrast[i], count)
-                     );
+           tab_text_format (t, count + 2, i + 2, TAB_RIGHT, "%g",
+                             subc_list_double_at (&cmd.dl_contrast[i], count));
        }
     }
 
@@ -661,7 +663,7 @@ show_contrast_tests (short *bad_contrast)
 
   t = tab_create (n_cols, n_rows, 0);
   tab_headers (t, 3, 0, 1, 0);
-  tab_dim (t, tab_natural_dimensions);
+  tab_dim (t, tab_natural_dimensions, NULL);
 
   /* Put a frame around the entire box, and vertical lines inside */
   tab_box (t,
@@ -738,12 +740,13 @@ show_contrast_tests (short *bad_contrast)
                        _("Does not assume equal"));
            }
 
-         tab_text (t,  2, (v * lines_per_variable) + i + 1,
-                   TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d", i + 1);
+         tab_text_format (t,  2, (v * lines_per_variable) + i + 1,
+                           TAB_CENTER | TAT_TITLE, "%d", i + 1);
 
 
-         tab_text (t,  2, (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
-                   TAB_CENTER | TAT_TITLE | TAT_PRINTF, "%d", i + 1);
+         tab_text_format (t,  2,
+                           (v * lines_per_variable) + i + 1 + cmd.sbc_contrast,
+                           TAB_CENTER | TAT_TITLE, "%d", i + 1);
 
 
          if ( bad_contrast[i])
@@ -878,10 +881,25 @@ precalc (struct cmd_oneway *cmd UNUSED)
     }
 }
 
+static int
+compare_double_3way (const void *a_, const void *b_, const void *aux UNUSED)
+{
+  const double *a = a_;
+  const double *b = b_;
+  return *a < *b ? -1 : *a > *b;
+}
+
+static unsigned
+do_hash_double (const void *value_, const void *aux UNUSED)
+{
+  const double *value = value_;
+  return hash_double (*value, 0);
+}
+
 static void
-free_value (void *value_, const void *aux UNUSED)
+free_double (void *value_, const void *aux UNUSED)
 {
-  union value *value = value_;
+  double *value = value_;
   free (value);
 }
 
@@ -908,9 +926,9 @@ run_oneway (struct cmd_oneway *cmd,
   taint = taint_clone (casereader_get_taint (input));
 
   global_group_hash = hsh_create (4,
-                                 compare_values_short,
-                                 hash_value_short,
-                                 free_value,
+                                 compare_double_3way,
+                                 do_hash_double,
+                                 free_double,
                                  indep_var);
 
   precalc (cmd);
@@ -931,9 +949,12 @@ run_oneway (struct cmd_oneway *cmd,
       const double weight = dict_get_case_weight (dict, c, NULL);
 
       const union value *indep_val = case_data (c, indep_var);
-      void **p = hsh_probe (global_group_hash, indep_val);
+      void **p = hsh_probe (global_group_hash, &indep_val->f);
       if (*p == NULL)
-        *p = value_dup (indep_val, var_get_width (indep_var));
+        {
+          double *value = *p = xmalloc (sizeof *value);
+          *value = indep_val->f;
+        }
 
       for (i = 0; i < n_vars; ++i)
        {