annotate src/buffer.h @ 771:943eaba38521

[xemacs-hg @ 2002-03-13 08:51:24 by ben] The big ben-mule-21-5 check-in! Various files were added and deleted. See CHANGES-ben-mule. There are still some test suite failures. No crashes, though. Many of the failures have to do with problems in the test suite itself rather than in the actual code. I'll be addressing these in the next day or so -- none of the test suite failures are at all critical. Meanwhile I'll be trying to address the biggest issues -- i.e. build or run failures, which will almost certainly happen on various platforms. All comments should be sent to ben@xemacs.org -- use a Cc: if necessary when sending to mailing lists. There will be pre- and post- tags, something like pre-ben-mule-21-5-merge-in, and post-ben-mule-21-5-merge-in.
author ben
date Wed, 13 Mar 2002 08:54:06 +0000
parents fdefd0186b75
children e38acbeb1cae
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 /* Header file for the buffer manipulation primitives.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5 Copyright (C) 2001, 2002 Ben Wing.
428
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 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 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
11 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 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
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 Boston, MA 02111-1307, USA. */
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 /* Synched up with: FSF 19.30. */
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 /* Authorship:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28 FSF: long ago.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 JWZ: separated out bufslots.h, early in Lemacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 Ben Wing: almost completely rewritten for Mule, 19.12.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
33 #ifndef INCLUDED_buffer_h_
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
34 #define INCLUDED_buffer_h_
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
36 #include "casetab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
37 #include "chartab.h"
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
38
428
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 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41 /* definition of Lisp buffer object */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
45 /* Note: we keep both Bytebpos and Charbpos versions of some of the
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 important buffer positions because they are accessed so much.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47 If we didn't do this, we would constantly be invalidating the
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
48 charbpos<->bytebpos cache under Mule.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
49
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50 Note that under non-Mule, both versions will always be the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51 same so we don't really need to keep track of them. But it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52 simplifies the logic to go ahead and do so all the time and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 the memory loss is insignificant. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
55 /* Formerly, it didn't much matter what went inside the struct buffer_text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56 and what went outside it. Now it does, with the advent of "indirect
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 buffers" that share text with another buffer. An indirect buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 shares the same *text* as another buffer, but has its own buffer-local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
59 variables, its own accessible region, and its own markers and extents.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60 (Due to the nature of markers, it doesn't actually matter much whether
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
61 we stick them inside or out of the struct buffer_text -- the user won't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 notice any difference -- but we go ahead and put them outside for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
63 consistency and overall saneness of algorithm.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65 FSFmacs gets away with not maintaining any "children" pointers from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 a buffer to the indirect buffers that refer to it by putting the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
67 markers inside of the struct buffer_text, using markers to keep track
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
68 of BEGV and ZV in indirect buffers, and relying on the fact that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
69 all intervals (text properties and overlays) use markers for their
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 start and end points. We don't do this for extents (markers are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 inefficient anyway and take up space), so we have to maintain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 children pointers. This is not terribly hard, though, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73 code to maintain this is just like the code already present in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 extent-parent and extent-children.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 struct buffer_text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
79 Intbyte *beg; /* Actual address of buffer contents. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
80 Bytebpos gpt; /* Index of gap in buffer. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
81 Bytebpos z; /* Index of end of buffer. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
82 Charbpos bufz; /* Equivalent as a Charbpos. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
83 Bytecount gap_size;/* Size of buffer's gap */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
84 Bytecount end_gap_size;/* Size of buffer's end gap */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85 long modiff; /* This counts buffer-modification events
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 for this buffer. It is incremented for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 each such event, and never otherwise
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 changed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 long save_modiff; /* Previous value of modiff, as of last
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 time buffer visited or saved a file. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #ifdef MULE
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
93 /* We keep track of a "known" region for very fast access. This
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
94 information is text-only so it goes here. We update this at each
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
95 change to the buffer, so if it's entirely ASCII, these will always
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
96 contain the minimum and maximum positions of the buffer. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
97 Charbpos mule_bufmin, mule_bufmax;
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
98 Bytebpos mule_bytmin, mule_bytmax;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 int mule_shifter, mule_three_p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 /* And we also cache 16 positions for fairly fast access near those
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 positions. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
103 Charbpos mule_charbpos_cache[16];
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
104 Bytebpos mule_bytebpos_cache[16];
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
105
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
106 int entirely_ascii_p;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 /* Similar to the above, we keep track of positions for which line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 number has last been calculated. See line-number.c. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 Lisp_Object line_number_cache;
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 /* Change data that goes with the text. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 struct buffer_text_change_data *changes;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117 struct buffer
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 struct lcrecord_header header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121 /* This structure holds the coordinates of the buffer contents
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 in ordinary buffers. In indirect buffers, this is not used. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 struct buffer_text own_text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125 /* This points to the `struct buffer_text' that is used for this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 In an ordinary buffer, this is the own_text field above.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 In an indirect buffer, this is the own_text field of another buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 struct buffer_text *text;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
130 Bytebpos pt; /* Position of point in buffer. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
131 Charbpos bufpt; /* Equivalent as a Charbpos. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
132 Bytebpos begv; /* Index of beginning of accessible range. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
133 Charbpos bufbegv; /* Equivalent as a Charbpos. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
134 Bytebpos zv; /* Index of end of accessible range. */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
135 Charbpos bufzv; /* Equivalent as a Charbpos. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137 int face_change; /* This is set when a change in how the text should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 be displayed (e.g., font, color) is made. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
140 /* Whether buffer specific face is specified. */
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
141 int buffer_local_face_property;
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 446
diff changeset
142
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 /* change data indicating what portion of the text has changed
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 since the last time this was reset. Used by redisplay.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 Logically we should keep this with the text structure, but
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 redisplay resets it for each buffer individually and we don't
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 want interference between an indirect buffer and its base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 struct each_buffer_change_data *changes;
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 #ifdef REGION_CACHE_NEEDS_WORK
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152 /* If the long line scan cache is enabled (i.e. the buffer-local
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 variable cache-long-line-scans is non-nil), newline_cache
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 points to the newline cache, and width_run_cache points to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 width run cache.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 The newline cache records which stretches of the buffer are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 known *not* to contain newlines, so that they can be skipped
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 quickly when we search for newlines.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 The width run cache records which stretches of the buffer are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 known to contain characters whose widths are all the same. If
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163 the width run cache maps a character to a value > 0, that value
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 is the character's width; if it maps a character to zero, we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 don't know what its width is. This allows compute_motion to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 process such regions very quickly, using algebra instead of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 inspecting each character. See also width_table, below. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 struct region_cache *newline_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 struct region_cache *width_run_cache;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 #endif /* REGION_CACHE_NEEDS_WORK */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 /* The markers that refer to this buffer. This is actually a single
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 marker -- successive elements in its marker `chain' are the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 markers referring to this buffer */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
175 Lisp_Marker *markers;
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 /* The buffer's extent info. This is its own type, an extent-info
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 object (done this way for ease in marking / finalizing). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
179 Lisp_Object extent_info;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
181 /* ----------------------------------------------------------------- */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
182 /* All the stuff above this line is the responsibility of insdel.c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
183 with some help from marker.c and extents.c.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 All the stuff below this line is the responsibility of buffer.c. */
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 /* In an indirect buffer, this points to the base buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
187 In an ordinary buffer, it is 0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
188 We DO mark through this slot. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
189 struct buffer *base_buffer;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
191 /* List of indirect buffers whose base is this buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
192 If we are an indirect buffer, this will be nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
193 Do NOT mark through this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
194 Lisp_Object indirect_children;
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 /* Flags saying which DEFVAR_PER_BUFFER variables
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
197 are local to this buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
198 int local_var_flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
200 /* Set to the modtime of the visited file when read or written.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
201 -1 means visited file was nonexistent.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 0 means visited file modtime unknown; in no case complain
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 about any mismatch on next save attempt. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 int modtime;
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 /* the value of text->modiff at the last auto-save. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
207 long auto_save_modified;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 /* The time at which we detected a failure to auto-save,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 Or -1 if we didn't have a failure. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 int auto_save_failure_time;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 /* Position in buffer at which display started
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214 the last time this buffer was displayed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
215 int last_window_start;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
217 /* Everything from here down must be a Lisp_Object */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
219 #define MARKED_SLOT(x) Lisp_Object x
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220 #include "bufslots.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 #undef MARKED_SLOT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 DECLARE_LRECORD (buffer, struct buffer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 #define XBUFFER(x) XRECORD (x, buffer, struct buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 #define XSETBUFFER(x, p) XSETRECORD (x, p, buffer)
617
af57a77cbc92 [xemacs-hg @ 2001-06-18 07:09:50 by ben]
ben
parents: 616
diff changeset
227 #define wrap_buffer(p) wrap_record (p, buffer)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 #define BUFFERP(x) RECORDP (x, buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer)
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 #define BUFFER_LIVE_P(b) (!NILP ((b)->name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
234 #define CHECK_LIVE_BUFFER(x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 CHECK_BUFFER (x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 if (!BUFFER_LIVE_P (XBUFFER (x))) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237 dead_wrong_type_argument (Qbuffer_live_p, (x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 } while (0)
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 #define CONCHECK_LIVE_BUFFER(x) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 CONCHECK_BUFFER (x); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242 if (!BUFFER_LIVE_P (XBUFFER (x))) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 x = wrong_type_argument (Qbuffer_live_p, (x)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
244 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245
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 #define BUFFER_BASE_BUFFER(b) ((b)->base_buffer ? (b)->base_buffer : (b))
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 /* Map over buffers sharing the same text as MPS_BUF. MPS_BUFVAR is a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 variable that gets the buffer values (beginning with the base
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 buffer, then the children), and MPS_BUFCONS should be a temporary
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252 Lisp_Object variable. */
647
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
253 #define MAP_INDIRECT_BUFFERS(mps_buf, mps_bufvar, mps_bufcons) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
254 for (mps_bufcons = Qunbound, \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
255 mps_bufvar = BUFFER_BASE_BUFFER (mps_buf); \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
256 UNBOUNDP (mps_bufcons) ? \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
257 (mps_bufcons = mps_bufvar->indirect_children, \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
258 1) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
259 : (!NILP (mps_bufcons) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
260 && (mps_bufvar = XBUFFER (XCAR (mps_bufcons)), 1) \
b39c14581166 [xemacs-hg @ 2001-08-13 04:45:47 by ben]
ben
parents: 617
diff changeset
261 && (mps_bufcons = XCDR (mps_bufcons), 1)); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262 )
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266 /* Accessor macros for important positions in a buffer */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 /* We put them here because some stuff below wants them before the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 place where we would normally put them. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 /* None of these are lvalues. Use the settor macros below to change
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273 the positions. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 /* Beginning of buffer. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
276 #define BI_BUF_BEG(buf) ((Bytebpos) 1)
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
277 #define BUF_BEG(buf) ((Charbpos) 1)
428
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 /* Beginning of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 #define BI_BUF_BEGV(buf) ((buf)->begv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 #define BUF_BEGV(buf) ((buf)->bufbegv + 0)
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 /* End of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
284 #define BI_BUF_ZV(buf) ((buf)->zv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 #define BUF_ZV(buf) ((buf)->bufzv + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287 /* End of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 #define BI_BUF_Z(buf) ((buf)->text->z + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
289 #define BUF_Z(buf) ((buf)->text->bufz + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 /* Point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 #define BI_BUF_PT(buf) ((buf)->pt + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293 #define BUF_PT(buf) ((buf)->bufpt + 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
295 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 /* Converting between positions and addresses */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
299 /* Convert the address of a byte in the buffer into a position. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
300 INLINE_HEADER Bytebpos BI_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
301 INLINE_HEADER Bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
302 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 return (ptr - buf->text->beg + 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305 - ((ptr - buf->text->beg + 1) > buf->text->gpt
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
306 ? buf->text->gap_size : 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
307 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
308
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 #define BUF_PTR_BYTE_POS(buf, ptr) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
310 bytebpos_to_charbpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312 /* Address of byte at position POS in buffer. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
313 INLINE_HEADER Intbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
314 INLINE_HEADER Intbyte *
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
315 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
317 return (buf->text->beg +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 - 1));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 #define BUF_BYTE_ADDRESS(buf, pos) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
323 BI_BUF_BYTE_ADDRESS (buf, charbpos_to_bytebpos (buf, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 /* Address of byte before position POS in buffer. */
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
326 INLINE_HEADER Intbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
327 INLINE_HEADER Intbyte *
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
328 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330 return (buf->text->beg +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 - 2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
336 BI_BUF_BYTE_ADDRESS_BEFORE (buf, charbpos_to_bytebpos (buf, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 /* Converting between byte indices and memory indices */
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
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
342 INLINE_HEADER int valid_membpos_p (struct buffer *buf, Membpos x);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
343 INLINE_HEADER int
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
344 valid_membpos_p (struct buffer *buf, Membpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
346 return ((x >= 1 && x <= (Membpos) buf->text->gpt) ||
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
347 (x > (Membpos) (buf->text->gpt + buf->text->gap_size) &&
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
348 x <= (Membpos) (buf->text->z + buf->text->gap_size)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
351 INLINE_HEADER Membpos bytebpos_to_membpos (struct buffer *buf, Bytebpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
352 INLINE_HEADER Membpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
353 bytebpos_to_membpos (struct buffer *buf, Bytebpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
355 return (Membpos) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
359 INLINE_HEADER Bytebpos membpos_to_bytebpos (struct buffer *buf, Membpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
360 INLINE_HEADER Bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
361 membpos_to_bytebpos (struct buffer *buf, Membpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
363 #ifdef ERROR_CHECK_CHARBPOS
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
364 assert (valid_membpos_p (buf, x));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 #endif
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
366 return (Bytebpos) ((x > (Membpos) buf->text->gpt) ?
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 x - buf->text->gap_size :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368 x);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
371 #define membpos_to_charbpos(buf, x) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
372 bytebpos_to_charbpos (buf, membpos_to_bytebpos (buf, x))
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
373 #define charbpos_to_membpos(buf, x) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
374 bytebpos_to_membpos (buf, charbpos_to_bytebpos (buf, x))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 /* These macros generalize many standard buffer-position functions to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 either a buffer or a string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
379 /* Converting between Membposs and Bytebposs, for a buffer-or-string.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380 For strings, this is a no-op. For buffers, this resolves
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
381 to the standard membpos<->bytebpos converters. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
383 #define buffer_or_string_bytebpos_to_membpos(obj, ind) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
384 (BUFFERP (obj) ? bytebpos_to_membpos (XBUFFER (obj), ind) : (Membpos) ind)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
386 #define buffer_or_string_membpos_to_bytebpos(obj, ind) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
387 (BUFFERP (obj) ? membpos_to_bytebpos (XBUFFER (obj), ind) : (Bytebpos) ind)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
389 /* Converting between Charbpos's and Bytebposs, for a buffer-or-string.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 For strings, this maps to the bytecount<->charcount converters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
392 #define buffer_or_string_charbpos_to_bytebpos(obj, pos) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
393 (BUFFERP (obj) ? charbpos_to_bytebpos (XBUFFER (obj), pos) : \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
394 (Bytebpos) XSTRING_INDEX_CHAR_TO_BYTE (obj, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
396 #define buffer_or_string_bytebpos_to_charbpos(obj, ind) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
397 (BUFFERP (obj) ? bytebpos_to_charbpos (XBUFFER (obj), ind) : \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
398 (Charbpos) XSTRING_INDEX_BYTE_TO_CHAR (obj, ind))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
400 /* Similar for Charbpos's and Membposs. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
402 #define buffer_or_string_charbpos_to_membpos(obj, pos) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
403 (BUFFERP (obj) ? charbpos_to_membpos (XBUFFER (obj), pos) : \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
404 (Membpos) XSTRING_INDEX_CHAR_TO_BYTE (obj, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
406 #define buffer_or_string_membpos_to_charbpos(obj, ind) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
407 (BUFFERP (obj) ? membpos_to_charbpos (XBUFFER (obj), ind) : \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
408 (Charbpos) XSTRING_INDEX_BYTE_TO_CHAR (obj, ind))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409
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 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 /* working with buffer-level data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 /* */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416 /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
417
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 (A) Working with byte indices:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 ------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
421 VALID_BYTEBPOS_P(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 Given a byte index, does it point to the beginning of a character?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
424 ASSERT_VALID_BYTEBPOS_UNSAFE(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425 If error-checking is enabled, assert that the given byte index
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
426 is within range and points to the beginning of a character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 or to the end of the buffer. Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
429 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 If error-checking is enabled, assert that the given byte index
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
431 is within range and satisfies ASSERT_VALID_BYTEBPOS() and also
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 does not refer to the beginning of the buffer. (i.e. movement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 backwards is OK.) Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
435 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 If error-checking is enabled, assert that the given byte index
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
437 is within range and satisfies ASSERT_VALID_BYTEBPOS() and also
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 does not refer to the end of the buffer. (i.e. movement
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 forwards is OK.) Otherwise, do nothing.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
441 VALIDATE_BYTEBPOS_BACKWARD(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442 Make sure that the given byte index is pointing to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 of a character. If not, back up until this is the case. Note
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 that there are not too many places where it is legitimate to do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 this sort of thing. It's an error if you're passed an "invalid"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 byte index.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
448 VALIDATE_BYTEBPOS_FORWARD(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 Make sure that the given byte index is pointing to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 of a character. If not, move forward until this is the case.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451 Note that there are not too many places where it is legitimate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 to do this sort of thing. It's an error if you're passed an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453 "invalid" byte index.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
455 INC_BYTEBPOS(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 Given a byte index (assumed to point at the beginning of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457 character), modify that value so it points to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 of the next character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
460 DEC_BYTEBPOS(buf, bi):
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 Given a byte index (assumed to point at the beginning of a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 character), modify that value so it points to the beginning
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 of the previous character. Unlike for DEC_CHARPTR(), we can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 do all the assert()s because there are sentinels at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 beginning of the gap and the end of the buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
467 BYTEBPOS_INVALID:
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
468 A constant representing an invalid Bytebpos. Valid Bytebposs
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 can never have this value.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
472 (B) Converting between Charbpos's and Bytebposs:
428
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
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
475 charbpos_to_bytebpos(buf, bu):
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
476 Given a Charbpos, return the equivalent Bytebpos.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
478 bytebpos_to_charbpos(buf, bi):
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
479 Given a Bytebpos, return the equivalent Charbpos.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
481 make_charbpos(buf, bi):
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
482 Given a Bytebpos, return the equivalent Charbpos as a Lisp Object.
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 /* working with byte indices */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 #ifdef MULE
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
491 # define VALID_BYTEBPOS_P(buf, x) \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
492 INTBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 #else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
494 # define VALID_BYTEBPOS_P(buf, x) 1
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
497 #ifdef ERROR_CHECK_CHARBPOS
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
499 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x) do { \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 assert (BUFFER_LIVE_P (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 assert ((x) >= BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
502 assert (VALID_BYTEBPOS_P (buf, x)); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 } while (0)
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
504 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x) do { \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 assert (BUFFER_LIVE_P (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 assert ((x) > BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
507 assert (VALID_BYTEBPOS_P (buf, x)); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 } while (0)
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
509 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x) do { \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 assert (BUFFER_LIVE_P (buf)); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511 assert ((x) >= BI_BUF_BEG (buf) && x < BI_BUF_Z (buf)); \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
512 assert (VALID_BYTEBPOS_P (buf, x)); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
515 #else /* not ERROR_CHECK_CHARBPOS */
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
516 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x)
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
517 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x)
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
518 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
520 #endif /* not ERROR_CHECK_CHARBPOS */
428
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 /* Note that, although the Mule version will work fine for non-Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 as well (it should reduce down to nothing), we provide a separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
524 version to avoid compilation warnings and possible non-optimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
525 results with stupid compilers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 #ifdef MULE
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
528 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) do { \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
529 Intbyte *VBB_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
530 while (!INTBYTE_FIRST_BYTE_P (*VBB_ptr)) \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
531 VBB_ptr--, (x)--; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
532 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
533 #else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
534 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
535 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 /* Note that, although the Mule version will work fine for non-Mule
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538 as well (it should reduce down to nothing), we provide a separate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 version to avoid compilation warnings and possible non-optimal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 results with stupid compilers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 #ifdef MULE
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
543 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) do { \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
544 Intbyte *VBF_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
545 while (!INTBYTE_FIRST_BYTE_P (*VBF_ptr)) \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 VBF_ptr++, (x)++; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 #else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
549 # define VALIDATE_BYTEBPOS_FORWARD(buf, x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
552 /* Note that in the simplest case (no MULE, no ERROR_CHECK_CHARBPOS),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 this crap reduces down to simply (x)++. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
555 #define INC_BYTEBPOS(buf, x) do \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 { \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
557 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE (buf, x); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 /* Note that we do the increment first to \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 make sure that the pointer in \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
560 VALIDATE_BYTEBPOS_FORWARD() ends up on \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 the correct side of the gap */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 (x)++; \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
563 VALIDATE_BYTEBPOS_FORWARD (buf, x); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
566 /* Note that in the simplest case (no MULE, no ERROR_CHECK_CHARBPOS),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 this crap reduces down to simply (x)--. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
569 #define DEC_BYTEBPOS(buf, x) do \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
570 { \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
571 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE (buf, x); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 /* Note that we do the decrement first to \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573 make sure that the pointer in \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
574 VALIDATE_BYTEBPOS_BACKWARD() ends up on \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 the correct side of the gap */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 (x)--; \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
577 VALIDATE_BYTEBPOS_BACKWARD (buf, x); \
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
580 INLINE_HEADER Bytebpos prev_bytebpos (struct buffer *buf, Bytebpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
581 INLINE_HEADER Bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
582 prev_bytebpos (struct buffer *buf, Bytebpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
584 DEC_BYTEBPOS (buf, x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 return x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
588 INLINE_HEADER Bytebpos next_bytebpos (struct buffer *buf, Bytebpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
589 INLINE_HEADER Bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
590 next_bytebpos (struct buffer *buf, Bytebpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 {
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
592 INC_BYTEBPOS (buf, x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 return x;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
596 #define BYTEBPOS_INVALID ((Bytebpos) -1)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 /* Converting between buffer positions and byte indices */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
604 Bytebpos charbpos_to_bytebpos_func (struct buffer *buf, Charbpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
605 Charbpos bytebpos_to_charbpos_func (struct buffer *buf, Bytebpos x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 /* The basic algorithm we use is to keep track of a known region of
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
608 characters in each buffer, all of which are of the same width. We keep
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
609 track of the boundaries of the region in both Charbpos and Bytebpos
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
610 coordinates and also keep track of the char width, which is 1 - 4 bytes.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
611 If the position we're translating is not in the known region, then we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
612 invoke a function to update the known region to surround the position in
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
613 question. This assumes locality of reference, which is usually the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
614 case.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
615
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
616 Note that the function to update the known region can be simple or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
617 complicated depending on how much information we cache. In addition to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
618 the known region, we always cache the correct conversions for point,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
619 BEGV, and ZV, and in addition to this we cache 16 positions where the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
620 conversion is known. We only look in the cache or update it when we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
621 need to move the known region more than a certain amount (currently 50
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
622 chars), and then we throw away a "random" value and replace it with the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
623 newly calculated value.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
624
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
625 Finally, we maintain an extra flag that tracks whether the buffer is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
626 entirely ASCII, to speed up the conversions even more. This flag is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
627 actually of dubious value because in an entirely-ASCII buffer the known
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
628 region will always span the entire buffer (in fact, we update the flag
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
629 based on this fact), and so all we're saving is a few machine cycles.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
631 A potentially smarter method than what we do with known regions and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
632 cached positions would be to keep some sort of pseudo-extent layer over
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
633 the buffer; maybe keep track of the charbpos/bytebpos correspondence at the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
634 beginning of each line, which would allow us to do a binary search over
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
635 the pseudo-extents to narrow things down to the correct line, at which
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
636 point you could use a linear movement method. This would also mesh well
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
637 with efficiently implementing a line-numbering scheme. However, you
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
638 have to weigh the amount of time spent updating the cache vs. the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
639 savings that result from it. In reality, we modify the buffer far less
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
640 often than we access it, so a cache of this sort that provides
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
641 guaranteed LOG (N) performance (or perhaps N * LOG (N), if we set a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
642 maximum on the cache size) would indeed be a win, particularly in very
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
643 large buffers. If we ever implement this, we should probably set a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
644 reasonably high minimum below which we use the old method, because the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
645 time spent updating the fancy cache would likely become dominant when
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
646 making buffer modifications in smaller buffers.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
648 Note also that we have to multiply or divide by the char width in order
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
649 to convert the positions. We do some tricks to avoid ever actually
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
650 having to do a multiply or divide, because that is typically an
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
651 expensive operation (esp. divide). Multiplying or dividing by 1, 2, or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
652 4 can be implemented simply as a shift left or shift right, and we keep
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
653 track of a shifter value (0, 1, or 2) indicating how much to shift.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
654 Multiplying by 3 can be implemented by doubling and then adding the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
655 original value. Dividing by 3, alas, cannot be implemented in any
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
656 simple shift/subtract method, as far as I know; so we just do a table
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
657 lookup. For simplicity, we use a table of size 128K, which indexes the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
658 "divide-by-3" values for the first 64K non-negative numbers. (Note that
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
659 we can increase the size up to 384K, i.e. indexing the first 192K
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
660 non-negative numbers, while still using shorts in the array.) This also
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
661 means that the size of the known region can be at most 64K for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
662 width-three characters.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
663
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
664 !!#### We should investigate the algorithm in GNU Emacs. I think it
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
665 does something similar, but it may differ in some details, and it's
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
666 worth seeing if anything can be gleaned.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669 extern short three_to_one_table[];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
671 INLINE_HEADER Bytebpos real_charbpos_to_bytebpos (struct buffer *buf, Charbpos x);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
672 INLINE_HEADER Bytebpos
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
673 real_charbpos_to_bytebpos (struct buffer *buf, Charbpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
675 if (buf->text->entirely_ascii_p)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
676 return (Bytebpos) x;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 return (buf->text->mule_bytmin +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
682 return charbpos_to_bytebpos_func (buf, x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
685 INLINE_HEADER Charbpos real_bytebpos_to_charbpos (struct buffer *buf, Bytebpos x);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
686 INLINE_HEADER Charbpos
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
687 real_bytebpos_to_charbpos (struct buffer *buf, Bytebpos x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
689 if (buf->text->entirely_ascii_p)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
690 return (Charbpos) x;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 return (buf->text->mule_bufmin +
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693 ((buf->text->mule_three_p
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 ? three_to_one_table[x - buf->text->mule_bytmin]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 else
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
697 return bytebpos_to_charbpos_func (buf, x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 #else /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
702 # define real_charbpos_to_bytebpos(buf, x) ((Bytebpos) x)
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
703 # define real_bytebpos_to_charbpos(buf, x) ((Charbpos) x)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 #endif /* not MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
707 #ifdef ERROR_CHECK_CHARBPOS
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
709 Bytebpos charbpos_to_bytebpos (struct buffer *buf, Charbpos x);
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
710 Charbpos bytebpos_to_charbpos (struct buffer *buf, Bytebpos x);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
712 #else /* not ERROR_CHECK_CHARBPOS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
713
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
714 #define charbpos_to_bytebpos real_charbpos_to_bytebpos
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
715 #define bytebpos_to_charbpos real_bytebpos_to_charbpos
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
717 #endif /* not ERROR_CHECK_CHARBPOS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
719 #define make_charbpos(buf, ind) make_int (bytebpos_to_charbpos (buf, ind))
428
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 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 /* Converting between buffer bytes and Emacs characters */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 /*----------------------------------------------------------------------*/
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 /* The character at position POS in buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 #define BI_BUF_FETCH_CHAR(buf, pos) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 charptr_emchar (BI_BUF_BYTE_ADDRESS (buf, pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 #define BUF_FETCH_CHAR(buf, pos) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
729 BI_BUF_FETCH_CHAR (buf, charbpos_to_bytebpos (buf, pos))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 /* The character at position POS in buffer, as a string. This is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732 equivalent to set_charptr_emchar (str, BUF_FETCH_CHAR (buf, pos))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 but is faster for Mule. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
738 BI_BUF_CHARPTR_COPY_CHAR (buf, charbpos_to_bytebpos (buf, pos), str)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
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 /************************************************************************/
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
742 /* */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 /* higher-level buffer-position functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 /* Settor macros for important positions in a buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 /* Set beginning of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 #define SET_BOTH_BUF_BEGV(buf, val, bival) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 (buf)->begv = (bival); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 (buf)->bufbegv = (val); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 } while (0)
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 /* Set end of accessible range of buffer. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 #define SET_BOTH_BUF_ZV(buf, val, bival) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 (buf)->zv = (bival); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 (buf)->bufzv = (val); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767 /* Set point. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 /* Since BEGV and ZV are almost never set, it's reasonable to enforce
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
769 the restriction that the Charbpos and Bytebpos values must both be
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
770 specified. However, point is set in lots and lots of places. So
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 we provide the ability to specify both (for efficiency) or just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772 one. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 #define BOTH_BUF_SET_PT(buf, val, bival) set_buffer_point (buf, val, bival)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 #define BI_BUF_SET_PT(buf, bival) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
775 BOTH_BUF_SET_PT (buf, bytebpos_to_charbpos (buf, bival), bival)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 #define BUF_SET_PT(buf, value) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
777 BOTH_BUF_SET_PT (buf, value, charbpos_to_bytebpos (buf, value))
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 #if 0 /* FSFmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 does too much stuff, such as moving out of invisible extents. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 #define SET_BUF_PT(buf, value) ((buf)->pt = (value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 #endif /* FSFmacs */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 /*----------------------------------------------------------------------*/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 /* Miscellaneous buffer values */
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 /* Number of characters in buffer */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 /* Is this buffer narrowed? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 #define BUF_NARROWED(buf) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 ((BI_BUF_BEGV (buf) != BI_BUF_BEG (buf)) || \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 (BI_BUF_ZV (buf) != BI_BUF_Z (buf)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 /* Modification count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800 #define BUF_MODIFF(buf) ((buf)->text->modiff)
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 /* Saved modification count. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805 /* Face changed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 #define BUF_FACECHANGE(buf) ((buf)->face_change)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 #define POINT_MARKER_P(marker) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 (XMARKER (marker)->buffer != 0 && \
434
9d177e8d4150 Import from CVS: tag r21-2-25
cvs
parents: 428
diff changeset
810 EQ (marker, XMARKER (marker)->buffer->point_marker))
428
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 #define BUF_MARKERS(buf) ((buf)->markers)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 /* WARNING:
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 The new definitions of CEILING_OF() and FLOOR_OF() differ semantically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817 from the old ones (in FSF Emacs and XEmacs 19.11 and before).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 Conversion is as follows:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 OLD_BI_CEILING_OF(n) = NEW_BI_CEILING_OF(n) - 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821 OLD_BI_FLOOR_OF(n) = NEW_BI_FLOOR_OF(n + 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 The definitions were changed because the new definitions are more
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
824 consistent with the way everything else works in XEmacs.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 */
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 /* Properties of CEILING_OF and FLOOR_OF (also apply to BI_ variants):
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 1) FLOOR_OF (CEILING_OF (n)) = n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 CEILING_OF (FLOOR_OF (n)) = n
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 2) CEILING_OF (n) = n if and only if n = ZV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 FLOOR_OF (n) = n if and only if n = BEGV
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 3) CEILING_OF (CEILING_OF (n)) = ZV
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 FLOOR_OF (FLOOR_OF (n)) = BEGV
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 4) The bytes in the regions
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 [BYTE_ADDRESS (n), BYTE_ADDRESS_BEFORE (CEILING_OF (n))]
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 and
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 [BYTE_ADDRESS (FLOOR_OF (n)), BYTE_ADDRESS_BEFORE (n)]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 are contiguous.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
847
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
848 A typical loop using CEILING_OF to process contiguous ranges of text
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
849 between [from, to) looks like this:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
850
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
851 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
852 Bytebpos pos = from;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
853
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
854 while (pos < to)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
855 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
856 Bytebpos ceil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
857
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
858 ceil = BI_BUF_CEILING_OF (buf, pos);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
859 ceil = min (to, ceil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
860 process_intbyte_string (BI_BUF_BYTE_ADDRESS (buf, pos), ceil - pos);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
861 pos = ceil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
862 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
863 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
864
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
865 Currently there will be at most two iterations in the loop, but it is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
866 written in such a way that it will still work if the buffer
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
867 representation is changed to have multiple gaps in it.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
868 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 /* Return the maximum index in the buffer it is safe to scan forwards
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 past N to. This is used to prevent buffer scans from running into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 the gap (e.g. search.c). All characters between N and CEILING_OF(N)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 are located contiguous in memory. Note that the character *at*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 CEILING_OF(N) is not contiguous in memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 #define BI_BUF_CEILING_OF(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_ZV (b) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 (b)->text->gpt : BI_BUF_ZV (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 #define BUF_CEILING_OF(b, n) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
880 bytebpos_to_charbpos (b, BI_BUF_CEILING_OF (b, charbpos_to_bytebpos (b, n)))
428
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 /* Return the minimum index in the buffer it is safe to scan backwards
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883 past N to. All characters between FLOOR_OF(N) and N are located
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 contiguous in memory. Note that the character *at* N may not be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885 contiguous in memory. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 #define BI_BUF_FLOOR_OF(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887 (BI_BUF_BEGV (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 (b)->text->gpt : BI_BUF_BEGV (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 #define BUF_FLOOR_OF(b, n) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
890 bytebpos_to_charbpos (b, BI_BUF_FLOOR_OF (b, charbpos_to_bytebpos (b, n)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 #define BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_Z (b) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
894 (b)->text->gpt : BI_BUF_Z (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
895 #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
896 bytebpos_to_charbpos \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
897 (b, BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
898
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
899 #define BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
900 (BI_BUF_BEG (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
901 (b)->text->gpt : BI_BUF_BEG (b))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
902 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
903 bytebpos_to_charbpos \
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
904 (b, BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
905
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
906 /* This structure marks which slots in a buffer have corresponding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
907 default values in Vbuffer_defaults.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
908 Each such slot has a nonzero value in this structure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
909 The value has only one nonzero bit.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
910
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
911 When a buffer has its own local value for a slot,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
912 the bit for that slot (found in the same slot in this structure)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
913 is turned on in the buffer's local_var_flags slot.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
915 If a slot in this structure is zero, then even though there may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
916 be a DEFVAR_BUFFER_LOCAL for the slot, there is no default value for it;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 and the corresponding slot in Vbuffer_defaults is not used. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 extern struct buffer buffer_local_flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
921
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
922 /* Allocation of buffer data. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
923
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 #ifdef REL_ALLOC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
926 char *r_alloc (unsigned char **, size_t);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
927 char *r_re_alloc (unsigned char **, size_t);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928 void r_alloc_free (unsigned char **);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930 #define BUFFER_ALLOC(data, size) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
931 ((Intbyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Intbyte)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
932 #define BUFFER_REALLOC(data, size) \
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
933 ((Intbyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Intbyte)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 #else /* !REL_ALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939 #define BUFFER_ALLOC(data,size)\
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
940 (data = xnew_array (Intbyte, size))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
941 #define BUFFER_REALLOC(data,size)\
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 650
diff changeset
942 ((Intbyte *) xrealloc (data, (size) * sizeof(Intbyte)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
943 /* Avoid excess parentheses, or syntax errors may rear their heads. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
944 #define BUFFER_FREE(data) xfree (data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
945 #define R_ALLOC_DECLARE(var,data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
946
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
947 #endif /* !REL_ALLOC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
948
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951 /* Case conversion */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
952 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
953
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 /* A "trt" table is a mapping from characters to other characters,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
955 typically used to convert between uppercase and lowercase. For
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
956 compatibility reasons, trt tables are currently in the form of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
957 a Lisp string of 256 characters, specifying the conversion for each
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
958 of the first 256 Emacs characters (i.e. the 256 Latin-1 characters).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
959 This should be generalized at some point to support conversions for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
960 all of the allowable Mule characters.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
962
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 /* The _1 macros are named as such because they assume that you have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 already guaranteed that the character values are all in the range
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 0 - 255. Bad lossage will happen otherwise. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
967 #define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
968 INLINE_HEADER Emchar TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar c);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
969 INLINE_HEADER Emchar
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
970 TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar ch)
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
971 {
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
972 Lisp_Object TRT_char;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
973 TRT_char = get_char_table (ch, XCHAR_TABLE (table));
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
974 if (NILP (TRT_char))
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
975 return ch;
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
976 else
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
977 return XCHAR (TRT_char);
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
978 }
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
979 #define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
980 Fput_char_table (make_char (ch1), make_char (ch2), table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
982 INLINE_HEADER Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
983 INLINE_HEADER Emchar
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 TRT_TABLE_OF (Lisp_Object trt, Emchar c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 {
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
986 return TRT_TABLE_CHAR_1 (trt, c);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
989 INLINE_HEADER Lisp_Object BUFFER_CASE_TABLE (struct buffer *buf);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
990 INLINE_HEADER Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
991 BUFFER_CASE_TABLE (struct buffer *buf)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
992 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
993 return buf ? buf->case_table : Vstandard_case_table;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
994 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
995
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
996 /* Macros used below. */
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
997 #define DOWNCASE_TABLE_OF(buf, c) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
998 TRT_TABLE_OF (XCASE_TABLE_DOWNCASE (BUFFER_CASE_TABLE (buf)), c)
446
1ccc32a20af4 Import from CVS: tag r21-2-38
cvs
parents: 444
diff changeset
999 #define UPCASE_TABLE_OF(buf, c) \
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1000 TRT_TABLE_OF (XCASE_TABLE_UPCASE (BUFFER_CASE_TABLE (buf)), c)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1002 /* 1 if CH is upper case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1003
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1004 INLINE_HEADER int UPPERCASEP (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1005 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 UPPERCASEP (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 return DOWNCASE_TABLE_OF (buf, ch) != ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 /* 1 if CH is lower case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1013 INLINE_HEADER int LOWERCASEP (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1014 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 LOWERCASEP (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017 return (UPCASE_TABLE_OF (buf, ch) != ch &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 DOWNCASE_TABLE_OF (buf, ch) == ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 /* 1 if CH is neither upper nor lower case. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1023 INLINE_HEADER int NOCASEP (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1024 INLINE_HEADER int
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 NOCASEP (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 return UPCASE_TABLE_OF (buf, ch) == ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 /* Upcase a character, or make no change if that cannot be done. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1032 INLINE_HEADER Emchar UPCASE (struct buffer *buf, Emchar ch);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1033 INLINE_HEADER Emchar
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 UPCASE (struct buffer *buf, Emchar ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 /* Upcase a character known to be not upper case. Unused. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 /* Downcase a character, or make no change if that cannot be done. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 434
diff changeset
1047 #endif /* INCLUDED_buffer_h_ */