case: Introduce new functions for numbers and substrings in cases.
[pspp] / src / language / xforms / recode.c
index a1c2f7a4493a9413fff250e8d2bddfda488ded48..f1834cc8a5fb09daffa0a1eb68b4070e781d084e 100644 (file)
@@ -158,7 +158,7 @@ cmd_recode (struct lexer *lexer, struct dataset *ds)
          as the widest destination variable. */
       if (trns->dst_type == VAL_STRING)
        {
-         if ( ! enlarge_dst_widths (trns))
+         if (! enlarge_dst_widths (trns))
            {
              recode_trns_free (trns);
              return CMD_FAILURE;
@@ -328,7 +328,7 @@ parse_map_in (struct lexer *lexer, struct map_in *in, struct pool *pool,
         set_map_in_generic (in, MAP_MISSING);
       else if (!lex_force_string (lexer))
         return false;
-      else 
+      else
        {
          set_map_in_str (in, pool, lex_tokss (lexer), max_src_width,
                           dict_encoding);
@@ -336,7 +336,7 @@ parse_map_in (struct lexer *lexer, struct map_in *in, struct pool *pool,
          if (lex_token (lexer) == T_ID
              && lex_id_match (ss_cstr ("THRU"), lex_tokss (lexer)))
            {
-             msg (SE, _("THRU is not allowed with string variables."));
+             msg (SE, _("%s is not allowed with string variables."), "THRU");
              return false;
            }
        }
@@ -412,10 +412,10 @@ parse_map_out (struct lexer *lexer, struct pool *pool, struct map_out *out)
       set_map_out_str (out, pool, lex_tokss (lexer));
       lex_get (lexer);
     }
-  else if (lex_match_id (lexer, "COPY")) 
+  else if (lex_match_id (lexer, "COPY"))
     {
       out->copy_input = true;
-      out->width = 0; 
+      out->width = 0;
     }
   else
     {
@@ -452,7 +452,7 @@ set_map_out_str (struct map_out *out, struct pool *pool,
 
   out->copy_input = false;
   value_init_pool (pool, &out->value, length);
-  memcpy (value_str_rw (&out->value, length), string, length);
+  memcpy (out->value.s, string, length);
   out->width = length;
 }
 
@@ -541,7 +541,7 @@ enlarge_dst_widths (struct recode_trns *trns)
   const struct variable *narrow_var = NULL;
   int min_dst_width = INT_MAX;
   trns->max_dst_width = 0;
-  
+
   for (i = 0; i < trns->var_cnt; i++)
     {
       const struct variable *v = trns->dst_vars[i];
@@ -562,12 +562,12 @@ enlarge_dst_widths (struct recode_trns *trns)
        {
          if (out->width > min_dst_width)
            {
-             msg (ME, 
+             msg (ME,
                   _("Cannot recode because the variable %s would require a width of %d bytes or greater, but it has a width of only %d bytes."),
                   var_get_name (narrow_var), out->width, min_dst_width);
              return false;
            }
-           
+
          value_resize_pool (trns->pool, &out->value,
                             out->width, trns->max_dst_width);
        }
@@ -656,8 +656,7 @@ find_src_string (struct recode_trns *trns, const uint8_t *value,
       switch (in->type)
         {
         case MAP_SINGLE:
-          match = !memcmp (value, value_str (&in->x, trns->max_src_width),
-                           width);
+          match = !memcmp (value, in->x.s, width);
           break;
         case MAP_ELSE:
           match = true;
@@ -668,7 +667,8 @@ find_src_string (struct recode_trns *trns, const uint8_t *value,
             char *error;
 
             error = data_in (ss_buffer (CHAR_CAST_BUG (char *, value), width),
-                             C_ENCODING, FMT_F, &uv, 0, encoding);
+                             C_ENCODING, FMT_F, settings_get_fmt_settings (),
+                             &uv, 0, encoding);
             match = error == NULL;
             free (error);
 
@@ -710,7 +710,7 @@ recode_trns_proc (void *trns_, struct ccase **c, casenumber case_idx UNUSED)
 
       if (trns->dst_type == VAL_NUMERIC)
         {
-          double *dst = &case_data_rw (*c, dst_var)->f;
+          double *dst = case_num_rw (*c, dst_var);
           if (out != NULL)
             *dst = !out->copy_input ? out->value.f : case_num (*c, src_var);
           else if (trns->src_vars != trns->dst_vars)
@@ -722,8 +722,7 @@ recode_trns_proc (void *trns_, struct ccase **c, casenumber case_idx UNUSED)
           if (out != NULL)
             {
               if (!out->copy_input)
-                memcpy (dst, value_str (&out->value, trns->max_dst_width),
-                        var_get_width (dst_var));
+                memcpy (dst, out->value.s, var_get_width (dst_var));
               else if (trns->src_vars != trns->dst_vars)
                 {
                   union value *dst_data = case_data_rw (*c, dst_var);