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