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