Change "union value" to dynamically allocate long strings.
[pspp-builds.git] / src / language / dictionary / value-labels.c
index 6af0b62c57aa981175253e0f5dd04f2ad10f9640..6f9652f58bea708e0db93a85c79b765b16de69f6 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2009 Free Software Foundation, Inc.
 
    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
 #include <language/command.h>
 #include <language/lexer/lexer.h>
 #include <language/lexer/variable-parser.h>
-#include <libpspp/alloc.h>
 #include <libpspp/hash.h>
 #include <libpspp/message.h>
 #include <libpspp/str.h>
 
+#include "xalloc.h"
+
 #include "gettext.h"
 #define _(msgid) gettext (msgid)
 \f
@@ -146,6 +147,7 @@ get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt)
     {
       union value value;
       struct string label;
+      int width;
       size_t i;
 
       /* Set value. */
@@ -156,17 +158,20 @@ get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt)
               lex_error (lexer, _("expecting string"));
              return 0;
            }
-         buf_copy_str_rpad (value.s, MAX_SHORT_STRING, ds_cstr (lex_tokstr (lexer)));
+          width = MAX_SHORT_STRING;
+          value_init (&value, width);
+         buf_copy_str_rpad (value_str_rw (&value, width), width,
+                             ds_cstr (lex_tokstr (lexer)), ' ');
        }
       else
        {
          if (!lex_is_number (lexer))
            {
-             lex_error (lexer, _("expecting integer"));
+             lex_error (lexer, _("expecting number"));
              return 0;
            }
-         if (!lex_is_integer (lexer))
-           msg (SW, _("Value label `%g' is not integer."), lex_tokval (lexer));
+          width = 0;
+          value_init (&value, width);
          value.f = lex_tokval (lexer);
        }
       lex_get (lexer);
@@ -174,7 +179,10 @@ get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt)
 
       /* Set label. */
       if (!lex_force_string (lexer))
-       return 0;
+        {
+          value_destroy (&value, width);
+          return 0;
+        }
 
       ds_init_string (&label, lex_tokstr (lexer));
 
@@ -188,6 +196,7 @@ get_label (struct lexer *lexer, struct variable **vars, size_t var_cnt)
         var_replace_value_label (vars[i], &value, ds_cstr (&label));
 
       ds_destroy (&label);
+      value_destroy (&value, width);
 
       lex_get (lexer);
       lex_match (lexer, ',');