* get.c: (mtf_processing) Don't assume that mtf_compare_BY_values()
authorBen Pfaff <blp@gnu.org>
Thu, 7 Jul 2005 03:46:04 +0000 (03:46 +0000)
committerBen Pfaff <blp@gnu.org>
Thu, 7 Jul 2005 03:46:04 +0000 (03:46 +0000)
always returns -1, 0, or 1.  Actually, it returns a negative, zero, or
positive result.  Fixes MATCH FILES bug on Mac OS X reported by
"Marshall DeBerry" <mdb@radix.net>.

src/ChangeLog
src/get.c

index fbae824189716c9790bfcfbb9ed20bbed4b6409b..2505600b37d08ee43f81f2153ebeea6f5ab7d9f4 100644 (file)
@@ -1,3 +1,10 @@
+Wed Jul  6 20:44:27 2005  Ben Pfaff  <blp@gnu.org>
+
+       * get.c: (mtf_processing) Don't assume that
+       mtf_compare_BY_values() always returns -1, 0, or 1.  Actually, it
+       returns a negative, zero, or positive result.  Fixes MATCH FILES
+       bug on Mac OS X reported by "Marshall DeBerry" <mdb@radix.net>.
+
 Mon Jul  4 18:01:15 2005  Ben Pfaff  <blp@gnu.org>
 
        * flip.c: [HAVE_SYS_TYPES_H] Really include <sys/types.h>.  The
index 32602b35c66907565d0e81cb0e857fbacfcb7fa2..44e5af4ad2403acc60a3289da1169c090d545538 100644 (file)
--- a/src/get.c
+++ b/src/get.c
@@ -1222,38 +1222,34 @@ mtf_processing (struct ccase *c, void *mtf_)
       min_head = min_tail = mtf->head;
       max_head = max_tail = NULL;
       for (iter = mtf->head->next; iter && iter->type == MTF_FILE;
-          iter = iter->next)
-       switch (mtf_compare_BY_values (mtf, min_head, iter, c))
-         {
-         case -1:
-           if (max_head)
-             max_tail = max_tail->next_min = iter;
-           else
-             max_head = max_tail = iter;
-           break;
-
-         case 0:
+          iter = iter->next) 
+        {
+          int cmp = mtf_compare_BY_values (mtf, min_head, iter, c);
+          if (cmp < 0) 
+            {
+              if (max_head)
+                max_tail = max_tail->next_min = iter;
+              else
+                max_head = max_tail = iter;
+            }
+          else if (cmp == 0) 
            min_tail = min_tail->next_min = iter;
-           break;
-
-         case 1:
-           if (max_head)
-             {
-               max_tail->next_min = min_head;
-               max_tail = min_tail;
-             }
-           else
-             {
-               max_head = min_head;
-               max_tail = min_tail;
-             }
-           min_head = min_tail = iter;
-           break;
-
-         default:
-           assert (0);
-         }
-
+          else /* cmp > 0 */
+            {
+              if (max_head)
+                {
+                  max_tail->next_min = min_head;
+                  max_tail = min_tail;
+                }
+              else
+                {
+                  max_head = min_head;
+                  max_tail = min_tail;
+                }
+              min_head = min_tail = iter;
+            }
+        }
+      
       /* 4. For every TABLE, read another record as long as the BY
         values on the TABLE's input record are less than the FILEs'
         BY values.  If an exact match is found, store all the values
@@ -1263,32 +1259,28 @@ mtf_processing (struct ccase *c, void *mtf_)
          assert (iter->type == MTF_TABLE);
       
          next = iter->next;
-
-       again:
-         switch (mtf_compare_BY_values (mtf, min_head, iter, c))
-           {
-           case -1:
-             if (max_head)
-               max_tail = max_tail->next_min = iter;
-             else
-               max_head = max_tail = iter;
-             break;
-
-           case 0:
-             min_tail = min_tail->next_min = iter;
-             break;
-
-           case 1:
-             if (iter->handle == NULL)
-               return 1;
-             if (sfm_read_case (iter->reader, &iter->input))
-               goto again;
-             mtf_delete_file_in_place (mtf, &iter);
-             break;
-
-           default:
-             assert (0);
-           }
+          for (;;) 
+            {
+              int cmp = mtf_compare_BY_values (mtf, min_head, iter, c);
+              if (cmp < 0) 
+                {
+                  if (max_head)
+                    max_tail = max_tail->next_min = iter;
+                  else
+                    max_head = max_tail = iter;
+                }
+              else if (cmp == 0)
+                min_tail = min_tail->next_min = iter;
+              else /* cmp > 0 */
+                {
+                  if (iter->handle == NULL)
+                    return 1;
+                  if (sfm_read_case (iter->reader, &iter->input))
+                    continue;
+                  mtf_delete_file_in_place (mtf, &iter);
+                }
+              break;
+            }
        }
 
       /* Next sequence number. */