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