0
|
1 /* Header file for the buffer manipulation primitives.
|
|
2 Copyright (C) 1985, 1986, 1992, 1993, 1994, 1995
|
|
3 Free Software Foundation, Inc.
|
|
4 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: FSF 19.30. */
|
|
24
|
|
25 /* Authorship:
|
|
26
|
|
27 FSF: long ago.
|
|
28 JWZ: separated out bufslots.h, early in Lemacs.
|
|
29 Ben Wing: almost completely rewritten for Mule, 19.12.
|
|
30 */
|
|
31
|
|
32 #ifndef _XEMACS_BUFFER_H_
|
|
33 #define _XEMACS_BUFFER_H_
|
|
34
|
70
|
35 #ifdef MULE
|
|
36 #include "mule-charset.h"
|
|
37 #endif
|
16
|
38
|
0
|
39 /************************************************************************/
|
|
40 /* */
|
|
41 /* definition of Lisp buffer object */
|
|
42 /* */
|
|
43 /************************************************************************/
|
|
44
|
|
45 /* Note: we keep both Bytind and Bufpos versions of some of the
|
|
46 important buffer positions because they are accessed so much.
|
|
47 If we didn't do this, we would constantly be invalidating the
|
|
48 bufpos<->bytind cache under Mule.
|
|
49
|
|
50 Note that under non-Mule, both versions will always be the
|
|
51 same so we don't really need to keep track of them. But it
|
|
52 simplifies the logic to go ahead and do so all the time and
|
|
53 the memory loss is insignificant. */
|
|
54
|
|
55 /* Formerly, it didn't much matter what went inside the struct buffer_text
|
|
56 and what went outside it. Now it does, with the advent of "indirect
|
|
57 buffers" that share text with another buffer. An indirect buffer
|
|
58 shares the same *text* as another buffer, but has its own buffer-local
|
|
59 variables, its own accessible region, and its own markers and extents.
|
|
60 (Due to the nature of markers, it doesn't actually matter much whether
|
|
61 we stick them inside or out of the struct buffer_text -- the user won't
|
|
62 notice any difference -- but we go ahead and put them outside for
|
|
63 consistency and overall saneness of algorithm.)
|
|
64
|
|
65 FSFmacs gets away with not maintaining any "children" pointers from
|
|
66 a buffer to the indirect buffers that refer to it by putting the
|
|
67 markers inside of the struct buffer_text, using markers to keep track
|
|
68 of BEGV and ZV in indirect buffers, and relying on the fact that
|
|
69 all intervals (text properties and overlays) use markers for their
|
|
70 start and end points. We don't do this for extents (markers are
|
|
71 inefficient anyway and take up space), so we have to maintain
|
|
72 children pointers. This is not terribly hard, though, and the
|
|
73 code to maintain this is just like the code already present in
|
|
74 extent-parent and extent-children.
|
|
75 */
|
|
76
|
|
77 struct buffer_text
|
167
|
78 {
|
185
|
79 Bufbyte *beg; /* Actual address of buffer contents. */
|
167
|
80 Bytind gpt; /* Index of gap in buffer. */
|
|
81 Bytind z; /* Index of end of buffer. */
|
|
82 Bufpos bufz; /* Equivalent as a Bufpos. */
|
|
83 int gap_size; /* Size of buffer's gap */
|
|
84 int end_gap_size; /* Size of buffer's end gap */
|
|
85 long modiff; /* This counts buffer-modification events
|
|
86 for this buffer. It is incremented for
|
|
87 each such event, and never otherwise
|
|
88 changed. */
|
|
89 long save_modiff; /* Previous value of modiff, as of last
|
|
90 time buffer visited or saved a file. */
|
0
|
91
|
70
|
92 #ifdef MULE
|
167
|
93 /* We keep track of a "known" region for very fast access.
|
|
94 This information is text-only so it goes here. */
|
|
95 Bufpos mule_bufmin, mule_bufmax;
|
|
96 Bytind mule_bytmin, mule_bytmax;
|
|
97 int mule_shifter, mule_three_p;
|
70
|
98
|
167
|
99 /* And we also cache 16 positions for fairly fast access near those
|
|
100 positions. */
|
|
101 Bufpos mule_bufpos_cache[16];
|
|
102 Bytind mule_bytind_cache[16];
|
70
|
103 #endif
|
0
|
104
|
167
|
105 /* Change data that goes with the text. */
|
|
106 struct buffer_text_change_data *changes;
|
0
|
107
|
167
|
108 };
|
0
|
109
|
|
110 struct buffer
|
167
|
111 {
|
|
112 struct lcrecord_header header;
|
0
|
113
|
167
|
114 /* This structure holds the coordinates of the buffer contents
|
|
115 in ordinary buffers. In indirect buffers, this is not used. */
|
|
116 struct buffer_text own_text;
|
0
|
117
|
167
|
118 /* This points to the `struct buffer_text' that is used for this buffer.
|
|
119 In an ordinary buffer, this is the own_text field above.
|
|
120 In an indirect buffer, this is the own_text field of another buffer. */
|
|
121 struct buffer_text *text;
|
0
|
122
|
167
|
123 Bytind pt; /* Position of point in buffer. */
|
|
124 Bufpos bufpt; /* Equivalent as a Bufpos. */
|
|
125 Bytind begv; /* Index of beginning of accessible range. */
|
|
126 Bufpos bufbegv; /* Equivalent as a Bufpos. */
|
|
127 Bytind zv; /* Index of end of accessible range. */
|
|
128 Bufpos bufzv; /* Equivalent as a Bufpos. */
|
0
|
129
|
167
|
130 int face_change; /* This is set when a change in how the text should
|
|
131 be displayed (e.g., font, color) is made. */
|
0
|
132
|
167
|
133 /* change data indicating what portion of the text has changed
|
|
134 since the last time this was reset. Used by redisplay.
|
|
135 Logically we should keep this with the text structure, but
|
|
136 redisplay resets it for each buffer individually and we don't
|
|
137 want interference between an indirect buffer and its base
|
|
138 buffer. */
|
|
139 struct each_buffer_change_data *changes;
|
0
|
140
|
|
141 #ifdef REGION_CACHE_NEEDS_WORK
|
167
|
142 /* If the long line scan cache is enabled (i.e. the buffer-local
|
|
143 variable cache-long-line-scans is non-nil), newline_cache
|
|
144 points to the newline cache, and width_run_cache points to the
|
|
145 width run cache.
|
0
|
146
|
167
|
147 The newline cache records which stretches of the buffer are
|
|
148 known *not* to contain newlines, so that they can be skipped
|
|
149 quickly when we search for newlines.
|
0
|
150
|
167
|
151 The width run cache records which stretches of the buffer are
|
|
152 known to contain characters whose widths are all the same. If
|
|
153 the width run cache maps a character to a value > 0, that value
|
|
154 is the character's width; if it maps a character to zero, we
|
|
155 don't know what its width is. This allows compute_motion to
|
|
156 process such regions very quickly, using algebra instead of
|
|
157 inspecting each character. See also width_table, below. */
|
|
158 struct region_cache *newline_cache;
|
|
159 struct region_cache *width_run_cache;
|
|
160 #endif /* REGION_CACHE_NEEDS_WORK */
|
0
|
161
|
167
|
162 /* The markers that refer to this buffer. This is actually a single
|
|
163 marker -- successive elements in its marker `chain' are the other
|
|
164 markers referring to this buffer */
|
|
165 struct Lisp_Marker *markers;
|
0
|
166
|
167
|
167 /* The buffer's extent info. This is its own type, an extent-info
|
|
168 object (done this way for ease in marking / finalizing). */
|
|
169 Lisp_Object extent_info;
|
0
|
170
|
167
|
171 /* ----------------------------------------------------------------- */
|
|
172 /* All the stuff above this line is the responsibility of insdel.c,
|
|
173 with some help from marker.c and extents.c.
|
|
174 All the stuff below this line is the responsibility of buffer.c. */
|
0
|
175
|
167
|
176 /* In an indirect buffer, this points to the base buffer.
|
|
177 In an ordinary buffer, it is 0.
|
|
178 We DO mark through this slot. */
|
|
179 struct buffer *base_buffer;
|
0
|
180
|
167
|
181 /* List of indirect buffers whose base is this buffer.
|
|
182 If we are an indirect buffer, this will be nil.
|
|
183 Do NOT mark through this. */
|
|
184 Lisp_Object indirect_children;
|
0
|
185
|
167
|
186 /* Flags saying which DEFVAR_PER_BUFFER variables
|
|
187 are local to this buffer. */
|
|
188 int local_var_flags;
|
0
|
189
|
167
|
190 /* Set to the modtime of the visited file when read or written.
|
|
191 -1 means visited file was nonexistent.
|
|
192 0 means visited file modtime unknown; in no case complain
|
|
193 about any mismatch on next save attempt. */
|
|
194 int modtime;
|
0
|
195
|
167
|
196 /* the value of text->modiff at the last auto-save. */
|
|
197 int auto_save_modified;
|
0
|
198
|
167
|
199 /* The time at which we detected a failure to auto-save,
|
|
200 Or -1 if we didn't have a failure. */
|
|
201 int auto_save_failure_time;
|
0
|
202
|
167
|
203 /* Position in buffer at which display started
|
|
204 the last time this buffer was displayed. */
|
|
205 int last_window_start;
|
0
|
206
|
167
|
207 /* Everything from here down must be a Lisp_Object */
|
0
|
208
|
|
209 #define MARKED_SLOT(x) Lisp_Object x
|
|
210 #include "bufslots.h"
|
|
211 #undef MARKED_SLOT
|
167
|
212 };
|
0
|
213
|
|
214 DECLARE_LRECORD (buffer, struct buffer);
|
|
215 #define XBUFFER(x) XRECORD (x, buffer, struct buffer)
|
|
216 #define XSETBUFFER(x, p) XSETRECORD (x, p, buffer)
|
|
217 #define BUFFERP(x) RECORDP (x, buffer)
|
|
218 #define GC_BUFFERP(x) GC_RECORDP (x, buffer)
|
|
219 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer)
|
|
220 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer)
|
|
221
|
|
222 #define BUFFER_LIVE_P(b) (!NILP ((b)->name))
|
|
223 extern Lisp_Object Qbuffer_live_p;
|
183
|
224 #define CHECK_LIVE_BUFFER(x) \
|
|
225 do { CHECK_BUFFER (x); \
|
|
226 if (!BUFFER_LIVE_P (XBUFFER (x))) \
|
|
227 dead_wrong_type_argument (Qbuffer_live_p, (x)); \
|
0
|
228 } while (0)
|
183
|
229 #define CONCHECK_LIVE_BUFFER(x) \
|
|
230 do { CONCHECK_BUFFER (x); \
|
|
231 if (!BUFFER_LIVE_P (XBUFFER (x))) \
|
|
232 x = wrong_type_argument (Qbuffer_live_p, (x)); \
|
0
|
233 } while (0)
|
|
234
|
|
235 #define BUFFER_OR_STRING_P(x) (BUFFERP (x) || STRINGP (x))
|
|
236
|
|
237 extern Lisp_Object Qbuffer_or_string_p;
|
183
|
238 #define CHECK_BUFFER_OR_STRING(x) \
|
|
239 do { if (!BUFFER_OR_STRING_P (x)) \
|
|
240 dead_wrong_type_argument (Qbuffer_or_string_p, (x)); \
|
0
|
241 } while (0)
|
183
|
242 #define CONCHECK_BUFFER_OR_STRING(x) \
|
|
243 do { if (!BUFFER_OR_STRING_P (x)) \
|
|
244 x = wrong_type_argument (Qbuffer_or_string_p, (x)); \
|
0
|
245 } while (0)
|
|
246
|
183
|
247 #define CHECK_LIVE_BUFFER_OR_STRING(x) \
|
|
248 do { CHECK_BUFFER_OR_STRING (x); \
|
|
249 if (BUFFERP (x)) \
|
|
250 CHECK_LIVE_BUFFER (x); \
|
0
|
251 } while (0)
|
183
|
252 #define CONCHECK_LIVE_BUFFER_OR_STRING(x) \
|
|
253 do { CONCHECK_BUFFER_OR_STRING (x); \
|
|
254 if (BUFFERP (x)) \
|
|
255 CONCHECK_LIVE_BUFFER (x); \
|
0
|
256 } while (0)
|
|
257
|
|
258
|
|
259
|
|
260 /* NOTE: In all the following macros, we follow these rules concerning
|
|
261 multiple evaluation of the arguments:
|
|
262
|
|
263 1) Anything that's an lvalue can be evaluated more than once.
|
|
264 2) Anything that's a Lisp Object can be evaluated more than once.
|
|
265 This should probably be changed, but this follows the way
|
|
266 that all the macros in lisp.h do things.
|
|
267 3) 'struct buffer *' arguments can be evaluated more than once.
|
|
268 4) Nothing else can be evaluated more than once. Use MTxx
|
|
269 variables to prevent multiple evaluation.
|
|
270 5) An exception to (4) is that there are some macros below that
|
|
271 may evaluate their arguments more than once. They are all
|
|
272 denoted with the word "unsafe" in their name and are generally
|
|
273 meant to be called only by other macros that have already
|
|
274 stored the calling values in temporary variables.
|
|
275
|
|
276 */
|
|
277
|
|
278 /************************************************************************/
|
|
279 /* */
|
|
280 /* working with raw internal-format data */
|
|
281 /* */
|
|
282 /************************************************************************/
|
|
283
|
|
284 /* Use these on contiguous strings of data. If the text you're
|
|
285 operating on is known to come from a buffer, use the buffer-level
|
|
286 functions below -- they know about the gap and may be more
|
|
287 efficient. */
|
|
288
|
|
289 /* Functions are as follows:
|
|
290
|
|
291
|
|
292 (A) For working with charptr's (pointers to internally-formatted text):
|
|
293 -----------------------------------------------------------------------
|
|
294
|
|
295 VALID_CHARPTR_P(ptr):
|
|
296 Given a charptr, does it point to the beginning of a character?
|
|
297
|
|
298 ASSERT_VALID_CHARPTR(ptr):
|
|
299 If error-checking is enabled, assert that the given charptr
|
|
300 points to the beginning of a character. Otherwise, do nothing.
|
|
301
|
|
302 INC_CHARPTR(ptr):
|
|
303 Given a charptr (assumed to point at the beginning of a character),
|
|
304 modify that pointer so it points to the beginning of the next
|
|
305 character.
|
|
306
|
|
307 DEC_CHARPTR(ptr):
|
|
308 Given a charptr (assumed to point at the beginning of a
|
|
309 character or at the very end of the text), modify that pointer
|
|
310 so it points to the beginning of the previous character.
|
|
311
|
|
312 VALIDATE_CHARPTR_BACKWARD(ptr):
|
|
313 Make sure that PTR is pointing to the beginning of a character.
|
|
314 If not, back up until this is the case. Note that there are not
|
|
315 too many places where it is legitimate to do this sort of thing.
|
|
316 It's an error if you're passed an "invalid" char * pointer.
|
|
317 NOTE: PTR *must* be pointing to a valid part of the string (i.e.
|
|
318 not the very end, unless the string is zero-terminated or
|
|
319 something) in order for this function to not cause crashes.
|
|
320
|
|
321 VALIDATE_CHARPTR_FORWARD(ptr):
|
|
322 Make sure that PTR is pointing to the beginning of a character.
|
|
323 If not, move forward until this is the case. Note that there
|
|
324 are not too many places where it is legitimate to do this sort
|
|
325 of thing. It's an error if you're passed an "invalid" char *
|
|
326 pointer.
|
|
327
|
|
328
|
|
329 (B) For working with the length (in bytes and characters) of a
|
|
330 section of internally-formatted text:
|
|
331 --------------------------------------------------------------
|
|
332
|
|
333 bytecount_to_charcount(ptr, nbi):
|
|
334 Given a pointer to a text string and a length in bytes,
|
|
335 return the equivalent length in characters.
|
|
336
|
|
337 charcount_to_bytecount(ptr, nch):
|
|
338 Given a pointer to a text string and a length in characters,
|
|
339 return the equivalent length in bytes.
|
|
340
|
|
341 charptr_n_addr(ptr, n):
|
|
342 Return a pointer to the beginning of the character offset N
|
|
343 (in characters) from PTR.
|
|
344
|
|
345 charptr_length(ptr):
|
|
346 Given a zero-terminated pointer to Emacs characters,
|
|
347 return the number of Emacs characters contained within.
|
|
348
|
|
349
|
|
350 (C) For retrieving or changing the character pointed to by a charptr:
|
|
351 ---------------------------------------------------------------------
|
|
352
|
|
353 charptr_emchar(ptr):
|
|
354 Retrieve the character pointed to by PTR as an Emchar.
|
|
355
|
|
356 charptr_emchar_n(ptr, n):
|
|
357 Retrieve the character at offset N (in characters) from PTR,
|
|
358 as an Emchar.
|
|
359
|
|
360 set_charptr_emchar(ptr, ch):
|
|
361 Store the character CH (an Emchar) as internally-formatted
|
|
362 text starting at PTR. Return the number of bytes stored.
|
|
363
|
|
364 charptr_copy_char(ptr, ptr2):
|
|
365 Retrieve the character pointed to by PTR and store it as
|
|
366 internally-formatted text in PTR2.
|
|
367
|
|
368
|
|
369 (D) For working with Emchars:
|
|
370 -----------------------------
|
|
371
|
70
|
372 [Note that there are other functions/macros for working with Emchars
|
|
373 in mule-charset.h, for retrieving the charset of an Emchar
|
|
374 and such. These are only valid when MULE is defined.]
|
|
375
|
0
|
376 valid_char_p(ch):
|
|
377 Return whether the given Emchar is valid.
|
|
378
|
|
379 CHARP(ch):
|
|
380 Return whether the given Lisp_Object is a valid character.
|
|
381 This is approximately the same as saying the Lisp_Object is
|
|
382 an int whose value is a valid Emchar. (But not exactly
|
|
383 because when MULE is not defined, we allow arbitrary values
|
|
384 in all but the lowest 8 bits and mask them off, for backward
|
|
385 compatibility.)
|
|
386
|
|
387 CHECK_CHAR_COERCE_INT(ch):
|
|
388 Signal an error if CH is not a valid character as per CHARP().
|
|
389 Also canonicalize the value into a valid Emchar, as necessary.
|
|
390 (This only means anything when MULE is not defined.)
|
|
391
|
|
392 COERCE_CHAR(ch):
|
|
393 Coerce an object that is known to satisfy CHARP() into a
|
|
394 valid Emchar.
|
|
395
|
|
396 MAX_EMCHAR_LEN:
|
|
397 Maximum number of buffer bytes per Emacs character.
|
|
398
|
|
399 */
|
|
400
|
|
401
|
|
402 /* ---------------------------------------------------------------------- */
|
|
403 /* (A) For working with charptr's (pointers to internally-formatted text) */
|
|
404 /* ---------------------------------------------------------------------- */
|
|
405
|
70
|
406 #ifdef MULE
|
|
407 # define VALID_CHARPTR_P(ptr) BUFBYTE_FIRST_BYTE_P (* (unsigned char *) ptr)
|
|
408 #else
|
16
|
409 # define VALID_CHARPTR_P(ptr) 1
|
70
|
410 #endif
|
0
|
411
|
|
412 #ifdef ERROR_CHECK_BUFPOS
|
|
413 # define ASSERT_VALID_CHARPTR(ptr) assert (VALID_CHARPTR_P (ptr))
|
|
414 #else
|
|
415 # define ASSERT_VALID_CHARPTR(ptr)
|
|
416 #endif
|
|
417
|
|
418 /* Note that INC_CHARPTR() and DEC_CHARPTR() have to be written in
|
|
419 completely separate ways. INC_CHARPTR() cannot use the DEC_CHARPTR()
|
|
420 trick of looking for a valid first byte because it might run off
|
|
421 the end of the string. DEC_CHARPTR() can't use the INC_CHARPTR()
|
|
422 method because it doesn't have easy access to the first byte of
|
|
423 the character it's moving over. */
|
|
424
|
|
425 #define real_inc_charptr_fun(ptr) \
|
|
426 ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))
|
|
427 #ifdef ERROR_CHECK_BUFPOS
|
|
428 #define inc_charptr_fun(ptr) (ASSERT_VALID_CHARPTR (ptr), \
|
|
429 real_inc_charptr_fun (ptr))
|
|
430 #else
|
|
431 #define inc_charptr_fun(ptr) real_inc_charptr_fun (ptr)
|
|
432 #endif
|
|
433
|
|
434 #define REAL_INC_CHARPTR(ptr) do \
|
|
435 { \
|
|
436 real_inc_charptr_fun (ptr); \
|
|
437 } while (0)
|
|
438
|
|
439 #define INC_CHARPTR(ptr) do \
|
|
440 { \
|
|
441 ASSERT_VALID_CHARPTR (ptr); \
|
|
442 REAL_INC_CHARPTR (ptr); \
|
|
443 } while (0)
|
|
444
|
|
445 #define REAL_DEC_CHARPTR(ptr) do \
|
|
446 { \
|
|
447 (ptr)--; \
|
|
448 } while (!VALID_CHARPTR_P (ptr))
|
|
449
|
|
450 #ifdef ERROR_CHECK_BUFPOS
|
|
451 #define DEC_CHARPTR(ptr) do \
|
|
452 { \
|
|
453 CONST Bufbyte *__dcptr__ = (ptr); \
|
|
454 CONST Bufbyte *__dcptr2__ = __dcptr__; \
|
|
455 REAL_DEC_CHARPTR (__dcptr2__); \
|
|
456 assert (__dcptr__ - __dcptr2__ == \
|
|
457 REP_BYTES_BY_FIRST_BYTE (*__dcptr2__)); \
|
|
458 (ptr) = __dcptr2__; \
|
|
459 } while (0)
|
|
460 #else
|
|
461 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr)
|
|
462 #endif
|
|
463
|
70
|
464 #ifdef MULE
|
|
465
|
|
466 #define VALIDATE_CHARPTR_BACKWARD(ptr) do \
|
|
467 { \
|
|
468 while (!VALID_CHARPTR_P (ptr)) ptr--; \
|
|
469 } while (0)
|
|
470
|
|
471 /* This needs to be trickier to avoid the possibility of running off
|
|
472 the end of the string. */
|
|
473
|
|
474 #define VALIDATE_CHARPTR_FORWARD(ptr) do \
|
|
475 { \
|
|
476 Bufbyte *__vcfptr__ = (ptr); \
|
|
477 VALIDATE_CHARPTR_BACKWARD (__vcfptr__); \
|
|
478 if (__vcfptr__ != (ptr)) \
|
|
479 { \
|
|
480 (ptr) = __vcfptr__; \
|
|
481 INC_CHARPTR (ptr); \
|
|
482 } \
|
|
483 } while (0)
|
|
484
|
|
485 #else /* not MULE */
|
0
|
486 #define VALIDATE_CHARPTR_BACKWARD(ptr)
|
|
487 #define VALIDATE_CHARPTR_FORWARD(ptr)
|
70
|
488 #endif /* not MULE */
|
0
|
489
|
|
490 /* -------------------------------------------------------------- */
|
|
491 /* (B) For working with the length (in bytes and characters) of a */
|
|
492 /* section of internally-formatted text */
|
|
493 /* -------------------------------------------------------------- */
|
|
494
|
|
495 INLINE CONST Bufbyte *charptr_n_addr (CONST Bufbyte *ptr, Charcount offset);
|
|
496 INLINE CONST Bufbyte *
|
|
497 charptr_n_addr (CONST Bufbyte *ptr, Charcount offset)
|
|
498 {
|
|
499 return ptr + charcount_to_bytecount (ptr, offset);
|
|
500 }
|
|
501
|
|
502 INLINE Charcount charptr_length (CONST Bufbyte *ptr);
|
|
503 INLINE Charcount
|
|
504 charptr_length (CONST Bufbyte *ptr)
|
|
505 {
|
|
506 return bytecount_to_charcount (ptr, strlen ((CONST char *) ptr));
|
|
507 }
|
|
508
|
|
509
|
|
510 /* -------------------------------------------------------------------- */
|
|
511 /* (C) For retrieving or changing the character pointed to by a charptr */
|
|
512 /* -------------------------------------------------------------------- */
|
|
513
|
|
514 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0])
|
|
515 #define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Bufbyte) (x), 1)
|
|
516 #define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1)
|
|
517
|
70
|
518 #ifdef MULE
|
|
519
|
|
520 Emchar non_ascii_charptr_emchar (CONST Bufbyte *ptr);
|
|
521 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c);
|
167
|
522 Bytecount non_ascii_charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
|
70
|
523
|
|
524 INLINE Emchar charptr_emchar (CONST Bufbyte *ptr);
|
|
525 INLINE Emchar
|
|
526 charptr_emchar (CONST Bufbyte *ptr)
|
|
527 {
|
183
|
528 return BYTE_ASCII_P (*ptr) ?
|
|
529 simple_charptr_emchar (ptr) :
|
|
530 non_ascii_charptr_emchar (ptr);
|
70
|
531 }
|
|
532
|
|
533 INLINE Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x);
|
|
534 INLINE Bytecount
|
|
535 set_charptr_emchar (Bufbyte *ptr, Emchar x)
|
|
536 {
|
183
|
537 return !CHAR_MULTIBYTE_P (x) ?
|
|
538 simple_set_charptr_emchar (ptr, x) :
|
|
539 non_ascii_set_charptr_emchar (ptr, x);
|
70
|
540 }
|
|
541
|
|
542 INLINE Bytecount charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
|
|
543 INLINE Bytecount
|
|
544 charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2)
|
|
545 {
|
183
|
546 return BYTE_ASCII_P (*ptr) ?
|
|
547 simple_charptr_copy_char (ptr, ptr2) :
|
|
548 non_ascii_charptr_copy_char (ptr, ptr2);
|
70
|
549 }
|
|
550
|
|
551 #else /* not MULE */
|
|
552
|
0
|
553 # define charptr_emchar(ptr) simple_charptr_emchar (ptr)
|
|
554 # define set_charptr_emchar(ptr, x) simple_set_charptr_emchar (ptr, x)
|
|
555 # define charptr_copy_char(ptr, ptr2) simple_charptr_copy_char (ptr, ptr2)
|
|
556
|
70
|
557 #endif /* not MULE */
|
|
558
|
0
|
559 #define charptr_emchar_n(ptr, offset) \
|
|
560 charptr_emchar (charptr_n_addr (ptr, offset))
|
|
561
|
|
562
|
|
563 /* ---------------------------- */
|
|
564 /* (D) For working with Emchars */
|
|
565 /* ---------------------------- */
|
|
566
|
70
|
567 #ifdef MULE
|
|
568
|
|
569 int non_ascii_valid_char_p (Emchar ch);
|
|
570
|
|
571 INLINE int valid_char_p (Emchar ch);
|
|
572 INLINE int
|
|
573 valid_char_p (Emchar ch)
|
|
574 {
|
183
|
575 return (ch >= 0 && ch <= 255) || non_ascii_valid_char_p (ch);
|
70
|
576 }
|
|
577
|
|
578 #else /* not MULE */
|
|
579
|
183
|
580 #define valid_char_p(ch) ((unsigned int) (ch) <= 255)
|
0
|
581
|
70
|
582 #endif /* not MULE */
|
|
583
|
0
|
584 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x)))
|
|
585
|
|
586 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
|
|
587
|
|
588 #ifdef ERROR_CHECK_TYPECHECK
|
|
589
|
|
590 INLINE Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj);
|
|
591 INLINE Emchar
|
|
592 XCHAR_OR_CHAR_INT (Lisp_Object obj)
|
|
593 {
|
|
594 assert (CHAR_OR_CHAR_INTP (obj));
|
209
|
595 return CHARP (obj) ? XCHAR (obj) : XINT (obj);
|
0
|
596 }
|
|
597
|
|
598 #else
|
|
599
|
209
|
600 #define XCHAR_OR_CHAR_INT(obj) (CHARP ((obj)) ? XCHAR ((obj)) : XINT ((obj)))
|
0
|
601
|
|
602 #endif
|
|
603
|
183
|
604 #define CHECK_CHAR_COERCE_INT(x) do { \
|
|
605 if (CHARP (x)) \
|
|
606 ; \
|
|
607 else if (CHAR_INTP (x)) \
|
|
608 x = make_char (XINT (x)); \
|
|
609 else \
|
|
610 x = wrong_type_argument (Qcharacterp, x); \
|
|
611 } while (0)
|
0
|
612
|
70
|
613 #ifdef MULE
|
|
614 # define MAX_EMCHAR_LEN 4
|
|
615 #else
|
16
|
616 # define MAX_EMCHAR_LEN 1
|
70
|
617 #endif
|
0
|
618
|
|
619
|
|
620 /*----------------------------------------------------------------------*/
|
|
621 /* Accessor macros for important positions in a buffer */
|
|
622 /*----------------------------------------------------------------------*/
|
|
623
|
|
624 /* We put them here because some stuff below wants them before the
|
|
625 place where we would normally put them. */
|
|
626
|
|
627 /* None of these are lvalues. Use the settor macros below to change
|
|
628 the positions. */
|
|
629
|
185
|
630 /* Beginning of buffer. */
|
0
|
631 #define BI_BUF_BEG(buf) ((Bytind) 1)
|
|
632 #define BUF_BEG(buf) ((Bufpos) 1)
|
|
633
|
185
|
634 /* Beginning of accessible range of buffer. */
|
0
|
635 #define BI_BUF_BEGV(buf) ((buf)->begv + 0)
|
|
636 #define BUF_BEGV(buf) ((buf)->bufbegv + 0)
|
|
637
|
185
|
638 /* End of accessible range of buffer. */
|
0
|
639 #define BI_BUF_ZV(buf) ((buf)->zv + 0)
|
|
640 #define BUF_ZV(buf) ((buf)->bufzv + 0)
|
|
641
|
185
|
642 /* End of buffer. */
|
0
|
643 #define BI_BUF_Z(buf) ((buf)->text->z + 0)
|
|
644 #define BUF_Z(buf) ((buf)->text->bufz + 0)
|
|
645
|
|
646 /* Point. */
|
|
647 #define BI_BUF_PT(buf) ((buf)->pt + 0)
|
|
648 #define BUF_PT(buf) ((buf)->bufpt + 0)
|
|
649
|
|
650 /*----------------------------------------------------------------------*/
|
|
651 /* Converting between positions and addresses */
|
|
652 /*----------------------------------------------------------------------*/
|
|
653
|
|
654 /* Convert the address of a byte in the buffer into a position. */
|
|
655 INLINE Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr);
|
|
656 INLINE Bytind
|
|
657 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr)
|
|
658 {
|
|
659 return ((ptr) - (buf)->text->beg + 1
|
183
|
660 - ((ptr - (buf)->text->beg + 1) > (buf)->text->gpt
|
|
661 ? (buf)->text->gap_size : 0));
|
0
|
662 }
|
|
663
|
|
664 #define BUF_PTR_BYTE_POS(buf, ptr) \
|
|
665 bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr))
|
|
666
|
|
667 /* Address of byte at position POS in buffer. */
|
|
668 INLINE Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos);
|
|
669 INLINE Bufbyte *
|
|
670 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos)
|
|
671 {
|
|
672 return ((buf)->text->beg +
|
|
673 ((pos >= (buf)->text->gpt ? (pos + (buf)->text->gap_size) : pos)
|
|
674 - 1));
|
|
675 }
|
|
676
|
|
677 #define BUF_BYTE_ADDRESS(buf, pos) \
|
|
678 BI_BUF_BYTE_ADDRESS (buf, bufpos_to_bytind (buf, pos))
|
|
679
|
|
680 /* Address of byte before position POS in buffer. */
|
|
681 INLINE Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos);
|
|
682 INLINE Bufbyte *
|
|
683 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos)
|
|
684 {
|
|
685 return ((buf)->text->beg +
|
|
686 ((pos > (buf)->text->gpt ? (pos + (buf)->text->gap_size) : pos)
|
|
687 - 2));
|
|
688 }
|
|
689
|
|
690 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \
|
|
691 BI_BUF_BYTE_ADDRESS_BEFORE (buf, bufpos_to_bytind (buf, pos))
|
|
692
|
|
693 /*----------------------------------------------------------------------*/
|
|
694 /* Converting between byte indices and memory indices */
|
|
695 /*----------------------------------------------------------------------*/
|
|
696
|
|
697 INLINE int valid_memind_p (struct buffer *buf, Memind x);
|
|
698 INLINE int
|
|
699 valid_memind_p (struct buffer *buf, Memind x)
|
|
700 {
|
183
|
701 return ((x >= 1 && x <= (Memind) (buf)->text->gpt) ||
|
|
702 (x > (Memind) ((buf)->text->gpt + (buf)->text->gap_size) &&
|
|
703 x <= (Memind) ((buf)->text->z + (buf)->text->gap_size)));
|
0
|
704 }
|
|
705
|
|
706 INLINE Memind bytind_to_memind (struct buffer *buf, Bytind x);
|
|
707 INLINE Memind
|
|
708 bytind_to_memind (struct buffer *buf, Bytind x)
|
|
709 {
|
183
|
710 return (Memind) ((x > (buf)->text->gpt) ? (x + (buf)->text->gap_size) : x);
|
0
|
711 }
|
|
712
|
|
713 #ifdef ERROR_CHECK_BUFPOS
|
|
714
|
|
715 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x);
|
|
716 INLINE Bytind
|
|
717 memind_to_bytind (struct buffer *buf, Memind x)
|
|
718 {
|
|
719 assert (valid_memind_p (buf, x));
|
183
|
720 return (Bytind) ((x > (Memind) (buf)->text->gpt) ?
|
|
721 x - (buf)->text->gap_size :
|
|
722 x);
|
0
|
723 }
|
|
724
|
|
725 #else
|
|
726
|
|
727 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x);
|
|
728 INLINE Bytind
|
|
729 memind_to_bytind (struct buffer *buf, Memind x)
|
|
730 {
|
183
|
731 return (Bytind) ((x > (Memind) (buf)->text->gpt) ?
|
|
732 x - (buf)->text->gap_size :
|
|
733 x);
|
0
|
734 }
|
|
735
|
|
736 #endif
|
|
737
|
|
738 #define memind_to_bufpos(buf, x) \
|
|
739 bytind_to_bufpos (buf, memind_to_bytind (buf, x))
|
|
740 #define bufpos_to_memind(buf, x) \
|
|
741 bytind_to_memind (buf, bufpos_to_bytind (buf, x))
|
|
742
|
|
743 /* These macros generalize many standard buffer-position functions to
|
|
744 either a buffer or a string. */
|
|
745
|
|
746 /* Converting between Meminds and Bytinds, for a buffer-or-string.
|
|
747 For strings, this is a no-op. For buffers, this resolves
|
|
748 to the standard memind<->bytind converters. */
|
|
749
|
|
750 #define buffer_or_string_bytind_to_memind(obj, ind) \
|
|
751 (BUFFERP (obj) ? bytind_to_memind (XBUFFER (obj), ind) : (Memind) ind)
|
|
752
|
|
753 #define buffer_or_string_memind_to_bytind(obj, ind) \
|
|
754 (BUFFERP (obj) ? memind_to_bytind (XBUFFER (obj), ind) : (Bytind) ind)
|
|
755
|
|
756 /* Converting between Bufpos's and Bytinds, for a buffer-or-string.
|
|
757 For strings, this maps to the bytecount<->charcount converters. */
|
|
758
|
|
759 #define buffer_or_string_bufpos_to_bytind(obj, pos) \
|
|
760 (BUFFERP (obj) ? bufpos_to_bytind (XBUFFER (obj), pos) : \
|
14
|
761 (Bytind) charcount_to_bytecount (XSTRING_DATA (obj), pos))
|
0
|
762
|
|
763 #define buffer_or_string_bytind_to_bufpos(obj, ind) \
|
|
764 (BUFFERP (obj) ? bytind_to_bufpos (XBUFFER (obj), ind) : \
|
14
|
765 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind))
|
0
|
766
|
|
767 /* Similar for Bufpos's and Meminds. */
|
|
768
|
|
769 #define buffer_or_string_bufpos_to_memind(obj, pos) \
|
|
770 (BUFFERP (obj) ? bufpos_to_memind (XBUFFER (obj), pos) : \
|
14
|
771 (Memind) charcount_to_bytecount (XSTRING_DATA (obj), pos))
|
0
|
772
|
|
773 #define buffer_or_string_memind_to_bufpos(obj, ind) \
|
|
774 (BUFFERP (obj) ? memind_to_bufpos (XBUFFER (obj), ind) : \
|
14
|
775 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind))
|
0
|
776
|
|
777 /************************************************************************/
|
|
778 /* */
|
|
779 /* working with buffer-level data */
|
|
780 /* */
|
|
781 /************************************************************************/
|
|
782
|
|
783 /*
|
|
784
|
|
785 (A) Working with byte indices:
|
|
786 ------------------------------
|
|
787
|
|
788 VALID_BYTIND_P(buf, bi):
|
|
789 Given a byte index, does it point to the beginning of a character?
|
|
790
|
|
791 ASSERT_VALID_BYTIND_UNSAFE(buf, bi):
|
|
792 If error-checking is enabled, assert that the given byte index
|
|
793 is within range and points to the beginning of a character
|
|
794 or to the end of the buffer. Otherwise, do nothing.
|
|
795
|
|
796 ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, bi):
|
|
797 If error-checking is enabled, assert that the given byte index
|
|
798 is within range and satisfies ASSERT_VALID_BYTIND() and also
|
|
799 does not refer to the beginning of the buffer. (i.e. movement
|
|
800 backwards is OK.) Otherwise, do nothing.
|
|
801
|
|
802 ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, bi):
|
|
803 If error-checking is enabled, assert that the given byte index
|
|
804 is within range and satisfies ASSERT_VALID_BYTIND() and also
|
|
805 does not refer to the end of the buffer. (i.e. movement
|
|
806 forwards is OK.) Otherwise, do nothing.
|
|
807
|
|
808 VALIDATE_BYTIND_BACKWARD(buf, bi):
|
|
809 Make sure that the given byte index is pointing to the beginning
|
|
810 of a character. If not, back up until this is the case. Note
|
|
811 that there are not too many places where it is legitimate to do
|
|
812 this sort of thing. It's an error if you're passed an "invalid"
|
|
813 byte index.
|
|
814
|
|
815 VALIDATE_BYTIND_FORWARD(buf, bi):
|
|
816 Make sure that the given byte index is pointing to the beginning
|
|
817 of a character. If not, move forward until this is the case.
|
|
818 Note that there are not too many places where it is legitimate
|
|
819 to do this sort of thing. It's an error if you're passed an
|
|
820 "invalid" byte index.
|
|
821
|
|
822 INC_BYTIND(buf, bi):
|
|
823 Given a byte index (assumed to point at the beginning of a
|
|
824 character), modify that value so it points to the beginning
|
|
825 of the next character.
|
|
826
|
|
827 DEC_BYTIND(buf, bi):
|
|
828 Given a byte index (assumed to point at the beginning of a
|
|
829 character), modify that value so it points to the beginning
|
|
830 of the previous character. Unlike for DEC_CHARPTR(), we can
|
|
831 do all the assert()s because there are sentinels at the
|
|
832 beginning of the gap and the end of the buffer.
|
|
833
|
|
834 BYTIND_INVALID:
|
|
835 A constant representing an invalid Bytind. Valid Bytinds
|
|
836 can never have this value.
|
|
837
|
|
838
|
|
839 (B) Converting between Bufpos's and Bytinds:
|
|
840 --------------------------------------------
|
|
841
|
|
842 bufpos_to_bytind(buf, bu):
|
|
843 Given a Bufpos, return the equivalent Bytind.
|
|
844
|
|
845 bytind_to_bufpos(buf, bi):
|
|
846 Given a Bytind, return the equivalent Bufpos.
|
|
847
|
|
848 make_bufpos(buf, bi):
|
|
849 Given a Bytind, return the equivalent Bufpos as a Lisp Object.
|
|
850 */
|
|
851
|
|
852
|
|
853 /*----------------------------------------------------------------------*/
|
|
854 /* working with byte indices */
|
|
855 /*----------------------------------------------------------------------*/
|
|
856
|
70
|
857 #ifdef MULE
|
|
858 # define VALID_BYTIND_P(buf, x) \
|
|
859 BUFBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x))
|
|
860 #else
|
16
|
861 # define VALID_BYTIND_P(buf, x) 1
|
70
|
862 #endif
|
0
|
863
|
|
864 #ifdef ERROR_CHECK_BUFPOS
|
|
865
|
|
866 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x) do \
|
|
867 { \
|
|
868 assert (BUFFER_LIVE_P (buf)); \
|
|
869 assert ((x) >= BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
|
|
870 assert (VALID_BYTIND_P (buf, x)); \
|
|
871 } while (0)
|
|
872 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x) do \
|
|
873 { \
|
|
874 assert (BUFFER_LIVE_P (buf)); \
|
|
875 assert ((x) > BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
|
|
876 assert (VALID_BYTIND_P (buf, x)); \
|
|
877 } while (0)
|
|
878 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x) do \
|
|
879 { \
|
|
880 assert (BUFFER_LIVE_P (buf)); \
|
|
881 assert ((x) >= BI_BUF_BEG (buf) && x < BI_BUF_Z (buf)); \
|
|
882 assert (VALID_BYTIND_P (buf, x)); \
|
|
883 } while (0)
|
|
884
|
|
885 #else /* not ERROR_CHECK_BUFPOS */
|
|
886 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x)
|
|
887 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x)
|
|
888 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x)
|
|
889
|
|
890 #endif /* not ERROR_CHECK_BUFPOS */
|
|
891
|
70
|
892 /* Note that, although the Mule version will work fine for non-Mule
|
|
893 as well (it should reduce down to nothing), we provide a separate
|
|
894 version to avoid compilation warnings and possible non-optimal
|
|
895 results with stupid compilers. */
|
|
896
|
|
897 #ifdef MULE
|
|
898 # define VALIDATE_BYTIND_BACKWARD(buf, x) do \
|
|
899 { \
|
|
900 Bufbyte *__ibptr = BI_BUF_BYTE_ADDRESS (buf, x); \
|
|
901 while (!BUFBYTE_FIRST_BYTE_P (*__ibptr)) \
|
|
902 __ibptr--, (x)--; \
|
|
903 } while (0)
|
|
904 #else
|
16
|
905 # define VALIDATE_BYTIND_BACKWARD(buf, x)
|
70
|
906 #endif
|
0
|
907
|
70
|
908 /* Note that, although the Mule version will work fine for non-Mule
|
|
909 as well (it should reduce down to nothing), we provide a separate
|
|
910 version to avoid compilation warnings and possible non-optimal
|
|
911 results with stupid compilers. */
|
|
912
|
|
913 #ifdef MULE
|
|
914 # define VALIDATE_BYTIND_FORWARD(buf, x) do \
|
|
915 { \
|
|
916 Bufbyte *__ibptr = BI_BUF_BYTE_ADDRESS (buf, x); \
|
|
917 while (!BUFBYTE_FIRST_BYTE_P (*__ibptr)) \
|
|
918 __ibptr++, (x)++; \
|
|
919 } while (0)
|
|
920 #else
|
16
|
921 # define VALIDATE_BYTIND_FORWARD(buf, x)
|
70
|
922 #endif
|
0
|
923
|
|
924 /* Note that in the simplest case (no MULE, no ERROR_CHECK_BUFPOS),
|
|
925 this crap reduces down to simply (x)++. */
|
|
926
|
|
927 #define INC_BYTIND(buf, x) do \
|
|
928 { \
|
|
929 ASSERT_VALID_BYTIND_FORWARD_UNSAFE (buf, x); \
|
|
930 /* Note that we do the increment first to \
|
|
931 make sure that the pointer in \
|
|
932 VALIDATE_BYTIND_FORWARD() ends up on \
|
|
933 the correct side of the gap */ \
|
|
934 (x)++; \
|
|
935 VALIDATE_BYTIND_FORWARD (buf, x); \
|
|
936 } while (0)
|
|
937
|
|
938 /* Note that in the simplest case (no MULE, no ERROR_CHECK_BUFPOS),
|
|
939 this crap reduces down to simply (x)--. */
|
|
940
|
|
941 #define DEC_BYTIND(buf, x) do \
|
|
942 { \
|
|
943 ASSERT_VALID_BYTIND_BACKWARD_UNSAFE (buf, x); \
|
|
944 /* Note that we do the decrement first to \
|
|
945 make sure that the pointer in \
|
|
946 VALIDATE_BYTIND_BACKWARD() ends up on \
|
|
947 the correct side of the gap */ \
|
|
948 (x)--; \
|
|
949 VALIDATE_BYTIND_BACKWARD (buf, x); \
|
|
950 } while (0)
|
|
951
|
|
952 INLINE Bytind prev_bytind (struct buffer *buf, Bytind x);
|
|
953 INLINE Bytind
|
|
954 prev_bytind (struct buffer *buf, Bytind x)
|
|
955 {
|
|
956 DEC_BYTIND (buf, x);
|
|
957 return x;
|
|
958 }
|
|
959
|
|
960 INLINE Bytind next_bytind (struct buffer *buf, Bytind x);
|
|
961 INLINE Bytind
|
|
962 next_bytind (struct buffer *buf, Bytind x)
|
|
963 {
|
|
964 INC_BYTIND (buf, x);
|
|
965 return x;
|
|
966 }
|
|
967
|
|
968 #define BYTIND_INVALID ((Bytind) -1)
|
|
969
|
|
970 /*----------------------------------------------------------------------*/
|
|
971 /* Converting between buffer positions and byte indices */
|
|
972 /*----------------------------------------------------------------------*/
|
|
973
|
70
|
974 #ifdef MULE
|
|
975
|
|
976 Bytind bufpos_to_bytind_func (struct buffer *buf, Bufpos x);
|
|
977 Bufpos bytind_to_bufpos_func (struct buffer *buf, Bytind x);
|
|
978
|
|
979 /* The basic algorithm we use is to keep track of a known region of
|
|
980 characters in each buffer, all of which are of the same width. We
|
|
981 keep track of the boundaries of the region in both Bufpos and
|
|
982 Bytind coordinates and also keep track of the char width, which
|
|
983 is 1 - 4 bytes. If the position we're translating is not in
|
|
984 the known region, then we invoke a function to update the known
|
|
985 region to surround the position in question. This assumes
|
|
986 locality of reference, which is usually the case.
|
|
987
|
|
988 Note that the function to update the known region can be simple
|
|
989 or complicated depending on how much information we cache.
|
|
990 For the moment, we don't cache any information, and just move
|
|
991 linearly forward or back from the known region, with a few
|
|
992 shortcuts to catch all-ASCII buffers. (Note that this will
|
|
993 thrash with bad locality of reference.) A smarter method would
|
|
994 be to keep some sort of pseudo-extent layer over the buffer;
|
|
995 maybe keep track of the bufpos/bytind correspondence at the
|
|
996 beginning of each line, which would allow us to do a binary
|
|
997 search over the pseudo-extents to narrow things down to the
|
|
998 correct line, at which point you could use a linear movement
|
|
999 method. This would also mesh well with efficiently
|
|
1000 implementing a line-numbering scheme.
|
|
1001
|
|
1002 Note also that we have to multiply or divide by the char width
|
|
1003 in order to convert the positions. We do some tricks to avoid
|
|
1004 ever actually having to do a multiply or divide, because that
|
|
1005 is typically an expensive operation (esp. divide). Multiplying
|
|
1006 or dividing by 1, 2, or 4 can be implemented simply as a
|
|
1007 shift left or shift right, and we keep track of a shifter value
|
|
1008 (0, 1, or 2) indicating how much to shift. Multiplying by 3
|
|
1009 can be implemented by doubling and then adding the original
|
|
1010 value. Dividing by 3, alas, cannot be implemented in any
|
|
1011 simple shift/subtract method, as far as I know; so we just
|
|
1012 do a table lookup. For simplicity, we use a table of size
|
|
1013 128K, which indexes the "divide-by-3" values for the first
|
|
1014 64K non-negative numbers. (Note that we can increase the
|
|
1015 size up to 384K, i.e. indexing the first 192K non-negative
|
|
1016 numbers, while still using shorts in the array.) This also
|
|
1017 means that the size of the known region can be at most
|
|
1018 64K for width-three characters.
|
|
1019 */
|
185
|
1020
|
70
|
1021 extern short three_to_one_table[];
|
|
1022
|
|
1023 INLINE int real_bufpos_to_bytind (struct buffer *buf, Bufpos x);
|
|
1024 INLINE int
|
|
1025 real_bufpos_to_bytind (struct buffer *buf, Bufpos x)
|
|
1026 {
|
|
1027 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax)
|
|
1028 return (buf->text->mule_bytmin +
|
|
1029 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) +
|
|
1030 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0));
|
|
1031 else
|
|
1032 return bufpos_to_bytind_func (buf, x);
|
|
1033 }
|
|
1034
|
|
1035 INLINE int real_bytind_to_bufpos (struct buffer *buf, Bytind x);
|
|
1036 INLINE int
|
|
1037 real_bytind_to_bufpos (struct buffer *buf, Bytind x)
|
|
1038 {
|
|
1039 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax)
|
|
1040 return (buf->text->mule_bufmin +
|
|
1041 ((buf->text->mule_three_p
|
|
1042 ? three_to_one_table[x - buf->text->mule_bytmin]
|
|
1043 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter)));
|
|
1044 else
|
|
1045 return bytind_to_bufpos_func (buf, x);
|
|
1046 }
|
|
1047
|
|
1048 #else /* not MULE */
|
|
1049
|
16
|
1050 # define real_bufpos_to_bytind(buf, x) ((Bytind) x)
|
|
1051 # define real_bytind_to_bufpos(buf, x) ((Bufpos) x)
|
0
|
1052
|
70
|
1053 #endif /* not MULE */
|
|
1054
|
0
|
1055 #ifdef ERROR_CHECK_BUFPOS
|
|
1056
|
|
1057 Bytind bufpos_to_bytind (struct buffer *buf, Bufpos x);
|
|
1058 Bufpos bytind_to_bufpos (struct buffer *buf, Bytind x);
|
|
1059
|
|
1060 #else /* not ERROR_CHECK_BUFPOS */
|
|
1061
|
|
1062 #define bufpos_to_bytind real_bufpos_to_bytind
|
|
1063 #define bytind_to_bufpos real_bytind_to_bufpos
|
|
1064
|
|
1065 #endif /* not ERROR_CHECK_BUFPOS */
|
|
1066
|
|
1067 #define make_bufpos(buf, ind) make_int (bytind_to_bufpos (buf, ind))
|
|
1068
|
|
1069 /*----------------------------------------------------------------------*/
|
|
1070 /* Converting between buffer bytes and Emacs characters */
|
|
1071 /*----------------------------------------------------------------------*/
|
|
1072
|
|
1073 /* The character at position POS in buffer. */
|
|
1074 #define BI_BUF_FETCH_CHAR(buf, pos) \
|
|
1075 charptr_emchar (BI_BUF_BYTE_ADDRESS (buf, pos))
|
|
1076 #define BUF_FETCH_CHAR(buf, pos) \
|
|
1077 BI_BUF_FETCH_CHAR (buf, bufpos_to_bytind (buf, pos))
|
|
1078
|
|
1079 /* The character at position POS in buffer, as a string. This is
|
|
1080 equivalent to set_charptr_emchar (str, BUF_FETCH_CHAR (buf, pos))
|
|
1081 but is faster for Mule. */
|
|
1082
|
|
1083 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
|
|
1084 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str)
|
|
1085 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
|
|
1086 BI_BUF_CHARPTR_COPY_CHAR (buf, bufpos_to_bytind (buf, pos), str)
|
|
1087
|
|
1088
|
|
1089
|
|
1090
|
|
1091 /************************************************************************/
|
|
1092 /* */
|
|
1093 /* working with externally-formatted data */
|
|
1094 /* */
|
|
1095 /************************************************************************/
|
|
1096
|
|
1097 /* Sometimes strings need to be converted into one or another
|
|
1098 external format, for passing to a library function. (Note
|
|
1099 that we encapsulate and automatically convert the arguments
|
|
1100 of some functions, but not others.) At times this conversion
|
|
1101 also has to go the other way -- i.e. when we get external-
|
|
1102 format strings back from a library function.
|
|
1103 */
|
|
1104
|
259
|
1105 #ifdef FILE_CODING
|
70
|
1106
|
|
1107 /* WARNING: These use a static buffer. This can lead to disaster if
|
|
1108 these functions are not used *very* carefully. Under normal
|
|
1109 circumstances, do not call these functions; call the front ends
|
|
1110 below. */
|
|
1111
|
|
1112 CONST Extbyte *convert_to_external_format (CONST Bufbyte *ptr,
|
|
1113 Bytecount len,
|
|
1114 Extcount *len_out,
|
|
1115 enum external_data_format fmt);
|
|
1116 CONST Bufbyte *convert_from_external_format (CONST Extbyte *ptr,
|
|
1117 Extcount len,
|
|
1118 Bytecount *len_out,
|
|
1119 enum external_data_format fmt);
|
|
1120
|
|
1121 #else /* ! MULE */
|
|
1122
|
0
|
1123 #define convert_to_external_format(ptr, len, len_out, fmt) \
|
|
1124 (*(len_out) = (int) (len), (CONST Extbyte *) (ptr))
|
|
1125 #define convert_from_external_format(ptr, len, len_out, fmt) \
|
|
1126 (*(len_out) = (Bytecount) (len), (CONST Bufbyte *) (ptr))
|
|
1127
|
70
|
1128 #endif /* ! MULE */
|
0
|
1129
|
|
1130 /* In all of the following macros we use the following general principles:
|
|
1131
|
|
1132 -- Functions that work with charptr's accept two sorts of charptr's:
|
|
1133
|
|
1134 a) Pointers to memory with a length specified. The pointer will be
|
|
1135 fundamentally of type `unsigned char *' (although labelled
|
|
1136 as `Bufbyte *' for internal-format data and `Extbyte *' for
|
|
1137 external-format data) and the length will be fundamentally of
|
|
1138 type `int' (although labelled as `Bytecount' for internal-format
|
|
1139 data and `Extcount' for external-format data). The length is
|
|
1140 always a count in bytes.
|
|
1141 b) Zero-terminated pointers; no length specified. The pointer
|
|
1142 is of type `char *', whether the data pointed to is internal-format
|
|
1143 or external-format. These sorts of pointers are available for
|
|
1144 convenience in working with C library functions and literal
|
|
1145 strings. In general you should use these sorts of pointers only
|
|
1146 to interface to library routines and not for general manipulation,
|
|
1147 as you are liable to lose embedded nulls and such. This could
|
|
1148 be a big problem for routines that want Unicode-formatted data,
|
|
1149 which is likely to have lots of embedded nulls in it.
|
|
1150
|
|
1151 -- Functions that work with Lisp strings accept strings as Lisp Objects
|
|
1152 (as opposed to the `struct Lisp_String *' for some of the other
|
|
1153 string accessors). This is for convenience in working with the
|
|
1154 functions, as otherwise you will almost always have to call
|
|
1155 XSTRING() on the object.
|
|
1156
|
|
1157 -- Functions that work with charptr's are not guaranteed to copy
|
|
1158 their data into alloca()ed space. Functions that work with
|
|
1159 Lisp strings are, however. The reason is that Lisp strings can
|
|
1160 be relocated any time a GC happens, and it could happen at some
|
|
1161 rather unexpected times. The internal-external conversion is
|
|
1162 rarely done in time-critical functions, and so the slight
|
|
1163 extra time required for alloca() and copy is well-worth the
|
|
1164 safety of knowing your string data won't be relocated out from
|
|
1165 under you.
|
|
1166 */
|
185
|
1167
|
|
1168
|
0
|
1169 /* Maybe convert charptr's data into ext-format and store the result in
|
|
1170 alloca()'ed space.
|
185
|
1171
|
0
|
1172 You may wonder why this is written in this fashion and not as a
|
|
1173 function call. With a little trickery it could certainly be
|
|
1174 written this way, but it won't work because of those DAMN GCC WANKERS
|
|
1175 who couldn't be bothered to handle alloca() properly on the x86
|
|
1176 architecture. (If you put a call to alloca() in the argument to
|
|
1177 a function call, the stack space gets allocated right in the
|
|
1178 middle of the arguments to the function call and you are unbelievably
|
|
1179 hosed.) */
|
185
|
1180
|
70
|
1181 #ifdef MULE
|
|
1182
|
|
1183 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here) \
|
|
1184 do \
|
|
1185 { \
|
|
1186 Bytecount __gceda_len_in__ = (len); \
|
|
1187 Extcount __gceda_len_out__; \
|
|
1188 CONST Bufbyte *__gceda_ptr_in__ = (ptr); \
|
|
1189 CONST Extbyte *__gceda_ptr_out__; \
|
|
1190 \
|
|
1191 __gceda_ptr_out__ = \
|
|
1192 convert_to_external_format (__gceda_ptr_in__, __gceda_len_in__, \
|
|
1193 &__gceda_len_out__, fmt); \
|
|
1194 /* If the new string is identical to the old (will be the case most \
|
|
1195 of the time), just return the same string back. This saves \
|
|
1196 on alloca()ing, which can be useful on C alloca() machines and \
|
|
1197 on stack-space-challenged environments. */ \
|
|
1198 \
|
|
1199 if (__gceda_len_in__ == __gceda_len_out__ && \
|
|
1200 !memcmp (__gceda_ptr_in__, __gceda_ptr_out__, __gceda_len_out__)) \
|
|
1201 { \
|
|
1202 (stick_value_here) = (CONST Extbyte *) __gceda_ptr_in__; \
|
|
1203 (stick_len_here) = (Extcount) __gceda_len_in__; \
|
|
1204 } \
|
|
1205 else \
|
|
1206 { \
|
|
1207 (stick_value_here) = (CONST Extbyte *) alloca(1 + __gceda_len_out__);\
|
|
1208 memcpy ((Extbyte *) stick_value_here, __gceda_ptr_out__, \
|
|
1209 1 + __gceda_len_out__); \
|
|
1210 (stick_len_here) = (Extcount) __gceda_len_out__; \
|
|
1211 } \
|
|
1212 } while (0)
|
|
1213
|
|
1214 #else /* ! MULE */
|
|
1215
|
0
|
1216 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\
|
|
1217 do \
|
|
1218 { \
|
|
1219 (stick_value_here) = (CONST Extbyte *) (ptr); \
|
|
1220 (stick_len_here) = (Extcount) (len); \
|
|
1221 } while (0)
|
|
1222
|
70
|
1223 #endif /* ! MULE */
|
|
1224
|
0
|
1225 #define GET_C_CHARPTR_EXT_DATA_ALLOCA(ptr, fmt, stick_value_here) \
|
|
1226 do \
|
|
1227 { \
|
|
1228 Extcount __gcceda_ignored_len__; \
|
|
1229 CONST char *__gcceda_ptr_in__; \
|
|
1230 CONST Extbyte *__gcceda_ptr_out__; \
|
|
1231 \
|
|
1232 __gcceda_ptr_in__ = ptr; \
|
|
1233 GET_CHARPTR_EXT_DATA_ALLOCA ((CONST Extbyte *) __gcceda_ptr_in__, \
|
|
1234 strlen (__gcceda_ptr_in__), fmt, \
|
|
1235 __gcceda_ptr_out__, \
|
|
1236 __gcceda_ignored_len__); \
|
|
1237 (stick_value_here) = (CONST char *) __gcceda_ptr_out__; \
|
|
1238 } while (0)
|
|
1239
|
|
1240 #define GET_C_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, stick_value_here) \
|
|
1241 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_BINARY, stick_value_here)
|
|
1242 #define GET_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \
|
|
1243 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, stick_value_here, \
|
|
1244 stick_len_here)
|
|
1245
|
|
1246 #define GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, stick_value_here) \
|
|
1247 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_FILENAME, stick_value_here)
|
|
1248 #define GET_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \
|
|
1249 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, stick_value_here, \
|
|
1250 stick_len_here)
|
|
1251
|
|
1252 #define GET_C_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, stick_value_here) \
|
|
1253 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_CTEXT, stick_value_here)
|
|
1254 #define GET_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \
|
|
1255 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, stick_value_here, \
|
|
1256 stick_len_here)
|
|
1257
|
|
1258 /* Maybe convert external charptr's data into internal format and store
|
|
1259 the result in alloca()'ed space.
|
185
|
1260
|
0
|
1261 You may wonder why this is written in this fashion and not as a
|
|
1262 function call. With a little trickery it could certainly be
|
|
1263 written this way, but it won't work because of those DAMN GCC WANKERS
|
|
1264 who couldn't be bothered to handle alloca() properly on the x86
|
|
1265 architecture. (If you put a call to alloca() in the argument to
|
|
1266 a function call, the stack space gets allocated right in the
|
|
1267 middle of the arguments to the function call and you are unbelievably
|
|
1268 hosed.) */
|
185
|
1269
|
70
|
1270 #ifdef MULE
|
|
1271
|
0
|
1272 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\
|
70
|
1273 do \
|
|
1274 { \
|
|
1275 Extcount __gcida_len_in__ = (len); \
|
|
1276 Bytecount __gcida_len_out__; \
|
|
1277 CONST Extbyte *__gcida_ptr_in__ = (ptr); \
|
|
1278 CONST Bufbyte *__gcida_ptr_out__; \
|
|
1279 \
|
|
1280 __gcida_ptr_out__ = \
|
|
1281 convert_from_external_format (__gcida_ptr_in__, __gcida_len_in__, \
|
|
1282 &__gcida_len_out__, fmt); \
|
|
1283 /* If the new string is identical to the old (will be the case most \
|
|
1284 of the time), just return the same string back. This saves \
|
|
1285 on alloca()ing, which can be useful on C alloca() machines and \
|
|
1286 on stack-space-challenged environments. */ \
|
|
1287 \
|
|
1288 if (__gcida_len_in__ == __gcida_len_out__ && \
|
|
1289 !memcmp (__gcida_ptr_in__, __gcida_ptr_out__, __gcida_len_out__)) \
|
|
1290 { \
|
|
1291 (stick_value_here) = (CONST Bufbyte *) __gcida_ptr_in__; \
|
|
1292 (stick_len_here) = (Bytecount) __gcida_len_in__; \
|
|
1293 } \
|
|
1294 else \
|
|
1295 { \
|
82
|
1296 (stick_value_here) = (CONST Extbyte *) alloca (1 + __gcida_len_out__); \
|
70
|
1297 memcpy ((Bufbyte *) stick_value_here, __gcida_ptr_out__, \
|
|
1298 1 + __gcida_len_out__); \
|
|
1299 (stick_len_here) = __gcida_len_out__; \
|
|
1300 } \
|
0
|
1301 } while (0)
|
|
1302
|
70
|
1303 #else /* ! MULE */
|
|
1304
|
|
1305 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\
|
|
1306 do \
|
|
1307 { \
|
|
1308 (stick_value_here) = (CONST Bufbyte *) (ptr); \
|
|
1309 (stick_len_here) = (Bytecount) (len); \
|
|
1310 } while (0)
|
|
1311
|
|
1312 #endif /* ! MULE */
|
|
1313
|
0
|
1314 #define GET_C_CHARPTR_INT_DATA_ALLOCA(ptr, fmt, stick_value_here) \
|
|
1315 do \
|
|
1316 { \
|
|
1317 Bytecount __gccida_ignored_len__; \
|
|
1318 CONST char *__gccida_ptr_in__; \
|
|
1319 CONST Bufbyte *__gccida_ptr_out__; \
|
|
1320 \
|
|
1321 __gccida_ptr_in__ = ptr; \
|
|
1322 GET_CHARPTR_INT_DATA_ALLOCA ((CONST Extbyte *) __gccida_ptr_in__, \
|
|
1323 strlen (__gccida_ptr_in__), fmt, \
|
|
1324 __gccida_ptr_out__, \
|
|
1325 __gccida_ignored_len__); \
|
|
1326 (stick_value_here) = (CONST char *) __gccida_ptr_out__; \
|
|
1327 } while (0)
|
|
1328
|
|
1329 #define GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, stick_value_here) \
|
|
1330 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_BINARY, stick_value_here)
|
|
1331 #define GET_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \
|
|
1332 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, stick_value_here, \
|
|
1333 stick_len_here)
|
|
1334
|
|
1335 #define GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, stick_value_here) \
|
|
1336 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_FILENAME, stick_value_here)
|
|
1337 #define GET_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \
|
|
1338 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, stick_value_here, \
|
|
1339 stick_len_here)
|
|
1340
|
|
1341 #define GET_C_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, stick_value_here) \
|
|
1342 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_CTEXT, stick_value_here)
|
|
1343 #define GET_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \
|
|
1344 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, stick_value_here, \
|
|
1345 stick_len_here)
|
|
1346
|
|
1347
|
|
1348 /* Maybe convert Lisp string's data into ext-format and store the result in
|
|
1349 alloca()'ed space.
|
|
1350
|
|
1351 You may wonder why this is written in this fashion and not as a
|
|
1352 function call. With a little trickery it could certainly be
|
|
1353 written this way, but it won't work because of those DAMN GCC WANKERS
|
|
1354 who couldn't be bothered to handle alloca() properly on the x86
|
|
1355 architecture. (If you put a call to alloca() in the argument to
|
|
1356 a function call, the stack space gets allocated right in the
|
|
1357 middle of the arguments to the function call and you are unbelievably
|
|
1358 hosed.) */
|
|
1359
|
|
1360 #define GET_STRING_EXT_DATA_ALLOCA(s, fmt, stick_value_here, stick_len_here)\
|
|
1361 do \
|
|
1362 { \
|
|
1363 Extcount __gseda_len__; \
|
|
1364 CONST Extbyte *__gseda_ptr__; \
|
|
1365 struct Lisp_String *__gseda_s__ = XSTRING (s); \
|
|
1366 \
|
|
1367 __gseda_ptr__ = convert_to_external_format (string_data (__gseda_s__), \
|
|
1368 string_length (__gseda_s__), \
|
|
1369 &__gseda_len__, fmt); \
|
84
|
1370 (stick_value_here) = (CONST Extbyte *) alloca (1 + __gseda_len__); \
|
0
|
1371 memcpy ((Extbyte *) stick_value_here, __gseda_ptr__, 1 + __gseda_len__); \
|
|
1372 (stick_len_here) = __gseda_len__; \
|
|
1373 } while (0)
|
|
1374
|
|
1375
|
|
1376 #define GET_C_STRING_EXT_DATA_ALLOCA(s, fmt, stick_value_here) \
|
|
1377 do \
|
|
1378 { \
|
|
1379 Extcount __gcseda_ignored_len__; \
|
|
1380 CONST Extbyte *__gcseda_ptr__; \
|
|
1381 \
|
|
1382 GET_STRING_EXT_DATA_ALLOCA (s, fmt, __gcseda_ptr__, \
|
|
1383 __gcseda_ignored_len__); \
|
|
1384 (stick_value_here) = (CONST char *) __gcseda_ptr__; \
|
|
1385 } while (0)
|
|
1386
|
|
1387 #define GET_STRING_BINARY_DATA_ALLOCA(s, stick_value_here, stick_len_here) \
|
|
1388 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, stick_value_here, \
|
|
1389 stick_len_here)
|
|
1390 #define GET_C_STRING_BINARY_DATA_ALLOCA(s, stick_value_here) \
|
|
1391 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, stick_value_here)
|
|
1392
|
|
1393 #define GET_STRING_FILENAME_DATA_ALLOCA(s, stick_value_here, stick_len_here) \
|
|
1394 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, stick_value_here, \
|
|
1395 stick_len_here)
|
|
1396 #define GET_C_STRING_FILENAME_DATA_ALLOCA(s, stick_value_here) \
|
|
1397 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, stick_value_here)
|
|
1398
|
|
1399 #define GET_STRING_OS_DATA_ALLOCA(s, stick_value_here, stick_len_here) \
|
|
1400 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, stick_value_here, \
|
|
1401 stick_len_here)
|
|
1402 #define GET_C_STRING_OS_DATA_ALLOCA(s, stick_value_here) \
|
|
1403 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, stick_value_here)
|
|
1404
|
|
1405 #define GET_STRING_CTEXT_DATA_ALLOCA(s, stick_value_here, stick_len_here) \
|
|
1406 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, stick_value_here, \
|
|
1407 stick_len_here)
|
|
1408 #define GET_C_STRING_CTEXT_DATA_ALLOCA(s, stick_value_here) \
|
|
1409 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, stick_value_here)
|
|
1410
|
|
1411
|
|
1412
|
|
1413 /************************************************************************/
|
|
1414 /* */
|
|
1415 /* fake charset functions */
|
|
1416 /* */
|
|
1417 /************************************************************************/
|
|
1418
|
70
|
1419 /* used when MULE is not defined, so that Charset-type stuff can still
|
|
1420 be done */
|
|
1421
|
|
1422 #ifndef MULE
|
|
1423
|
0
|
1424 #define Vcharset_ascii Qnil
|
|
1425
|
|
1426 #define CHAR_CHARSET(ch) Vcharset_ascii
|
|
1427 #define CHAR_LEADING_BYTE(ch) LEADING_BYTE_ASCII
|
|
1428 #define LEADING_BYTE_ASCII 0x80
|
|
1429 #define NUM_LEADING_BYTES 1
|
|
1430 #define MIN_LEADING_BYTE 0x80
|
|
1431 #define CHARSETP(cs) 1
|
181
|
1432 #define CHARSET_BY_LEADING_BYTE(lb) Vcharset_ascii
|
0
|
1433 #define XCHARSET_LEADING_BYTE(cs) LEADING_BYTE_ASCII
|
|
1434 #define XCHARSET_GRAPHIC(cs) -1
|
|
1435 #define XCHARSET_COLUMNS(cs) 1
|
|
1436 #define XCHARSET_DIMENSION(cs) 1
|
|
1437 #define REP_BYTES_BY_FIRST_BYTE(fb) 1
|
|
1438 #define BREAKUP_CHAR(ch, charset, byte1, byte2)\
|
|
1439 do \
|
|
1440 { \
|
|
1441 (charset) = Vcharset_ascii; \
|
|
1442 (byte1) = (ch); \
|
|
1443 (byte2) = 0; \
|
|
1444 } while (0)
|
14
|
1445 #define BYTE_ASCII_P(byte) 1
|
0
|
1446
|
70
|
1447 #endif /* ! MULE */
|
0
|
1448
|
|
1449 /************************************************************************/
|
|
1450 /* */
|
|
1451 /* higher-level buffer-position functions */
|
|
1452 /* */
|
|
1453 /************************************************************************/
|
|
1454
|
|
1455 /*----------------------------------------------------------------------*/
|
|
1456 /* Settor macros for important positions in a buffer */
|
|
1457 /*----------------------------------------------------------------------*/
|
|
1458
|
185
|
1459 /* Set beginning of accessible range of buffer. */
|
0
|
1460 #define SET_BOTH_BUF_BEGV(buf, val, bival) \
|
|
1461 do \
|
|
1462 { \
|
|
1463 (buf)->begv = (bival); \
|
|
1464 (buf)->bufbegv = (val); \
|
|
1465 } while (0)
|
|
1466
|
185
|
1467 /* Set end of accessible range of buffer. */
|
0
|
1468 #define SET_BOTH_BUF_ZV(buf, val, bival) \
|
|
1469 do \
|
|
1470 { \
|
|
1471 (buf)->zv = (bival); \
|
|
1472 (buf)->bufzv = (val); \
|
|
1473 } while (0)
|
|
1474
|
|
1475 /* Set point. */
|
|
1476 /* Since BEGV and ZV are almost never set, it's reasonable to enforce
|
|
1477 the restriction that the Bufpos and Bytind values must both be
|
|
1478 specified. However, point is set in lots and lots of places. So
|
|
1479 we provide the ability to specify both (for efficiency) or just
|
|
1480 one. */
|
|
1481 #define BOTH_BUF_SET_PT(buf, val, bival) set_buffer_point (buf, val, bival)
|
|
1482 #define BI_BUF_SET_PT(buf, bival) \
|
|
1483 BOTH_BUF_SET_PT (buf, bytind_to_bufpos (buf, bival), bival)
|
|
1484 #define BUF_SET_PT(buf, value) \
|
|
1485 BOTH_BUF_SET_PT (buf, value, bufpos_to_bytind (buf, value))
|
|
1486
|
|
1487
|
|
1488 #if 0 /* FSFmacs */
|
|
1489 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly
|
|
1490 does too much stuff, such as moving out of invisible extents. */
|
|
1491 #define TEMP_SET_PT(position) (temp_set_point ((position), current_buffer))
|
|
1492 #define SET_BUF_PT(buf, value) ((buf)->pt = (value))
|
183
|
1493 #endif /* FSFmacs */
|
0
|
1494
|
|
1495 /*----------------------------------------------------------------------*/
|
|
1496 /* Miscellaneous buffer values */
|
|
1497 /*----------------------------------------------------------------------*/
|
|
1498
|
|
1499 /* Number of characters in buffer */
|
|
1500 #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf))
|
|
1501
|
|
1502 /* Is this buffer narrowed? */
|
183
|
1503 #define BUF_NARROWED(buf) \
|
|
1504 ((BI_BUF_BEGV (buf) != BI_BUF_BEG (buf)) || \
|
|
1505 (BI_BUF_ZV (buf) != BI_BUF_Z (buf)))
|
0
|
1506
|
|
1507 /* Modification count. */
|
|
1508 #define BUF_MODIFF(buf) ((buf)->text->modiff)
|
|
1509
|
|
1510 /* Saved modification count. */
|
|
1511 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff)
|
|
1512
|
|
1513 /* Face changed. */
|
|
1514 #define BUF_FACECHANGE(buf) ((buf)->face_change)
|
|
1515
|
|
1516 #define POINT_MARKER_P(marker) \
|
|
1517 (XMARKER (marker)->buffer != 0 && \
|
|
1518 EQ ((marker), XMARKER (marker)->buffer->point_marker))
|
|
1519
|
|
1520 #define BUF_MARKERS(buf) ((buf)->markers)
|
|
1521
|
|
1522 /* WARNING:
|
|
1523
|
|
1524 The new definitions of CEILING_OF() and FLOOR_OF() differ semantically
|
|
1525 from the old ones (in FSF Emacs and XEmacs 19.11 and before).
|
|
1526 Conversion is as follows:
|
|
1527
|
|
1528 OLD_BI_CEILING_OF(n) = NEW_BI_CEILING_OF(n) - 1
|
|
1529 OLD_BI_FLOOR_OF(n) = NEW_BI_FLOOR_OF(n + 1)
|
|
1530
|
|
1531 The definitions were changed because the new definitions are more
|
|
1532 consistent with the way everything else works in Emacs.
|
|
1533 */
|
|
1534
|
|
1535 /* Properties of CEILING_OF and FLOOR_OF (also apply to BI_ variants):
|
|
1536
|
|
1537 1) FLOOR_OF (CEILING_OF (n)) = n
|
|
1538 CEILING_OF (FLOOR_OF (n)) = n
|
|
1539
|
|
1540 2) CEILING_OF (n) = n if and only if n = ZV
|
|
1541 FLOOR_OF (n) = n if and only if n = BEGV
|
|
1542
|
|
1543 3) CEILING_OF (CEILING_OF (n)) = ZV
|
|
1544 FLOOR_OF (FLOOR_OF (n)) = BEGV
|
|
1545
|
|
1546 4) The bytes in the regions
|
|
1547
|
|
1548 [BYTE_ADDRESS (n), BYTE_ADDRESS_BEFORE (CEILING_OF (n))]
|
|
1549
|
|
1550 and
|
|
1551
|
|
1552 [BYTE_ADDRESS (FLOOR_OF (n)), BYTE_ADDRESS_BEFORE (n)]
|
|
1553
|
|
1554 are contiguous.
|
|
1555 */
|
|
1556
|
|
1557
|
|
1558 /* Return the maximum index in the buffer it is safe to scan forwards
|
|
1559 past N to. This is used to prevent buffer scans from running into
|
|
1560 the gap (e.g. search.c). All characters between N and CEILING_OF(N)
|
|
1561 are located contiguous in memory. Note that the character *at*
|
|
1562 CEILING_OF(N) is not contiguous in memory. */
|
|
1563 #define BI_BUF_CEILING_OF(b, n) \
|
|
1564 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_ZV (b) ? \
|
|
1565 (b)->text->gpt : BI_BUF_ZV (b))
|
|
1566 #define BUF_CEILING_OF(b, n) \
|
|
1567 bytind_to_bufpos (b, BI_BUF_CEILING_OF (b, bufpos_to_bytind (b, n)))
|
|
1568
|
|
1569 /* Return the minimum index in the buffer it is safe to scan backwards
|
|
1570 past N to. All characters between FLOOR_OF(N) and N are located
|
|
1571 contiguous in memory. Note that the character *at* N may not be
|
|
1572 contiguous in memory. */
|
|
1573 #define BI_BUF_FLOOR_OF(b, n) \
|
|
1574 (BI_BUF_BEGV (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
|
|
1575 (b)->text->gpt : BI_BUF_BEGV (b))
|
|
1576 #define BUF_FLOOR_OF(b, n) \
|
|
1577 bytind_to_bufpos (b, BI_BUF_FLOOR_OF (b, bufpos_to_bytind (b, n)))
|
|
1578
|
|
1579 #define BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
|
|
1580 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_Z (b) ? \
|
|
1581 (b)->text->gpt : BI_BUF_Z (b))
|
|
1582 #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
|
|
1583 bytind_to_bufpos \
|
|
1584 (b, BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE (b, bufpos_to_bytind (b, n)))
|
|
1585
|
|
1586 #define BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
|
|
1587 (BI_BUF_BEG (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
|
|
1588 (b)->text->gpt : BI_BUF_BEG (b))
|
|
1589 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
|
|
1590 bytind_to_bufpos \
|
|
1591 (b, BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, bufpos_to_bytind (b, n)))
|
|
1592
|
|
1593
|
|
1594
|
|
1595
|
|
1596 extern struct buffer *current_buffer;
|
|
1597
|
|
1598 /* This structure holds the default values of the buffer-local variables
|
|
1599 defined with DEFVAR_BUFFER_LOCAL, that have special slots in each buffer.
|
|
1600 The default value occupies the same slot in this structure
|
|
1601 as an individual buffer's value occupies in that buffer.
|
|
1602 Setting the default value also goes through the alist of buffers
|
|
1603 and stores into each buffer that does not say it has a local value. */
|
|
1604
|
|
1605 extern Lisp_Object Vbuffer_defaults;
|
|
1606
|
|
1607 /* This structure marks which slots in a buffer have corresponding
|
|
1608 default values in buffer_defaults.
|
|
1609 Each such slot has a nonzero value in this structure.
|
|
1610 The value has only one nonzero bit.
|
|
1611
|
|
1612 When a buffer has its own local value for a slot,
|
|
1613 the bit for that slot (found in the same slot in this structure)
|
|
1614 is turned on in the buffer's local_var_flags slot.
|
|
1615
|
|
1616 If a slot in this structure is zero, then even though there may
|
|
1617 be a DEFVAR_BUFFER_LOCAL for the slot, there is no default value for it;
|
|
1618 and the corresponding slot in buffer_defaults is not used. */
|
|
1619
|
|
1620 extern struct buffer buffer_local_flags;
|
|
1621
|
|
1622
|
|
1623 /* Allocation of buffer data. */
|
|
1624
|
|
1625 #ifdef REL_ALLOC
|
|
1626
|
185
|
1627 char *r_alloc (unsigned char **, unsigned long);
|
|
1628 char *r_re_alloc (unsigned char **, unsigned long);
|
|
1629 void r_alloc_free (unsigned char **);
|
0
|
1630
|
185
|
1631 #define BUFFER_ALLOC(data, size) \
|
|
1632 ((Bufbyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Bufbyte)))
|
|
1633 #define BUFFER_REALLOC(data, size) \
|
|
1634 ((Bufbyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Bufbyte)))
|
|
1635 #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data))
|
0
|
1636 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data)
|
|
1637
|
|
1638 #else /* !REL_ALLOC */
|
|
1639
|
|
1640 #define BUFFER_ALLOC(data,size)\
|
185
|
1641 ((void) (data = xnew_array (Bufbyte, size)))
|
0
|
1642 #define BUFFER_REALLOC(data,size)\
|
|
1643 ((Bufbyte *) xrealloc (data, (size) * sizeof(Bufbyte)))
|
|
1644 /* Avoid excess parentheses, or syntax errors may rear their heads. */
|
|
1645 #define BUFFER_FREE(data) xfree (data)
|
|
1646 #define R_ALLOC_DECLARE(var,data)
|
|
1647
|
|
1648 #endif /* !REL_ALLOC */
|
|
1649
|
|
1650 extern Lisp_Object Vbuffer_alist;
|
|
1651 void set_buffer_internal (struct buffer *b);
|
|
1652 struct buffer *decode_buffer (Lisp_Object buffer, int allow_string);
|
|
1653
|
|
1654 /* from editfns.c */
|
|
1655 void widen_buffer (struct buffer *b, int no_clip);
|
|
1656 int beginning_of_line_p (struct buffer *b, Bufpos pt);
|
|
1657
|
|
1658 /* from insdel.c */
|
|
1659 void set_buffer_point (struct buffer *buf, Bufpos pos, Bytind bipos);
|
|
1660 void find_charsets_in_bufbyte_string (unsigned char *charsets,
|
|
1661 CONST Bufbyte *str,
|
|
1662 Bytecount len);
|
|
1663 void find_charsets_in_emchar_string (unsigned char *charsets,
|
|
1664 CONST Emchar *str,
|
|
1665 Charcount len);
|
|
1666 int bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len);
|
|
1667 int emchar_string_displayed_columns (CONST Emchar *str, Charcount len);
|
|
1668 void convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str,
|
|
1669 Bytecount len,
|
185
|
1670 Emchar_dynarr *dyn);
|
0
|
1671 int convert_bufbyte_string_into_emchar_string (CONST Bufbyte *str,
|
|
1672 Bytecount len,
|
|
1673 Emchar *arr);
|
|
1674 void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels,
|
185
|
1675 Bufbyte_dynarr *dyn);
|
0
|
1676 Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels,
|
|
1677 Bytecount *len_out);
|
|
1678
|
|
1679 /* flags for get_buffer_pos_char(), get_buffer_range_char(), etc. */
|
|
1680 /* At most one of GB_COERCE_RANGE and GB_NO_ERROR_IF_BAD should be
|
|
1681 specified. At most one of GB_NEGATIVE_FROM_END and GB_NO_ERROR_IF_BAD
|
|
1682 should be specified. */
|
|
1683
|
|
1684 #define GB_ALLOW_PAST_ACCESSIBLE (1 << 0)
|
|
1685 #define GB_ALLOW_NIL (1 << 1)
|
|
1686 #define GB_CHECK_ORDER (1 << 2)
|
|
1687 #define GB_COERCE_RANGE (1 << 3)
|
|
1688 #define GB_NO_ERROR_IF_BAD (1 << 4)
|
|
1689 #define GB_NEGATIVE_FROM_END (1 << 5)
|
|
1690 #define GB_HISTORICAL_STRING_BEHAVIOR (GB_NEGATIVE_FROM_END | GB_ALLOW_NIL)
|
|
1691
|
|
1692 Bufpos get_buffer_pos_char (struct buffer *b, Lisp_Object pos,
|
|
1693 unsigned int flags);
|
|
1694 Bytind get_buffer_pos_byte (struct buffer *b, Lisp_Object pos,
|
|
1695 unsigned int flags);
|
|
1696 void get_buffer_range_char (struct buffer *b, Lisp_Object from, Lisp_Object to,
|
|
1697 Bufpos *from_out, Bufpos *to_out,
|
|
1698 unsigned int flags);
|
|
1699 void get_buffer_range_byte (struct buffer *b, Lisp_Object from, Lisp_Object to,
|
|
1700 Bytind *from_out, Bytind *to_out,
|
|
1701 unsigned int flags);
|
|
1702 Charcount get_string_pos_char (Lisp_Object string, Lisp_Object pos,
|
|
1703 unsigned int flags);
|
|
1704 Bytecount get_string_pos_byte (Lisp_Object string, Lisp_Object pos,
|
|
1705 unsigned int flags);
|
|
1706 void get_string_range_char (Lisp_Object string, Lisp_Object from,
|
|
1707 Lisp_Object to, Charcount *from_out,
|
|
1708 Charcount *to_out, unsigned int flags);
|
|
1709 void get_string_range_byte (Lisp_Object string, Lisp_Object from,
|
|
1710 Lisp_Object to, Bytecount *from_out,
|
|
1711 Bytecount *to_out, unsigned int flags);
|
|
1712 Bufpos get_buffer_or_string_pos_char (Lisp_Object object, Lisp_Object pos,
|
|
1713 unsigned int flags);
|
|
1714 Bytind get_buffer_or_string_pos_byte (Lisp_Object object, Lisp_Object pos,
|
|
1715 unsigned int flags);
|
|
1716 void get_buffer_or_string_range_char (Lisp_Object object, Lisp_Object from,
|
|
1717 Lisp_Object to, Bufpos *from_out,
|
|
1718 Bufpos *to_out, unsigned int flags);
|
|
1719 void get_buffer_or_string_range_byte (Lisp_Object object, Lisp_Object from,
|
|
1720 Lisp_Object to, Bytind *from_out,
|
|
1721 Bytind *to_out, unsigned int flags);
|
|
1722 Bufpos buffer_or_string_accessible_begin_char (Lisp_Object object);
|
|
1723 Bufpos buffer_or_string_accessible_end_char (Lisp_Object object);
|
|
1724 Bytind buffer_or_string_accessible_begin_byte (Lisp_Object object);
|
|
1725 Bytind buffer_or_string_accessible_end_byte (Lisp_Object object);
|
|
1726 Bufpos buffer_or_string_absolute_begin_char (Lisp_Object object);
|
|
1727 Bufpos buffer_or_string_absolute_end_char (Lisp_Object object);
|
|
1728 Bytind buffer_or_string_absolute_begin_byte (Lisp_Object object);
|
|
1729 Bytind buffer_or_string_absolute_end_byte (Lisp_Object object);
|
|
1730 void record_buffer (Lisp_Object buf);
|
|
1731 Lisp_Object get_buffer (Lisp_Object name,
|
|
1732 int error_if_deleted_or_does_not_exist);
|
|
1733 int map_over_sharing_buffers (struct buffer *buf,
|
|
1734 int (*mapfun) (struct buffer *buf,
|
|
1735 void *closure),
|
|
1736 void *closure);
|
|
1737
|
|
1738
|
|
1739 /************************************************************************/
|
|
1740 /* Case conversion */
|
|
1741 /************************************************************************/
|
|
1742
|
|
1743 /* A "trt" table is a mapping from characters to other characters,
|
|
1744 typically used to convert between uppercase and lowercase. For
|
|
1745 compatibility reasons, trt tables are currently in the form of
|
|
1746 a Lisp string of 256 characters, specifying the conversion for each
|
|
1747 of the first 256 Emacs characters (i.e. the 256 extended-ASCII
|
|
1748 characters). This should be generalized at some point to support
|
|
1749 conversions for all of the allowable Mule characters.
|
|
1750 */
|
|
1751
|
|
1752 /* The _1 macros are named as such because they assume that you have
|
|
1753 already guaranteed that the character values are all in the range
|
|
1754 0 - 255. Bad lossage will happen otherwise. */
|
|
1755
|
|
1756 # define MAKE_TRT_TABLE() Fmake_string (make_int (256), make_char (0))
|
16
|
1757 # define TRT_TABLE_AS_STRING(table) XSTRING_DATA (table)
|
0
|
1758 # define TRT_TABLE_CHAR_1(table, ch) \
|
|
1759 string_char (XSTRING (table), (Charcount) ch)
|
|
1760 # define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \
|
|
1761 set_string_char (XSTRING (table), (Charcount) ch1, ch2)
|
|
1762
|
70
|
1763 #ifdef MULE
|
|
1764 # define MAKE_MIRROR_TRT_TABLE() make_opaque (256, 0)
|
|
1765 # define MIRROR_TRT_TABLE_AS_STRING(table) ((Bufbyte *) XOPAQUE_DATA (table))
|
|
1766 # define MIRROR_TRT_TABLE_CHAR_1(table, ch) \
|
|
1767 ((Emchar) (MIRROR_TRT_TABLE_AS_STRING (table)[ch]))
|
|
1768 # define SET_MIRROR_TRT_TABLE_CHAR_1(table, ch1, ch2) \
|
|
1769 (MIRROR_TRT_TABLE_AS_STRING (table)[ch1] = (Bufbyte) (ch2))
|
|
1770 #endif
|
|
1771
|
183
|
1772 # define IN_TRT_TABLE_DOMAIN(c) (((unsigned EMACS_INT) (c)) <= 255)
|
0
|
1773
|
70
|
1774 #ifdef MULE
|
|
1775 #define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \
|
|
1776 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_downcase_table)
|
|
1777 #define MIRROR_UPCASE_TABLE_AS_STRING(buf) \
|
|
1778 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_upcase_table)
|
|
1779 #define MIRROR_CANON_TABLE_AS_STRING(buf) \
|
|
1780 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_case_canon_table)
|
|
1781 #define MIRROR_EQV_TABLE_AS_STRING(buf) \
|
|
1782 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_case_eqv_table)
|
|
1783 #else
|
0
|
1784 #define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \
|
|
1785 TRT_TABLE_AS_STRING (buf->downcase_table)
|
|
1786 #define MIRROR_UPCASE_TABLE_AS_STRING(buf) \
|
|
1787 TRT_TABLE_AS_STRING (buf->upcase_table)
|
|
1788 #define MIRROR_CANON_TABLE_AS_STRING(buf) \
|
|
1789 TRT_TABLE_AS_STRING (buf->case_canon_table)
|
|
1790 #define MIRROR_EQV_TABLE_AS_STRING(buf) \
|
|
1791 TRT_TABLE_AS_STRING (buf->case_eqv_table)
|
70
|
1792 #endif
|
0
|
1793
|
|
1794 INLINE Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c);
|
|
1795 INLINE Emchar
|
|
1796 TRT_TABLE_OF (Lisp_Object trt, Emchar c)
|
|
1797 {
|
183
|
1798 return IN_TRT_TABLE_DOMAIN (c) ? TRT_TABLE_CHAR_1 (trt, c) : c;
|
0
|
1799 }
|
|
1800
|
|
1801 /* Macros used below. */
|
|
1802 #define DOWNCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->downcase_table, c)
|
|
1803 #define UPCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->upcase_table, c)
|
|
1804
|
|
1805 /* 1 if CH is upper case. */
|
|
1806
|
|
1807 INLINE int UPPERCASEP (struct buffer *buf, Emchar ch);
|
|
1808 INLINE int
|
|
1809 UPPERCASEP (struct buffer *buf, Emchar ch)
|
|
1810 {
|
183
|
1811 return DOWNCASE_TABLE_OF (buf, ch) != ch;
|
0
|
1812 }
|
|
1813
|
|
1814 /* 1 if CH is lower case. */
|
|
1815
|
|
1816 INLINE int LOWERCASEP (struct buffer *buf, Emchar ch);
|
|
1817 INLINE int
|
|
1818 LOWERCASEP (struct buffer *buf, Emchar ch)
|
|
1819 {
|
183
|
1820 return (UPCASE_TABLE_OF (buf, ch) != ch &&
|
0
|
1821 DOWNCASE_TABLE_OF (buf, ch) == ch);
|
|
1822 }
|
|
1823
|
|
1824 /* 1 if CH is neither upper nor lower case. */
|
|
1825
|
|
1826 INLINE int NOCASEP (struct buffer *buf, Emchar ch);
|
|
1827 INLINE int
|
|
1828 NOCASEP (struct buffer *buf, Emchar ch)
|
|
1829 {
|
183
|
1830 return UPCASE_TABLE_OF (buf, ch) == ch;
|
0
|
1831 }
|
|
1832
|
|
1833 /* Upcase a character, or make no change if that cannot be done. */
|
|
1834
|
|
1835 INLINE Emchar UPCASE (struct buffer *buf, Emchar ch);
|
|
1836 INLINE Emchar
|
|
1837 UPCASE (struct buffer *buf, Emchar ch)
|
|
1838 {
|
183
|
1839 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch;
|
0
|
1840 }
|
|
1841
|
|
1842 /* Upcase a character known to be not upper case. */
|
|
1843
|
|
1844 #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch)
|
|
1845
|
|
1846 /* Downcase a character, or make no change if that cannot be done. */
|
|
1847
|
|
1848 #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch)
|
|
1849
|
|
1850
|
167
|
1851 /* put it here, somewhat arbitrarily ... it needs to be in *some*
|
0
|
1852 header file. */
|
|
1853 DECLARE_LRECORD (range_table, struct Lisp_Range_Table);
|
|
1854
|
|
1855 #endif /* _XEMACS_BUFFER_H_ */
|