Work to get rid of GCC 4.0 warnings, part 2.
[pspp] / src / modify-vars.c
index ed28ee4c671d4a0df0c4a185e9ec0dcb4b93930d..5f1ad4c9cc6ed71643cf09442ae9ef88a4f870c5 100644 (file)
 
    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 <stdlib.h>
-#include <assert.h>
+#include "error.h"
 #include "algorithm.h"
 #include "alloc.h"
 #include "bitvector.h"
 #include "command.h"
+#include "dictionary.h"
 #include "error.h"
 #include "hash.h"
 #include "lexer.h"
@@ -32,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(). */
@@ -83,8 +87,12 @@ cmd_modify_vars (void)
 
   size_t i;
 
-  lex_match_id ("MODIFY");
-  lex_match_id ("VARS");
+  if (temporary != 0)
+    {
+      msg (SE, _("MODIFY VARS may not be used after TEMPORARY.  "
+                 "Temporary transformations will be made permanent."));
+      cancel_temporary (); 
+    }
 
   vm.reorder_vars = NULL;
   vm.reorder_cnt = 0;
@@ -101,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)
            {
@@ -114,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"));
@@ -176,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 ('('))
                {
@@ -218,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)
            {
@@ -239,6 +247,7 @@ 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);
@@ -260,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)
            {
@@ -309,7 +318,7 @@ cmd_modify_vars (void)
   if (already_encountered & (1 | 4))
     {
       /* Read the data. */
-      procedure (NULL, NULL, NULL);
+      procedure (NULL, NULL);
     }
 
   if (!rearrange_dict (default_dict, &vm))
@@ -343,7 +352,7 @@ compare_variables_given_ordering (const void *a_, const void *b_,
   if (ordering->positional)
     result = a->index < b->index ? -1 : a->index > b->index;
   else
-    result = strcmp (a->name, b->name);
+    result = strcasecmp (a->name, b->name);
   if (!ordering->forward)
     result = -result;
   return result;
@@ -353,19 +362,19 @@ compare_variables_given_ordering (const void *a_, const void *b_,
 struct var_renaming
   {
     struct variable *var;
-    char new_name[9];
+    char new_name[LONG_NAME_LEN + 1];
   };
 
 /* A algo_compare_func that compares new_name members in struct
    var_renaming structures A and B. */
 static int
 compare_var_renaming_by_new_name (const void *a_, const void *b_,
-                                  void *foo unused
+                                  void *foo UNUSED
 {
   const struct var_renaming *a = a_;
   const struct var_renaming *b = b_;
 
-  return strcmp (a->new_name, b->new_name);
+  return strcasecmp (a->new_name, b->new_name);
 }
 
 /* Returns true if performing VM on dictionary D would not cause
@@ -382,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;
@@ -399,6 +409,7 @@ validate_var_modification (const struct dictionary *d,
         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);
   if (set_difference (all_vars, all_cnt,