comparison src/intervals.c @ 1189:164176515d2a

comment changes
author Joseph Arceneaux <jla@gnu.org>
date Mon, 21 Sep 1992 23:57:58 +0000
parents adfaeccad01d
children 9f50cccf5963
comparison
equal deleted inserted replaced
1188:a6d32838af49 1189:164176515d2a
629 629
630 If POSITION is the first character of an interval, meaning that point 630 If POSITION is the first character of an interval, meaning that point
631 is actually between the two intervals, make the new text belong to 631 is actually between the two intervals, make the new text belong to
632 the interval which is "sticky". 632 the interval which is "sticky".
633 633
634 If both intervals are "stick", then make them belong to the left-most 634 If both intervals are "sticky", then make them belong to the left-most
635 interval. Another possibility would be to create a new interval for 635 interval. Another possibility would be to create a new interval for
636 this text, and make it have the merged properties of both ends. */ 636 this text, and make it have the merged properties of both ends. */
637 637
638 static INTERVAL 638 static INTERVAL
639 adjust_intervals_for_insertion (tree, position, length) 639 adjust_intervals_for_insertion (tree, position, length)
837 if (! NULL_INTERVAL_P (parent->right)) 837 if (! NULL_INTERVAL_P (parent->right))
838 parent->right->parent = parent; 838 parent->right->parent = parent;
839 } 839 }
840 } 840 }
841 841
842 /* Recurse down to the interval containing FROM. Then delete as much 842 /* Find the interval in TREE corresponding to the character position FROM
843 as possible (up to AMOUNT) from that interval, adjusting parental 843 and delete as much as possible of AMOUNT from that interval, starting
844 intervals on the way up. If an interval is zeroed out, then 844 after the relative position of FROM within it. Return the amount
845 it is deleted. 845 actually deleted, and if the interval was zeroed-out, delete that
846 846 interval node from the tree.
847 Returns the amount deleted. */ 847
848 Do this by recursing down TREE to the interval in question, and
849 deleting the appropriate amount of text. */
848 850
849 static int 851 static int
850 interval_deletion_adjustment (tree, from, amount) 852 interval_deletion_adjustment (tree, from, amount)
851 register INTERVAL tree; 853 register INTERVAL tree;
852 register int from, amount; 854 register int from, amount;
922 return my_amount; 924 return my_amount;
923 } 925 }
924 } 926 }
925 } 927 }
926 928
929 /* Never reach here */
927 abort (); 930 abort ();
928 } 931 }
932
933 /* Effect the adjustments neccessary to the interval tree of BUFFER
934 to correspond to the deletion of LENGTH characters from that buffer
935 text. The deletion is effected at position START (relative to the
936 buffer). */
929 937
930 static void 938 static void
931 adjust_intervals_for_deletion (buffer, start, length) 939 adjust_intervals_for_deletion (buffer, start, length)
932 struct buffer *buffer; 940 struct buffer *buffer;
933 int start, length; 941 int start, length;
964 return; 972 return;
965 } 973 }
966 } 974 }
967 } 975 }
968 976
969 /* Note that all intervals in OBJECT after START have slid by LENGTH. */ 977 /* Make the adjustments neccessary to the interval tree of BUFFER to
978 represent an addition or deletion of LENGTH characters starting
979 at position START. Addition or deletion is indicated by the sign
980 of LENGTH. */
970 981
971 INLINE void 982 INLINE void
972 offset_intervals (buffer, start, length) 983 offset_intervals (buffer, start, length)
973 struct buffer *buffer; 984 struct buffer *buffer;
974 int start, length; 985 int start, length;
979 if (length > 0) 990 if (length > 0)
980 adjust_intervals_for_insertion (buffer->intervals, start, length); 991 adjust_intervals_for_insertion (buffer->intervals, start, length);
981 else 992 else
982 adjust_intervals_for_deletion (buffer, start, -length); 993 adjust_intervals_for_deletion (buffer, start, -length);
983 } 994 }
995
996 /* Make an exact copy of interval tree SOURCE which descends from
997 PARENT. This is done by recursing through SOURCE, copying
998 the current interval and its properties, and then adjusting
999 the pointers of the copy. */
984 1000
985 static INTERVAL 1001 static INTERVAL
986 reproduce_tree (source, parent) 1002 reproduce_tree (source, parent)
987 INTERVAL source, parent; 1003 INTERVAL source, parent;
988 { 1004 {
996 if (! NULL_RIGHT_CHILD (source)) 1012 if (! NULL_RIGHT_CHILD (source))
997 t->right = reproduce_tree (source->right, t); 1013 t->right = reproduce_tree (source->right, t);
998 1014
999 return t; 1015 return t;
1000 } 1016 }
1017
1018 /* Make a new interval of length LENGTH starting at START in the
1019 group of intervals INTERVALS, which is actually an interval tree.
1020 Returns the new interval.
1021
1022 Generate an error if the new positions would overlap an existing
1023 interval. */
1001 1024
1002 static INTERVAL 1025 static INTERVAL
1003 make_new_interval (intervals, start, length) 1026 make_new_interval (intervals, start, length)
1004 INTERVAL intervals; 1027 INTERVAL intervals;
1005 int start, length; 1028 int start, length;