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