Mercurial > hg > xemacs-beta
comparison src/rangetab.c @ 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 | 312503644bc3 |
children | 6ef8256a020a 19a72041c5ed |
comparison
equal
deleted
inserted
replaced
4830:a9833e8a32ec | 4831:2e15c29cc2b3 |
---|---|
1 /* XEmacs routines to deal with range tables. | 1 /* XEmacs routines to deal with range tables. |
2 Copyright (C) 1995 Sun Microsystems, Inc. | 2 Copyright (C) 1995 Sun Microsystems, Inc. |
3 Copyright (C) 1995, 2002, 2004, 2005 Ben Wing. | 3 Copyright (C) 1995, 2002, 2004, 2005, 2010 Ben Wing. |
4 | 4 |
5 This file is part of XEmacs. | 5 This file is part of XEmacs. |
6 | 6 |
7 XEmacs is free software; you can redistribute it and/or modify it | 7 XEmacs is free software; you can redistribute it and/or modify it |
8 under the terms of the GNU General Public License as published by the | 8 under the terms of the GNU General Public License as published by the |
375 | 375 |
376 return get_range_table (XINT (pos), Dynarr_length (rt->entries), | 376 return get_range_table (XINT (pos), Dynarr_length (rt->entries), |
377 Dynarr_atp (rt->entries, 0), default_); | 377 Dynarr_atp (rt->entries, 0), default_); |
378 } | 378 } |
379 | 379 |
380 static void | |
381 external_to_internal_adjust_ends (enum range_table_type type, | |
382 EMACS_INT *first, EMACS_INT *last) | |
383 { | |
384 /* Fix up the numbers in accordance with the open/closedness to make | |
385 them behave like default open/closed. */ | |
386 switch (type) | |
387 { | |
388 case RANGE_START_CLOSED_END_OPEN: break; | |
389 case RANGE_START_CLOSED_END_CLOSED: (*last)++; break; | |
390 case RANGE_START_OPEN_END_OPEN: (*first)++; break; | |
391 case RANGE_START_OPEN_END_CLOSED: (*first)++, (*last)++; break; | |
392 } | |
393 } | |
394 | |
395 static void | |
396 internal_to_external_adjust_ends (enum range_table_type type, | |
397 EMACS_INT *first, EMACS_INT *last) | |
398 { | |
399 /* Reverse the changes made in external_to_internal_adjust_ends(). | |
400 */ | |
401 switch (type) | |
402 { | |
403 case RANGE_START_CLOSED_END_OPEN: break; | |
404 case RANGE_START_CLOSED_END_CLOSED: (*last)--; break; | |
405 case RANGE_START_OPEN_END_OPEN: (*first)--; break; | |
406 case RANGE_START_OPEN_END_CLOSED: (*first)--, (*last)--; break; | |
407 } | |
408 } | |
409 | |
380 void | 410 void |
381 put_range_table (Lisp_Object table, EMACS_INT first, | 411 put_range_table (Lisp_Object table, EMACS_INT first, |
382 EMACS_INT last, Lisp_Object val) | 412 EMACS_INT last, Lisp_Object val) |
383 { | 413 { |
384 int i; | 414 int i; |
385 int insert_me_here = -1; | 415 int insert_me_here = -1; |
386 Lisp_Range_Table *rt = XRANGE_TABLE (table); | 416 Lisp_Range_Table *rt = XRANGE_TABLE (table); |
387 | 417 |
388 /* Fix up the numbers in accordance with the open/closedness to make | 418 external_to_internal_adjust_ends (rt->type, &first, &last); |
389 them behave like default open/closed. */ | |
390 | |
391 switch (rt->type) | |
392 { | |
393 case RANGE_START_CLOSED_END_OPEN: break; | |
394 case RANGE_START_CLOSED_END_CLOSED: last++; break; | |
395 case RANGE_START_OPEN_END_OPEN: first++; break; | |
396 case RANGE_START_OPEN_END_CLOSED: first++, last++; break; | |
397 } | |
398 | |
399 if (first == last) | 419 if (first == last) |
400 return; | 420 return; |
401 if (first > last) | 421 if (first > last) |
402 /* This will happen if originally first == last and both ends are | 422 /* This will happen if originally first == last and both ends are |
403 open. #### Should we signal an error? */ | 423 open. #### Should we signal an error? */ |
604 args[0] = function; | 624 args[0] = function; |
605 /* Fix up the numbers in accordance with the open/closedness of the | 625 /* Fix up the numbers in accordance with the open/closedness of the |
606 table. */ | 626 table. */ |
607 { | 627 { |
608 EMACS_INT premier = first, dernier = last; | 628 EMACS_INT premier = first, dernier = last; |
609 switch (rt->type) | 629 internal_to_external_adjust_ends (rt->type, &premier, &dernier); |
610 { | |
611 case RANGE_START_CLOSED_END_OPEN: break; | |
612 case RANGE_START_CLOSED_END_CLOSED: dernier--; break; | |
613 case RANGE_START_OPEN_END_OPEN: premier--; break; | |
614 case RANGE_START_OPEN_END_CLOSED: premier--, dernier--; break; | |
615 } | |
616 args[1] = make_int (premier); | 630 args[1] = make_int (premier); |
617 args[2] = make_int (dernier); | 631 args[2] = make_int (dernier); |
618 } | 632 } |
619 args[3] = entry->val; | 633 args[3] = entry->val; |
620 Ffuncall (countof (args), args); | 634 Ffuncall (countof (args), args); |
751 some number of `struct range_table_entry' entries. */ | 765 some number of `struct range_table_entry' entries. */ |
752 | 766 |
753 struct unified_range_table | 767 struct unified_range_table |
754 { | 768 { |
755 int nentries; | 769 int nentries; |
770 enum range_table_type type; | |
756 struct range_table_entry first; | 771 struct range_table_entry first; |
757 }; | 772 }; |
758 | 773 |
759 /* Return size in bytes needed to store the data in a range table. */ | 774 /* Return size in bytes needed to store the data in a range table. */ |
760 | 775 |
792 * ((unsigned char *) dest + 2) = total_needed & 0xFF; | 807 * ((unsigned char *) dest + 2) = total_needed & 0xFF; |
793 total_needed >>= 8; | 808 total_needed >>= 8; |
794 * ((unsigned char *) dest + 3) = total_needed & 0xFF; | 809 * ((unsigned char *) dest + 3) = total_needed & 0xFF; |
795 un = (struct unified_range_table *) new_dest; | 810 un = (struct unified_range_table *) new_dest; |
796 un->nentries = Dynarr_length (rted); | 811 un->nentries = Dynarr_length (rted); |
812 un->type = XRANGE_TABLE (rangetab)->type; | |
797 memcpy (&un->first, Dynarr_atp (rted, 0), | 813 memcpy (&un->first, Dynarr_atp (rted, 0), |
798 sizeof (struct range_table_entry) * Dynarr_length (rted)); | 814 sizeof (struct range_table_entry) * Dynarr_length (rted)); |
799 } | 815 } |
800 | 816 |
801 /* Return number of bytes actually used by a unified range table. */ | 817 /* Return number of bytes actually used by a unified range table. */ |
872 assert (offset >= 0 && offset < un->nentries); | 888 assert (offset >= 0 && offset < un->nentries); |
873 tab = (&un->first) + offset; | 889 tab = (&un->first) + offset; |
874 *min = tab->first; | 890 *min = tab->first; |
875 *max = tab->last; | 891 *max = tab->last; |
876 *val = tab->val; | 892 *val = tab->val; |
893 | |
894 internal_to_external_adjust_ends (un->type, min, max); | |
877 } | 895 } |
878 | 896 |
879 | 897 |
880 /************************************************************************/ | 898 /************************************************************************/ |
881 /* Initialization */ | 899 /* Initialization */ |