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