changeset 4831:2e15c29cc2b3

fix bug in returning range table ends in unified range table code
author Ben Wing <ben@xemacs.org>
date Sun, 10 Jan 2010 00:49:14 -0600
parents a9833e8a32ec
children 07fa38c30fdf
files src/rangetab.c
diffstat 1 files changed, 37 insertions(+), 19 deletions(-) [+]
line wrap: on
line diff
--- a/src/rangetab.c	Sun Jan 10 00:48:55 2010 -0600
+++ b/src/rangetab.c	Sun Jan 10 00:49:14 2010 -0600
@@ -1,6 +1,6 @@
 /* XEmacs routines to deal with range tables.
    Copyright (C) 1995 Sun Microsystems, Inc.
-   Copyright (C) 1995, 2002, 2004, 2005 Ben Wing.
+   Copyright (C) 1995, 2002, 2004, 2005, 2010 Ben Wing.
 
 This file is part of XEmacs.
 
@@ -377,6 +377,36 @@
 			  Dynarr_atp (rt->entries, 0), default_);
 }
 
+static void
+external_to_internal_adjust_ends (enum range_table_type type,
+				  EMACS_INT *first, EMACS_INT *last)
+{
+  /* Fix up the numbers in accordance with the open/closedness to make
+     them behave like default open/closed. */
+  switch (type)
+    {
+    case RANGE_START_CLOSED_END_OPEN: break;
+    case RANGE_START_CLOSED_END_CLOSED: (*last)++; break;
+    case RANGE_START_OPEN_END_OPEN: (*first)++; break;
+    case RANGE_START_OPEN_END_CLOSED: (*first)++, (*last)++; break;
+    }
+}
+
+static void
+internal_to_external_adjust_ends (enum range_table_type type,
+				  EMACS_INT *first, EMACS_INT *last)
+{
+  /* Reverse the changes made in external_to_internal_adjust_ends().
+   */
+  switch (type)
+    {
+    case RANGE_START_CLOSED_END_OPEN: break;
+    case RANGE_START_CLOSED_END_CLOSED: (*last)--; break;
+    case RANGE_START_OPEN_END_OPEN: (*first)--; break;
+    case RANGE_START_OPEN_END_CLOSED: (*first)--, (*last)--; break;
+    }
+}
+
 void
 put_range_table (Lisp_Object table, EMACS_INT first,
 		 EMACS_INT last, Lisp_Object val)
@@ -385,17 +415,7 @@
   int insert_me_here = -1;
   Lisp_Range_Table *rt = XRANGE_TABLE (table);
 
-  /* Fix up the numbers in accordance with the open/closedness to make
-     them behave like default open/closed. */
-
-  switch (rt->type)
-    {
-    case RANGE_START_CLOSED_END_OPEN: break;
-    case RANGE_START_CLOSED_END_CLOSED: last++; break;
-    case RANGE_START_OPEN_END_OPEN: first++; break;
-    case RANGE_START_OPEN_END_CLOSED: first++, last++; break;
-    }
-
+  external_to_internal_adjust_ends (rt->type, &first, &last);
   if (first == last)
     return;
   if (first > last)
@@ -606,13 +626,7 @@
 	 table. */
       {
 	EMACS_INT premier = first, dernier = last;
-	switch (rt->type)
-	  {
-	  case RANGE_START_CLOSED_END_OPEN: break;
-	  case RANGE_START_CLOSED_END_CLOSED: dernier--; break;
-	  case RANGE_START_OPEN_END_OPEN: premier--; break;
-	  case RANGE_START_OPEN_END_CLOSED: premier--, dernier--; break;
-	  }
+	internal_to_external_adjust_ends (rt->type, &premier, &dernier);
 	args[1] = make_int (premier);
 	args[2] = make_int (dernier);
       }
@@ -753,6 +767,7 @@
 struct unified_range_table
 {
   int nentries;
+  enum range_table_type type;
   struct range_table_entry first;
 };
 
@@ -794,6 +809,7 @@
   * ((unsigned char *) dest + 3) = total_needed & 0xFF;
   un = (struct unified_range_table *) new_dest;
   un->nentries = Dynarr_length (rted);
+  un->type = XRANGE_TABLE (rangetab)->type;
   memcpy (&un->first, Dynarr_atp (rted, 0),
 	  sizeof (struct range_table_entry) * Dynarr_length (rted));
 }
@@ -874,6 +890,8 @@
   *min = tab->first;
   *max = tab->last;
   *val = tab->val;
+
+  internal_to_external_adjust_ends (un->type, min, max);
 }