variable: Make var_set_label() use the variable's own encoding.
[pspp-builds.git] / src / language / stats / descriptives.c
index 50d52d3cff03f68d2bac2d9d0a84097b961ae032..017b78c277a175ad4feeacedb0306db6b98d57e0 100644 (file)
@@ -22,8 +22,8 @@
 
 #include "data/casegrouper.h"
 #include "data/casereader.h"
+#include "data/dataset.h"
 #include "data/dictionary.h"
-#include "data/procedure.h"
 #include "data/transformations.h"
 #include "data/variable.h"
 #include "language/command.h"
 #include "language/lexer/lexer.h"
 #include "language/lexer/variable-parser.h"
 #include "libpspp/array.h"
+#include "libpspp/assertion.h"
 #include "libpspp/compiler.h"
+#include "libpspp/i18n.h"
 #include "libpspp/message.h"
-#include "libpspp/assertion.h"
 #include "math/moments.h"
 #include "output/tab.h"
 
@@ -303,7 +304,7 @@ cmd_descriptives (struct lexer *lexer, struct dataset *ds)
         }
       else if (var_cnt == 0)
         {
-          if (lex_look_ahead (lexer) == T_EQUALS)
+          if (lex_next_token (lexer, 1) == T_EQUALS)
             {
               lex_match_id (lexer, "VARIABLES");
               lex_match (lexer, T_EQUALS);
@@ -507,17 +508,22 @@ static char *
 generate_z_varname (const struct dictionary *dict, struct dsc_proc *dsc,
                     const char *var_name, int *z_cnt)
 {
-  char name[VAR_NAME_LEN + 1];
+  char *z_name, *trunc_name;
 
   /* Try a name based on the original variable name. */
-  name[0] = 'Z';
-  str_copy_trunc (name + 1, sizeof name - 1, var_name);
-  if (try_name (dict, dsc, name))
-    return xstrdup (name);
+  z_name = xasprintf ("Z%s", var_name);
+  trunc_name = utf8_encoding_trunc (z_name, dict_get_encoding (dict),
+                                    ID_MAX_LEN);
+  free (z_name);
+  if (try_name (dict, dsc, trunc_name))
+    return trunc_name;
+  free (trunc_name);
 
   /* Generate a synthetic name. */
   for (;;)
     {
+      char name[8];
+
       (*z_cnt)++;
 
       if (*z_cnt <= 99)
@@ -674,8 +680,9 @@ setup_z_trns (struct dsc_proc *dsc, struct dataset *ds)
          struct variable *dst_var;
 
          dst_var = dict_create_var_assert (dataset_dict (ds), dv->z_name, 0);
-          var_set_label (dst_var, xasprintf (_("Z-score of %s"),
-                                             var_to_string (dv->v)));
+          var_set_label (dst_var,
+                         xasprintf (_("Z-score of %s"),var_to_string (dv->v)),
+                         false);
 
           z = &t->z_scores[cnt++];
           z->src_var = dv->v;