annotate src/rangetab.c @ 5118:e0db3c197671 ben-lisp-object

merge up to latest default branch, doesn't compile yet
author Ben Wing <ben@xemacs.org>
date Sat, 26 Dec 2009 21:18:49 -0600
parents 3742ea8250b5 312503644bc3
children b5df3737028a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* XEmacs routines to deal with range tables.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1995 Sun Microsystems, Inc.
2952
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
3 Copyright (C) 1995, 2002, 2004, 2005 Ben Wing.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Synched up with: Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* Written by Ben Wing, August 1995. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 #include "rangetab.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 Lisp_Object Qrange_tablep;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 Lisp_Object Qrange_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
33 Lisp_Object Qstart_closed_end_open;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
34 Lisp_Object Qstart_open_end_open;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
35 Lisp_Object Qstart_closed_end_closed;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
36 Lisp_Object Qstart_open_end_closed;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
37
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
40 /* Range table object */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
43 static enum range_table_type
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
44 range_table_symbol_to_type (Lisp_Object symbol)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
45 {
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
46 if (NILP (symbol))
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
47 return RANGE_START_CLOSED_END_OPEN;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
48
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
49 CHECK_SYMBOL (symbol);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
50 if (EQ (symbol, Qstart_closed_end_open))
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
51 return RANGE_START_CLOSED_END_OPEN;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
52 if (EQ (symbol, Qstart_closed_end_closed))
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
53 return RANGE_START_CLOSED_END_CLOSED;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
54 if (EQ (symbol, Qstart_open_end_open))
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
55 return RANGE_START_OPEN_END_OPEN;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
56 if (EQ (symbol, Qstart_open_end_closed))
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
57 return RANGE_START_OPEN_END_CLOSED;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
58
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
59 invalid_constant ("Unknown range table type", symbol);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
60 RETURN_NOT_REACHED (RANGE_START_CLOSED_END_OPEN);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
61 }
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
62
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
63 static Lisp_Object
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
64 range_table_type_to_symbol (enum range_table_type type)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
65 {
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
66 switch (type)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
67 {
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
68 case RANGE_START_CLOSED_END_OPEN:
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
69 return Qstart_closed_end_open;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
70 case RANGE_START_CLOSED_END_CLOSED:
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
71 return Qstart_closed_end_closed;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
72 case RANGE_START_OPEN_END_OPEN:
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
73 return Qstart_open_end_open;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
74 case RANGE_START_OPEN_END_CLOSED:
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
75 return Qstart_open_end_closed;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
76 }
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
77
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2425
diff changeset
78 ABORT ();
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
79 return Qnil;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
80 }
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
81
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82 /* We use a sorted array of ranges.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 #### We should be using the gap array stuff from extents.c. This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 is not hard but just requires moving that stuff out of that file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 mark_range_table (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
90 Lisp_Range_Table *rt = XRANGE_TABLE (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 for (i = 0; i < Dynarr_length (rt->entries); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 mark_object (Dynarr_at (rt->entries, i).val);
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4391
diff changeset
95
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1204
diff changeset
100 print_range_table (Lisp_Object obj, Lisp_Object printcharfun,
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1204
diff changeset
101 int UNUSED (escapeflag))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
103 Lisp_Range_Table *rt = XRANGE_TABLE (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
106 if (print_readably)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
107 write_fmt_string_lisp (printcharfun, "#s(range-table type %s data (",
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
108 1, range_table_type_to_symbol (rt->type));
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
109 else
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
110 write_c_string (printcharfun, "#<range-table ");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 for (i = 0; i < Dynarr_length (rt->entries); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 struct range_table_entry *rte = Dynarr_atp (rt->entries, i);
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
114 int so, ec;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 if (i > 0)
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
116 write_c_string (printcharfun, " ");
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
117 switch (rt->type)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
118 {
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
119 case RANGE_START_CLOSED_END_OPEN: so = 0, ec = 0; break;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
120 case RANGE_START_CLOSED_END_CLOSED: so = 0, ec = 1; break;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
121 case RANGE_START_OPEN_END_OPEN: so = 1, ec = 0; break;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
122 case RANGE_START_OPEN_END_CLOSED: so = 1; ec = 1; break;
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2425
diff changeset
123 default: ABORT (); so = 0, ec = 0; break;
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
124 }
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
125 write_fmt_string (printcharfun, "%c%ld %ld%c ",
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
126 print_readably ? '(' : so ? '(' : '[',
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
127 (long) (rte->first - so),
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
128 (long) (rte->last - ec),
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
129 print_readably ? ')' : ec ? ']' : ')'
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
130 );
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 print_internal (rte->val, printcharfun, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132 }
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
133 if (print_readably)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
134 write_c_string (printcharfun, "))");
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
135 else
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
136 write_fmt_string (printcharfun, " 0x%x>", rt->header.uid);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 range_table_equal (Lisp_Object obj1, Lisp_Object obj2, int depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
142 Lisp_Range_Table *rt1 = XRANGE_TABLE (obj1);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
143 Lisp_Range_Table *rt2 = XRANGE_TABLE (obj2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 if (Dynarr_length (rt1->entries) != Dynarr_length (rt2->entries))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 for (i = 0; i < Dynarr_length (rt1->entries); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 struct range_table_entry *rte1 = Dynarr_atp (rt1->entries, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 struct range_table_entry *rte2 = Dynarr_atp (rt2->entries, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 if (rte1->first != rte2->first
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 || rte1->last != rte2->last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 || !internal_equal (rte1->val, rte2->val, depth + 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162
2515
de9952d2ed18 [xemacs-hg @ 2005-01-26 10:22:19 by ben]
ben
parents: 2500
diff changeset
163 static Hashcode
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 range_table_entry_hash (struct range_table_entry *rte, int depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 return HASH3 (rte->first, rte->last, internal_hash (rte->val, depth + 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168
2515
de9952d2ed18 [xemacs-hg @ 2005-01-26 10:22:19 by ben]
ben
parents: 2500
diff changeset
169 static Hashcode
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 range_table_hash (Lisp_Object obj, int depth)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
172 Lisp_Range_Table *rt = XRANGE_TABLE (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 int size = Dynarr_length (rt->entries);
2515
de9952d2ed18 [xemacs-hg @ 2005-01-26 10:22:19 by ben]
ben
parents: 2500
diff changeset
175 Hashcode hash = size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 /* approach based on internal_array_hash(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 if (size <= 5)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180 for (i = 0; i < size; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 hash = HASH2 (hash,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 range_table_entry_hash (Dynarr_atp (rt->entries, i),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 depth));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 return hash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
185 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
186
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 /* just pick five elements scattered throughout the array.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 A slightly better approach would be to offset by some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 noise factor from the points chosen below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 for (i = 0; i < 5; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 hash = HASH2 (hash, range_table_entry_hash (Dynarr_atp (rt->entries,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 i*size/5),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 depth));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 return hash;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
195 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
197 static const struct memory_description rte_description_1[] = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
198 { XD_LISP_OBJECT, offsetof (range_table_entry, val) },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
202 static const struct sized_memory_description rte_description = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
203 sizeof (range_table_entry),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 rte_description_1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
207 static const struct memory_description rted_description_1[] = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
208 XD_DYNARR_DESC (range_table_entry_dynarr, &rte_description),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
212 static const struct sized_memory_description rted_description = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
213 sizeof (range_table_entry_dynarr),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 rted_description_1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 934
diff changeset
217 static const struct memory_description range_table_description[] = {
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2515
diff changeset
218 { XD_BLOCK_PTR, offsetof (Lisp_Range_Table, entries), 1,
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2515
diff changeset
219 { &rted_description } },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4713
diff changeset
223 DEFINE_DUMPABLE_LISP_OBJECT ("range-table", range_table,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4713
diff changeset
224 mark_range_table, print_range_table, 0,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4713
diff changeset
225 range_table_equal, range_table_hash,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4713
diff changeset
226 range_table_description,
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4713
diff changeset
227 Lisp_Range_Table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 /* Range table operations */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
233 #ifdef ERROR_CHECK_STRUCTURES
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 static void
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
236 verify_range_table (Lisp_Range_Table *rt)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
239
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 for (i = 0; i < Dynarr_length (rt->entries); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 struct range_table_entry *rte = Dynarr_atp (rt->entries, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 assert (rte->last >= rte->first);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 if (i > 0)
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
245 assert (Dynarr_at (rt->entries, i - 1).last <= rte->first);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
249 #else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 #define verify_range_table(rt)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 /* Look up in a range table without the Dynarr wrapper.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 Used also by the unified range table format. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 get_range_table (EMACS_INT pos, int nentries, struct range_table_entry *tab,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 Lisp_Object default_)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 int left = 0, right = nentries;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 /* binary search for the entry. Based on similar code in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 extent_list_locate(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 while (left != right)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 /* RIGHT might not point to a valid entry (i.e. it's at the end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 of the list), so NEWPOS must round down. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 578
diff changeset
270 int newpos = (left + right) >> 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 struct range_table_entry *entry = tab + newpos;
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
272 if (pos >= entry->last)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
273 left = newpos + 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274 else if (pos < entry->first)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 right = newpos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277 return entry->val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
279
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 return default_;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 DEFUN ("range-table-p", Frange_table_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 Return non-nil if OBJECT is a range table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 return RANGE_TABLEP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
291 DEFUN ("range-table-type", Frange_table_type, 1, 1, 0, /*
4713
312503644bc3 Correct the docstring for #'range-table-type.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4690
diff changeset
292 Return the type of RANGE-TABLE.
312503644bc3 Correct the docstring for #'range-table-type.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4690
diff changeset
293
312503644bc3 Correct the docstring for #'range-table-type.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4690
diff changeset
294 This will be a symbol describing how ranges in RANGE-TABLE function at their
312503644bc3 Correct the docstring for #'range-table-type.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4690
diff changeset
295 ends; see `make-range-table'.
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
296 */
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
297 (range_table))
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
298 {
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
299 CHECK_RANGE_TABLE (range_table);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
300 return range_table_type_to_symbol (XRANGE_TABLE (range_table)->type);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
301 }
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
302
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
303 DEFUN ("make-range-table", Fmake_range_table, 0, 1, 0, /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 Return a new, empty range table.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 You can manipulate it using `put-range-table', `get-range-table',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 `remove-range-table', and `clear-range-table'.
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
307 Range tables allow you to efficiently set values for ranges of integers.
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
308
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
309 TYPE is a symbol indicating how ranges are assumed to function at their
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
310 ends. It can be one of
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
311
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
312 SYMBOL RANGE-START RANGE-END
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
313 ------ ----------- ---------
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
314 `start-closed-end-open' (the default) closed open
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
315 `start-closed-end-closed' closed closed
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
316 `start-open-end-open' open open
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
317 `start-open-end-closed' open closed
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
318
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
319 A `closed' endpoint of a range means that the number at that end is included
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
320 in the range. For an `open' endpoint, the number would not be included.
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
321
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
322 For example, a closed-open range from 5 to 20 would be indicated as [5,
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
323 20) where a bracket indicates a closed end and a parenthesis an open end,
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
324 and would mean `all the numbers between 5 and 20', including 5 but not 20.
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
325 This seems a little strange at first but is in fact extremely common in
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
326 the outside world as well as in computers and makes things work sensibly.
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
327 For example, if I say "there are seven days between today and next week
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
328 today", I'm including today but not next week today; if I included both,
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
329 there would be eight days. Similarly, there are 15 (= 20 - 5) elements in
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
330 the range [5, 20), but 16 in the range [5, 20].
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 */
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
332 (type))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
334 Lisp_Object obj = ALLOC_LISP_OBJECT (range_table);
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
335 Lisp_Range_Table *rt = XRANGE_TABLE (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 rt->entries = Dynarr_new (range_table_entry);
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
337 rt->type = range_table_symbol_to_type (type);
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
338 return obj;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 DEFUN ("copy-range-table", Fcopy_range_table, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
342 Return a new range table which is a copy of RANGE-TABLE.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
343 It will contain the same values for the same ranges as RANGE-TABLE.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
344 The values will not themselves be copied.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
346 (range_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
348 Lisp_Range_Table *rt, *rtnew;
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
349 Lisp_Object obj;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
351 CHECK_RANGE_TABLE (range_table);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
352 rt = XRANGE_TABLE (range_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
354 obj = ALLOC_LISP_OBJECT (range_table);
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
355 rtnew = XRANGE_TABLE (obj);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 rtnew->entries = Dynarr_new (range_table_entry);
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
357 rtnew->type = rt->type;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359 Dynarr_add_many (rtnew->entries, Dynarr_atp (rt->entries, 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 Dynarr_length (rt->entries));
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
361 return obj;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 DEFUN ("get-range-table", Fget_range_table, 2, 3, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
365 Find value for position POS in RANGE-TABLE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 If there is no corresponding value, return DEFAULT (defaults to nil).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
368 (pos, range_table, default_))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
370 Lisp_Range_Table *rt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
372 CHECK_RANGE_TABLE (range_table);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
373 rt = XRANGE_TABLE (range_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 CHECK_INT_COERCE_CHAR (pos);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 return get_range_table (XINT (pos), Dynarr_length (rt->entries),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 Dynarr_atp (rt->entries, 0), default_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
379 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 put_range_table (Lisp_Object table, EMACS_INT first,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 EMACS_INT last, Lisp_Object val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 int insert_me_here = -1;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 428
diff changeset
387 Lisp_Range_Table *rt = XRANGE_TABLE (table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
389 /* Fix up the numbers in accordance with the open/closedness to make
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
390 them behave like default open/closed. */
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
391
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
392 switch (rt->type)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
393 {
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
394 case RANGE_START_CLOSED_END_OPEN: break;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
395 case RANGE_START_CLOSED_END_CLOSED: last++; break;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
396 case RANGE_START_OPEN_END_OPEN: first++; break;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
397 case RANGE_START_OPEN_END_CLOSED: first++, last++; break;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
398 }
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
399
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
400 if (first == last)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
401 return;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
402 if (first > last)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
403 /* This will happen if originally first == last and both ends are
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
404 open. #### Should we signal an error? */
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
405 return;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
406
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 /* Now insert in the proper place. This gets tricky because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 we may be overlapping one or more existing ranges and need
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 to fix them up. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 /* First delete all sections of any existing ranges that overlap
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 the new range. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 for (i = 0; i < Dynarr_length (rt->entries); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 struct range_table_entry *entry = Dynarr_atp (rt->entries, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 /* We insert before the first range that begins at or after the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417 new range. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 if (entry->first >= first && insert_me_here < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 insert_me_here = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 if (entry->last < first)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 /* completely before the new range. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 continue;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 if (entry->first > last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 /* completely after the new range. No more possibilities of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 finding overlapping ranges. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 break;
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
427 /* At this point the existing ENTRY overlaps or touches the new one. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 if (entry->first < first && entry->last <= last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 /* looks like:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
431
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
432 [ NEW )
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
433 [ EXISTING )
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
434
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
435 or
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
436
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
437 [ NEW )
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
438 [ EXISTING )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 /* truncate the end off of it. */
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
442 entry->last = first;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 else if (entry->first < first && entry->last > last)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 /* looks like:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
447 [ NEW )
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
448 [ EXISTING )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 /* need to split this one in two. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 struct range_table_entry insert_me_too;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
455 insert_me_too.first = last;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 insert_me_too.last = entry->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 insert_me_too.val = entry->val;
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
458 entry->last = first;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 Dynarr_insert_many (rt->entries, &insert_me_too, 1, i + 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460 }
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
461 else if (entry->last >= last)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 /* looks like:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
465 [ NEW )
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
466 [ EXISTING )
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
467
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
468 or
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
469
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
470 [ NEW )
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
471 [ EXISTING )
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 /* truncate the start off of it. */
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
475 entry->first = last;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 /* existing is entirely within new. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 Dynarr_delete_many (rt->entries, i, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481 i--; /* back up since everything shifted one to the left. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 /* Someone asked us to delete the range, not insert it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 if (UNBOUNDP (val))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 /* Now insert the new entry, maybe at the end. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 if (insert_me_here < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 insert_me_here = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 struct range_table_entry insert_me;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 insert_me.first = first;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 insert_me.last = last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 insert_me.val = val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 Dynarr_insert_many (rt->entries, &insert_me, 1, insert_me_here);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 /* Now see if we can combine this entry with adjacent ones just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 before or after. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 if (insert_me_here > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 struct range_table_entry *entry = Dynarr_atp (rt->entries,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 insert_me_here - 1);
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
511 if (EQ (val, entry->val) && entry->last == first)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 entry->last = last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514 Dynarr_delete_many (rt->entries, insert_me_here, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 insert_me_here--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 /* We have morphed into a larger range. Update our records
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 in case we also combine with the one after. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 first = entry->first;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 if (insert_me_here < Dynarr_length (rt->entries) - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 struct range_table_entry *entry = Dynarr_atp (rt->entries,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 insert_me_here + 1);
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
526 if (EQ (val, entry->val) && entry->first == last)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528 entry->first = first;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
529 Dynarr_delete_many (rt->entries, insert_me_here, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
534 DEFUN ("put-range-table", Fput_range_table, 4, 4, 0, /*
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
535 Set the value for range START .. END to be VALUE in RANGE-TABLE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
537 (start, end, value, range_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 EMACS_INT first, last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
541 CHECK_RANGE_TABLE (range_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 CHECK_INT_COERCE_CHAR (start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 first = XINT (start);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 CHECK_INT_COERCE_CHAR (end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 last = XINT (end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 if (first > last)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 444
diff changeset
547 invalid_argument_2 ("start must be <= end", start, end);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
549 put_range_table (range_table, first, last, value);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
550 verify_range_table (XRANGE_TABLE (range_table));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 DEFUN ("remove-range-table", Fremove_range_table, 3, 3, 0, /*
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
555 Remove the value for range START .. END in RANGE-TABLE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
557 (start, end, range_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
559 return Fput_range_table (start, end, Qunbound, range_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 DEFUN ("clear-range-table", Fclear_range_table, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
563 Flush RANGE-TABLE.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
565 (range_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
567 CHECK_RANGE_TABLE (range_table);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
568 Dynarr_reset (XRANGE_TABLE (range_table)->entries);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 DEFUN ("map-range-table", Fmap_range_table, 2, 2, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
573 Map FUNCTION over entries in RANGE-TABLE, calling it with three args,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 the beginning and end of the range and the corresponding value.
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
575
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
576 Results are guaranteed to be correct (i.e. each entry processed
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
577 exactly once) if FUNCTION modifies or deletes the current entry
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
578 \(i.e. passes the current range to `put-range-table' or
4391
cbf129b005df Clarify #'map-range-table docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3017
diff changeset
579 `remove-range-table'). If FUNCTION modifies or deletes any other entry,
cbf129b005df Clarify #'map-range-table docstring.
Aidan Kehoe <kehoea@parhasard.net>
parents: 3017
diff changeset
580 this guarantee doesn't hold.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
582 (function, range_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
584 Lisp_Range_Table *rt;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
585 int i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
586
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
587 CHECK_RANGE_TABLE (range_table);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
588 CHECK_FUNCTION (function);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
589
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
590 rt = XRANGE_TABLE (range_table);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
591
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
592 /* Do not "optimize" by pulling out the length computation below!
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
593 FUNCTION may have changed the table. */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
594 for (i = 0; i < Dynarr_length (rt->entries); i++)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
595 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
596 struct range_table_entry *entry = Dynarr_atp (rt->entries, i);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
597 EMACS_INT first, last;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
598 Lisp_Object args[4];
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
599 int oldlen;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
600
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
601 again:
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
602 first = entry->first;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
603 last = entry->last;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
604 oldlen = Dynarr_length (rt->entries);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
605 args[0] = function;
2952
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
606 /* Fix up the numbers in accordance with the open/closedness of the
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
607 table. */
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
608 {
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
609 EMACS_INT premier = first, dernier = last;
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
610 switch (rt->type)
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
611 {
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
612 case RANGE_START_CLOSED_END_OPEN: break;
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
613 case RANGE_START_CLOSED_END_CLOSED: dernier--; break;
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
614 case RANGE_START_OPEN_END_OPEN: premier--; break;
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
615 case RANGE_START_OPEN_END_CLOSED: premier--, dernier--; break;
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
616 }
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
617 args[1] = make_int (premier);
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
618 args[2] = make_int (dernier);
861a7995b9fe [xemacs-hg @ 2005-09-26 08:29:27 by ben]
ben
parents: 2720
diff changeset
619 }
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
620 args[3] = entry->val;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
621 Ffuncall (countof (args), args);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
622 /* Has FUNCTION removed the entry? */
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
623 if (oldlen > Dynarr_length (rt->entries)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
624 && i < Dynarr_length (rt->entries)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
625 && (first != entry->first || last != entry->last))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
626 goto again;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
627 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
628
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 /* Range table read syntax */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637 static int
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
638 rangetab_type_validate (Lisp_Object UNUSED (keyword), Lisp_Object value,
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
639 Error_Behavior UNUSED (errb))
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
640 {
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
641 /* #### should deal with ERRB */
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
642 range_table_symbol_to_type (value);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
643 return 1;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
644 }
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
645
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
646 static int
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1204
diff changeset
647 rangetab_data_validate (Lisp_Object UNUSED (keyword), Lisp_Object value,
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 1204
diff changeset
648 Error_Behavior UNUSED (errb))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
650 /* #### should deal with ERRB */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2286
diff changeset
651 EXTERNAL_PROPERTY_LIST_LOOP_3 (range, data, value)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 if (!INTP (range) && !CHARP (range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 && !(CONSP (range) && CONSP (XCDR (range))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
655 && NILP (XCDR (XCDR (range)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 && (INTP (XCAR (range)) || CHARP (XCAR (range)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 && (INTP (XCAR (XCDR (range))) || CHARP (XCAR (XCDR (range))))))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 444
diff changeset
658 sferror ("Invalid range format", range);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664 static Lisp_Object
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
665 rangetab_instantiate (Lisp_Object plist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 {
2425
b3315b0c8558 [xemacs-hg @ 2004-12-06 23:27:15 by ben]
ben
parents: 2421
diff changeset
667 Lisp_Object data = Qnil, type = Qnil, rangetab;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
669 PROPERTY_LIST_LOOP_3 (key, value, plist)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 {
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
671 if (EQ (key, Qtype)) type = value;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
672 else if (EQ (key, Qdata)) data = value;
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
673 else
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2425
diff changeset
674 ABORT ();
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
675 }
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
676
2425
b3315b0c8558 [xemacs-hg @ 2004-12-06 23:27:15 by ben]
ben
parents: 2421
diff changeset
677 rangetab = Fmake_range_table (type);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
679 {
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
680 PROPERTY_LIST_LOOP_3 (range, val, data)
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
681 {
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
682 if (CONSP (range))
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
683 Fput_range_table (Fcar (range), Fcar (Fcdr (range)), val,
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
684 rangetab);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
685 else
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
686 Fput_range_table (range, range, val, rangetab);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
687 }
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
688 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 return rangetab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 /* Unified range tables */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 /* A "unified range table" is a format for storing range tables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 as contiguous blocks of memory. This is used by the regexp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 code, which needs to use range tables to properly handle []
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 constructs in the presence of extended characters but wants to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 store an entire compiled pattern as a contiguous block of memory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 Unified range tables are designed so that they can be placed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 at an arbitrary (possibly mis-aligned) place in memory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 (Dealing with alignment is a pain in the ass.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 WARNING: No provisions for garbage collection are currently made.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 This means that there must not be any Lisp objects in a unified
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 range table that need to be marked for garbage collection.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 Good candidates for objects that can go into a range table are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713 -- numbers and characters (do not need to be marked)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 -- nil, t (marked elsewhere)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 -- charsets and coding systems (automatically marked because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 they are in a marked list,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 and can't be removed)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 Good but slightly less so:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 -- symbols (could be uninterned, but that is not likely)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 Somewhat less good:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 -- buffers, frames, devices (could get deleted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 It is expected that you work with range tables in the normal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 format and then convert to unified format when you are done
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730 making modifications. As such, no functions are provided
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 for modifying a unified range table. The only operations
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 you can do to unified range tables are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 -- look up a value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 -- retrieve all the ranges in an iterative fashion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739 /* The format of a unified range table is as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 -- The first byte contains the number of bytes to skip to find the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742 actual start of the table. This deals with alignment constraints,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 since the table might want to go at any arbitrary place in memory.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 -- The next three bytes contain the number of bytes to skip (from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 *first* byte) to find the stuff after the table. It's stored in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 little-endian format because that's how God intended things. We don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 necessarily start the stuff at the very end of the table because
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 we want to have at least ALIGNOF (EMACS_INT) extra space in case
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 we have to move the range table around. (It appears that some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 architectures don't maintain alignment when reallocing.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 -- At the prescribed offset is a struct unified_range_table, containing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 some number of `struct range_table_entry' entries. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 struct unified_range_table
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 int nentries;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 struct range_table_entry first;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 /* Return size in bytes needed to store the data in a range table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 unified_range_table_bytes_needed (Lisp_Object rangetab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 return (sizeof (struct range_table_entry) *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 (Dynarr_length (XRANGE_TABLE (rangetab)->entries) - 1) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 sizeof (struct unified_range_table) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 /* ALIGNOF a struct may be too big. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 /* We have four bytes for the size numbers, and an extra
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 four or eight bytes for making sure we get the alignment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 OK. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 ALIGNOF (EMACS_INT) + 4);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
775 /* Convert a range table into unified format and store in DEST,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 which must be able to hold the number of bytes returned by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777 range_table_bytes_needed(). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 unified_range_table_copy_data (Lisp_Object rangetab, void *dest)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 /* We cast to the above structure rather than just casting to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 char * and adding sizeof(int), because that will lead to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 mis-aligned data on the Alpha machines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 struct unified_range_table *un;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 range_table_entry_dynarr *rted = XRANGE_TABLE (rangetab)->entries;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 int total_needed = unified_range_table_bytes_needed (rangetab);
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
788 void *new_dest = ALIGN_PTR ((char *) dest + 4, EMACS_INT);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 * (char *) dest = (char) ((char *) new_dest - (char *) dest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 * ((unsigned char *) dest + 1) = total_needed & 0xFF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 total_needed >>= 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793 * ((unsigned char *) dest + 2) = total_needed & 0xFF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 total_needed >>= 8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 * ((unsigned char *) dest + 3) = total_needed & 0xFF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 un = (struct unified_range_table *) new_dest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 un->nentries = Dynarr_length (rted);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 memcpy (&un->first, Dynarr_atp (rted, 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 sizeof (struct range_table_entry) * Dynarr_length (rted));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 /* Return number of bytes actually used by a unified range table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 unified_range_table_bytes_used (void *unrangetab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 return ((* ((unsigned char *) unrangetab + 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 + ((* ((unsigned char *) unrangetab + 2)) << 8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 + ((* ((unsigned char *) unrangetab + 3)) << 16));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 /* Make sure the table is aligned, and move it around if it's not. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 align_the_damn_table (void *unrangetab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 void *cur_dest = (char *) unrangetab + * (char *) unrangetab;
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
817 if (cur_dest != ALIGN_PTR (cur_dest, EMACS_INT))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 int count = (unified_range_table_bytes_used (unrangetab) - 4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 - ALIGNOF (EMACS_INT));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 /* Find the proper location, just like above. */
826
6728e641994e [xemacs-hg @ 2002-05-05 11:30:15 by ben]
ben
parents: 800
diff changeset
822 void *new_dest = ALIGN_PTR ((char *) unrangetab + 4, EMACS_INT);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 /* memmove() works in the presence of overlapping data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824 memmove (new_dest, cur_dest, count);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 * (char *) unrangetab = (char) ((char *) new_dest - (char *) unrangetab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 /* Look up a value in a unified range table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 unified_range_table_lookup (void *unrangetab, EMACS_INT pos,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 Lisp_Object default_)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 void *new_dest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 struct unified_range_table *un;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 align_the_damn_table (unrangetab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 new_dest = (char *) unrangetab + * (char *) unrangetab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 un = (struct unified_range_table *) new_dest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 return get_range_table (pos, un->nentries, &un->first, default_);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 /* Return number of entries in a unified range table. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 unified_range_table_nentries (void *unrangetab)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850 void *new_dest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 struct unified_range_table *un;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853 align_the_damn_table (unrangetab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 new_dest = (char *) unrangetab + * (char *) unrangetab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 un = (struct unified_range_table *) new_dest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856 return un->nentries;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 /* Return the OFFSETth range (counting from 0) in UNRANGETAB. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 unified_range_table_get_range (void *unrangetab, int offset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 EMACS_INT *min, EMACS_INT *max,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 Lisp_Object *val)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865 void *new_dest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 struct unified_range_table *un;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 struct range_table_entry *tab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 align_the_damn_table (unrangetab);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 new_dest = (char *) unrangetab + * (char *) unrangetab;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 un = (struct unified_range_table *) new_dest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 assert (offset >= 0 && offset < un->nentries);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 tab = (&un->first) + offset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 *min = tab->first;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 *max = tab->last;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 *val = tab->val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
882 /* Initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 syms_of_rangetab (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3017
diff changeset
888 INIT_LISP_OBJECT (range_table);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
889
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 444
diff changeset
890 DEFSYMBOL_MULTIWORD_PREDICATE (Qrange_tablep);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 444
diff changeset
891 DEFSYMBOL (Qrange_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
893 DEFSYMBOL (Qstart_closed_end_open);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
894 DEFSYMBOL (Qstart_open_end_open);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
895 DEFSYMBOL (Qstart_closed_end_closed);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
896 DEFSYMBOL (Qstart_open_end_closed);
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
897
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898 DEFSUBR (Frange_table_p);
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
899 DEFSUBR (Frange_table_type);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 DEFSUBR (Fmake_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 DEFSUBR (Fcopy_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 DEFSUBR (Fget_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
903 DEFSUBR (Fput_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
904 DEFSUBR (Fremove_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905 DEFSUBR (Fclear_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 DEFSUBR (Fmap_range_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910 structure_type_create_rangetab (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 struct structure_type *st;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 st = define_structure_type (Qrange_table, 0, rangetab_instantiate);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 define_structure_type_keyword (st, Qdata, rangetab_data_validate);
2421
ab71ad6ff3dd [xemacs-hg @ 2004-12-06 03:50:53 by ben]
ben
parents: 2367
diff changeset
917 define_structure_type_keyword (st, Qtype, rangetab_type_validate);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 }