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