Descriptives: Constness
[pspp] / src / language / stats / autorecode.c
index dc357f7c4482496be6182c8698c53e820da24503..e7d06a818ddfa7c8d860943d82d492696d0d9111 100644 (file)
@@ -105,7 +105,7 @@ static bool
 value_is_blank (const union value *val, int width, const struct dictionary *dict)
 {
   mbi_iterator_t iter;
-  const char *str = CHAR_CAST_BUG (const char*, value_str (val, width));
+  const char *str = CHAR_CAST_BUG (const char *, val->s);
   char *text = recode_string (UTF8, dict_get_encoding (dict), str, width);
 
   for (mbi_init (iter, text, width); mbi_avail (iter); mbi_advance (iter))
@@ -140,7 +140,6 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
   struct casereader *input;
   struct ccase *c;
 
-  size_t i;
   bool ok;
 
   /* Create procedure. */
@@ -153,6 +152,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
   if (!parse_variables_const (lexer, dict, &src_vars, &n_srcs,
                               PV_NO_DUPLICATE | PV_NO_SCRATCH))
     goto error;
+  lex_match (lexer, T_SLASH);
   if (!lex_force_match_id (lexer, "INTO"))
     goto error;
   lex_match (lexer, T_EQUALS);
@@ -167,7 +167,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
 
       goto error;
     }
-  for (i = 0; i < n_dsts; i++)
+  for (size_t i = 0; i < n_dsts; i++)
     {
       const char *name = dst_names[i];
 
@@ -206,10 +206,16 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
              arc->blank_valid = false;
            }
          else
-           goto error;
+            {
+              lex_error_expecting (lexer, "VALID", "MISSING");
+              goto error;
+            }
        }
       else
-       goto error;
+        {
+          lex_error_expecting (lexer, "DESCENDING", "PRINT", "GROUP", "BLANK");
+          goto error;
+        }
     }
 
   if (lex_token (lexer) != T_ENDCMD)
@@ -222,7 +228,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
   arc->n_specs = n_dsts;
 
 
-  for (i = 0; i < n_dsts; i++)
+  for (size_t i = 0; i < n_dsts; i++)
     {
       struct arc_spec *spec = &arc->specs[i];
 
@@ -246,7 +252,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
   /* Execute procedure. */
   input = proc_open (ds);
   for (; (c = casereader_read (input)) != NULL; case_unref (c))
-    for (i = 0; i < arc->n_specs; i++)
+    for (size_t i = 0; i < arc->n_specs; i++)
       {
         struct arc_spec *spec = &arc->specs[i];
         int width = spec->width;
@@ -256,7 +262,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
 
         item = find_arc_item (spec, value, hash);
         if ( (item == NULL)
-            &&  
+            &&
             ( arc->blank_valid
                || val_type_from_width (spec->width) == VAL_NUMERIC
                || ! value_is_blank (value, width, dict))
@@ -276,7 +282,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
   dict = dataset_dict (ds);
 
   /* Create transformation. */
-  for (i = 0; i < arc->n_specs; i++)
+  for (size_t i = 0; i < arc->n_specs; i++)
     {
       struct arc_spec *spec = &arc->specs[i];
       struct arc_item **items;
@@ -311,21 +317,21 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
          value_init (&to_val, 0);
 
          items[j]->to = direction == ASCENDING ? j + 1 : n_items - j;
-         
+
          to_val.f = items[j]->to;
 
          /* Add value labels to the destination variable which indicate
             the source value from whence the new value comes. */
          if (src_width > 0)
            {
-             const char *str = CHAR_CAST_BUG (const char*, value_str (from, src_width));
+             const char *str = CHAR_CAST_BUG (const char *, from->s);
 
              recoded_value = recode_string (UTF8, dict_get_encoding (dict),
                                              str, src_width);
            }
          else
            recoded_value = c_xasprintf ("%.*g", DBL_DIG + 1, from->f);
-         
+
          /* Remove trailing whitespace */
           len = strlen (recoded_value);
           while (len > 0 && recoded_value[len - 1] == ' ')
@@ -341,7 +347,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
     }
   add_transformation (ds, autorecode_trns_proc, autorecode_trns_free, arc);
 
-  for (i = 0; i < n_dsts; i++)
+  for (size_t i = 0; i < n_dsts; i++)
     free (dst_names[i]);
   free (dst_names);
   free (src_vars);
@@ -349,7 +355,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
   return ok ? CMD_SUCCESS : CMD_CASCADING_FAILURE;
 
 error:
-  for (i = 0; i < n_dsts; i++)
+  for (size_t i = 0; i < n_dsts; i++)
     free (dst_names[i]);
   free (dst_names);
   free (src_vars);
@@ -362,9 +368,7 @@ arc_free (struct autorecode_pgm *arc)
 {
   if (arc != NULL)
     {
-      size_t i;
-
-      for (i = 0; i < arc->n_specs; i++)
+      for (size_t i = 0; i < arc->n_specs; i++)
         {
           struct arc_spec *spec = &arc->specs[i];
           struct arc_item *item, *next;
@@ -378,10 +382,10 @@ arc_free (struct autorecode_pgm *arc)
            }
         }
 
-      for (i = 0; i < arc->n_specs; i++)
+      for (size_t i = 0; i < arc->n_specs; i++)
        {
          struct arc_spec *spec = &arc->specs[i];
-         
+
          if (--spec->items->refcnt == 0)
            {
              hmap_destroy (&spec->items->ht);
@@ -394,7 +398,7 @@ arc_free (struct autorecode_pgm *arc)
          hmap_destroy (&arc->global_items->ht);
          free (arc->global_items);
        }
-      
+
       free (arc->specs);
       free (arc);
     }
@@ -429,8 +433,8 @@ compare_arc_items (const void *a_, const void *b_, const void *aux UNUSED)
   if ( width_b == 0 && width_a != 0)
     return +1;
 
-  return buf_compare_rpad (CHAR_CAST_BUG (const char *, value_str (&(*a)->from, width_a)), width_a,
-                          CHAR_CAST_BUG (const char *, value_str (&(*b)->from, width_b)), width_b);
+  return buf_compare_rpad (CHAR_CAST_BUG (const char *, (*a)->from.s), width_a,
+                          CHAR_CAST_BUG (const char *, (*b)->from.s), width_b);
 }
 
 static int
@@ -438,10 +442,9 @@ autorecode_trns_proc (void *arc_, struct ccase **c,
                       casenumber case_idx UNUSED)
 {
   struct autorecode_pgm *arc = arc_;
-  size_t i;
 
   *c = case_unshare (*c);
-  for (i = 0; i < arc->n_specs; i++)
+  for (size_t i = 0; i < arc->n_specs; i++)
     {
       const struct arc_spec *spec = &arc->specs[i];
       const union value *value = case_data_idx (*c, spec->src_idx);