Changed all the licence notices in all the files.
[pspp-builds.git] / src / val-labs.c
index 882f26e625933b7364510bb112ef57f2e0edf2af..2fa02e646e06d413b41875cd9ccc207f0fdd2ba5 100644 (file)
@@ -14,8 +14,8 @@
 
    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
-   Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
-   02111-1307, USA. */
+   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+   02110-1301, USA. */
 
 #include <config.h>
 #include <stdio.h>
@@ -57,12 +57,19 @@ do_value_labels (int erase)
 {
   struct variable **vars; /* Variable list. */
   int var_cnt;            /* Number of variables. */
+  int parse_err=0;        /* true if error parsing variables */
 
   lex_match ('/');
   
   while (token != '.')
     {
-      parse_variables (default_dict, &vars, &var_cnt, PV_SAME_TYPE);
+      parse_err = !parse_variables (default_dict, &vars, &var_cnt, 
+                                   PV_SAME_TYPE) ;
+      if (var_cnt < 1)
+       {
+         free(vars);
+         return CMD_FAILURE;
+       }
       if (!verify_val_labs (vars, var_cnt))
         goto lossage;
       if (erase)
@@ -72,12 +79,15 @@ do_value_labels (int erase)
           goto lossage;
 
       if (token != '/')
+       {
+       free (vars);
        break;
+       }
+
       lex_get ();
 
       free (vars);
     }
-  free (vars);
 
   if (token != '.')
     {
@@ -85,7 +95,7 @@ do_value_labels (int erase)
       return CMD_TRAILING_GARBAGE;
     }
 
-  return CMD_SUCCESS;
+  return parse_err ? CMD_PART_SUCCESS_MAYBE : CMD_SUCCESS;
 
  lossage:
   free (vars);
@@ -103,7 +113,7 @@ verify_val_labs (struct variable **vars, int var_cnt)
     {
       struct variable *vp = vars[i];
 
-      if (vp->type == ALPHA && vp->width > 8)
+      if (vp->type == ALPHA && vp->width > MAX_SHORT_STRING)
        {
          msg (SE, _("It is not possible to assign value labels to long "
                     "string variables such as %s."), vp->name);
@@ -144,16 +154,16 @@ get_label (struct variable **vars, int var_cnt)
               lex_error (_("expecting string"));
              return 0;
            }
-         st_bare_pad_copy (value.s, ds_value (&tokstr), MAX_SHORT_STRING);
+         st_bare_pad_copy (value.s, ds_c_str (&tokstr), MAX_SHORT_STRING);
        }
       else
        {
-         if (token != T_NUM)
+         if (!lex_is_number ())
            {
              lex_error (_("expecting integer"));
              return 0;
            }
-         if (!lex_integer_p ())
+         if (!lex_is_integer ())
            msg (SW, _("Value label `%g' is not integer."), tokval);
          value.f = tokval;
        }
@@ -167,7 +177,7 @@ get_label (struct variable **vars, int var_cnt)
          msg (SW, _("Truncating value label to 60 characters."));
          ds_truncate (&tokstr, 60);
        }
-      label = ds_value (&tokstr);
+      label = ds_c_str (&tokstr);
 
       for (i = 0; i < var_cnt; i++)
         val_labs_replace (vars[i]->val_labs, value, label);