Mercurial > hg > xemacs-beta
comparison src/text.h @ 867:804517e16990
[xemacs-hg @ 2002-06-05 09:54:39 by ben]
Textual renaming: text/char names
abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, charset.h, chartab.c, chartab.h, cmds.c, console-gtk.h, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console-x.h, console.h, data.c, device-msw.c, device-x.c, dialog-msw.c, dired-msw.c, dired.c, doc.c, doprnt.c, editfns.c, eldap.c, emodules.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, event-unixoid.c, events.c, events.h, file-coding.c, file-coding.h, fileio.c, filelock.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, glyphs-eimage.c, glyphs-msw.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-x.c, gui-x.h, gui.c, gui.h, hpplay.c, indent.c, insdel.c, insdel.h, intl-win32.c, keymap.c, line-number.c, line-number.h, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, md5.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, ndir.h, nt.c, objects-gtk.c, objects-gtk.h, objects-msw.c, objects-tty.c, objects-x.c, objects.c, objects.h, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, procimpl.h, realpath.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-tty.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, search.c, select-common.h, select-gtk.c, select-x.c, sound.h, symbols.c, syntax.c, syntax.h, sysdep.c, sysdep.h, sysdir.h, sysfile.h, sysproc.h, syspwd.h, systime.h, syswindows.h, termcap.c, tests.c, text.c, text.h, toolbar-common.c, tooltalk.c, ui-gtk.c, unexnt.c, unicode.c, win32.c: Text/char naming rationalization.
[a] distinguish between "charptr" when it refers to operations on
the pointer itself and when it refers to operations on text; and
[b] use consistent naming for everything referring to internal
format, i.e.
Itext == text in internal format
Ibyte == a byte in such text
Ichar == a char as represented in internal character format
thus e.g.
set_charptr_emchar -> set_itext_ichar
The pre and post tags on either side of this change are:
pre-internal-format-textual-renaming
post-internal-format-textual-renaming
See the Internals Manual for details of exactly how this was done,
how to handle the change in your workspace, etc.
author | ben |
---|---|
date | Wed, 05 Jun 2002 09:58:45 +0000 |
parents | e7ee5f8bde58 |
children | e10cdc51a200 |
comparison
equal
deleted
inserted
replaced
866:613552a02607 | 867:804517e16990 |
---|---|
52 | 52 |
53 #ifndef MULE | 53 #ifndef MULE |
54 | 54 |
55 #define rep_bytes_by_first_byte(fb) 1 | 55 #define rep_bytes_by_first_byte(fb) 1 |
56 #define byte_ascii_p(byte) 1 | 56 #define byte_ascii_p(byte) 1 |
57 #define MAX_EMCHAR_LEN 1 | 57 #define MAX_ICHAR_LEN 1 |
58 | 58 |
59 #else /* MULE */ | 59 #else /* MULE */ |
60 | 60 |
61 /* These are carefully designed to work if BYTE is signed or unsigned. */ | 61 /* These are carefully designed to work if BYTE is signed or unsigned. */ |
62 /* Note that SPC and DEL are considered ASCII, not control. */ | 62 /* Note that SPC and DEL are considered ASCII, not control. */ |
69 | 69 |
70 #ifdef ERROR_CHECK_TEXT | 70 #ifdef ERROR_CHECK_TEXT |
71 | 71 |
72 DECLARE_INLINE_HEADER ( | 72 DECLARE_INLINE_HEADER ( |
73 int | 73 int |
74 intbyte_first_byte_p_1 (int byte, const char *file, int line) | 74 ibyte_first_byte_p_1 (int byte, const char *file, int line) |
75 ) | 75 ) |
76 { | 76 { |
77 assert_at_line (byte >= 0 && byte < 256, file, line); | 77 assert_at_line (byte >= 0 && byte < 256, file, line); |
78 return byte < 0xA0; | 78 return byte < 0xA0; |
79 } | 79 } |
80 | 80 |
81 #define intbyte_first_byte_p(byte) \ | 81 #define ibyte_first_byte_p(byte) \ |
82 intbyte_first_byte_p_1 (byte, __FILE__, __LINE__) | 82 ibyte_first_byte_p_1 (byte, __FILE__, __LINE__) |
83 | 83 |
84 #else | 84 #else |
85 | 85 |
86 #define intbyte_first_byte_p(byte) ((byte) < 0xA0) | 86 #define ibyte_first_byte_p(byte) ((byte) < 0xA0) |
87 | 87 |
88 #endif | 88 #endif |
89 | 89 |
90 #ifdef ERROR_CHECK_TEXT | 90 #ifdef ERROR_CHECK_TEXT |
91 | 91 |
92 /* Does BYTE represent the first byte of a multi-byte character? */ | 92 /* Does BYTE represent the first byte of a multi-byte character? */ |
93 | 93 |
94 DECLARE_INLINE_HEADER ( | 94 DECLARE_INLINE_HEADER ( |
95 int | 95 int |
96 intbyte_leading_byte_p_1 (int byte, const char *file, int line) | 96 ibyte_leading_byte_p_1 (int byte, const char *file, int line) |
97 ) | 97 ) |
98 { | 98 { |
99 assert_at_line (byte >= 0 && byte < 256, file, line); | 99 assert_at_line (byte >= 0 && byte < 256, file, line); |
100 return byte_c1_p (byte); | 100 return byte_c1_p (byte); |
101 } | 101 } |
102 | 102 |
103 #define intbyte_leading_byte_p(byte) \ | 103 #define ibyte_leading_byte_p(byte) \ |
104 intbyte_leading_byte_p_1 (byte, __FILE__, __LINE__) | 104 ibyte_leading_byte_p_1 (byte, __FILE__, __LINE__) |
105 | 105 |
106 #else | 106 #else |
107 | 107 |
108 #define intbyte_leading_byte_p(byte) byte_c1_p (byte) | 108 #define ibyte_leading_byte_p(byte) byte_c1_p (byte) |
109 | 109 |
110 #endif | 110 #endif |
111 | 111 |
112 /* Table of number of bytes in the string representation of a character | 112 /* Table of number of bytes in the string representation of a character |
113 indexed by the first byte of that representation. | 113 indexed by the first byte of that representation. |
140 #endif /* ERROR_CHECK_TEXT */ | 140 #endif /* ERROR_CHECK_TEXT */ |
141 | 141 |
142 /* Is this character represented by more than one byte in a string in the | 142 /* Is this character represented by more than one byte in a string in the |
143 default format? */ | 143 default format? */ |
144 | 144 |
145 #define emchar_multibyte_p(c) ((c) >= 0x80) | 145 #define ichar_multibyte_p(c) ((c) >= 0x80) |
146 | 146 |
147 #define emchar_ascii_p(c) (!emchar_multibyte_p (c)) | 147 #define ichar_ascii_p(c) (!ichar_multibyte_p (c)) |
148 | 148 |
149 /* Maximum number of bytes per Emacs character when represented as text, in | 149 /* Maximum number of bytes per Emacs character when represented as text, in |
150 any format. | 150 any format. |
151 */ | 151 */ |
152 | 152 |
153 #define MAX_EMCHAR_LEN 4 | 153 #define MAX_ICHAR_LEN 4 |
154 | 154 |
155 #endif /* not MULE */ | 155 #endif /* not MULE */ |
156 | 156 |
157 /* ---------------- Handling non-default formats ----------------- */ | 157 /* ---------------- Handling non-default formats ----------------- */ |
158 | 158 |
180 represent only a subset of the possible characters. How these subsets | 180 represent only a subset of the possible characters. How these subsets |
181 are defined can be simple or very tricky. | 181 are defined can be simple or very tricky. |
182 | 182 |
183 Currently we support only the default format and the 8-bit fixed format, | 183 Currently we support only the default format and the 8-bit fixed format, |
184 and in the latter, we only allow these to be the first 256 characters in | 184 and in the latter, we only allow these to be the first 256 characters in |
185 an Emchar (ASCII and Latin 1). | 185 an Ichar (ASCII and Latin 1). |
186 | 186 |
187 One reasonable approach for 8-bit fixed is to allow the upper half to | 187 One reasonable approach for 8-bit fixed is to allow the upper half to |
188 represent any 1-byte charset, which is specified on a per-buffer basis. | 188 represent any 1-byte charset, which is specified on a per-buffer basis. |
189 This should work fairly well in practice since most documents are in | 189 This should work fairly well in practice since most documents are in |
190 only one foreign language (possibly with some English mixed in). I | 190 only one foreign language (possibly with some English mixed in). I |
233 /* "OBJECT" below will usually be a buffer, string, or nil. This needs to | 233 /* "OBJECT" below will usually be a buffer, string, or nil. This needs to |
234 be passed in because the interpretation of 8-bit-fixed and 16-bit-fixed | 234 be passed in because the interpretation of 8-bit-fixed and 16-bit-fixed |
235 values may depend on the buffer, e.g. depending on what language the | 235 values may depend on the buffer, e.g. depending on what language the |
236 text in the buffer is in. */ | 236 text in the buffer is in. */ |
237 | 237 |
238 /* True if Emchar CH can be represented in 8-bit-fixed format. */ | 238 /* True if Ichar CH can be represented in 8-bit-fixed format. */ |
239 #define emchar_8_bit_fixed_p(ch, object) (((ch) & ~0xff) == 0) | 239 #define ichar_8_bit_fixed_p(ch, object) (((ch) & ~0xff) == 0) |
240 /* Convert Emchar CH to an 8-bit int, as will be stored in the buffer. */ | 240 /* Convert Ichar CH to an 8-bit int, as will be stored in the buffer. */ |
241 #define emchar_to_raw_8_bit_fixed(ch, object) ((Intbyte) (ch)) | 241 #define ichar_to_raw_8_bit_fixed(ch, object) ((Ibyte) (ch)) |
242 /* Convert the other way. */ | 242 /* Convert the other way. */ |
243 #define raw_8_bit_fixed_to_emchar(ch, object) ((Emchar) (ch)) | 243 #define raw_8_bit_fixed_to_ichar(ch, object) ((Ichar) (ch)) |
244 | 244 |
245 #define emchar_16_bit_fixed_p(ch, object) (((ch) & ~0xffff) == 0) | 245 #define ichar_16_bit_fixed_p(ch, object) (((ch) & ~0xffff) == 0) |
246 /* Convert Emchar CH to a 16-bit int, as will be stored in the buffer. */ | 246 /* Convert Ichar CH to a 16-bit int, as will be stored in the buffer. */ |
247 #define emchar_to_raw_16_bit_fixed(ch, object) ((UINT_16_BIT) (ch)) | 247 #define ichar_to_raw_16_bit_fixed(ch, object) ((UINT_16_BIT) (ch)) |
248 /* Convert the other way. */ | 248 /* Convert the other way. */ |
249 #define raw_16_bit_fixed_to_emchar(ch, object) ((Emchar) (ch)) | 249 #define raw_16_bit_fixed_to_ichar(ch, object) ((Ichar) (ch)) |
250 | 250 |
251 /* Convert Emchar CH to a 32-bit int, as will be stored in the buffer. */ | 251 /* Convert Ichar CH to a 32-bit int, as will be stored in the buffer. */ |
252 #define emchar_to_raw_32_bit_fixed(ch, object) ((UINT_32_BIT) (ch)) | 252 #define ichar_to_raw_32_bit_fixed(ch, object) ((UINT_32_BIT) (ch)) |
253 /* Convert the other way. */ | 253 /* Convert the other way. */ |
254 #define raw_32_bit_fixed_to_emchar(ch, object) ((Emchar) (ch)) | 254 #define raw_32_bit_fixed_to_ichar(ch, object) ((Ichar) (ch)) |
255 | 255 |
256 /* Return the "raw value" of a character as stored in the buffer. In the | 256 /* Return the "raw value" of a character as stored in the buffer. In the |
257 default format, this is just the same as the character. In fixed-width | 257 default format, this is just the same as the character. In fixed-width |
258 formats, this is the actual value in the buffer, which will be limited | 258 formats, this is the actual value in the buffer, which will be limited |
259 to the range as established by the format. This is used when searching | 259 to the range as established by the format. This is used when searching |
260 for a character in a buffer -- it's faster to convert the character to | 260 for a character in a buffer -- it's faster to convert the character to |
261 the raw value and look for that, than repeatedly convert each raw value | 261 the raw value and look for that, than repeatedly convert each raw value |
262 in the buffer into a character. */ | 262 in the buffer into a character. */ |
263 | 263 |
264 DECLARE_INLINE_HEADER ( | 264 DECLARE_INLINE_HEADER ( |
265 Raw_Emchar | 265 Raw_Ichar |
266 emchar_to_raw (Emchar ch, Internal_Format fmt, Lisp_Object object) | 266 ichar_to_raw (Ichar ch, Internal_Format fmt, Lisp_Object object) |
267 ) | 267 ) |
268 { | 268 { |
269 switch (fmt) | 269 switch (fmt) |
270 { | 270 { |
271 case FORMAT_DEFAULT: | 271 case FORMAT_DEFAULT: |
272 return (Raw_Emchar) ch; | 272 return (Raw_Ichar) ch; |
273 case FORMAT_16_BIT_FIXED: | 273 case FORMAT_16_BIT_FIXED: |
274 text_checking_assert (emchar_16_bit_fixed_p (ch, object)); | 274 text_checking_assert (ichar_16_bit_fixed_p (ch, object)); |
275 return (Raw_Emchar) emchar_to_raw_16_bit_fixed (ch, object); | 275 return (Raw_Ichar) ichar_to_raw_16_bit_fixed (ch, object); |
276 case FORMAT_32_BIT_FIXED: | 276 case FORMAT_32_BIT_FIXED: |
277 return (Raw_Emchar) emchar_to_raw_32_bit_fixed (ch, object); | 277 return (Raw_Ichar) ichar_to_raw_32_bit_fixed (ch, object); |
278 default: | 278 default: |
279 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); | 279 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); |
280 text_checking_assert (emchar_8_bit_fixed_p (ch, object)); | 280 text_checking_assert (ichar_8_bit_fixed_p (ch, object)); |
281 return (Raw_Emchar) emchar_to_raw_8_bit_fixed (ch, object); | 281 return (Raw_Ichar) ichar_to_raw_8_bit_fixed (ch, object); |
282 } | 282 } |
283 } | 283 } |
284 | 284 |
285 /* Return whether CH is representable in the given format in the given | 285 /* Return whether CH is representable in the given format in the given |
286 object. */ | 286 object. */ |
287 | 287 |
288 DECLARE_INLINE_HEADER ( | 288 DECLARE_INLINE_HEADER ( |
289 int | 289 int |
290 emchar_fits_in_format (Emchar ch, Internal_Format fmt, Lisp_Object object) | 290 ichar_fits_in_format (Ichar ch, Internal_Format fmt, Lisp_Object object) |
291 ) | 291 ) |
292 { | 292 { |
293 switch (fmt) | 293 switch (fmt) |
294 { | 294 { |
295 case FORMAT_DEFAULT: | 295 case FORMAT_DEFAULT: |
296 return 1; | 296 return 1; |
297 case FORMAT_16_BIT_FIXED: | 297 case FORMAT_16_BIT_FIXED: |
298 return emchar_16_bit_fixed_p (ch, object); | 298 return ichar_16_bit_fixed_p (ch, object); |
299 case FORMAT_32_BIT_FIXED: | 299 case FORMAT_32_BIT_FIXED: |
300 return 1; | 300 return 1; |
301 default: | 301 default: |
302 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); | 302 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); |
303 return emchar_8_bit_fixed_p (ch, object); | 303 return ichar_8_bit_fixed_p (ch, object); |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
307 /* Assuming the formats are the same, return whether the two objects | 307 /* Assuming the formats are the same, return whether the two objects |
308 represent text in exactly the same way. */ | 308 represent text in exactly the same way. */ |
318 return 1; | 318 return 1; |
319 } | 319 } |
320 | 320 |
321 #else | 321 #else |
322 | 322 |
323 #define emchar_to_raw(ch, fmt, object) ((Raw_Emchar) (ch)) | 323 #define ichar_to_raw(ch, fmt, object) ((Raw_Ichar) (ch)) |
324 #define emchar_fits_in_format(ch, fmt, object) 1 | 324 #define ichar_fits_in_format(ch, fmt, object) 1 |
325 #define objects_have_same_internal_representation(srcobj, dstobj) 1 | 325 #define objects_have_same_internal_representation(srcobj, dstobj) 1 |
326 | 326 |
327 #endif /* MULE */ | 327 #endif /* MULE */ |
328 | 328 |
329 int dfc_coding_system_is_unicode (Lisp_Object coding_system); | 329 int dfc_coding_system_is_unicode (Lisp_Object coding_system); |
353 use the buffer-level functions in buffer.h, which automatically know the | 353 use the buffer-level functions in buffer.h, which automatically know the |
354 correct format and handle the gap. | 354 correct format and handle the gap. |
355 | 355 |
356 Some terminology: | 356 Some terminology: |
357 | 357 |
358 "charptr" appearing in the macros means "internal-format text" -- type | 358 "itext" appearing in the macros means "internal-format text" -- type |
359 `Intbyte *'. Operations on such pointers themselves, rather than on the | 359 `Ibyte *'. Operations on such pointers themselves, rather than on the |
360 text being pointed to, have "charptr" instead of "charptr" in the macro | 360 text being pointed to, have "itext" instead of "itext" in the macro |
361 name. "emchar" in the macro names means an Emchar -- the representation | 361 name. "ichar" in the macro names means an Ichar -- the representation |
362 of a character as a single integer rather than a series of bytes, as part | 362 of a character as a single integer rather than a series of bytes, as part |
363 of "charptr". Many of the macros below are for converting between the | 363 of "itext". Many of the macros below are for converting between the |
364 two representations of characters. | 364 two representations of characters. |
365 | 365 |
366 Note also that we try to consistently distinguish between an "Emchar" and | 366 Note also that we try to consistently distinguish between an "Ichar" and |
367 a Lisp character. Stuff working with Lisp characters often just says | 367 a Lisp character. Stuff working with Lisp characters often just says |
368 "char", so we consistently use "Emchar" when that's what we're working | 368 "char", so we consistently use "Ichar" when that's what we're working |
369 with. */ | 369 with. */ |
370 | 370 |
371 /* The three golden rules of macros: | 371 /* The three golden rules of macros: |
372 | 372 |
373 1) Anything that's an lvalue can be evaluated more than once. | 373 1) Anything that's an lvalue can be evaluated more than once. |
414 | 414 |
415 -- Try to avoid capitalizing any other macros. | 415 -- Try to avoid capitalizing any other macros. |
416 */ | 416 */ |
417 | 417 |
418 /* ---------------------------------------------------------------------- */ | 418 /* ---------------------------------------------------------------------- */ |
419 /* Working with charptr's (pointers to internally-formatted text) */ | 419 /* Working with itext's (pointers to internally-formatted text) */ |
420 /* ---------------------------------------------------------------------- */ | 420 /* ---------------------------------------------------------------------- */ |
421 | 421 |
422 /* Given an charptr, does it point to the beginning of a character? | 422 /* Given an itext, does it point to the beginning of a character? |
423 */ | 423 */ |
424 | 424 |
425 #ifdef MULE | 425 #ifdef MULE |
426 # define valid_charptr_p(ptr) intbyte_first_byte_p (* (ptr)) | 426 # define valid_ibyteptr_p(ptr) ibyte_first_byte_p (* (ptr)) |
427 #else | 427 #else |
428 # define valid_charptr_p(ptr) 1 | 428 # define valid_ibyteptr_p(ptr) 1 |
429 #endif | 429 #endif |
430 | 430 |
431 /* If error-checking is enabled, assert that the given charptr points to | 431 /* If error-checking is enabled, assert that the given itext points to |
432 the beginning of a character. Otherwise, do nothing. | 432 the beginning of a character. Otherwise, do nothing. |
433 */ | 433 */ |
434 | 434 |
435 #define assert_valid_charptr(ptr) text_checking_assert (valid_charptr_p (ptr)) | 435 #define assert_valid_ibyteptr(ptr) text_checking_assert (valid_ibyteptr_p (ptr)) |
436 | 436 |
437 /* Given a charptr (assumed to point at the beginning of a character), | 437 /* Given a itext (assumed to point at the beginning of a character), |
438 modify that pointer so it points to the beginning of the next character. | 438 modify that pointer so it points to the beginning of the next character. |
439 | 439 |
440 Note that INC_CHARPTR() and DEC_CHARPTR() have to be written in | 440 Note that INC_IBYTEPTR() and DEC_IBYTEPTR() have to be written in |
441 completely separate ways. INC_CHARPTR() cannot use the DEC_CHARPTR() | 441 completely separate ways. INC_IBYTEPTR() cannot use the DEC_IBYTEPTR() |
442 trick of looking for a valid first byte because it might run off | 442 trick of looking for a valid first byte because it might run off |
443 the end of the string. DEC_CHARPTR() can't use the INC_CHARPTR() | 443 the end of the string. DEC_IBYTEPTR() can't use the INC_IBYTEPTR() |
444 method because it doesn't have easy access to the first byte of | 444 method because it doesn't have easy access to the first byte of |
445 the character it's moving over. */ | 445 the character it's moving over. */ |
446 | 446 |
447 #define INC_CHARPTR(ptr) do { \ | 447 #define INC_IBYTEPTR(ptr) do { \ |
448 assert_valid_charptr (ptr); \ | 448 assert_valid_ibyteptr (ptr); \ |
449 (ptr) += rep_bytes_by_first_byte (* (ptr)); \ | 449 (ptr) += rep_bytes_by_first_byte (* (ptr)); \ |
450 } while (0) | 450 } while (0) |
451 | 451 |
452 #define INC_CHARPTR_FMT(ptr, fmt) \ | 452 #define INC_IBYTEPTR_FMT(ptr, fmt) \ |
453 do { \ | 453 do { \ |
454 Internal_Format __icf_fmt = (fmt); \ | 454 Internal_Format __icf_fmt = (fmt); \ |
455 switch (__icf_fmt) \ | 455 switch (__icf_fmt) \ |
456 { \ | 456 { \ |
457 case FORMAT_DEFAULT: \ | 457 case FORMAT_DEFAULT: \ |
458 INC_CHARPTR (ptr); \ | 458 INC_IBYTEPTR (ptr); \ |
459 break; \ | 459 break; \ |
460 case FORMAT_16_BIT_FIXED: \ | 460 case FORMAT_16_BIT_FIXED: \ |
461 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); \ | 461 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); \ |
462 (ptr) += 2; \ | 462 (ptr) += 2; \ |
463 break; \ | 463 break; \ |
470 (ptr)++; \ | 470 (ptr)++; \ |
471 break; \ | 471 break; \ |
472 } \ | 472 } \ |
473 } while (0) | 473 } while (0) |
474 | 474 |
475 /* Given a charptr (assumed to point at the beginning of a character or at | 475 /* Given a itext (assumed to point at the beginning of a character or at |
476 the very end of the text), modify that pointer so it points to the | 476 the very end of the text), modify that pointer so it points to the |
477 beginning of the previous character. | 477 beginning of the previous character. |
478 */ | 478 */ |
479 | 479 |
480 #ifdef ERROR_CHECK_TEXT | 480 #ifdef ERROR_CHECK_TEXT |
481 /* We use a separate definition to avoid warnings about unused dc_ptr1 */ | 481 /* We use a separate definition to avoid warnings about unused dc_ptr1 */ |
482 #define DEC_CHARPTR(ptr) do { \ | 482 #define DEC_IBYTEPTR(ptr) do { \ |
483 const Intbyte *dc_ptr1 = (ptr); \ | 483 const Ibyte *dc_ptr1 = (ptr); \ |
484 do { \ | 484 do { \ |
485 (ptr)--; \ | 485 (ptr)--; \ |
486 } while (!valid_charptr_p (ptr)); \ | 486 } while (!valid_ibyteptr_p (ptr)); \ |
487 text_checking_assert (dc_ptr1 - (ptr) == rep_bytes_by_first_byte (*(ptr))); \ | 487 text_checking_assert (dc_ptr1 - (ptr) == rep_bytes_by_first_byte (*(ptr))); \ |
488 } while (0) | 488 } while (0) |
489 #else | 489 #else |
490 #define DEC_CHARPTR(ptr) do { \ | 490 #define DEC_IBYTEPTR(ptr) do { \ |
491 do { \ | 491 do { \ |
492 (ptr)--; \ | 492 (ptr)--; \ |
493 } while (!valid_charptr_p (ptr)); \ | 493 } while (!valid_ibyteptr_p (ptr)); \ |
494 } while (0) | 494 } while (0) |
495 #endif /* ERROR_CHECK_TEXT */ | 495 #endif /* ERROR_CHECK_TEXT */ |
496 | 496 |
497 #define DEC_CHARPTR_FMT(ptr, fmt) \ | 497 #define DEC_IBYTEPTR_FMT(ptr, fmt) \ |
498 do { \ | 498 do { \ |
499 Internal_Format __icf_fmt = (fmt); \ | 499 Internal_Format __icf_fmt = (fmt); \ |
500 switch (__icf_fmt) \ | 500 switch (__icf_fmt) \ |
501 { \ | 501 { \ |
502 case FORMAT_DEFAULT: \ | 502 case FORMAT_DEFAULT: \ |
503 DEC_CHARPTR (ptr); \ | 503 DEC_IBYTEPTR (ptr); \ |
504 break; \ | 504 break; \ |
505 case FORMAT_16_BIT_FIXED: \ | 505 case FORMAT_16_BIT_FIXED: \ |
506 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); \ | 506 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); \ |
507 (ptr) -= 2; \ | 507 (ptr) -= 2; \ |
508 break; \ | 508 break; \ |
528 crashes. | 528 crashes. |
529 */ | 529 */ |
530 | 530 |
531 /* Note that this reads the byte at *PTR! */ | 531 /* Note that this reads the byte at *PTR! */ |
532 | 532 |
533 #define VALIDATE_CHARPTR_BACKWARD(ptr) do { \ | 533 #define VALIDATE_IBYTEPTR_BACKWARD(ptr) do { \ |
534 while (!valid_charptr_p (ptr)) ptr--; \ | 534 while (!valid_ibyteptr_p (ptr)) ptr--; \ |
535 } while (0) | 535 } while (0) |
536 | 536 |
537 /* Make sure that PTR is pointing to the beginning of a character. If not, | 537 /* Make sure that PTR is pointing to the beginning of a character. If not, |
538 move forward until this is the case. Note that there are not too many | 538 move forward until this is the case. Note that there are not too many |
539 places where it is legitimate to do this sort of thing. It's an error | 539 places where it is legitimate to do this sort of thing. It's an error |
540 if you're passed an "invalid" char * pointer. | 540 if you're passed an "invalid" char * pointer. |
541 */ | 541 */ |
542 | 542 |
543 /* This needs to be trickier than VALIDATE_CHARPTR_BACKWARD() to avoid the | 543 /* This needs to be trickier than VALIDATE_IBYTEPTR_BACKWARD() to avoid the |
544 possibility of running off the end of the string. */ | 544 possibility of running off the end of the string. */ |
545 | 545 |
546 #define VALIDATE_CHARPTR_FORWARD(ptr) do { \ | 546 #define VALIDATE_IBYTEPTR_FORWARD(ptr) do { \ |
547 Intbyte *vcf_ptr = (ptr); \ | 547 Ibyte *vcf_ptr = (ptr); \ |
548 VALIDATE_CHARPTR_BACKWARD (vcf_ptr); \ | 548 VALIDATE_IBYTEPTR_BACKWARD (vcf_ptr); \ |
549 if (vcf_ptr != (ptr)) \ | 549 if (vcf_ptr != (ptr)) \ |
550 { \ | 550 { \ |
551 (ptr) = vcf_ptr; \ | 551 (ptr) = vcf_ptr; \ |
552 INC_CHARPTR (ptr); \ | 552 INC_IBYTEPTR (ptr); \ |
553 } \ | 553 } \ |
554 } while (0) | 554 } while (0) |
555 | 555 |
556 #else /* not MULE */ | 556 #else /* not MULE */ |
557 #define VALIDATE_CHARPTR_BACKWARD(ptr) | 557 #define VALIDATE_IBYTEPTR_BACKWARD(ptr) |
558 #define VALIDATE_CHARPTR_FORWARD(ptr) | 558 #define VALIDATE_IBYTEPTR_FORWARD(ptr) |
559 #endif /* not MULE */ | 559 #endif /* not MULE */ |
560 | 560 |
561 #ifdef MULE | 561 #ifdef MULE |
562 | 562 |
563 /* Given a Intbyte string at PTR of size N, possibly with a partial | 563 /* Given a Ibyte string at PTR of size N, possibly with a partial |
564 character at the end, return the size of the longest substring of | 564 character at the end, return the size of the longest substring of |
565 complete characters. Does not assume that the byte at *(PTR + N) is | 565 complete characters. Does not assume that the byte at *(PTR + N) is |
566 readable. Note that there are not too many places where it is | 566 readable. Note that there are not too many places where it is |
567 legitimate to do this sort of thing. It's an error if you're passed an | 567 legitimate to do this sort of thing. It's an error if you're passed an |
568 "invalid" offset. */ | 568 "invalid" offset. */ |
569 | 569 |
570 DECLARE_INLINE_HEADER ( | 570 DECLARE_INLINE_HEADER ( |
571 Bytecount | 571 Bytecount |
572 validate_intbyte_string_backward (const Intbyte *ptr, Bytecount n) | 572 validate_ibyte_string_backward (const Ibyte *ptr, Bytecount n) |
573 ) | 573 ) |
574 { | 574 { |
575 const Intbyte *ptr2; | 575 const Ibyte *ptr2; |
576 | 576 |
577 if (n == 0) | 577 if (n == 0) |
578 return n; | 578 return n; |
579 ptr2 = ptr + n - 1; | 579 ptr2 = ptr + n - 1; |
580 VALIDATE_CHARPTR_BACKWARD (ptr2); | 580 VALIDATE_IBYTEPTR_BACKWARD (ptr2); |
581 if (ptr2 + rep_bytes_by_first_byte (*ptr2) != ptr + n) | 581 if (ptr2 + rep_bytes_by_first_byte (*ptr2) != ptr + n) |
582 return ptr2 - ptr; | 582 return ptr2 - ptr; |
583 return n; | 583 return n; |
584 } | 584 } |
585 | 585 |
586 #else | 586 #else |
587 | 587 |
588 #define validate_intbyte_string_backward(ptr, n) (n) | 588 #define validate_ibyte_string_backward(ptr, n) (n) |
589 | 589 |
590 #endif /* MULE */ | 590 #endif /* MULE */ |
591 | 591 |
592 /* -------------------------------------------------------------- */ | 592 /* -------------------------------------------------------------- */ |
593 /* Working with the length (in bytes and characters) of a */ | 593 /* Working with the length (in bytes and characters) of a */ |
594 /* section of internally-formatted text */ | 594 /* section of internally-formatted text */ |
595 /* -------------------------------------------------------------- */ | 595 /* -------------------------------------------------------------- */ |
596 | 596 |
597 #ifdef MULE | 597 #ifdef MULE |
598 | 598 |
599 Charcount bytecount_to_charcount_fun (const Intbyte *ptr, Bytecount len); | 599 Charcount bytecount_to_charcount_fun (const Ibyte *ptr, Bytecount len); |
600 Bytecount charcount_to_bytecount_fun (const Intbyte *ptr, Charcount len); | 600 Bytecount charcount_to_bytecount_fun (const Ibyte *ptr, Charcount len); |
601 | 601 |
602 /* Given a pointer to a text string and a length in bytes, return | 602 /* Given a pointer to a text string and a length in bytes, return |
603 the equivalent length in characters. */ | 603 the equivalent length in characters. */ |
604 | 604 |
605 DECLARE_INLINE_HEADER ( | 605 DECLARE_INLINE_HEADER ( |
606 Charcount | 606 Charcount |
607 bytecount_to_charcount (const Intbyte *ptr, Bytecount len) | 607 bytecount_to_charcount (const Ibyte *ptr, Bytecount len) |
608 ) | 608 ) |
609 { | 609 { |
610 if (len < 20) /* Just a random guess, but it should be more or less correct. | 610 if (len < 20) /* Just a random guess, but it should be more or less correct. |
611 If number of bytes is small, just do a simple loop, | 611 If number of bytes is small, just do a simple loop, |
612 which should be more efficient. */ | 612 which should be more efficient. */ |
613 { | 613 { |
614 Charcount count = 0; | 614 Charcount count = 0; |
615 const Intbyte *end = ptr + len; | 615 const Ibyte *end = ptr + len; |
616 while (ptr < end) | 616 while (ptr < end) |
617 { | 617 { |
618 INC_CHARPTR (ptr); | 618 INC_IBYTEPTR (ptr); |
619 count++; | 619 count++; |
620 } | 620 } |
621 /* Bomb out if the specified substring ends in the middle | 621 /* Bomb out if the specified substring ends in the middle |
622 of a character. Note that we might have already gotten | 622 of a character. Note that we might have already gotten |
623 a core dump above from an invalid reference, but at least | 623 a core dump above from an invalid reference, but at least |
636 equivalent length in bytes. | 636 equivalent length in bytes. |
637 */ | 637 */ |
638 | 638 |
639 DECLARE_INLINE_HEADER ( | 639 DECLARE_INLINE_HEADER ( |
640 Bytecount | 640 Bytecount |
641 charcount_to_bytecount (const Intbyte *ptr, Charcount len) | 641 charcount_to_bytecount (const Ibyte *ptr, Charcount len) |
642 ) | 642 ) |
643 { | 643 { |
644 text_checking_assert (len >= 0); | 644 text_checking_assert (len >= 0); |
645 if (len < 20) /* See above */ | 645 if (len < 20) /* See above */ |
646 { | 646 { |
647 const Intbyte *newptr = ptr; | 647 const Ibyte *newptr = ptr; |
648 while (len > 0) | 648 while (len > 0) |
649 { | 649 { |
650 INC_CHARPTR (newptr); | 650 INC_IBYTEPTR (newptr); |
651 len--; | 651 len--; |
652 } | 652 } |
653 return newptr - ptr; | 653 return newptr - ptr; |
654 } | 654 } |
655 else | 655 else |
660 bytes, return the equivalent length in characters. | 660 bytes, return the equivalent length in characters. |
661 */ | 661 */ |
662 | 662 |
663 DECLARE_INLINE_HEADER ( | 663 DECLARE_INLINE_HEADER ( |
664 Charcount | 664 Charcount |
665 bytecount_to_charcount_fmt (const Intbyte *ptr, Bytecount len, | 665 bytecount_to_charcount_fmt (const Ibyte *ptr, Bytecount len, |
666 Internal_Format fmt) | 666 Internal_Format fmt) |
667 ) | 667 ) |
668 { | 668 { |
669 switch (fmt) | 669 switch (fmt) |
670 { | 670 { |
686 characters, return the equivalent length in bytes. | 686 characters, return the equivalent length in bytes. |
687 */ | 687 */ |
688 | 688 |
689 DECLARE_INLINE_HEADER ( | 689 DECLARE_INLINE_HEADER ( |
690 Bytecount | 690 Bytecount |
691 charcount_to_bytecount_fmt (const Intbyte *ptr, Charcount len, | 691 charcount_to_bytecount_fmt (const Ibyte *ptr, Charcount len, |
692 Internal_Format fmt) | 692 Internal_Format fmt) |
693 ) | 693 ) |
694 { | 694 { |
695 switch (fmt) | 695 switch (fmt) |
696 { | 696 { |
726 should really optimize charcount_to_bytecount (ptr, 1) to the same as | 726 should really optimize charcount_to_bytecount (ptr, 1) to the same as |
727 the following, with no error checking. But since this idiom occurs so | 727 the following, with no error checking. But since this idiom occurs so |
728 often, we'll be helpful and define a special macro for it.] | 728 often, we'll be helpful and define a special macro for it.] |
729 */ | 729 */ |
730 | 730 |
731 #define charptr_emchar_len(ptr) rep_bytes_by_first_byte (*(ptr)) | 731 #define itext_ichar_len(ptr) rep_bytes_by_first_byte (*(ptr)) |
732 | 732 |
733 /* Return the length of the first character at PTR, which is in the | 733 /* Return the length of the first character at PTR, which is in the |
734 specified internal format. Equivalent to charcount_to_bytecount_fmt | 734 specified internal format. Equivalent to charcount_to_bytecount_fmt |
735 (ptr, 1, fmt). | 735 (ptr, 1, fmt). |
736 */ | 736 */ |
737 | 737 |
738 DECLARE_INLINE_HEADER ( | 738 DECLARE_INLINE_HEADER ( |
739 Bytecount | 739 Bytecount |
740 charptr_emchar_len_fmt (const Intbyte *ptr, Internal_Format fmt) | 740 itext_ichar_len_fmt (const Ibyte *ptr, Internal_Format fmt) |
741 ) | 741 ) |
742 { | 742 { |
743 switch (fmt) | 743 switch (fmt) |
744 { | 744 { |
745 case FORMAT_DEFAULT: | 745 case FORMAT_DEFAULT: |
746 return charptr_emchar_len (ptr); | 746 return itext_ichar_len (ptr); |
747 case FORMAT_16_BIT_FIXED: | 747 case FORMAT_16_BIT_FIXED: |
748 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); | 748 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); |
749 return 2; | 749 return 2; |
750 case FORMAT_32_BIT_FIXED: | 750 case FORMAT_32_BIT_FIXED: |
751 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); | 751 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); |
759 /* Return a pointer to the beginning of the character offset N (in | 759 /* Return a pointer to the beginning of the character offset N (in |
760 characters) from PTR. | 760 characters) from PTR. |
761 */ | 761 */ |
762 | 762 |
763 DECLARE_INLINE_HEADER ( | 763 DECLARE_INLINE_HEADER ( |
764 const Intbyte * | 764 const Ibyte * |
765 charptr_n_addr (const Intbyte *ptr, Charcount offset) | 765 itext_n_addr (const Ibyte *ptr, Charcount offset) |
766 ) | 766 ) |
767 { | 767 { |
768 return ptr + charcount_to_bytecount (ptr, offset); | 768 return ptr + charcount_to_bytecount (ptr, offset); |
769 } | 769 } |
770 | 770 |
771 /* Given a charptr and an offset into the text pointed to by the charptr, | 771 /* Given a itext and an offset into the text pointed to by the itext, |
772 modify the offset so it points to the beginning of the next character. | 772 modify the offset so it points to the beginning of the next character. |
773 */ | 773 */ |
774 | 774 |
775 #define INC_BYTECOUNT(ptr, pos) do { \ | 775 #define INC_BYTECOUNT(ptr, pos) do { \ |
776 assert_valid_charptr (ptr); \ | 776 assert_valid_ibyteptr (ptr); \ |
777 (pos += rep_bytes_by_first_byte (* ((ptr) + (pos)))); \ | 777 (pos += rep_bytes_by_first_byte (* ((ptr) + (pos)))); \ |
778 } while (0) | 778 } while (0) |
779 | 779 |
780 /* -------------------------------------------------------------------- */ | 780 /* -------------------------------------------------------------------- */ |
781 /* Retrieving or changing the character pointed to by a charptr */ | 781 /* Retrieving or changing the character pointed to by a itext */ |
782 /* -------------------------------------------------------------------- */ | 782 /* -------------------------------------------------------------------- */ |
783 | 783 |
784 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0]) | 784 #define simple_itext_ichar(ptr) ((Ichar) (ptr)[0]) |
785 #define simple_set_charptr_emchar(ptr, x) \ | 785 #define simple_set_itext_ichar(ptr, x) \ |
786 ((ptr)[0] = (Intbyte) (x), (Bytecount) 1) | 786 ((ptr)[0] = (Ibyte) (x), (Bytecount) 1) |
787 #define simple_charptr_copy_emchar(src, dst) \ | 787 #define simple_itext_copy_ichar(src, dst) \ |
788 ((dst)[0] = *(src), (Bytecount) 1) | 788 ((dst)[0] = *(src), (Bytecount) 1) |
789 | 789 |
790 #ifdef MULE | 790 #ifdef MULE |
791 | 791 |
792 Emchar non_ascii_charptr_emchar (const Intbyte *ptr); | 792 Ichar non_ascii_itext_ichar (const Ibyte *ptr); |
793 Bytecount non_ascii_set_charptr_emchar (Intbyte *ptr, Emchar c); | 793 Bytecount non_ascii_set_itext_ichar (Ibyte *ptr, Ichar c); |
794 Bytecount non_ascii_charptr_copy_emchar (const Intbyte *src, Intbyte *dst); | 794 Bytecount non_ascii_itext_copy_ichar (const Ibyte *src, Ibyte *dst); |
795 | 795 |
796 /* Retrieve the character pointed to by PTR as an Emchar. */ | 796 /* Retrieve the character pointed to by PTR as an Ichar. */ |
797 | 797 |
798 DECLARE_INLINE_HEADER ( | 798 DECLARE_INLINE_HEADER ( |
799 Emchar | 799 Ichar |
800 charptr_emchar (const Intbyte *ptr) | 800 itext_ichar (const Ibyte *ptr) |
801 ) | 801 ) |
802 { | 802 { |
803 return byte_ascii_p (*ptr) ? | 803 return byte_ascii_p (*ptr) ? |
804 simple_charptr_emchar (ptr) : | 804 simple_itext_ichar (ptr) : |
805 non_ascii_charptr_emchar (ptr); | 805 non_ascii_itext_ichar (ptr); |
806 } | 806 } |
807 | 807 |
808 /* Retrieve the character pointed to by PTR (a pointer to text in the | 808 /* Retrieve the character pointed to by PTR (a pointer to text in the |
809 format FMT, coming from OBJECT [a buffer, string?, or nil]) as an | 809 format FMT, coming from OBJECT [a buffer, string?, or nil]) as an |
810 Emchar. | 810 Ichar. |
811 | 811 |
812 Note: For these and other *_fmt() functions, if you pass in a constant | 812 Note: For these and other *_fmt() functions, if you pass in a constant |
813 FMT, the switch will be optimized out of existence. Therefore, there is | 813 FMT, the switch will be optimized out of existence. Therefore, there is |
814 no need to create separate versions for the various formats for | 814 no need to create separate versions for the various formats for |
815 "efficiency reasons". In fact, we don't really need charptr_emchar() | 815 "efficiency reasons". In fact, we don't really need itext_ichar() |
816 and such written separately, but they are used often so it's simpler | 816 and such written separately, but they are used often so it's simpler |
817 that way. */ | 817 that way. */ |
818 | 818 |
819 DECLARE_INLINE_HEADER ( | 819 DECLARE_INLINE_HEADER ( |
820 Emchar | 820 Ichar |
821 charptr_emchar_fmt (const Intbyte *ptr, Internal_Format fmt, | 821 itext_ichar_fmt (const Ibyte *ptr, Internal_Format fmt, |
822 Lisp_Object object) | 822 Lisp_Object object) |
823 ) | 823 ) |
824 { | 824 { |
825 switch (fmt) | 825 switch (fmt) |
826 { | 826 { |
827 case FORMAT_DEFAULT: | 827 case FORMAT_DEFAULT: |
828 return charptr_emchar (ptr); | 828 return itext_ichar (ptr); |
829 case FORMAT_16_BIT_FIXED: | 829 case FORMAT_16_BIT_FIXED: |
830 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); | 830 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); |
831 return raw_16_bit_fixed_to_emchar (* (UINT_16_BIT *) ptr, object); | 831 return raw_16_bit_fixed_to_ichar (* (UINT_16_BIT *) ptr, object); |
832 case FORMAT_32_BIT_FIXED: | 832 case FORMAT_32_BIT_FIXED: |
833 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); | 833 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); |
834 return raw_32_bit_fixed_to_emchar (* (UINT_32_BIT *) ptr, object); | 834 return raw_32_bit_fixed_to_ichar (* (UINT_32_BIT *) ptr, object); |
835 default: | 835 default: |
836 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); | 836 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); |
837 return raw_8_bit_fixed_to_emchar (*ptr, object); | 837 return raw_8_bit_fixed_to_ichar (*ptr, object); |
838 } | 838 } |
839 } | 839 } |
840 | 840 |
841 /* Return the character at PTR (which is in format FMT), suitable for | 841 /* Return the character at PTR (which is in format FMT), suitable for |
842 comparison with an ASCII character. This guarantees that if the | 842 comparison with an ASCII character. This guarantees that if the |
843 character at PTR is ASCII (range 0 - 127), that character will be | 843 character at PTR is ASCII (range 0 - 127), that character will be |
844 returned; otherwise, some character outside of the ASCII range will be | 844 returned; otherwise, some character outside of the ASCII range will be |
845 returned, but not necessarily the character actually at PTR. This will | 845 returned, but not necessarily the character actually at PTR. This will |
846 be faster than charptr_emchar_fmt() for some formats -- in particular, | 846 be faster than itext_ichar_fmt() for some formats -- in particular, |
847 FORMAT_DEFAULT. */ | 847 FORMAT_DEFAULT. */ |
848 | 848 |
849 DECLARE_INLINE_HEADER ( | 849 DECLARE_INLINE_HEADER ( |
850 Emchar | 850 Ichar |
851 charptr_emchar_ascii_fmt (const Intbyte *ptr, Internal_Format fmt, | 851 itext_ichar_ascii_fmt (const Ibyte *ptr, Internal_Format fmt, |
852 Lisp_Object object) | 852 Lisp_Object object) |
853 ) | 853 ) |
854 { | 854 { |
855 switch (fmt) | 855 switch (fmt) |
856 { | 856 { |
857 case FORMAT_DEFAULT: | 857 case FORMAT_DEFAULT: |
858 return (Emchar) *ptr; | 858 return (Ichar) *ptr; |
859 case FORMAT_16_BIT_FIXED: | 859 case FORMAT_16_BIT_FIXED: |
860 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); | 860 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); |
861 return raw_16_bit_fixed_to_emchar (* (UINT_16_BIT *) ptr, object); | 861 return raw_16_bit_fixed_to_ichar (* (UINT_16_BIT *) ptr, object); |
862 case FORMAT_32_BIT_FIXED: | 862 case FORMAT_32_BIT_FIXED: |
863 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); | 863 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); |
864 return raw_32_bit_fixed_to_emchar (* (UINT_32_BIT *) ptr, object); | 864 return raw_32_bit_fixed_to_ichar (* (UINT_32_BIT *) ptr, object); |
865 default: | 865 default: |
866 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); | 866 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); |
867 return raw_8_bit_fixed_to_emchar (*ptr, object); | 867 return raw_8_bit_fixed_to_ichar (*ptr, object); |
868 } | 868 } |
869 } | 869 } |
870 | 870 |
871 /* Return the "raw value" of the character at PTR, in format FMT. This is | 871 /* Return the "raw value" of the character at PTR, in format FMT. This is |
872 useful when searching for a character; convert the character using | 872 useful when searching for a character; convert the character using |
873 emchar_to_raw(). */ | 873 ichar_to_raw(). */ |
874 | 874 |
875 DECLARE_INLINE_HEADER ( | 875 DECLARE_INLINE_HEADER ( |
876 Raw_Emchar | 876 Raw_Ichar |
877 charptr_emchar_raw_fmt (const Intbyte *ptr, Internal_Format fmt) | 877 itext_ichar_raw_fmt (const Ibyte *ptr, Internal_Format fmt) |
878 ) | 878 ) |
879 { | 879 { |
880 switch (fmt) | 880 switch (fmt) |
881 { | 881 { |
882 case FORMAT_DEFAULT: | 882 case FORMAT_DEFAULT: |
883 return (Raw_Emchar) charptr_emchar (ptr); | 883 return (Raw_Ichar) itext_ichar (ptr); |
884 case FORMAT_16_BIT_FIXED: | 884 case FORMAT_16_BIT_FIXED: |
885 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); | 885 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); |
886 return (Raw_Emchar) (* (UINT_16_BIT *) ptr); | 886 return (Raw_Ichar) (* (UINT_16_BIT *) ptr); |
887 case FORMAT_32_BIT_FIXED: | 887 case FORMAT_32_BIT_FIXED: |
888 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); | 888 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); |
889 return (Raw_Emchar) (* (UINT_32_BIT *) ptr); | 889 return (Raw_Ichar) (* (UINT_32_BIT *) ptr); |
890 default: | 890 default: |
891 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); | 891 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); |
892 return (Raw_Emchar) (*ptr); | 892 return (Raw_Ichar) (*ptr); |
893 } | 893 } |
894 } | 894 } |
895 | 895 |
896 /* Store the character CH (an Emchar) as internally-formatted text starting | 896 /* Store the character CH (an Ichar) as internally-formatted text starting |
897 at PTR. Return the number of bytes stored. | 897 at PTR. Return the number of bytes stored. |
898 */ | 898 */ |
899 | 899 |
900 DECLARE_INLINE_HEADER ( | 900 DECLARE_INLINE_HEADER ( |
901 Bytecount | 901 Bytecount |
902 set_charptr_emchar (Intbyte *ptr, Emchar x) | 902 set_itext_ichar (Ibyte *ptr, Ichar x) |
903 ) | 903 ) |
904 { | 904 { |
905 return !emchar_multibyte_p (x) ? | 905 return !ichar_multibyte_p (x) ? |
906 simple_set_charptr_emchar (ptr, x) : | 906 simple_set_itext_ichar (ptr, x) : |
907 non_ascii_set_charptr_emchar (ptr, x); | 907 non_ascii_set_itext_ichar (ptr, x); |
908 } | 908 } |
909 | 909 |
910 /* Store the character CH (an Emchar) as internally-formatted text of | 910 /* Store the character CH (an Ichar) as internally-formatted text of |
911 format FMT starting at PTR, which comes from OBJECT. Return the number | 911 format FMT starting at PTR, which comes from OBJECT. Return the number |
912 of bytes stored. | 912 of bytes stored. |
913 */ | 913 */ |
914 | 914 |
915 DECLARE_INLINE_HEADER ( | 915 DECLARE_INLINE_HEADER ( |
916 Bytecount | 916 Bytecount |
917 set_charptr_emchar_fmt (Intbyte *ptr, Emchar x, Internal_Format fmt, | 917 set_itext_ichar_fmt (Ibyte *ptr, Ichar x, Internal_Format fmt, |
918 Lisp_Object object) | 918 Lisp_Object object) |
919 ) | 919 ) |
920 { | 920 { |
921 switch (fmt) | 921 switch (fmt) |
922 { | 922 { |
923 case FORMAT_DEFAULT: | 923 case FORMAT_DEFAULT: |
924 return set_charptr_emchar (ptr, x); | 924 return set_itext_ichar (ptr, x); |
925 case FORMAT_16_BIT_FIXED: | 925 case FORMAT_16_BIT_FIXED: |
926 text_checking_assert (emchar_16_bit_fixed_p (x, object)); | 926 text_checking_assert (ichar_16_bit_fixed_p (x, object)); |
927 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); | 927 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_16_BIT)); |
928 * (UINT_16_BIT *) ptr = emchar_to_raw_16_bit_fixed (x, object); | 928 * (UINT_16_BIT *) ptr = ichar_to_raw_16_bit_fixed (x, object); |
929 return 2; | 929 return 2; |
930 case FORMAT_32_BIT_FIXED: | 930 case FORMAT_32_BIT_FIXED: |
931 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); | 931 text_checking_assert (ptr == ALIGN_PTR (ptr, UINT_32_BIT)); |
932 * (UINT_32_BIT *) ptr = emchar_to_raw_32_bit_fixed (x, object); | 932 * (UINT_32_BIT *) ptr = ichar_to_raw_32_bit_fixed (x, object); |
933 return 4; | 933 return 4; |
934 default: | 934 default: |
935 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); | 935 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); |
936 text_checking_assert (emchar_8_bit_fixed_p (x, object)); | 936 text_checking_assert (ichar_8_bit_fixed_p (x, object)); |
937 *ptr = emchar_to_raw_8_bit_fixed (x, object); | 937 *ptr = ichar_to_raw_8_bit_fixed (x, object); |
938 return 1; | 938 return 1; |
939 } | 939 } |
940 } | 940 } |
941 | 941 |
942 /* Retrieve the character pointed to by SRC and store it as | 942 /* Retrieve the character pointed to by SRC and store it as |
943 internally-formatted text in DST. | 943 internally-formatted text in DST. |
944 */ | 944 */ |
945 | 945 |
946 DECLARE_INLINE_HEADER ( | 946 DECLARE_INLINE_HEADER ( |
947 Bytecount | 947 Bytecount |
948 charptr_copy_emchar (const Intbyte *src, Intbyte *dst) | 948 itext_copy_ichar (const Ibyte *src, Ibyte *dst) |
949 ) | 949 ) |
950 { | 950 { |
951 return byte_ascii_p (*src) ? | 951 return byte_ascii_p (*src) ? |
952 simple_charptr_copy_emchar (src, dst) : | 952 simple_itext_copy_ichar (src, dst) : |
953 non_ascii_charptr_copy_emchar (src, dst); | 953 non_ascii_itext_copy_ichar (src, dst); |
954 } | 954 } |
955 | 955 |
956 #else /* not MULE */ | 956 #else /* not MULE */ |
957 | 957 |
958 # define charptr_emchar(ptr) simple_charptr_emchar (ptr) | 958 # define itext_ichar(ptr) simple_itext_ichar (ptr) |
959 # define charptr_emchar_fmt(ptr, fmt, object) charptr_emchar (ptr) | 959 # define itext_ichar_fmt(ptr, fmt, object) itext_ichar (ptr) |
960 # define charptr_emchar_ascii_fmt(ptr, fmt, object) charptr_emchar (ptr) | 960 # define itext_ichar_ascii_fmt(ptr, fmt, object) itext_ichar (ptr) |
961 # define charptr_emchar_raw_fmt(ptr, fmt) charptr_emchar (ptr) | 961 # define itext_ichar_raw_fmt(ptr, fmt) itext_ichar (ptr) |
962 # define set_charptr_emchar(ptr, x) simple_set_charptr_emchar (ptr, x) | 962 # define set_itext_ichar(ptr, x) simple_set_itext_ichar (ptr, x) |
963 # define set_charptr_emchar_fmt(ptr, x, fmt, obj) set_charptr_emchar (ptr, x) | 963 # define set_itext_ichar_fmt(ptr, x, fmt, obj) set_itext_ichar (ptr, x) |
964 # define charptr_copy_emchar(src, dst) simple_charptr_copy_emchar (src, dst) | 964 # define itext_copy_ichar(src, dst) simple_itext_copy_ichar (src, dst) |
965 | 965 |
966 #endif /* not MULE */ | 966 #endif /* not MULE */ |
967 | 967 |
968 /* Retrieve the character at offset N (in characters) from PTR, as an | 968 /* Retrieve the character at offset N (in characters) from PTR, as an |
969 Emchar. | 969 Ichar. |
970 */ | 970 */ |
971 | 971 |
972 #define charptr_emchar_n(ptr, offset) \ | 972 #define itext_ichar_n(ptr, offset) \ |
973 charptr_emchar (charptr_n_addr (ptr, offset)) | 973 itext_ichar (itext_n_addr (ptr, offset)) |
974 | 974 |
975 | 975 |
976 /* ---------------------------- */ | 976 /* ---------------------------- */ |
977 /* Working with Emchars */ | 977 /* Working with Ichars */ |
978 /* ---------------------------- */ | 978 /* ---------------------------- */ |
979 | 979 |
980 /* NOTE: There are other functions/macros for working with Emchars in | 980 /* NOTE: There are other functions/macros for working with Ichars in |
981 charset.h, for retrieving the charset of an Emchar, the length of an | 981 charset.h, for retrieving the charset of an Ichar, the length of an |
982 Emchar when converted to text, etc. | 982 Ichar when converted to text, etc. |
983 */ | 983 */ |
984 | 984 |
985 #ifdef MULE | 985 #ifdef MULE |
986 | 986 |
987 int non_ascii_valid_emchar_p (Emchar ch); | 987 int non_ascii_valid_ichar_p (Ichar ch); |
988 | 988 |
989 /* Return whether the given Emchar is valid. | 989 /* Return whether the given Ichar is valid. |
990 */ | 990 */ |
991 | 991 |
992 DECLARE_INLINE_HEADER ( | 992 DECLARE_INLINE_HEADER ( |
993 int | 993 int |
994 valid_emchar_p (Emchar ch) | 994 valid_ichar_p (Ichar ch) |
995 ) | 995 ) |
996 { | 996 { |
997 return (! (ch & ~0xFF)) || non_ascii_valid_emchar_p (ch); | 997 return (! (ch & ~0xFF)) || non_ascii_valid_ichar_p (ch); |
998 } | 998 } |
999 | 999 |
1000 #else /* not MULE */ | 1000 #else /* not MULE */ |
1001 | 1001 |
1002 #define valid_emchar_p(ch) (! (ch & ~0xFF)) | 1002 #define valid_ichar_p(ch) (! (ch & ~0xFF)) |
1003 | 1003 |
1004 #endif /* not MULE */ | 1004 #endif /* not MULE */ |
1005 | 1005 |
1006 DECLARE_INLINE_HEADER ( | 1006 DECLARE_INLINE_HEADER ( |
1007 Lisp_Object | 1007 Lisp_Object |
1008 make_char (Emchar val) | 1008 make_char (Ichar val) |
1009 ) | 1009 ) |
1010 { | 1010 { |
1011 type_checking_assert (valid_emchar_p (val)); | 1011 type_checking_assert (valid_ichar_p (val)); |
1012 return make_char_1 (val); | 1012 return make_char_1 (val); |
1013 } | 1013 } |
1014 | 1014 |
1015 #define CHAR_INTP(x) (INTP (x) && valid_emchar_p (XINT (x))) | 1015 #define CHAR_INTP(x) (INTP (x) && valid_ichar_p (XINT (x))) |
1016 | 1016 |
1017 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x)) | 1017 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x)) |
1018 | 1018 |
1019 DECLARE_INLINE_HEADER ( | 1019 DECLARE_INLINE_HEADER ( |
1020 Emchar | 1020 Ichar |
1021 XCHAR_OR_CHAR_INT (Lisp_Object obj) | 1021 XCHAR_OR_CHAR_INT (Lisp_Object obj) |
1022 ) | 1022 ) |
1023 { | 1023 { |
1024 return CHARP (obj) ? XCHAR (obj) : XINT (obj); | 1024 return CHARP (obj) ? XCHAR (obj) : XINT (obj); |
1025 } | 1025 } |
1056 text_checking_assert ((x) >= 0 && x <= string_char_length (s)); \ | 1056 text_checking_assert ((x) >= 0 && x <= string_char_length (s)); \ |
1057 } while (0) | 1057 } while (0) |
1058 | 1058 |
1059 #define ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE(s, x) do { \ | 1059 #define ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE(s, x) do { \ |
1060 text_checking_assert ((x) >= 0 && x <= XSTRING_LENGTH (s)); \ | 1060 text_checking_assert ((x) >= 0 && x <= XSTRING_LENGTH (s)); \ |
1061 text_checking_assert (valid_charptr_p (string_byte_addr (s, x))); \ | 1061 text_checking_assert (valid_ibyteptr_p (string_byte_addr (s, x))); \ |
1062 } while (0) | 1062 } while (0) |
1063 | 1063 |
1064 /* Convert offset I in string S to a pointer to text there. */ | 1064 /* Convert offset I in string S to a pointer to text there. */ |
1065 #define string_byte_addr(s, i) (&(XSTRING_DATA (s)[i])) | 1065 #define string_byte_addr(s, i) (&(XSTRING_DATA (s)[i])) |
1066 /* Convert pointer to text in string S into the byte offset to that text. */ | 1066 /* Convert pointer to text in string S into the byte offset to that text. */ |
1067 #define string_addr_to_byte(s, ptr) ((Bytecount) ((ptr) - XSTRING_DATA (s))) | 1067 #define string_addr_to_byte(s, ptr) ((Bytecount) ((ptr) - XSTRING_DATA (s))) |
1068 /* Return the Emchar at *CHARACTER* offset I. */ | 1068 /* Return the Ichar at *CHARACTER* offset I. */ |
1069 #define string_emchar(s, i) charptr_emchar (string_char_addr (s, i)) | 1069 #define string_ichar(s, i) itext_ichar (string_char_addr (s, i)) |
1070 | 1070 |
1071 #ifdef ERROR_CHECK_TEXT | 1071 #ifdef ERROR_CHECK_TEXT |
1072 #define SLEDGEHAMMER_CHECK_ASCII_BEGIN | 1072 #define SLEDGEHAMMER_CHECK_ASCII_BEGIN |
1073 #endif | 1073 #endif |
1074 | 1074 |
1079 #endif | 1079 #endif |
1080 | 1080 |
1081 /* Make an alloca'd copy of a Lisp string */ | 1081 /* Make an alloca'd copy of a Lisp string */ |
1082 #define LISP_STRING_TO_ALLOCA(s, lval) \ | 1082 #define LISP_STRING_TO_ALLOCA(s, lval) \ |
1083 do { \ | 1083 do { \ |
1084 Intbyte **_lta_ = (Intbyte **) &(lval); \ | 1084 Ibyte **_lta_ = (Ibyte **) &(lval); \ |
1085 Lisp_Object _lta_2 = (s); \ | 1085 Lisp_Object _lta_2 = (s); \ |
1086 *_lta_ = alloca_array (Intbyte, 1 + XSTRING_LENGTH (_lta_2)); \ | 1086 *_lta_ = alloca_array (Ibyte, 1 + XSTRING_LENGTH (_lta_2)); \ |
1087 memcpy (*_lta_, XSTRING_DATA (_lta_2), 1 + XSTRING_LENGTH (_lta_2)); \ | 1087 memcpy (*_lta_, XSTRING_DATA (_lta_2), 1 + XSTRING_LENGTH (_lta_2)); \ |
1088 } while (0) | 1088 } while (0) |
1089 | 1089 |
1090 /* Make an alloca'd copy of a Intbyte * */ | 1090 /* Make an alloca'd copy of a Ibyte * */ |
1091 #define INTBYTE_STRING_TO_ALLOCA(p, lval) \ | 1091 #define IBYTE_STRING_TO_ALLOCA(p, lval) \ |
1092 do { \ | 1092 do { \ |
1093 Intbyte **_bsta_ = (Intbyte **) &(lval); \ | 1093 Ibyte **_bsta_ = (Ibyte **) &(lval); \ |
1094 const Intbyte *_bsta_2 = (p); \ | 1094 const Ibyte *_bsta_2 = (p); \ |
1095 Bytecount _bsta_3 = qxestrlen (_bsta_2); \ | 1095 Bytecount _bsta_3 = qxestrlen (_bsta_2); \ |
1096 *_bsta_ = alloca_array (Intbyte, 1 + _bsta_3); \ | 1096 *_bsta_ = alloca_array (Ibyte, 1 + _bsta_3); \ |
1097 memcpy (*_bsta_, _bsta_2, 1 + _bsta_3); \ | 1097 memcpy (*_bsta_, _bsta_2, 1 + _bsta_3); \ |
1098 } while (0) | 1098 } while (0) |
1099 | 1099 |
1100 | 1100 |
1101 #define alloca_intbytes(num) alloca_array (Intbyte, num) | 1101 #define alloca_ibytes(num) alloca_array (Ibyte, num) |
1102 #define alloca_extbytes(num) alloca_array (Extbyte, num) | 1102 #define alloca_extbytes(num) alloca_array (Extbyte, num) |
1103 | 1103 |
1104 void resize_string (Lisp_Object s, Bytecount pos, Bytecount delta); | 1104 void resize_string (Lisp_Object s, Bytecount pos, Bytecount delta); |
1105 | 1105 |
1106 /* Convert a byte index into a string into a char index. */ | 1106 /* Convert a byte index into a string into a char index. */ |
1216 ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE (s, off + retval); | 1216 ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE (s, off + retval); |
1217 return retval; | 1217 return retval; |
1218 } | 1218 } |
1219 | 1219 |
1220 DECLARE_INLINE_HEADER ( | 1220 DECLARE_INLINE_HEADER ( |
1221 const Intbyte * | 1221 const Ibyte * |
1222 string_char_addr (Lisp_Object s, Charcount idx) | 1222 string_char_addr (Lisp_Object s, Charcount idx) |
1223 ) | 1223 ) |
1224 { | 1224 { |
1225 return XSTRING_DATA (s) + string_index_char_to_byte (s, idx); | 1225 return XSTRING_DATA (s) + string_index_char_to_byte (s, idx); |
1226 } | 1226 } |
1227 | 1227 |
1228 /* WARNING: If you modify an existing string, you must call | 1228 /* WARNING: If you modify an existing string, you must call |
1229 bump_string_modiff() afterwards. */ | 1229 bump_string_modiff() afterwards. */ |
1230 #ifdef MULE | 1230 #ifdef MULE |
1231 void set_string_char (Lisp_Object s, Charcount i, Emchar c); | 1231 void set_string_char (Lisp_Object s, Charcount i, Ichar c); |
1232 #else | 1232 #else |
1233 #define set_string_char(s, i, c) set_string_byte (s, i, c) | 1233 #define set_string_char(s, i, c) set_string_byte (s, i, c) |
1234 #endif /* not MULE */ | 1234 #endif /* not MULE */ |
1235 | 1235 |
1236 /* Return index to character before the one at IDX. */ | 1236 /* Return index to character before the one at IDX. */ |
1237 DECLARE_INLINE_HEADER ( | 1237 DECLARE_INLINE_HEADER ( |
1238 Bytecount | 1238 Bytecount |
1239 prev_string_index (Lisp_Object s, Bytecount idx) | 1239 prev_string_index (Lisp_Object s, Bytecount idx) |
1240 ) | 1240 ) |
1241 { | 1241 { |
1242 const Intbyte *ptr = string_byte_addr (s, idx); | 1242 const Ibyte *ptr = string_byte_addr (s, idx); |
1243 DEC_CHARPTR (ptr); | 1243 DEC_IBYTEPTR (ptr); |
1244 return string_addr_to_byte (s, ptr); | 1244 return string_addr_to_byte (s, ptr); |
1245 } | 1245 } |
1246 | 1246 |
1247 /* Return index to character after the one at IDX. */ | 1247 /* Return index to character after the one at IDX. */ |
1248 DECLARE_INLINE_HEADER ( | 1248 DECLARE_INLINE_HEADER ( |
1249 Bytecount | 1249 Bytecount |
1250 next_string_index (Lisp_Object s, Bytecount idx) | 1250 next_string_index (Lisp_Object s, Bytecount idx) |
1251 ) | 1251 ) |
1252 { | 1252 { |
1253 const Intbyte *ptr = string_byte_addr (s, idx); | 1253 const Ibyte *ptr = string_byte_addr (s, idx); |
1254 INC_CHARPTR (ptr); | 1254 INC_IBYTEPTR (ptr); |
1255 return string_addr_to_byte (s, ptr); | 1255 return string_addr_to_byte (s, ptr); |
1256 } | 1256 } |
1257 | 1257 |
1258 | 1258 |
1259 /************************************************************************/ | 1259 /************************************************************************/ |
1279 (d) it knows its own length, so it does not suffer from standard null | 1279 (d) it knows its own length, so it does not suffer from standard null |
1280 byte brain-damage -- but it null-terminates the data anyway, so | 1280 byte brain-damage -- but it null-terminates the data anyway, so |
1281 it can be passed to standard routines | 1281 it can be passed to standard routines |
1282 (e) it provides a much more powerful set of operations and knows about | 1282 (e) it provides a much more powerful set of operations and knows about |
1283 all the standard places where string data might reside: Lisp_Objects, | 1283 all the standard places where string data might reside: Lisp_Objects, |
1284 other Eistrings, Intbyte * data with or without an explicit length, | 1284 other Eistrings, Ibyte * data with or without an explicit length, |
1285 ASCII strings, Emchars, etc. | 1285 ASCII strings, Ichars, etc. |
1286 (f) it provides easy operations to convert to/from externally-formatted | 1286 (f) it provides easy operations to convert to/from externally-formatted |
1287 data, and is easier to use than the standard TO_INTERNAL_FORMAT | 1287 data, and is easier to use than the standard TO_INTERNAL_FORMAT |
1288 and TO_EXTERNAL_FORMAT macros. (An Eistring can store both the internal | 1288 and TO_EXTERNAL_FORMAT macros. (An Eistring can store both the internal |
1289 and external version of its data, but the external version is only | 1289 and external version of its data, but the external version is only |
1290 initialized or changed when you call eito_external().) | 1290 initialized or changed when you call eito_external().) |
1366 | 1366 |
1367 void eicpy_ei (Eistring *eistr, Eistring *eistr2); | 1367 void eicpy_ei (Eistring *eistr, Eistring *eistr2); |
1368 ... from another Eistring. | 1368 ... from another Eistring. |
1369 void eicpy_lstr (Eistring *eistr, Lisp_Object lisp_string); | 1369 void eicpy_lstr (Eistring *eistr, Lisp_Object lisp_string); |
1370 ... from a Lisp_Object string. | 1370 ... from a Lisp_Object string. |
1371 void eicpy_ch (Eistring *eistr, Emchar ch); | 1371 void eicpy_ch (Eistring *eistr, Ichar ch); |
1372 ... from an Emchar (this can be a conventional C character). | 1372 ... from an Ichar (this can be a conventional C character). |
1373 | 1373 |
1374 void eicpy_lstr_off (Eistring *eistr, Lisp_Object lisp_string, | 1374 void eicpy_lstr_off (Eistring *eistr, Lisp_Object lisp_string, |
1375 Bytecount off, Charcount charoff, | 1375 Bytecount off, Charcount charoff, |
1376 Bytecount len, Charcount charlen); | 1376 Bytecount len, Charcount charlen); |
1377 ... from a section of a Lisp_Object string. | 1377 ... from a section of a Lisp_Object string. |
1378 void eicpy_lbuf (Eistring *eistr, Lisp_Object lisp_buf, | 1378 void eicpy_lbuf (Eistring *eistr, Lisp_Object lisp_buf, |
1379 Bytecount off, Charcount charoff, | 1379 Bytecount off, Charcount charoff, |
1380 Bytecount len, Charcount charlen); | 1380 Bytecount len, Charcount charlen); |
1381 ... from a section of a Lisp_Object buffer. | 1381 ... from a section of a Lisp_Object buffer. |
1382 void eicpy_raw (Eistring *eistr, const Intbyte *data, Bytecount len); | 1382 void eicpy_raw (Eistring *eistr, const Ibyte *data, Bytecount len); |
1383 ... from raw internal-format data in the default internal format. | 1383 ... from raw internal-format data in the default internal format. |
1384 void eicpy_rawz (Eistring *eistr, const Intbyte *data); | 1384 void eicpy_rawz (Eistring *eistr, const Ibyte *data); |
1385 ... from raw internal-format data in the default internal format | 1385 ... from raw internal-format data in the default internal format |
1386 that is "null-terminated" (the meaning of this depends on the nature | 1386 that is "null-terminated" (the meaning of this depends on the nature |
1387 of the default internal format). | 1387 of the default internal format). |
1388 void eicpy_raw_fmt (Eistring *eistr, const Intbyte *data, Bytecount len, | 1388 void eicpy_raw_fmt (Eistring *eistr, const Ibyte *data, Bytecount len, |
1389 Internal_Format intfmt, Lisp_Object object); | 1389 Internal_Format intfmt, Lisp_Object object); |
1390 ... from raw internal-format data in the specified format. | 1390 ... from raw internal-format data in the specified format. |
1391 void eicpy_rawz_fmt (Eistring *eistr, const Intbyte *data, | 1391 void eicpy_rawz_fmt (Eistring *eistr, const Ibyte *data, |
1392 Internal_Format intfmt, Lisp_Object object); | 1392 Internal_Format intfmt, Lisp_Object object); |
1393 ... from raw internal-format data in the specified format that is | 1393 ... from raw internal-format data in the specified format that is |
1394 "null-terminated" (the meaning of this depends on the nature of | 1394 "null-terminated" (the meaning of this depends on the nature of |
1395 the specific format). | 1395 the specific format). |
1396 void eicpy_c (Eistring *eistr, const Char_ASCII *c_string); | 1396 void eicpy_c (Eistring *eistr, const Char_ASCII *c_string); |
1412 | 1412 |
1413 ********************************************** | 1413 ********************************************** |
1414 * Getting the data out of the Eistring * | 1414 * Getting the data out of the Eistring * |
1415 ********************************************** | 1415 ********************************************** |
1416 | 1416 |
1417 Intbyte *eidata (Eistring *eistr); | 1417 Ibyte *eidata (Eistring *eistr); |
1418 Return a pointer to the raw data in an Eistring. This is NOT | 1418 Return a pointer to the raw data in an Eistring. This is NOT |
1419 a copy. | 1419 a copy. |
1420 | 1420 |
1421 Lisp_Object eimake_string (Eistring *eistr); | 1421 Lisp_Object eimake_string (Eistring *eistr); |
1422 Make a Lisp string out of the Eistring. | 1422 Make a Lisp string out of the Eistring. |
1424 Lisp_Object eimake_string_off (Eistring *eistr, | 1424 Lisp_Object eimake_string_off (Eistring *eistr, |
1425 Bytecount off, Charcount charoff, | 1425 Bytecount off, Charcount charoff, |
1426 Bytecount len, Charcount charlen); | 1426 Bytecount len, Charcount charlen); |
1427 Make a Lisp string out of a section of the Eistring. | 1427 Make a Lisp string out of a section of the Eistring. |
1428 | 1428 |
1429 void eicpyout_alloca (Eistring *eistr, LVALUE: Intbyte *ptr_out, | 1429 void eicpyout_alloca (Eistring *eistr, LVALUE: Ibyte *ptr_out, |
1430 LVALUE: Bytecount len_out); | 1430 LVALUE: Bytecount len_out); |
1431 Make an ALLOCA() copy of the data in the Eistring, using the | 1431 Make an ALLOCA() copy of the data in the Eistring, using the |
1432 default internal format. Due to the nature of ALLOCA(), this | 1432 default internal format. Due to the nature of ALLOCA(), this |
1433 must be a macro, with all lvalues passed in as parameters. | 1433 must be a macro, with all lvalues passed in as parameters. |
1434 (More specifically, not all compilers correctly handle using | 1434 (More specifically, not all compilers correctly handle using |
1435 ALLOCA() as the argument to a function call -- GCC on x86 | 1435 ALLOCA() as the argument to a function call -- GCC on x86 |
1436 didn't used to, for example.) A pointer to the ALLOCA()ed data | 1436 didn't used to, for example.) A pointer to the ALLOCA()ed data |
1437 is stored in PTR_OUT, and the length of the data (not including | 1437 is stored in PTR_OUT, and the length of the data (not including |
1438 the terminating zero) is stored in LEN_OUT. | 1438 the terminating zero) is stored in LEN_OUT. |
1439 | 1439 |
1440 void eicpyout_alloca_fmt (Eistring *eistr, LVALUE: Intbyte *ptr_out, | 1440 void eicpyout_alloca_fmt (Eistring *eistr, LVALUE: Ibyte *ptr_out, |
1441 LVALUE: Bytecount len_out, | 1441 LVALUE: Bytecount len_out, |
1442 Internal_Format intfmt, Lisp_Object object); | 1442 Internal_Format intfmt, Lisp_Object object); |
1443 Like eicpyout_alloca(), but converts to the specified internal | 1443 Like eicpyout_alloca(), but converts to the specified internal |
1444 format. (No formats other than FORMAT_DEFAULT are currently | 1444 format. (No formats other than FORMAT_DEFAULT are currently |
1445 implemented, and you get an assertion failure if you try.) | 1445 implemented, and you get an assertion failure if you try.) |
1446 | 1446 |
1447 Intbyte *eicpyout_malloc (Eistring *eistr, Bytecount *intlen_out); | 1447 Ibyte *eicpyout_malloc (Eistring *eistr, Bytecount *intlen_out); |
1448 Make a malloc() copy of the data in the Eistring, using the | 1448 Make a malloc() copy of the data in the Eistring, using the |
1449 default internal format. This is a real function. No lvalues | 1449 default internal format. This is a real function. No lvalues |
1450 passed in. Returns the new data, and stores the length (not | 1450 passed in. Returns the new data, and stores the length (not |
1451 including the terminating zero) using INTLEN_OUT, unless it's | 1451 including the terminating zero) using INTLEN_OUT, unless it's |
1452 a NULL pointer. | 1452 a NULL pointer. |
1453 | 1453 |
1454 Intbyte *eicpyout_malloc_fmt (Eistring *eistr, Internal_Format intfmt, | 1454 Ibyte *eicpyout_malloc_fmt (Eistring *eistr, Internal_Format intfmt, |
1455 Bytecount *intlen_out, Lisp_Object object); | 1455 Bytecount *intlen_out, Lisp_Object object); |
1456 Like eicpyout_malloc(), but converts to the specified internal | 1456 Like eicpyout_malloc(), but converts to the specified internal |
1457 format. (No formats other than FORMAT_DEFAULT are currently | 1457 format. (No formats other than FORMAT_DEFAULT are currently |
1458 implemented, and you get an assertion failure if you try.) | 1458 implemented, and you get an assertion failure if you try.) |
1459 | 1459 |
1508 | 1508 |
1509 ********************************************** | 1509 ********************************************** |
1510 * Getting the character at a position * | 1510 * Getting the character at a position * |
1511 ********************************************** | 1511 ********************************************** |
1512 | 1512 |
1513 Emchar eigetch (Eistring *eistr, Bytecount bytepos); | 1513 Ichar eigetch (Eistring *eistr, Bytecount bytepos); |
1514 Return the character at a particular byte offset. | 1514 Return the character at a particular byte offset. |
1515 Emchar eigetch_char (Eistring *eistr, Charcount charpos); | 1515 Ichar eigetch_char (Eistring *eistr, Charcount charpos); |
1516 Return the character at a particular character offset. | 1516 Return the character at a particular character offset. |
1517 | 1517 |
1518 | 1518 |
1519 ********************************************** | 1519 ********************************************** |
1520 * Setting the character at a position * | 1520 * Setting the character at a position * |
1521 ********************************************** | 1521 ********************************************** |
1522 | 1522 |
1523 Emchar eisetch (Eistring *eistr, Bytecount bytepos, Emchar chr); | 1523 Ichar eisetch (Eistring *eistr, Bytecount bytepos, Ichar chr); |
1524 Set the character at a particular byte offset. | 1524 Set the character at a particular byte offset. |
1525 Emchar eisetch_char (Eistring *eistr, Charcount charpos, Emchar chr); | 1525 Ichar eisetch_char (Eistring *eistr, Charcount charpos, Ichar chr); |
1526 Set the character at a particular character offset. | 1526 Set the character at a particular character offset. |
1527 | 1527 |
1528 | 1528 |
1529 ********************************************** | 1529 ********************************************** |
1530 * Concatenation * | 1530 * Concatenation * |
1537 void eicat_ei (Eistring *eistr, Eistring *eistr2); | 1537 void eicat_ei (Eistring *eistr, Eistring *eistr2); |
1538 ... from another Eistring. | 1538 ... from another Eistring. |
1539 void eicat_c (Eistring *eistr, Char_ASCII *c_string); | 1539 void eicat_c (Eistring *eistr, Char_ASCII *c_string); |
1540 ... from an ASCII null-terminated string. Non-ASCII characters in | 1540 ... from an ASCII null-terminated string. Non-ASCII characters in |
1541 the string are *ILLEGAL* (read abort() with error-checking defined). | 1541 the string are *ILLEGAL* (read abort() with error-checking defined). |
1542 void eicat_raw (ei, const Intbyte *data, Bytecount len); | 1542 void eicat_raw (ei, const Ibyte *data, Bytecount len); |
1543 ... from raw internal-format data in the default internal format. | 1543 ... from raw internal-format data in the default internal format. |
1544 void eicat_rawz (ei, const Intbyte *data); | 1544 void eicat_rawz (ei, const Ibyte *data); |
1545 ... from raw internal-format data in the default internal format | 1545 ... from raw internal-format data in the default internal format |
1546 that is "null-terminated" (the meaning of this depends on the nature | 1546 that is "null-terminated" (the meaning of this depends on the nature |
1547 of the default internal format). | 1547 of the default internal format). |
1548 void eicat_lstr (ei, Lisp_Object lisp_string); | 1548 void eicat_lstr (ei, Lisp_Object lisp_string); |
1549 ... from a Lisp_Object string. | 1549 ... from a Lisp_Object string. |
1550 void eicat_ch (ei, Emchar ch); | 1550 void eicat_ch (ei, Ichar ch); |
1551 ... from an Emchar. | 1551 ... from an Ichar. |
1552 | 1552 |
1553 (All except the first variety are convenience functions. | 1553 (All except the first variety are convenience functions. |
1554 In the general case, create another Eistring from the source.) | 1554 In the general case, create another Eistring from the source.) |
1555 | 1555 |
1556 | 1556 |
1568 void eisub_c (Eistring *eistr, Bytecount off, Charcount charoff, | 1568 void eisub_c (Eistring *eistr, Bytecount off, Charcount charoff, |
1569 Bytecount len, Charcount charlen, Char_ASCII *c_string); | 1569 Bytecount len, Charcount charlen, Char_ASCII *c_string); |
1570 ... with an ASCII null-terminated string. Non-ASCII characters in | 1570 ... with an ASCII null-terminated string. Non-ASCII characters in |
1571 the string are *ILLEGAL* (read abort() with error-checking defined). | 1571 the string are *ILLEGAL* (read abort() with error-checking defined). |
1572 void eisub_ch (Eistring *eistr, Bytecount off, Charcount charoff, | 1572 void eisub_ch (Eistring *eistr, Bytecount off, Charcount charoff, |
1573 Bytecount len, Charcount charlen, Emchar ch); | 1573 Bytecount len, Charcount charlen, Ichar ch); |
1574 ... with an Emchar. | 1574 ... with an Ichar. |
1575 | 1575 |
1576 void eidel (Eistring *eistr, Bytecount off, Charcount charoff, | 1576 void eidel (Eistring *eistr, Bytecount off, Charcount charoff, |
1577 Bytecount len, Charcount charlen); | 1577 Bytecount len, Charcount charlen); |
1578 Delete a section of the Eistring. | 1578 Delete a section of the Eistring. |
1579 | 1579 |
1600 | 1600 |
1601 ********************************************** | 1601 ********************************************** |
1602 * Searching in the Eistring for a character * | 1602 * Searching in the Eistring for a character * |
1603 ********************************************** | 1603 ********************************************** |
1604 | 1604 |
1605 Bytecount eichr (Eistring *eistr, Emchar chr); | 1605 Bytecount eichr (Eistring *eistr, Ichar chr); |
1606 Charcount eichr_char (Eistring *eistr, Emchar chr); | 1606 Charcount eichr_char (Eistring *eistr, Ichar chr); |
1607 Bytecount eichr_off (Eistring *eistr, Emchar chr, Bytecount off, | 1607 Bytecount eichr_off (Eistring *eistr, Ichar chr, Bytecount off, |
1608 Charcount charoff); | 1608 Charcount charoff); |
1609 Charcount eichr_off_char (Eistring *eistr, Emchar chr, Bytecount off, | 1609 Charcount eichr_off_char (Eistring *eistr, Ichar chr, Bytecount off, |
1610 Charcount charoff); | 1610 Charcount charoff); |
1611 Bytecount eirchr (Eistring *eistr, Emchar chr); | 1611 Bytecount eirchr (Eistring *eistr, Ichar chr); |
1612 Charcount eirchr_char (Eistring *eistr, Emchar chr); | 1612 Charcount eirchr_char (Eistring *eistr, Ichar chr); |
1613 Bytecount eirchr_off (Eistring *eistr, Emchar chr, Bytecount off, | 1613 Bytecount eirchr_off (Eistring *eistr, Ichar chr, Bytecount off, |
1614 Charcount charoff); | 1614 Charcount charoff); |
1615 Charcount eirchr_off_char (Eistring *eistr, Emchar chr, Bytecount off, | 1615 Charcount eirchr_off_char (Eistring *eistr, Ichar chr, Bytecount off, |
1616 Charcount charoff); | 1616 Charcount charoff); |
1617 | 1617 |
1618 | 1618 |
1619 ********************************************** | 1619 ********************************************** |
1620 * Searching in the Eistring for a string * | 1620 * Searching in the Eistring for a string * |
1737 would be to create a whole series of Ei operations that work on | 1737 would be to create a whole series of Ei operations that work on |
1738 nothing but Eistrings. Although theoretically nice, in | 1738 nothing but Eistrings. Although theoretically nice, in |
1739 practice it's a hassle, so we suggest that you provide | 1739 practice it's a hassle, so we suggest that you provide |
1740 convenience functions. In particular, there are two paths you | 1740 convenience functions. In particular, there are two paths you |
1741 can take. One is minimalist -- it only allows other Eistrings | 1741 can take. One is minimalist -- it only allows other Eistrings |
1742 and ASCII data, and Emchars if the particular operation makes | 1742 and ASCII data, and Ichars if the particular operation makes |
1743 sense with a character. The other provides interfaces for the | 1743 sense with a character. The other provides interfaces for the |
1744 most commonly-used forms -- Eistring, ASCII data, Lisp string, | 1744 most commonly-used forms -- Eistring, ASCII data, Lisp string, |
1745 raw internal-format string with length, raw internal-format | 1745 raw internal-format string with length, raw internal-format |
1746 string without, and possibly Emchar. (In the function names, | 1746 string without, and possibly Ichar. (In the function names, |
1747 these are designated `ei', `c', `lstr', `raw', `rawz', and | 1747 these are designated `ei', `c', `lstr', `raw', `rawz', and |
1748 `ch', respectively.) | 1748 `ch', respectively.) |
1749 | 1749 |
1750 (5) When coding a new type of operation, such as was discussed in | 1750 (5) When coding a new type of operation, such as was discussed in |
1751 previous section, the correct approach is to declare an worker | 1751 previous section, the correct approach is to declare an worker |
1782 | 1782 |
1783 typedef struct | 1783 typedef struct |
1784 { | 1784 { |
1785 /* Data for the Eistring, stored in the default internal format. | 1785 /* Data for the Eistring, stored in the default internal format. |
1786 Always includes terminating null. */ | 1786 Always includes terminating null. */ |
1787 Intbyte *data_; | 1787 Ibyte *data_; |
1788 /* Total number of bytes allocated in DATA (including null). */ | 1788 /* Total number of bytes allocated in DATA (including null). */ |
1789 Bytecount max_size_allocated_; | 1789 Bytecount max_size_allocated_; |
1790 Bytecount bytelen_; | 1790 Bytecount bytelen_; |
1791 Charcount charlen_; | 1791 Charcount charlen_; |
1792 int mallocp_; | 1792 int mallocp_; |
1868 } \ | 1868 } \ |
1869 if (ei1newsize != (ei)->max_size_allocated_) \ | 1869 if (ei1newsize != (ei)->max_size_allocated_) \ |
1870 { \ | 1870 { \ |
1871 if ((ei)->mallocp_) \ | 1871 if ((ei)->mallocp_) \ |
1872 /* xrealloc always preserves existing data as much as possible */ \ | 1872 /* xrealloc always preserves existing data as much as possible */ \ |
1873 (ei)->data_ = (Intbyte *) xrealloc ((ei)->data_, ei1newsize); \ | 1873 (ei)->data_ = (Ibyte *) xrealloc ((ei)->data_, ei1newsize); \ |
1874 else \ | 1874 else \ |
1875 { \ | 1875 { \ |
1876 /* We don't have realloc, so ALLOCA() more space and copy the \ | 1876 /* We don't have realloc, so ALLOCA() more space and copy the \ |
1877 data into it. */ \ | 1877 data into it. */ \ |
1878 Intbyte *ei1oldeidata = (ei)->data_; \ | 1878 Ibyte *ei1oldeidata = (ei)->data_; \ |
1879 (ei)->data_ = (Intbyte *) ALLOCA (ei1newsize); \ | 1879 (ei)->data_ = (Ibyte *) ALLOCA (ei1newsize); \ |
1880 if (ei1oldeidata) \ | 1880 if (ei1oldeidata) \ |
1881 memcpy ((ei)->data_, ei1oldeidata, ei1oldeibytelen + 1); \ | 1881 memcpy ((ei)->data_, ei1oldeidata, ei1oldeibytelen + 1); \ |
1882 } \ | 1882 } \ |
1883 (ei)->max_size_allocated_ = ei1newsize; \ | 1883 (ei)->max_size_allocated_ = ei1newsize; \ |
1884 } \ | 1884 } \ |
1934 Lisp_Object ei23lstr = (lisp_string); \ | 1934 Lisp_Object ei23lstr = (lisp_string); \ |
1935 int ei23off = (off); \ | 1935 int ei23off = (off); \ |
1936 int ei23charoff = (charoff); \ | 1936 int ei23charoff = (charoff); \ |
1937 int ei23len = (len); \ | 1937 int ei23len = (len); \ |
1938 int ei23charlen = (charlen); \ | 1938 int ei23charlen = (charlen); \ |
1939 const Intbyte *ei23data = XSTRING_DATA (ei23lstr); \ | 1939 const Ibyte *ei23data = XSTRING_DATA (ei23lstr); \ |
1940 \ | 1940 \ |
1941 int ei23oldbytelen = (ei)->bytelen_; \ | 1941 int ei23oldbytelen = (ei)->bytelen_; \ |
1942 \ | 1942 \ |
1943 eifixup_byte (ei23data, ei23off, ei23charoff); \ | 1943 eifixup_byte (ei23data, ei23off, ei23charoff); \ |
1944 eifixup_bytechar (ei23data + ei23off, ei23len, ei23charlen); \ | 1944 eifixup_bytechar (ei23data + ei23off, ei23len, ei23charlen); \ |
1946 EI_ALLOC_AND_COPY (ei, ei23data + ei23off, ei23len, ei23charlen); \ | 1946 EI_ALLOC_AND_COPY (ei, ei23data + ei23off, ei23len, ei23charlen); \ |
1947 } while (0) | 1947 } while (0) |
1948 | 1948 |
1949 #define eicpy_raw_fmt(ei, ptr, len, fmt, object) \ | 1949 #define eicpy_raw_fmt(ei, ptr, len, fmt, object) \ |
1950 do { \ | 1950 do { \ |
1951 const Intbyte *ei12ptr = (ptr); \ | 1951 const Ibyte *ei12ptr = (ptr); \ |
1952 Internal_Format ei12fmt = (fmt); \ | 1952 Internal_Format ei12fmt = (fmt); \ |
1953 int ei12len = (len); \ | 1953 int ei12len = (len); \ |
1954 assert (ei12fmt == FORMAT_DEFAULT); \ | 1954 assert (ei12fmt == FORMAT_DEFAULT); \ |
1955 EI_ALLOC_AND_COPY (ei, ei12ptr, ei12len, \ | 1955 EI_ALLOC_AND_COPY (ei, ei12ptr, ei12len, \ |
1956 bytecount_to_charcount (ei12ptr, ei12len)); \ | 1956 bytecount_to_charcount (ei12ptr, ei12len)); \ |
1959 #define eicpy_raw(ei, ptr, len) \ | 1959 #define eicpy_raw(ei, ptr, len) \ |
1960 eicpy_raw_fmt (ei, ptr, len, FORMAT_DEFAULT, Qnil) | 1960 eicpy_raw_fmt (ei, ptr, len, FORMAT_DEFAULT, Qnil) |
1961 | 1961 |
1962 #define eicpy_rawz_fmt(ei, ptr, fmt, object) \ | 1962 #define eicpy_rawz_fmt(ei, ptr, fmt, object) \ |
1963 do { \ | 1963 do { \ |
1964 const Intbyte *ei12p1ptr = (ptr); \ | 1964 const Ibyte *ei12p1ptr = (ptr); \ |
1965 Internal_Format ei12p1fmt = (fmt); \ | 1965 Internal_Format ei12p1fmt = (fmt); \ |
1966 assert (ei12p1fmt == FORMAT_DEFAULT); \ | 1966 assert (ei12p1fmt == FORMAT_DEFAULT); \ |
1967 eicpy_raw_fmt (ei, ei12p1ptr, qxestrlen (ei12p1ptr), fmt, object); \ | 1967 eicpy_raw_fmt (ei, ei12p1ptr, qxestrlen (ei12p1ptr), fmt, object); \ |
1968 } while (0) | 1968 } while (0) |
1969 | 1969 |
1970 #define eicpy_rawz(ei, ptr) eicpy_rawz_fmt (ei, ptr, FORMAT_DEFAULT, Qnil) | 1970 #define eicpy_rawz(ei, ptr) eicpy_rawz_fmt (ei, ptr, FORMAT_DEFAULT, Qnil) |
1971 | 1971 |
1972 #define eicpy_ch(ei, ch) \ | 1972 #define eicpy_ch(ei, ch) \ |
1973 do { \ | 1973 do { \ |
1974 Intbyte ei12p2[MAX_EMCHAR_LEN]; \ | 1974 Ibyte ei12p2[MAX_ICHAR_LEN]; \ |
1975 Bytecount ei12p2len = set_charptr_emchar (ei12p2, ch); \ | 1975 Bytecount ei12p2len = set_itext_ichar (ei12p2, ch); \ |
1976 EI_ALLOC_AND_COPY (ei, ei12p2, ei12p2len, 1); \ | 1976 EI_ALLOC_AND_COPY (ei, ei12p2, ei12p2len, 1); \ |
1977 } while (0) | 1977 } while (0) |
1978 | 1978 |
1979 #define eicpy_c(ei, c_string) \ | 1979 #define eicpy_c(ei, c_string) \ |
1980 do { \ | 1980 do { \ |
2017 NOT YET IMPLEMENTED | 2017 NOT YET IMPLEMENTED |
2018 | 2018 |
2019 #define eicpy_lstream(eistr, lstream) \ | 2019 #define eicpy_lstream(eistr, lstream) \ |
2020 NOT YET IMPLEMENTED | 2020 NOT YET IMPLEMENTED |
2021 | 2021 |
2022 #define eireset(eistr) eicpy_rawz (eistr, (Intbyte *) "") | 2022 #define eireset(eistr) eicpy_rawz (eistr, (Ibyte *) "") |
2023 | 2023 |
2024 /* ----- Getting the data out of the Eistring ----- */ | 2024 /* ----- Getting the data out of the Eistring ----- */ |
2025 | 2025 |
2026 #define eidata(ei) ((ei)->data_) | 2026 #define eidata(ei) ((ei)->data_) |
2027 | 2027 |
2043 | 2043 |
2044 #define eicpyout_alloca(eistr, ptrout, lenout) \ | 2044 #define eicpyout_alloca(eistr, ptrout, lenout) \ |
2045 eicpyout_alloca_fmt (eistr, ptrout, lenout, FORMAT_DEFAULT, Qnil) | 2045 eicpyout_alloca_fmt (eistr, ptrout, lenout, FORMAT_DEFAULT, Qnil) |
2046 #define eicpyout_malloc(eistr, lenout) \ | 2046 #define eicpyout_malloc(eistr, lenout) \ |
2047 eicpyout_malloc_fmt (eistr, lenout, FORMAT_DEFAULT, Qnil) | 2047 eicpyout_malloc_fmt (eistr, lenout, FORMAT_DEFAULT, Qnil) |
2048 Intbyte *eicpyout_malloc_fmt (Eistring *eistr, Bytecount *len_out, | 2048 Ibyte *eicpyout_malloc_fmt (Eistring *eistr, Bytecount *len_out, |
2049 Internal_Format fmt, Lisp_Object object); | 2049 Internal_Format fmt, Lisp_Object object); |
2050 #define eicpyout_alloca_fmt(eistr, ptrout, lenout, fmt, object) \ | 2050 #define eicpyout_alloca_fmt(eistr, ptrout, lenout, fmt, object) \ |
2051 do { \ | 2051 do { \ |
2052 Internal_Format ei23fmt = (fmt); \ | 2052 Internal_Format ei23fmt = (fmt); \ |
2053 Intbyte *ei23ptrout = &(ptrout); \ | 2053 Ibyte *ei23ptrout = &(ptrout); \ |
2054 Bytecount *ei23lenout = &(lenout); \ | 2054 Bytecount *ei23lenout = &(lenout); \ |
2055 \ | 2055 \ |
2056 assert (ei23fmt == FORMAT_DEFAULT); \ | 2056 assert (ei23fmt == FORMAT_DEFAULT); \ |
2057 \ | 2057 \ |
2058 *ei23lenout = (eistr)->bytelen_; \ | 2058 *ei23lenout = (eistr)->bytelen_; \ |
2059 *ei23ptrout = alloca_array (Intbyte, (eistr)->bytelen_ + 1); \ | 2059 *ei23ptrout = alloca_array (Ibyte, (eistr)->bytelen_ + 1); \ |
2060 memcpy (*ei23ptrout, (eistr)->data_, (eistr)->bytelen_ + 1); \ | 2060 memcpy (*ei23ptrout, (eistr)->data_, (eistr)->bytelen_ + 1); \ |
2061 } while (0) | 2061 } while (0) |
2062 | 2062 |
2063 /* ----- Moving to the heap ----- */ | 2063 /* ----- Moving to the heap ----- */ |
2064 | 2064 |
2086 if (!(ei)->mallocp_) \ | 2086 if (!(ei)->mallocp_) \ |
2087 return; \ | 2087 return; \ |
2088 (ei)->mallocp_ = 0; \ | 2088 (ei)->mallocp_ = 0; \ |
2089 if ((ei)->data_) \ | 2089 if ((ei)->data_) \ |
2090 { \ | 2090 { \ |
2091 Intbyte *ei13newdata; \ | 2091 Ibyte *ei13newdata; \ |
2092 \ | 2092 \ |
2093 (ei)->max_size_allocated_ = \ | 2093 (ei)->max_size_allocated_ = \ |
2094 eifind_large_enough_buffer (0, (ei)->bytelen_ + 1); \ | 2094 eifind_large_enough_buffer (0, (ei)->bytelen_ + 1); \ |
2095 ei13newdata = (Intbyte *) ALLOCA ((ei)->max_size_allocated_); \ | 2095 ei13newdata = (Ibyte *) ALLOCA ((ei)->max_size_allocated_); \ |
2096 memcpy (ei13newdata, (ei)->data_, (ei)->bytelen_ + 1); \ | 2096 memcpy (ei13newdata, (ei)->data_, (ei)->bytelen_ + 1); \ |
2097 xfree ((ei)->data_); \ | 2097 xfree ((ei)->data_); \ |
2098 (ei)->data_ = ei13newdata; \ | 2098 (ei)->data_ = ei13newdata; \ |
2099 } \ | 2099 } \ |
2100 \ | 2100 \ |
2127 | 2127 |
2128 DECLARE_INLINE_HEADER (Bytecount eiincpos_1 (Eistring *eistr, | 2128 DECLARE_INLINE_HEADER (Bytecount eiincpos_1 (Eistring *eistr, |
2129 Bytecount bytepos, | 2129 Bytecount bytepos, |
2130 Charcount n)) | 2130 Charcount n)) |
2131 { | 2131 { |
2132 Intbyte *pos = eistr->data_ + bytepos; | 2132 Ibyte *pos = eistr->data_ + bytepos; |
2133 Charcount i; | 2133 Charcount i; |
2134 | 2134 |
2135 text_checking_assert (bytepos >= 0 && bytepos <= eistr->bytelen_); | 2135 text_checking_assert (bytepos >= 0 && bytepos <= eistr->bytelen_); |
2136 text_checking_assert (n >= 0 && n <= eistr->charlen_); | 2136 text_checking_assert (n >= 0 && n <= eistr->charlen_); |
2137 /* We could check N more correctly now, but that would require a | 2137 /* We could check N more correctly now, but that would require a |
2138 call to bytecount_to_charcount(), which would be needlessly | 2138 call to bytecount_to_charcount(), which would be needlessly |
2139 expensive (it would convert O(N) algorithms into O(N^2) algorithms | 2139 expensive (it would convert O(N) algorithms into O(N^2) algorithms |
2140 with ERROR_CHECK_TEXT, which would be bad). If N is bad, we are | 2140 with ERROR_CHECK_TEXT, which would be bad). If N is bad, we are |
2141 guaranteed to catch it either inside INC_CHARPTR() or in the check | 2141 guaranteed to catch it either inside INC_IBYTEPTR() or in the check |
2142 below. */ | 2142 below. */ |
2143 for (i = 0; i < n; i++) | 2143 for (i = 0; i < n; i++) |
2144 INC_CHARPTR (pos); | 2144 INC_IBYTEPTR (pos); |
2145 text_checking_assert (pos - eistr->data_ <= eistr->bytelen_); | 2145 text_checking_assert (pos - eistr->data_ <= eistr->bytelen_); |
2146 return pos - eistr->data_; | 2146 return pos - eistr->data_; |
2147 } | 2147 } |
2148 | 2148 |
2149 #define eiincpos (ei, bytepos) eiincpos_1 (ei, bytepos, 1) | 2149 #define eiincpos (ei, bytepos) eiincpos_1 (ei, bytepos, 1) |
2151 | 2151 |
2152 DECLARE_INLINE_HEADER (Bytecount eidecpos_1 (Eistring *eistr, | 2152 DECLARE_INLINE_HEADER (Bytecount eidecpos_1 (Eistring *eistr, |
2153 Bytecount bytepos, | 2153 Bytecount bytepos, |
2154 Charcount n)) | 2154 Charcount n)) |
2155 { | 2155 { |
2156 Intbyte *pos = eistr->data_ + bytepos; | 2156 Ibyte *pos = eistr->data_ + bytepos; |
2157 int i; | 2157 int i; |
2158 | 2158 |
2159 text_checking_assert (bytepos >= 0 && bytepos <= eistr->bytelen_); | 2159 text_checking_assert (bytepos >= 0 && bytepos <= eistr->bytelen_); |
2160 text_checking_assert (n >= 0 && n <= eistr->charlen_); | 2160 text_checking_assert (n >= 0 && n <= eistr->charlen_); |
2161 /* We could check N more correctly now, but ... see above. */ | 2161 /* We could check N more correctly now, but ... see above. */ |
2162 for (i = 0; i < n; i++) | 2162 for (i = 0; i < n; i++) |
2163 DEC_CHARPTR (pos); | 2163 DEC_IBYTEPTR (pos); |
2164 text_checking_assert (pos - eistr->data_ <= eistr->bytelen_); | 2164 text_checking_assert (pos - eistr->data_ <= eistr->bytelen_); |
2165 return pos - eistr->data_; | 2165 return pos - eistr->data_; |
2166 } | 2166 } |
2167 | 2167 |
2168 #define eidecpos (ei, bytepos) eidecpos_1 (ei, bytepos, 1) | 2168 #define eidecpos (ei, bytepos) eidecpos_1 (ei, bytepos, 1) |
2170 | 2170 |
2171 | 2171 |
2172 /* ----- Getting the character at a position ----- */ | 2172 /* ----- Getting the character at a position ----- */ |
2173 | 2173 |
2174 #define eigetch(ei, bytepos) \ | 2174 #define eigetch(ei, bytepos) \ |
2175 charptr_emchar ((ei)->data_ + (bytepos)) | 2175 itext_ichar ((ei)->data_ + (bytepos)) |
2176 #define eigetch_char(ei, charpos) charptr_emchar_n ((ei)->data_, charpos) | 2176 #define eigetch_char(ei, charpos) itext_ichar_n ((ei)->data_, charpos) |
2177 | 2177 |
2178 | 2178 |
2179 /* ----- Setting the character at a position ----- */ | 2179 /* ----- Setting the character at a position ----- */ |
2180 | 2180 |
2181 #define eisetch(ei, bytepos, chr) \ | 2181 #define eisetch(ei, bytepos, chr) \ |
2207 const Char_ASCII *ei15 = (c_string); \ | 2207 const Char_ASCII *ei15 = (c_string); \ |
2208 int ei15len = strlen (ei15); \ | 2208 int ei15len = strlen (ei15); \ |
2209 \ | 2209 \ |
2210 EI_ASSERT_ASCII (ei15, ei15len); \ | 2210 EI_ASSERT_ASCII (ei15, ei15len); \ |
2211 eicat_1 (ei, ei15, ei15len, \ | 2211 eicat_1 (ei, ei15, ei15len, \ |
2212 bytecount_to_charcount ((Intbyte *) ei15, ei15len)); \ | 2212 bytecount_to_charcount ((Ibyte *) ei15, ei15len)); \ |
2213 } while (0) | 2213 } while (0) |
2214 | 2214 |
2215 #define eicat_raw(ei, data, len) \ | 2215 #define eicat_raw(ei, data, len) \ |
2216 do { \ | 2216 do { \ |
2217 int ei16len = (len); \ | 2217 int ei16len = (len); \ |
2218 const Intbyte *ei16data = (data); \ | 2218 const Ibyte *ei16data = (data); \ |
2219 eicat_1 (ei, ei16data, ei16len, \ | 2219 eicat_1 (ei, ei16data, ei16len, \ |
2220 bytecount_to_charcount (ei16data, ei16len)); \ | 2220 bytecount_to_charcount (ei16data, ei16len)); \ |
2221 } while (0) | 2221 } while (0) |
2222 | 2222 |
2223 #define eicat_rawz(ei, ptr) \ | 2223 #define eicat_rawz(ei, ptr) \ |
2224 do { \ | 2224 do { \ |
2225 const Intbyte *ei16p5ptr = (ptr); \ | 2225 const Ibyte *ei16p5ptr = (ptr); \ |
2226 eicat_raw (ei, ei16p5ptr, qxestrlen (ei16p5ptr)); \ | 2226 eicat_raw (ei, ei16p5ptr, qxestrlen (ei16p5ptr)); \ |
2227 } while (0) | 2227 } while (0) |
2228 | 2228 |
2229 #define eicat_lstr(ei, lisp_string) \ | 2229 #define eicat_lstr(ei, lisp_string) \ |
2230 do { \ | 2230 do { \ |
2233 string_char_length (ei17)); \ | 2233 string_char_length (ei17)); \ |
2234 } while (0) | 2234 } while (0) |
2235 | 2235 |
2236 #define eicat_ch(ei, ch) \ | 2236 #define eicat_ch(ei, ch) \ |
2237 do { \ | 2237 do { \ |
2238 Intbyte ei22ch[MAX_EMCHAR_LEN]; \ | 2238 Ibyte ei22ch[MAX_ICHAR_LEN]; \ |
2239 Bytecount ei22len = set_charptr_emchar (ei22ch, ch); \ | 2239 Bytecount ei22len = set_itext_ichar (ei22ch, ch); \ |
2240 eicat_1 (ei, ei22ch, ei22len, 1); \ | 2240 eicat_1 (ei, ei22ch, ei22len, 1); \ |
2241 } while (0) | 2241 } while (0) |
2242 | 2242 |
2243 | 2243 |
2244 /* ----- Replacement ----- */ | 2244 /* ----- Replacement ----- */ |
2251 do { \ | 2251 do { \ |
2252 int ei18off = (off); \ | 2252 int ei18off = (off); \ |
2253 int ei18charoff = (charoff); \ | 2253 int ei18charoff = (charoff); \ |
2254 int ei18len = (len); \ | 2254 int ei18len = (len); \ |
2255 int ei18charlen = (charlen); \ | 2255 int ei18charlen = (charlen); \ |
2256 Intbyte *ei18src = (Intbyte *) (src); \ | 2256 Ibyte *ei18src = (Ibyte *) (src); \ |
2257 int ei18srclen = (srclen); \ | 2257 int ei18srclen = (srclen); \ |
2258 int ei18srccharlen = (srccharlen); \ | 2258 int ei18srccharlen = (srccharlen); \ |
2259 \ | 2259 \ |
2260 int ei18oldeibytelen = (ei)->bytelen_; \ | 2260 int ei18oldeibytelen = (ei)->bytelen_; \ |
2261 \ | 2261 \ |
2289 eisub_1 (ei, off, charoff, len, charlen, ei20, ei20len, -1); \ | 2289 eisub_1 (ei, off, charoff, len, charlen, ei20, ei20len, -1); \ |
2290 } while (0) | 2290 } while (0) |
2291 | 2291 |
2292 #define eisub_ch(ei, off, charoff, len, charlen, ch) \ | 2292 #define eisub_ch(ei, off, charoff, len, charlen, ch) \ |
2293 do { \ | 2293 do { \ |
2294 Intbyte ei21ch[MAX_EMCHAR_LEN]; \ | 2294 Ibyte ei21ch[MAX_ICHAR_LEN]; \ |
2295 Bytecount ei21len = set_charptr_emchar (ei21ch, ch); \ | 2295 Bytecount ei21len = set_itext_ichar (ei21ch, ch); \ |
2296 eisub_1 (ei, off, charoff, len, charlen, ei21ch, ei21len, 1); \ | 2296 eisub_1 (ei, off, charoff, len, charlen, ei21ch, ei21len, 1); \ |
2297 } while (0) | 2297 } while (0) |
2298 | 2298 |
2299 #define eidel(ei, off, charoff, len, charlen) \ | 2299 #define eidel(ei, off, charoff, len, charlen) \ |
2300 eisub_1(ei, off, charoff, len, charlen, NULL, 0, 0) | 2300 eisub_1(ei, off, charoff, len, charlen, NULL, 0, 0) |
2383 | 2383 |
2384 | 2384 |
2385 /* ----- Comparison ----- */ | 2385 /* ----- Comparison ----- */ |
2386 | 2386 |
2387 int eicmp_1 (Eistring *ei, Bytecount off, Charcount charoff, | 2387 int eicmp_1 (Eistring *ei, Bytecount off, Charcount charoff, |
2388 Bytecount len, Charcount charlen, const Intbyte *data, | 2388 Bytecount len, Charcount charlen, const Ibyte *data, |
2389 const Eistring *ei2, int is_c, int fold_case); | 2389 const Eistring *ei2, int is_c, int fold_case); |
2390 | 2390 |
2391 #define eicmp_ei(eistr, eistr2) \ | 2391 #define eicmp_ei(eistr, eistr2) \ |
2392 eicmp_1 (eistr, 0, -1, -1, -1, 0, eistr2, 0, 0) | 2392 eicmp_1 (eistr, 0, -1, -1, -1, 0, eistr2, 0, 0) |
2393 #define eicmp_off_ei(eistr, off, charoff, len, charlen, eistr2) \ | 2393 #define eicmp_off_ei(eistr, off, charoff, len, charlen, eistr2) \ |
2415 eicmp_1 (eistr, off, charoff, len, charlen, c_string, 0, 1, 2) | 2415 eicmp_1 (eistr, off, charoff, len, charlen, c_string, 0, 1, 2) |
2416 | 2416 |
2417 | 2417 |
2418 /* ----- Case-changing the Eistring ----- */ | 2418 /* ----- Case-changing the Eistring ----- */ |
2419 | 2419 |
2420 int eistr_casefiddle_1 (Intbyte *olddata, Bytecount len, Intbyte *newdata, | 2420 int eistr_casefiddle_1 (Ibyte *olddata, Bytecount len, Ibyte *newdata, |
2421 int downp); | 2421 int downp); |
2422 | 2422 |
2423 #define EI_CASECHANGE(ei, downp) \ | 2423 #define EI_CASECHANGE(ei, downp) \ |
2424 do { \ | 2424 do { \ |
2425 int ei11new_allocmax = (ei)->charlen_ * MAX_EMCHAR_LEN + 1; \ | 2425 int ei11new_allocmax = (ei)->charlen_ * MAX_ICHAR_LEN + 1; \ |
2426 Intbyte *ei11storage = \ | 2426 Ibyte *ei11storage = \ |
2427 (Intbyte *) alloca_array (Intbyte, ei11new_allocmax); \ | 2427 (Ibyte *) alloca_array (Ibyte, ei11new_allocmax); \ |
2428 int ei11newlen = eistr_casefiddle_1 ((ei)->data_, (ei)->bytelen_, \ | 2428 int ei11newlen = eistr_casefiddle_1 ((ei)->data_, (ei)->bytelen_, \ |
2429 ei11storage, downp); \ | 2429 ei11storage, downp); \ |
2430 \ | 2430 \ |
2431 if (ei11newlen) \ | 2431 if (ei11newlen) \ |
2432 { \ | 2432 { \ |
2747 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 2); \ | 2747 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 2); \ |
2748 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 2); \ | 2748 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 2); \ |
2749 ((dfc_aliasing_voidpp) &(sink))->p = dfc_sink_ret; \ | 2749 ((dfc_aliasing_voidpp) &(sink))->p = dfc_sink_ret; \ |
2750 } while (0) | 2750 } while (0) |
2751 #define DFC_LISP_STRING_USE_CONVERTED_DATA(sink) \ | 2751 #define DFC_LISP_STRING_USE_CONVERTED_DATA(sink) \ |
2752 sink = make_string ((Intbyte *) dfc_sink.data.ptr, dfc_sink.data.len) | 2752 sink = make_string ((Ibyte *) dfc_sink.data.ptr, dfc_sink.data.len) |
2753 #define DFC_LISP_OPAQUE_USE_CONVERTED_DATA(sink) \ | 2753 #define DFC_LISP_OPAQUE_USE_CONVERTED_DATA(sink) \ |
2754 sink = make_opaque (dfc_sink.data.ptr, dfc_sink.data.len) | 2754 sink = make_opaque (dfc_sink.data.ptr, dfc_sink.data.len) |
2755 #define DFC_LISP_LSTREAM_USE_CONVERTED_DATA(sink) /* data already used */ | 2755 #define DFC_LISP_LSTREAM_USE_CONVERTED_DATA(sink) /* data already used */ |
2756 #define DFC_LISP_BUFFER_USE_CONVERTED_DATA(sink) \ | 2756 #define DFC_LISP_BUFFER_USE_CONVERTED_DATA(sink) \ |
2757 Lstream_delete (XLSTREAM (dfc_sink.lisp_object)) | 2757 Lstream_delete (XLSTREAM (dfc_sink.lisp_object)) |
2802 int __gsnum__ = (num); \ | 2802 int __gsnum__ = (num); \ |
2803 Extbyte * __gserr__ = strerror (__gsnum__); \ | 2803 Extbyte * __gserr__ = strerror (__gsnum__); \ |
2804 \ | 2804 \ |
2805 if (!__gserr__) \ | 2805 if (!__gserr__) \ |
2806 { \ | 2806 { \ |
2807 var = alloca_intbytes (99); \ | 2807 var = alloca_ibytes (99); \ |
2808 qxesprintf (var, "Unknown error %d", __gsnum__); \ | 2808 qxesprintf (var, "Unknown error %d", __gsnum__); \ |
2809 } \ | 2809 } \ |
2810 else \ | 2810 else \ |
2811 EXTERNAL_TO_C_STRING (__gserr__, var, Qstrerror_encoding); \ | 2811 EXTERNAL_TO_C_STRING (__gserr__, var, Qstrerror_encoding); \ |
2812 } while (0) | 2812 } while (0) |