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