annotate src/rangetab.c @ 28:1917ad0d78d7 r19-15b97

Import from CVS: tag r19-15b97
author cvs
date Mon, 13 Aug 2007 08:51:55 +0200
parents 859a2309aef8
children 8eaf7971accc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
1 /* XEmacs routines to deal with range tables.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
2 Copyright (C) 1995 Sun Microsystems, Inc.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
3 Copyright (C) 1995 Ben Wing.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
5 This file is part of XEmacs.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
6
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
10 later version.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
11
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
15 for more details.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
16
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
21
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
23
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
24 /* Written by Ben Wing, August 1995. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
25
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
26 #include <config.h>
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
27 #include "lisp.h"
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
28
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
29 struct range_table_entry
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
30 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
31 EMACS_INT first;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
32 EMACS_INT last;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
33 Lisp_Object val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
34 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
35
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
36 typedef struct range_table_entry_dynarr_type
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
37 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
38 Dynarr_declare (struct range_table_entry);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
39 } range_table_entry_dynarr;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
40
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
41 struct Lisp_Range_Table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
42 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
43 struct lcrecord_header header;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
44 range_table_entry_dynarr *entries;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
45 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
46
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
47 DECLARE_LRECORD (range_table, struct Lisp_Range_Table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
48 #define XRANGE_TABLE(x) \
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
49 XRECORD (x, range_table, struct Lisp_Range_Table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
50 #define XSETRANGE_TABLE(x, p) XSETRECORD (x, p, range_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
51 #define RANGE_TABLEP(x) RECORDP (x, range_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
52 #define GC_RANGE_TABLEP(x) GC_RECORDP (x, range_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
53 #define CHECK_RANGE_TABLE(x) CHECK_RECORD (x, range_table)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
54
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
55 Lisp_Object Qrange_tablep;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
56 Lisp_Object Qrange_table;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
57
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
58
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
59 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
60 /* Range table object */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
61 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
62
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
63 /* We use a sorted array of ranges.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
65 #### We should be using the gap array stuff from extents.c. This
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
66 is not hard but just requires moving that stuff out of that file. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
67
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
68 static Lisp_Object mark_range_table (Lisp_Object, void (*) (Lisp_Object));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
69 static void print_range_table (Lisp_Object, Lisp_Object, int);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
70 static int range_table_equal (Lisp_Object, Lisp_Object, int depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
71 static unsigned long range_table_hash (Lisp_Object obj, int depth);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
72 DEFINE_LRECORD_IMPLEMENTATION ("range-table", range_table,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
73 mark_range_table, print_range_table, 0,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
74 range_table_equal, range_table_hash,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
75 struct Lisp_Range_Table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
76
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
77 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
78 mark_range_table (Lisp_Object obj, void (*markobj) (Lisp_Object))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
79 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
80 struct Lisp_Range_Table *rt = XRANGE_TABLE (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
81 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
82
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
83 for (i = 0; i < Dynarr_length (rt->entries); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
84 (markobj) (Dynarr_at (rt->entries, i).val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
85 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
86 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
87
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
88 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
89 print_range_table (Lisp_Object obj, Lisp_Object printcharfun, int escapeflag)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
90 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
91 struct Lisp_Range_Table *rt = XRANGE_TABLE (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
92 char buf[200];
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
93 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
94
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
95 write_c_string ("#s(range-table data (", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
96 for (i = 0; i < Dynarr_length (rt->entries); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
97 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
98 struct range_table_entry *rte = Dynarr_atp (rt->entries, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
99 if (i > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
100 write_c_string (" ", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
101 if (rte->first == rte->last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
102 sprintf (buf, "%d ", rte->first);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
103 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
104 sprintf (buf, "(%d %d) ", rte->first, rte->last);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
105 write_c_string (buf, printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
106 print_internal (rte->val, printcharfun, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
107 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
108 write_c_string ("))", printcharfun);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
109 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
110
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
111 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
112 range_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
113 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
114 struct Lisp_Range_Table *rt1 = XRANGE_TABLE (obj1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
115 struct Lisp_Range_Table *rt2 = XRANGE_TABLE (obj2);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
116 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
117
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
118 if (Dynarr_length (rt1->entries) != Dynarr_length (rt2->entries))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
119 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
120
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
121 for (i = 0; i < Dynarr_length (rt1->entries); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
122 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
123 struct range_table_entry *rte1 = Dynarr_atp (rt1->entries, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
124 struct range_table_entry *rte2 = Dynarr_atp (rt2->entries, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
125
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
126 if (rte1->first != rte2->first
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
127 || rte1->last != rte2->last
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
128 || !internal_equal (rte1->val, rte2->val, depth + 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
129 return 0;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
130 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
131
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
132 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
133 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
134
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
135 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
136 range_table_entry_hash (struct range_table_entry *rte, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
137 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
138 return HASH3 (rte->first, rte->last, internal_hash (rte->val, depth + 1));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
139 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
140
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
141 static unsigned long
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
142 range_table_hash (Lisp_Object obj, int depth)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
143 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
144 struct Lisp_Range_Table *rt = XRANGE_TABLE (obj);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
145 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
146 int size = Dynarr_length (rt->entries);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
147 unsigned long hash = size;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
148
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
149 /* approach based on internal_array_hash(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
150 if (size <= 5)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
151 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
152 for (i = 0; i < size; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
153 hash = HASH2 (hash,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
154 range_table_entry_hash (Dynarr_atp (rt->entries, i),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
155 depth));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
156 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
157 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
158
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
159 /* just pick five elements scattered throughout the array.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
160 A slightly better approach would be to offset by some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
161 noise factor from the points chosen below. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
162 for (i = 0; i < 5; i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
163 hash = HASH2 (hash, range_table_entry_hash (Dynarr_atp (rt->entries,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
164 i*size/5),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
165 depth));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
166
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
167 return hash;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
168 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
169
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
170
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
171 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
172 /* Range table operations */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
173 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
174
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
175 #ifdef ERROR_CHECK_TYPECHECK
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
176
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
177 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
178 verify_range_table (struct Lisp_Range_Table *rt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
179 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
180 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
181
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
182 for (i = 0; i < Dynarr_length (rt->entries); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
183 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
184 struct range_table_entry *rte = Dynarr_atp (rt->entries, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
185 assert (rte->last >= rte->first);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
186 if (i > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
187 assert (Dynarr_at (rt->entries, i - 1).last < rte->first);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
188 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
189 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
190
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
191 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
192
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
193 #define verify_range_table(rt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
194
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
195 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
196
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
197 /* Look up in a range table without the Dynarr wrapper.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
198 Used also by the unified range table format. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
199
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
200 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
201 get_range_table (EMACS_INT pos, int nentries, struct range_table_entry *tab,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
202 Lisp_Object defalt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
203 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
204 int left = 0, right = nentries;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
205
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
206 /* binary search for the entry. Based on similar code in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
207 extent_list_locate(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
208 while (left != right)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
209 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
210 /* RIGHT might not point to a valid entry (i.e. it's at the end
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
211 of the list), so NEWPOS must round down. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
212 unsigned int newpos = (left + right) >> 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
213 struct range_table_entry *entry = tab + newpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
214 if (pos > entry->last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
215 left = newpos+1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
216 else if (pos < entry->first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
217 right = newpos;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
218 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
219 return entry->val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
220 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
221
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
222 return defalt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
223 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
224
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
225 DEFUN ("range-table-p", Frange_table_p, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
226 Return non-nil if OBJECT is a range table.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
227 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
228 (object))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
229 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
230 return (RANGE_TABLEP (object) ? Qt : Qnil);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
231 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
232
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
233 DEFUN ("make-range-table", Fmake_range_table, 0, 0, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
234 Make a new, empty range table.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
235 You can manipulate it using `put-range-table', `get-range-table',
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
236 `remove-range-table', and `clear-range-table'.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
237 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
238 ())
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
239 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
240 struct Lisp_Range_Table *rt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
241 Lisp_Object obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
242
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
243 rt = (struct Lisp_Range_Table *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
244 alloc_lcrecord (sizeof (struct Lisp_Range_Table), lrecord_range_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
245 rt->entries = Dynarr_new (struct range_table_entry);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
246 XSETRANGE_TABLE (obj, rt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
247 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
248 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
249
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
250 DEFUN ("copy-range-table", Fcopy_range_table, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
251 Make a new range table which contains the same values for the same
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
252 ranges as the given table. The values will not themselves be copied.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
253 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
254 (old_table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
255 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
256 struct Lisp_Range_Table *rt, *rtnew;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
257 Lisp_Object obj = Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
258
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
259 CHECK_RANGE_TABLE (old_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
260 rt = XRANGE_TABLE (old_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
261 rtnew = (struct Lisp_Range_Table *)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
262 alloc_lcrecord (sizeof (struct Lisp_Range_Table), lrecord_range_table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
263 rtnew->entries = Dynarr_new (struct range_table_entry);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
264
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
265 Dynarr_add_many (rtnew->entries, Dynarr_atp (rt->entries, 0),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
266 Dynarr_length (rt->entries));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
267 XSETRANGE_TABLE (obj, rtnew);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
268 return obj;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
269 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
270
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
271 DEFUN ("get-range-table", Fget_range_table, 2, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
272 Find value for position POS in TABLE.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
273 If there is no corresponding value, return DEFAULT (defaults to nil).
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
274 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
275 (pos, table, defalt))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
276 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
277 struct Lisp_Range_Table *rt;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
278 EMACS_INT po;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
279
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
280 CHECK_RANGE_TABLE (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
281 rt = XRANGE_TABLE (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
282
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
283 CHECK_INT_COERCE_CHAR (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
284 po = XINT (pos);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
285
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
286 return get_range_table (po, Dynarr_length (rt->entries),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
287 Dynarr_atp (rt->entries, 0), defalt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
288 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
289
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
290 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
291 put_range_table (Lisp_Object table, EMACS_INT first,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
292 EMACS_INT last, Lisp_Object val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
293 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
294 int i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
295 int insert_me_here = -1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
296 struct Lisp_Range_Table *rt = XRANGE_TABLE (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
297
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
298 /* Now insert in the proper place. This gets tricky because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
299 we may be overlapping one or more existing ranges and need
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
300 to fix them up. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
301
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
302 /* First delete all sections of any existing ranges that overlap
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
303 the new range. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
304 for (i = 0; i < Dynarr_length (rt->entries); i++)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
305 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
306 struct range_table_entry *entry = Dynarr_atp (rt->entries, i);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
307 /* We insert before the first range that begins at or after the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
308 new range. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
309 if (entry->first >= first && insert_me_here < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
310 insert_me_here = i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
311 if (entry->last < first)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
312 /* completely before the new range. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
313 continue;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
314 if (entry->first > last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
315 /* completely after the new range. No more possibilities of
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
316 finding overlapping ranges. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
317 break;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
318 if (entry->first < first && entry->last <= last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
319 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
320 /* looks like:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
321
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
322 [ NEW ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
323 [ EXISTING ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
324
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
325 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
326 /* truncate the end off of it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
327 entry->last = first - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
328 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
329 else if (entry->first < first && entry->last > last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
330 /* looks like:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
331
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
332 [ NEW ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
333 [ EXISTING ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
334
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
335 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
336 /* need to split this one in two. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
337 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
338 struct range_table_entry insert_me_too;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
339
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
340 insert_me_too.first = last + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
341 insert_me_too.last = entry->last;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
342 insert_me_too.val = entry->val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
343 entry->last = first - 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
344 Dynarr_insert_many (rt->entries, &insert_me_too, 1, i + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
345 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
346 else if (entry->last > last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
347 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
348 /* looks like:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
349
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
350 [ NEW ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
351 [ EXISTING ]
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
352
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
353 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
354 /* truncate the start off of it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
355 entry->first = last + 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
356 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
357 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
358 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
359 /* existing is entirely within new. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
360 Dynarr_delete_many (rt->entries, i, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
361 i--; /* back up since everything shifted one to the left. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
362 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
363 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
364
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
365 /* Someone asked us to delete the range, not insert it. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
366 if (UNBOUNDP (val))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
367 return;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
368
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
369 /* Now insert the new entry, maybe at the end. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
370
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
371 if (insert_me_here < 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
372 insert_me_here = i;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
373
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
374 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
375 struct range_table_entry insert_me;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
376
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
377 insert_me.first = first;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
378 insert_me.last = last;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
379 insert_me.val = val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
380
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
381 Dynarr_insert_many (rt->entries, &insert_me, 1, insert_me_here);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
382 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
383
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
384 /* Now see if we can combine this entry with adjacent ones just
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
385 before or after. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
386
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
387 if (insert_me_here > 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
388 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
389 struct range_table_entry *entry = Dynarr_atp (rt->entries,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
390 insert_me_here - 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
391 if (EQ (val, entry->val) && entry->last == first - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
392 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
393 entry->last = last;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
394 Dynarr_delete_many (rt->entries, insert_me_here, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
395 insert_me_here--;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
396 /* We have morphed into a larger range. Update our records
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
397 in case we also combine with the one after. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
398 first = entry->first;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
399 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
400 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
401
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
402 if (insert_me_here < Dynarr_length (rt->entries) - 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
403 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
404 struct range_table_entry *entry = Dynarr_atp (rt->entries,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
405 insert_me_here + 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
406 if (EQ (val, entry->val) && entry->first == last + 1)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
407 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
408 entry->first = first;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
409 Dynarr_delete_many (rt->entries, insert_me_here, 1);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
410 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
411 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
412 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
413
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
414 DEFUN ("put-range-table", Fput_range_table, 4, 4, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
415 Set the value for range (START, END) to be VAL in TABLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
416 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
417 (start, end, val, table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
418 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
419 EMACS_INT first, last;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
420
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
421 CHECK_RANGE_TABLE (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
422 CHECK_INT_COERCE_CHAR (start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
423 first = XINT (start);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
424 CHECK_INT_COERCE_CHAR (end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
425 last = XINT (end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
426 if (first > last)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
427 signal_simple_error_2 ("start must be <= end", start, end);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
428
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
429 put_range_table (table, first, last, val);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
430 verify_range_table (XRANGE_TABLE (table));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
431 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
432 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
433
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
434 DEFUN ("remove-range-table", Fremove_range_table, 3, 3, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
435 Remove the value for range (START, END) in TABLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
436 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
437 (start, end, table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
438 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
439 return Fput_range_table (start, end, Qunbound, table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
440 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
441
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
442 DEFUN ("clear-range-table", Fclear_range_table, 1, 1, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
443 Flush TABLE.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
444 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
445 (table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
446 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
447 CHECK_RANGE_TABLE (table);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
448 Dynarr_reset (XRANGE_TABLE (table)->entries);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
449 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
450 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
451
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
452 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /*
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
453 Map FUNCTION over entries in TABLE, calling it with three args,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
454 the beginning and end of the range and the corresponding value.
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
455 */
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
456 (function, table))
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
457 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
458 error ("not yet implemented");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
459 return Qnil;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
460 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
461
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
462
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
463 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
464 /* Range table read syntax */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
465 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
466
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
467 static int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
468 rangetab_data_validate (Lisp_Object keyword, Lisp_Object value,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
469 Error_behavior errb)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
470 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
471 Lisp_Object rest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
472
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
473 /* #### should deal with errb */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
474 EXTERNAL_LIST_LOOP (rest, value)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
475 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
476 Lisp_Object range = XCAR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
477 rest = XCDR (rest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
478 if (!CONSP (rest))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
479 signal_simple_error ("Invalid list format", value);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
480 if (!INTP (range) && !CHARP (range)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
481 && !(CONSP (range) && CONSP (XCDR (range))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
482 && NILP (XCDR (XCDR (range)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
483 && (INTP (XCAR (range)) || CHARP (XCAR (range)))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
484 && (INTP (XCAR (XCDR (range))) || CHARP (XCAR (XCDR (range))))))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
485 signal_simple_error ("Invalid range format", range);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
486 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
487
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
488 return 1;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
489 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
490
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
491 static Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
492 rangetab_instantiate (Lisp_Object data)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
493 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
494 Lisp_Object rangetab = Fmake_range_table ();
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
495
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
496 if (!NILP (data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
497 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
498 data = Fcar (Fcdr (data)); /* skip over 'data keyword */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
499 while (!NILP (data))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
500 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
501 Lisp_Object range = Fcar (data);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
502 Lisp_Object val = Fcar (Fcdr (data));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
503
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
504 data = Fcdr (Fcdr (data));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
505 if (CONSP (range))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
506 Fput_range_table (Fcar (range), Fcar (Fcdr (range)), val,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
507 rangetab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
508 else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
509 Fput_range_table (range, range, val, rangetab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
510 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
511 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
512
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
513 return rangetab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
514 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
515
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
516
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
517 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
518 /* Unified range tables */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
519 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
520
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
521 /* A "unified range table" is a format for storing range tables
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
522 as contiguous blocks of memory. This is used by the regexp
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
523 code, which needs to use range tables to properly handle []
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
524 constructs in the presence of extended characters but wants to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
525 store an entire compiled pattern as a contiguous block of memory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
526
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
527 Unified range tables are designed so that they can be placed
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
528 at an arbitrary (possibly mis-aligned) place in memory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
529 (Dealing with alignment is a pain in the ass.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
530
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
531 WARNING: No provisions for garbage collection are currently made.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
532 This means that there must not be any Lisp objects in a unified
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
533 range table that need to be marked for garbage collection.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
534 Good candidates for objects that can go into a range table are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
535
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
536 -- numbers and characters (do not need to be marked)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
537 -- nil, t (marked elsewhere)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
538 -- charsets and coding systems (automatically marked because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
539 they are in a marked list,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
540 and can't be removed)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
541
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
542 Good but slightly less so:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
543
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
544 -- symbols (could be uninterned, but that is not likely)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
545
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
546 Somewhat less good:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
547
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
548 -- buffers, frames, devices (could get deleted)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
549
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
550
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
551 It is expected that you work with range tables in the normal
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
552 format and then convert to unified format when you are done
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
553 making modifications. As such, no functions are provided
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
554 for modifying a unified range table. The only operations
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
555 you can do to unified range tables are
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
556
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
557 -- look up a value
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
558 -- retrieve all the ranges in an iterative fashion
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
559
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
560 */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
561
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
562 /* The format of a unified range table is as follows:
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
563
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
564 -- The first byte contains the number of bytes to skip to find the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
565 actual start of the table. This deals with alignment constraints,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
566 since the table might want to go at any arbitrary place in memory.
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
567 -- The next three bytes contain the number of bytes to skip (from the
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
568 *first* byte) to find the stuff after the table. It's stored in
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
569 little-endian format because that's how God intended things. We don't
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
570 necessarily start the stuff at the very end of the table because
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
571 we want to have at least ALIGNOF (EMACS_INT) extra space in case
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
572 we have to move the range table around. (It appears that some
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
573 architectures don't maintain alignment when reallocing.)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
574 -- At the prescribed offset is a struct unified_range_table, containing
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
575 some number of `struct range_table_entry' entries. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
576
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
577 struct unified_range_table
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
578 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
579 int nentries;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
580 struct range_table_entry first;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
581 };
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
582
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
583 /* Return size in bytes needed to store the data in a range table. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
584
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
585 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
586 unified_range_table_bytes_needed (Lisp_Object rangetab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
587 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
588 return (sizeof (struct range_table_entry) *
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
589 (Dynarr_length (XRANGE_TABLE (rangetab)->entries) - 1) +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
590 sizeof (struct unified_range_table) +
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
591 /* ALIGNOF a struct may be too big. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
592 /* We have four bytes for the size numbers, and an extra
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
593 four or eight bytes for making sure we get the alignment
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
594 OK. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
595 ALIGNOF (EMACS_INT) + 4);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
596 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
597
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
598 /* Convert a range table into unified format and store in DEST,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
599 which must be able to hold the number of bytes returned by
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
600 range_table_bytes_needed(). */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
601
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
602 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
603 unified_range_table_copy_data (Lisp_Object rangetab, void *dest)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
604 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
605 /* We cast to the above structure rather than just casting to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
606 char * and adding sizeof(int), because that will lead to
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
607 mis-aligned data on the Alpha machines. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
608 struct unified_range_table *un;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
609 range_table_entry_dynarr *rted = XRANGE_TABLE (rangetab)->entries;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
610 int total_needed = unified_range_table_bytes_needed (rangetab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
611 void *new_dest = ALIGN_PTR ((char *) dest + 4, ALIGNOF (EMACS_INT));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
612
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
613 * (char *) dest = (char) ((char *) new_dest - (char *) dest);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
614 * ((unsigned char *) dest + 1) = total_needed & 0xFF;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
615 total_needed >>= 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
616 * ((unsigned char *) dest + 2) = total_needed & 0xFF;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
617 total_needed >>= 8;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
618 * ((unsigned char *) dest + 3) = total_needed & 0xFF;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
619 un = (struct unified_range_table *) new_dest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
620 un->nentries = Dynarr_length (rted);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
621 memcpy (&un->first, Dynarr_atp (rted, 0),
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
622 sizeof (struct range_table_entry) * Dynarr_length (rted));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
623 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
624
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
625 /* Return number of bytes actually used by a unified range table. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
626
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
627 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
628 unified_range_table_bytes_used (void *unrangetab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
629 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
630 return ((* ((unsigned char *) unrangetab + 1))
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
631 + ((* ((unsigned char *) unrangetab + 2)) << 8)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
632 + ((* ((unsigned char *) unrangetab + 3)) << 16));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
633 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
634
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
635 /* Make sure the table is aligned, and move it around if it's not. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
636 static void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
637 align_the_damn_table (void *unrangetab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
638 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
639 void *cur_dest = (char *) unrangetab + * (char *) unrangetab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
640 #if LONGBITS == 64
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
641 if ((((long) cur_dest) & 7) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
642 #else
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
643 if ((((int) cur_dest) & 3) != 0)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
644 #endif
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
645 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
646 int count = (unified_range_table_bytes_used (unrangetab) - 4
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
647 - ALIGNOF (EMACS_INT));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
648 /* Find the proper location, just like above. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
649 void *new_dest = ALIGN_PTR ((char *) unrangetab + 4,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
650 ALIGNOF (EMACS_INT));
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
651 /* memmove() works in the presence of overlapping data. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
652 memmove (new_dest, cur_dest, count);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
653 * (char *) unrangetab = (char) ((char *) new_dest - (char *) unrangetab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
654 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
655 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
656
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
657 /* Look up a value in a unified range table. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
658
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
659 Lisp_Object
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
660 unified_range_table_lookup (void *unrangetab, EMACS_INT pos,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
661 Lisp_Object defalt)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
662 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
663 void *new_dest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
664 struct unified_range_table *un;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
665
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
666 align_the_damn_table (unrangetab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
667 new_dest = (char *) unrangetab + * (char *) unrangetab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
668 un = (struct unified_range_table *) new_dest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
669
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
670 return get_range_table (pos, un->nentries, &un->first, defalt);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
671 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
672
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
673 /* Return number of entries in a unified range table. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
674
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
675 int
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
676 unified_range_table_nentries (void *unrangetab)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
677 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
678 void *new_dest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
679 struct unified_range_table *un;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
680
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
681 align_the_damn_table (unrangetab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
682 new_dest = (char *) unrangetab + * (char *) unrangetab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
683 un = (struct unified_range_table *) new_dest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
684 return un->nentries;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
685 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
686
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
687 /* Return the OFFSETth range (counting from 0) in UNRANGETAB. */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
688 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
689 unified_range_table_get_range (void *unrangetab, int offset,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
690 EMACS_INT *min, EMACS_INT *max,
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
691 Lisp_Object *val)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
692 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
693 void *new_dest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
694 struct unified_range_table *un;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
695 struct range_table_entry *tab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
696
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
697 align_the_damn_table (unrangetab);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
698 new_dest = (char *) unrangetab + * (char *) unrangetab;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
699 un = (struct unified_range_table *) new_dest;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
700
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
701 assert (offset >= 0 && offset < un->nentries);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
702 tab = (&un->first) + offset;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
703 *min = tab->first;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
704 *max = tab->last;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
705 *val = tab->val;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
706 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
707
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
708
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
709 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
710 /* Initialization */
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
711 /************************************************************************/
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
712
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
713 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
714 syms_of_rangetab (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
715 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
716 defsymbol (&Qrange_tablep, "range-table-p");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
717 defsymbol (&Qrange_table, "range-table");
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
718
20
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
719 DEFSUBR (Frange_table_p);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
720 DEFSUBR (Fmake_range_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
721 DEFSUBR (Fcopy_range_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
722 DEFSUBR (Fget_range_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
723 DEFSUBR (Fput_range_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
724 DEFSUBR (Fremove_range_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
725 DEFSUBR (Fclear_range_table);
859a2309aef8 Import from CVS: tag r19-15b93
cvs
parents: 0
diff changeset
726 DEFSUBR (Fmap_range_table);
0
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
727 }
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
728
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
729 void
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
730 structure_type_create_rangetab (void)
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
731 {
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
732 struct structure_type *st;
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
733
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
734 st = define_structure_type (Qrange_table, 0, rangetab_instantiate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
735
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
736 define_structure_type_keyword (st, Qdata, rangetab_data_validate);
376386a54a3c Import from CVS: tag r19-14
cvs
parents:
diff changeset
737 }