added automake.mk files in src/language
[pspp] / src / modify-vars.c
index fee6d59b840f92afdff88c1a877dc0a15cfc0a6e..4d01b6a942399b7b1568d77d53b4c76829758c09 100644 (file)
@@ -33,6 +33,9 @@
 #include "var.h"
 #include "vfm.h"
 
+#include "gettext.h"
+#define _(msgid) gettext (msgid)
+
 /* FIXME: should change weighting variable, etc. */
 /* These control the ordering produced by
    compare_variables_given_ordering(). */
@@ -106,7 +109,7 @@ cmd_modify_vars (void)
       if (lex_match_id ("REORDER"))
        {
          struct variable **v = NULL;
-         int nv = 0;
+         size_t nv = 0;
 
          if (already_encountered & 1)
            {
@@ -119,7 +122,7 @@ cmd_modify_vars (void)
          do
            {
               struct ordering ordering;
-             int prev_nv = nv;
+             size_t prev_nv = nv;
 
              ordering.forward = ordering.positional = 1;
              if (lex_match_id ("FORWARD"));
@@ -181,8 +184,8 @@ cmd_modify_vars (void)
          lex_match ('=');
          do
            {
-             int prev_nv_1 = vm.rename_cnt;
-             int prev_nv_2 = vm.rename_cnt;
+             size_t prev_nv_1 = vm.rename_cnt;
+             size_t prev_nv_2 = vm.rename_cnt;
 
              if (!lex_match ('('))
                {
@@ -223,7 +226,7 @@ cmd_modify_vars (void)
       else if (lex_match_id ("KEEP"))
        {
          struct variable **keep_vars, **all_vars, **drop_vars;
-         int keep_cnt, all_cnt, drop_cnt;
+         size_t keep_cnt, all_cnt, drop_cnt;
 
          if (already_encountered & 4)
            {
@@ -244,9 +247,10 @@ cmd_modify_vars (void)
                 compare_variables_given_ordering, &forward_positional_ordering);
 
           dict_get_vars (default_dict, &all_vars, &all_cnt, 0);
+          assert (all_cnt >= keep_cnt);
 
           drop_cnt = all_cnt - keep_cnt;
-          drop_vars = xmalloc (drop_cnt * sizeof *keep_vars);
+          drop_vars = xnmalloc (drop_cnt, sizeof *keep_vars);
           if (set_difference (all_vars, all_cnt,
                               keep_vars, keep_cnt,
                               sizeof *all_vars,
@@ -265,7 +269,7 @@ cmd_modify_vars (void)
       else if (lex_match_id ("DROP"))
        {
          struct variable **drop_vars;
-         int drop_cnt;
+         size_t drop_cnt;
 
          if (already_encountered & 4)
            {
@@ -387,7 +391,8 @@ validate_var_modification (const struct dictionary *d,
   struct variable **all_vars;
   struct variable **keep_vars;
   struct variable **drop_vars;
-  size_t all_cnt, keep_cnt, drop_cnt;
+  size_t keep_cnt, drop_cnt;
+  size_t all_cnt;
 
   struct var_renaming *var_renaming;
   int valid;
@@ -398,14 +403,15 @@ validate_var_modification (const struct dictionary *d,
 
   /* Drop variables, in index order. */
   drop_cnt = vm->drop_cnt;
-  drop_vars = xmalloc (drop_cnt * sizeof *drop_vars);
+  drop_vars = xnmalloc (drop_cnt, sizeof *drop_vars);
   memcpy (drop_vars, vm->drop_vars, drop_cnt * sizeof *drop_vars);
   sort (drop_vars, drop_cnt, sizeof *drop_vars,
         compare_variables_given_ordering, &forward_positional_ordering);
 
   /* Keep variables, in index order. */
+  assert (all_cnt >= drop_cnt);
   keep_cnt = all_cnt - drop_cnt;
-  keep_vars = xmalloc (keep_cnt * sizeof *keep_vars);
+  keep_vars = xnmalloc (keep_cnt, sizeof *keep_vars);
   if (set_difference (all_vars, all_cnt,
                       drop_vars, drop_cnt,
                       sizeof *all_vars,
@@ -415,7 +421,7 @@ validate_var_modification (const struct dictionary *d,
     assert (0);
 
   /* Copy variables into var_renaming array. */
-  var_renaming = xmalloc (keep_cnt * sizeof *var_renaming);
+  var_renaming = xnmalloc (keep_cnt, sizeof *var_renaming);
   for (i = 0; i < keep_cnt; i++) 
     {
       var_renaming[i].var = keep_vars[i];
@@ -480,7 +486,7 @@ rearrange_dict (struct dictionary *d, const struct var_modification *vm)
   /* Record the old names of variables to rename.  After
      variables are deleted, we can't depend on the variables to
      still exist, but we can still look them up by name. */
-  rename_old_names = xmalloc (vm->rename_cnt * sizeof *rename_old_names);
+  rename_old_names = xnmalloc (vm->rename_cnt, sizeof *rename_old_names);
   for (i = 0; i < vm->rename_cnt; i++)
     rename_old_names[i] = xstrdup (vm->rename_vars[i]->name);
 
@@ -489,8 +495,8 @@ rearrange_dict (struct dictionary *d, const struct var_modification *vm)
   dict_delete_vars (d, vm->drop_vars, vm->drop_cnt);
 
   /* Compose lists of variables to rename and their new names. */
-  rename_vars = xmalloc (vm->rename_cnt * sizeof *rename_vars);
-  rename_new_names = xmalloc (vm->rename_cnt * sizeof *rename_new_names);
+  rename_vars = xnmalloc (vm->rename_cnt, sizeof *rename_vars);
+  rename_new_names = xnmalloc (vm->rename_cnt, sizeof *rename_new_names);
   rename_cnt = 0;
   for (i = 0; i < vm->rename_cnt; i++)
     {