771
|
1 /* Header file for text manipulation primitives and macros.
|
|
2 Copyright (C) 1985-1995 Free Software Foundation, Inc.
|
|
3 Copyright (C) 1995 Sun Microsystems, Inc.
|
1318
|
4 Copyright (C) 2000, 2001, 2002, 2003 Ben Wing.
|
771
|
5
|
|
6 This file is part of XEmacs.
|
|
7
|
|
8 XEmacs is free software; you can redistribute it and/or modify it
|
|
9 under the terms of the GNU General Public License as published by the
|
|
10 Free Software Foundation; either version 2, or (at your option) any
|
|
11 later version.
|
|
12
|
|
13 XEmacs is distributed in the hope that it will be useful, but WITHOUT
|
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
16 for more details.
|
|
17
|
|
18 You should have received a copy of the GNU General Public License
|
|
19 along with XEmacs; see the file COPYING. If not, write to
|
|
20 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
21 Boston, MA 02111-1307, USA. */
|
|
22
|
|
23 /* Synched up with: FSF 19.30. */
|
|
24
|
|
25 /* Authorship:
|
|
26
|
|
27 Mostly written by Ben Wing, starting around 1995.
|
|
28 Current TO_IN/EXTERNAL_FORMAT macros written by Martin Buchholz,
|
|
29 designed by Ben Wing based on earlier macros by Ben Wing.
|
|
30 Separated out June 18, 2000 from buffer.h into text.h.
|
|
31 */
|
|
32
|
|
33 #ifndef INCLUDED_text_h_
|
|
34 #define INCLUDED_text_h_
|
|
35
|
912
|
36 #ifdef HAVE_WCHAR_H
|
771
|
37 #include <wchar.h>
|
912
|
38 #else
|
1257
|
39 size_t wcslen (const wchar_t *);
|
912
|
40 #endif
|
1204
|
41 #ifndef HAVE_STRLWR
|
1257
|
42 char *strlwr (char *);
|
1204
|
43 #endif
|
|
44 #ifndef HAVE_STRUPR
|
1257
|
45 char *strupr (char *);
|
1204
|
46 #endif
|
771
|
47
|
|
48 /* ---------------------------------------------------------------------- */
|
|
49 /* Super-basic character properties */
|
|
50 /* ---------------------------------------------------------------------- */
|
|
51
|
|
52 /* These properties define the specifics of how our current encoding fits
|
|
53 in the basic model used for the encoding. Because this model is the same
|
|
54 as is used for UTF-8, all these properties could be defined for it, too.
|
|
55 This would instantly make the rest of this file work with UTF-8 (with
|
|
56 the exception of a few called functions that would need to be redefined).
|
|
57
|
|
58 (UTF-2000 implementers, take note!)
|
|
59 */
|
|
60
|
|
61 /* If you want more than this, you need to include charset.h */
|
|
62
|
|
63 #ifndef MULE
|
|
64
|
826
|
65 #define rep_bytes_by_first_byte(fb) 1
|
|
66 #define byte_ascii_p(byte) 1
|
867
|
67 #define MAX_ICHAR_LEN 1
|
771
|
68
|
|
69 #else /* MULE */
|
|
70
|
|
71 /* These are carefully designed to work if BYTE is signed or unsigned. */
|
|
72 /* Note that SPC and DEL are considered ASCII, not control. */
|
|
73
|
826
|
74 #define byte_ascii_p(byte) (((byte) & ~0x7f) == 0)
|
|
75 #define byte_c0_p(byte) (((byte) & ~0x1f) == 0)
|
|
76 #define byte_c1_p(byte) (((byte) & ~0x1f) == 0x80)
|
771
|
77
|
|
78 /* Does BYTE represent the first byte of a character? */
|
|
79
|
826
|
80 #ifdef ERROR_CHECK_TEXT
|
|
81
|
|
82 DECLARE_INLINE_HEADER (
|
|
83 int
|
867
|
84 ibyte_first_byte_p_1 (int byte, const char *file, int line)
|
826
|
85 )
|
|
86 {
|
|
87 assert_at_line (byte >= 0 && byte < 256, file, line);
|
|
88 return byte < 0xA0;
|
|
89 }
|
|
90
|
867
|
91 #define ibyte_first_byte_p(byte) \
|
|
92 ibyte_first_byte_p_1 (byte, __FILE__, __LINE__)
|
826
|
93
|
|
94 #else
|
|
95
|
867
|
96 #define ibyte_first_byte_p(byte) ((byte) < 0xA0)
|
826
|
97
|
|
98 #endif
|
|
99
|
|
100 #ifdef ERROR_CHECK_TEXT
|
771
|
101
|
|
102 /* Does BYTE represent the first byte of a multi-byte character? */
|
|
103
|
826
|
104 DECLARE_INLINE_HEADER (
|
|
105 int
|
867
|
106 ibyte_leading_byte_p_1 (int byte, const char *file, int line)
|
826
|
107 )
|
|
108 {
|
|
109 assert_at_line (byte >= 0 && byte < 256, file, line);
|
|
110 return byte_c1_p (byte);
|
|
111 }
|
|
112
|
867
|
113 #define ibyte_leading_byte_p(byte) \
|
|
114 ibyte_leading_byte_p_1 (byte, __FILE__, __LINE__)
|
826
|
115
|
|
116 #else
|
|
117
|
867
|
118 #define ibyte_leading_byte_p(byte) byte_c1_p (byte)
|
826
|
119
|
|
120 #endif
|
771
|
121
|
|
122 /* Table of number of bytes in the string representation of a character
|
|
123 indexed by the first byte of that representation.
|
|
124
|
|
125 This value can be derived in other ways -- e.g. something like
|
826
|
126 XCHARSET_REP_BYTES (charset_by_leading_byte (first_byte))
|
771
|
127 but it's faster this way. */
|
1632
|
128 extern MODULE_API const Bytecount rep_bytes_by_first_byte[0xA0];
|
771
|
129
|
|
130 /* Number of bytes in the string representation of a character. */
|
788
|
131
|
800
|
132 #ifdef ERROR_CHECK_TEXT
|
788
|
133
|
826
|
134 DECLARE_INLINE_HEADER (
|
|
135 Bytecount
|
|
136 rep_bytes_by_first_byte_1 (int fb, const char *file, int line)
|
|
137 )
|
771
|
138 {
|
826
|
139 assert_at_line (fb >= 0 && fb < 0xA0, file, line);
|
771
|
140 return rep_bytes_by_first_byte[fb];
|
|
141 }
|
|
142
|
826
|
143 #define rep_bytes_by_first_byte(fb) \
|
|
144 rep_bytes_by_first_byte_1 (fb, __FILE__, __LINE__)
|
788
|
145
|
800
|
146 #else /* ERROR_CHECK_TEXT */
|
788
|
147
|
826
|
148 #define rep_bytes_by_first_byte(fb) (rep_bytes_by_first_byte[fb])
|
788
|
149
|
800
|
150 #endif /* ERROR_CHECK_TEXT */
|
788
|
151
|
826
|
152 /* Is this character represented by more than one byte in a string in the
|
|
153 default format? */
|
|
154
|
867
|
155 #define ichar_multibyte_p(c) ((c) >= 0x80)
|
|
156
|
|
157 #define ichar_ascii_p(c) (!ichar_multibyte_p (c))
|
826
|
158
|
|
159 /* Maximum number of bytes per Emacs character when represented as text, in
|
|
160 any format.
|
|
161 */
|
771
|
162
|
867
|
163 #define MAX_ICHAR_LEN 4
|
771
|
164
|
826
|
165 #endif /* not MULE */
|
|
166
|
|
167 /* ---------------- Handling non-default formats ----------------- */
|
|
168
|
|
169 /* We support, at least to some extent, formats other than the default
|
|
170 variable-width format, for speed; all of these alternative formats are
|
|
171 fixed-width. Currently we only handle these non-default formats in
|
|
172 buffers, because access to their text is strictly controlled and thus
|
|
173 the details of the format mostly compartmentalized. The only really
|
|
174 tricky part is the search code -- the regex, Boyer-Moore, and
|
|
175 simple-search algorithms in search.c and regex.c. All other code that
|
|
176 knows directly about the buffer representation is the basic code to
|
|
177 modify or retrieve the buffer text.
|
|
178
|
|
179 Supporting fixed-width formats in Lisp strings is harder, but possible
|
|
180 -- FSF currently does this, for example. In this case, however,
|
|
181 probably only 8-bit-fixed is reasonable for Lisp strings -- getting
|
|
182 non-ASCII-compatible fixed-width formats to work is much, much harder
|
|
183 because a lot of code assumes that strings are ASCII-compatible
|
|
184 (i.e. ASCII + other characters represented exclusively using high-bit
|
|
185 bytes) and a lot of code mixes Lisp strings and non-Lisp strings freely.
|
|
186
|
|
187 The different possible fixed-width formats are 8-bit fixed, 16-bit
|
|
188 fixed, and 32-bit fixed. The latter can represent all possible
|
|
189 characters, but at a substantial memory penalty. The other two can
|
|
190 represent only a subset of the possible characters. How these subsets
|
|
191 are defined can be simple or very tricky.
|
|
192
|
|
193 Currently we support only the default format and the 8-bit fixed format,
|
|
194 and in the latter, we only allow these to be the first 256 characters in
|
867
|
195 an Ichar (ASCII and Latin 1).
|
826
|
196
|
|
197 One reasonable approach for 8-bit fixed is to allow the upper half to
|
|
198 represent any 1-byte charset, which is specified on a per-buffer basis.
|
|
199 This should work fairly well in practice since most documents are in
|
|
200 only one foreign language (possibly with some English mixed in). I
|
|
201 think FSF does something like this; or at least, they have something
|
|
202 called nonascii-translation-table and use it when converting from
|
|
203 8-bit-fixed text ("unibyte text") to default text ("multibyte text").
|
|
204 With 16-bit fixed, you could do something like assign chunks of the 64K
|
|
205 worth of characters to charsets as they're encountered in documents.
|
|
206 This should work well with most Asian documents.
|
|
207
|
|
208 If/when we switch to using Unicode internally, we might have formats more
|
|
209 like this:
|
|
210
|
|
211 -- UTF-8 or some extension as the default format. Perl uses an
|
|
212 extension that handles 64-bit chars and requires as much as 13 bytes per
|
|
213 char, vs. the standard of 31-bit chars and 6 bytes max. UTF-8 has the
|
|
214 same basic properties as our own variable-width format (see text.c,
|
|
215 Internal String Encoding) and so most code would not need to be changed.
|
|
216
|
|
217 -- UTF-16 as a "pseudo-fixed" format (i.e. 16-bit fixed plus surrogates
|
|
218 for representing characters not in the BMP, aka >= 65536). The vast
|
|
219 majority of documents will have no surrogates in them so byte/char
|
|
220 conversion will be very fast.
|
|
221
|
|
222 -- an 8-bit fixed format, like currently.
|
|
223
|
|
224 -- possibly, UCS-4 as a 32-bit fixed format.
|
|
225
|
|
226 The fixed-width formats essentially treat the buffer as an array of
|
|
227 8-bit, 16-bit or 32-bit integers. This means that how they are stored
|
|
228 in memory (in particular, big-endian or little-endian) depends on the
|
|
229 native format of the machine's processor. It also means we have to
|
|
230 worry a bit about alignment (basically, we just need to keep the gap an
|
|
231 integral size of the character size, and get things aligned properly
|
|
232 when converting the buffer between formats).
|
|
233 */
|
|
234 typedef enum internal_format
|
|
235 {
|
|
236 FORMAT_DEFAULT,
|
|
237 FORMAT_8_BIT_FIXED,
|
|
238 FORMAT_16_BIT_FIXED, /* not implemented */
|
|
239 FORMAT_32_BIT_FIXED /* not implemented */
|
|
240 } Internal_Format;
|
|
241
|
|
242 #ifdef MULE
|
|
243 /* "OBJECT" below will usually be a buffer, string, or nil. This needs to
|
|
244 be passed in because the interpretation of 8-bit-fixed and 16-bit-fixed
|
|
245 values may depend on the buffer, e.g. depending on what language the
|
|
246 text in the buffer is in. */
|
|
247
|
867
|
248 /* True if Ichar CH can be represented in 8-bit-fixed format. */
|
|
249 #define ichar_8_bit_fixed_p(ch, object) (((ch) & ~0xff) == 0)
|
|
250 /* Convert Ichar CH to an 8-bit int, as will be stored in the buffer. */
|
|
251 #define ichar_to_raw_8_bit_fixed(ch, object) ((Ibyte) (ch))
|
826
|
252 /* Convert the other way. */
|
867
|
253 #define raw_8_bit_fixed_to_ichar(ch, object) ((Ichar) (ch))
|
|
254
|
|
255 #define ichar_16_bit_fixed_p(ch, object) (((ch) & ~0xffff) == 0)
|
|
256 /* Convert Ichar CH to a 16-bit int, as will be stored in the buffer. */
|
|
257 #define ichar_to_raw_16_bit_fixed(ch, object) ((UINT_16_BIT) (ch))
|
826
|
258 /* Convert the other way. */
|
867
|
259 #define raw_16_bit_fixed_to_ichar(ch, object) ((Ichar) (ch))
|
|
260
|
|
261 /* Convert Ichar CH to a 32-bit int, as will be stored in the buffer. */
|
|
262 #define ichar_to_raw_32_bit_fixed(ch, object) ((UINT_32_BIT) (ch))
|
826
|
263 /* Convert the other way. */
|
867
|
264 #define raw_32_bit_fixed_to_ichar(ch, object) ((Ichar) (ch))
|
826
|
265
|
|
266 /* Return the "raw value" of a character as stored in the buffer. In the
|
|
267 default format, this is just the same as the character. In fixed-width
|
|
268 formats, this is the actual value in the buffer, which will be limited
|
|
269 to the range as established by the format. This is used when searching
|
|
270 for a character in a buffer -- it's faster to convert the character to
|
|
271 the raw value and look for that, than repeatedly convert each raw value
|
|
272 in the buffer into a character. */
|
|
273
|
|
274 DECLARE_INLINE_HEADER (
|
867
|
275 Raw_Ichar
|
|
276 ichar_to_raw (Ichar ch, Internal_Format fmt, Lisp_Object object)
|
826
|
277 )
|
|
278 {
|
|
279 switch (fmt)
|
|
280 {
|
|
281 case FORMAT_DEFAULT:
|
867
|
282 return (Raw_Ichar) ch;
|
826
|
283 case FORMAT_16_BIT_FIXED:
|
867
|
284 text_checking_assert (ichar_16_bit_fixed_p (ch, object));
|
|
285 return (Raw_Ichar) ichar_to_raw_16_bit_fixed (ch, object);
|
826
|
286 case FORMAT_32_BIT_FIXED:
|
867
|
287 return (Raw_Ichar) ichar_to_raw_32_bit_fixed (ch, object);
|
826
|
288 default:
|
|
289 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
867
|
290 text_checking_assert (ichar_8_bit_fixed_p (ch, object));
|
|
291 return (Raw_Ichar) ichar_to_raw_8_bit_fixed (ch, object);
|
826
|
292 }
|
|
293 }
|
|
294
|
|
295 /* Return whether CH is representable in the given format in the given
|
|
296 object. */
|
|
297
|
|
298 DECLARE_INLINE_HEADER (
|
|
299 int
|
867
|
300 ichar_fits_in_format (Ichar ch, Internal_Format fmt, Lisp_Object object)
|
826
|
301 )
|
|
302 {
|
|
303 switch (fmt)
|
|
304 {
|
|
305 case FORMAT_DEFAULT:
|
|
306 return 1;
|
|
307 case FORMAT_16_BIT_FIXED:
|
867
|
308 return ichar_16_bit_fixed_p (ch, object);
|
826
|
309 case FORMAT_32_BIT_FIXED:
|
|
310 return 1;
|
|
311 default:
|
|
312 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
867
|
313 return ichar_8_bit_fixed_p (ch, object);
|
826
|
314 }
|
|
315 }
|
|
316
|
|
317 /* Assuming the formats are the same, return whether the two objects
|
|
318 represent text in exactly the same way. */
|
|
319
|
|
320 DECLARE_INLINE_HEADER (
|
|
321 int
|
|
322 objects_have_same_internal_representation (Lisp_Object srcobj,
|
|
323 Lisp_Object dstobj)
|
|
324 )
|
|
325 {
|
|
326 /* &&#### implement this properly when we allow per-object format
|
|
327 differences */
|
|
328 return 1;
|
|
329 }
|
|
330
|
|
331 #else
|
|
332
|
867
|
333 #define ichar_to_raw(ch, fmt, object) ((Raw_Ichar) (ch))
|
|
334 #define ichar_fits_in_format(ch, fmt, object) 1
|
826
|
335 #define objects_have_same_internal_representation(srcobj, dstobj) 1
|
|
336
|
771
|
337 #endif /* MULE */
|
|
338
|
1632
|
339 MODULE_API int dfc_coding_system_is_unicode (Lisp_Object codesys);
|
771
|
340
|
|
341 DECLARE_INLINE_HEADER (
|
|
342 Bytecount dfc_external_data_len (const void *ptr, Lisp_Object codesys)
|
|
343 )
|
|
344 {
|
|
345 if (dfc_coding_system_is_unicode (codesys))
|
|
346 return sizeof (wchar_t) * wcslen ((wchar_t *) ptr);
|
|
347 else
|
|
348 return strlen ((char *) ptr);
|
|
349 }
|
|
350
|
|
351
|
|
352 /************************************************************************/
|
|
353 /* */
|
|
354 /* working with raw internal-format data */
|
|
355 /* */
|
|
356 /************************************************************************/
|
|
357
|
826
|
358 /*
|
|
359 Use the following functions/macros on contiguous text in any of the
|
|
360 internal formats. Those that take a format arg work on all internal
|
|
361 formats; the others work only on the default (variable-width under Mule)
|
|
362 format. If the text you're operating on is known to come from a buffer,
|
|
363 use the buffer-level functions in buffer.h, which automatically know the
|
|
364 correct format and handle the gap.
|
|
365
|
|
366 Some terminology:
|
|
367
|
867
|
368 "itext" appearing in the macros means "internal-format text" -- type
|
|
369 `Ibyte *'. Operations on such pointers themselves, rather than on the
|
|
370 text being pointed to, have "itext" instead of "itext" in the macro
|
|
371 name. "ichar" in the macro names means an Ichar -- the representation
|
826
|
372 of a character as a single integer rather than a series of bytes, as part
|
867
|
373 of "itext". Many of the macros below are for converting between the
|
826
|
374 two representations of characters.
|
|
375
|
867
|
376 Note also that we try to consistently distinguish between an "Ichar" and
|
826
|
377 a Lisp character. Stuff working with Lisp characters often just says
|
867
|
378 "char", so we consistently use "Ichar" when that's what we're working
|
826
|
379 with. */
|
|
380
|
|
381 /* The three golden rules of macros:
|
771
|
382
|
|
383 1) Anything that's an lvalue can be evaluated more than once.
|
826
|
384
|
|
385 2) Macros where anything else can be evaluated more than once should
|
|
386 have the word "unsafe" in their name (exceptions may be made for
|
|
387 large sets of macros that evaluate arguments of certain types more
|
|
388 than once, e.g. struct buffer * arguments, when clearly indicated in
|
|
389 the macro documentation). These macros are generally meant to be
|
|
390 called only by other macros that have already stored the calling
|
|
391 values in temporary variables.
|
|
392
|
|
393 3) Nothing else can be evaluated more than once. Use inline
|
771
|
394 functions, if necessary, to prevent multiple evaluation.
|
826
|
395
|
|
396 NOTE: The functions and macros below are given full prototypes in their
|
|
397 docs, even when the implementation is a macro. In such cases, passing
|
|
398 an argument of a type other than expected will produce undefined
|
|
399 results. Also, given that macros can do things functions can't (in
|
|
400 particular, directly modify arguments as if they were passed by
|
|
401 reference), the declaration syntax has been extended to include the
|
|
402 call-by-reference syntax from C++, where an & after a type indicates
|
|
403 that the argument is an lvalue and is passed by reference, i.e. the
|
|
404 function can modify its value. (This is equivalent in C to passing a
|
|
405 pointer to the argument, but without the need to explicitly worry about
|
|
406 pointers.)
|
|
407
|
|
408 When to capitalize macros:
|
|
409
|
|
410 -- Capitalize macros doing stuff obviously impossible with (C)
|
|
411 functions, e.g. directly modifying arguments as if they were passed by
|
|
412 reference.
|
|
413
|
|
414 -- Capitalize macros that evaluate *any* argument more than once regardless
|
|
415 of whether that's "allowed" (e.g. buffer arguments).
|
|
416
|
|
417 -- Capitalize macros that directly access a field in a Lisp_Object or
|
|
418 its equivalent underlying structure. In such cases, access through the
|
|
419 Lisp_Object precedes the macro with an X, and access through the underlying
|
|
420 structure doesn't.
|
|
421
|
|
422 -- Capitalize certain other basic macros relating to Lisp_Objects; e.g.
|
|
423 FRAMEP, CHECK_FRAME, etc.
|
|
424
|
|
425 -- Try to avoid capitalizing any other macros.
|
771
|
426 */
|
|
427
|
|
428 /* ---------------------------------------------------------------------- */
|
867
|
429 /* Working with itext's (pointers to internally-formatted text) */
|
771
|
430 /* ---------------------------------------------------------------------- */
|
|
431
|
867
|
432 /* Given an itext, does it point to the beginning of a character?
|
826
|
433 */
|
|
434
|
771
|
435 #ifdef MULE
|
867
|
436 # define valid_ibyteptr_p(ptr) ibyte_first_byte_p (* (ptr))
|
771
|
437 #else
|
867
|
438 # define valid_ibyteptr_p(ptr) 1
|
771
|
439 #endif
|
|
440
|
867
|
441 /* If error-checking is enabled, assert that the given itext points to
|
826
|
442 the beginning of a character. Otherwise, do nothing.
|
|
443 */
|
|
444
|
867
|
445 #define assert_valid_ibyteptr(ptr) text_checking_assert (valid_ibyteptr_p (ptr))
|
|
446
|
|
447 /* Given a itext (assumed to point at the beginning of a character),
|
826
|
448 modify that pointer so it points to the beginning of the next character.
|
|
449
|
867
|
450 Note that INC_IBYTEPTR() and DEC_IBYTEPTR() have to be written in
|
|
451 completely separate ways. INC_IBYTEPTR() cannot use the DEC_IBYTEPTR()
|
771
|
452 trick of looking for a valid first byte because it might run off
|
867
|
453 the end of the string. DEC_IBYTEPTR() can't use the INC_IBYTEPTR()
|
771
|
454 method because it doesn't have easy access to the first byte of
|
|
455 the character it's moving over. */
|
|
456
|
867
|
457 #define INC_IBYTEPTR(ptr) do { \
|
|
458 assert_valid_ibyteptr (ptr); \
|
826
|
459 (ptr) += rep_bytes_by_first_byte (* (ptr)); \
|
|
460 } while (0)
|
|
461
|
1204
|
462 #define INC_IBYTEPTR_FMT(ptr, fmt) \
|
|
463 do { \
|
|
464 Internal_Format __icf_fmt = (fmt); \
|
|
465 switch (__icf_fmt) \
|
|
466 { \
|
|
467 case FORMAT_DEFAULT: \
|
|
468 INC_IBYTEPTR (ptr); \
|
|
469 break; \
|
|
470 case FORMAT_16_BIT_FIXED: \
|
|
471 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_16_BIT)); \
|
|
472 (ptr) += 2; \
|
|
473 break; \
|
|
474 case FORMAT_32_BIT_FIXED: \
|
|
475 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_32_BIT)); \
|
|
476 (ptr) += 4; \
|
|
477 break; \
|
|
478 default: \
|
|
479 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); \
|
|
480 (ptr)++; \
|
|
481 break; \
|
|
482 } \
|
826
|
483 } while (0)
|
|
484
|
867
|
485 /* Given a itext (assumed to point at the beginning of a character or at
|
826
|
486 the very end of the text), modify that pointer so it points to the
|
|
487 beginning of the previous character.
|
|
488 */
|
771
|
489
|
800
|
490 #ifdef ERROR_CHECK_TEXT
|
826
|
491 /* We use a separate definition to avoid warnings about unused dc_ptr1 */
|
867
|
492 #define DEC_IBYTEPTR(ptr) do { \
|
1333
|
493 const Ibyte *dc_ptr1 = (ptr); \
|
826
|
494 do { \
|
|
495 (ptr)--; \
|
867
|
496 } while (!valid_ibyteptr_p (ptr)); \
|
826
|
497 text_checking_assert (dc_ptr1 - (ptr) == rep_bytes_by_first_byte (*(ptr))); \
|
771
|
498 } while (0)
|
826
|
499 #else
|
867
|
500 #define DEC_IBYTEPTR(ptr) do { \
|
826
|
501 do { \
|
|
502 (ptr)--; \
|
867
|
503 } while (!valid_ibyteptr_p (ptr)); \
|
771
|
504 } while (0)
|
826
|
505 #endif /* ERROR_CHECK_TEXT */
|
|
506
|
1204
|
507 #define DEC_IBYTEPTR_FMT(ptr, fmt) \
|
|
508 do { \
|
|
509 Internal_Format __icf_fmt = (fmt); \
|
|
510 switch (__icf_fmt) \
|
|
511 { \
|
|
512 case FORMAT_DEFAULT: \
|
|
513 DEC_IBYTEPTR (ptr); \
|
|
514 break; \
|
|
515 case FORMAT_16_BIT_FIXED: \
|
|
516 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_16_BIT)); \
|
|
517 (ptr) -= 2; \
|
|
518 break; \
|
|
519 case FORMAT_32_BIT_FIXED: \
|
|
520 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_32_BIT)); \
|
|
521 (ptr) -= 4; \
|
|
522 break; \
|
|
523 default: \
|
|
524 text_checking_assert (fmt == FORMAT_8_BIT_FIXED); \
|
|
525 (ptr)--; \
|
|
526 break; \
|
|
527 } \
|
771
|
528 } while (0)
|
|
529
|
|
530 #ifdef MULE
|
|
531
|
826
|
532 /* Make sure that PTR is pointing to the beginning of a character. If not,
|
|
533 back up until this is the case. Note that there are not too many places
|
|
534 where it is legitimate to do this sort of thing. It's an error if
|
|
535 you're passed an "invalid" char * pointer. NOTE: PTR *must* be pointing
|
|
536 to a valid part of the string (i.e. not the very end, unless the string
|
|
537 is zero-terminated or something) in order for this function to not cause
|
|
538 crashes.
|
|
539 */
|
|
540
|
771
|
541 /* Note that this reads the byte at *PTR! */
|
|
542
|
867
|
543 #define VALIDATE_IBYTEPTR_BACKWARD(ptr) do { \
|
|
544 while (!valid_ibyteptr_p (ptr)) ptr--; \
|
771
|
545 } while (0)
|
|
546
|
826
|
547 /* Make sure that PTR is pointing to the beginning of a character. If not,
|
|
548 move forward until this is the case. Note that there are not too many
|
|
549 places where it is legitimate to do this sort of thing. It's an error
|
|
550 if you're passed an "invalid" char * pointer.
|
|
551 */
|
771
|
552
|
867
|
553 /* This needs to be trickier than VALIDATE_IBYTEPTR_BACKWARD() to avoid the
|
771
|
554 possibility of running off the end of the string. */
|
|
555
|
867
|
556 #define VALIDATE_IBYTEPTR_FORWARD(ptr) do { \
|
|
557 Ibyte *vcf_ptr = (ptr); \
|
|
558 VALIDATE_IBYTEPTR_BACKWARD (vcf_ptr); \
|
771
|
559 if (vcf_ptr != (ptr)) \
|
|
560 { \
|
|
561 (ptr) = vcf_ptr; \
|
867
|
562 INC_IBYTEPTR (ptr); \
|
771
|
563 } \
|
|
564 } while (0)
|
|
565
|
|
566 #else /* not MULE */
|
867
|
567 #define VALIDATE_IBYTEPTR_BACKWARD(ptr)
|
|
568 #define VALIDATE_IBYTEPTR_FORWARD(ptr)
|
826
|
569 #endif /* not MULE */
|
|
570
|
|
571 #ifdef MULE
|
|
572
|
867
|
573 /* Given a Ibyte string at PTR of size N, possibly with a partial
|
826
|
574 character at the end, return the size of the longest substring of
|
|
575 complete characters. Does not assume that the byte at *(PTR + N) is
|
|
576 readable. Note that there are not too many places where it is
|
|
577 legitimate to do this sort of thing. It's an error if you're passed an
|
|
578 "invalid" offset. */
|
|
579
|
|
580 DECLARE_INLINE_HEADER (
|
|
581 Bytecount
|
867
|
582 validate_ibyte_string_backward (const Ibyte *ptr, Bytecount n)
|
826
|
583 )
|
|
584 {
|
867
|
585 const Ibyte *ptr2;
|
826
|
586
|
|
587 if (n == 0)
|
|
588 return n;
|
|
589 ptr2 = ptr + n - 1;
|
867
|
590 VALIDATE_IBYTEPTR_BACKWARD (ptr2);
|
826
|
591 if (ptr2 + rep_bytes_by_first_byte (*ptr2) != ptr + n)
|
|
592 return ptr2 - ptr;
|
|
593 return n;
|
|
594 }
|
|
595
|
|
596 #else
|
|
597
|
867
|
598 #define validate_ibyte_string_backward(ptr, n) (n)
|
826
|
599
|
|
600 #endif /* MULE */
|
771
|
601
|
|
602 /* -------------------------------------------------------------- */
|
826
|
603 /* Working with the length (in bytes and characters) of a */
|
|
604 /* section of internally-formatted text */
|
771
|
605 /* -------------------------------------------------------------- */
|
|
606
|
826
|
607 #ifdef MULE
|
|
608
|
1632
|
609 MODULE_API Charcount
|
|
610 bytecount_to_charcount_fun (const Ibyte *ptr, Bytecount len);
|
|
611 MODULE_API Bytecount
|
|
612 charcount_to_bytecount_fun (const Ibyte *ptr, Charcount len);
|
826
|
613
|
|
614 /* Given a pointer to a text string and a length in bytes, return
|
|
615 the equivalent length in characters. */
|
|
616
|
|
617 DECLARE_INLINE_HEADER (
|
|
618 Charcount
|
867
|
619 bytecount_to_charcount (const Ibyte *ptr, Bytecount len)
|
826
|
620 )
|
|
621 {
|
|
622 if (len < 20) /* Just a random guess, but it should be more or less correct.
|
|
623 If number of bytes is small, just do a simple loop,
|
|
624 which should be more efficient. */
|
|
625 {
|
|
626 Charcount count = 0;
|
867
|
627 const Ibyte *end = ptr + len;
|
826
|
628 while (ptr < end)
|
|
629 {
|
867
|
630 INC_IBYTEPTR (ptr);
|
826
|
631 count++;
|
|
632 }
|
|
633 /* Bomb out if the specified substring ends in the middle
|
|
634 of a character. Note that we might have already gotten
|
|
635 a core dump above from an invalid reference, but at least
|
|
636 we will get no farther than here.
|
|
637
|
|
638 This also catches len < 0. */
|
|
639 text_checking_assert (ptr == end);
|
|
640
|
|
641 return count;
|
|
642 }
|
|
643 else
|
|
644 return bytecount_to_charcount_fun (ptr, len);
|
|
645 }
|
|
646
|
|
647 /* Given a pointer to a text string and a length in characters, return the
|
|
648 equivalent length in bytes.
|
|
649 */
|
|
650
|
|
651 DECLARE_INLINE_HEADER (
|
|
652 Bytecount
|
867
|
653 charcount_to_bytecount (const Ibyte *ptr, Charcount len)
|
826
|
654 )
|
|
655 {
|
|
656 text_checking_assert (len >= 0);
|
|
657 if (len < 20) /* See above */
|
|
658 {
|
867
|
659 const Ibyte *newptr = ptr;
|
826
|
660 while (len > 0)
|
|
661 {
|
867
|
662 INC_IBYTEPTR (newptr);
|
826
|
663 len--;
|
|
664 }
|
|
665 return newptr - ptr;
|
|
666 }
|
|
667 else
|
|
668 return charcount_to_bytecount_fun (ptr, len);
|
|
669 }
|
|
670
|
|
671 /* Given a pointer to a text string in the specified format and a length in
|
|
672 bytes, return the equivalent length in characters.
|
|
673 */
|
|
674
|
|
675 DECLARE_INLINE_HEADER (
|
|
676 Charcount
|
867
|
677 bytecount_to_charcount_fmt (const Ibyte *ptr, Bytecount len,
|
826
|
678 Internal_Format fmt)
|
|
679 )
|
|
680 {
|
|
681 switch (fmt)
|
|
682 {
|
|
683 case FORMAT_DEFAULT:
|
|
684 return bytecount_to_charcount (ptr, len);
|
|
685 case FORMAT_16_BIT_FIXED:
|
1204
|
686 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_16_BIT));
|
826
|
687 return (Charcount) (len << 1);
|
|
688 case FORMAT_32_BIT_FIXED:
|
1204
|
689 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_32_BIT));
|
826
|
690 return (Charcount) (len << 2);
|
|
691 default:
|
|
692 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
|
693 return (Charcount) len;
|
|
694 }
|
|
695 }
|
|
696
|
|
697 /* Given a pointer to a text string in the specified format and a length in
|
|
698 characters, return the equivalent length in bytes.
|
|
699 */
|
|
700
|
|
701 DECLARE_INLINE_HEADER (
|
|
702 Bytecount
|
867
|
703 charcount_to_bytecount_fmt (const Ibyte *ptr, Charcount len,
|
826
|
704 Internal_Format fmt)
|
|
705 )
|
|
706 {
|
|
707 switch (fmt)
|
|
708 {
|
|
709 case FORMAT_DEFAULT:
|
|
710 return charcount_to_bytecount (ptr, len);
|
|
711 case FORMAT_16_BIT_FIXED:
|
1204
|
712 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_16_BIT));
|
826
|
713 text_checking_assert (!(len & 1));
|
|
714 return (Bytecount) (len >> 1);
|
|
715 case FORMAT_32_BIT_FIXED:
|
|
716 text_checking_assert (!(len & 3));
|
1204
|
717 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_32_BIT));
|
826
|
718 return (Bytecount) (len >> 2);
|
|
719 default:
|
|
720 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
|
721 return (Bytecount) len;
|
|
722 }
|
|
723 }
|
|
724
|
|
725 #else
|
|
726
|
|
727 #define bytecount_to_charcount(ptr, len) ((Charcount) (len))
|
|
728 #define bytecount_to_charcount_fmt(ptr, len, fmt) ((Charcount) (len))
|
|
729 #define charcount_to_bytecount(ptr, len) ((Bytecount) (len))
|
|
730 #define charcount_to_bytecount_fmt(ptr, len, fmt) ((Bytecount) (len))
|
|
731
|
|
732 #endif /* MULE */
|
|
733
|
|
734 /* Return the length of the first character at PTR. Equivalent to
|
|
735 charcount_to_bytecount (ptr, 1).
|
|
736
|
|
737 [Since charcount_to_bytecount() is Written as inline, a smart compiler
|
|
738 should really optimize charcount_to_bytecount (ptr, 1) to the same as
|
|
739 the following, with no error checking. But since this idiom occurs so
|
|
740 often, we'll be helpful and define a special macro for it.]
|
|
741 */
|
|
742
|
867
|
743 #define itext_ichar_len(ptr) rep_bytes_by_first_byte (*(ptr))
|
826
|
744
|
|
745 /* Return the length of the first character at PTR, which is in the
|
|
746 specified internal format. Equivalent to charcount_to_bytecount_fmt
|
|
747 (ptr, 1, fmt).
|
|
748 */
|
|
749
|
|
750 DECLARE_INLINE_HEADER (
|
|
751 Bytecount
|
867
|
752 itext_ichar_len_fmt (const Ibyte *ptr, Internal_Format fmt)
|
826
|
753 )
|
|
754 {
|
|
755 switch (fmt)
|
|
756 {
|
|
757 case FORMAT_DEFAULT:
|
867
|
758 return itext_ichar_len (ptr);
|
826
|
759 case FORMAT_16_BIT_FIXED:
|
1204
|
760 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_16_BIT));
|
826
|
761 return 2;
|
|
762 case FORMAT_32_BIT_FIXED:
|
1204
|
763 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_32_BIT));
|
826
|
764 return 4;
|
|
765 default:
|
|
766 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
|
767 return 1;
|
|
768 }
|
|
769 }
|
|
770
|
|
771 /* Return a pointer to the beginning of the character offset N (in
|
|
772 characters) from PTR.
|
|
773 */
|
|
774
|
|
775 DECLARE_INLINE_HEADER (
|
867
|
776 const Ibyte *
|
|
777 itext_n_addr (const Ibyte *ptr, Charcount offset)
|
826
|
778 )
|
771
|
779 {
|
|
780 return ptr + charcount_to_bytecount (ptr, offset);
|
|
781 }
|
|
782
|
867
|
783 /* Given a itext and an offset into the text pointed to by the itext,
|
826
|
784 modify the offset so it points to the beginning of the next character.
|
|
785 */
|
|
786
|
|
787 #define INC_BYTECOUNT(ptr, pos) do { \
|
867
|
788 assert_valid_ibyteptr (ptr); \
|
826
|
789 (pos += rep_bytes_by_first_byte (* ((ptr) + (pos)))); \
|
|
790 } while (0)
|
|
791
|
771
|
792 /* -------------------------------------------------------------------- */
|
867
|
793 /* Retrieving or changing the character pointed to by a itext */
|
771
|
794 /* -------------------------------------------------------------------- */
|
|
795
|
867
|
796 #define simple_itext_ichar(ptr) ((Ichar) (ptr)[0])
|
|
797 #define simple_set_itext_ichar(ptr, x) \
|
|
798 ((ptr)[0] = (Ibyte) (x), (Bytecount) 1)
|
|
799 #define simple_itext_copy_ichar(src, dst) \
|
814
|
800 ((dst)[0] = *(src), (Bytecount) 1)
|
771
|
801
|
|
802 #ifdef MULE
|
|
803
|
1632
|
804 MODULE_API Ichar non_ascii_itext_ichar (const Ibyte *ptr);
|
|
805 MODULE_API Bytecount non_ascii_set_itext_ichar (Ibyte *ptr, Ichar c);
|
|
806 MODULE_API Bytecount non_ascii_itext_copy_ichar (const Ibyte *src, Ibyte *dst);
|
867
|
807
|
|
808 /* Retrieve the character pointed to by PTR as an Ichar. */
|
826
|
809
|
|
810 DECLARE_INLINE_HEADER (
|
867
|
811 Ichar
|
|
812 itext_ichar (const Ibyte *ptr)
|
826
|
813 )
|
771
|
814 {
|
826
|
815 return byte_ascii_p (*ptr) ?
|
867
|
816 simple_itext_ichar (ptr) :
|
|
817 non_ascii_itext_ichar (ptr);
|
771
|
818 }
|
|
819
|
826
|
820 /* Retrieve the character pointed to by PTR (a pointer to text in the
|
|
821 format FMT, coming from OBJECT [a buffer, string?, or nil]) as an
|
867
|
822 Ichar.
|
826
|
823
|
|
824 Note: For these and other *_fmt() functions, if you pass in a constant
|
|
825 FMT, the switch will be optimized out of existence. Therefore, there is
|
|
826 no need to create separate versions for the various formats for
|
867
|
827 "efficiency reasons". In fact, we don't really need itext_ichar()
|
826
|
828 and such written separately, but they are used often so it's simpler
|
|
829 that way. */
|
|
830
|
|
831 DECLARE_INLINE_HEADER (
|
867
|
832 Ichar
|
|
833 itext_ichar_fmt (const Ibyte *ptr, Internal_Format fmt,
|
826
|
834 Lisp_Object object)
|
|
835 )
|
|
836 {
|
|
837 switch (fmt)
|
|
838 {
|
|
839 case FORMAT_DEFAULT:
|
867
|
840 return itext_ichar (ptr);
|
826
|
841 case FORMAT_16_BIT_FIXED:
|
1204
|
842 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_16_BIT));
|
867
|
843 return raw_16_bit_fixed_to_ichar (* (UINT_16_BIT *) ptr, object);
|
826
|
844 case FORMAT_32_BIT_FIXED:
|
1204
|
845 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_32_BIT));
|
867
|
846 return raw_32_bit_fixed_to_ichar (* (UINT_32_BIT *) ptr, object);
|
826
|
847 default:
|
|
848 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
867
|
849 return raw_8_bit_fixed_to_ichar (*ptr, object);
|
826
|
850 }
|
|
851 }
|
|
852
|
|
853 /* Return the character at PTR (which is in format FMT), suitable for
|
|
854 comparison with an ASCII character. This guarantees that if the
|
|
855 character at PTR is ASCII (range 0 - 127), that character will be
|
|
856 returned; otherwise, some character outside of the ASCII range will be
|
|
857 returned, but not necessarily the character actually at PTR. This will
|
867
|
858 be faster than itext_ichar_fmt() for some formats -- in particular,
|
826
|
859 FORMAT_DEFAULT. */
|
|
860
|
|
861 DECLARE_INLINE_HEADER (
|
867
|
862 Ichar
|
|
863 itext_ichar_ascii_fmt (const Ibyte *ptr, Internal_Format fmt,
|
826
|
864 Lisp_Object object)
|
|
865 )
|
|
866 {
|
|
867 switch (fmt)
|
|
868 {
|
|
869 case FORMAT_DEFAULT:
|
867
|
870 return (Ichar) *ptr;
|
826
|
871 case FORMAT_16_BIT_FIXED:
|
1204
|
872 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_16_BIT));
|
867
|
873 return raw_16_bit_fixed_to_ichar (* (UINT_16_BIT *) ptr, object);
|
826
|
874 case FORMAT_32_BIT_FIXED:
|
1204
|
875 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_32_BIT));
|
867
|
876 return raw_32_bit_fixed_to_ichar (* (UINT_32_BIT *) ptr, object);
|
826
|
877 default:
|
|
878 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
867
|
879 return raw_8_bit_fixed_to_ichar (*ptr, object);
|
826
|
880 }
|
|
881 }
|
|
882
|
|
883 /* Return the "raw value" of the character at PTR, in format FMT. This is
|
|
884 useful when searching for a character; convert the character using
|
867
|
885 ichar_to_raw(). */
|
826
|
886
|
|
887 DECLARE_INLINE_HEADER (
|
867
|
888 Raw_Ichar
|
|
889 itext_ichar_raw_fmt (const Ibyte *ptr, Internal_Format fmt)
|
826
|
890 )
|
|
891 {
|
|
892 switch (fmt)
|
|
893 {
|
|
894 case FORMAT_DEFAULT:
|
867
|
895 return (Raw_Ichar) itext_ichar (ptr);
|
826
|
896 case FORMAT_16_BIT_FIXED:
|
1204
|
897 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_16_BIT));
|
867
|
898 return (Raw_Ichar) (* (UINT_16_BIT *) ptr);
|
826
|
899 case FORMAT_32_BIT_FIXED:
|
1204
|
900 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_32_BIT));
|
867
|
901 return (Raw_Ichar) (* (UINT_32_BIT *) ptr);
|
826
|
902 default:
|
|
903 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
867
|
904 return (Raw_Ichar) (*ptr);
|
826
|
905 }
|
|
906 }
|
|
907
|
867
|
908 /* Store the character CH (an Ichar) as internally-formatted text starting
|
826
|
909 at PTR. Return the number of bytes stored.
|
|
910 */
|
|
911
|
|
912 DECLARE_INLINE_HEADER (
|
|
913 Bytecount
|
867
|
914 set_itext_ichar (Ibyte *ptr, Ichar x)
|
826
|
915 )
|
771
|
916 {
|
867
|
917 return !ichar_multibyte_p (x) ?
|
|
918 simple_set_itext_ichar (ptr, x) :
|
|
919 non_ascii_set_itext_ichar (ptr, x);
|
771
|
920 }
|
|
921
|
867
|
922 /* Store the character CH (an Ichar) as internally-formatted text of
|
826
|
923 format FMT starting at PTR, which comes from OBJECT. Return the number
|
|
924 of bytes stored.
|
|
925 */
|
|
926
|
|
927 DECLARE_INLINE_HEADER (
|
|
928 Bytecount
|
867
|
929 set_itext_ichar_fmt (Ibyte *ptr, Ichar x, Internal_Format fmt,
|
826
|
930 Lisp_Object object)
|
|
931 )
|
771
|
932 {
|
826
|
933 switch (fmt)
|
|
934 {
|
|
935 case FORMAT_DEFAULT:
|
867
|
936 return set_itext_ichar (ptr, x);
|
826
|
937 case FORMAT_16_BIT_FIXED:
|
867
|
938 text_checking_assert (ichar_16_bit_fixed_p (x, object));
|
1204
|
939 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_16_BIT));
|
867
|
940 * (UINT_16_BIT *) ptr = ichar_to_raw_16_bit_fixed (x, object);
|
826
|
941 return 2;
|
|
942 case FORMAT_32_BIT_FIXED:
|
1204
|
943 text_checking_assert ((void *) ptr == ALIGN_PTR (ptr, UINT_32_BIT));
|
867
|
944 * (UINT_32_BIT *) ptr = ichar_to_raw_32_bit_fixed (x, object);
|
826
|
945 return 4;
|
|
946 default:
|
|
947 text_checking_assert (fmt == FORMAT_8_BIT_FIXED);
|
867
|
948 text_checking_assert (ichar_8_bit_fixed_p (x, object));
|
|
949 *ptr = ichar_to_raw_8_bit_fixed (x, object);
|
826
|
950 return 1;
|
|
951 }
|
|
952 }
|
|
953
|
|
954 /* Retrieve the character pointed to by SRC and store it as
|
|
955 internally-formatted text in DST.
|
|
956 */
|
|
957
|
|
958 DECLARE_INLINE_HEADER (
|
|
959 Bytecount
|
867
|
960 itext_copy_ichar (const Ibyte *src, Ibyte *dst)
|
826
|
961 )
|
|
962 {
|
|
963 return byte_ascii_p (*src) ?
|
867
|
964 simple_itext_copy_ichar (src, dst) :
|
|
965 non_ascii_itext_copy_ichar (src, dst);
|
771
|
966 }
|
|
967
|
|
968 #else /* not MULE */
|
|
969
|
867
|
970 # define itext_ichar(ptr) simple_itext_ichar (ptr)
|
|
971 # define itext_ichar_fmt(ptr, fmt, object) itext_ichar (ptr)
|
|
972 # define itext_ichar_ascii_fmt(ptr, fmt, object) itext_ichar (ptr)
|
|
973 # define itext_ichar_raw_fmt(ptr, fmt) itext_ichar (ptr)
|
|
974 # define set_itext_ichar(ptr, x) simple_set_itext_ichar (ptr, x)
|
|
975 # define set_itext_ichar_fmt(ptr, x, fmt, obj) set_itext_ichar (ptr, x)
|
|
976 # define itext_copy_ichar(src, dst) simple_itext_copy_ichar (src, dst)
|
771
|
977
|
|
978 #endif /* not MULE */
|
|
979
|
826
|
980 /* Retrieve the character at offset N (in characters) from PTR, as an
|
867
|
981 Ichar.
|
826
|
982 */
|
|
983
|
867
|
984 #define itext_ichar_n(ptr, offset) \
|
|
985 itext_ichar (itext_n_addr (ptr, offset))
|
771
|
986
|
|
987
|
|
988 /* ---------------------------- */
|
867
|
989 /* Working with Ichars */
|
771
|
990 /* ---------------------------- */
|
|
991
|
867
|
992 /* NOTE: There are other functions/macros for working with Ichars in
|
|
993 charset.h, for retrieving the charset of an Ichar, the length of an
|
|
994 Ichar when converted to text, etc.
|
826
|
995 */
|
|
996
|
771
|
997 #ifdef MULE
|
|
998
|
1632
|
999 MODULE_API int non_ascii_valid_ichar_p (Ichar ch);
|
867
|
1000
|
|
1001 /* Return whether the given Ichar is valid.
|
826
|
1002 */
|
|
1003
|
|
1004 DECLARE_INLINE_HEADER (
|
|
1005 int
|
867
|
1006 valid_ichar_p (Ichar ch)
|
826
|
1007 )
|
771
|
1008 {
|
867
|
1009 return (! (ch & ~0xFF)) || non_ascii_valid_ichar_p (ch);
|
771
|
1010 }
|
|
1011
|
|
1012 #else /* not MULE */
|
|
1013
|
867
|
1014 #define valid_ichar_p(ch) (! (ch & ~0xFF))
|
771
|
1015
|
|
1016 #endif /* not MULE */
|
|
1017
|
831
|
1018 DECLARE_INLINE_HEADER (
|
|
1019 Lisp_Object
|
867
|
1020 make_char (Ichar val)
|
831
|
1021 )
|
|
1022 {
|
867
|
1023 type_checking_assert (valid_ichar_p (val));
|
831
|
1024 return make_char_1 (val);
|
|
1025 }
|
|
1026
|
867
|
1027 #define CHAR_INTP(x) (INTP (x) && valid_ichar_p (XINT (x)))
|
771
|
1028
|
|
1029 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
|
|
1030
|
826
|
1031 DECLARE_INLINE_HEADER (
|
867
|
1032 Ichar
|
771
|
1033 XCHAR_OR_CHAR_INT (Lisp_Object obj)
|
826
|
1034 )
|
771
|
1035 {
|
|
1036 return CHARP (obj) ? XCHAR (obj) : XINT (obj);
|
|
1037 }
|
|
1038
|
826
|
1039 /* Signal an error if CH is not a valid character or integer Lisp_Object.
|
|
1040 If CH is an integer Lisp_Object, convert it to a character Lisp_Object,
|
|
1041 but merely by repackaging, without performing tests for char validity.
|
|
1042 */
|
|
1043
|
771
|
1044 #define CHECK_CHAR_COERCE_INT(x) do { \
|
|
1045 if (CHARP (x)) \
|
|
1046 ; \
|
|
1047 else if (CHAR_INTP (x)) \
|
|
1048 x = make_char (XINT (x)); \
|
|
1049 else \
|
|
1050 x = wrong_type_argument (Qcharacterp, x); \
|
|
1051 } while (0)
|
|
1052
|
|
1053
|
|
1054
|
|
1055 /************************************************************************/
|
|
1056 /* */
|
826
|
1057 /* working with Lisp strings */
|
|
1058 /* */
|
|
1059 /************************************************************************/
|
|
1060
|
|
1061 #define string_char_length(s) \
|
|
1062 string_index_byte_to_char (s, XSTRING_LENGTH (s))
|
|
1063 #define string_byte(s, i) (XSTRING_DATA (s)[i] + 0)
|
|
1064 /* In case we ever allow strings to be in a different format ... */
|
|
1065 #define set_string_byte(s, i, c) (XSTRING_DATA (s)[i] = (c))
|
|
1066
|
|
1067 #define ASSERT_VALID_CHAR_STRING_INDEX_UNSAFE(s, x) do { \
|
|
1068 text_checking_assert ((x) >= 0 && x <= string_char_length (s)); \
|
|
1069 } while (0)
|
|
1070
|
|
1071 #define ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE(s, x) do { \
|
|
1072 text_checking_assert ((x) >= 0 && x <= XSTRING_LENGTH (s)); \
|
867
|
1073 text_checking_assert (valid_ibyteptr_p (string_byte_addr (s, x))); \
|
826
|
1074 } while (0)
|
|
1075
|
|
1076 /* Convert offset I in string S to a pointer to text there. */
|
|
1077 #define string_byte_addr(s, i) (&(XSTRING_DATA (s)[i]))
|
|
1078 /* Convert pointer to text in string S into the byte offset to that text. */
|
|
1079 #define string_addr_to_byte(s, ptr) ((Bytecount) ((ptr) - XSTRING_DATA (s)))
|
867
|
1080 /* Return the Ichar at *CHARACTER* offset I. */
|
|
1081 #define string_ichar(s, i) itext_ichar (string_char_addr (s, i))
|
826
|
1082
|
|
1083 #ifdef ERROR_CHECK_TEXT
|
|
1084 #define SLEDGEHAMMER_CHECK_ASCII_BEGIN
|
|
1085 #endif
|
|
1086
|
|
1087 #ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN
|
|
1088 void sledgehammer_check_ascii_begin (Lisp_Object str);
|
|
1089 #else
|
|
1090 #define sledgehammer_check_ascii_begin(str)
|
|
1091 #endif
|
|
1092
|
|
1093 /* Make an alloca'd copy of a Lisp string */
|
|
1094 #define LISP_STRING_TO_ALLOCA(s, lval) \
|
|
1095 do { \
|
1315
|
1096 Ibyte **_lta_ = (Ibyte **) &(lval); \
|
826
|
1097 Lisp_Object _lta_2 = (s); \
|
867
|
1098 *_lta_ = alloca_array (Ibyte, 1 + XSTRING_LENGTH (_lta_2)); \
|
826
|
1099 memcpy (*_lta_, XSTRING_DATA (_lta_2), 1 + XSTRING_LENGTH (_lta_2)); \
|
|
1100 } while (0)
|
|
1101
|
1449
|
1102 /* Make an alloca'd copy of a Ibyte * */
|
867
|
1103 #define IBYTE_STRING_TO_ALLOCA(p, lval) \
|
1315
|
1104 do { \
|
867
|
1105 Ibyte **_bsta_ = (Ibyte **) &(lval); \
|
1315
|
1106 const Ibyte *_bsta_2 = (p); \
|
|
1107 Bytecount _bsta_3 = qxestrlen (_bsta_2); \
|
867
|
1108 *_bsta_ = alloca_array (Ibyte, 1 + _bsta_3); \
|
1315
|
1109 memcpy (*_bsta_, _bsta_2, 1 + _bsta_3); \
|
826
|
1110 } while (0)
|
|
1111
|
851
|
1112
|
867
|
1113 #define alloca_ibytes(num) alloca_array (Ibyte, num)
|
826
|
1114 #define alloca_extbytes(num) alloca_array (Extbyte, num)
|
|
1115
|
|
1116 void resize_string (Lisp_Object s, Bytecount pos, Bytecount delta);
|
|
1117
|
|
1118 /* Convert a byte index into a string into a char index. */
|
|
1119 DECLARE_INLINE_HEADER (
|
|
1120 Charcount
|
|
1121 string_index_byte_to_char (Lisp_Object s, Bytecount idx)
|
|
1122 )
|
|
1123 {
|
|
1124 Charcount retval;
|
|
1125 ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE (s, idx);
|
|
1126 #ifdef MULE
|
|
1127 if (idx <= (Bytecount) XSTRING_ASCII_BEGIN (s))
|
|
1128 retval = (Charcount) idx;
|
|
1129 else
|
|
1130 retval = (XSTRING_ASCII_BEGIN (s) +
|
|
1131 bytecount_to_charcount (XSTRING_DATA (s) +
|
|
1132 XSTRING_ASCII_BEGIN (s),
|
|
1133 idx - XSTRING_ASCII_BEGIN (s)));
|
|
1134 # ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN
|
|
1135 assert (retval == bytecount_to_charcount (XSTRING_DATA (s), idx));
|
|
1136 # endif
|
|
1137 #else
|
|
1138 retval = (Charcount) idx;
|
|
1139 #endif
|
|
1140 /* Don't call ASSERT_VALID_CHAR_STRING_INDEX_UNSAFE() here because it will
|
|
1141 call string_index_byte_to_char(). */
|
|
1142 return retval;
|
|
1143 }
|
|
1144
|
|
1145 /* Convert a char index into a string into a byte index. */
|
|
1146 DECLARE_INLINE_HEADER (
|
|
1147 Bytecount
|
|
1148 string_index_char_to_byte (Lisp_Object s, Charcount idx)
|
|
1149 )
|
|
1150 {
|
|
1151 Bytecount retval;
|
|
1152 ASSERT_VALID_CHAR_STRING_INDEX_UNSAFE (s, idx);
|
|
1153 #ifdef MULE
|
|
1154 if (idx <= (Charcount) XSTRING_ASCII_BEGIN (s))
|
|
1155 retval = (Bytecount) idx;
|
|
1156 else
|
|
1157 retval = (XSTRING_ASCII_BEGIN (s) +
|
|
1158 charcount_to_bytecount (XSTRING_DATA (s) +
|
|
1159 XSTRING_ASCII_BEGIN (s),
|
|
1160 idx - XSTRING_ASCII_BEGIN (s)));
|
|
1161 # ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN
|
|
1162 assert (retval == charcount_to_bytecount (XSTRING_DATA (s), idx));
|
|
1163 # endif
|
|
1164 #else
|
|
1165 retval = (Bytecount) idx;
|
|
1166 #endif
|
|
1167 ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE (s, retval);
|
|
1168 return retval;
|
|
1169 }
|
|
1170
|
|
1171 /* Convert a substring length (starting at byte offset OFF) from bytes to
|
|
1172 chars. */
|
|
1173 DECLARE_INLINE_HEADER (
|
|
1174 Charcount
|
|
1175 string_offset_byte_to_char_len (Lisp_Object s, Bytecount off, Bytecount len)
|
|
1176 )
|
|
1177 {
|
|
1178 Charcount retval;
|
|
1179 ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE (s, off);
|
|
1180 ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE (s, off + len);
|
|
1181 #ifdef MULE
|
|
1182 if (off + len <= (Bytecount) XSTRING_ASCII_BEGIN (s))
|
|
1183 retval = (Charcount) len;
|
|
1184 else if (off < (Bytecount) XSTRING_ASCII_BEGIN (s))
|
|
1185 retval =
|
|
1186 XSTRING_ASCII_BEGIN (s) - (Charcount) off +
|
|
1187 bytecount_to_charcount (XSTRING_DATA (s) + XSTRING_ASCII_BEGIN (s),
|
|
1188 len - (XSTRING_ASCII_BEGIN (s) - off));
|
|
1189 else
|
|
1190 retval = bytecount_to_charcount (XSTRING_DATA (s) + off, len);
|
|
1191 # ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN
|
|
1192 assert (retval == bytecount_to_charcount (XSTRING_DATA (s) + off, len));
|
|
1193 # endif
|
|
1194 #else
|
|
1195 retval = (Charcount) len;
|
|
1196 #endif
|
|
1197 return retval;
|
|
1198 }
|
|
1199
|
|
1200 /* Convert a substring length (starting at byte offset OFF) from chars to
|
|
1201 bytes. */
|
|
1202 DECLARE_INLINE_HEADER (
|
|
1203 Bytecount
|
|
1204 string_offset_char_to_byte_len (Lisp_Object s, Bytecount off, Charcount len)
|
|
1205 )
|
|
1206 {
|
|
1207 Bytecount retval;
|
|
1208 ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE (s, off);
|
|
1209 #ifdef MULE
|
|
1210 /* casts to avoid errors from combining Bytecount/Charcount and warnings
|
|
1211 from signed/unsigned comparisons */
|
|
1212 if (off + (Bytecount) len <= (Bytecount) XSTRING_ASCII_BEGIN (s))
|
|
1213 retval = (Bytecount) len;
|
|
1214 else if (off < (Bytecount) XSTRING_ASCII_BEGIN (s))
|
|
1215 retval =
|
|
1216 XSTRING_ASCII_BEGIN (s) - off +
|
|
1217 charcount_to_bytecount (XSTRING_DATA (s) + XSTRING_ASCII_BEGIN (s),
|
|
1218 len - (XSTRING_ASCII_BEGIN (s) -
|
|
1219 (Charcount) off));
|
|
1220 else
|
|
1221 retval = charcount_to_bytecount (XSTRING_DATA (s) + off, len);
|
|
1222 # ifdef SLEDGEHAMMER_CHECK_ASCII_BEGIN
|
|
1223 assert (retval == charcount_to_bytecount (XSTRING_DATA (s) + off, len));
|
|
1224 # endif
|
|
1225 #else
|
|
1226 retval = (Bytecount) len;
|
|
1227 #endif
|
|
1228 ASSERT_VALID_BYTE_STRING_INDEX_UNSAFE (s, off + retval);
|
|
1229 return retval;
|
|
1230 }
|
|
1231
|
|
1232 DECLARE_INLINE_HEADER (
|
867
|
1233 const Ibyte *
|
826
|
1234 string_char_addr (Lisp_Object s, Charcount idx)
|
|
1235 )
|
|
1236 {
|
|
1237 return XSTRING_DATA (s) + string_index_char_to_byte (s, idx);
|
|
1238 }
|
|
1239
|
|
1240 /* WARNING: If you modify an existing string, you must call
|
|
1241 bump_string_modiff() afterwards. */
|
|
1242 #ifdef MULE
|
867
|
1243 void set_string_char (Lisp_Object s, Charcount i, Ichar c);
|
826
|
1244 #else
|
|
1245 #define set_string_char(s, i, c) set_string_byte (s, i, c)
|
|
1246 #endif /* not MULE */
|
|
1247
|
|
1248 /* Return index to character before the one at IDX. */
|
|
1249 DECLARE_INLINE_HEADER (
|
|
1250 Bytecount
|
|
1251 prev_string_index (Lisp_Object s, Bytecount idx)
|
|
1252 )
|
|
1253 {
|
867
|
1254 const Ibyte *ptr = string_byte_addr (s, idx);
|
|
1255 DEC_IBYTEPTR (ptr);
|
826
|
1256 return string_addr_to_byte (s, ptr);
|
|
1257 }
|
|
1258
|
|
1259 /* Return index to character after the one at IDX. */
|
|
1260 DECLARE_INLINE_HEADER (
|
|
1261 Bytecount
|
|
1262 next_string_index (Lisp_Object s, Bytecount idx)
|
|
1263 )
|
|
1264 {
|
867
|
1265 const Ibyte *ptr = string_byte_addr (s, idx);
|
|
1266 INC_IBYTEPTR (ptr);
|
826
|
1267 return string_addr_to_byte (s, ptr);
|
|
1268 }
|
|
1269
|
|
1270
|
|
1271 /************************************************************************/
|
|
1272 /* */
|
771
|
1273 /* working with Eistrings */
|
|
1274 /* */
|
|
1275 /************************************************************************/
|
|
1276
|
|
1277 /*
|
|
1278 #### NOTE: This is a work in progress. Neither the API nor especially
|
|
1279 the implementation is finished.
|
|
1280
|
|
1281 NOTE: An Eistring is a structure that makes it easy to work with
|
|
1282 internally-formatted strings of data. It provides operations similar
|
|
1283 in feel to the standard strcpy(), strcat(), strlen(), etc., but
|
|
1284
|
|
1285 (a) it is Mule-correct
|
|
1286 (b) it does dynamic allocation so you never have to worry about size
|
793
|
1287 restrictions
|
851
|
1288 (c) it comes in an ALLOCA() variety (all allocation is stack-local,
|
793
|
1289 so there is no need to explicitly clean up) as well as a malloc()
|
|
1290 variety
|
|
1291 (d) it knows its own length, so it does not suffer from standard null
|
|
1292 byte brain-damage -- but it null-terminates the data anyway, so
|
|
1293 it can be passed to standard routines
|
|
1294 (e) it provides a much more powerful set of operations and knows about
|
771
|
1295 all the standard places where string data might reside: Lisp_Objects,
|
867
|
1296 other Eistrings, Ibyte * data with or without an explicit length,
|
|
1297 ASCII strings, Ichars, etc.
|
793
|
1298 (f) it provides easy operations to convert to/from externally-formatted
|
|
1299 data, and is easier to use than the standard TO_INTERNAL_FORMAT
|
771
|
1300 and TO_EXTERNAL_FORMAT macros. (An Eistring can store both the internal
|
|
1301 and external version of its data, but the external version is only
|
|
1302 initialized or changed when you call eito_external().)
|
|
1303
|
793
|
1304 The idea is to make it as easy to write Mule-correct string manipulation
|
|
1305 code as it is to write normal string manipulation code. We also make
|
|
1306 the API sufficiently general that it can handle multiple internal data
|
|
1307 formats (e.g. some fixed-width optimizing formats and a default variable
|
|
1308 width format) and allows for *ANY* data format we might choose in the
|
|
1309 future for the default format, including UCS2. (In other words, we can't
|
|
1310 assume that the internal format is ASCII-compatible and we can't assume
|
|
1311 it doesn't have embedded null bytes. We do assume, however, that any
|
|
1312 chosen format will have the concept of null-termination.) All of this is
|
|
1313 hidden from the user.
|
771
|
1314
|
|
1315 #### It is really too bad that we don't have a real object-oriented
|
|
1316 language, or at least a language with polymorphism!
|
|
1317
|
|
1318
|
|
1319 **********************************************
|
|
1320 * Declaration *
|
|
1321 **********************************************
|
|
1322
|
|
1323 To declare an Eistring, either put one of the following in the local
|
|
1324 variable section:
|
|
1325
|
|
1326 DECLARE_EISTRING (name);
|
|
1327 Declare a new Eistring. This is a standard local variable declaration
|
|
1328 and can go anywhere in the variable declaration section. NAME itself
|
|
1329 is declared as an Eistring *, and its storage declared on the stack.
|
|
1330
|
|
1331 DECLARE_EISTRING_MALLOC (name);
|
851
|
1332 Declare a new Eistring, which uses malloc()ed instead of ALLOCA()ed
|
771
|
1333 data. This is a standard local variable declaration and can go
|
|
1334 anywhere in the variable declaration section. Once you initialize
|
|
1335 the Eistring, you will have to free it using eifree() to avoid
|
793
|
1336 memory leaks. You will need to use this form if you are passing
|
|
1337 an Eistring to any function that modifies it (otherwise, the
|
|
1338 modified data may be in stack space and get overwritten when the
|
|
1339 function returns).
|
771
|
1340
|
|
1341 or use
|
|
1342
|
793
|
1343 Eistring ei;
|
|
1344 void eiinit (Eistring *ei);
|
|
1345 void eiinit_malloc (Eistring *einame);
|
771
|
1346 If you need to put an Eistring elsewhere than in a local variable
|
|
1347 declaration (e.g. in a structure), declare it as shown and then
|
|
1348 call one of the init macros.
|
|
1349
|
|
1350 Also note:
|
|
1351
|
793
|
1352 void eifree (Eistring *ei);
|
771
|
1353 If you declared an Eistring to use malloc() to hold its data,
|
|
1354 or converted it to the heap using eito_malloc(), then this
|
|
1355 releases any data in it and afterwards resets the Eistring
|
|
1356 using eiinit_malloc(). Otherwise, it just resets the Eistring
|
|
1357 using eiinit().
|
|
1358
|
|
1359
|
|
1360 **********************************************
|
|
1361 * Conventions *
|
|
1362 **********************************************
|
|
1363
|
|
1364 - The names of the functions have been chosen, where possible, to
|
|
1365 match the names of str*() functions in the standard C API.
|
|
1366 -
|
|
1367
|
|
1368
|
|
1369 **********************************************
|
|
1370 * Initialization *
|
|
1371 **********************************************
|
|
1372
|
|
1373 void eireset (Eistring *eistr);
|
|
1374 Initialize the Eistring to the empty string.
|
|
1375
|
|
1376 void eicpy_* (Eistring *eistr, ...);
|
|
1377 Initialize the Eistring from somewhere:
|
|
1378
|
|
1379 void eicpy_ei (Eistring *eistr, Eistring *eistr2);
|
|
1380 ... from another Eistring.
|
|
1381 void eicpy_lstr (Eistring *eistr, Lisp_Object lisp_string);
|
|
1382 ... from a Lisp_Object string.
|
867
|
1383 void eicpy_ch (Eistring *eistr, Ichar ch);
|
|
1384 ... from an Ichar (this can be a conventional C character).
|
771
|
1385
|
|
1386 void eicpy_lstr_off (Eistring *eistr, Lisp_Object lisp_string,
|
|
1387 Bytecount off, Charcount charoff,
|
|
1388 Bytecount len, Charcount charlen);
|
|
1389 ... from a section of a Lisp_Object string.
|
|
1390 void eicpy_lbuf (Eistring *eistr, Lisp_Object lisp_buf,
|
|
1391 Bytecount off, Charcount charoff,
|
|
1392 Bytecount len, Charcount charlen);
|
|
1393 ... from a section of a Lisp_Object buffer.
|
867
|
1394 void eicpy_raw (Eistring *eistr, const Ibyte *data, Bytecount len);
|
771
|
1395 ... from raw internal-format data in the default internal format.
|
867
|
1396 void eicpy_rawz (Eistring *eistr, const Ibyte *data);
|
771
|
1397 ... from raw internal-format data in the default internal format
|
|
1398 that is "null-terminated" (the meaning of this depends on the nature
|
|
1399 of the default internal format).
|
867
|
1400 void eicpy_raw_fmt (Eistring *eistr, const Ibyte *data, Bytecount len,
|
826
|
1401 Internal_Format intfmt, Lisp_Object object);
|
771
|
1402 ... from raw internal-format data in the specified format.
|
867
|
1403 void eicpy_rawz_fmt (Eistring *eistr, const Ibyte *data,
|
826
|
1404 Internal_Format intfmt, Lisp_Object object);
|
771
|
1405 ... from raw internal-format data in the specified format that is
|
|
1406 "null-terminated" (the meaning of this depends on the nature of
|
|
1407 the specific format).
|
|
1408 void eicpy_c (Eistring *eistr, const Char_ASCII *c_string);
|
|
1409 ... from an ASCII null-terminated string. Non-ASCII characters in
|
|
1410 the string are *ILLEGAL* (read abort() with error-checking defined).
|
|
1411 void eicpy_c_len (Eistring *eistr, const Char_ASCII *c_string, len);
|
|
1412 ... from an ASCII string, with length specified. Non-ASCII characters
|
|
1413 in the string are *ILLEGAL* (read abort() with error-checking defined).
|
|
1414 void eicpy_ext (Eistring *eistr, const Extbyte *extdata,
|
1318
|
1415 Lisp_Object codesys);
|
771
|
1416 ... from external null-terminated data, with coding system specified.
|
|
1417 void eicpy_ext_len (Eistring *eistr, const Extbyte *extdata,
|
1318
|
1418 Bytecount extlen, Lisp_Object codesys);
|
771
|
1419 ... from external data, with length and coding system specified.
|
|
1420 void eicpy_lstream (Eistring *eistr, Lisp_Object lstream);
|
|
1421 ... from an lstream; reads data till eof. Data must be in default
|
|
1422 internal format; otherwise, interpose a decoding lstream.
|
|
1423
|
|
1424
|
|
1425 **********************************************
|
|
1426 * Getting the data out of the Eistring *
|
|
1427 **********************************************
|
|
1428
|
867
|
1429 Ibyte *eidata (Eistring *eistr);
|
771
|
1430 Return a pointer to the raw data in an Eistring. This is NOT
|
|
1431 a copy.
|
|
1432
|
|
1433 Lisp_Object eimake_string (Eistring *eistr);
|
|
1434 Make a Lisp string out of the Eistring.
|
|
1435
|
|
1436 Lisp_Object eimake_string_off (Eistring *eistr,
|
|
1437 Bytecount off, Charcount charoff,
|
|
1438 Bytecount len, Charcount charlen);
|
|
1439 Make a Lisp string out of a section of the Eistring.
|
|
1440
|
867
|
1441 void eicpyout_alloca (Eistring *eistr, LVALUE: Ibyte *ptr_out,
|
771
|
1442 LVALUE: Bytecount len_out);
|
851
|
1443 Make an ALLOCA() copy of the data in the Eistring, using the
|
|
1444 default internal format. Due to the nature of ALLOCA(), this
|
771
|
1445 must be a macro, with all lvalues passed in as parameters.
|
793
|
1446 (More specifically, not all compilers correctly handle using
|
851
|
1447 ALLOCA() as the argument to a function call -- GCC on x86
|
|
1448 didn't used to, for example.) A pointer to the ALLOCA()ed data
|
793
|
1449 is stored in PTR_OUT, and the length of the data (not including
|
|
1450 the terminating zero) is stored in LEN_OUT.
|
771
|
1451
|
867
|
1452 void eicpyout_alloca_fmt (Eistring *eistr, LVALUE: Ibyte *ptr_out,
|
771
|
1453 LVALUE: Bytecount len_out,
|
826
|
1454 Internal_Format intfmt, Lisp_Object object);
|
771
|
1455 Like eicpyout_alloca(), but converts to the specified internal
|
|
1456 format. (No formats other than FORMAT_DEFAULT are currently
|
|
1457 implemented, and you get an assertion failure if you try.)
|
|
1458
|
867
|
1459 Ibyte *eicpyout_malloc (Eistring *eistr, Bytecount *intlen_out);
|
771
|
1460 Make a malloc() copy of the data in the Eistring, using the
|
|
1461 default internal format. This is a real function. No lvalues
|
|
1462 passed in. Returns the new data, and stores the length (not
|
|
1463 including the terminating zero) using INTLEN_OUT, unless it's
|
|
1464 a NULL pointer.
|
|
1465
|
867
|
1466 Ibyte *eicpyout_malloc_fmt (Eistring *eistr, Internal_Format intfmt,
|
826
|
1467 Bytecount *intlen_out, Lisp_Object object);
|
771
|
1468 Like eicpyout_malloc(), but converts to the specified internal
|
|
1469 format. (No formats other than FORMAT_DEFAULT are currently
|
|
1470 implemented, and you get an assertion failure if you try.)
|
|
1471
|
|
1472
|
|
1473 **********************************************
|
|
1474 * Moving to the heap *
|
|
1475 **********************************************
|
|
1476
|
|
1477 void eito_malloc (Eistring *eistr);
|
|
1478 Move this Eistring to the heap. Its data will be stored in a
|
|
1479 malloc()ed block rather than the stack. Subsequent changes to
|
|
1480 this Eistring will realloc() the block as necessary. Use this
|
|
1481 when you want the Eistring to remain in scope past the end of
|
|
1482 this function call. You will have to manually free the data
|
|
1483 in the Eistring using eifree().
|
|
1484
|
|
1485 void eito_alloca (Eistring *eistr);
|
|
1486 Move this Eistring back to the stack, if it was moved to the
|
|
1487 heap with eito_malloc(). This will automatically free any
|
|
1488 heap-allocated data.
|
|
1489
|
|
1490
|
|
1491
|
|
1492 **********************************************
|
|
1493 * Retrieving the length *
|
|
1494 **********************************************
|
|
1495
|
|
1496 Bytecount eilen (Eistring *eistr);
|
|
1497 Return the length of the internal data, in bytes. See also
|
|
1498 eiextlen(), below.
|
|
1499 Charcount eicharlen (Eistring *eistr);
|
|
1500 Return the length of the internal data, in characters.
|
|
1501
|
|
1502
|
|
1503 **********************************************
|
|
1504 * Working with positions *
|
|
1505 **********************************************
|
|
1506
|
|
1507 Bytecount eicharpos_to_bytepos (Eistring *eistr, Charcount charpos);
|
|
1508 Convert a char offset to a byte offset.
|
|
1509 Charcount eibytepos_to_charpos (Eistring *eistr, Bytecount bytepos);
|
|
1510 Convert a byte offset to a char offset.
|
|
1511 Bytecount eiincpos (Eistring *eistr, Bytecount bytepos);
|
|
1512 Increment the given position by one character.
|
|
1513 Bytecount eiincpos_n (Eistring *eistr, Bytecount bytepos, Charcount n);
|
|
1514 Increment the given position by N characters.
|
|
1515 Bytecount eidecpos (Eistring *eistr, Bytecount bytepos);
|
|
1516 Decrement the given position by one character.
|
|
1517 Bytecount eidecpos_n (Eistring *eistr, Bytecount bytepos, Charcount n);
|
|
1518 Deccrement the given position by N characters.
|
|
1519
|
|
1520
|
|
1521 **********************************************
|
|
1522 * Getting the character at a position *
|
|
1523 **********************************************
|
|
1524
|
867
|
1525 Ichar eigetch (Eistring *eistr, Bytecount bytepos);
|
771
|
1526 Return the character at a particular byte offset.
|
867
|
1527 Ichar eigetch_char (Eistring *eistr, Charcount charpos);
|
771
|
1528 Return the character at a particular character offset.
|
|
1529
|
|
1530
|
|
1531 **********************************************
|
|
1532 * Setting the character at a position *
|
|
1533 **********************************************
|
|
1534
|
867
|
1535 Ichar eisetch (Eistring *eistr, Bytecount bytepos, Ichar chr);
|
771
|
1536 Set the character at a particular byte offset.
|
867
|
1537 Ichar eisetch_char (Eistring *eistr, Charcount charpos, Ichar chr);
|
771
|
1538 Set the character at a particular character offset.
|
|
1539
|
|
1540
|
|
1541 **********************************************
|
|
1542 * Concatenation *
|
|
1543 **********************************************
|
|
1544
|
|
1545 void eicat_* (Eistring *eistr, ...);
|
|
1546 Concatenate onto the end of the Eistring, with data coming from the
|
|
1547 same places as above:
|
|
1548
|
|
1549 void eicat_ei (Eistring *eistr, Eistring *eistr2);
|
|
1550 ... from another Eistring.
|
|
1551 void eicat_c (Eistring *eistr, Char_ASCII *c_string);
|
|
1552 ... from an ASCII null-terminated string. Non-ASCII characters in
|
|
1553 the string are *ILLEGAL* (read abort() with error-checking defined).
|
867
|
1554 void eicat_raw (ei, const Ibyte *data, Bytecount len);
|
771
|
1555 ... from raw internal-format data in the default internal format.
|
867
|
1556 void eicat_rawz (ei, const Ibyte *data);
|
771
|
1557 ... from raw internal-format data in the default internal format
|
|
1558 that is "null-terminated" (the meaning of this depends on the nature
|
|
1559 of the default internal format).
|
|
1560 void eicat_lstr (ei, Lisp_Object lisp_string);
|
|
1561 ... from a Lisp_Object string.
|
867
|
1562 void eicat_ch (ei, Ichar ch);
|
|
1563 ... from an Ichar.
|
771
|
1564
|
|
1565 (All except the first variety are convenience functions.
|
|
1566 In the general case, create another Eistring from the source.)
|
|
1567
|
|
1568
|
|
1569 **********************************************
|
|
1570 * Replacement *
|
|
1571 **********************************************
|
|
1572
|
|
1573 void eisub_* (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1574 Bytecount len, Charcount charlen, ...);
|
|
1575 Replace a section of the Eistring, specifically:
|
|
1576
|
|
1577 void eisub_ei (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1578 Bytecount len, Charcount charlen, Eistring *eistr2);
|
|
1579 ... with another Eistring.
|
|
1580 void eisub_c (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1581 Bytecount len, Charcount charlen, Char_ASCII *c_string);
|
|
1582 ... with an ASCII null-terminated string. Non-ASCII characters in
|
|
1583 the string are *ILLEGAL* (read abort() with error-checking defined).
|
|
1584 void eisub_ch (Eistring *eistr, Bytecount off, Charcount charoff,
|
867
|
1585 Bytecount len, Charcount charlen, Ichar ch);
|
|
1586 ... with an Ichar.
|
771
|
1587
|
|
1588 void eidel (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1589 Bytecount len, Charcount charlen);
|
|
1590 Delete a section of the Eistring.
|
|
1591
|
|
1592
|
|
1593 **********************************************
|
|
1594 * Converting to an external format *
|
|
1595 **********************************************
|
|
1596
|
1318
|
1597 void eito_external (Eistring *eistr, Lisp_Object codesys);
|
771
|
1598 Convert the Eistring to an external format and store the result
|
|
1599 in the string. NOTE: Further changes to the Eistring will *NOT*
|
|
1600 change the external data stored in the string. You will have to
|
|
1601 call eito_external() again in such a case if you want the external
|
|
1602 data.
|
|
1603
|
|
1604 Extbyte *eiextdata (Eistring *eistr);
|
|
1605 Return a pointer to the external data stored in the Eistring as
|
|
1606 a result of a prior call to eito_external().
|
|
1607
|
|
1608 Bytecount eiextlen (Eistring *eistr);
|
|
1609 Return the length in bytes of the external data stored in the
|
|
1610 Eistring as a result of a prior call to eito_external().
|
|
1611
|
|
1612
|
|
1613 **********************************************
|
|
1614 * Searching in the Eistring for a character *
|
|
1615 **********************************************
|
|
1616
|
867
|
1617 Bytecount eichr (Eistring *eistr, Ichar chr);
|
|
1618 Charcount eichr_char (Eistring *eistr, Ichar chr);
|
|
1619 Bytecount eichr_off (Eistring *eistr, Ichar chr, Bytecount off,
|
771
|
1620 Charcount charoff);
|
867
|
1621 Charcount eichr_off_char (Eistring *eistr, Ichar chr, Bytecount off,
|
771
|
1622 Charcount charoff);
|
867
|
1623 Bytecount eirchr (Eistring *eistr, Ichar chr);
|
|
1624 Charcount eirchr_char (Eistring *eistr, Ichar chr);
|
|
1625 Bytecount eirchr_off (Eistring *eistr, Ichar chr, Bytecount off,
|
771
|
1626 Charcount charoff);
|
867
|
1627 Charcount eirchr_off_char (Eistring *eistr, Ichar chr, Bytecount off,
|
771
|
1628 Charcount charoff);
|
|
1629
|
|
1630
|
|
1631 **********************************************
|
|
1632 * Searching in the Eistring for a string *
|
|
1633 **********************************************
|
|
1634
|
|
1635 Bytecount eistr_ei (Eistring *eistr, Eistring *eistr2);
|
|
1636 Charcount eistr_ei_char (Eistring *eistr, Eistring *eistr2);
|
|
1637 Bytecount eistr_ei_off (Eistring *eistr, Eistring *eistr2, Bytecount off,
|
|
1638 Charcount charoff);
|
|
1639 Charcount eistr_ei_off_char (Eistring *eistr, Eistring *eistr2,
|
|
1640 Bytecount off, Charcount charoff);
|
|
1641 Bytecount eirstr_ei (Eistring *eistr, Eistring *eistr2);
|
|
1642 Charcount eirstr_ei_char (Eistring *eistr, Eistring *eistr2);
|
|
1643 Bytecount eirstr_ei_off (Eistring *eistr, Eistring *eistr2, Bytecount off,
|
|
1644 Charcount charoff);
|
|
1645 Charcount eirstr_ei_off_char (Eistring *eistr, Eistring *eistr2,
|
|
1646 Bytecount off, Charcount charoff);
|
|
1647
|
|
1648 Bytecount eistr_c (Eistring *eistr, Char_ASCII *c_string);
|
|
1649 Charcount eistr_c_char (Eistring *eistr, Char_ASCII *c_string);
|
|
1650 Bytecount eistr_c_off (Eistring *eistr, Char_ASCII *c_string, Bytecount off,
|
|
1651 Charcount charoff);
|
|
1652 Charcount eistr_c_off_char (Eistring *eistr, Char_ASCII *c_string,
|
|
1653 Bytecount off, Charcount charoff);
|
|
1654 Bytecount eirstr_c (Eistring *eistr, Char_ASCII *c_string);
|
|
1655 Charcount eirstr_c_char (Eistring *eistr, Char_ASCII *c_string);
|
|
1656 Bytecount eirstr_c_off (Eistring *eistr, Char_ASCII *c_string,
|
|
1657 Bytecount off, Charcount charoff);
|
|
1658 Charcount eirstr_c_off_char (Eistring *eistr, Char_ASCII *c_string,
|
|
1659 Bytecount off, Charcount charoff);
|
|
1660
|
|
1661
|
|
1662 **********************************************
|
|
1663 * Comparison *
|
|
1664 **********************************************
|
|
1665
|
|
1666 int eicmp_* (Eistring *eistr, ...);
|
|
1667 int eicmp_off_* (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1668 Bytecount len, Charcount charlen, ...);
|
|
1669 int eicasecmp_* (Eistring *eistr, ...);
|
|
1670 int eicasecmp_off_* (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1671 Bytecount len, Charcount charlen, ...);
|
|
1672 int eicasecmp_i18n_* (Eistring *eistr, ...);
|
|
1673 int eicasecmp_i18n_off_* (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1674 Bytecount len, Charcount charlen, ...);
|
|
1675
|
|
1676 Compare the Eistring with the other data. Return value same as
|
|
1677 from strcmp. The `*' is either `ei' for another Eistring (in
|
|
1678 which case `...' is an Eistring), or `c' for a pure-ASCII string
|
|
1679 (in which case `...' is a pointer to that string). For anything
|
|
1680 more complex, first create an Eistring out of the source.
|
|
1681 Comparison is either simple (`eicmp_...'), ASCII case-folding
|
|
1682 (`eicasecmp_...'), or multilingual case-folding
|
|
1683 (`eicasecmp_i18n_...).
|
|
1684
|
|
1685
|
|
1686 More specifically, the prototypes are:
|
|
1687
|
|
1688 int eicmp_ei (Eistring *eistr, Eistring *eistr2);
|
|
1689 int eicmp_off_ei (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1690 Bytecount len, Charcount charlen, Eistring *eistr2);
|
|
1691 int eicasecmp_ei (Eistring *eistr, Eistring *eistr2);
|
|
1692 int eicasecmp_off_ei (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1693 Bytecount len, Charcount charlen, Eistring *eistr2);
|
|
1694 int eicasecmp_i18n_ei (Eistring *eistr, Eistring *eistr2);
|
|
1695 int eicasecmp_i18n_off_ei (Eistring *eistr, Bytecount off,
|
|
1696 Charcount charoff, Bytecount len,
|
|
1697 Charcount charlen, Eistring *eistr2);
|
|
1698
|
|
1699 int eicmp_c (Eistring *eistr, Char_ASCII *c_string);
|
|
1700 int eicmp_off_c (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1701 Bytecount len, Charcount charlen, Char_ASCII *c_string);
|
|
1702 int eicasecmp_c (Eistring *eistr, Char_ASCII *c_string);
|
|
1703 int eicasecmp_off_c (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1704 Bytecount len, Charcount charlen,
|
|
1705 Char_ASCII *c_string);
|
|
1706 int eicasecmp_i18n_c (Eistring *eistr, Char_ASCII *c_string);
|
|
1707 int eicasecmp_i18n_off_c (Eistring *eistr, Bytecount off, Charcount charoff,
|
|
1708 Bytecount len, Charcount charlen,
|
|
1709 Char_ASCII *c_string);
|
|
1710
|
|
1711
|
|
1712 **********************************************
|
|
1713 * Case-changing the Eistring *
|
|
1714 **********************************************
|
|
1715
|
|
1716 void eilwr (Eistring *eistr);
|
|
1717 Convert all characters in the Eistring to lowercase.
|
|
1718 void eiupr (Eistring *eistr);
|
|
1719 Convert all characters in the Eistring to uppercase.
|
|
1720 */
|
|
1721
|
|
1722
|
|
1723 /* Principles for writing Eistring functions:
|
|
1724
|
|
1725 (1) Unfortunately, we have to write most of the Eistring functions
|
851
|
1726 as macros, because of the use of ALLOCA(). The principle used
|
771
|
1727 below to assure no conflict in local variables is to prefix all
|
|
1728 local variables with "ei" plus a number, which should be unique
|
|
1729 among macros. In practice, when finding a new number, find the
|
|
1730 highest so far used, and add 1.
|
|
1731
|
|
1732 (2) We also suffix the Eistring fields with an _ to avoid problems
|
|
1733 with macro parameters of the same name. (And as the standard
|
|
1734 signal not to access these fields directly.)
|
|
1735
|
|
1736 (3) We maintain both the length in bytes and chars of the data in
|
|
1737 the Eistring at all times, for convenient retrieval by outside
|
|
1738 functions. That means when writing functions that manipulate
|
|
1739 Eistrings, you too need to keep both lengths up to date for all
|
|
1740 data that you work with.
|
|
1741
|
|
1742 (4) When writing a new type of operation (e.g. substitution), you
|
|
1743 will often find yourself working with outside data, and thus
|
|
1744 have a series of related API's, for different forms that the
|
|
1745 outside data is in. Generally, you will want to choose a
|
|
1746 subset of the forms supported by eicpy_*, which has to be
|
|
1747 totally general because that's the fundamental way to get data
|
|
1748 into an Eistring, and once the data is into the string, it
|
|
1749 would be to create a whole series of Ei operations that work on
|
|
1750 nothing but Eistrings. Although theoretically nice, in
|
|
1751 practice it's a hassle, so we suggest that you provide
|
|
1752 convenience functions. In particular, there are two paths you
|
|
1753 can take. One is minimalist -- it only allows other Eistrings
|
867
|
1754 and ASCII data, and Ichars if the particular operation makes
|
771
|
1755 sense with a character. The other provides interfaces for the
|
|
1756 most commonly-used forms -- Eistring, ASCII data, Lisp string,
|
|
1757 raw internal-format string with length, raw internal-format
|
867
|
1758 string without, and possibly Ichar. (In the function names,
|
771
|
1759 these are designated `ei', `c', `lstr', `raw', `rawz', and
|
|
1760 `ch', respectively.)
|
|
1761
|
|
1762 (5) When coding a new type of operation, such as was discussed in
|
|
1763 previous section, the correct approach is to declare an worker
|
|
1764 function that does the work of everything, and is called by the
|
|
1765 other "container" macros that handle the different outside data
|
|
1766 forms. The data coming into the worker function, which
|
|
1767 typically ends in `_1', is in the form of three parameters:
|
|
1768 DATA, LEN, CHARLEN. (See point [3] about having two lengths and
|
|
1769 keeping them in sync.)
|
|
1770
|
|
1771 (6) Handling argument evaluation in macros: We take great care
|
|
1772 never to evaluate any argument more than once in any macro,
|
|
1773 except the initial Eistring parameter. This can and will be
|
|
1774 evaluated multiple times, but it should pretty much always just
|
|
1775 be a simple variable. This means, for example, that if an
|
|
1776 Eistring is the second (not first) argument of a macro, it
|
|
1777 doesn't fall under the "initial Eistring" exemption, so it
|
|
1778 needs protection against multi-evaluation. (Take the address of
|
|
1779 the Eistring structure, store in a temporary variable, and use
|
|
1780 temporary variable for all access to the Eistring.
|
|
1781 Essentially, we want it to appear as if these Eistring macros
|
|
1782 are functions -- we would like to declare them as functions but
|
851
|
1783 they use ALLOCA(), so we can't (and we can't make them inline
|
|
1784 functions either -- ALLOCA() is explicitly disallowed in inline
|
771
|
1785 functions.)
|
|
1786
|
|
1787 (7) Note that our rules regarding multiple evaluation are *more*
|
|
1788 strict than the rules listed above under the heading "working
|
|
1789 with raw internal-format data".
|
|
1790 */
|
|
1791
|
|
1792
|
|
1793 /* ----- Declaration ----- */
|
|
1794
|
|
1795 typedef struct
|
|
1796 {
|
|
1797 /* Data for the Eistring, stored in the default internal format.
|
|
1798 Always includes terminating null. */
|
867
|
1799 Ibyte *data_;
|
771
|
1800 /* Total number of bytes allocated in DATA (including null). */
|
|
1801 Bytecount max_size_allocated_;
|
|
1802 Bytecount bytelen_;
|
|
1803 Charcount charlen_;
|
|
1804 int mallocp_;
|
|
1805
|
|
1806 Extbyte *extdata_;
|
|
1807 Bytecount extlen_;
|
|
1808 } Eistring;
|
|
1809
|
|
1810 extern Eistring the_eistring_zero_init, the_eistring_malloc_zero_init;
|
|
1811
|
|
1812 #define DECLARE_EISTRING(name) \
|
|
1813 Eistring __ ## name ## __storage__ = the_eistring_zero_init; \
|
|
1814 Eistring *name = & __ ## name ## __storage__
|
|
1815 #define DECLARE_EISTRING_MALLOC(name) \
|
|
1816 Eistring __ ## name ## __storage__ = the_eistring_malloc_zero_init; \
|
|
1817 Eistring *name = & __ ## name ## __storage__
|
|
1818
|
|
1819 #define eiinit(ei) \
|
|
1820 do { \
|
793
|
1821 *(ei) = the_eistring_zero_init; \
|
771
|
1822 } while (0)
|
|
1823
|
|
1824 #define eiinit_malloc(ei) \
|
|
1825 do { \
|
793
|
1826 *(ei) = the_eistring_malloc_zero_init; \
|
771
|
1827 } while (0)
|
|
1828
|
|
1829
|
|
1830 /* ----- Utility ----- */
|
|
1831
|
|
1832 /* Make sure both LEN and CHARLEN are specified, in case one is given
|
|
1833 as -1. PTR evaluated at most once, others multiply. */
|
|
1834 #define eifixup_bytechar(ptr, len, charlen) \
|
|
1835 do { \
|
|
1836 if ((len) == -1) \
|
|
1837 (len) = charcount_to_bytecount (ptr, charlen); \
|
|
1838 else if ((charlen) == -1) \
|
|
1839 (charlen) = bytecount_to_charcount (ptr, len); \
|
|
1840 } while (0)
|
|
1841
|
|
1842 /* Make sure LEN is specified, in case it's is given as -1. PTR
|
|
1843 evaluated at most once, others multiply. */
|
|
1844 #define eifixup_byte(ptr, len, charlen) \
|
|
1845 do { \
|
|
1846 if ((len) == -1) \
|
|
1847 (len) = charcount_to_bytecount (ptr, charlen); \
|
|
1848 } while (0)
|
|
1849
|
|
1850 /* Make sure CHARLEN is specified, in case it's is given as -1. PTR
|
|
1851 evaluated at most once, others multiply. */
|
|
1852 #define eifixup_char(ptr, len, charlen) \
|
|
1853 do { \
|
|
1854 if ((charlen) == -1) \
|
|
1855 (charlen) = bytecount_to_charcount (ptr, len); \
|
|
1856 } while (0)
|
|
1857
|
|
1858
|
|
1859
|
|
1860 /* Make sure we can hold NEWBYTELEN bytes (which is NEWCHARLEN chars)
|
|
1861 plus a zero terminator. Preserve existing data as much as possible,
|
|
1862 including existing zero terminator. Put a new zero terminator where it
|
|
1863 should go if NEWZ if non-zero. All args but EI are evalled only once. */
|
|
1864
|
|
1865 #define EI_ALLOC(ei, newbytelen, newcharlen, newz) \
|
|
1866 do { \
|
|
1867 int ei1oldeibytelen = (ei)->bytelen_; \
|
|
1868 \
|
|
1869 (ei)->charlen_ = (newcharlen); \
|
|
1870 (ei)->bytelen_ = (newbytelen); \
|
|
1871 \
|
|
1872 if (ei1oldeibytelen != (ei)->bytelen_) \
|
|
1873 { \
|
|
1874 int ei1newsize = (ei)->max_size_allocated_; \
|
|
1875 while (ei1newsize < (ei)->bytelen_ + 1) \
|
|
1876 { \
|
|
1877 ei1newsize = (int) (ei1newsize * 1.5); \
|
|
1878 if (ei1newsize < 32) \
|
|
1879 ei1newsize = 32; \
|
|
1880 } \
|
|
1881 if (ei1newsize != (ei)->max_size_allocated_) \
|
|
1882 { \
|
|
1883 if ((ei)->mallocp_) \
|
|
1884 /* xrealloc always preserves existing data as much as possible */ \
|
1333
|
1885 (ei)->data_ = (Ibyte *) xrealloc ((ei)->data_, ei1newsize); \
|
771
|
1886 else \
|
|
1887 { \
|
851
|
1888 /* We don't have realloc, so ALLOCA() more space and copy the \
|
771
|
1889 data into it. */ \
|
867
|
1890 Ibyte *ei1oldeidata = (ei)->data_; \
|
|
1891 (ei)->data_ = (Ibyte *) ALLOCA (ei1newsize); \
|
771
|
1892 if (ei1oldeidata) \
|
|
1893 memcpy ((ei)->data_, ei1oldeidata, ei1oldeibytelen + 1); \
|
|
1894 } \
|
|
1895 (ei)->max_size_allocated_ = ei1newsize; \
|
|
1896 } \
|
|
1897 if (newz) \
|
|
1898 (ei)->data_[(ei)->bytelen_] = '\0'; \
|
|
1899 } \
|
|
1900 } while (0)
|
|
1901
|
|
1902 #define EI_ALLOC_AND_COPY(ei, data, bytelen, charlen) \
|
|
1903 do { \
|
|
1904 EI_ALLOC (ei, bytelen, charlen, 1); \
|
|
1905 memcpy ((ei)->data_, data, (ei)->bytelen_); \
|
|
1906 } while (0)
|
|
1907
|
800
|
1908 #ifdef ERROR_CHECK_TEXT
|
771
|
1909 #define EI_ASSERT_ASCII(ptr, len) \
|
|
1910 do { \
|
|
1911 int ei5; \
|
|
1912 const Char_ASCII *ei5ptr = (ptr); \
|
|
1913 int ei5len = (len); \
|
|
1914 \
|
|
1915 for (ei5 = 0; ei5 < ei5len; ei5++) \
|
|
1916 assert (ei5ptr[ei5] >= 0x00 && ei5ptr[ei5] < 0x7F); \
|
|
1917 } while (0)
|
|
1918 #define EI_ASSERT_ASCIIZ(ptr) \
|
|
1919 do { \
|
|
1920 const Char_ASCII *ei5p1 = (ptr); \
|
|
1921 EI_ASSERT_ASCII (ei5p1, strlen (ei5p1)); \
|
|
1922 } while (0)
|
|
1923 #else
|
|
1924 #define EI_ASSERT_ASCII(ptr, len)
|
|
1925 #define EI_ASSERT_ASCIIZ(ptr)
|
|
1926 #endif
|
|
1927
|
|
1928
|
|
1929 /* ----- Initialization ----- */
|
|
1930
|
|
1931 #define eicpy_ei(ei, eicpy) \
|
|
1932 do { \
|
|
1933 const Eistring *ei2 = (eicpy); \
|
|
1934 EI_ALLOC_AND_COPY (ei, ei2->data_, ei2->bytelen_, ei2->charlen_); \
|
|
1935 } while (0)
|
|
1936
|
|
1937 #define eicpy_lstr(ei, lisp_string) \
|
|
1938 do { \
|
|
1939 Lisp_Object ei3 = (lisp_string); \
|
|
1940 EI_ALLOC_AND_COPY (ei, XSTRING_DATA (ei3), XSTRING_LENGTH (ei3), \
|
1333
|
1941 string_char_length (ei3)); \
|
771
|
1942 } while (0)
|
|
1943
|
|
1944 #define eicpy_lstr_off(ei, lisp_string, off, charoff, len, charlen) \
|
|
1945 do { \
|
|
1946 Lisp_Object ei23lstr = (lisp_string); \
|
|
1947 int ei23off = (off); \
|
|
1948 int ei23charoff = (charoff); \
|
|
1949 int ei23len = (len); \
|
|
1950 int ei23charlen = (charlen); \
|
867
|
1951 const Ibyte *ei23data = XSTRING_DATA (ei23lstr); \
|
771
|
1952 \
|
|
1953 int ei23oldbytelen = (ei)->bytelen_; \
|
|
1954 \
|
|
1955 eifixup_byte (ei23data, ei23off, ei23charoff); \
|
|
1956 eifixup_bytechar (ei23data + ei23off, ei23len, ei23charlen); \
|
|
1957 \
|
|
1958 EI_ALLOC_AND_COPY (ei, ei23data + ei23off, ei23len, ei23charlen); \
|
|
1959 } while (0)
|
|
1960
|
826
|
1961 #define eicpy_raw_fmt(ei, ptr, len, fmt, object) \
|
771
|
1962 do { \
|
1333
|
1963 const Ibyte *ei12ptr = (ptr); \
|
771
|
1964 Internal_Format ei12fmt = (fmt); \
|
|
1965 int ei12len = (len); \
|
|
1966 assert (ei12fmt == FORMAT_DEFAULT); \
|
|
1967 EI_ALLOC_AND_COPY (ei, ei12ptr, ei12len, \
|
|
1968 bytecount_to_charcount (ei12ptr, ei12len)); \
|
|
1969 } while (0)
|
|
1970
|
826
|
1971 #define eicpy_raw(ei, ptr, len) \
|
|
1972 eicpy_raw_fmt (ei, ptr, len, FORMAT_DEFAULT, Qnil)
|
|
1973
|
|
1974 #define eicpy_rawz_fmt(ei, ptr, fmt, object) \
|
|
1975 do { \
|
867
|
1976 const Ibyte *ei12p1ptr = (ptr); \
|
826
|
1977 Internal_Format ei12p1fmt = (fmt); \
|
|
1978 assert (ei12p1fmt == FORMAT_DEFAULT); \
|
|
1979 eicpy_raw_fmt (ei, ei12p1ptr, qxestrlen (ei12p1ptr), fmt, object); \
|
771
|
1980 } while (0)
|
|
1981
|
826
|
1982 #define eicpy_rawz(ei, ptr) eicpy_rawz_fmt (ei, ptr, FORMAT_DEFAULT, Qnil)
|
771
|
1983
|
1333
|
1984 #define eicpy_ch(ei, ch) \
|
|
1985 do { \
|
867
|
1986 Ibyte ei12p2[MAX_ICHAR_LEN]; \
|
|
1987 Bytecount ei12p2len = set_itext_ichar (ei12p2, ch); \
|
1333
|
1988 EI_ALLOC_AND_COPY (ei, ei12p2, ei12p2len, 1); \
|
771
|
1989 } while (0)
|
|
1990
|
|
1991 #define eicpy_c(ei, c_string) \
|
|
1992 do { \
|
|
1993 const Char_ASCII *ei4 = (c_string); \
|
|
1994 \
|
|
1995 EI_ASSERT_ASCIIZ (ei4); \
|
|
1996 eicpy_ext (ei, ei4, Qbinary); \
|
|
1997 } while (0)
|
|
1998
|
|
1999 #define eicpy_c_len(ei, c_string, c_len) \
|
|
2000 do { \
|
|
2001 const Char_ASCII *ei6 = (c_string); \
|
|
2002 int ei6len = (c_len); \
|
|
2003 \
|
|
2004 EI_ASSERT_ASCII (ei6, ei6len); \
|
|
2005 eicpy_ext_len (ei, ei6, ei6len, Qbinary); \
|
|
2006 } while (0)
|
|
2007
|
1318
|
2008 #define eicpy_ext_len(ei, extdata, extlen, codesys) \
|
771
|
2009 do { \
|
|
2010 const Extbyte *ei7 = (extdata); \
|
|
2011 int ei7len = (extlen); \
|
|
2012 \
|
1318
|
2013 SIZED_EXTERNAL_TO_SIZED_C_STRING (ei7, ei7len, (ei)->data_, \
|
|
2014 (ei)->bytelen_, codesys); \
|
771
|
2015 (ei)->max_size_allocated_ = (ei)->bytelen_ + 1; \
|
|
2016 (ei)->charlen_ = bytecount_to_charcount ((ei)->data_, (ei)->bytelen_); \
|
|
2017 } while (0)
|
|
2018
|
1318
|
2019 #define eicpy_ext(ei, extdata, codesys) \
|
|
2020 do { \
|
|
2021 const Extbyte *ei8 = (extdata); \
|
|
2022 \
|
|
2023 eicpy_ext_len (ei, ei8, dfc_external_data_len (ei8, codesys), \
|
|
2024 codesys); \
|
771
|
2025 } while (0)
|
|
2026
|
|
2027 #define eicpy_lbuf(eistr, lisp_buf, off, charoff, len, charlen) \
|
|
2028 NOT YET IMPLEMENTED
|
|
2029
|
|
2030 #define eicpy_lstream(eistr, lstream) \
|
|
2031 NOT YET IMPLEMENTED
|
|
2032
|
867
|
2033 #define eireset(eistr) eicpy_rawz (eistr, (Ibyte *) "")
|
771
|
2034
|
|
2035 /* ----- Getting the data out of the Eistring ----- */
|
|
2036
|
|
2037 #define eidata(ei) ((ei)->data_)
|
|
2038
|
|
2039 #define eimake_string(ei) make_string (eidata (ei), eilen (ei))
|
|
2040
|
|
2041 #define eimake_string_off(eistr, off, charoff, len, charlen) \
|
|
2042 do { \
|
|
2043 Lisp_Object ei24lstr; \
|
|
2044 int ei24off = (off); \
|
|
2045 int ei24charoff = (charoff); \
|
|
2046 int ei24len = (len); \
|
|
2047 int ei24charlen = (charlen); \
|
|
2048 \
|
|
2049 eifixup_byte ((eistr)->data_, ei24off, ei24charoff); \
|
|
2050 eifixup_byte ((eistr)->data_ + ei24off, ei24len, ei24charlen); \
|
|
2051 \
|
|
2052 return make_string ((eistr)->data_ + ei24off, ei24len); \
|
|
2053 } while (0)
|
|
2054
|
|
2055 #define eicpyout_alloca(eistr, ptrout, lenout) \
|
826
|
2056 eicpyout_alloca_fmt (eistr, ptrout, lenout, FORMAT_DEFAULT, Qnil)
|
771
|
2057 #define eicpyout_malloc(eistr, lenout) \
|
826
|
2058 eicpyout_malloc_fmt (eistr, lenout, FORMAT_DEFAULT, Qnil)
|
867
|
2059 Ibyte *eicpyout_malloc_fmt (Eistring *eistr, Bytecount *len_out,
|
826
|
2060 Internal_Format fmt, Lisp_Object object);
|
|
2061 #define eicpyout_alloca_fmt(eistr, ptrout, lenout, fmt, object) \
|
771
|
2062 do { \
|
|
2063 Internal_Format ei23fmt = (fmt); \
|
867
|
2064 Ibyte *ei23ptrout = &(ptrout); \
|
771
|
2065 Bytecount *ei23lenout = &(lenout); \
|
|
2066 \
|
|
2067 assert (ei23fmt == FORMAT_DEFAULT); \
|
|
2068 \
|
|
2069 *ei23lenout = (eistr)->bytelen_; \
|
867
|
2070 *ei23ptrout = alloca_array (Ibyte, (eistr)->bytelen_ + 1); \
|
771
|
2071 memcpy (*ei23ptrout, (eistr)->data_, (eistr)->bytelen_ + 1); \
|
|
2072 } while (0)
|
|
2073
|
|
2074 /* ----- Moving to the heap ----- */
|
|
2075
|
|
2076 #define eifree(ei) \
|
|
2077 do { \
|
|
2078 if ((ei)->mallocp_) \
|
|
2079 { \
|
|
2080 if ((ei)->data_) \
|
|
2081 xfree ((ei)->data_); \
|
|
2082 if ((ei)->extdata_) \
|
|
2083 xfree ((ei)->extdata_); \
|
|
2084 eiinit_malloc (ei); \
|
|
2085 } \
|
|
2086 else \
|
|
2087 eiinit (ei); \
|
|
2088 } while (0)
|
|
2089
|
|
2090 int eifind_large_enough_buffer (int oldbufsize, int needed_size);
|
|
2091 void eito_malloc_1 (Eistring *ei);
|
|
2092
|
|
2093 #define eito_malloc(ei) eito_malloc_1 (ei)
|
|
2094
|
|
2095 #define eito_alloca(ei) \
|
|
2096 do { \
|
|
2097 if (!(ei)->mallocp_) \
|
|
2098 return; \
|
|
2099 (ei)->mallocp_ = 0; \
|
|
2100 if ((ei)->data_) \
|
|
2101 { \
|
867
|
2102 Ibyte *ei13newdata; \
|
771
|
2103 \
|
|
2104 (ei)->max_size_allocated_ = \
|
|
2105 eifind_large_enough_buffer (0, (ei)->bytelen_ + 1); \
|
867
|
2106 ei13newdata = (Ibyte *) ALLOCA ((ei)->max_size_allocated_); \
|
771
|
2107 memcpy (ei13newdata, (ei)->data_, (ei)->bytelen_ + 1); \
|
|
2108 xfree ((ei)->data_); \
|
|
2109 (ei)->data_ = ei13newdata; \
|
|
2110 } \
|
|
2111 \
|
|
2112 if ((ei)->extdata_) \
|
|
2113 { \
|
851
|
2114 Extbyte *ei13newdata = (Extbyte *) ALLOCA ((ei)->extlen_ + 2); \
|
771
|
2115 \
|
|
2116 memcpy (ei13newdata, (ei)->extdata_, (ei)->extlen_); \
|
|
2117 /* Double null-terminate in case of Unicode data */ \
|
|
2118 ei13newdata[(ei)->extlen_] = '\0'; \
|
|
2119 ei13newdata[(ei)->extlen_ + 1] = '\0'; \
|
|
2120 xfree ((ei)->extdata_); \
|
|
2121 (ei)->extdata_ = ei13newdata; \
|
|
2122 } \
|
|
2123 } while (0)
|
|
2124
|
|
2125
|
|
2126 /* ----- Retrieving the length ----- */
|
|
2127
|
|
2128 #define eilen(ei) ((ei)->bytelen_)
|
|
2129 #define eicharlen(ei) ((ei)->charlen_)
|
|
2130
|
|
2131
|
|
2132 /* ----- Working with positions ----- */
|
|
2133
|
|
2134 #define eicharpos_to_bytepos(ei, charpos) \
|
|
2135 charcount_to_bytecount ((ei)->data_, charpos)
|
|
2136 #define eibytepos_to_charpos(ei, bytepos) \
|
|
2137 bytecount_to_charcount ((ei)->data_, bytepos)
|
|
2138
|
|
2139 DECLARE_INLINE_HEADER (Bytecount eiincpos_1 (Eistring *eistr,
|
|
2140 Bytecount bytepos,
|
|
2141 Charcount n))
|
|
2142 {
|
867
|
2143 Ibyte *pos = eistr->data_ + bytepos;
|
814
|
2144 Charcount i;
|
771
|
2145
|
800
|
2146 text_checking_assert (bytepos >= 0 && bytepos <= eistr->bytelen_);
|
|
2147 text_checking_assert (n >= 0 && n <= eistr->charlen_);
|
771
|
2148 /* We could check N more correctly now, but that would require a
|
|
2149 call to bytecount_to_charcount(), which would be needlessly
|
|
2150 expensive (it would convert O(N) algorithms into O(N^2) algorithms
|
800
|
2151 with ERROR_CHECK_TEXT, which would be bad). If N is bad, we are
|
867
|
2152 guaranteed to catch it either inside INC_IBYTEPTR() or in the check
|
771
|
2153 below. */
|
|
2154 for (i = 0; i < n; i++)
|
867
|
2155 INC_IBYTEPTR (pos);
|
800
|
2156 text_checking_assert (pos - eistr->data_ <= eistr->bytelen_);
|
771
|
2157 return pos - eistr->data_;
|
|
2158 }
|
|
2159
|
|
2160 #define eiincpos (ei, bytepos) eiincpos_1 (ei, bytepos, 1)
|
|
2161 #define eiincpos_n (ei, bytepos, n) eiincpos_1 (ei, bytepos, n)
|
|
2162
|
|
2163 DECLARE_INLINE_HEADER (Bytecount eidecpos_1 (Eistring *eistr,
|
|
2164 Bytecount bytepos,
|
|
2165 Charcount n))
|
|
2166 {
|
867
|
2167 Ibyte *pos = eistr->data_ + bytepos;
|
771
|
2168 int i;
|
|
2169
|
800
|
2170 text_checking_assert (bytepos >= 0 && bytepos <= eistr->bytelen_);
|
|
2171 text_checking_assert (n >= 0 && n <= eistr->charlen_);
|
771
|
2172 /* We could check N more correctly now, but ... see above. */
|
|
2173 for (i = 0; i < n; i++)
|
867
|
2174 DEC_IBYTEPTR (pos);
|
800
|
2175 text_checking_assert (pos - eistr->data_ <= eistr->bytelen_);
|
771
|
2176 return pos - eistr->data_;
|
|
2177 }
|
|
2178
|
|
2179 #define eidecpos (ei, bytepos) eidecpos_1 (ei, bytepos, 1)
|
|
2180 #define eidecpos_n (ei, bytepos, n) eidecpos_1 (ei, bytepos, n)
|
|
2181
|
|
2182
|
|
2183 /* ----- Getting the character at a position ----- */
|
|
2184
|
|
2185 #define eigetch(ei, bytepos) \
|
867
|
2186 itext_ichar ((ei)->data_ + (bytepos))
|
|
2187 #define eigetch_char(ei, charpos) itext_ichar_n ((ei)->data_, charpos)
|
771
|
2188
|
|
2189
|
|
2190 /* ----- Setting the character at a position ----- */
|
|
2191
|
|
2192 #define eisetch(ei, bytepos, chr) \
|
|
2193 eisub_ch (ei, bytepos, -1, -1, 1, chr)
|
|
2194 #define eisetch_char(ei, charpos, chr) \
|
|
2195 eisub_ch (ei, -1, charpos, -1, 1, chr)
|
|
2196
|
|
2197
|
|
2198 /* ----- Concatenation ----- */
|
|
2199
|
|
2200 #define eicat_1(ei, data, bytelen, charlen) \
|
|
2201 do { \
|
|
2202 int ei14oldeibytelen = (ei)->bytelen_; \
|
|
2203 int ei14bytelen = (bytelen); \
|
|
2204 EI_ALLOC (ei, (ei)->bytelen_ + ei14bytelen, \
|
|
2205 (ei)->charlen_ + (charlen), 1); \
|
|
2206 memcpy ((ei)->data_ + ei14oldeibytelen, (data), \
|
|
2207 ei14bytelen); \
|
|
2208 } while (0)
|
|
2209
|
|
2210 #define eicat_ei(ei, ei2) \
|
|
2211 do { \
|
|
2212 const Eistring *ei9 = (ei2); \
|
|
2213 eicat_1 (ei, ei9->data_, ei9->bytelen_, ei9->charlen_); \
|
|
2214 } while (0)
|
|
2215
|
|
2216 #define eicat_c(ei, c_string) \
|
|
2217 do { \
|
|
2218 const Char_ASCII *ei15 = (c_string); \
|
|
2219 int ei15len = strlen (ei15); \
|
|
2220 \
|
|
2221 EI_ASSERT_ASCII (ei15, ei15len); \
|
|
2222 eicat_1 (ei, ei15, ei15len, \
|
867
|
2223 bytecount_to_charcount ((Ibyte *) ei15, ei15len)); \
|
771
|
2224 } while (0)
|
|
2225
|
|
2226 #define eicat_raw(ei, data, len) \
|
|
2227 do { \
|
|
2228 int ei16len = (len); \
|
867
|
2229 const Ibyte *ei16data = (data); \
|
771
|
2230 eicat_1 (ei, ei16data, ei16len, \
|
|
2231 bytecount_to_charcount (ei16data, ei16len)); \
|
|
2232 } while (0)
|
|
2233
|
|
2234 #define eicat_rawz(ei, ptr) \
|
|
2235 do { \
|
867
|
2236 const Ibyte *ei16p5ptr = (ptr); \
|
771
|
2237 eicat_raw (ei, ei16p5ptr, qxestrlen (ei16p5ptr)); \
|
|
2238 } while (0)
|
|
2239
|
|
2240 #define eicat_lstr(ei, lisp_string) \
|
|
2241 do { \
|
|
2242 Lisp_Object ei17 = (lisp_string); \
|
|
2243 eicat_1 (ei, XSTRING_DATA (ei17), XSTRING_LENGTH (ei17), \
|
826
|
2244 string_char_length (ei17)); \
|
771
|
2245 } while (0)
|
|
2246
|
|
2247 #define eicat_ch(ei, ch) \
|
|
2248 do { \
|
1333
|
2249 Ibyte ei22ch[MAX_ICHAR_LEN]; \
|
867
|
2250 Bytecount ei22len = set_itext_ichar (ei22ch, ch); \
|
771
|
2251 eicat_1 (ei, ei22ch, ei22len, 1); \
|
|
2252 } while (0)
|
|
2253
|
|
2254
|
|
2255 /* ----- Replacement ----- */
|
|
2256
|
|
2257 /* Replace the section of an Eistring at (OFF, LEN) with the data at
|
|
2258 SRC of length LEN. All positions have corresponding character values,
|
|
2259 and either can be -1 -- it will be computed from the other. */
|
|
2260
|
|
2261 #define eisub_1(ei, off, charoff, len, charlen, src, srclen, srccharlen) \
|
|
2262 do { \
|
|
2263 int ei18off = (off); \
|
|
2264 int ei18charoff = (charoff); \
|
|
2265 int ei18len = (len); \
|
|
2266 int ei18charlen = (charlen); \
|
867
|
2267 Ibyte *ei18src = (Ibyte *) (src); \
|
771
|
2268 int ei18srclen = (srclen); \
|
|
2269 int ei18srccharlen = (srccharlen); \
|
|
2270 \
|
|
2271 int ei18oldeibytelen = (ei)->bytelen_; \
|
|
2272 \
|
|
2273 eifixup_bytechar ((ei)->data_, ei18off, ei18charoff); \
|
|
2274 eifixup_bytechar ((ei)->data_ + ei18off, ei18len, ei18charlen); \
|
|
2275 eifixup_bytechar (ei18src, ei18srclen, ei18srccharlen); \
|
|
2276 \
|
|
2277 EI_ALLOC (ei, (ei)->bytelen_ + ei18srclen - ei18len, \
|
|
2278 (ei)->charlen_ + ei18srccharlen - ei18charlen, 0); \
|
|
2279 if (ei18len != ei18srclen) \
|
|
2280 memmove ((ei)->data_ + ei18off + ei18srclen, \
|
|
2281 (ei)->data_ + ei18off + ei18len, \
|
|
2282 /* include zero terminator. */ \
|
|
2283 ei18oldeibytelen - (ei18off + ei18len) + 1); \
|
|
2284 if (ei18srclen > 0) \
|
|
2285 memcpy ((ei)->data_ + ei18off, ei18src, ei18srclen); \
|
|
2286 } while (0)
|
|
2287
|
|
2288 #define eisub_ei(ei, off, charoff, len, charlen, ei2) \
|
|
2289 do { \
|
1333
|
2290 const Eistring *ei19 = (ei2); \
|
771
|
2291 eisub_1 (ei, off, charoff, len, charlen, ei19->data_, ei19->bytelen_, \
|
|
2292 ei19->charlen_); \
|
|
2293 } while (0)
|
|
2294
|
|
2295 #define eisub_c(ei, off, charoff, len, charlen, c_string) \
|
|
2296 do { \
|
|
2297 const Char_ASCII *ei20 = (c_string); \
|
|
2298 int ei20len = strlen (ei20); \
|
|
2299 EI_ASSERT_ASCII (ei20, ei20len); \
|
|
2300 eisub_1 (ei, off, charoff, len, charlen, ei20, ei20len, -1); \
|
|
2301 } while (0)
|
|
2302
|
|
2303 #define eisub_ch(ei, off, charoff, len, charlen, ch) \
|
|
2304 do { \
|
1333
|
2305 Ibyte ei21ch[MAX_ICHAR_LEN]; \
|
867
|
2306 Bytecount ei21len = set_itext_ichar (ei21ch, ch); \
|
771
|
2307 eisub_1 (ei, off, charoff, len, charlen, ei21ch, ei21len, 1); \
|
|
2308 } while (0)
|
|
2309
|
|
2310 #define eidel(ei, off, charoff, len, charlen) \
|
|
2311 eisub_1(ei, off, charoff, len, charlen, NULL, 0, 0)
|
|
2312
|
|
2313
|
|
2314 /* ----- Converting to an external format ----- */
|
|
2315
|
1333
|
2316 #define eito_external(ei, codesys) \
|
771
|
2317 do { \
|
|
2318 if ((ei)->mallocp_) \
|
|
2319 { \
|
|
2320 if ((ei)->extdata_) \
|
|
2321 { \
|
|
2322 xfree ((ei)->extdata_); \
|
|
2323 (ei)->extdata_ = 0; \
|
|
2324 } \
|
|
2325 TO_EXTERNAL_FORMAT (DATA, ((ei)->data_, (ei)->bytelen_), \
|
|
2326 MALLOC, ((ei)->extdata_, (ei)->extlen_), \
|
1333
|
2327 codesys); \
|
771
|
2328 } \
|
|
2329 else \
|
|
2330 TO_EXTERNAL_FORMAT (DATA, ((ei)->data_, (ei)->bytelen_), \
|
|
2331 ALLOCA, ((ei)->extdata_, (ei)->extlen_), \
|
1318
|
2332 codesys); \
|
771
|
2333 } while (0)
|
|
2334
|
|
2335 #define eiextdata(ei) ((ei)->extdata_)
|
|
2336 #define eiextlen(ei) ((ei)->extlen_)
|
|
2337
|
|
2338
|
|
2339 /* ----- Searching in the Eistring for a character ----- */
|
|
2340
|
|
2341 #define eichr(eistr, chr) \
|
|
2342 NOT YET IMPLEMENTED
|
|
2343 #define eichr_char(eistr, chr) \
|
|
2344 NOT YET IMPLEMENTED
|
|
2345 #define eichr_off(eistr, chr, off, charoff) \
|
|
2346 NOT YET IMPLEMENTED
|
|
2347 #define eichr_off_char(eistr, chr, off, charoff) \
|
|
2348 NOT YET IMPLEMENTED
|
|
2349 #define eirchr(eistr, chr) \
|
|
2350 NOT YET IMPLEMENTED
|
|
2351 #define eirchr_char(eistr, chr) \
|
|
2352 NOT YET IMPLEMENTED
|
|
2353 #define eirchr_off(eistr, chr, off, charoff) \
|
|
2354 NOT YET IMPLEMENTED
|
|
2355 #define eirchr_off_char(eistr, chr, off, charoff) \
|
|
2356 NOT YET IMPLEMENTED
|
|
2357
|
|
2358
|
|
2359 /* ----- Searching in the Eistring for a string ----- */
|
|
2360
|
|
2361 #define eistr_ei(eistr, eistr2) \
|
|
2362 NOT YET IMPLEMENTED
|
|
2363 #define eistr_ei_char(eistr, eistr2) \
|
|
2364 NOT YET IMPLEMENTED
|
|
2365 #define eistr_ei_off(eistr, eistr2, off, charoff) \
|
|
2366 NOT YET IMPLEMENTED
|
|
2367 #define eistr_ei_off_char(eistr, eistr2, off, charoff) \
|
|
2368 NOT YET IMPLEMENTED
|
|
2369 #define eirstr_ei(eistr, eistr2) \
|
|
2370 NOT YET IMPLEMENTED
|
|
2371 #define eirstr_ei_char(eistr, eistr2) \
|
|
2372 NOT YET IMPLEMENTED
|
|
2373 #define eirstr_ei_off(eistr, eistr2, off, charoff) \
|
|
2374 NOT YET IMPLEMENTED
|
|
2375 #define eirstr_ei_off_char(eistr, eistr2, off, charoff) \
|
|
2376 NOT YET IMPLEMENTED
|
|
2377
|
|
2378 #define eistr_c(eistr, c_string) \
|
|
2379 NOT YET IMPLEMENTED
|
|
2380 #define eistr_c_char(eistr, c_string) \
|
|
2381 NOT YET IMPLEMENTED
|
|
2382 #define eistr_c_off(eistr, c_string, off, charoff) \
|
|
2383 NOT YET IMPLEMENTED
|
|
2384 #define eistr_c_off_char(eistr, c_string, off, charoff) \
|
|
2385 NOT YET IMPLEMENTED
|
|
2386 #define eirstr_c(eistr, c_string) \
|
|
2387 NOT YET IMPLEMENTED
|
|
2388 #define eirstr_c_char(eistr, c_string) \
|
|
2389 NOT YET IMPLEMENTED
|
|
2390 #define eirstr_c_off(eistr, c_string, off, charoff) \
|
|
2391 NOT YET IMPLEMENTED
|
|
2392 #define eirstr_c_off_char(eistr, c_string, off, charoff) \
|
|
2393 NOT YET IMPLEMENTED
|
|
2394
|
|
2395
|
|
2396 /* ----- Comparison ----- */
|
|
2397
|
|
2398 int eicmp_1 (Eistring *ei, Bytecount off, Charcount charoff,
|
867
|
2399 Bytecount len, Charcount charlen, const Ibyte *data,
|
771
|
2400 const Eistring *ei2, int is_c, int fold_case);
|
|
2401
|
|
2402 #define eicmp_ei(eistr, eistr2) \
|
|
2403 eicmp_1 (eistr, 0, -1, -1, -1, 0, eistr2, 0, 0)
|
|
2404 #define eicmp_off_ei(eistr, off, charoff, len, charlen, eistr2) \
|
|
2405 eicmp_1 (eistr, off, charoff, len, charlen, 0, eistr2, 0, 0)
|
|
2406 #define eicasecmp_ei(eistr, eistr2) \
|
|
2407 eicmp_1 (eistr, 0, -1, -1, -1, 0, eistr2, 0, 1)
|
|
2408 #define eicasecmp_off_ei(eistr, off, charoff, len, charlen, eistr2) \
|
|
2409 eicmp_1 (eistr, off, charoff, len, charlen, 0, eistr2, 0, 1)
|
|
2410 #define eicasecmp_i18n_ei(eistr, eistr2) \
|
|
2411 eicmp_1 (eistr, 0, -1, -1, -1, 0, eistr2, 0, 2)
|
|
2412 #define eicasecmp_i18n_off_ei(eistr, off, charoff, len, charlen, eistr2) \
|
|
2413 eicmp_1 (eistr, off, charoff, len, charlen, 0, eistr2, 0, 2)
|
|
2414
|
|
2415 #define eicmp_c(eistr, c_string) \
|
|
2416 eicmp_1 (eistr, 0, -1, -1, -1, c_string, 0, 1, 0)
|
|
2417 #define eicmp_off_c(eistr, off, charoff, len, charlen, c_string) \
|
|
2418 eicmp_1 (eistr, off, charoff, len, charlen, c_string, 0, 1, 0)
|
|
2419 #define eicasecmp_c(eistr, c_string) \
|
|
2420 eicmp_1 (eistr, 0, -1, -1, -1, c_string, 0, 1, 1)
|
|
2421 #define eicasecmp_off_c(eistr, off, charoff, len, charlen, c_string) \
|
|
2422 eicmp_1 (eistr, off, charoff, len, charlen, c_string, 0, 1, 1)
|
|
2423 #define eicasecmp_i18n_c(eistr, c_string) \
|
|
2424 eicmp_1 (eistr, 0, -1, -1, -1, c_string, 0, 1, 2)
|
|
2425 #define eicasecmp_i18n_off_c(eistr, off, charoff, len, charlen, c_string) \
|
|
2426 eicmp_1 (eistr, off, charoff, len, charlen, c_string, 0, 1, 2)
|
|
2427
|
|
2428
|
|
2429 /* ----- Case-changing the Eistring ----- */
|
|
2430
|
867
|
2431 int eistr_casefiddle_1 (Ibyte *olddata, Bytecount len, Ibyte *newdata,
|
771
|
2432 int downp);
|
|
2433
|
|
2434 #define EI_CASECHANGE(ei, downp) \
|
|
2435 do { \
|
867
|
2436 int ei11new_allocmax = (ei)->charlen_ * MAX_ICHAR_LEN + 1; \
|
1333
|
2437 Ibyte *ei11storage = \
|
|
2438 (Ibyte *) alloca_array (Ibyte, ei11new_allocmax); \
|
771
|
2439 int ei11newlen = eistr_casefiddle_1 ((ei)->data_, (ei)->bytelen_, \
|
|
2440 ei11storage, downp); \
|
|
2441 \
|
|
2442 if (ei11newlen) \
|
|
2443 { \
|
|
2444 (ei)->max_size_allocated_ = ei11new_allocmax; \
|
1333
|
2445 (ei)->data_ = ei11storage; \
|
771
|
2446 (ei)->bytelen_ = ei11newlen; \
|
|
2447 /* charlen is the same. */ \
|
|
2448 } \
|
|
2449 } while (0)
|
|
2450
|
|
2451 #define eilwr(ei) EI_CASECHANGE (ei, 1)
|
|
2452 #define eiupr(ei) EI_CASECHANGE (ei, 0)
|
|
2453
|
|
2454
|
|
2455 /************************************************************************/
|
|
2456 /* */
|
|
2457 /* Converting between internal and external format */
|
|
2458 /* */
|
|
2459 /************************************************************************/
|
|
2460 /*
|
1318
|
2461 The macros below are used for converting data between different formats.
|
|
2462 Generally, the data is textual, and the formats are related to
|
|
2463 internationalization (e.g. converting between internal-format text and
|
|
2464 UTF-8) -- but the mechanism is general, and could be used for anything,
|
|
2465 e.g. decoding gzipped data.
|
|
2466
|
|
2467 In general, conversion involves a source of data, a sink, the existing
|
|
2468 format of the source data, and the desired format of the sink. The
|
|
2469 macros below, however, always require that either the source or sink is
|
|
2470 internal-format text. Therefore, in practice the conversions below
|
|
2471 involve source, sink, an external format (specified by a coding system),
|
|
2472 and the direction of conversion (internal->external or vice-versa).
|
|
2473
|
|
2474 Sources and sinks can be raw data (sized or unsized -- when unsized,
|
|
2475 input data is assumed to be null-terminated [double null-terminated for
|
|
2476 Unicode-format data], and on output the length is not stored anywhere),
|
|
2477 Lisp strings, Lisp buffers, lstreams, and opaque data objects. When the
|
|
2478 output is raw data, the result can be allocated either with alloca() or
|
|
2479 malloc(). (There is currently no provision for writing into a fixed
|
|
2480 buffer. If you want this, use alloca() output and then copy the data --
|
|
2481 but be careful with the size! Unless you are very sure of the encoding
|
|
2482 being used, upper bounds for the size are not in general computable.)
|
|
2483 The obvious restrictions on source and sink types apply (e.g. Lisp
|
|
2484 strings are a source and sink only for internal data).
|
|
2485
|
|
2486 All raw data outputted will contain an extra null byte (two bytes for
|
|
2487 Unicode -- currently, in fact, all output data, whether internal or
|
|
2488 external, is double-null-terminated, but you can't count on this; see
|
|
2489 below). This means that enough space is allocated to contain the extra
|
|
2490 nulls; however, these nulls are not reflected in the returned output
|
|
2491 size.
|
|
2492
|
|
2493 The most basic macros are TO_EXTERNAL_FORMAT and TO_INTERNAL_FORMAT.
|
|
2494 These can be used to convert between any kinds of sources or sinks.
|
|
2495 However, 99% of conversions involve raw data or Lisp strings as both
|
|
2496 source and sink, and usually data is output as alloca() rather than
|
|
2497 malloc(). For this reason, convenience macros are defined for many types
|
|
2498 of conversions involving raw data and/or Lisp strings, especially when
|
|
2499 the output is an alloca()ed string. (When the destination is a
|
|
2500 Lisp_String, there are other functions that should be used instead --
|
|
2501 build_ext_string() and make_ext_string(), for example.) The convenience
|
|
2502 macros are of two types -- the older kind that store the result into a
|
|
2503 specified variable, and the newer kind that return the result. The newer
|
|
2504 kind of macros don't exist when the output is sized data, because that
|
|
2505 would have two return values. NOTE: All convenience macros are
|
|
2506 ultimately defined in terms of TO_EXTERNAL_FORMAT and TO_INTERNAL_FORMAT.
|
|
2507 Thus, any comments below about the workings of these macros also apply to
|
|
2508 all convenience macros.
|
|
2509
|
|
2510 TO_EXTERNAL_FORMAT (source_type, source, sink_type, sink, codesys)
|
|
2511 TO_INTERNAL_FORMAT (source_type, source, sink_type, sink, codesys)
|
771
|
2512
|
|
2513 Typical use is
|
|
2514
|
|
2515 TO_EXTERNAL_FORMAT (DATA, (ptr, len),
|
|
2516 LISP_BUFFER, buffer,
|
|
2517 Qfile_name);
|
|
2518
|
|
2519 NOTE: GC is inhibited during the entire operation of these macros. This
|
|
2520 is because frequently the data to be converted comes from strings but
|
|
2521 gets passed in as just DATA, and GC may move around the string data. If
|
|
2522 we didn't inhibit GC, there'd have to be a lot of messy recoding,
|
|
2523 alloca-copying of strings and other annoying stuff.
|
|
2524
|
|
2525 The source or sink can be specified in one of these ways:
|
|
2526
|
|
2527 DATA, (ptr, len), // input data is a fixed buffer of size len
|
851
|
2528 ALLOCA, (ptr, len), // output data is in a ALLOCA()ed buffer of size len
|
771
|
2529 MALLOC, (ptr, len), // output data is in a malloc()ed buffer of size len
|
|
2530 C_STRING_ALLOCA, ptr, // equivalent to ALLOCA (ptr, len_ignored) on output
|
|
2531 C_STRING_MALLOC, ptr, // equivalent to MALLOC (ptr, len_ignored) on output
|
|
2532 C_STRING, ptr, // equivalent to DATA, (ptr, strlen/wcslen (ptr))
|
|
2533 // on input (the Unicode version is used when correct)
|
|
2534 LISP_STRING, string, // input or output is a Lisp_Object of type string
|
|
2535 LISP_BUFFER, buffer, // output is written to (point) in lisp buffer
|
|
2536 LISP_LSTREAM, lstream, // input or output is a Lisp_Object of type lstream
|
|
2537 LISP_OPAQUE, object, // input or output is a Lisp_Object of type opaque
|
|
2538
|
|
2539 When specifying the sink, use lvalues, since the macro will assign to them,
|
|
2540 except when the sink is an lstream or a lisp buffer.
|
|
2541
|
|
2542 The macros accept the kinds of sources and sinks appropriate for
|
|
2543 internal and external data representation. See the type_checking_assert
|
|
2544 macros below for the actual allowed types.
|
|
2545
|
|
2546 Since some sources and sinks use one argument (a Lisp_Object) to
|
|
2547 specify them, while others take a (pointer, length) pair, we use
|
|
2548 some C preprocessor trickery to allow pair arguments to be specified
|
|
2549 by parenthesizing them, as in the examples above.
|
|
2550
|
|
2551 Anything prefixed by dfc_ (`data format conversion') is private.
|
|
2552 They are only used to implement these macros.
|
|
2553
|
|
2554 [[Using C_STRING* is appropriate for using with external APIs that
|
|
2555 take null-terminated strings. For internal data, we should try to
|
|
2556 be '\0'-clean - i.e. allow arbitrary data to contain embedded '\0'.
|
|
2557
|
|
2558 Sometime in the future we might allow output to C_STRING_ALLOCA or
|
|
2559 C_STRING_MALLOC _only_ with TO_EXTERNAL_FORMAT(), not
|
|
2560 TO_INTERNAL_FORMAT().]]
|
|
2561
|
|
2562 The above comments are not true. Frequently (most of the time, in
|
|
2563 fact), external strings come as zero-terminated entities, where the
|
|
2564 zero-termination is the only way to find out the length. Even in
|
|
2565 cases where you can get the length, most of the time the system will
|
|
2566 still use the null to signal the end of the string, and there will
|
|
2567 still be no way to either send in or receive a string with embedded
|
|
2568 nulls. In such situations, it's pointless to track the length
|
|
2569 because null bytes can never be in the string. We have a lot of
|
|
2570 operations that make it easy to operate on zero-terminated strings,
|
|
2571 and forcing the user the deal with the length everywhere would only
|
|
2572 make the code uglier and more complicated, for no gain. --ben
|
|
2573
|
|
2574 There is no problem using the same lvalue for source and sink.
|
|
2575
|
|
2576 Also, when pointers are required, the code (currently at least) is
|
|
2577 lax and allows any pointer types, either in the source or the sink.
|
|
2578 This makes it possible, e.g., to deal with internal format data held
|
|
2579 in char *'s or external format data held in WCHAR * (i.e. Unicode).
|
|
2580
|
|
2581 Finally, whenever storage allocation is called for, extra space is
|
|
2582 allocated for a terminating zero, and such a zero is stored in the
|
|
2583 appropriate place, regardless of whether the source data was
|
|
2584 specified using a length or was specified as zero-terminated. This
|
|
2585 allows you to freely pass the resulting data, no matter how
|
|
2586 obtained, to a routine that expects zero termination (modulo, of
|
|
2587 course, that any embedded zeros in the resulting text will cause
|
|
2588 truncation). In fact, currently two embedded zeros are allocated
|
|
2589 and stored after the data result. This is to allow for the
|
|
2590 possibility of storing a Unicode value on output, which needs the
|
|
2591 two zeros. Currently, however, the two zeros are stored regardless
|
|
2592 of whether the conversion is internal or external and regardless of
|
|
2593 whether the external coding system is in fact Unicode. This
|
|
2594 behavior may change in the future, and you cannot rely on this --
|
|
2595 the most you can rely on is that sink data in Unicode format will
|
|
2596 have two terminating nulls, which combine to form one Unicode null
|
|
2597 character. */
|
|
2598
|
|
2599 #define TO_EXTERNAL_FORMAT(source_type, source, sink_type, sink, codesys) \
|
|
2600 do { \
|
|
2601 dfc_conversion_type dfc_simplified_source_type; \
|
|
2602 dfc_conversion_type dfc_simplified_sink_type; \
|
|
2603 dfc_conversion_data dfc_source; \
|
|
2604 dfc_conversion_data dfc_sink; \
|
|
2605 Lisp_Object dfc_codesys = (codesys); \
|
|
2606 \
|
|
2607 type_checking_assert \
|
|
2608 ((DFC_TYPE_##source_type == DFC_TYPE_DATA || \
|
|
2609 DFC_TYPE_##source_type == DFC_TYPE_C_STRING || \
|
|
2610 DFC_TYPE_##source_type == DFC_TYPE_LISP_STRING || \
|
|
2611 DFC_TYPE_##source_type == DFC_TYPE_LISP_OPAQUE || \
|
|
2612 DFC_TYPE_##source_type == DFC_TYPE_LISP_LSTREAM) \
|
|
2613 && \
|
|
2614 (DFC_TYPE_##sink_type == DFC_TYPE_ALLOCA || \
|
|
2615 DFC_TYPE_##sink_type == DFC_TYPE_MALLOC || \
|
|
2616 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_ALLOCA || \
|
|
2617 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_MALLOC || \
|
|
2618 DFC_TYPE_##sink_type == DFC_TYPE_LISP_LSTREAM || \
|
|
2619 DFC_TYPE_##sink_type == DFC_TYPE_LISP_OPAQUE)); \
|
|
2620 \
|
|
2621 DFC_EXT_SOURCE_##source_type##_TO_ARGS (source, dfc_codesys); \
|
|
2622 DFC_SINK_##sink_type##_TO_ARGS (sink); \
|
|
2623 \
|
|
2624 dfc_convert_to_external_format (dfc_simplified_source_type, &dfc_source, \
|
|
2625 dfc_codesys, \
|
|
2626 dfc_simplified_sink_type, &dfc_sink); \
|
|
2627 \
|
|
2628 DFC_##sink_type##_USE_CONVERTED_DATA (sink); \
|
|
2629 } while (0)
|
|
2630
|
|
2631 #define TO_INTERNAL_FORMAT(source_type, source, sink_type, sink, codesys) \
|
|
2632 do { \
|
|
2633 dfc_conversion_type dfc_simplified_source_type; \
|
|
2634 dfc_conversion_type dfc_simplified_sink_type; \
|
|
2635 dfc_conversion_data dfc_source; \
|
|
2636 dfc_conversion_data dfc_sink; \
|
|
2637 Lisp_Object dfc_codesys = (codesys); \
|
|
2638 \
|
|
2639 type_checking_assert \
|
|
2640 ((DFC_TYPE_##source_type == DFC_TYPE_DATA || \
|
|
2641 DFC_TYPE_##source_type == DFC_TYPE_C_STRING || \
|
|
2642 DFC_TYPE_##source_type == DFC_TYPE_LISP_OPAQUE || \
|
|
2643 DFC_TYPE_##source_type == DFC_TYPE_LISP_LSTREAM) \
|
|
2644 && \
|
|
2645 (DFC_TYPE_##sink_type == DFC_TYPE_ALLOCA || \
|
|
2646 DFC_TYPE_##sink_type == DFC_TYPE_MALLOC || \
|
|
2647 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_ALLOCA || \
|
|
2648 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_MALLOC || \
|
|
2649 DFC_TYPE_##sink_type == DFC_TYPE_LISP_STRING || \
|
|
2650 DFC_TYPE_##sink_type == DFC_TYPE_LISP_LSTREAM || \
|
|
2651 DFC_TYPE_##sink_type == DFC_TYPE_LISP_BUFFER)); \
|
|
2652 \
|
|
2653 DFC_INT_SOURCE_##source_type##_TO_ARGS (source, dfc_codesys); \
|
|
2654 DFC_SINK_##sink_type##_TO_ARGS (sink); \
|
|
2655 \
|
|
2656 dfc_convert_to_internal_format (dfc_simplified_source_type, &dfc_source, \
|
|
2657 dfc_codesys, \
|
|
2658 dfc_simplified_sink_type, &dfc_sink); \
|
|
2659 \
|
|
2660 DFC_##sink_type##_USE_CONVERTED_DATA (sink); \
|
|
2661 } while (0)
|
|
2662
|
814
|
2663 #ifdef __cplusplus
|
771
|
2664
|
814
|
2665 /* Error if you try to use a union here: "member `struct {anonymous
|
|
2666 union}::{anonymous} {anonymous union}::data' with constructor not allowed
|
|
2667 in union" (Bytecount is a class) */
|
|
2668
|
|
2669 typedef struct
|
|
2670 #else
|
771
|
2671 typedef union
|
814
|
2672 #endif
|
771
|
2673 {
|
|
2674 struct { const void *ptr; Bytecount len; } data;
|
|
2675 Lisp_Object lisp_object;
|
|
2676 } dfc_conversion_data;
|
|
2677
|
|
2678 enum dfc_conversion_type
|
|
2679 {
|
|
2680 DFC_TYPE_DATA,
|
|
2681 DFC_TYPE_ALLOCA,
|
|
2682 DFC_TYPE_MALLOC,
|
|
2683 DFC_TYPE_C_STRING,
|
|
2684 DFC_TYPE_C_STRING_ALLOCA,
|
|
2685 DFC_TYPE_C_STRING_MALLOC,
|
|
2686 DFC_TYPE_LISP_STRING,
|
|
2687 DFC_TYPE_LISP_LSTREAM,
|
|
2688 DFC_TYPE_LISP_OPAQUE,
|
|
2689 DFC_TYPE_LISP_BUFFER
|
|
2690 };
|
|
2691 typedef enum dfc_conversion_type dfc_conversion_type;
|
|
2692
|
|
2693 /* WARNING: These use a static buffer. This can lead to disaster if
|
|
2694 these functions are not used *very* carefully. Another reason to only use
|
|
2695 TO_EXTERNAL_FORMAT() and TO_INTERNAL_FORMAT(). */
|
1632
|
2696 MODULE_API void
|
771
|
2697 dfc_convert_to_external_format (dfc_conversion_type source_type,
|
|
2698 dfc_conversion_data *source,
|
1318
|
2699 Lisp_Object codesys,
|
771
|
2700 dfc_conversion_type sink_type,
|
|
2701 dfc_conversion_data *sink);
|
1632
|
2702 MODULE_API void
|
771
|
2703 dfc_convert_to_internal_format (dfc_conversion_type source_type,
|
|
2704 dfc_conversion_data *source,
|
1318
|
2705 Lisp_Object codesys,
|
771
|
2706 dfc_conversion_type sink_type,
|
|
2707 dfc_conversion_data *sink);
|
|
2708 /* CPP Trickery */
|
|
2709 #define DFC_CPP_CAR(x,y) (x)
|
|
2710 #define DFC_CPP_CDR(x,y) (y)
|
|
2711
|
|
2712 /* Convert `source' to args for dfc_convert_to_external_format() */
|
|
2713 #define DFC_EXT_SOURCE_DATA_TO_ARGS(val, codesys) do { \
|
|
2714 dfc_source.data.ptr = DFC_CPP_CAR val; \
|
|
2715 dfc_source.data.len = DFC_CPP_CDR val; \
|
|
2716 dfc_simplified_source_type = DFC_TYPE_DATA; \
|
|
2717 } while (0)
|
|
2718 #define DFC_EXT_SOURCE_C_STRING_TO_ARGS(val, codesys) do { \
|
|
2719 dfc_source.data.len = \
|
|
2720 strlen ((char *) (dfc_source.data.ptr = (val))); \
|
|
2721 dfc_simplified_source_type = DFC_TYPE_DATA; \
|
|
2722 } while (0)
|
|
2723 #define DFC_EXT_SOURCE_LISP_STRING_TO_ARGS(val, codesys) do { \
|
|
2724 Lisp_Object dfc_slsta = (val); \
|
|
2725 type_checking_assert (STRINGP (dfc_slsta)); \
|
|
2726 dfc_source.lisp_object = dfc_slsta; \
|
|
2727 dfc_simplified_source_type = DFC_TYPE_LISP_STRING; \
|
|
2728 } while (0)
|
|
2729 #define DFC_EXT_SOURCE_LISP_LSTREAM_TO_ARGS(val, codesys) do { \
|
|
2730 Lisp_Object dfc_sllta = (val); \
|
|
2731 type_checking_assert (LSTREAMP (dfc_sllta)); \
|
|
2732 dfc_source.lisp_object = dfc_sllta; \
|
|
2733 dfc_simplified_source_type = DFC_TYPE_LISP_LSTREAM; \
|
|
2734 } while (0)
|
|
2735 #define DFC_EXT_SOURCE_LISP_OPAQUE_TO_ARGS(val, codesys) do { \
|
|
2736 Lisp_Opaque *dfc_slota = XOPAQUE (val); \
|
|
2737 dfc_source.data.ptr = OPAQUE_DATA (dfc_slota); \
|
|
2738 dfc_source.data.len = OPAQUE_SIZE (dfc_slota); \
|
|
2739 dfc_simplified_source_type = DFC_TYPE_DATA; \
|
|
2740 } while (0)
|
|
2741
|
|
2742 /* Convert `source' to args for dfc_convert_to_internal_format() */
|
|
2743 #define DFC_INT_SOURCE_DATA_TO_ARGS(val, codesys) \
|
|
2744 DFC_EXT_SOURCE_DATA_TO_ARGS (val, codesys)
|
|
2745 #define DFC_INT_SOURCE_C_STRING_TO_ARGS(val, codesys) do { \
|
|
2746 dfc_source.data.len = dfc_external_data_len (dfc_source.data.ptr = (val), \
|
|
2747 codesys); \
|
|
2748 dfc_simplified_source_type = DFC_TYPE_DATA; \
|
|
2749 } while (0)
|
|
2750 #define DFC_INT_SOURCE_LISP_STRING_TO_ARGS(val, codesys) \
|
|
2751 DFC_EXT_SOURCE_LISP_STRING_TO_ARGS (val, codesys)
|
|
2752 #define DFC_INT_SOURCE_LISP_LSTREAM_TO_ARGS(val, codesys) \
|
|
2753 DFC_EXT_SOURCE_LISP_LSTREAM_TO_ARGS (val, codesys)
|
|
2754 #define DFC_INT_SOURCE_LISP_OPAQUE_TO_ARGS(val, codesys) \
|
|
2755 DFC_EXT_SOURCE_LISP_OPAQUE_TO_ARGS (val, codesys)
|
|
2756
|
|
2757 /* Convert `sink' to args for dfc_convert_to_*_format() */
|
|
2758 #define DFC_SINK_ALLOCA_TO_ARGS(val) \
|
|
2759 dfc_simplified_sink_type = DFC_TYPE_DATA
|
|
2760 #define DFC_SINK_C_STRING_ALLOCA_TO_ARGS(val) \
|
|
2761 dfc_simplified_sink_type = DFC_TYPE_DATA
|
|
2762 #define DFC_SINK_MALLOC_TO_ARGS(val) \
|
|
2763 dfc_simplified_sink_type = DFC_TYPE_DATA
|
|
2764 #define DFC_SINK_C_STRING_MALLOC_TO_ARGS(val) \
|
|
2765 dfc_simplified_sink_type = DFC_TYPE_DATA
|
|
2766 #define DFC_SINK_LISP_STRING_TO_ARGS(val) \
|
|
2767 dfc_simplified_sink_type = DFC_TYPE_DATA
|
|
2768 #define DFC_SINK_LISP_OPAQUE_TO_ARGS(val) \
|
|
2769 dfc_simplified_sink_type = DFC_TYPE_DATA
|
|
2770 #define DFC_SINK_LISP_LSTREAM_TO_ARGS(val) do { \
|
|
2771 Lisp_Object dfc_sllta = (val); \
|
|
2772 type_checking_assert (LSTREAMP (dfc_sllta)); \
|
|
2773 dfc_sink.lisp_object = dfc_sllta; \
|
|
2774 dfc_simplified_sink_type = DFC_TYPE_LISP_LSTREAM; \
|
|
2775 } while (0)
|
|
2776 #define DFC_SINK_LISP_BUFFER_TO_ARGS(val) do { \
|
|
2777 struct buffer *dfc_slbta = XBUFFER (val); \
|
|
2778 dfc_sink.lisp_object = \
|
|
2779 make_lisp_buffer_output_stream \
|
|
2780 (dfc_slbta, BUF_PT (dfc_slbta), 0); \
|
|
2781 dfc_simplified_sink_type = DFC_TYPE_LISP_LSTREAM; \
|
|
2782 } while (0)
|
|
2783
|
|
2784 /* Assign to the `sink' lvalue(s) using the converted data. */
|
|
2785 /* + 2 because we double zero-extended to account for Unicode conversion */
|
|
2786 typedef union { char c; void *p; } *dfc_aliasing_voidpp;
|
|
2787 #define DFC_ALLOCA_USE_CONVERTED_DATA(sink) do { \
|
851
|
2788 void * dfc_sink_ret = ALLOCA (dfc_sink.data.len + 2); \
|
771
|
2789 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 2); \
|
|
2790 ((dfc_aliasing_voidpp) &(DFC_CPP_CAR sink))->p = dfc_sink_ret; \
|
|
2791 (DFC_CPP_CDR sink) = dfc_sink.data.len; \
|
|
2792 } while (0)
|
|
2793 #define DFC_MALLOC_USE_CONVERTED_DATA(sink) do { \
|
|
2794 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 2); \
|
|
2795 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 2); \
|
|
2796 ((dfc_aliasing_voidpp) &(DFC_CPP_CAR sink))->p = dfc_sink_ret; \
|
|
2797 (DFC_CPP_CDR sink) = dfc_sink.data.len; \
|
|
2798 } while (0)
|
|
2799 #define DFC_C_STRING_ALLOCA_USE_CONVERTED_DATA(sink) do { \
|
851
|
2800 void * dfc_sink_ret = ALLOCA (dfc_sink.data.len + 2); \
|
771
|
2801 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 2); \
|
|
2802 ((dfc_aliasing_voidpp) &(sink))->p = dfc_sink_ret; \
|
|
2803 } while (0)
|
|
2804 #define DFC_C_STRING_MALLOC_USE_CONVERTED_DATA(sink) do { \
|
|
2805 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 2); \
|
|
2806 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 2); \
|
|
2807 ((dfc_aliasing_voidpp) &(sink))->p = dfc_sink_ret; \
|
|
2808 } while (0)
|
|
2809 #define DFC_LISP_STRING_USE_CONVERTED_DATA(sink) \
|
867
|
2810 sink = make_string ((Ibyte *) dfc_sink.data.ptr, dfc_sink.data.len)
|
771
|
2811 #define DFC_LISP_OPAQUE_USE_CONVERTED_DATA(sink) \
|
|
2812 sink = make_opaque (dfc_sink.data.ptr, dfc_sink.data.len)
|
|
2813 #define DFC_LISP_LSTREAM_USE_CONVERTED_DATA(sink) /* data already used */
|
|
2814 #define DFC_LISP_BUFFER_USE_CONVERTED_DATA(sink) \
|
|
2815 Lstream_delete (XLSTREAM (dfc_sink.lisp_object))
|
|
2816
|
1318
|
2817 /* #define TEST_NEW_DFC */
|
|
2818
|
771
|
2819 /* Convenience macros for extremely common invocations */
|
1318
|
2820 #ifdef TEST_NEW_DFC
|
|
2821 #define C_STRING_TO_EXTERNAL(in, out, codesys) \
|
|
2822 do { * (Extbyte **) &(out) = \
|
|
2823 NEW_C_STRING_TO_EXTERNAL (in, codesys); } while (0)
|
|
2824 #define SIZED_C_STRING_TO_EXTERNAL(in, inlen, out, codesys) \
|
|
2825 do { * (Extbyte **) &(out) = \
|
|
2826 NEW_SIZED_C_STRING_TO_EXTERNAL (in, inlen, codesys); } while (0)
|
|
2827 #define EXTERNAL_TO_C_STRING(in, out, codesys) \
|
|
2828 do { * (Ibyte **) &(out) = \
|
|
2829 NEW_EXTERNAL_TO_C_STRING (in, codesys); } while (0)
|
|
2830 #define SIZED_EXTERNAL_TO_C_STRING(in, inlen, out, codesys) \
|
|
2831 do { * (Ibyte **) &(out) = \
|
|
2832 NEW_SIZED_EXTERNAL_TO_C_STRING (in, inlen, codesys); } while (0)
|
|
2833 #define LISP_STRING_TO_EXTERNAL(in, out, codesys) \
|
|
2834 do { * (Extbyte **) &(out) = \
|
|
2835 NEW_LISP_STRING_TO_EXTERNAL (in, codesys); } while (0)
|
|
2836 #else
|
|
2837 #define C_STRING_TO_EXTERNAL(in, out, codesys) \
|
|
2838 TO_EXTERNAL_FORMAT (C_STRING, in, C_STRING_ALLOCA, out, codesys)
|
|
2839 #define SIZED_C_STRING_TO_EXTERNAL(in, inlen, out, codesys) \
|
|
2840 TO_EXTERNAL_FORMAT (DATA, (in, inlen), C_STRING_ALLOCA, out, codesys)
|
|
2841 #define EXTERNAL_TO_C_STRING(in, out, codesys) \
|
|
2842 TO_INTERNAL_FORMAT (C_STRING, in, C_STRING_ALLOCA, out, codesys)
|
|
2843 #define SIZED_EXTERNAL_TO_C_STRING(in, inlen, out, codesys) \
|
|
2844 TO_INTERNAL_FORMAT (DATA, (in, inlen), C_STRING_ALLOCA, out, codesys)
|
|
2845 #define LISP_STRING_TO_EXTERNAL(in, out, codesys) \
|
|
2846 TO_EXTERNAL_FORMAT (LISP_STRING, in, C_STRING_ALLOCA, out, codesys)
|
|
2847 #endif /* TEST_NEW_DFC */
|
|
2848
|
|
2849 #define C_STRING_TO_SIZED_EXTERNAL(in, out, outlen, codesys) \
|
|
2850 TO_EXTERNAL_FORMAT (C_STRING, in, ALLOCA, (out, outlen), codesys)
|
|
2851 #define SIZED_C_STRING_TO_SIZED_EXTERNAL(in, inlen, out, outlen, codesys) \
|
|
2852 TO_EXTERNAL_FORMAT (DATA, (in, inlen), ALLOCA, (out, outlen), codesys)
|
|
2853 #define EXTERNAL_TO_SIZED_C_STRING(in, out, outlen, codesys) \
|
|
2854 TO_INTERNAL_FORMAT (C_STRING, in, ALLOCA, (out, outlen), codesys)
|
|
2855 #define SIZED_EXTERNAL_TO_SIZED_C_STRING(in, inlen, out, outlen, codesys) \
|
|
2856 TO_INTERNAL_FORMAT (DATA, (in, inlen), ALLOCA, (out, outlen), codesys)
|
|
2857 #define LISP_STRING_TO_SIZED_EXTERNAL(in, out, outlen, codesys) \
|
|
2858 TO_EXTERNAL_FORMAT (LISP_STRING, in, ALLOCA, (out, outlen), codesys)
|
|
2859
|
|
2860 /* In place of EXTERNAL_TO_LISP_STRING(), use build_ext_string() and/or
|
|
2861 make_ext_string(). */
|
|
2862
|
|
2863 #ifdef TEST_NEW_DFC
|
|
2864 #define C_STRING_TO_EXTERNAL_MALLOC(in, out, codesys) \
|
|
2865 do { * (Extbyte **) &(out) = \
|
|
2866 NEW_C_STRING_TO_EXTERNAL_MALLOC (in, codesys); } while (0)
|
|
2867 #define EXTERNAL_TO_C_STRING_MALLOC(in, out, codesys) \
|
|
2868 do { * (Ibyte **) &(out) = \
|
|
2869 NEW_EXTERNAL_TO_C_STRING_MALLOC (in, codesys); } while (0)
|
|
2870 #define LISP_STRING_TO_EXTERNAL_MALLOC(in, out, codesys) \
|
|
2871 do { * (Extbyte **) &(out) = \
|
|
2872 NEW_LISP_STRING_TO_EXTERNAL_MALLOC (in, codesys); } while (0)
|
|
2873 #else
|
|
2874 #define C_STRING_TO_EXTERNAL_MALLOC(in, out, codesys) \
|
|
2875 TO_EXTERNAL_FORMAT (C_STRING, in, C_STRING_MALLOC, out, codesys)
|
|
2876 #define EXTERNAL_TO_C_STRING_MALLOC(in, out, codesys) \
|
|
2877 TO_INTERNAL_FORMAT (C_STRING, in, C_STRING_MALLOC, out, codesys)
|
|
2878 #define LISP_STRING_TO_EXTERNAL_MALLOC(in, out, codesys) \
|
|
2879 TO_EXTERNAL_FORMAT (LISP_STRING, in, C_STRING_MALLOC, out, codesys)
|
|
2880 #endif /* TEST_NEW_DFC */
|
|
2881
|
|
2882 enum new_dfc_src_type
|
|
2883 {
|
|
2884 DFC_EXTERNAL,
|
|
2885 DFC_SIZED_EXTERNAL,
|
|
2886 DFC_INTERNAL,
|
|
2887 DFC_SIZED_INTERNAL,
|
|
2888 DFC_LISP_STRING
|
|
2889 };
|
|
2890
|
1632
|
2891 MODULE_API void *new_dfc_convert_malloc (const void *src, Bytecount src_size,
|
|
2892 enum new_dfc_src_type type,
|
|
2893 Lisp_Object codesys);
|
|
2894 MODULE_API void *new_dfc_convert_alloca (const char *srctext, void *alloca_data);
|
|
2895 MODULE_API Bytecount new_dfc_convert_size (const char *srctext, const void *src,
|
|
2896 Bytecount src_size,
|
|
2897 enum new_dfc_src_type type,
|
|
2898 Lisp_Object codesys);
|
1318
|
2899
|
|
2900 /* Version of EXTERNAL_TO_C_STRING that *RETURNS* the translated string,
|
|
2901 still in alloca() space. Requires some trickiness to do this, but gets
|
|
2902 it done! */
|
|
2903
|
|
2904 /* NOTE: If you make two invocations of the dfc functions below in the same
|
|
2905 subexpression and use the exact same expression for the source in both
|
|
2906 cases, you will lose. In this unlikely case, you will get an abort, and
|
|
2907 need to rewrite the code.
|
|
2908 */
|
|
2909
|
|
2910 /* We need to use ALLOCA_FUNCALL_OK here. Some compilers have been known
|
|
2911 to choke when alloca() occurs as a funcall argument, and so we check
|
|
2912 this in configure. Rewriting the expressions below to use a temporary
|
|
2913 variable, so that the call to alloca() is outside of
|
|
2914 new_dfc_convert_alloca(), won't help because the entire NEW_DFC call
|
|
2915 could be inside of a function call. */
|
|
2916
|
|
2917 #define NEW_DFC_CONVERT_1_ALLOCA(src, src_size, type, codesys) \
|
|
2918 new_dfc_convert_alloca \
|
|
2919 (#src, ALLOCA_FUNCALL_OK (new_dfc_convert_size (#src, src, src_size, \
|
|
2920 type, codesys)))
|
|
2921
|
|
2922 #define NEW_EXTERNAL_TO_C_STRING(src, codesys) \
|
|
2923 (Ibyte *) NEW_DFC_CONVERT_1_ALLOCA (src, -1, DFC_EXTERNAL, codesys)
|
|
2924 #define NEW_EXTERNAL_TO_C_STRING_MALLOC(src, codesys) \
|
|
2925 (Ibyte *) new_dfc_convert_malloc (src, -1, DFC_EXTERNAL, codesys)
|
|
2926 #define NEW_SIZED_EXTERNAL_TO_C_STRING(src, len, codesys) \
|
|
2927 (Ibyte *) NEW_DFC_CONVERT_1_ALLOCA (src, len, DFC_SIZED_EXTERNAL, codesys)
|
|
2928 #define NEW_SIZED_EXTERNAL_TO_C_STRING_MALLOC(src, len, codesys) \
|
|
2929 (Ibyte *) new_dfc_convert_malloc (src, len, DFC_SIZED_EXTERNAL, codesys)
|
|
2930 #define NEW_C_STRING_TO_EXTERNAL(src, codesys) \
|
|
2931 (Extbyte *) NEW_DFC_CONVERT_1_ALLOCA (src, -1, DFC_INTERNAL, codesys)
|
|
2932 #define NEW_C_STRING_TO_EXTERNAL_MALLOC(src, codesys) \
|
|
2933 (Extbyte *) new_dfc_convert_malloc (src, -1, DFC_INTERNAL, codesys)
|
|
2934 #define NEW_SIZED_C_STRING_TO_EXTERNAL(src, len, codesys) \
|
|
2935 (Extbyte *) NEW_DFC_CONVERT_1_ALLOCA (src, len, DFC_SIZED_INTERNAL, codesys)
|
|
2936 #define NEW_SIZED_C_STRING_TO_EXTERNAL_MALLOC(src, len, codesys) \
|
|
2937 (Extbyte *) new_dfc_convert_malloc (src, len, DFC_SIZED_INTERNAL, codesys)
|
|
2938 #define NEW_LISP_STRING_TO_EXTERNAL(src, codesys) \
|
|
2939 (Extbyte *) NEW_DFC_CONVERT_1_ALLOCA (LISP_TO_VOID (src), -1, \
|
|
2940 DFC_LISP_STRING, codesys)
|
|
2941 #define NEW_LISP_STRING_TO_EXTERNAL_MALLOC(src, codesys) \
|
|
2942 (Extbyte *) new_dfc_convert_malloc (LISP_TO_VOID (src), -1, \
|
|
2943 DFC_LISP_STRING, codesys)
|
771
|
2944
|
|
2945 /* Standins for various encodings, until we know them better */
|
|
2946 #define Qcommand_argument_encoding Qnative
|
|
2947 #define Qenvironment_variable_encoding Qnative
|
|
2948 #define Qunix_host_name_encoding Qnative
|
|
2949 #define Qunix_service_name_encoding Qnative
|
|
2950 #define Qmswindows_host_name_encoding Qmswindows_multibyte
|
|
2951 #define Qmswindows_service_name_encoding Qmswindows_multibyte
|
|
2952
|
1318
|
2953 /* Standins for various X encodings, until we know them better.
|
|
2954
|
|
2955 About encodings in X:
|
|
2956
|
|
2957 X works with 5 different encodings:
|
|
2958
|
|
2959 -- "Host Portable Character Encoding" == printable ASCII + space, tab,
|
|
2960 newline
|
|
2961
|
|
2962 -- STRING encoding == ASCII + Latin-1 + tab, newline
|
|
2963
|
|
2964 -- Locale-specific encoding
|
|
2965
|
|
2966 -- Compound text == STRING encoding + ISO-2022 escape sequences to
|
|
2967 switch between different locale-specific encodings.
|
|
2968
|
|
2969 -- ANSI C wide-character encoding
|
|
2970
|
|
2971 The Host Portable Character Encoding (HPCE) is used for atom names, font
|
|
2972 names, color names, keysyms, geometry strings, resource manager quarks,
|
|
2973 display names, locale names, and various other things. When describing
|
|
2974 such strings, the X manual typically says "If the ... is not in the Host
|
|
2975 Portable Character Encoding, the result is implementation dependent."
|
|
2976
|
|
2977 The wide-character encoding is used only in the Xwc* functions, which
|
|
2978 are provided as equivalents to Xmb* functions.
|
|
2979
|
|
2980 STRING and compound text are used in the value of string properties and
|
|
2981 selection data, both of which are values with an associated type atom,
|
|
2982 which can be STRING or COMPOUND_TEXT. It can also be a locale name, as
|
|
2983 specified in setlocale() (#### as usual, there is no normalization
|
|
2984 whatsoever of these names).
|
|
2985
|
|
2986 X also defines a type called "TEXT", which is used only as a requested
|
|
2987 type, and produces data in a type "convenient to the owner". However,
|
|
2988 there is some indication that X expects this to be the locale-specific
|
|
2989 encoding.
|
|
2990
|
|
2991 According to the glossary, the locale is used in
|
|
2992
|
|
2993 -- Encoding and processing of input method text
|
|
2994 -- Encoding of resource files and values
|
|
2995 -- Encoding and imaging of text strings
|
|
2996 -- Encoding and decoding for inter-client text communication
|
|
2997
|
|
2998 The functions XmbTextListToTextProperty and XmbTextPropertyToTextList
|
|
2999 (and Xwc* equivalents) can be used to convert between the
|
|
3000 locale-specific encoding (XTextStyle), STRING (XStringStyle), and
|
|
3001 compound text (XCompoundTextStyle), as well as XStdICCTextStyle, which
|
|
3002 converts to STRING if possible, and if not, COMPOUND_TEXT. This is
|
|
3003 used, for example, in XmbSetWMProperties, in the window_name and
|
|
3004 icon_name properties (WM_NAME and WM_ICON_NAME), which are in the
|
|
3005 locale-specific encoding on input, and are stored as STRING if possible,
|
|
3006 COMPOUND_TEXT otherwise.
|
|
3007 */
|
771
|
3008
|
|
3009 /* !!#### Need to verify the encoding used in lwlib -- Qnative or Qctext?
|
|
3010 Almost certainly the former. Use a standin for now. */
|
|
3011 #define Qlwlib_encoding Qnative
|
|
3012
|
1318
|
3013 /* The Host Portable Character Encoding. */
|
|
3014 #define Qx_hpc_encoding Qnative
|
|
3015
|
|
3016 #define Qx_atom_name_encoding Qx_hpc_encoding
|
|
3017 #define Qx_font_name_encoding Qx_hpc_encoding
|
|
3018 #define Qx_color_name_encoding Qx_hpc_encoding
|
|
3019 #define Qx_keysym_encoding Qx_hpc_encoding
|
|
3020 #define Qx_geometry_encoding Qx_hpc_encoding
|
|
3021 #define Qx_resource_name_encoding Qx_hpc_encoding
|
|
3022 #define Qx_application_class_encoding Qx_hpc_encoding
|
771
|
3023 /* the following probably must agree with Qcommand_argument_encoding and
|
|
3024 Qenvironment_variable_encoding */
|
1318
|
3025 #define Qx_display_name_encoding Qx_hpc_encoding
|
|
3026 #define Qx_xpm_data_encoding Qx_hpc_encoding
|
|
3027
|
|
3028 /* RedHat 6.2 contains a locale called "Francais" with the C-cedilla
|
|
3029 encoded in ISO2022! */
|
|
3030 #define Qlocale_name_encoding Qctext
|
771
|
3031
|
|
3032 #define Qstrerror_encoding Qnative
|
|
3033
|
1318
|
3034 /* Encoding for strings coming from Offix drag-n-drop */
|
|
3035 #define Qoffix_dnd_encoding Qnative
|
|
3036
|
|
3037 /* !!#### This exists to remind us that our hexify routine is totally
|
|
3038 un-Muleized. */
|
|
3039 #define Qdnd_hexify_encoding Qascii
|
|
3040
|
771
|
3041 #define GET_STRERROR(var, num) \
|
|
3042 do { \
|
|
3043 int __gsnum__ = (num); \
|
|
3044 Extbyte * __gserr__ = strerror (__gsnum__); \
|
|
3045 \
|
|
3046 if (!__gserr__) \
|
|
3047 { \
|
867
|
3048 var = alloca_ibytes (99); \
|
771
|
3049 qxesprintf (var, "Unknown error %d", __gsnum__); \
|
|
3050 } \
|
|
3051 else \
|
|
3052 EXTERNAL_TO_C_STRING (__gserr__, var, Qstrerror_encoding); \
|
|
3053 } while (0)
|
|
3054
|
|
3055 #endif /* INCLUDED_text_h_ */
|