treewide: Replace <name>_cnt by n_<name>s and <name>_cap by allocated_<name>.
[pspp] / src / language / stats / rank.c
index 857d6f5dff552c6f53aa74e5bb3c26364b440e1f..ecf9a65914bd6403ceb3defd673463b3dd647cff 100644 (file)
@@ -91,14 +91,14 @@ enum rank_func
   };
 
 static const struct fmt_spec dest_format[n_RANK_FUNCS] = {
-  {FMT_F, 9, 3}, /* rank */
-  {FMT_F, 6, 4}, /* normal */
-  {FMT_F, 6, 2}, /* percent */
-  {FMT_F, 6, 4}, /* rfraction */
-  {FMT_F, 6, 4}, /* proportion */
-  {FMT_F, 6, 0}, /* n */
-  {FMT_F, 3, 0}, /* ntiles */
-  {FMT_F, 8, 4}  /* savage */
+  [RANK]       = { .type = FMT_F, .w = 9, .d = 3 },
+  [NORMAL]     = { .type = FMT_F, .w = 6, .d = 4 },
+  [PERCENT]    = { .type = FMT_F, .w = 6, .d = 2 },
+  [RFRACTION]  = { .type = FMT_F, .w = 6, .d = 4 },
+  [PROPORTION] = { .type = FMT_F, .w = 6, .d = 4 },
+  [N]          = { .type = FMT_F, .w = 6, .d = 0 },
+  [NTILES]     = { .type = FMT_F, .w = 3, .d = 0 },
+  [SAVAGE]     = { .type = FMT_F, .w = 8, .d = 4 }
 };
 
 static const char * const function_name[n_RANK_FUNCS] = {
@@ -290,7 +290,7 @@ parse_into (struct lexer *lexer, struct rank *cmd,
       if (!lex_force_match (lexer, T_LPAREN))
        return false;
 
-      if (! lex_force_int (lexer))
+      if (! lex_force_int_range (lexer, "NTILES", 1, INT_MAX))
        return false;
 
       cmd->k_ntiles = lex_integer (lexer);
@@ -573,12 +573,12 @@ rank_sorted_file (struct casereader *input,
           size_t i;
 
           out_case = case_create (casewriter_get_proto (output));
-          case_data_rw_idx (out_case, 0)->f = case_num_idx (c, 1);
+          *case_num_rw_idx (out_case, 0) = case_num_idx (c, 1);
           for (i = 0; i < cmd->n_rs; ++i)
             {
               rank_function_t func = rank_func[cmd->rs[i].rfunc];
               double rank = func (cmd, tw, cc, cc_1, tie_group, w);
-              case_data_rw_idx (out_case, i + 1)->f = rank;
+              *case_num_rw_idx (out_case, i + 1) = rank;
             }
 
           casewriter_write (output, out_case);
@@ -661,6 +661,7 @@ cmd_rank (struct lexer *lexer, struct dataset *ds)
   rank.ties = TIES_MEAN;
   rank.fraction = FRAC_BLOM;
   rank.print = true;
+  rank.vars = NULL;
   rank.pool = pool_create ();
 
   string_set_init (&new_names);
@@ -823,7 +824,6 @@ cmd_rank (struct lexer *lexer, struct dataset *ds)
     {
       struct pivot_table *table = pivot_table_create (
         N_("Variables Created by RANK"));
-      table->look.omit_empty = true;
 
       pivot_dimension_create (table, PIVOT_AXIS_COLUMN, N_("New Variable"),
                               N_("New Variable"), N_("Function"),
@@ -929,7 +929,7 @@ rank_trns_proc (void *trns_, struct ccase **c, casenumber case_idx UNUSED)
             size_t i;
 
             for (i = 0; i < trns->n_funcs; i++)
-              case_data_rw (*c, iv->output_vars[i])->f
+              *case_num_rw (*c, iv->output_vars[i])
                 = case_num_idx (iv->current, i + 1);
             advance_ranking (iv);
             break;
@@ -1032,11 +1032,11 @@ rank_cmd (struct dataset *ds, const struct rank *cmd)
       subcase_add_vars_always (&projection,
                                cmd->group_vars, cmd->n_group_vars);
       subcase_add_vars_always (&projection, dict_get_split_vars (d),
-                               dict_get_split_cnt (d));
+                               dict_get_n_splits (d));
       if (weight_var != NULL)
         {
           subcase_add_var_always (&projection, weight_var, SC_ASCEND);
-          weight_idx = 2 + cmd->n_group_vars + dict_get_split_cnt (d);
+          weight_idx = 2 + cmd->n_group_vars + dict_get_n_splits (d);
         }
       else
         weight_idx = -1;
@@ -1057,7 +1057,7 @@ rank_cmd (struct dataset *ds, const struct rank *cmd)
 
       /* Group by split variables */
       subcase_init_empty (&split_vars);
-      for (j = 0; j < dict_get_split_cnt (d); j++)
+      for (j = 0; j < dict_get_n_splits (d); j++)
         subcase_add_always (&split_vars, 2 + j + cmd->n_group_vars,
                             var_get_width (dict_get_split_vars (d)[j]),
                             SC_ASCEND);