771
|
1 /* Buffer manipulation primitives for XEmacs.
|
|
2 Copyright (C) 1995 Sun Microsystems, Inc.
|
|
3 Copyright (C) 1995, 1996, 2000, 2001, 2002 Ben Wing.
|
|
4 Copyright (C) 1999 Martin Buchholz.
|
|
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: Not in FSF. */
|
|
24
|
|
25 /* Authorship:
|
|
26 */
|
|
27
|
|
28 #include <config.h>
|
|
29 #include "lisp.h"
|
|
30
|
|
31 #include "buffer.h"
|
|
32 #include "charset.h"
|
|
33 #include "file-coding.h"
|
|
34 #include "lstream.h"
|
|
35
|
|
36
|
|
37 /************************************************************************/
|
|
38 /* long comments */
|
|
39 /************************************************************************/
|
|
40
|
|
41 /*
|
826
|
42 ==========================================================================
|
|
43 1. Character Sets
|
|
44 ==========================================================================
|
771
|
45
|
|
46 A character set (or "charset") is an ordered set of characters.
|
826
|
47
|
|
48 A character (which is, BTW, a surprisingly complex concept) is, in a
|
|
49 written representation of text, the most basic written unit that has a
|
|
50 meaning of its own. It's comparable to a phoneme when analyzing words
|
|
51 in spoken speech. Just like with a phoneme (which is an abstract
|
|
52 concept, and is represented in actual spoken speech by one or more
|
|
53 allophones, ...&&#### finish this., a character is actually an abstract
|
|
54 concept
|
|
55
|
771
|
56 A particular character in a charset is indexed using one or
|
|
57 more "position codes", which are non-negative integers.
|
|
58 The number of position codes needed to identify a particular
|
|
59 character in a charset is called the "dimension" of the
|
|
60 charset. In XEmacs/Mule, all charsets have 1 or 2 dimensions,
|
|
61 and the size of all charsets (except for a few special cases)
|
|
62 is either 94, 96, 94 by 94, or 96 by 96. The range of
|
|
63 position codes used to index characters from any of these
|
|
64 types of character sets is as follows:
|
|
65
|
|
66 Charset type Position code 1 Position code 2
|
|
67 ------------------------------------------------------------
|
|
68 94 33 - 126 N/A
|
|
69 96 32 - 127 N/A
|
|
70 94x94 33 - 126 33 - 126
|
|
71 96x96 32 - 127 32 - 127
|
|
72
|
|
73 Note that in the above cases position codes do not start at
|
|
74 an expected value such as 0 or 1. The reason for this will
|
|
75 become clear later.
|
|
76
|
|
77 For example, Latin-1 is a 96-character charset, and JISX0208
|
|
78 (the Japanese national character set) is a 94x94-character
|
|
79 charset.
|
|
80
|
|
81 [Note that, although the ranges above define the *valid*
|
|
82 position codes for a charset, some of the slots in a particular
|
|
83 charset may in fact be empty. This is the case for JISX0208,
|
|
84 for example, where (e.g.) all the slots whose first
|
|
85 position code is in the range 118 - 127 are empty.]
|
|
86
|
|
87 There are three charsets that do not follow the above rules.
|
|
88 All of them have one dimension, and have ranges of position
|
|
89 codes as follows:
|
|
90
|
|
91 Charset name Position code 1
|
|
92 ------------------------------------
|
|
93 ASCII 0 - 127
|
|
94 Control-1 0 - 31
|
|
95 Composite 0 - some large number
|
|
96
|
|
97 (The upper bound of the position code for composite characters
|
|
98 has not yet been determined, but it will probably be at
|
|
99 least 16,383).
|
|
100
|
|
101 ASCII is the union of two subsidiary character sets:
|
|
102 Printing-ASCII (the printing ASCII character set,
|
|
103 consisting of position codes 33 - 126, like for a standard
|
|
104 94-character charset) and Control-ASCII (the non-printing
|
|
105 characters that would appear in a binary file with codes 0
|
|
106 - 32 and 127).
|
|
107
|
|
108 Control-1 contains the non-printing characters that would
|
|
109 appear in a binary file with codes 128 - 159.
|
|
110
|
|
111 Composite contains characters that are generated by
|
|
112 overstriking one or more characters from other charsets.
|
|
113
|
|
114 Note that some characters in ASCII, and all characters
|
|
115 in Control-1, are "control" (non-printing) characters.
|
|
116 These have no printed representation but instead control
|
|
117 some other function of the printing (e.g. TAB or 8 moves
|
|
118 the current character position to the next tab stop).
|
|
119 All other characters in all charsets are "graphic"
|
|
120 (printing) characters.
|
|
121
|
|
122 When a binary file is read in, the bytes in the file are
|
|
123 assigned to character sets as follows:
|
|
124
|
|
125 Bytes Character set Range
|
|
126 --------------------------------------------------
|
|
127 0 - 127 ASCII 0 - 127
|
|
128 128 - 159 Control-1 0 - 31
|
|
129 160 - 255 Latin-1 32 - 127
|
|
130
|
|
131 This is a bit ad-hoc but gets the job done.
|
|
132
|
826
|
133 ==========================================================================
|
|
134 2. Encodings
|
|
135 ==========================================================================
|
771
|
136
|
|
137 An "encoding" is a way of numerically representing
|
|
138 characters from one or more character sets. If an encoding
|
|
139 only encompasses one character set, then the position codes
|
|
140 for the characters in that character set could be used
|
|
141 directly. This is not possible, however, if more than one
|
|
142 character set is to be used in the encoding.
|
|
143
|
|
144 For example, the conversion detailed above between bytes in
|
|
145 a binary file and characters is effectively an encoding
|
|
146 that encompasses the three character sets ASCII, Control-1,
|
|
147 and Latin-1 in a stream of 8-bit bytes.
|
|
148
|
|
149 Thus, an encoding can be viewed as a way of encoding
|
|
150 characters from a specified group of character sets using a
|
|
151 stream of bytes, each of which contains a fixed number of
|
|
152 bits (but not necessarily 8, as in the common usage of
|
|
153 "byte").
|
|
154
|
|
155 Here are descriptions of a couple of common
|
|
156 encodings:
|
|
157
|
|
158
|
|
159 A. Japanese EUC (Extended Unix Code)
|
|
160
|
|
161 This encompasses the character sets:
|
|
162 - Printing-ASCII,
|
|
163 - Katakana-JISX0201 (half-width katakana, the right half of JISX0201).
|
|
164 - Japanese-JISX0208
|
|
165 - Japanese-JISX0212
|
|
166 It uses 8-bit bytes.
|
|
167
|
|
168 Note that Printing-ASCII and Katakana-JISX0201 are 94-character
|
|
169 charsets, while Japanese-JISX0208 is a 94x94-character charset.
|
|
170
|
|
171 The encoding is as follows:
|
|
172
|
|
173 Character set Representation (PC == position-code)
|
|
174 ------------- --------------
|
|
175 Printing-ASCII PC1
|
|
176 Japanese-JISX0208 PC1 + 0x80 | PC2 + 0x80
|
|
177 Katakana-JISX0201 0x8E | PC1 + 0x80
|
|
178
|
|
179
|
|
180 B. JIS7
|
|
181
|
|
182 This encompasses the character sets:
|
|
183 - Printing-ASCII
|
|
184 - Latin-JISX0201 (the left half of JISX0201; this character set is
|
|
185 very similar to Printing-ASCII and is a 94-character charset)
|
|
186 - Japanese-JISX0208
|
|
187 - Katakana-JISX0201
|
|
188 It uses 7-bit bytes.
|
|
189
|
|
190 Unlike Japanese EUC, this is a "modal" encoding, which
|
|
191 means that there are multiple states that the encoding can
|
|
192 be in, which affect how the bytes are to be interpreted.
|
|
193 Special sequences of bytes (called "escape sequences")
|
|
194 are used to change states.
|
|
195
|
|
196 The encoding is as follows:
|
|
197
|
|
198 Character set Representation
|
|
199 ------------- --------------
|
|
200 Printing-ASCII PC1
|
|
201 Latin-JISX0201 PC1
|
|
202 Katakana-JISX0201 PC1
|
|
203 Japanese-JISX0208 PC1 | PC2
|
|
204
|
|
205 Escape sequence ASCII equivalent Meaning
|
|
206 --------------- ---------------- -------
|
|
207 0x1B 0x28 0x42 ESC ( B invoke Printing-ASCII
|
|
208 0x1B 0x28 0x4A ESC ( J invoke Latin-JISX0201
|
|
209 0x1B 0x28 0x49 ESC ( I invoke Katakana-JISX0201
|
|
210 0x1B 0x24 0x42 ESC $ B invoke Japanese-JISX0208
|
|
211
|
|
212 Initially, Printing-ASCII is invoked.
|
|
213
|
826
|
214 ==========================================================================
|
|
215 3. Internal Mule Encodings
|
|
216 ==========================================================================
|
771
|
217
|
|
218 In XEmacs/Mule, each character set is assigned a unique number,
|
|
219 called a "leading byte". This is used in the encodings of a
|
|
220 character. Leading bytes are in the range 0x80 - 0xFF
|
|
221 (except for ASCII, which has a leading byte of 0), although
|
|
222 some leading bytes are reserved.
|
|
223
|
|
224 Charsets whose leading byte is in the range 0x80 - 0x9F are
|
|
225 called "official" and are used for built-in charsets.
|
|
226 Other charsets are called "private" and have leading bytes
|
|
227 in the range 0xA0 - 0xFF; these are user-defined charsets.
|
|
228
|
|
229 More specifically:
|
|
230
|
|
231 Character set Leading byte
|
|
232 ------------- ------------
|
|
233 ASCII 0 (0x7F in arrays indexed by leading byte)
|
|
234 Composite 0x8D
|
|
235 Dimension-1 Official 0x80 - 0x8C/0x8D
|
|
236 (0x8E is free)
|
|
237 Control 0x8F
|
|
238 Dimension-2 Official 0x90 - 0x99
|
|
239 (0x9A - 0x9D are free)
|
|
240 Dimension-1 Private Marker 0x9E
|
|
241 Dimension-2 Private Marker 0x9F
|
|
242 Dimension-1 Private 0xA0 - 0xEF
|
|
243 Dimension-2 Private 0xF0 - 0xFF
|
|
244
|
|
245 There are two internal encodings for characters in XEmacs/Mule.
|
|
246 One is called "string encoding" and is an 8-bit encoding that
|
|
247 is used for representing characters in a buffer or string.
|
|
248 It uses 1 to 4 bytes per character. The other is called
|
|
249 "character encoding" and is a 19-bit encoding that is used
|
|
250 for representing characters individually in a variable.
|
|
251
|
|
252 (In the following descriptions, we'll ignore composite
|
|
253 characters for the moment. We also give a general (structural)
|
|
254 overview first, followed later by the exact details.)
|
|
255
|
|
256 A. Internal String Encoding
|
|
257
|
|
258 ASCII characters are encoded using their position code directly.
|
|
259 Other characters are encoded using their leading byte followed
|
|
260 by their position code(s) with the high bit set. Characters
|
|
261 in private character sets have their leading byte prefixed with
|
|
262 a "leading byte prefix", which is either 0x9E or 0x9F. (No
|
|
263 character sets are ever assigned these leading bytes.) Specifically:
|
|
264
|
|
265 Character set Encoding (PC == position-code)
|
|
266 ------------- -------- (LB == leading-byte)
|
|
267 ASCII PC1 |
|
|
268 Control-1 LB | PC1 + 0xA0
|
|
269 Dimension-1 official LB | PC1 + 0x80
|
|
270 Dimension-1 private 0x9E | LB | PC1 + 0x80
|
|
271 Dimension-2 official LB | PC1 | PC2 + 0x80
|
|
272 Dimension-2 private 0x9F | LB | PC1 + 0x80 | PC2 + 0x80
|
|
273
|
|
274 The basic characteristic of this encoding is that the first byte
|
|
275 of all characters is in the range 0x00 - 0x9F, and the second and
|
|
276 following bytes of all characters is in the range 0xA0 - 0xFF.
|
|
277 This means that it is impossible to get out of sync, or more
|
|
278 specifically:
|
|
279
|
|
280 1. Given any byte position, the beginning of the character it is
|
|
281 within can be determined in constant time.
|
|
282 2. Given any byte position at the beginning of a character, the
|
|
283 beginning of the next character can be determined in constant
|
|
284 time.
|
|
285 3. Given any byte position at the beginning of a character, the
|
|
286 beginning of the previous character can be determined in constant
|
|
287 time.
|
|
288 4. Textual searches can simply treat encoded strings as if they
|
|
289 were encoded in a one-byte-per-character fashion rather than
|
|
290 the actual multi-byte encoding.
|
|
291
|
|
292 None of the standard non-modal encodings meet all of these
|
|
293 conditions. For example, EUC satisfies only (2) and (3), while
|
|
294 Shift-JIS and Big5 (not yet described) satisfy only (2). (All
|
|
295 non-modal encodings must satisfy (2), in order to be unambiguous.)
|
|
296
|
|
297 B. Internal Character Encoding
|
|
298
|
|
299 One 19-bit word represents a single character. The word is
|
|
300 separated into three fields:
|
|
301
|
|
302 Bit number: 18 17 16 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
|
|
303 <------------> <------------------> <------------------>
|
|
304 Field: 1 2 3
|
|
305
|
|
306 Note that fields 2 and 3 hold 7 bits each, while field 1 holds 5 bits.
|
|
307
|
|
308 Character set Field 1 Field 2 Field 3
|
|
309 ------------- ------- ------- -------
|
|
310 ASCII 0 0 PC1
|
|
311 range: (00 - 7F)
|
|
312 Control-1 0 1 PC1
|
|
313 range: (00 - 1F)
|
|
314 Dimension-1 official 0 LB - 0x7F PC1
|
|
315 range: (01 - 0D) (20 - 7F)
|
|
316 Dimension-1 private 0 LB - 0x80 PC1
|
|
317 range: (20 - 6F) (20 - 7F)
|
|
318 Dimension-2 official LB - 0x8F PC1 PC2
|
|
319 range: (01 - 0A) (20 - 7F) (20 - 7F)
|
|
320 Dimension-2 private LB - 0xE1 PC1 PC2
|
|
321 range: (0F - 1E) (20 - 7F) (20 - 7F)
|
|
322 Composite 0x1F ? ?
|
|
323
|
|
324 Note that character codes 0 - 255 are the same as the "binary encoding"
|
|
325 described above.
|
826
|
326
|
|
327 Most of the code in XEmacs knows nothing of the representation of a
|
|
328 character other than that values 0 - 255 represent ASCII, Control 1,
|
|
329 and Latin 1.
|
|
330
|
|
331 WARNING WARNING WARNING: The Boyer-Moore code in search.c, and the
|
|
332 code in search_buffer() that determines whether that code can be used,
|
|
333 knows that "field 3" in a character always corresponds to the last
|
|
334 byte in the textual representation of the character. (This is important
|
|
335 because the Boyer-Moore algorithm works by looking at the last byte
|
|
336 of the search string and &&#### finish this.
|
|
337
|
|
338 ==========================================================================
|
|
339 4. Buffer Positions and Other Typedefs
|
|
340 ==========================================================================
|
|
341
|
|
342 A. Buffer Positions
|
|
343
|
|
344 There are three possible ways to specify positions in a buffer. All
|
|
345 of these are one-based: the beginning of the buffer is position or
|
|
346 index 1, and 0 is not a valid position.
|
|
347
|
|
348 As a "buffer position" (typedef Charbpos):
|
|
349
|
|
350 This is an index specifying an offset in characters from the
|
|
351 beginning of the buffer. Note that buffer positions are
|
|
352 logically *between* characters, not on a character. The
|
|
353 difference between two buffer positions specifies the number of
|
|
354 characters between those positions. Buffer positions are the
|
|
355 only kind of position externally visible to the user.
|
|
356
|
|
357 As a "byte index" (typedef Bytebpos):
|
|
358
|
|
359 This is an index over the bytes used to represent the characters
|
|
360 in the buffer. If there is no Mule support, this is identical
|
|
361 to a buffer position, because each character is represented
|
|
362 using one byte. However, with Mule support, many characters
|
|
363 require two or more bytes for their representation, and so a
|
|
364 byte index may be greater than the corresponding buffer
|
|
365 position.
|
|
366
|
|
367 As a "memory index" (typedef Membpos):
|
|
368
|
|
369 This is the byte index adjusted for the gap. For positions
|
|
370 before the gap, this is identical to the byte index. For
|
|
371 positions after the gap, this is the byte index plus the gap
|
|
372 size. There are two possible memory indices for the gap
|
|
373 position; the memory index at the beginning of the gap should
|
|
374 always be used, except in code that deals with manipulating the
|
|
375 gap, where both indices may be seen. The address of the
|
|
376 character "at" (i.e. following) a particular position can be
|
|
377 obtained from the formula
|
|
378
|
|
379 buffer_start_address + memory_index(position) - 1
|
|
380
|
|
381 except in the case of characters at the gap position.
|
|
382
|
|
383 B. Other Typedefs
|
|
384
|
|
385 Emchar:
|
|
386 -------
|
|
387 This typedef represents a single Emacs character, which can be
|
|
388 ASCII, ISO-8859, or some extended character, as would typically
|
|
389 be used for Kanji. Note that the representation of a character
|
|
390 as an Emchar is *not* the same as the representation of that
|
|
391 same character in a string; thus, you cannot do the standard
|
|
392 C trick of passing a pointer to a character to a function that
|
|
393 expects a string.
|
|
394
|
|
395 An Emchar takes up 19 bits of representation and (for code
|
|
396 compatibility and such) is compatible with an int. This
|
|
397 representation is visible on the Lisp level. The important
|
|
398 characteristics of the Emchar representation are
|
|
399
|
|
400 -- values 0x00 - 0x7f represent ASCII.
|
|
401 -- values 0x80 - 0xff represent the right half of ISO-8859-1.
|
|
402 -- values 0x100 and up represent all other characters.
|
|
403
|
|
404 This means that Emchar values are upwardly compatible with
|
|
405 the standard 8-bit representation of ASCII/ISO-8859-1.
|
|
406
|
|
407 Intbyte:
|
|
408 --------
|
|
409 The data in a buffer or string is logically made up of Intbyte
|
|
410 objects, where a Intbyte takes up the same amount of space as a
|
|
411 char. (It is declared differently, though, to catch invalid
|
|
412 usages.) Strings stored using Intbytes are said to be in
|
|
413 "internal format". The important characteristics of internal
|
|
414 format are
|
|
415
|
|
416 -- ASCII characters are represented as a single Intbyte,
|
|
417 in the range 0 - 0x7f.
|
|
418 -- All other characters are represented as a Intbyte in
|
|
419 the range 0x80 - 0x9f followed by one or more Intbytes
|
|
420 in the range 0xa0 to 0xff.
|
|
421
|
|
422 This leads to a number of desirable properties:
|
|
423
|
|
424 -- Given the position of the beginning of a character,
|
|
425 you can find the beginning of the next or previous
|
|
426 character in constant time.
|
|
427 -- When searching for a substring or an ASCII character
|
|
428 within the string, you need merely use standard
|
|
429 searching routines.
|
|
430
|
|
431 array of char:
|
|
432 --------------
|
|
433 Strings that go in or out of Emacs are in "external format",
|
|
434 typedef'ed as an array of char or a char *. There is more
|
|
435 than one external format (JIS, EUC, etc.) but they all
|
|
436 have similar properties. They are modal encodings,
|
|
437 which is to say that the meaning of particular bytes is
|
|
438 not fixed but depends on what "mode" the string is currently
|
|
439 in (e.g. bytes in the range 0 - 0x7f might be
|
|
440 interpreted as ASCII, or as Hiragana, or as 2-byte Kanji,
|
|
441 depending on the current mode). The mode starts out in
|
|
442 ASCII/ISO-8859-1 and is switched using escape sequences --
|
|
443 for example, in the JIS encoding, 'ESC $ B' switches to a
|
|
444 mode where pairs of bytes in the range 0 - 0x7f
|
|
445 are interpreted as Kanji characters.
|
|
446
|
|
447 External-formatted data is generally desirable for passing
|
|
448 data between programs because it is upwardly compatible
|
|
449 with standard ASCII/ISO-8859-1 strings and may require
|
|
450 less space than internal encodings such as the one
|
|
451 described above. In addition, some encodings (e.g. JIS)
|
|
452 keep all characters (except the ESC used to switch modes)
|
|
453 in the printing ASCII range 0x20 - 0x7e, which results in
|
|
454 a much higher probability that the data will avoid being
|
|
455 garbled in transmission. Externally-formatted data is
|
|
456 generally not very convenient to work with, however, and
|
|
457 for this reason is usually converted to internal format
|
|
458 before any work is done on the string.
|
|
459
|
|
460 NOTE: filenames need to be in external format so that
|
|
461 ISO-8859-1 characters come out correctly.
|
|
462
|
|
463 Charcount:
|
|
464 ----------
|
|
465 This typedef represents a count of characters, such as
|
|
466 a character offset into a string or the number of
|
|
467 characters between two positions in a buffer. The
|
|
468 difference between two Charbpos's is a Charcount, and
|
|
469 character positions in a string are represented using
|
|
470 a Charcount.
|
|
471
|
|
472 Bytecount:
|
|
473 ----------
|
|
474 Similar to a Charcount but represents a count of bytes.
|
|
475 The difference between two Bytebpos's is a Bytecount.
|
|
476
|
|
477
|
|
478 C. Usage of the Various Representations
|
|
479
|
|
480 Memory indices are used in low-level functions in insdel.c and for
|
|
481 extent endpoints and marker positions. The reason for this is that
|
|
482 this way, the extents and markers don't need to be updated for most
|
|
483 insertions, which merely shrink the gap and don't move any
|
|
484 characters around in memory.
|
|
485
|
|
486 (The beginning-of-gap memory index simplifies insertions w.r.t.
|
|
487 markers, because text usually gets inserted after markers. For
|
|
488 extents, it is merely for consistency, because text can get
|
|
489 inserted either before or after an extent's endpoint depending on
|
|
490 the open/closedness of the endpoint.)
|
|
491
|
|
492 Byte indices are used in other code that needs to be fast,
|
|
493 such as the searching, redisplay, and extent-manipulation code.
|
|
494
|
|
495 Buffer positions are used in all other code. This is because this
|
|
496 representation is easiest to work with (especially since Lisp
|
|
497 code always uses buffer positions), necessitates the fewest
|
|
498 changes to existing code, and is the safest (e.g. if the text gets
|
|
499 shifted underneath a buffer position, it will still point to a
|
|
500 character; if text is shifted under a byte index, it might point
|
|
501 to the middle of a character, which would be bad).
|
|
502
|
|
503 Similarly, Charcounts are used in all code that deals with strings
|
|
504 except for code that needs to be fast, which used Bytecounts.
|
|
505
|
|
506 Strings are always passed around internally using internal format.
|
|
507 Conversions between external format are performed at the time
|
|
508 that the data goes in or out of Emacs.
|
|
509
|
|
510 D. Working With the Various Representations
|
|
511
|
|
512 We write things this way because it's very important the
|
|
513 MAX_BYTEBPOS_GAP_SIZE_3 is a multiple of 3. (As it happens,
|
|
514 65535 is a multiple of 3, but this may not always be the
|
|
515 case. #### unfinished
|
|
516
|
|
517 ==========================================================================
|
|
518 5. Miscellaneous
|
|
519 ==========================================================================
|
|
520
|
|
521 A. Unicode Support
|
771
|
522
|
|
523 Adding Unicode support is very desirable. Unicode will likely be a
|
|
524 very common representation in the future, and thus we should
|
|
525 represent Unicode characters using three bytes instead of four.
|
|
526 This means we need to find leading bytes for Unicode. Given that
|
|
527 there are 65,536 characters in Unicode and we can attach 96x96 =
|
|
528 9,216 characters per leading byte, we need eight leading bytes for
|
|
529 Unicode. We currently have four free (0x9A - 0x9D), and with a
|
|
530 little bit of rearranging we can get five: ASCII doesn't really
|
|
531 need to take up a leading byte. (We could just as well use 0x7F,
|
|
532 with a little change to the functions that assume that 0x80 is the
|
|
533 lowest leading byte.) This means we still need to dump three
|
|
534 leading bytes and move them into private space. The CNS charsets
|
|
535 are good candidates since they are rarely used, and
|
|
536 JAPANESE_JISX0208_1978 is becoming less and less used and could
|
826
|
537 also be dumped.
|
|
538
|
|
539 B. Composite Characters
|
|
540
|
|
541 Composite characters are characters constructed by overstriking two
|
771
|
542 or more regular characters.
|
|
543
|
|
544 1) The old Mule implementation involves storing composite characters
|
|
545 in a buffer as a tag followed by all of the actual characters
|
|
546 used to make up the composite character. I think this is a bad
|
|
547 idea; it greatly complicates code that wants to handle strings
|
|
548 one character at a time because it has to deal with the possibility
|
|
549 of great big ungainly characters. It's much more reasonable to
|
|
550 simply store an index into a table of composite characters.
|
|
551
|
|
552 2) The current implementation only allows for 16,384 separate
|
|
553 composite characters over the lifetime of the XEmacs process.
|
|
554 This could become a potential problem if the user
|
|
555 edited lots of different files that use composite characters.
|
|
556 Due to FSF bogosity, increasing the number of allowable
|
|
557 composite characters under Mule would decrease the number
|
|
558 of possible faces that can exist. Mule already has shrunk
|
|
559 this to 2048, and further shrinkage would become uncomfortable.
|
|
560 No such problems exist in XEmacs.
|
|
561
|
|
562 Composite characters could be represented as 0x8D C1 C2 C3,
|
|
563 where each C[1-3] is in the range 0xA0 - 0xFF. This allows
|
|
564 for slightly under 2^20 (one million) composite characters
|
|
565 over the XEmacs process lifetime, and you only need to
|
|
566 increase the size of a Mule character from 19 to 21 bits.
|
|
567 Or you could use 0x8D C1 C2 C3 C4, allowing for about
|
826
|
568 85 million (slightly over 2^26) composite characters.
|
|
569
|
|
570 */
|
771
|
571
|
|
572
|
|
573 /************************************************************************/
|
|
574 /* declarations */
|
|
575 /************************************************************************/
|
|
576
|
|
577 Eistring the_eistring_zero_init, the_eistring_malloc_zero_init;
|
|
578
|
|
579 #define MAX_CHARBPOS_GAP_SIZE_3 (65535/3)
|
|
580 #define MAX_BYTEBPOS_GAP_SIZE_3 (3 * MAX_CHARBPOS_GAP_SIZE_3)
|
|
581
|
|
582 short three_to_one_table[1 + MAX_BYTEBPOS_GAP_SIZE_3];
|
|
583
|
|
584 #ifdef MULE
|
|
585
|
|
586 /* Table of number of bytes in the string representation of a character
|
|
587 indexed by the first byte of that representation.
|
|
588
|
|
589 rep_bytes_by_first_byte(c) is more efficient than the equivalent
|
|
590 canonical computation:
|
|
591
|
826
|
592 XCHARSET_REP_BYTES (charset_by_leading_byte (c)) */
|
771
|
593
|
|
594 const Bytecount rep_bytes_by_first_byte[0xA0] =
|
|
595 { /* 0x00 - 0x7f are for straight ASCII */
|
|
596 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
597 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
598 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
599 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
600 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
601 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
602 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
603 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
|
|
604 /* 0x80 - 0x8f are for Dimension-1 official charsets */
|
|
605 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
|
|
606 /* 0x90 - 0x9d are for Dimension-2 official charsets */
|
|
607 /* 0x9e is for Dimension-1 private charsets */
|
|
608 /* 0x9f is for Dimension-2 private charsets */
|
|
609 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 4
|
|
610 };
|
|
611
|
|
612 #ifdef ENABLE_COMPOSITE_CHARS
|
|
613
|
|
614 /* Hash tables for composite chars. One maps string representing
|
|
615 composed chars to their equivalent chars; one goes the
|
|
616 other way. */
|
|
617 Lisp_Object Vcomposite_char_char2string_hash_table;
|
|
618 Lisp_Object Vcomposite_char_string2char_hash_table;
|
|
619
|
|
620 static int composite_char_row_next;
|
|
621 static int composite_char_col_next;
|
|
622
|
|
623 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
624
|
|
625 #endif /* MULE */
|
|
626
|
|
627
|
|
628 /************************************************************************/
|
|
629 /* qxestr***() functions */
|
|
630 /************************************************************************/
|
|
631
|
|
632 /* Most are inline functions in lisp.h */
|
|
633
|
|
634 int
|
|
635 qxesprintf (Intbyte *buffer, const CIntbyte *format, ...)
|
|
636 {
|
|
637 va_list args;
|
|
638 int retval;
|
|
639
|
|
640 va_start (args, format);
|
|
641 retval = vsprintf ((char *) buffer, format, args);
|
|
642 va_end (args);
|
|
643
|
|
644 return retval;
|
|
645 }
|
|
646
|
|
647 /* strcasecmp() implementation from BSD */
|
|
648 static Intbyte strcasecmp_charmap[] = {
|
|
649 '\000', '\001', '\002', '\003', '\004', '\005', '\006', '\007',
|
|
650 '\010', '\011', '\012', '\013', '\014', '\015', '\016', '\017',
|
|
651 '\020', '\021', '\022', '\023', '\024', '\025', '\026', '\027',
|
|
652 '\030', '\031', '\032', '\033', '\034', '\035', '\036', '\037',
|
|
653 '\040', '\041', '\042', '\043', '\044', '\045', '\046', '\047',
|
|
654 '\050', '\051', '\052', '\053', '\054', '\055', '\056', '\057',
|
|
655 '\060', '\061', '\062', '\063', '\064', '\065', '\066', '\067',
|
|
656 '\070', '\071', '\072', '\073', '\074', '\075', '\076', '\077',
|
|
657 '\100', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
658 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
659 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
660 '\170', '\171', '\172', '\133', '\134', '\135', '\136', '\137',
|
|
661 '\140', '\141', '\142', '\143', '\144', '\145', '\146', '\147',
|
|
662 '\150', '\151', '\152', '\153', '\154', '\155', '\156', '\157',
|
|
663 '\160', '\161', '\162', '\163', '\164', '\165', '\166', '\167',
|
|
664 '\170', '\171', '\172', '\173', '\174', '\175', '\176', '\177',
|
|
665 '\200', '\201', '\202', '\203', '\204', '\205', '\206', '\207',
|
|
666 '\210', '\211', '\212', '\213', '\214', '\215', '\216', '\217',
|
|
667 '\220', '\221', '\222', '\223', '\224', '\225', '\226', '\227',
|
|
668 '\230', '\231', '\232', '\233', '\234', '\235', '\236', '\237',
|
|
669 '\240', '\241', '\242', '\243', '\244', '\245', '\246', '\247',
|
|
670 '\250', '\251', '\252', '\253', '\254', '\255', '\256', '\257',
|
|
671 '\260', '\261', '\262', '\263', '\264', '\265', '\266', '\267',
|
|
672 '\270', '\271', '\272', '\273', '\274', '\275', '\276', '\277',
|
|
673 '\300', '\301', '\302', '\303', '\304', '\305', '\306', '\307',
|
|
674 '\310', '\311', '\312', '\313', '\314', '\315', '\316', '\317',
|
|
675 '\320', '\321', '\322', '\323', '\324', '\325', '\326', '\327',
|
|
676 '\330', '\331', '\332', '\333', '\334', '\335', '\336', '\337',
|
|
677 '\340', '\341', '\342', '\343', '\344', '\345', '\346', '\347',
|
|
678 '\350', '\351', '\352', '\353', '\354', '\355', '\356', '\357',
|
|
679 '\360', '\361', '\362', '\363', '\364', '\365', '\366', '\367',
|
|
680 '\370', '\371', '\372', '\373', '\374', '\375', '\376', '\377',
|
|
681 };
|
|
682
|
|
683 /* A version that works like generic strcasecmp() -- only collapsing
|
|
684 case in ASCII A-Z/a-z. This is safe on Mule strings due to the
|
|
685 current representation.
|
|
686
|
|
687 This version was written by some Berkeley coder, favoring
|
|
688 nanosecond improvements over clarity. In all other versions below,
|
|
689 we use symmetrical algorithms that may sacrifice a few machine
|
|
690 cycles but are MUCH MUCH clearer, which counts a lot more.
|
|
691 */
|
|
692
|
|
693 int
|
|
694 qxestrcasecmp (const Intbyte *s1, const Intbyte *s2)
|
|
695 {
|
|
696 Intbyte *cm = strcasecmp_charmap;
|
|
697
|
|
698 while (cm[*s1] == cm[*s2++])
|
|
699 if (*s1++ == '\0')
|
|
700 return (0);
|
|
701
|
|
702 return (cm[*s1] - cm[*--s2]);
|
|
703 }
|
|
704
|
|
705 int
|
|
706 ascii_strcasecmp (const Char_ASCII *s1, const Char_ASCII *s2)
|
|
707 {
|
|
708 return qxestrcasecmp ((const Intbyte *) s1, (const Intbyte *) s2);
|
|
709 }
|
|
710
|
|
711 int
|
|
712 qxestrcasecmp_c (const Intbyte *s1, const Char_ASCII *s2)
|
|
713 {
|
|
714 return qxestrcasecmp (s1, (const Intbyte *) s2);
|
|
715 }
|
|
716
|
|
717 /* An internationalized version that collapses case in a general fashion.
|
|
718 */
|
|
719
|
|
720 int
|
|
721 qxestrcasecmp_i18n (const Intbyte *s1, const Intbyte *s2)
|
|
722 {
|
|
723 while (*s1 && *s2)
|
|
724 {
|
|
725 if (DOWNCASE (0, charptr_emchar (s1)) !=
|
|
726 DOWNCASE (0, charptr_emchar (s2)))
|
|
727 break;
|
|
728 INC_CHARPTR (s1);
|
|
729 INC_CHARPTR (s2);
|
|
730 }
|
|
731
|
|
732 return (DOWNCASE (0, charptr_emchar (s1)) -
|
|
733 DOWNCASE (0, charptr_emchar (s2)));
|
|
734 }
|
|
735
|
|
736 /* The only difference between these next two and
|
|
737 qxememcasecmp()/qxememcasecmp_i18n() is that these two will stop if
|
|
738 both strings are equal and less than LEN in length, while
|
|
739 the mem...() versions would would run off the end. */
|
|
740
|
|
741 int
|
|
742 qxestrncasecmp (const Intbyte *s1, const Intbyte *s2, Bytecount len)
|
|
743 {
|
|
744 Intbyte *cm = strcasecmp_charmap;
|
|
745
|
|
746 while (len--)
|
|
747 {
|
|
748 int diff = cm[*s1] - cm[*s2];
|
|
749 if (diff != 0)
|
|
750 return diff;
|
|
751 if (!*s1)
|
|
752 return 0;
|
|
753 s1++, s2++;
|
|
754 }
|
|
755
|
|
756 return 0;
|
|
757 }
|
|
758
|
|
759 int
|
|
760 ascii_strncasecmp (const Char_ASCII *s1, const Char_ASCII *s2, Bytecount len)
|
|
761 {
|
|
762 return qxestrncasecmp ((const Intbyte *) s1, (const Intbyte *) s2, len);
|
|
763 }
|
|
764
|
|
765 int
|
|
766 qxestrncasecmp_c (const Intbyte *s1, const Char_ASCII *s2, Bytecount len)
|
|
767 {
|
|
768 return qxestrncasecmp (s1, (const Intbyte *) s2, len);
|
|
769 }
|
|
770
|
801
|
771 /* Compare LEN_FROM_S1 worth of characters from S1 with the same number of
|
|
772 characters from S2, case insensitive. NOTE: Downcasing can convert
|
|
773 characters from one length in bytes to another, so reversing S1 and S2
|
|
774 is *NOT* a symmetric operations! You must choose a length that agrees
|
|
775 with S1. */
|
|
776
|
771
|
777 int
|
801
|
778 qxestrncasecmp_i18n (const Intbyte *s1, const Intbyte *s2,
|
|
779 Bytecount len_from_s1)
|
771
|
780 {
|
801
|
781 while (len_from_s1 > 0)
|
771
|
782 {
|
|
783 const Intbyte *old_s1 = s1;
|
|
784 int diff = (DOWNCASE (0, charptr_emchar (s1)) -
|
|
785 DOWNCASE (0, charptr_emchar (s2)));
|
|
786 if (diff != 0)
|
|
787 return diff;
|
|
788 if (!*s1)
|
|
789 return 0;
|
|
790 INC_CHARPTR (s1);
|
|
791 INC_CHARPTR (s2);
|
801
|
792 len_from_s1 -= s1 - old_s1;
|
771
|
793 }
|
|
794
|
|
795 return 0;
|
|
796 }
|
|
797
|
|
798 int
|
|
799 qxememcmp (const Intbyte *s1, const Intbyte *s2, Bytecount len)
|
|
800 {
|
|
801 return memcmp (s1, s2, len);
|
|
802 }
|
|
803
|
|
804 int
|
801
|
805 qxememcmp4 (const Intbyte *s1, Bytecount len1,
|
|
806 const Intbyte *s2, Bytecount len2)
|
|
807 {
|
|
808 int retval = qxememcmp (s1, s2, min (len1, len2));
|
|
809 if (retval)
|
|
810 return retval;
|
|
811 return len1 - len2;
|
|
812 }
|
|
813
|
|
814 int
|
771
|
815 qxememcasecmp (const Intbyte *s1, const Intbyte *s2, Bytecount len)
|
|
816 {
|
|
817 Intbyte *cm = strcasecmp_charmap;
|
|
818
|
|
819 while (len--)
|
|
820 {
|
|
821 int diff = cm[*s1] - cm[*s2];
|
|
822 if (diff != 0)
|
|
823 return diff;
|
|
824 s1++, s2++;
|
|
825 }
|
|
826
|
|
827 return 0;
|
|
828 }
|
|
829
|
|
830 int
|
801
|
831 qxememcasecmp4 (const Intbyte *s1, Bytecount len1,
|
|
832 const Intbyte *s2, Bytecount len2)
|
771
|
833 {
|
801
|
834 int retval = qxememcasecmp (s1, s2, min (len1, len2));
|
|
835 if (retval)
|
|
836 return retval;
|
|
837 return len1 - len2;
|
|
838 }
|
|
839
|
|
840 /* Do a character-by-character comparison, returning "which is greater" by
|
|
841 comparing the Emchar values. (#### Should have option to compare Unicode
|
|
842 points) */
|
|
843
|
|
844 int
|
|
845 qxetextcmp (const Intbyte *s1, Bytecount len1,
|
|
846 const Intbyte *s2, Bytecount len2)
|
|
847 {
|
|
848 while (len1 > 0 && len2 > 0)
|
771
|
849 {
|
|
850 const Intbyte *old_s1 = s1;
|
801
|
851 const Intbyte *old_s2 = s2;
|
|
852 int diff = charptr_emchar (s1) - charptr_emchar (s2);
|
|
853 if (diff != 0)
|
|
854 return diff;
|
|
855 INC_CHARPTR (s1);
|
|
856 INC_CHARPTR (s2);
|
|
857 len1 -= s1 - old_s1;
|
|
858 len2 -= s2 - old_s2;
|
|
859 }
|
|
860
|
|
861 assert (len1 >= 0 && len2 >= 0);
|
|
862 return len1 - len2;
|
|
863 }
|
|
864
|
|
865 int
|
|
866 qxetextcmp_matching (const Intbyte *s1, Bytecount len1,
|
|
867 const Intbyte *s2, Bytecount len2,
|
|
868 Charcount *matching)
|
|
869 {
|
|
870 *matching = 0;
|
|
871 while (len1 > 0 && len2 > 0)
|
|
872 {
|
|
873 const Intbyte *old_s1 = s1;
|
|
874 const Intbyte *old_s2 = s2;
|
|
875 int diff = charptr_emchar (s1) - charptr_emchar (s2);
|
|
876 if (diff != 0)
|
|
877 return diff;
|
|
878 INC_CHARPTR (s1);
|
|
879 INC_CHARPTR (s2);
|
|
880 len1 -= s1 - old_s1;
|
|
881 len2 -= s2 - old_s2;
|
|
882 (*matching)++;
|
|
883 }
|
|
884
|
|
885 assert (len1 >= 0 && len2 >= 0);
|
|
886 return len1 - len2;
|
|
887 }
|
|
888
|
|
889 /* Do a character-by-character comparison, returning "which is greater" by
|
|
890 comparing the Emchar values, case insensitively (by downcasing both
|
|
891 first). (#### Should have option to compare Unicode points)
|
|
892
|
|
893 In this case, both lengths must be specified becaused downcasing can
|
|
894 convert characters from one length in bytes to another; therefore, two
|
|
895 blocks of text of different length might be equal. If both compare
|
|
896 equal up to the limit in length of one but not the other, the longer one
|
|
897 is "greater". */
|
|
898
|
|
899 int
|
|
900 qxetextcasecmp (const Intbyte *s1, Bytecount len1,
|
|
901 const Intbyte *s2, Bytecount len2)
|
|
902 {
|
|
903 while (len1 > 0 && len2 > 0)
|
|
904 {
|
|
905 const Intbyte *old_s1 = s1;
|
|
906 const Intbyte *old_s2 = s2;
|
771
|
907 int diff = (DOWNCASE (0, charptr_emchar (s1)) -
|
|
908 DOWNCASE (0, charptr_emchar (s2)));
|
|
909 if (diff != 0)
|
|
910 return diff;
|
|
911 INC_CHARPTR (s1);
|
|
912 INC_CHARPTR (s2);
|
801
|
913 len1 -= s1 - old_s1;
|
|
914 len2 -= s2 - old_s2;
|
771
|
915 }
|
|
916
|
801
|
917 assert (len1 >= 0 && len2 >= 0);
|
|
918 return len1 - len2;
|
|
919 }
|
|
920
|
|
921 /* Like qxetextcasecmp() but also return number of characters at
|
|
922 beginning that match. */
|
|
923
|
|
924 int
|
|
925 qxetextcasecmp_matching (const Intbyte *s1, Bytecount len1,
|
|
926 const Intbyte *s2, Bytecount len2,
|
|
927 Charcount *matching)
|
|
928 {
|
|
929 *matching = 0;
|
|
930 while (len1 > 0 && len2 > 0)
|
|
931 {
|
|
932 const Intbyte *old_s1 = s1;
|
|
933 const Intbyte *old_s2 = s2;
|
|
934 int diff = (DOWNCASE (0, charptr_emchar (s1)) -
|
|
935 DOWNCASE (0, charptr_emchar (s2)));
|
|
936 if (diff != 0)
|
|
937 return diff;
|
|
938 INC_CHARPTR (s1);
|
|
939 INC_CHARPTR (s2);
|
|
940 len1 -= s1 - old_s1;
|
|
941 len2 -= s2 - old_s2;
|
|
942 (*matching)++;
|
|
943 }
|
|
944
|
|
945 assert (len1 >= 0 && len2 >= 0);
|
|
946 return len1 - len2;
|
771
|
947 }
|
|
948
|
|
949 int
|
|
950 lisp_strcasecmp (Lisp_Object s1, Lisp_Object s2)
|
|
951 {
|
|
952 Intbyte *cm = strcasecmp_charmap;
|
|
953 Intbyte *p1 = XSTRING_DATA (s1);
|
|
954 Intbyte *p2 = XSTRING_DATA (s2);
|
|
955 Intbyte *e1 = p1 + XSTRING_LENGTH (s1);
|
|
956 Intbyte *e2 = p2 + XSTRING_LENGTH (s2);
|
|
957
|
|
958 /* again, we use a symmetric algorithm and favor clarity over
|
|
959 nanosecond improvements. */
|
|
960 while (1)
|
|
961 {
|
|
962 /* if we reached the end of either string, compare lengths.
|
|
963 do NOT compare the final null byte against anything, in case
|
|
964 the other string also has a null byte at that position. */
|
|
965 if (p1 == e1 || p2 == e2)
|
|
966 return e1 - e2;
|
|
967 if (cm[*p1] != cm[*p2])
|
|
968 return cm[*p1] - cm[*p2];
|
|
969 p1++, p2++;
|
|
970 }
|
|
971 }
|
|
972
|
|
973 int
|
|
974 lisp_strcasecmp_i18n (Lisp_Object s1, Lisp_Object s2)
|
|
975 {
|
801
|
976 return qxetextcasecmp (XSTRING_DATA (s1), XSTRING_LENGTH (s1),
|
|
977 XSTRING_DATA (s2), XSTRING_LENGTH (s2));
|
771
|
978 }
|
|
979
|
|
980
|
|
981 /************************************************************************/
|
|
982 /* conversion between textual representations */
|
|
983 /************************************************************************/
|
|
984
|
|
985 /* NOTE: Does not reset the Dynarr. */
|
|
986
|
|
987 void
|
|
988 convert_intbyte_string_into_emchar_dynarr (const Intbyte *str, Bytecount len,
|
|
989 Emchar_dynarr *dyn)
|
|
990 {
|
|
991 const Intbyte *strend = str + len;
|
|
992
|
|
993 while (str < strend)
|
|
994 {
|
|
995 Emchar ch = charptr_emchar (str);
|
|
996 Dynarr_add (dyn, ch);
|
|
997 INC_CHARPTR (str);
|
|
998 }
|
|
999 }
|
|
1000
|
|
1001 Charcount
|
|
1002 convert_intbyte_string_into_emchar_string (const Intbyte *str, Bytecount len,
|
|
1003 Emchar *arr)
|
|
1004 {
|
|
1005 const Intbyte *strend = str + len;
|
|
1006 Charcount newlen = 0;
|
|
1007 while (str < strend)
|
|
1008 {
|
|
1009 Emchar ch = charptr_emchar (str);
|
|
1010 arr[newlen++] = ch;
|
|
1011 INC_CHARPTR (str);
|
|
1012 }
|
|
1013 return newlen;
|
|
1014 }
|
|
1015
|
|
1016 /* Convert an array of Emchars into the equivalent string representation.
|
|
1017 Store into the given Intbyte dynarr. Does not reset the dynarr.
|
|
1018 Does not add a terminating zero. */
|
|
1019
|
|
1020 void
|
|
1021 convert_emchar_string_into_intbyte_dynarr (Emchar *arr, int nels,
|
|
1022 Intbyte_dynarr *dyn)
|
|
1023 {
|
|
1024 Intbyte str[MAX_EMCHAR_LEN];
|
|
1025 int i;
|
|
1026
|
|
1027 for (i = 0; i < nels; i++)
|
|
1028 {
|
|
1029 Bytecount len = set_charptr_emchar (str, arr[i]);
|
|
1030 Dynarr_add_many (dyn, str, len);
|
|
1031 }
|
|
1032 }
|
|
1033
|
|
1034 /* Convert an array of Emchars into the equivalent string representation.
|
|
1035 Malloc the space needed for this and return it. If LEN_OUT is not a
|
|
1036 NULL pointer, store into LEN_OUT the number of Intbytes in the
|
|
1037 malloc()ed string. Note that the actual number of Intbytes allocated
|
|
1038 is one more than this: the returned string is zero-terminated. */
|
|
1039
|
|
1040 Intbyte *
|
|
1041 convert_emchar_string_into_malloced_string (Emchar *arr, int nels,
|
826
|
1042 Bytecount *len_out)
|
771
|
1043 {
|
|
1044 /* Damn zero-termination. */
|
851
|
1045 Intbyte *str = (Intbyte *) ALLOCA (nels * MAX_EMCHAR_LEN + 1);
|
771
|
1046 Intbyte *strorig = str;
|
|
1047 Bytecount len;
|
|
1048
|
|
1049 int i;
|
|
1050
|
|
1051 for (i = 0; i < nels; i++)
|
|
1052 str += set_charptr_emchar (str, arr[i]);
|
|
1053 *str = '\0';
|
|
1054 len = str - strorig;
|
|
1055 str = (Intbyte *) xmalloc (1 + len);
|
|
1056 memcpy (str, strorig, 1 + len);
|
|
1057 if (len_out)
|
|
1058 *len_out = len;
|
|
1059 return str;
|
|
1060 }
|
|
1061
|
826
|
1062 #define COPY_TEXT_BETWEEN_FORMATS(srcfmt, dstfmt) \
|
|
1063 do \
|
|
1064 { \
|
|
1065 if (dst) \
|
|
1066 { \
|
|
1067 Intbyte *dstend = dst + dstlen; \
|
|
1068 Intbyte *dstp = dst; \
|
|
1069 const Intbyte *srcend = src + srclen; \
|
|
1070 const Intbyte *srcp = src; \
|
|
1071 \
|
|
1072 while (srcp < srcend) \
|
|
1073 { \
|
|
1074 Emchar ch = charptr_emchar_fmt (srcp, srcfmt, srcobj); \
|
|
1075 Bytecount len = emchar_len_fmt (ch, dstfmt); \
|
|
1076 \
|
|
1077 if (dstp + len <= dstend) \
|
|
1078 { \
|
|
1079 set_charptr_emchar_fmt (dstp, ch, dstfmt, dstobj); \
|
|
1080 dstp += len; \
|
|
1081 } \
|
|
1082 else \
|
|
1083 break; \
|
|
1084 INC_CHARPTR_FMT (srcp, srcfmt); \
|
|
1085 } \
|
|
1086 text_checking_assert (srcp <= srcend); \
|
|
1087 if (src_used) \
|
|
1088 *src_used = srcp - src; \
|
|
1089 return dstp - dst; \
|
|
1090 } \
|
|
1091 else \
|
|
1092 { \
|
|
1093 const Intbyte *srcend = src + srclen; \
|
|
1094 const Intbyte *srcp = src; \
|
|
1095 Bytecount total = 0; \
|
|
1096 \
|
|
1097 while (srcp < srcend) \
|
|
1098 { \
|
|
1099 total += emchar_len_fmt (charptr_emchar_fmt (srcp, srcfmt, \
|
|
1100 srcobj), dstfmt); \
|
|
1101 INC_CHARPTR_FMT (srcp, srcfmt); \
|
|
1102 } \
|
|
1103 text_checking_assert (srcp == srcend); \
|
|
1104 if (src_used) \
|
|
1105 *src_used = srcp - src; \
|
|
1106 return total; \
|
|
1107 } \
|
|
1108 } \
|
|
1109 while (0)
|
|
1110
|
|
1111 /* Copy as much text from SRC/SRCLEN to DST/DSTLEN as will fit, converting
|
|
1112 from SRCFMT/SRCOBJ to DSTFMT/DSTOBJ. Return number of bytes stored into
|
|
1113 DST as return value, and number of bytes copied from SRC through
|
|
1114 SRC_USED (if not NULL). If DST is NULL, don't actually store anything
|
|
1115 and just return the size needed to store all the text. Will not copy
|
|
1116 partial characters into DST. */
|
|
1117
|
|
1118 Bytecount
|
|
1119 copy_text_between_formats (const Intbyte *src, Bytecount srclen,
|
|
1120 Internal_Format srcfmt,
|
|
1121 Lisp_Object srcobj,
|
|
1122 Intbyte *dst, Bytecount dstlen,
|
|
1123 Internal_Format dstfmt,
|
|
1124 Lisp_Object dstobj,
|
|
1125 Bytecount *src_used)
|
|
1126 {
|
|
1127 if (srcfmt == dstfmt &&
|
|
1128 objects_have_same_internal_representation (srcobj, dstobj))
|
|
1129 {
|
|
1130 if (dst)
|
|
1131 {
|
|
1132 srclen = min (srclen, dstlen);
|
|
1133 srclen = validate_intbyte_string_backward (src, srclen);
|
|
1134 memcpy (dst, src, srclen);
|
|
1135 if (src_used)
|
|
1136 *src_used = srclen;
|
|
1137 return srclen;
|
|
1138 }
|
|
1139 else
|
|
1140 return srclen;
|
|
1141 }
|
|
1142 /* Everything before the final else statement is an optimization.
|
|
1143 The inner loops inside COPY_TEXT_BETWEEN_FORMATS() have a number
|
|
1144 of calls to *_fmt(), each of which has a switch statement in it.
|
|
1145 By using constants as the FMT argument, these switch statements
|
|
1146 will be optimized out of existence. */
|
|
1147 #define ELSE_FORMATS(fmt1, fmt2) \
|
|
1148 else if (srcfmt == fmt1 && dstfmt == fmt2) \
|
|
1149 COPY_TEXT_BETWEEN_FORMATS (fmt1, fmt2)
|
|
1150 ELSE_FORMATS (FORMAT_DEFAULT, FORMAT_8_BIT_FIXED);
|
|
1151 ELSE_FORMATS (FORMAT_8_BIT_FIXED, FORMAT_DEFAULT);
|
|
1152 ELSE_FORMATS (FORMAT_DEFAULT, FORMAT_32_BIT_FIXED);
|
|
1153 ELSE_FORMATS (FORMAT_32_BIT_FIXED, FORMAT_DEFAULT);
|
|
1154 else
|
|
1155 COPY_TEXT_BETWEEN_FORMATS (srcfmt, dstfmt);
|
|
1156 #undef ELSE_FORMATS
|
|
1157 }
|
|
1158
|
|
1159 /* Copy as much buffer text in BUF, starting at POS, of length LEN, as will
|
|
1160 fit into DST/DSTLEN, converting to DSTFMT. Return number of bytes
|
|
1161 stored into DST as return value, and number of bytes copied from BUF
|
|
1162 through SRC_USED (if not NULL). If DST is NULL, don't actually store
|
|
1163 anything and just return the size needed to store all the text. */
|
|
1164
|
|
1165 Bytecount
|
|
1166 copy_buffer_text_out (struct buffer *buf, Bytebpos pos,
|
|
1167 Bytecount len, Intbyte *dst, Bytecount dstlen,
|
|
1168 Internal_Format dstfmt, Lisp_Object dstobj,
|
|
1169 Bytecount *src_used)
|
|
1170 {
|
|
1171 Bytecount dst_used = 0;
|
|
1172 if (src_used)
|
|
1173 *src_used = 0;
|
|
1174
|
|
1175 {
|
|
1176 BUFFER_TEXT_LOOP (buf, pos, len, runptr, runlen)
|
|
1177 {
|
|
1178 Bytecount the_src_used, the_dst_used;
|
|
1179
|
|
1180 the_dst_used = copy_text_between_formats (runptr, runlen,
|
|
1181 BUF_FORMAT (buf),
|
|
1182 wrap_buffer (buf),
|
|
1183 dst, dstlen, dstfmt,
|
|
1184 dstobj, &the_src_used);
|
|
1185 dst_used += the_dst_used;
|
|
1186 if (src_used)
|
|
1187 *src_used += the_src_used;
|
|
1188 if (dst)
|
|
1189 {
|
|
1190 dst += the_dst_used;
|
|
1191 dstlen -= the_dst_used;
|
841
|
1192 /* Stop if we didn't use all of the source text. Also stop
|
|
1193 if the destination is full. We need the first test because
|
|
1194 there might be a couple bytes left in the destination, but
|
|
1195 not enough to fit a full character. The first test will in
|
|
1196 fact catch the vast majority of cases where the destination
|
|
1197 is empty, too -- but in case the destination holds *exactly*
|
|
1198 the run length, we put in the second check. (It shouldn't
|
|
1199 really matter though -- next time through we'll just get a
|
|
1200 0.) */
|
|
1201 if (the_src_used < runlen || !dstlen)
|
826
|
1202 break;
|
|
1203 }
|
|
1204 }
|
|
1205 }
|
|
1206
|
|
1207 return dst_used;
|
|
1208 }
|
|
1209
|
771
|
1210
|
|
1211 /************************************************************************/
|
|
1212 /* charset properties of strings */
|
|
1213 /************************************************************************/
|
|
1214
|
|
1215 void
|
|
1216 find_charsets_in_intbyte_string (unsigned char *charsets, const Intbyte *str,
|
|
1217 Bytecount len)
|
|
1218 {
|
|
1219 #ifndef MULE
|
|
1220 /* Telescope this. */
|
|
1221 charsets[0] = 1;
|
|
1222 #else
|
|
1223 const Intbyte *strend = str + len;
|
|
1224 memset (charsets, 0, NUM_LEADING_BYTES);
|
|
1225
|
|
1226 /* #### SJT doesn't like this. */
|
|
1227 if (len == 0)
|
|
1228 {
|
|
1229 charsets[XCHARSET_LEADING_BYTE (Vcharset_ascii) - MIN_LEADING_BYTE] = 1;
|
|
1230 return;
|
|
1231 }
|
|
1232
|
|
1233 while (str < strend)
|
|
1234 {
|
826
|
1235 charsets[emchar_leading_byte (charptr_emchar (str)) - MIN_LEADING_BYTE] =
|
771
|
1236 1;
|
|
1237 INC_CHARPTR (str);
|
|
1238 }
|
|
1239 #endif
|
|
1240 }
|
|
1241
|
|
1242 void
|
|
1243 find_charsets_in_emchar_string (unsigned char *charsets, const Emchar *str,
|
|
1244 Charcount len)
|
|
1245 {
|
|
1246 #ifndef MULE
|
|
1247 /* Telescope this. */
|
|
1248 charsets[0] = 1;
|
|
1249 #else
|
|
1250 int i;
|
|
1251
|
|
1252 memset (charsets, 0, NUM_LEADING_BYTES);
|
|
1253
|
|
1254 /* #### SJT doesn't like this. */
|
|
1255 if (len == 0)
|
|
1256 {
|
|
1257 charsets[XCHARSET_LEADING_BYTE (Vcharset_ascii) - MIN_LEADING_BYTE] = 1;
|
|
1258 return;
|
|
1259 }
|
|
1260
|
|
1261 for (i = 0; i < len; i++)
|
|
1262 {
|
826
|
1263 charsets[emchar_leading_byte (str[i]) - MIN_LEADING_BYTE] = 1;
|
771
|
1264 }
|
|
1265 #endif
|
|
1266 }
|
|
1267
|
|
1268 int
|
|
1269 intbyte_string_displayed_columns (const Intbyte *str, Bytecount len)
|
|
1270 {
|
|
1271 int cols = 0;
|
|
1272 const Intbyte *end = str + len;
|
|
1273
|
|
1274 while (str < end)
|
|
1275 {
|
|
1276 #ifdef MULE
|
|
1277 Emchar ch = charptr_emchar (str);
|
826
|
1278 cols += XCHARSET_COLUMNS (emchar_charset (ch));
|
771
|
1279 #else
|
|
1280 cols++;
|
|
1281 #endif
|
|
1282 INC_CHARPTR (str);
|
|
1283 }
|
|
1284
|
|
1285 return cols;
|
|
1286 }
|
|
1287
|
|
1288 int
|
|
1289 emchar_string_displayed_columns (const Emchar *str, Charcount len)
|
|
1290 {
|
|
1291 #ifdef MULE
|
|
1292 int cols = 0;
|
|
1293 int i;
|
|
1294
|
|
1295 for (i = 0; i < len; i++)
|
826
|
1296 cols += XCHARSET_COLUMNS (emchar_charset (str[i]));
|
771
|
1297
|
|
1298 return cols;
|
|
1299 #else /* not MULE */
|
|
1300 return len;
|
|
1301 #endif
|
|
1302 }
|
|
1303
|
|
1304 Charcount
|
|
1305 intbyte_string_nonascii_chars (const Intbyte *str, Bytecount len)
|
|
1306 {
|
|
1307 #ifdef MULE
|
|
1308 const Intbyte *end = str + len;
|
|
1309 Charcount retval = 0;
|
|
1310
|
|
1311 while (str < end)
|
|
1312 {
|
826
|
1313 if (!byte_ascii_p (*str))
|
771
|
1314 retval++;
|
|
1315 INC_CHARPTR (str);
|
|
1316 }
|
|
1317
|
|
1318 return retval;
|
|
1319 #else
|
|
1320 return 0;
|
|
1321 #endif
|
|
1322 }
|
|
1323
|
|
1324
|
|
1325 /***************************************************************************/
|
|
1326 /* Eistring helper functions */
|
|
1327 /***************************************************************************/
|
|
1328
|
|
1329 int
|
|
1330 eistr_casefiddle_1 (Intbyte *olddata, Bytecount len, Intbyte *newdata,
|
|
1331 int downp)
|
|
1332 {
|
|
1333 Intbyte *endp = olddata + len;
|
|
1334 Intbyte *newp = newdata;
|
|
1335 int changedp = 0;
|
|
1336
|
|
1337 while (olddata < endp)
|
|
1338 {
|
|
1339 Emchar c = charptr_emchar (olddata);
|
|
1340 Emchar newc;
|
|
1341
|
|
1342 if (downp)
|
|
1343 newc = DOWNCASE (0, c);
|
|
1344 else
|
|
1345 newc = UPCASE (0, c);
|
|
1346
|
|
1347 if (c != newc)
|
|
1348 changedp = 1;
|
|
1349
|
|
1350 newp += set_charptr_emchar (newp, newc);
|
|
1351 INC_CHARPTR (olddata);
|
|
1352 }
|
|
1353
|
|
1354 *newp = '\0';
|
|
1355
|
|
1356 return changedp ? newp - newdata : 0;
|
|
1357 }
|
|
1358
|
|
1359 int
|
|
1360 eifind_large_enough_buffer (int oldbufsize, int needed_size)
|
|
1361 {
|
|
1362 while (oldbufsize < needed_size)
|
|
1363 {
|
|
1364 oldbufsize = oldbufsize * 3 / 2;
|
|
1365 oldbufsize = max (oldbufsize, 32);
|
|
1366 }
|
|
1367
|
|
1368 return oldbufsize;
|
|
1369 }
|
|
1370
|
|
1371 void
|
|
1372 eito_malloc_1 (Eistring *ei)
|
|
1373 {
|
|
1374 if (ei->mallocp_)
|
|
1375 return;
|
|
1376 ei->mallocp_ = 1;
|
|
1377 if (ei->data_)
|
|
1378 {
|
|
1379 Intbyte *newdata;
|
|
1380
|
|
1381 ei->max_size_allocated_ =
|
|
1382 eifind_large_enough_buffer (0, ei->bytelen_ + 1);
|
|
1383 newdata = (Intbyte *) xmalloc (ei->max_size_allocated_);
|
|
1384 memcpy (newdata, ei->data_, ei->bytelen_ + 1);
|
|
1385 ei->data_ = newdata;
|
|
1386 }
|
|
1387
|
|
1388 if (ei->extdata_)
|
|
1389 {
|
|
1390 Extbyte *newdata = (Extbyte *) xmalloc (ei->extlen_ + 2);
|
|
1391
|
|
1392 memcpy (newdata, ei->extdata_, ei->extlen_);
|
|
1393 /* Double null-terminate in case of Unicode data */
|
|
1394 newdata[ei->extlen_] = '\0';
|
|
1395 newdata[ei->extlen_ + 1] = '\0';
|
|
1396 ei->extdata_ = newdata;
|
|
1397 }
|
|
1398 }
|
|
1399
|
|
1400 int
|
|
1401 eicmp_1 (Eistring *ei, Bytecount off, Charcount charoff,
|
|
1402 Bytecount len, Charcount charlen, const Intbyte *data,
|
|
1403 const Eistring *ei2, int is_c, int fold_case)
|
|
1404 {
|
|
1405 assert ((off < 0) != (charoff < 0));
|
|
1406 if (off < 0)
|
|
1407 {
|
|
1408 off = charcount_to_bytecount (ei->data_, charoff);
|
|
1409 if (charlen < 0)
|
|
1410 len = -1;
|
|
1411 else
|
|
1412 len = charcount_to_bytecount (ei->data_ + off, charlen);
|
|
1413 }
|
|
1414 if (len < 0)
|
|
1415 len = ei->bytelen_ - off;
|
|
1416
|
|
1417 assert (off >= 0 && off <= ei->bytelen_);
|
|
1418 assert (len >= 0 && off + len <= ei->bytelen_);
|
|
1419 assert ((data == 0) != (ei == 0));
|
|
1420 assert ((is_c != 0) == (data != 0));
|
|
1421 assert (fold_case >= 0 && fold_case <= 2);
|
|
1422
|
|
1423 {
|
|
1424 Bytecount dstlen;
|
|
1425 const Intbyte *src = ei->data_, *dst;
|
|
1426
|
|
1427 if (data)
|
|
1428 {
|
|
1429 dst = data;
|
|
1430 dstlen = qxestrlen (data);
|
|
1431 }
|
|
1432 else
|
|
1433 {
|
|
1434 dst = ei2->data_;
|
|
1435 dstlen = ei2->bytelen_;
|
|
1436 }
|
|
1437
|
|
1438 if (is_c)
|
|
1439 EI_ASSERT_ASCII ((Char_ASCII *) dst, dstlen);
|
|
1440
|
801
|
1441 return (fold_case == 0 ? qxememcmp4 (src, len, dst, dstlen) :
|
|
1442 fold_case == 1 ? qxememcasecmp4 (src, len, dst, dstlen) :
|
|
1443 qxetextcasecmp (src, len, dst, dstlen));
|
771
|
1444 }
|
|
1445 }
|
|
1446
|
|
1447 Intbyte *
|
826
|
1448 eicpyout_malloc_fmt (Eistring *eistr, Bytecount *len_out, Internal_Format fmt,
|
|
1449 Lisp_Object object)
|
771
|
1450 {
|
|
1451 Intbyte *ptr;
|
|
1452
|
|
1453 assert (fmt == FORMAT_DEFAULT);
|
|
1454 ptr = xnew_array (Intbyte, eistr->bytelen_ + 1);
|
|
1455 if (len_out)
|
|
1456 *len_out = eistr->bytelen_;
|
|
1457 memcpy (ptr, eistr->data_, eistr->bytelen_ + 1);
|
|
1458 return ptr;
|
|
1459 }
|
|
1460
|
|
1461
|
|
1462 /************************************************************************/
|
|
1463 /* Charcount/Bytecount conversion */
|
|
1464 /************************************************************************/
|
|
1465
|
|
1466 /* Optimization. Do it. Live it. Love it. */
|
|
1467
|
|
1468 #ifdef MULE
|
|
1469
|
826
|
1470 /* Skip as many ASCII bytes as possible in the memory block [PTR, END).
|
|
1471 Return pointer to the first non-ASCII byte. optimized for long
|
|
1472 stretches of ASCII. */
|
|
1473 inline static const Intbyte *
|
|
1474 skip_ascii (const Intbyte *ptr, const Intbyte *end)
|
771
|
1475 {
|
826
|
1476 #ifdef EFFICIENT_INT_128_BIT
|
|
1477 # define STRIDE_TYPE INT_128_BIT
|
|
1478 # define HIGH_BIT_MASK \
|
|
1479 MAKE_128_BIT_UNSIGNED_CONSTANT (0x80808080808080808080808080808080)
|
|
1480 #elif defined (EFFICIENT_INT_64_BIT)
|
|
1481 # define STRIDE_TYPE INT_64_BIT
|
|
1482 # define HIGH_BIT_MASK MAKE_64_BIT_UNSIGNED_CONSTANT (0x8080808080808080)
|
771
|
1483 #else
|
826
|
1484 # define STRIDE_TYPE INT_32_BIT
|
|
1485 # define HIGH_BIT_MASK MAKE_32_BIT_UNSIGNED_CONSTANT (0x80808080)
|
771
|
1486 #endif
|
|
1487
|
|
1488 #define ALIGN_BITS ((EMACS_UINT) (ALIGNOF (STRIDE_TYPE) - 1))
|
|
1489 #define ALIGN_MASK (~ ALIGN_BITS)
|
|
1490 #define ALIGNED(ptr) ((((EMACS_UINT) ptr) & ALIGN_BITS) == 0)
|
|
1491 #define STRIDE sizeof (STRIDE_TYPE)
|
|
1492
|
826
|
1493 const unsigned STRIDE_TYPE *ascii_end;
|
|
1494
|
|
1495 /* Need to do in 3 sections -- before alignment start, aligned chunk,
|
|
1496 after alignment end. */
|
|
1497 while (!ALIGNED (ptr))
|
771
|
1498 {
|
826
|
1499 if (ptr == end || !byte_ascii_p (*ptr))
|
|
1500 return ptr;
|
|
1501 ptr++;
|
|
1502 }
|
|
1503 ascii_end = (const unsigned STRIDE_TYPE *) ptr;
|
|
1504 /* This loop screams, because we can detect ASCII
|
|
1505 characters 4 or 8 at a time. */
|
|
1506 while ((const Intbyte *) ascii_end + STRIDE <= end
|
|
1507 && !(*ascii_end & HIGH_BIT_MASK))
|
|
1508 ascii_end++;
|
|
1509 ptr = (Intbyte *) ascii_end;
|
|
1510 while (ptr < end && byte_ascii_p (*ptr))
|
|
1511 ptr++;
|
|
1512 return ptr;
|
|
1513 }
|
|
1514
|
|
1515 /* Function equivalents of bytecount_to_charcount/charcount_to_bytecount.
|
|
1516 These work on strings of all sizes but are more efficient than a simple
|
|
1517 loop on large strings and probably less efficient on sufficiently small
|
|
1518 strings. */
|
|
1519
|
|
1520 Charcount
|
|
1521 bytecount_to_charcount_fun (const Intbyte *ptr, Bytecount len)
|
|
1522 {
|
|
1523 Charcount count = 0;
|
|
1524 const Intbyte *end = ptr + len;
|
|
1525 while (1)
|
|
1526 {
|
|
1527 const Intbyte *newptr = skip_ascii (ptr, end);
|
|
1528 count += newptr - ptr;
|
|
1529 ptr = newptr;
|
|
1530 if (ptr == end)
|
|
1531 break;
|
|
1532 {
|
|
1533 /* Optimize for successive characters from the same charset */
|
|
1534 Intbyte leading_byte = *ptr;
|
|
1535 int bytes = rep_bytes_by_first_byte (leading_byte);
|
|
1536 while (ptr < end && *ptr == leading_byte)
|
|
1537 ptr += bytes, count++;
|
|
1538 }
|
771
|
1539 }
|
|
1540
|
|
1541 /* Bomb out if the specified substring ends in the middle
|
|
1542 of a character. Note that we might have already gotten
|
|
1543 a core dump above from an invalid reference, but at least
|
|
1544 we will get no farther than here.
|
|
1545
|
|
1546 This also catches len < 0. */
|
800
|
1547 text_checking_assert (ptr == end);
|
771
|
1548
|
|
1549 return count;
|
|
1550 }
|
|
1551
|
|
1552 Bytecount
|
826
|
1553 charcount_to_bytecount_fun (const Intbyte *ptr, Charcount len)
|
771
|
1554 {
|
|
1555 const Intbyte *newptr = ptr;
|
826
|
1556 while (1)
|
771
|
1557 {
|
826
|
1558 const Intbyte *newnewptr = skip_ascii (newptr, newptr + len);
|
|
1559 len -= newnewptr - newptr;
|
|
1560 newptr = newnewptr;
|
|
1561 if (!len)
|
|
1562 break;
|
|
1563 {
|
|
1564 /* Optimize for successive characters from the same charset */
|
|
1565 Intbyte leading_byte = *newptr;
|
|
1566 int bytes = rep_bytes_by_first_byte (leading_byte);
|
|
1567 while (len > 0 && *newptr == leading_byte)
|
|
1568 newptr += bytes, len--;
|
|
1569 }
|
771
|
1570 }
|
|
1571 return newptr - ptr;
|
|
1572 }
|
|
1573
|
|
1574 /* The next two functions are the actual meat behind the
|
|
1575 charbpos-to-bytebpos and bytebpos-to-charbpos conversions. Currently
|
|
1576 the method they use is fairly unsophisticated; see buffer.h.
|
|
1577
|
|
1578 Note that charbpos_to_bytebpos_func() is probably the most-called
|
|
1579 function in all of XEmacs. Therefore, it must be FAST FAST FAST.
|
|
1580 This is the reason why so much of the code is duplicated.
|
|
1581
|
|
1582 Similar considerations apply to bytebpos_to_charbpos_func(), although
|
|
1583 less so because the function is not called so often.
|
|
1584
|
|
1585 #### At some point this should use a more sophisticated method;
|
|
1586 see buffer.h. */
|
|
1587
|
|
1588 static int not_very_random_number;
|
|
1589
|
|
1590 Bytebpos
|
|
1591 charbpos_to_bytebpos_func (struct buffer *buf, Charbpos x)
|
|
1592 {
|
|
1593 Charbpos bufmin;
|
|
1594 Charbpos bufmax;
|
|
1595 Bytebpos bytmin;
|
|
1596 Bytebpos bytmax;
|
|
1597 int size;
|
|
1598 int forward_p;
|
|
1599 Bytebpos retval;
|
|
1600 int diff_so_far;
|
|
1601 int add_to_cache = 0;
|
|
1602
|
|
1603 /* Check for some cached positions, for speed. */
|
|
1604 if (x == BUF_PT (buf))
|
826
|
1605 return BYTE_BUF_PT (buf);
|
771
|
1606 if (x == BUF_ZV (buf))
|
826
|
1607 return BYTE_BUF_ZV (buf);
|
771
|
1608 if (x == BUF_BEGV (buf))
|
826
|
1609 return BYTE_BUF_BEGV (buf);
|
771
|
1610
|
|
1611 bufmin = buf->text->mule_bufmin;
|
|
1612 bufmax = buf->text->mule_bufmax;
|
|
1613 bytmin = buf->text->mule_bytmin;
|
|
1614 bytmax = buf->text->mule_bytmax;
|
|
1615 size = (1 << buf->text->mule_shifter) + !!buf->text->mule_three_p;
|
|
1616
|
|
1617 /* The basic idea here is that we shift the "known region" up or down
|
|
1618 until it overlaps the specified position. We do this by moving
|
|
1619 the upper bound of the known region up one character at a time,
|
|
1620 and moving the lower bound of the known region up as necessary
|
|
1621 when the size of the character just seen changes.
|
|
1622
|
|
1623 We optimize this, however, by first shifting the known region to
|
|
1624 one of the cached points if it's close by. (We don't check BEG or
|
|
1625 Z, even though they're cached; most of the time these will be the
|
|
1626 same as BEGV and ZV, and when they're not, they're not likely
|
|
1627 to be used.) */
|
|
1628
|
|
1629 if (x > bufmax)
|
|
1630 {
|
|
1631 Charbpos diffmax = x - bufmax;
|
|
1632 Charbpos diffpt = x - BUF_PT (buf);
|
|
1633 Charbpos diffzv = BUF_ZV (buf) - x;
|
|
1634 /* #### This value could stand some more exploration. */
|
|
1635 Charcount heuristic_hack = (bufmax - bufmin) >> 2;
|
|
1636
|
|
1637 /* Check if the position is closer to PT or ZV than to the
|
|
1638 end of the known region. */
|
|
1639
|
|
1640 if (diffpt < 0)
|
|
1641 diffpt = -diffpt;
|
|
1642 if (diffzv < 0)
|
|
1643 diffzv = -diffzv;
|
|
1644
|
|
1645 /* But also implement a heuristic that favors the known region
|
|
1646 over PT or ZV. The reason for this is that switching to
|
|
1647 PT or ZV will wipe out the knowledge in the known region,
|
|
1648 which might be annoying if the known region is large and
|
|
1649 PT or ZV is not that much closer than the end of the known
|
|
1650 region. */
|
|
1651
|
|
1652 diffzv += heuristic_hack;
|
|
1653 diffpt += heuristic_hack;
|
|
1654 if (diffpt < diffmax && diffpt <= diffzv)
|
|
1655 {
|
|
1656 bufmax = bufmin = BUF_PT (buf);
|
826
|
1657 bytmax = bytmin = BYTE_BUF_PT (buf);
|
771
|
1658 /* We set the size to 1 even though it doesn't really
|
|
1659 matter because the new known region contains no
|
|
1660 characters. We do this because this is the most
|
|
1661 likely size of the characters around the new known
|
|
1662 region, and we avoid potential yuckiness that is
|
|
1663 done when size == 3. */
|
|
1664 size = 1;
|
|
1665 }
|
|
1666 if (diffzv < diffmax)
|
|
1667 {
|
|
1668 bufmax = bufmin = BUF_ZV (buf);
|
826
|
1669 bytmax = bytmin = BYTE_BUF_ZV (buf);
|
771
|
1670 size = 1;
|
|
1671 }
|
|
1672 }
|
800
|
1673 #ifdef ERROR_CHECK_TEXT
|
771
|
1674 else if (x >= bufmin)
|
|
1675 abort ();
|
|
1676 #endif
|
|
1677 else
|
|
1678 {
|
|
1679 Charbpos diffmin = bufmin - x;
|
|
1680 Charbpos diffpt = BUF_PT (buf) - x;
|
|
1681 Charbpos diffbegv = x - BUF_BEGV (buf);
|
|
1682 /* #### This value could stand some more exploration. */
|
|
1683 Charcount heuristic_hack = (bufmax - bufmin) >> 2;
|
|
1684
|
|
1685 if (diffpt < 0)
|
|
1686 diffpt = -diffpt;
|
|
1687 if (diffbegv < 0)
|
|
1688 diffbegv = -diffbegv;
|
|
1689
|
|
1690 /* But also implement a heuristic that favors the known region --
|
|
1691 see above. */
|
|
1692
|
|
1693 diffbegv += heuristic_hack;
|
|
1694 diffpt += heuristic_hack;
|
|
1695
|
|
1696 if (diffpt < diffmin && diffpt <= diffbegv)
|
|
1697 {
|
|
1698 bufmax = bufmin = BUF_PT (buf);
|
826
|
1699 bytmax = bytmin = BYTE_BUF_PT (buf);
|
771
|
1700 /* We set the size to 1 even though it doesn't really
|
|
1701 matter because the new known region contains no
|
|
1702 characters. We do this because this is the most
|
|
1703 likely size of the characters around the new known
|
|
1704 region, and we avoid potential yuckiness that is
|
|
1705 done when size == 3. */
|
|
1706 size = 1;
|
|
1707 }
|
|
1708 if (diffbegv < diffmin)
|
|
1709 {
|
|
1710 bufmax = bufmin = BUF_BEGV (buf);
|
826
|
1711 bytmax = bytmin = BYTE_BUF_BEGV (buf);
|
771
|
1712 size = 1;
|
|
1713 }
|
|
1714 }
|
|
1715
|
|
1716 diff_so_far = x > bufmax ? x - bufmax : bufmin - x;
|
|
1717 if (diff_so_far > 50)
|
|
1718 {
|
|
1719 /* If we have to move more than a certain amount, then look
|
|
1720 into our cache. */
|
|
1721 int minval = INT_MAX;
|
|
1722 int found = 0;
|
|
1723 int i;
|
|
1724
|
|
1725 add_to_cache = 1;
|
|
1726 /* I considered keeping the positions ordered. This would speed
|
|
1727 up this loop, but updating the cache would take longer, so
|
|
1728 it doesn't seem like it would really matter. */
|
|
1729 for (i = 0; i < 16; i++)
|
|
1730 {
|
|
1731 int diff = buf->text->mule_charbpos_cache[i] - x;
|
|
1732
|
|
1733 if (diff < 0)
|
|
1734 diff = -diff;
|
|
1735 if (diff < minval)
|
|
1736 {
|
|
1737 minval = diff;
|
|
1738 found = i;
|
|
1739 }
|
|
1740 }
|
|
1741
|
|
1742 if (minval < diff_so_far)
|
|
1743 {
|
|
1744 bufmax = bufmin = buf->text->mule_charbpos_cache[found];
|
|
1745 bytmax = bytmin = buf->text->mule_bytebpos_cache[found];
|
|
1746 size = 1;
|
|
1747 }
|
|
1748 }
|
|
1749
|
|
1750 /* It's conceivable that the caching above could lead to X being
|
|
1751 the same as one of the range edges. */
|
|
1752 if (x >= bufmax)
|
|
1753 {
|
|
1754 Bytebpos newmax;
|
|
1755 Bytecount newsize;
|
|
1756
|
|
1757 forward_p = 1;
|
|
1758 while (x > bufmax)
|
|
1759 {
|
|
1760 newmax = bytmax;
|
|
1761
|
|
1762 INC_BYTEBPOS (buf, newmax);
|
|
1763 newsize = newmax - bytmax;
|
|
1764 if (newsize != size)
|
|
1765 {
|
|
1766 bufmin = bufmax;
|
|
1767 bytmin = bytmax;
|
|
1768 size = newsize;
|
|
1769 }
|
|
1770 bytmax = newmax;
|
|
1771 bufmax++;
|
|
1772 }
|
|
1773 retval = bytmax;
|
|
1774
|
|
1775 /* #### Should go past the found location to reduce the number
|
|
1776 of times that this function is called */
|
|
1777 }
|
|
1778 else /* x < bufmin */
|
|
1779 {
|
|
1780 Bytebpos newmin;
|
|
1781 Bytecount newsize;
|
|
1782
|
|
1783 forward_p = 0;
|
|
1784 while (x < bufmin)
|
|
1785 {
|
|
1786 newmin = bytmin;
|
|
1787
|
|
1788 DEC_BYTEBPOS (buf, newmin);
|
|
1789 newsize = bytmin - newmin;
|
|
1790 if (newsize != size)
|
|
1791 {
|
|
1792 bufmax = bufmin;
|
|
1793 bytmax = bytmin;
|
|
1794 size = newsize;
|
|
1795 }
|
|
1796 bytmin = newmin;
|
|
1797 bufmin--;
|
|
1798 }
|
|
1799 retval = bytmin;
|
|
1800
|
|
1801 /* #### Should go past the found location to reduce the number
|
|
1802 of times that this function is called
|
|
1803 */
|
|
1804 }
|
|
1805
|
|
1806 /* If size is three, than we have to max sure that the range we
|
|
1807 discovered isn't too large, because we use a fixed-length
|
|
1808 table to divide by 3. */
|
|
1809
|
|
1810 if (size == 3)
|
|
1811 {
|
|
1812 int gap = bytmax - bytmin;
|
|
1813 buf->text->mule_three_p = 1;
|
|
1814 buf->text->mule_shifter = 1;
|
|
1815
|
|
1816 if (gap > MAX_BYTEBPOS_GAP_SIZE_3)
|
|
1817 {
|
|
1818 if (forward_p)
|
|
1819 {
|
|
1820 bytmin = bytmax - MAX_BYTEBPOS_GAP_SIZE_3;
|
|
1821 bufmin = bufmax - MAX_CHARBPOS_GAP_SIZE_3;
|
|
1822 }
|
|
1823 else
|
|
1824 {
|
|
1825 bytmax = bytmin + MAX_BYTEBPOS_GAP_SIZE_3;
|
|
1826 bufmax = bufmin + MAX_CHARBPOS_GAP_SIZE_3;
|
|
1827 }
|
|
1828 }
|
|
1829 }
|
|
1830 else
|
|
1831 {
|
|
1832 buf->text->mule_three_p = 0;
|
|
1833 if (size == 4)
|
|
1834 buf->text->mule_shifter = 2;
|
|
1835 else
|
|
1836 buf->text->mule_shifter = size - 1;
|
|
1837 }
|
|
1838
|
|
1839 buf->text->mule_bufmin = bufmin;
|
|
1840 buf->text->mule_bufmax = bufmax;
|
|
1841 buf->text->mule_bytmin = bytmin;
|
|
1842 buf->text->mule_bytmax = bytmax;
|
|
1843
|
|
1844 if (add_to_cache)
|
|
1845 {
|
|
1846 int replace_loc;
|
|
1847
|
|
1848 /* We throw away a "random" cached value and replace it with
|
|
1849 the new value. It doesn't actually have to be very random
|
|
1850 at all, just evenly distributed.
|
|
1851
|
|
1852 #### It would be better to use a least-recently-used algorithm
|
|
1853 or something that tries to space things out, but I'm not sure
|
|
1854 it's worth it to go to the trouble of maintaining that. */
|
|
1855 not_very_random_number += 621;
|
|
1856 replace_loc = not_very_random_number & 15;
|
|
1857 buf->text->mule_charbpos_cache[replace_loc] = x;
|
|
1858 buf->text->mule_bytebpos_cache[replace_loc] = retval;
|
|
1859 }
|
|
1860
|
|
1861 return retval;
|
|
1862 }
|
|
1863
|
|
1864 /* The logic in this function is almost identical to the logic in
|
|
1865 the previous function. */
|
|
1866
|
|
1867 Charbpos
|
|
1868 bytebpos_to_charbpos_func (struct buffer *buf, Bytebpos x)
|
|
1869 {
|
|
1870 Charbpos bufmin;
|
|
1871 Charbpos bufmax;
|
|
1872 Bytebpos bytmin;
|
|
1873 Bytebpos bytmax;
|
|
1874 int size;
|
|
1875 int forward_p;
|
|
1876 Charbpos retval;
|
|
1877 int diff_so_far;
|
|
1878 int add_to_cache = 0;
|
|
1879
|
|
1880 /* Check for some cached positions, for speed. */
|
826
|
1881 if (x == BYTE_BUF_PT (buf))
|
771
|
1882 return BUF_PT (buf);
|
826
|
1883 if (x == BYTE_BUF_ZV (buf))
|
771
|
1884 return BUF_ZV (buf);
|
826
|
1885 if (x == BYTE_BUF_BEGV (buf))
|
771
|
1886 return BUF_BEGV (buf);
|
|
1887
|
|
1888 bufmin = buf->text->mule_bufmin;
|
|
1889 bufmax = buf->text->mule_bufmax;
|
|
1890 bytmin = buf->text->mule_bytmin;
|
|
1891 bytmax = buf->text->mule_bytmax;
|
|
1892 size = (1 << buf->text->mule_shifter) + !!buf->text->mule_three_p;
|
|
1893
|
|
1894 /* The basic idea here is that we shift the "known region" up or down
|
|
1895 until it overlaps the specified position. We do this by moving
|
|
1896 the upper bound of the known region up one character at a time,
|
|
1897 and moving the lower bound of the known region up as necessary
|
|
1898 when the size of the character just seen changes.
|
|
1899
|
|
1900 We optimize this, however, by first shifting the known region to
|
826
|
1901 one of the cached points if it's close by. (We don't check BYTE_BEG or
|
|
1902 BYTE_Z, even though they're cached; most of the time these will be the
|
|
1903 same as BYTE_BEGV and BYTE_ZV, and when they're not, they're not likely
|
771
|
1904 to be used.) */
|
|
1905
|
|
1906 if (x > bytmax)
|
|
1907 {
|
|
1908 Bytebpos diffmax = x - bytmax;
|
826
|
1909 Bytebpos diffpt = x - BYTE_BUF_PT (buf);
|
|
1910 Bytebpos diffzv = BYTE_BUF_ZV (buf) - x;
|
771
|
1911 /* #### This value could stand some more exploration. */
|
|
1912 Bytecount heuristic_hack = (bytmax - bytmin) >> 2;
|
|
1913
|
|
1914 /* Check if the position is closer to PT or ZV than to the
|
|
1915 end of the known region. */
|
|
1916
|
|
1917 if (diffpt < 0)
|
|
1918 diffpt = -diffpt;
|
|
1919 if (diffzv < 0)
|
|
1920 diffzv = -diffzv;
|
|
1921
|
|
1922 /* But also implement a heuristic that favors the known region
|
826
|
1923 over BYTE_PT or BYTE_ZV. The reason for this is that switching to
|
|
1924 BYTE_PT or BYTE_ZV will wipe out the knowledge in the known region,
|
771
|
1925 which might be annoying if the known region is large and
|
826
|
1926 BYTE_PT or BYTE_ZV is not that much closer than the end of the known
|
771
|
1927 region. */
|
|
1928
|
|
1929 diffzv += heuristic_hack;
|
|
1930 diffpt += heuristic_hack;
|
|
1931 if (diffpt < diffmax && diffpt <= diffzv)
|
|
1932 {
|
|
1933 bufmax = bufmin = BUF_PT (buf);
|
826
|
1934 bytmax = bytmin = BYTE_BUF_PT (buf);
|
771
|
1935 /* We set the size to 1 even though it doesn't really
|
|
1936 matter because the new known region contains no
|
|
1937 characters. We do this because this is the most
|
|
1938 likely size of the characters around the new known
|
|
1939 region, and we avoid potential yuckiness that is
|
|
1940 done when size == 3. */
|
|
1941 size = 1;
|
|
1942 }
|
|
1943 if (diffzv < diffmax)
|
|
1944 {
|
|
1945 bufmax = bufmin = BUF_ZV (buf);
|
826
|
1946 bytmax = bytmin = BYTE_BUF_ZV (buf);
|
771
|
1947 size = 1;
|
|
1948 }
|
|
1949 }
|
800
|
1950 #ifdef ERROR_CHECK_TEXT
|
771
|
1951 else if (x >= bytmin)
|
|
1952 abort ();
|
|
1953 #endif
|
|
1954 else
|
|
1955 {
|
|
1956 Bytebpos diffmin = bytmin - x;
|
826
|
1957 Bytebpos diffpt = BYTE_BUF_PT (buf) - x;
|
|
1958 Bytebpos diffbegv = x - BYTE_BUF_BEGV (buf);
|
771
|
1959 /* #### This value could stand some more exploration. */
|
|
1960 Bytecount heuristic_hack = (bytmax - bytmin) >> 2;
|
|
1961
|
|
1962 if (diffpt < 0)
|
|
1963 diffpt = -diffpt;
|
|
1964 if (diffbegv < 0)
|
|
1965 diffbegv = -diffbegv;
|
|
1966
|
|
1967 /* But also implement a heuristic that favors the known region --
|
|
1968 see above. */
|
|
1969
|
|
1970 diffbegv += heuristic_hack;
|
|
1971 diffpt += heuristic_hack;
|
|
1972
|
|
1973 if (diffpt < diffmin && diffpt <= diffbegv)
|
|
1974 {
|
|
1975 bufmax = bufmin = BUF_PT (buf);
|
826
|
1976 bytmax = bytmin = BYTE_BUF_PT (buf);
|
771
|
1977 /* We set the size to 1 even though it doesn't really
|
|
1978 matter because the new known region contains no
|
|
1979 characters. We do this because this is the most
|
|
1980 likely size of the characters around the new known
|
|
1981 region, and we avoid potential yuckiness that is
|
|
1982 done when size == 3. */
|
|
1983 size = 1;
|
|
1984 }
|
|
1985 if (diffbegv < diffmin)
|
|
1986 {
|
|
1987 bufmax = bufmin = BUF_BEGV (buf);
|
826
|
1988 bytmax = bytmin = BYTE_BUF_BEGV (buf);
|
771
|
1989 size = 1;
|
|
1990 }
|
|
1991 }
|
|
1992
|
|
1993 diff_so_far = x > bytmax ? x - bytmax : bytmin - x;
|
|
1994 if (diff_so_far > 50)
|
|
1995 {
|
|
1996 /* If we have to move more than a certain amount, then look
|
|
1997 into our cache. */
|
|
1998 int minval = INT_MAX;
|
|
1999 int found = 0;
|
|
2000 int i;
|
|
2001
|
|
2002 add_to_cache = 1;
|
|
2003 /* I considered keeping the positions ordered. This would speed
|
|
2004 up this loop, but updating the cache would take longer, so
|
|
2005 it doesn't seem like it would really matter. */
|
|
2006 for (i = 0; i < 16; i++)
|
|
2007 {
|
|
2008 int diff = buf->text->mule_bytebpos_cache[i] - x;
|
|
2009
|
|
2010 if (diff < 0)
|
|
2011 diff = -diff;
|
|
2012 if (diff < minval)
|
|
2013 {
|
|
2014 minval = diff;
|
|
2015 found = i;
|
|
2016 }
|
|
2017 }
|
|
2018
|
|
2019 if (minval < diff_so_far)
|
|
2020 {
|
|
2021 bufmax = bufmin = buf->text->mule_charbpos_cache[found];
|
|
2022 bytmax = bytmin = buf->text->mule_bytebpos_cache[found];
|
|
2023 size = 1;
|
|
2024 }
|
|
2025 }
|
|
2026
|
|
2027 /* It's conceivable that the caching above could lead to X being
|
|
2028 the same as one of the range edges. */
|
|
2029 if (x >= bytmax)
|
|
2030 {
|
|
2031 Bytebpos newmax;
|
|
2032 Bytecount newsize;
|
|
2033
|
|
2034 forward_p = 1;
|
|
2035 while (x > bytmax)
|
|
2036 {
|
|
2037 newmax = bytmax;
|
|
2038
|
|
2039 INC_BYTEBPOS (buf, newmax);
|
|
2040 newsize = newmax - bytmax;
|
|
2041 if (newsize != size)
|
|
2042 {
|
|
2043 bufmin = bufmax;
|
|
2044 bytmin = bytmax;
|
|
2045 size = newsize;
|
|
2046 }
|
|
2047 bytmax = newmax;
|
|
2048 bufmax++;
|
|
2049 }
|
|
2050 retval = bufmax;
|
|
2051
|
|
2052 /* #### Should go past the found location to reduce the number
|
|
2053 of times that this function is called */
|
|
2054 }
|
|
2055 else /* x <= bytmin */
|
|
2056 {
|
|
2057 Bytebpos newmin;
|
|
2058 Bytecount newsize;
|
|
2059
|
|
2060 forward_p = 0;
|
|
2061 while (x < bytmin)
|
|
2062 {
|
|
2063 newmin = bytmin;
|
|
2064
|
|
2065 DEC_BYTEBPOS (buf, newmin);
|
|
2066 newsize = bytmin - newmin;
|
|
2067 if (newsize != size)
|
|
2068 {
|
|
2069 bufmax = bufmin;
|
|
2070 bytmax = bytmin;
|
|
2071 size = newsize;
|
|
2072 }
|
|
2073 bytmin = newmin;
|
|
2074 bufmin--;
|
|
2075 }
|
|
2076 retval = bufmin;
|
|
2077
|
|
2078 /* #### Should go past the found location to reduce the number
|
|
2079 of times that this function is called
|
|
2080 */
|
|
2081 }
|
|
2082
|
|
2083 /* If size is three, than we have to max sure that the range we
|
|
2084 discovered isn't too large, because we use a fixed-length
|
|
2085 table to divide by 3. */
|
|
2086
|
|
2087 if (size == 3)
|
|
2088 {
|
|
2089 int gap = bytmax - bytmin;
|
|
2090 buf->text->mule_three_p = 1;
|
|
2091 buf->text->mule_shifter = 1;
|
|
2092
|
|
2093 if (gap > MAX_BYTEBPOS_GAP_SIZE_3)
|
|
2094 {
|
|
2095 if (forward_p)
|
|
2096 {
|
|
2097 bytmin = bytmax - MAX_BYTEBPOS_GAP_SIZE_3;
|
|
2098 bufmin = bufmax - MAX_CHARBPOS_GAP_SIZE_3;
|
|
2099 }
|
|
2100 else
|
|
2101 {
|
|
2102 bytmax = bytmin + MAX_BYTEBPOS_GAP_SIZE_3;
|
|
2103 bufmax = bufmin + MAX_CHARBPOS_GAP_SIZE_3;
|
|
2104 }
|
|
2105 }
|
|
2106 }
|
|
2107 else
|
|
2108 {
|
|
2109 buf->text->mule_three_p = 0;
|
|
2110 if (size == 4)
|
|
2111 buf->text->mule_shifter = 2;
|
|
2112 else
|
|
2113 buf->text->mule_shifter = size - 1;
|
|
2114 }
|
|
2115
|
|
2116 buf->text->mule_bufmin = bufmin;
|
|
2117 buf->text->mule_bufmax = bufmax;
|
|
2118 buf->text->mule_bytmin = bytmin;
|
|
2119 buf->text->mule_bytmax = bytmax;
|
|
2120
|
|
2121 if (add_to_cache)
|
|
2122 {
|
|
2123 int replace_loc;
|
|
2124
|
|
2125 /* We throw away a "random" cached value and replace it with
|
|
2126 the new value. It doesn't actually have to be very random
|
|
2127 at all, just evenly distributed.
|
|
2128
|
|
2129 #### It would be better to use a least-recently-used algorithm
|
|
2130 or something that tries to space things out, but I'm not sure
|
|
2131 it's worth it to go to the trouble of maintaining that. */
|
|
2132 not_very_random_number += 621;
|
|
2133 replace_loc = not_very_random_number & 15;
|
|
2134 buf->text->mule_charbpos_cache[replace_loc] = retval;
|
|
2135 buf->text->mule_bytebpos_cache[replace_loc] = x;
|
|
2136 }
|
|
2137
|
|
2138 return retval;
|
|
2139 }
|
|
2140
|
|
2141 /* Text of length BYTELENGTH and CHARLENGTH (in different units)
|
|
2142 was inserted at charbpos START. */
|
|
2143
|
|
2144 void
|
|
2145 buffer_mule_signal_inserted_region (struct buffer *buf, Charbpos start,
|
|
2146 Bytecount bytelength,
|
|
2147 Charcount charlength)
|
|
2148 {
|
|
2149 int size = (1 << buf->text->mule_shifter) + !!buf->text->mule_three_p;
|
|
2150 int i;
|
|
2151
|
|
2152 /* Adjust the cache of known positions. */
|
|
2153 for (i = 0; i < 16; i++)
|
|
2154 {
|
|
2155
|
|
2156 if (buf->text->mule_charbpos_cache[i] > start)
|
|
2157 {
|
|
2158 buf->text->mule_charbpos_cache[i] += charlength;
|
|
2159 buf->text->mule_bytebpos_cache[i] += bytelength;
|
|
2160 }
|
|
2161 }
|
|
2162
|
|
2163 if (start >= buf->text->mule_bufmax)
|
826
|
2164 return;
|
771
|
2165
|
|
2166 /* The insertion is either before the known region, in which case
|
|
2167 it shoves it forward; or within the known region, in which case
|
|
2168 it shoves the end forward. (But it may make the known region
|
|
2169 inconsistent, so we may have to shorten it.) */
|
|
2170
|
|
2171 if (start <= buf->text->mule_bufmin)
|
|
2172 {
|
|
2173 buf->text->mule_bufmin += charlength;
|
|
2174 buf->text->mule_bufmax += charlength;
|
|
2175 buf->text->mule_bytmin += bytelength;
|
|
2176 buf->text->mule_bytmax += bytelength;
|
|
2177 }
|
|
2178 else
|
|
2179 {
|
|
2180 Charbpos end = start + charlength;
|
|
2181 /* the insertion point divides the known region in two.
|
|
2182 Keep the longer half, at least, and expand into the
|
|
2183 inserted chunk as much as possible. */
|
|
2184
|
|
2185 if (start - buf->text->mule_bufmin > buf->text->mule_bufmax - start)
|
|
2186 {
|
|
2187 Bytebpos bytestart = (buf->text->mule_bytmin
|
|
2188 + size * (start - buf->text->mule_bufmin));
|
|
2189 Bytebpos bytenew;
|
|
2190
|
|
2191 while (start < end)
|
|
2192 {
|
|
2193 bytenew = bytestart;
|
|
2194 INC_BYTEBPOS (buf, bytenew);
|
|
2195 if (bytenew - bytestart != size)
|
|
2196 break;
|
|
2197 start++;
|
|
2198 bytestart = bytenew;
|
|
2199 }
|
|
2200 if (start != end)
|
|
2201 {
|
|
2202 buf->text->mule_bufmax = start;
|
|
2203 buf->text->mule_bytmax = bytestart;
|
|
2204 }
|
|
2205 else
|
|
2206 {
|
|
2207 buf->text->mule_bufmax += charlength;
|
|
2208 buf->text->mule_bytmax += bytelength;
|
|
2209 }
|
|
2210 }
|
|
2211 else
|
|
2212 {
|
|
2213 Bytebpos byteend = (buf->text->mule_bytmin
|
|
2214 + size * (start - buf->text->mule_bufmin)
|
|
2215 + bytelength);
|
|
2216 Bytebpos bytenew;
|
|
2217
|
|
2218 buf->text->mule_bufmax += charlength;
|
|
2219 buf->text->mule_bytmax += bytelength;
|
|
2220
|
|
2221 while (end > start)
|
|
2222 {
|
|
2223 bytenew = byteend;
|
|
2224 DEC_BYTEBPOS (buf, bytenew);
|
|
2225 if (byteend - bytenew != size)
|
|
2226 break;
|
|
2227 end--;
|
|
2228 byteend = bytenew;
|
|
2229 }
|
|
2230 if (start != end)
|
|
2231 {
|
|
2232 buf->text->mule_bufmin = end;
|
|
2233 buf->text->mule_bytmin = byteend;
|
|
2234 }
|
|
2235 }
|
|
2236 }
|
|
2237 }
|
|
2238
|
826
|
2239 /* Text from START to END (equivalent in Bytebpos's: from BYTE_START to
|
|
2240 BYTE_END) was deleted. */
|
771
|
2241
|
|
2242 void
|
|
2243 buffer_mule_signal_deleted_region (struct buffer *buf, Charbpos start,
|
826
|
2244 Charbpos end, Bytebpos byte_start,
|
|
2245 Bytebpos byte_end)
|
771
|
2246 {
|
|
2247 int i;
|
|
2248
|
|
2249 /* Adjust the cache of known positions. */
|
|
2250 for (i = 0; i < 16; i++)
|
|
2251 {
|
|
2252 /* After the end; gets shoved backward */
|
|
2253 if (buf->text->mule_charbpos_cache[i] > end)
|
|
2254 {
|
|
2255 buf->text->mule_charbpos_cache[i] -= end - start;
|
826
|
2256 buf->text->mule_bytebpos_cache[i] -= byte_end - byte_start;
|
771
|
2257 }
|
|
2258 /* In the range; moves to start of range */
|
|
2259 else if (buf->text->mule_charbpos_cache[i] > start)
|
|
2260 {
|
|
2261 buf->text->mule_charbpos_cache[i] = start;
|
826
|
2262 buf->text->mule_bytebpos_cache[i] = byte_start;
|
771
|
2263 }
|
|
2264 }
|
|
2265
|
|
2266 /* We don't care about any text after the end of the known region. */
|
|
2267
|
|
2268 end = min (end, buf->text->mule_bufmax);
|
826
|
2269 byte_end = min (byte_end, buf->text->mule_bytmax);
|
771
|
2270 if (start >= end)
|
826
|
2271 return;
|
771
|
2272
|
|
2273 /* The end of the known region offsets by the total amount of deletion,
|
|
2274 since it's all before it. */
|
|
2275
|
|
2276 buf->text->mule_bufmax -= end - start;
|
826
|
2277 buf->text->mule_bytmax -= byte_end - byte_start;
|
771
|
2278
|
|
2279 /* Now we don't care about any text after the start of the known region. */
|
|
2280
|
|
2281 end = min (end, buf->text->mule_bufmin);
|
826
|
2282 byte_end = min (byte_end, buf->text->mule_bytmin);
|
771
|
2283 if (start < end)
|
|
2284 {
|
|
2285 buf->text->mule_bufmin -= end - start;
|
826
|
2286 buf->text->mule_bytmin -= byte_end - byte_start;
|
771
|
2287 }
|
|
2288 }
|
|
2289
|
|
2290 #endif /* MULE */
|
|
2291
|
|
2292
|
|
2293 /************************************************************************/
|
|
2294 /* verifying buffer and string positions */
|
|
2295 /************************************************************************/
|
|
2296
|
|
2297 /* Functions below are tagged with either _byte or _char indicating
|
|
2298 whether they return byte or character positions. For a buffer,
|
|
2299 a character position is a "Charbpos" and a byte position is a "Bytebpos".
|
|
2300 For strings, these are sometimes typed using "Charcount" and
|
|
2301 "Bytecount". */
|
|
2302
|
|
2303 /* Flags for the functions below are:
|
|
2304
|
|
2305 GB_ALLOW_PAST_ACCESSIBLE
|
|
2306
|
|
2307 Allow positions to range over the entire buffer (BUF_BEG to BUF_Z),
|
|
2308 rather than just the accessible portion (BUF_BEGV to BUF_ZV).
|
|
2309 For strings, this flag has no effect.
|
|
2310
|
|
2311 GB_COERCE_RANGE
|
|
2312
|
|
2313 If the position is outside the allowable range, return the lower
|
|
2314 or upper bound of the range, whichever is closer to the specified
|
|
2315 position.
|
|
2316
|
|
2317 GB_NO_ERROR_IF_BAD
|
|
2318
|
|
2319 If the position is outside the allowable range, return -1.
|
|
2320
|
|
2321 GB_NEGATIVE_FROM_END
|
|
2322
|
|
2323 If a value is negative, treat it as an offset from the end.
|
|
2324 Only applies to strings.
|
|
2325
|
|
2326 The following additional flags apply only to the functions
|
|
2327 that return ranges:
|
|
2328
|
|
2329 GB_ALLOW_NIL
|
|
2330
|
|
2331 Either or both positions can be nil. If FROM is nil,
|
|
2332 FROM_OUT will contain the lower bound of the allowed range.
|
|
2333 If TO is nil, TO_OUT will contain the upper bound of the
|
|
2334 allowed range.
|
|
2335
|
|
2336 GB_CHECK_ORDER
|
|
2337
|
|
2338 FROM must contain the lower bound and TO the upper bound
|
|
2339 of the range. If the positions are reversed, an error is
|
|
2340 signalled.
|
|
2341
|
|
2342 The following is a combination flag:
|
|
2343
|
|
2344 GB_HISTORICAL_STRING_BEHAVIOR
|
|
2345
|
|
2346 Equivalent to (GB_NEGATIVE_FROM_END | GB_ALLOW_NIL).
|
|
2347 */
|
|
2348
|
|
2349 /* Return a buffer position stored in a Lisp_Object. Full
|
|
2350 error-checking is done on the position. Flags can be specified to
|
|
2351 control the behavior of out-of-range values. The default behavior
|
|
2352 is to require that the position is within the accessible part of
|
|
2353 the buffer (BEGV and ZV), and to signal an error if the position is
|
|
2354 out of range.
|
|
2355
|
|
2356 */
|
|
2357
|
|
2358 Charbpos
|
|
2359 get_buffer_pos_char (struct buffer *b, Lisp_Object pos, unsigned int flags)
|
|
2360 {
|
|
2361 /* Does not GC */
|
|
2362 Charbpos ind;
|
|
2363 Charbpos min_allowed, max_allowed;
|
|
2364
|
|
2365 CHECK_INT_COERCE_MARKER (pos);
|
|
2366 ind = XINT (pos);
|
|
2367 min_allowed = flags & GB_ALLOW_PAST_ACCESSIBLE ? BUF_BEG (b) : BUF_BEGV (b);
|
|
2368 max_allowed = flags & GB_ALLOW_PAST_ACCESSIBLE ? BUF_Z (b) : BUF_ZV (b);
|
|
2369
|
|
2370 if (ind < min_allowed || ind > max_allowed)
|
|
2371 {
|
|
2372 if (flags & GB_COERCE_RANGE)
|
|
2373 ind = ind < min_allowed ? min_allowed : max_allowed;
|
|
2374 else if (flags & GB_NO_ERROR_IF_BAD)
|
|
2375 ind = -1;
|
|
2376 else
|
|
2377 {
|
793
|
2378 Lisp_Object buffer = wrap_buffer (b);
|
|
2379
|
771
|
2380 args_out_of_range (buffer, pos);
|
|
2381 }
|
|
2382 }
|
|
2383
|
|
2384 return ind;
|
|
2385 }
|
|
2386
|
|
2387 Bytebpos
|
|
2388 get_buffer_pos_byte (struct buffer *b, Lisp_Object pos, unsigned int flags)
|
|
2389 {
|
|
2390 Charbpos bpos = get_buffer_pos_char (b, pos, flags);
|
|
2391 if (bpos < 0) /* could happen with GB_NO_ERROR_IF_BAD */
|
|
2392 return -1;
|
|
2393 return charbpos_to_bytebpos (b, bpos);
|
|
2394 }
|
|
2395
|
|
2396 /* Return a pair of buffer positions representing a range of text,
|
|
2397 taken from a pair of Lisp_Objects. Full error-checking is
|
|
2398 done on the positions. Flags can be specified to control the
|
|
2399 behavior of out-of-range values. The default behavior is to
|
|
2400 allow the range bounds to be specified in either order
|
|
2401 (however, FROM_OUT will always be the lower bound of the range
|
|
2402 and TO_OUT the upper bound),to require that the positions
|
|
2403 are within the accessible part of the buffer (BEGV and ZV),
|
|
2404 and to signal an error if the positions are out of range.
|
|
2405 */
|
|
2406
|
|
2407 void
|
|
2408 get_buffer_range_char (struct buffer *b, Lisp_Object from, Lisp_Object to,
|
826
|
2409 Charbpos *from_out, Charbpos *to_out,
|
|
2410 unsigned int flags)
|
771
|
2411 {
|
|
2412 /* Does not GC */
|
|
2413 Charbpos min_allowed, max_allowed;
|
|
2414
|
|
2415 min_allowed = (flags & GB_ALLOW_PAST_ACCESSIBLE) ?
|
|
2416 BUF_BEG (b) : BUF_BEGV (b);
|
|
2417 max_allowed = (flags & GB_ALLOW_PAST_ACCESSIBLE) ?
|
|
2418 BUF_Z (b) : BUF_ZV (b);
|
|
2419
|
|
2420 if (NILP (from) && (flags & GB_ALLOW_NIL))
|
|
2421 *from_out = min_allowed;
|
|
2422 else
|
|
2423 *from_out = get_buffer_pos_char (b, from, flags | GB_NO_ERROR_IF_BAD);
|
|
2424
|
|
2425 if (NILP (to) && (flags & GB_ALLOW_NIL))
|
|
2426 *to_out = max_allowed;
|
|
2427 else
|
|
2428 *to_out = get_buffer_pos_char (b, to, flags | GB_NO_ERROR_IF_BAD);
|
|
2429
|
|
2430 if ((*from_out < 0 || *to_out < 0) && !(flags & GB_NO_ERROR_IF_BAD))
|
|
2431 {
|
793
|
2432 Lisp_Object buffer = wrap_buffer (b);
|
|
2433
|
771
|
2434 args_out_of_range_3 (buffer, from, to);
|
|
2435 }
|
|
2436
|
|
2437 if (*from_out >= 0 && *to_out >= 0 && *from_out > *to_out)
|
|
2438 {
|
|
2439 if (flags & GB_CHECK_ORDER)
|
|
2440 invalid_argument_2 ("start greater than end", from, to);
|
|
2441 else
|
|
2442 {
|
|
2443 Charbpos temp = *from_out;
|
|
2444 *from_out = *to_out;
|
|
2445 *to_out = temp;
|
|
2446 }
|
|
2447 }
|
|
2448 }
|
|
2449
|
|
2450 void
|
|
2451 get_buffer_range_byte (struct buffer *b, Lisp_Object from, Lisp_Object to,
|
826
|
2452 Bytebpos *from_out, Bytebpos *to_out,
|
|
2453 unsigned int flags)
|
771
|
2454 {
|
|
2455 Charbpos s, e;
|
|
2456
|
|
2457 get_buffer_range_char (b, from, to, &s, &e, flags);
|
|
2458 if (s >= 0)
|
|
2459 *from_out = charbpos_to_bytebpos (b, s);
|
|
2460 else /* could happen with GB_NO_ERROR_IF_BAD */
|
|
2461 *from_out = -1;
|
|
2462 if (e >= 0)
|
|
2463 *to_out = charbpos_to_bytebpos (b, e);
|
|
2464 else
|
|
2465 *to_out = -1;
|
|
2466 }
|
|
2467
|
|
2468 static Charcount
|
|
2469 get_string_pos_char_1 (Lisp_Object string, Lisp_Object pos, unsigned int flags,
|
|
2470 Charcount known_length)
|
|
2471 {
|
|
2472 Charcount ccpos;
|
|
2473 Charcount min_allowed = 0;
|
|
2474 Charcount max_allowed = known_length;
|
|
2475
|
|
2476 /* Computation of KNOWN_LENGTH is potentially expensive so we pass
|
|
2477 it in. */
|
|
2478 CHECK_INT (pos);
|
|
2479 ccpos = XINT (pos);
|
|
2480 if (ccpos < 0 && flags & GB_NEGATIVE_FROM_END)
|
|
2481 ccpos += max_allowed;
|
|
2482
|
|
2483 if (ccpos < min_allowed || ccpos > max_allowed)
|
|
2484 {
|
|
2485 if (flags & GB_COERCE_RANGE)
|
|
2486 ccpos = ccpos < min_allowed ? min_allowed : max_allowed;
|
|
2487 else if (flags & GB_NO_ERROR_IF_BAD)
|
|
2488 ccpos = -1;
|
|
2489 else
|
|
2490 args_out_of_range (string, pos);
|
|
2491 }
|
|
2492
|
|
2493 return ccpos;
|
|
2494 }
|
|
2495
|
|
2496 Charcount
|
|
2497 get_string_pos_char (Lisp_Object string, Lisp_Object pos, unsigned int flags)
|
|
2498 {
|
|
2499 return get_string_pos_char_1 (string, pos, flags,
|
826
|
2500 string_char_length (string));
|
771
|
2501 }
|
|
2502
|
|
2503 Bytecount
|
|
2504 get_string_pos_byte (Lisp_Object string, Lisp_Object pos, unsigned int flags)
|
|
2505 {
|
|
2506 Charcount ccpos = get_string_pos_char (string, pos, flags);
|
|
2507 if (ccpos < 0) /* could happen with GB_NO_ERROR_IF_BAD */
|
|
2508 return -1;
|
793
|
2509 return string_index_char_to_byte (string, ccpos);
|
771
|
2510 }
|
|
2511
|
|
2512 void
|
|
2513 get_string_range_char (Lisp_Object string, Lisp_Object from, Lisp_Object to,
|
|
2514 Charcount *from_out, Charcount *to_out,
|
|
2515 unsigned int flags)
|
|
2516 {
|
|
2517 Charcount min_allowed = 0;
|
826
|
2518 Charcount max_allowed = string_char_length (string);
|
771
|
2519
|
|
2520 if (NILP (from) && (flags & GB_ALLOW_NIL))
|
|
2521 *from_out = min_allowed;
|
|
2522 else
|
|
2523 *from_out = get_string_pos_char_1 (string, from,
|
|
2524 flags | GB_NO_ERROR_IF_BAD,
|
|
2525 max_allowed);
|
|
2526
|
|
2527 if (NILP (to) && (flags & GB_ALLOW_NIL))
|
|
2528 *to_out = max_allowed;
|
|
2529 else
|
|
2530 *to_out = get_string_pos_char_1 (string, to,
|
|
2531 flags | GB_NO_ERROR_IF_BAD,
|
|
2532 max_allowed);
|
|
2533
|
|
2534 if ((*from_out < 0 || *to_out < 0) && !(flags & GB_NO_ERROR_IF_BAD))
|
|
2535 args_out_of_range_3 (string, from, to);
|
|
2536
|
|
2537 if (*from_out >= 0 && *to_out >= 0 && *from_out > *to_out)
|
|
2538 {
|
|
2539 if (flags & GB_CHECK_ORDER)
|
|
2540 invalid_argument_2 ("start greater than end", from, to);
|
|
2541 else
|
|
2542 {
|
|
2543 Charbpos temp = *from_out;
|
|
2544 *from_out = *to_out;
|
|
2545 *to_out = temp;
|
|
2546 }
|
|
2547 }
|
|
2548 }
|
|
2549
|
|
2550 void
|
|
2551 get_string_range_byte (Lisp_Object string, Lisp_Object from, Lisp_Object to,
|
|
2552 Bytecount *from_out, Bytecount *to_out,
|
|
2553 unsigned int flags)
|
|
2554 {
|
|
2555 Charcount s, e;
|
|
2556
|
|
2557 get_string_range_char (string, from, to, &s, &e, flags);
|
|
2558 if (s >= 0)
|
793
|
2559 *from_out = string_index_char_to_byte (string, s);
|
771
|
2560 else /* could happen with GB_NO_ERROR_IF_BAD */
|
|
2561 *from_out = -1;
|
|
2562 if (e >= 0)
|
793
|
2563 *to_out = string_index_char_to_byte (string, e);
|
771
|
2564 else
|
|
2565 *to_out = -1;
|
|
2566
|
|
2567 }
|
|
2568
|
826
|
2569 Charxpos
|
771
|
2570 get_buffer_or_string_pos_char (Lisp_Object object, Lisp_Object pos,
|
|
2571 unsigned int flags)
|
|
2572 {
|
|
2573 return STRINGP (object) ?
|
|
2574 get_string_pos_char (object, pos, flags) :
|
|
2575 get_buffer_pos_char (XBUFFER (object), pos, flags);
|
|
2576 }
|
|
2577
|
826
|
2578 Bytexpos
|
771
|
2579 get_buffer_or_string_pos_byte (Lisp_Object object, Lisp_Object pos,
|
|
2580 unsigned int flags)
|
|
2581 {
|
|
2582 return STRINGP (object) ?
|
|
2583 get_string_pos_byte (object, pos, flags) :
|
|
2584 get_buffer_pos_byte (XBUFFER (object), pos, flags);
|
|
2585 }
|
|
2586
|
|
2587 void
|
|
2588 get_buffer_or_string_range_char (Lisp_Object object, Lisp_Object from,
|
826
|
2589 Lisp_Object to, Charxpos *from_out,
|
|
2590 Charxpos *to_out, unsigned int flags)
|
771
|
2591 {
|
|
2592 if (STRINGP (object))
|
|
2593 get_string_range_char (object, from, to, from_out, to_out, flags);
|
|
2594 else
|
826
|
2595 get_buffer_range_char (XBUFFER (object), from, to, from_out, to_out,
|
|
2596 flags);
|
771
|
2597 }
|
|
2598
|
|
2599 void
|
|
2600 get_buffer_or_string_range_byte (Lisp_Object object, Lisp_Object from,
|
826
|
2601 Lisp_Object to, Bytexpos *from_out,
|
|
2602 Bytexpos *to_out, unsigned int flags)
|
771
|
2603 {
|
|
2604 if (STRINGP (object))
|
|
2605 get_string_range_byte (object, from, to, from_out, to_out, flags);
|
|
2606 else
|
826
|
2607 get_buffer_range_byte (XBUFFER (object), from, to, from_out, to_out,
|
|
2608 flags);
|
771
|
2609 }
|
|
2610
|
826
|
2611 Charxpos
|
771
|
2612 buffer_or_string_accessible_begin_char (Lisp_Object object)
|
|
2613 {
|
|
2614 return STRINGP (object) ? 0 : BUF_BEGV (XBUFFER (object));
|
|
2615 }
|
|
2616
|
826
|
2617 Charxpos
|
771
|
2618 buffer_or_string_accessible_end_char (Lisp_Object object)
|
|
2619 {
|
|
2620 return STRINGP (object) ?
|
826
|
2621 string_char_length (object) : BUF_ZV (XBUFFER (object));
|
771
|
2622 }
|
|
2623
|
826
|
2624 Bytexpos
|
771
|
2625 buffer_or_string_accessible_begin_byte (Lisp_Object object)
|
|
2626 {
|
826
|
2627 return STRINGP (object) ? 0 : BYTE_BUF_BEGV (XBUFFER (object));
|
771
|
2628 }
|
|
2629
|
826
|
2630 Bytexpos
|
771
|
2631 buffer_or_string_accessible_end_byte (Lisp_Object object)
|
|
2632 {
|
|
2633 return STRINGP (object) ?
|
826
|
2634 XSTRING_LENGTH (object) : BYTE_BUF_ZV (XBUFFER (object));
|
771
|
2635 }
|
|
2636
|
826
|
2637 Charxpos
|
771
|
2638 buffer_or_string_absolute_begin_char (Lisp_Object object)
|
|
2639 {
|
|
2640 return STRINGP (object) ? 0 : BUF_BEG (XBUFFER (object));
|
|
2641 }
|
|
2642
|
826
|
2643 Charxpos
|
771
|
2644 buffer_or_string_absolute_end_char (Lisp_Object object)
|
|
2645 {
|
|
2646 return STRINGP (object) ?
|
826
|
2647 string_char_length (object) : BUF_Z (XBUFFER (object));
|
|
2648 }
|
|
2649
|
|
2650 Bytexpos
|
|
2651 buffer_or_string_absolute_begin_byte (Lisp_Object object)
|
|
2652 {
|
|
2653 return STRINGP (object) ? 0 : BYTE_BUF_BEG (XBUFFER (object));
|
|
2654 }
|
|
2655
|
|
2656 Bytexpos
|
|
2657 buffer_or_string_absolute_end_byte (Lisp_Object object)
|
|
2658 {
|
|
2659 return STRINGP (object) ?
|
|
2660 XSTRING_LENGTH (object) : BYTE_BUF_Z (XBUFFER (object));
|
|
2661 }
|
|
2662
|
|
2663 Charbpos
|
|
2664 charbpos_clip_to_bounds (Charbpos lower, Charbpos num, Charbpos upper)
|
|
2665 {
|
|
2666 return (num < lower ? lower :
|
|
2667 num > upper ? upper :
|
|
2668 num);
|
771
|
2669 }
|
|
2670
|
|
2671 Bytebpos
|
826
|
2672 bytebpos_clip_to_bounds (Bytebpos lower, Bytebpos num, Bytebpos upper)
|
|
2673 {
|
|
2674 return (num < lower ? lower :
|
|
2675 num > upper ? upper :
|
|
2676 num);
|
|
2677 }
|
|
2678
|
|
2679 Charxpos
|
|
2680 charxpos_clip_to_bounds (Charxpos lower, Charxpos num, Charxpos upper)
|
771
|
2681 {
|
826
|
2682 return (num < lower ? lower :
|
|
2683 num > upper ? upper :
|
|
2684 num);
|
|
2685 }
|
|
2686
|
|
2687 Bytexpos
|
|
2688 bytexpos_clip_to_bounds (Bytexpos lower, Bytexpos num, Bytexpos upper)
|
|
2689 {
|
|
2690 return (num < lower ? lower :
|
|
2691 num > upper ? upper :
|
|
2692 num);
|
771
|
2693 }
|
|
2694
|
826
|
2695 /* These could be implemented in terms of the get_buffer_or_string()
|
|
2696 functions above, but those are complicated and handle lots of weird
|
|
2697 cases stemming from uncertain external input. */
|
|
2698
|
|
2699 Charxpos
|
|
2700 buffer_or_string_clip_to_accessible_char (Lisp_Object object, Charxpos pos)
|
|
2701 {
|
|
2702 return (charxpos_clip_to_bounds
|
|
2703 (pos, buffer_or_string_accessible_begin_char (object),
|
|
2704 buffer_or_string_accessible_end_char (object)));
|
|
2705 }
|
|
2706
|
|
2707 Bytexpos
|
|
2708 buffer_or_string_clip_to_accessible_byte (Lisp_Object object, Bytexpos pos)
|
771
|
2709 {
|
826
|
2710 return (bytexpos_clip_to_bounds
|
|
2711 (pos, buffer_or_string_accessible_begin_byte (object),
|
|
2712 buffer_or_string_accessible_end_byte (object)));
|
|
2713 }
|
|
2714
|
|
2715 Charxpos
|
|
2716 buffer_or_string_clip_to_absolute_char (Lisp_Object object, Charxpos pos)
|
|
2717 {
|
|
2718 return (charxpos_clip_to_bounds
|
|
2719 (pos, buffer_or_string_absolute_begin_char (object),
|
|
2720 buffer_or_string_absolute_end_char (object)));
|
|
2721 }
|
|
2722
|
|
2723 Bytexpos
|
|
2724 buffer_or_string_clip_to_absolute_byte (Lisp_Object object, Bytexpos pos)
|
|
2725 {
|
|
2726 return (bytexpos_clip_to_bounds
|
|
2727 (pos, buffer_or_string_absolute_begin_byte (object),
|
|
2728 buffer_or_string_absolute_end_byte (object)));
|
771
|
2729 }
|
|
2730
|
|
2731
|
|
2732 /************************************************************************/
|
|
2733 /* Implement TO_EXTERNAL_FORMAT, TO_INTERNAL_FORMAT */
|
|
2734 /************************************************************************/
|
|
2735
|
|
2736 typedef struct
|
|
2737 {
|
|
2738 Dynarr_declare (Intbyte_dynarr *);
|
|
2739 } Intbyte_dynarr_dynarr;
|
|
2740
|
|
2741 typedef struct
|
|
2742 {
|
|
2743 Dynarr_declare (Extbyte_dynarr *);
|
|
2744 } Extbyte_dynarr_dynarr;
|
|
2745
|
|
2746 static Extbyte_dynarr_dynarr *conversion_out_dynarr_list;
|
|
2747 static Intbyte_dynarr_dynarr *conversion_in_dynarr_list;
|
|
2748
|
|
2749 static int dfc_convert_to_external_format_in_use;
|
|
2750 static int dfc_convert_to_internal_format_in_use;
|
|
2751
|
|
2752 static Lisp_Object
|
|
2753 dfc_convert_to_external_format_reset_in_use (Lisp_Object value)
|
|
2754 {
|
|
2755 dfc_convert_to_external_format_in_use = XINT (value);
|
|
2756 return Qnil;
|
|
2757 }
|
|
2758
|
|
2759 static Lisp_Object
|
|
2760 dfc_convert_to_internal_format_reset_in_use (Lisp_Object value)
|
|
2761 {
|
|
2762 dfc_convert_to_internal_format_in_use = XINT (value);
|
|
2763 return Qnil;
|
|
2764 }
|
|
2765
|
|
2766 void
|
|
2767 dfc_convert_to_external_format (dfc_conversion_type source_type,
|
|
2768 dfc_conversion_data *source,
|
|
2769 Lisp_Object coding_system,
|
|
2770 dfc_conversion_type sink_type,
|
|
2771 dfc_conversion_data *sink)
|
|
2772 {
|
|
2773 /* It's guaranteed that many callers are not prepared for GC here,
|
|
2774 esp. given that this code conversion occurs in many very hidden
|
|
2775 places. */
|
|
2776 int count = begin_gc_forbidden ();
|
|
2777 Extbyte_dynarr *conversion_out_dynarr;
|
|
2778
|
|
2779 type_checking_assert
|
|
2780 (((source_type == DFC_TYPE_DATA) ||
|
|
2781 (source_type == DFC_TYPE_LISP_LSTREAM && LSTREAMP (source->lisp_object)) ||
|
|
2782 (source_type == DFC_TYPE_LISP_STRING && STRINGP (source->lisp_object)))
|
|
2783 &&
|
|
2784 ((sink_type == DFC_TYPE_DATA) ||
|
|
2785 (sink_type == DFC_TYPE_LISP_LSTREAM && LSTREAMP (source->lisp_object))));
|
|
2786
|
|
2787 record_unwind_protect (dfc_convert_to_external_format_reset_in_use,
|
|
2788 make_int (dfc_convert_to_external_format_in_use));
|
|
2789 if (Dynarr_length (conversion_out_dynarr_list) <=
|
|
2790 dfc_convert_to_external_format_in_use)
|
|
2791 Dynarr_add (conversion_out_dynarr_list, Dynarr_new (Extbyte));
|
|
2792 conversion_out_dynarr = Dynarr_at (conversion_out_dynarr_list,
|
|
2793 dfc_convert_to_external_format_in_use);
|
|
2794 dfc_convert_to_external_format_in_use++;
|
|
2795 Dynarr_reset (conversion_out_dynarr);
|
|
2796
|
|
2797 coding_system = get_coding_system_for_text_file (coding_system, 0);
|
|
2798
|
|
2799 /* Here we optimize in the case where the coding system does no
|
|
2800 conversion. However, we don't want to optimize in case the source
|
|
2801 or sink is an lstream, since writing to an lstream can cause a
|
|
2802 garbage collection, and this could be problematic if the source
|
|
2803 is a lisp string. */
|
|
2804 if (source_type != DFC_TYPE_LISP_LSTREAM &&
|
|
2805 sink_type != DFC_TYPE_LISP_LSTREAM &&
|
|
2806 coding_system_is_binary (coding_system))
|
|
2807 {
|
|
2808 const Intbyte *ptr;
|
|
2809 Bytecount len;
|
|
2810
|
|
2811 if (source_type == DFC_TYPE_LISP_STRING)
|
|
2812 {
|
|
2813 ptr = XSTRING_DATA (source->lisp_object);
|
|
2814 len = XSTRING_LENGTH (source->lisp_object);
|
|
2815 }
|
|
2816 else
|
|
2817 {
|
|
2818 ptr = (Intbyte *) source->data.ptr;
|
|
2819 len = source->data.len;
|
|
2820 }
|
|
2821
|
|
2822 #ifdef MULE
|
|
2823 {
|
|
2824 const Intbyte *end;
|
|
2825 for (end = ptr + len; ptr < end;)
|
|
2826 {
|
|
2827 Intbyte c =
|
826
|
2828 (byte_ascii_p (*ptr)) ? *ptr :
|
771
|
2829 (*ptr == LEADING_BYTE_CONTROL_1) ? (*(ptr+1) - 0x20) :
|
|
2830 (*ptr == LEADING_BYTE_LATIN_ISO8859_1) ? (*(ptr+1)) :
|
|
2831 '~';
|
|
2832
|
|
2833 Dynarr_add (conversion_out_dynarr, (Extbyte) c);
|
|
2834 INC_CHARPTR (ptr);
|
|
2835 }
|
800
|
2836 text_checking_assert (ptr == end);
|
771
|
2837 }
|
|
2838 #else
|
|
2839 Dynarr_add_many (conversion_out_dynarr, ptr, len);
|
|
2840 #endif
|
|
2841
|
|
2842 }
|
|
2843 #ifdef HAVE_WIN32_CODING_SYSTEMS
|
|
2844 /* Optimize the common case involving Unicode where only ASCII is involved */
|
|
2845 else if (source_type != DFC_TYPE_LISP_LSTREAM &&
|
|
2846 sink_type != DFC_TYPE_LISP_LSTREAM &&
|
|
2847 dfc_coding_system_is_unicode (coding_system))
|
|
2848 {
|
|
2849 const Intbyte *ptr, *p;
|
|
2850 Bytecount len;
|
|
2851 const Intbyte *end;
|
|
2852
|
|
2853 if (source_type == DFC_TYPE_LISP_STRING)
|
|
2854 {
|
|
2855 ptr = XSTRING_DATA (source->lisp_object);
|
|
2856 len = XSTRING_LENGTH (source->lisp_object);
|
|
2857 }
|
|
2858 else
|
|
2859 {
|
|
2860 ptr = (Intbyte *) source->data.ptr;
|
|
2861 len = source->data.len;
|
|
2862 }
|
|
2863 end = ptr + len;
|
|
2864
|
|
2865 for (p = ptr; p < end; p++)
|
|
2866 {
|
826
|
2867 if (!byte_ascii_p (*p))
|
771
|
2868 goto the_hard_way;
|
|
2869 }
|
|
2870
|
|
2871 for (p = ptr; p < end; p++)
|
|
2872 {
|
|
2873 Dynarr_add (conversion_out_dynarr, (Extbyte) (*p));
|
|
2874 Dynarr_add (conversion_out_dynarr, (Extbyte) '\0');
|
|
2875 }
|
|
2876 }
|
|
2877 #endif /* HAVE_WIN32_CODING_SYSTEMS */
|
|
2878 else
|
|
2879 {
|
|
2880 Lisp_Object streams_to_delete[3];
|
|
2881 int delete_count;
|
|
2882 Lisp_Object instream, outstream;
|
|
2883 Lstream *reader, *writer;
|
|
2884 struct gcpro gcpro1, gcpro2;
|
|
2885
|
|
2886 #ifdef HAVE_WIN32_CODING_SYSTEMS
|
|
2887 the_hard_way:
|
|
2888 #endif /* HAVE_WIN32_CODING_SYSTEMS */
|
|
2889 delete_count = 0;
|
|
2890 if (source_type == DFC_TYPE_LISP_LSTREAM)
|
|
2891 instream = source->lisp_object;
|
|
2892 else if (source_type == DFC_TYPE_DATA)
|
|
2893 streams_to_delete[delete_count++] = instream =
|
|
2894 make_fixed_buffer_input_stream (source->data.ptr, source->data.len);
|
|
2895 else
|
|
2896 {
|
|
2897 type_checking_assert (source_type == DFC_TYPE_LISP_STRING);
|
|
2898 streams_to_delete[delete_count++] = instream =
|
|
2899 /* This will GCPRO the Lisp string */
|
|
2900 make_lisp_string_input_stream (source->lisp_object, 0, -1);
|
|
2901 }
|
|
2902
|
|
2903 if (sink_type == DFC_TYPE_LISP_LSTREAM)
|
|
2904 outstream = sink->lisp_object;
|
|
2905 else
|
|
2906 {
|
|
2907 type_checking_assert (sink_type == DFC_TYPE_DATA);
|
|
2908 streams_to_delete[delete_count++] = outstream =
|
|
2909 make_dynarr_output_stream
|
|
2910 ((unsigned_char_dynarr *) conversion_out_dynarr);
|
|
2911 }
|
|
2912
|
|
2913 streams_to_delete[delete_count++] = outstream =
|
800
|
2914 make_coding_output_stream (XLSTREAM (outstream), coding_system,
|
|
2915 CODING_ENCODE, 0);
|
771
|
2916
|
|
2917 reader = XLSTREAM (instream);
|
|
2918 writer = XLSTREAM (outstream);
|
|
2919 /* decoding_stream will gc-protect outstream */
|
|
2920 GCPRO2 (instream, outstream);
|
|
2921
|
|
2922 while (1)
|
|
2923 {
|
|
2924 Bytecount size_in_bytes;
|
|
2925 char tempbuf[1024]; /* some random amount */
|
|
2926
|
|
2927 size_in_bytes = Lstream_read (reader, tempbuf, sizeof (tempbuf));
|
|
2928
|
|
2929 if (size_in_bytes == 0)
|
|
2930 break;
|
|
2931 else if (size_in_bytes < 0)
|
|
2932 signal_error (Qtext_conversion_error,
|
|
2933 "Error converting to external format", Qunbound);
|
|
2934
|
|
2935 if (Lstream_write (writer, tempbuf, size_in_bytes) < 0)
|
|
2936 signal_error (Qtext_conversion_error,
|
|
2937 "Error converting to external format", Qunbound);
|
|
2938 }
|
|
2939
|
|
2940 /* Closing writer will close any stream at the other end of writer. */
|
|
2941 Lstream_close (writer);
|
|
2942 Lstream_close (reader);
|
|
2943 UNGCPRO;
|
|
2944
|
|
2945 /* The idea is that this function will create no garbage. */
|
|
2946 while (delete_count)
|
|
2947 Lstream_delete (XLSTREAM (streams_to_delete [--delete_count]));
|
|
2948 }
|
|
2949
|
|
2950 unbind_to (count);
|
|
2951
|
|
2952 if (sink_type != DFC_TYPE_LISP_LSTREAM)
|
|
2953 {
|
|
2954 sink->data.len = Dynarr_length (conversion_out_dynarr);
|
|
2955 /* double zero-extend because we may be dealing with Unicode data */
|
|
2956 Dynarr_add (conversion_out_dynarr, '\0');
|
|
2957 Dynarr_add (conversion_out_dynarr, '\0');
|
|
2958 sink->data.ptr = Dynarr_atp (conversion_out_dynarr, 0);
|
|
2959 }
|
|
2960 }
|
|
2961
|
|
2962 void
|
|
2963 dfc_convert_to_internal_format (dfc_conversion_type source_type,
|
|
2964 dfc_conversion_data *source,
|
|
2965 Lisp_Object coding_system,
|
|
2966 dfc_conversion_type sink_type,
|
|
2967 dfc_conversion_data *sink)
|
|
2968 {
|
|
2969 /* It's guaranteed that many callers are not prepared for GC here,
|
|
2970 esp. given that this code conversion occurs in many very hidden
|
|
2971 places. */
|
|
2972 int count = begin_gc_forbidden ();
|
|
2973 Intbyte_dynarr *conversion_in_dynarr;
|
|
2974
|
|
2975 type_checking_assert
|
|
2976 ((source_type == DFC_TYPE_DATA ||
|
|
2977 source_type == DFC_TYPE_LISP_LSTREAM)
|
|
2978 &&
|
|
2979 (sink_type == DFC_TYPE_DATA ||
|
|
2980 sink_type == DFC_TYPE_LISP_LSTREAM));
|
|
2981
|
|
2982 record_unwind_protect (dfc_convert_to_internal_format_reset_in_use,
|
|
2983 make_int (dfc_convert_to_internal_format_in_use));
|
|
2984 if (Dynarr_length (conversion_in_dynarr_list) <=
|
|
2985 dfc_convert_to_internal_format_in_use)
|
|
2986 Dynarr_add (conversion_in_dynarr_list, Dynarr_new (Intbyte));
|
|
2987 conversion_in_dynarr = Dynarr_at (conversion_in_dynarr_list,
|
|
2988 dfc_convert_to_internal_format_in_use);
|
|
2989 dfc_convert_to_internal_format_in_use++;
|
|
2990 Dynarr_reset (conversion_in_dynarr);
|
|
2991
|
|
2992 coding_system = get_coding_system_for_text_file (coding_system, 1);
|
|
2993
|
|
2994 if (source_type != DFC_TYPE_LISP_LSTREAM &&
|
|
2995 sink_type != DFC_TYPE_LISP_LSTREAM &&
|
|
2996 coding_system_is_binary (coding_system))
|
|
2997 {
|
|
2998 #ifdef MULE
|
|
2999 const Intbyte *ptr = (const Intbyte *) source->data.ptr;
|
|
3000 Bytecount len = source->data.len;
|
|
3001 const Intbyte *end = ptr + len;
|
|
3002
|
|
3003 for (; ptr < end; ptr++)
|
|
3004 {
|
|
3005 Intbyte c = *ptr;
|
|
3006
|
826
|
3007 if (byte_ascii_p (c))
|
771
|
3008 Dynarr_add (conversion_in_dynarr, c);
|
826
|
3009 else if (byte_c1_p (c))
|
771
|
3010 {
|
|
3011 Dynarr_add (conversion_in_dynarr, LEADING_BYTE_CONTROL_1);
|
|
3012 Dynarr_add (conversion_in_dynarr, c + 0x20);
|
|
3013 }
|
|
3014 else
|
|
3015 {
|
|
3016 Dynarr_add (conversion_in_dynarr, LEADING_BYTE_LATIN_ISO8859_1);
|
|
3017 Dynarr_add (conversion_in_dynarr, c);
|
|
3018 }
|
|
3019 }
|
|
3020 #else
|
|
3021 Dynarr_add_many (conversion_in_dynarr, source->data.ptr, source->data.len);
|
|
3022 #endif
|
|
3023 }
|
|
3024 #ifdef HAVE_WIN32_CODING_SYSTEMS
|
|
3025 /* Optimize the common case involving Unicode where only ASCII/Latin-1 is involved */
|
|
3026 else if (source_type != DFC_TYPE_LISP_LSTREAM &&
|
|
3027 sink_type != DFC_TYPE_LISP_LSTREAM &&
|
|
3028 dfc_coding_system_is_unicode (coding_system))
|
|
3029 {
|
|
3030 const Intbyte *ptr = (const Intbyte *) source->data.ptr + 1;
|
|
3031 Bytecount len = source->data.len;
|
|
3032 const Intbyte *end = ptr + len;
|
|
3033
|
|
3034 if (len & 1)
|
|
3035 goto the_hard_way;
|
|
3036
|
|
3037 for (; ptr < end; ptr += 2)
|
|
3038 {
|
|
3039 if (*ptr)
|
|
3040 goto the_hard_way;
|
|
3041 }
|
|
3042
|
|
3043 ptr = (const Intbyte *) source->data.ptr;
|
|
3044 end = ptr + len;
|
|
3045
|
|
3046 for (; ptr < end; ptr += 2)
|
|
3047 {
|
|
3048 Intbyte c = *ptr;
|
|
3049
|
826
|
3050 if (byte_ascii_p (c))
|
771
|
3051 Dynarr_add (conversion_in_dynarr, c);
|
|
3052 #ifdef MULE
|
826
|
3053 else if (byte_c1_p (c))
|
771
|
3054 {
|
|
3055 Dynarr_add (conversion_in_dynarr, LEADING_BYTE_CONTROL_1);
|
|
3056 Dynarr_add (conversion_in_dynarr, c + 0x20);
|
|
3057 }
|
|
3058 else
|
|
3059 {
|
|
3060 Dynarr_add (conversion_in_dynarr, LEADING_BYTE_LATIN_ISO8859_1);
|
|
3061 Dynarr_add (conversion_in_dynarr, c);
|
|
3062 }
|
|
3063 #endif /* MULE */
|
|
3064 }
|
|
3065 }
|
|
3066 #endif /* HAVE_WIN32_CODING_SYSTEMS */
|
|
3067 else
|
|
3068 {
|
|
3069 Lisp_Object streams_to_delete[3];
|
|
3070 int delete_count;
|
|
3071 Lisp_Object instream, outstream;
|
|
3072 Lstream *reader, *writer;
|
|
3073 struct gcpro gcpro1, gcpro2;
|
|
3074
|
|
3075 #ifdef HAVE_WIN32_CODING_SYSTEMS
|
|
3076 the_hard_way:
|
|
3077 #endif /* HAVE_WIN32_CODING_SYSTEMS */
|
|
3078 delete_count = 0;
|
|
3079 if (source_type == DFC_TYPE_LISP_LSTREAM)
|
|
3080 instream = source->lisp_object;
|
|
3081 else
|
|
3082 {
|
|
3083 type_checking_assert (source_type == DFC_TYPE_DATA);
|
|
3084 streams_to_delete[delete_count++] = instream =
|
|
3085 make_fixed_buffer_input_stream (source->data.ptr, source->data.len);
|
|
3086 }
|
|
3087
|
|
3088 if (sink_type == DFC_TYPE_LISP_LSTREAM)
|
|
3089 outstream = sink->lisp_object;
|
|
3090 else
|
|
3091 {
|
|
3092 type_checking_assert (sink_type == DFC_TYPE_DATA);
|
|
3093 streams_to_delete[delete_count++] = outstream =
|
|
3094 make_dynarr_output_stream
|
|
3095 ((unsigned_char_dynarr *) conversion_in_dynarr);
|
|
3096 }
|
|
3097
|
|
3098 streams_to_delete[delete_count++] = outstream =
|
800
|
3099 make_coding_output_stream (XLSTREAM (outstream), coding_system,
|
|
3100 CODING_DECODE, 0);
|
771
|
3101
|
|
3102 reader = XLSTREAM (instream);
|
|
3103 writer = XLSTREAM (outstream);
|
|
3104 /* outstream will gc-protect its sink stream, if necessary */
|
|
3105 GCPRO2 (instream, outstream);
|
|
3106
|
|
3107 while (1)
|
|
3108 {
|
|
3109 Bytecount size_in_bytes;
|
|
3110 char tempbuf[1024]; /* some random amount */
|
|
3111
|
|
3112 size_in_bytes = Lstream_read (reader, tempbuf, sizeof (tempbuf));
|
|
3113
|
|
3114 if (size_in_bytes == 0)
|
|
3115 break;
|
|
3116 else if (size_in_bytes < 0)
|
|
3117 signal_error (Qtext_conversion_error,
|
|
3118 "Error converting to internal format", Qunbound);
|
|
3119
|
|
3120 if (Lstream_write (writer, tempbuf, size_in_bytes) < 0)
|
|
3121 signal_error (Qtext_conversion_error,
|
|
3122 "Error converting to internal format", Qunbound);
|
|
3123 }
|
|
3124
|
|
3125 /* Closing writer will close any stream at the other end of writer. */
|
|
3126 Lstream_close (writer);
|
|
3127 Lstream_close (reader);
|
|
3128 UNGCPRO;
|
|
3129
|
|
3130 /* The idea is that this function will create no garbage. */
|
|
3131 while (delete_count)
|
|
3132 Lstream_delete (XLSTREAM (streams_to_delete [--delete_count]));
|
|
3133 }
|
|
3134
|
|
3135 unbind_to (count);
|
|
3136
|
|
3137 if (sink_type != DFC_TYPE_LISP_LSTREAM)
|
|
3138 {
|
|
3139 sink->data.len = Dynarr_length (conversion_in_dynarr);
|
|
3140 Dynarr_add (conversion_in_dynarr, '\0'); /* remember to NUL-terminate! */
|
|
3141 /* The macros don't currently distinguish between internal and
|
|
3142 external sinks, and allocate and copy two extra bytes in both
|
|
3143 cases. So we add a second zero, just like for external data
|
|
3144 (in that case, because we may be converting to Unicode). */
|
|
3145 Dynarr_add (conversion_in_dynarr, '\0');
|
|
3146 sink->data.ptr = Dynarr_atp (conversion_in_dynarr, 0);
|
|
3147 }
|
|
3148 }
|
|
3149
|
|
3150
|
|
3151 /************************************************************************/
|
|
3152 /* Basic Emchar functions */
|
|
3153 /************************************************************************/
|
|
3154
|
|
3155 #ifdef MULE
|
|
3156
|
|
3157 /* Convert a non-ASCII Mule character C into a one-character Mule-encoded
|
|
3158 string in STR. Returns the number of bytes stored.
|
|
3159 Do not call this directly. Use the macro set_charptr_emchar() instead.
|
|
3160 */
|
|
3161
|
|
3162 Bytecount
|
|
3163 non_ascii_set_charptr_emchar (Intbyte *str, Emchar c)
|
|
3164 {
|
|
3165 Intbyte *p;
|
|
3166 Intbyte lb;
|
|
3167 int c1, c2;
|
|
3168 Lisp_Object charset;
|
|
3169
|
|
3170 p = str;
|
826
|
3171 BREAKUP_EMCHAR (c, charset, c1, c2);
|
|
3172 lb = emchar_leading_byte (c);
|
|
3173 if (leading_byte_private_p (lb))
|
|
3174 *p++ = private_leading_byte_prefix (lb);
|
771
|
3175 *p++ = lb;
|
|
3176 if (EQ (charset, Vcharset_control_1))
|
|
3177 c1 += 0x20;
|
|
3178 *p++ = c1 | 0x80;
|
|
3179 if (c2)
|
|
3180 *p++ = c2 | 0x80;
|
|
3181
|
|
3182 return (p - str);
|
|
3183 }
|
|
3184
|
|
3185 /* Return the first character from a Mule-encoded string in STR,
|
|
3186 assuming it's non-ASCII. Do not call this directly.
|
|
3187 Use the macro charptr_emchar() instead. */
|
|
3188
|
|
3189 Emchar
|
|
3190 non_ascii_charptr_emchar (const Intbyte *str)
|
|
3191 {
|
|
3192 Intbyte i0 = *str, i1, i2 = 0;
|
|
3193 Lisp_Object charset;
|
|
3194
|
|
3195 if (i0 == LEADING_BYTE_CONTROL_1)
|
|
3196 return (Emchar) (*++str - 0x20);
|
|
3197
|
826
|
3198 if (leading_byte_prefix_p (i0))
|
771
|
3199 i0 = *++str;
|
|
3200
|
|
3201 i1 = *++str & 0x7F;
|
|
3202
|
826
|
3203 charset = charset_by_leading_byte (i0);
|
771
|
3204 if (XCHARSET_DIMENSION (charset) == 2)
|
|
3205 i2 = *++str & 0x7F;
|
|
3206
|
826
|
3207 return make_emchar (charset, i1, i2);
|
771
|
3208 }
|
|
3209
|
|
3210 /* Return whether CH is a valid Emchar, assuming it's non-ASCII.
|
826
|
3211 Do not call this directly. Use the macro valid_emchar_p() instead. */
|
771
|
3212
|
|
3213 int
|
826
|
3214 non_ascii_valid_emchar_p (Emchar ch)
|
771
|
3215 {
|
|
3216 int f1, f2, f3;
|
|
3217
|
|
3218 /* Must have only lowest 19 bits set */
|
|
3219 if (ch & ~0x7FFFF)
|
|
3220 return 0;
|
|
3221
|
826
|
3222 f1 = emchar_field1 (ch);
|
|
3223 f2 = emchar_field2 (ch);
|
|
3224 f3 = emchar_field3 (ch);
|
771
|
3225
|
|
3226 if (f1 == 0)
|
|
3227 {
|
|
3228 /* dimension-1 char */
|
|
3229 Lisp_Object charset;
|
|
3230
|
|
3231 /* leading byte must be correct */
|
826
|
3232 if (f2 < MIN_EMCHAR_FIELD2_OFFICIAL ||
|
|
3233 (f2 > MAX_EMCHAR_FIELD2_OFFICIAL && f2 < MIN_EMCHAR_FIELD2_PRIVATE) ||
|
|
3234 f2 > MAX_EMCHAR_FIELD2_PRIVATE)
|
771
|
3235 return 0;
|
|
3236 /* octet not out of range */
|
|
3237 if (f3 < 0x20)
|
|
3238 return 0;
|
|
3239 /* charset exists */
|
|
3240 /*
|
|
3241 NOTE: This takes advantage of the fact that
|
|
3242 FIELD2_TO_OFFICIAL_LEADING_BYTE and
|
|
3243 FIELD2_TO_PRIVATE_LEADING_BYTE are the same.
|
|
3244 */
|
826
|
3245 charset = charset_by_leading_byte (f2 + FIELD2_TO_OFFICIAL_LEADING_BYTE);
|
771
|
3246 if (EQ (charset, Qnil))
|
|
3247 return 0;
|
|
3248 /* check range as per size (94 or 96) of charset */
|
|
3249 return ((f3 > 0x20 && f3 < 0x7f) || XCHARSET_CHARS (charset) == 96);
|
|
3250 }
|
|
3251 else
|
|
3252 {
|
|
3253 /* dimension-2 char */
|
|
3254 Lisp_Object charset;
|
|
3255
|
|
3256 /* leading byte must be correct */
|
826
|
3257 if (f1 < MIN_EMCHAR_FIELD1_OFFICIAL ||
|
|
3258 (f1 > MAX_EMCHAR_FIELD1_OFFICIAL && f1 < MIN_EMCHAR_FIELD1_PRIVATE) ||
|
|
3259 f1 > MAX_EMCHAR_FIELD1_PRIVATE)
|
771
|
3260 return 0;
|
|
3261 /* octets not out of range */
|
|
3262 if (f2 < 0x20 || f3 < 0x20)
|
|
3263 return 0;
|
|
3264
|
|
3265 #ifdef ENABLE_COMPOSITE_CHARS
|
|
3266 if (f1 + FIELD1_TO_OFFICIAL_LEADING_BYTE == LEADING_BYTE_COMPOSITE)
|
|
3267 {
|
|
3268 if (UNBOUNDP (Fgethash (make_int (ch),
|
|
3269 Vcomposite_char_char2string_hash_table,
|
|
3270 Qunbound)))
|
|
3271 return 0;
|
|
3272 return 1;
|
|
3273 }
|
|
3274 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
3275
|
|
3276 /* charset exists */
|
826
|
3277 if (f1 <= MAX_EMCHAR_FIELD1_OFFICIAL)
|
771
|
3278 charset =
|
826
|
3279 charset_by_leading_byte (f1 + FIELD1_TO_OFFICIAL_LEADING_BYTE);
|
771
|
3280 else
|
|
3281 charset =
|
826
|
3282 charset_by_leading_byte (f1 + FIELD1_TO_PRIVATE_LEADING_BYTE);
|
771
|
3283
|
|
3284 if (EQ (charset, Qnil))
|
|
3285 return 0;
|
|
3286 /* check range as per size (94x94 or 96x96) of charset */
|
|
3287 return ((f2 != 0x20 && f2 != 0x7F && f3 != 0x20 && f3 != 0x7F) ||
|
|
3288 XCHARSET_CHARS (charset) == 96);
|
|
3289 }
|
|
3290 }
|
|
3291
|
|
3292 /* Copy the character pointed to by SRC into DST. Do not call this
|
826
|
3293 directly. Use the macro charptr_copy_emchar() instead.
|
771
|
3294 Return the number of bytes copied. */
|
|
3295
|
|
3296 Bytecount
|
826
|
3297 non_ascii_charptr_copy_emchar (const Intbyte *src, Intbyte *dst)
|
771
|
3298 {
|
826
|
3299 Bytecount bytes = rep_bytes_by_first_byte (*src);
|
771
|
3300 Bytecount i;
|
|
3301 for (i = bytes; i; i--, dst++, src++)
|
|
3302 *dst = *src;
|
|
3303 return bytes;
|
|
3304 }
|
|
3305
|
|
3306 #endif /* MULE */
|
|
3307
|
|
3308
|
|
3309 /************************************************************************/
|
|
3310 /* streams of Emchars */
|
|
3311 /************************************************************************/
|
|
3312
|
|
3313 #ifdef MULE
|
|
3314
|
|
3315 /* Treat a stream as a stream of Emchar's rather than a stream of bytes.
|
|
3316 The functions below are not meant to be called directly; use
|
|
3317 the macros in insdel.h. */
|
|
3318
|
|
3319 Emchar
|
|
3320 Lstream_get_emchar_1 (Lstream *stream, int ch)
|
|
3321 {
|
|
3322 Intbyte str[MAX_EMCHAR_LEN];
|
|
3323 Intbyte *strptr = str;
|
|
3324 Bytecount bytes;
|
|
3325
|
|
3326 str[0] = (Intbyte) ch;
|
|
3327
|
826
|
3328 for (bytes = rep_bytes_by_first_byte (ch) - 1; bytes; bytes--)
|
771
|
3329 {
|
|
3330 int c = Lstream_getc (stream);
|
800
|
3331 text_checking_assert (c >= 0);
|
771
|
3332 *++strptr = (Intbyte) c;
|
|
3333 }
|
|
3334 return charptr_emchar (str);
|
|
3335 }
|
|
3336
|
|
3337 int
|
|
3338 Lstream_fput_emchar (Lstream *stream, Emchar ch)
|
|
3339 {
|
|
3340 Intbyte str[MAX_EMCHAR_LEN];
|
|
3341 Bytecount len = set_charptr_emchar (str, ch);
|
|
3342 return Lstream_write (stream, str, len);
|
|
3343 }
|
|
3344
|
|
3345 void
|
|
3346 Lstream_funget_emchar (Lstream *stream, Emchar ch)
|
|
3347 {
|
|
3348 Intbyte str[MAX_EMCHAR_LEN];
|
|
3349 Bytecount len = set_charptr_emchar (str, ch);
|
|
3350 Lstream_unread (stream, str, len);
|
|
3351 }
|
|
3352
|
|
3353 #endif /* MULE */
|
|
3354
|
|
3355
|
|
3356 /************************************************************************/
|
|
3357 /* Lisp primitives for working with characters */
|
|
3358 /************************************************************************/
|
|
3359
|
|
3360 DEFUN ("make-char", Fmake_char, 2, 3, 0, /*
|
|
3361 Make a character from CHARSET and octets ARG1 and ARG2.
|
|
3362 ARG2 is required only for characters from two-dimensional charsets.
|
|
3363
|
|
3364 Each octet should be in the range 32 through 127 for a 96 or 96x96
|
|
3365 charset and 33 through 126 for a 94 or 94x94 charset. (Most charsets
|
|
3366 are either 96 or 94x94.) Note that this is 32 more than the values
|
|
3367 typically given for 94x94 charsets. When two octets are required, the
|
|
3368 order is "standard" -- the same as appears in ISO-2022 encodings,
|
|
3369 reference tables, etc.
|
|
3370
|
|
3371 \(Note the following non-obvious result: Computerized translation
|
|
3372 tables often encode the two octets as the high and low bytes,
|
|
3373 respectively, of a hex short, while when there's only one octet, it
|
|
3374 goes in the low byte. When decoding such a value, you need to treat
|
|
3375 the two cases differently when calling make-char: One is (make-char
|
|
3376 CHARSET HIGH LOW), the other is (make-char CHARSET LOW).)
|
|
3377
|
|
3378 For example, (make-char 'latin-iso8859-2 185) or (make-char
|
|
3379 'latin-iso8859-2 57) will return the Latin 2 character s with caron.
|
|
3380
|
|
3381 As another example, the Japanese character for "kawa" (stream), which
|
|
3382 looks something like this:
|
|
3383
|
|
3384 | |
|
|
3385 | | |
|
|
3386 | | |
|
|
3387 | | |
|
|
3388 / |
|
|
3389
|
|
3390 appears in the Unicode Standard (version 2.0) on page 7-287 with the
|
|
3391 following values (see also page 7-4):
|
|
3392
|
|
3393 U 5DDD (Unicode)
|
|
3394 G 0-2008 (GB 2312-80)
|
|
3395 J 0-3278 (JIS X 0208-1990)
|
|
3396 K 0-8425 (KS C 5601-1987)
|
|
3397 B A474 (Big Five)
|
|
3398 C 1-4455 (CNS 11643-1986 (1st plane))
|
|
3399 A 213C34 (ANSI Z39.64-1989)
|
|
3400
|
|
3401 These are equivalent to:
|
|
3402
|
|
3403 \(make-char 'chinese-gb2312 52 40)
|
|
3404 \(make-char 'japanese-jisx0208 64 110)
|
|
3405 \(make-char 'korean-ksc5601 116 57)
|
|
3406 \(make-char 'chinese-cns11643-1 76 87)
|
|
3407 \(decode-big5-char '(164 . 116))
|
|
3408
|
|
3409 \(All codes above are two decimal numbers except for Big Five and ANSI
|
|
3410 Z39.64, which we don't support. We add 32 to each of the decimal
|
|
3411 numbers. Big Five is split in a rather hackish fashion into two
|
|
3412 charsets, `big5-1' and `big5-2', due to its excessive size -- 94x157,
|
|
3413 with the first codepoint in the range 0xA1 to 0xFE and the second in
|
|
3414 the range 0x40 to 0x7E or 0xA1 to 0xFE. `decode-big5-char' is used to
|
|
3415 generate the char from its codes, and `encode-big5-char' extracts the
|
|
3416 codes.)
|
|
3417
|
|
3418 When compiled without MULE, this function does not do much, but it's
|
|
3419 provided for compatibility. In this case, the following CHARSET symbols
|
|
3420 are allowed:
|
|
3421
|
|
3422 `ascii' -- ARG1 should be in the range 0 through 127.
|
|
3423 `control-1' -- ARG1 should be in the range 128 through 159.
|
|
3424 else -- ARG1 is coerced to be between 0 and 255, and then the high
|
|
3425 bit is set.
|
|
3426
|
|
3427 `int-to-char of the resulting ARG1' is returned, and ARG2 is always ignored.
|
|
3428 */
|
|
3429 (charset, arg1, arg2))
|
|
3430 {
|
|
3431 #ifdef MULE
|
|
3432 Lisp_Charset *cs;
|
|
3433 int a1, a2;
|
|
3434 int lowlim, highlim;
|
|
3435
|
|
3436 charset = Fget_charset (charset);
|
|
3437 cs = XCHARSET (charset);
|
|
3438
|
788
|
3439 get_charset_limits (charset, &lowlim, &highlim);
|
771
|
3440
|
|
3441 CHECK_INT (arg1);
|
|
3442 /* It is useful (and safe, according to Olivier Galibert) to strip
|
|
3443 the 8th bit off ARG1 and ARG2 because it allows programmers to
|
|
3444 write (make-char 'latin-iso8859-2 CODE) where code is the actual
|
|
3445 Latin 2 code of the character. */
|
|
3446 a1 = XINT (arg1) & 0x7f;
|
|
3447 if (a1 < lowlim || a1 > highlim)
|
|
3448 args_out_of_range_3 (arg1, make_int (lowlim), make_int (highlim));
|
|
3449
|
|
3450 if (CHARSET_DIMENSION (cs) == 1)
|
|
3451 {
|
|
3452 if (!NILP (arg2))
|
|
3453 invalid_argument
|
|
3454 ("Charset is of dimension one; second octet must be nil", arg2);
|
826
|
3455 return make_char (make_emchar (charset, a1, 0));
|
771
|
3456 }
|
|
3457
|
|
3458 CHECK_INT (arg2);
|
|
3459 a2 = XINT (arg2) & 0x7f;
|
|
3460 if (a2 < lowlim || a2 > highlim)
|
|
3461 args_out_of_range_3 (arg2, make_int (lowlim), make_int (highlim));
|
|
3462
|
826
|
3463 return make_char (make_emchar (charset, a1, a2));
|
771
|
3464 #else
|
|
3465 int a1;
|
|
3466 int lowlim, highlim;
|
|
3467
|
|
3468 if (EQ (charset, Qascii)) lowlim = 0, highlim = 127;
|
|
3469 else if (EQ (charset, Qcontrol_1)) lowlim = 0, highlim = 31;
|
|
3470 else lowlim = 0, highlim = 127;
|
|
3471
|
|
3472 CHECK_INT (arg1);
|
|
3473 /* It is useful (and safe, according to Olivier Galibert) to strip
|
|
3474 the 8th bit off ARG1 and ARG2 because it allows programmers to
|
|
3475 write (make-char 'latin-iso8859-2 CODE) where code is the actual
|
|
3476 Latin 2 code of the character. */
|
|
3477 a1 = XINT (arg1) & 0x7f;
|
|
3478 if (a1 < lowlim || a1 > highlim)
|
|
3479 args_out_of_range_3 (arg1, make_int (lowlim), make_int (highlim));
|
|
3480
|
|
3481 if (EQ (charset, Qascii))
|
|
3482 return make_char (a1);
|
|
3483 return make_char (a1 + 128);
|
|
3484 #endif /* MULE */
|
|
3485 }
|
|
3486
|
|
3487 #ifdef MULE
|
|
3488
|
|
3489 DEFUN ("char-charset", Fchar_charset, 1, 1, 0, /*
|
|
3490 Return the character set of char CH.
|
|
3491 */
|
|
3492 (ch))
|
|
3493 {
|
|
3494 CHECK_CHAR_COERCE_INT (ch);
|
|
3495
|
826
|
3496 return XCHARSET_NAME (charset_by_leading_byte
|
|
3497 (emchar_leading_byte (XCHAR (ch))));
|
771
|
3498 }
|
|
3499
|
|
3500 DEFUN ("char-octet", Fchar_octet, 1, 2, 0, /*
|
|
3501 Return the octet numbered N (should be 0 or 1) of char CH.
|
|
3502 N defaults to 0 if omitted.
|
|
3503 */
|
|
3504 (ch, n))
|
|
3505 {
|
|
3506 Lisp_Object charset;
|
|
3507 int octet0, octet1;
|
|
3508
|
|
3509 CHECK_CHAR_COERCE_INT (ch);
|
|
3510
|
826
|
3511 BREAKUP_EMCHAR (XCHAR (ch), charset, octet0, octet1);
|
771
|
3512
|
|
3513 if (NILP (n) || EQ (n, Qzero))
|
|
3514 return make_int (octet0);
|
|
3515 else if (EQ (n, make_int (1)))
|
|
3516 return make_int (octet1);
|
|
3517 else
|
|
3518 invalid_constant ("Octet number must be 0 or 1", n);
|
|
3519 }
|
|
3520
|
|
3521 DEFUN ("split-char", Fsplit_char, 1, 1, 0, /*
|
|
3522 Return list of charset and one or two position-codes of CHAR.
|
|
3523 */
|
|
3524 (character))
|
|
3525 {
|
|
3526 /* This function can GC */
|
|
3527 struct gcpro gcpro1, gcpro2;
|
|
3528 Lisp_Object charset = Qnil;
|
|
3529 Lisp_Object rc = Qnil;
|
|
3530 int c1, c2;
|
|
3531
|
|
3532 GCPRO2 (charset, rc);
|
|
3533 CHECK_CHAR_COERCE_INT (character);
|
|
3534
|
826
|
3535 BREAKUP_EMCHAR (XCHAR (character), charset, c1, c2);
|
771
|
3536
|
|
3537 if (XCHARSET_DIMENSION (Fget_charset (charset)) == 2)
|
|
3538 {
|
|
3539 rc = list3 (XCHARSET_NAME (charset), make_int (c1), make_int (c2));
|
|
3540 }
|
|
3541 else
|
|
3542 {
|
|
3543 rc = list2 (XCHARSET_NAME (charset), make_int (c1));
|
|
3544 }
|
|
3545 UNGCPRO;
|
|
3546
|
|
3547 return rc;
|
|
3548 }
|
|
3549
|
|
3550 #endif /* MULE */
|
|
3551
|
|
3552
|
|
3553 /************************************************************************/
|
|
3554 /* composite character functions */
|
|
3555 /************************************************************************/
|
|
3556
|
|
3557 #ifdef ENABLE_COMPOSITE_CHARS
|
|
3558
|
|
3559 Emchar
|
|
3560 lookup_composite_char (Intbyte *str, int len)
|
|
3561 {
|
|
3562 Lisp_Object lispstr = make_string (str, len);
|
|
3563 Lisp_Object ch = Fgethash (lispstr,
|
|
3564 Vcomposite_char_string2char_hash_table,
|
|
3565 Qunbound);
|
|
3566 Emchar emch;
|
|
3567
|
|
3568 if (UNBOUNDP (ch))
|
|
3569 {
|
|
3570 if (composite_char_row_next >= 128)
|
|
3571 invalid_operation ("No more composite chars available", lispstr);
|
826
|
3572 emch = make_emchar (Vcharset_composite, composite_char_row_next,
|
771
|
3573 composite_char_col_next);
|
|
3574 Fputhash (make_char (emch), lispstr,
|
|
3575 Vcomposite_char_char2string_hash_table);
|
|
3576 Fputhash (lispstr, make_char (emch),
|
|
3577 Vcomposite_char_string2char_hash_table);
|
|
3578 composite_char_col_next++;
|
|
3579 if (composite_char_col_next >= 128)
|
|
3580 {
|
|
3581 composite_char_col_next = 32;
|
|
3582 composite_char_row_next++;
|
|
3583 }
|
|
3584 }
|
|
3585 else
|
|
3586 emch = XCHAR (ch);
|
|
3587 return emch;
|
|
3588 }
|
|
3589
|
|
3590 Lisp_Object
|
|
3591 composite_char_string (Emchar ch)
|
|
3592 {
|
|
3593 Lisp_Object str = Fgethash (make_char (ch),
|
|
3594 Vcomposite_char_char2string_hash_table,
|
|
3595 Qunbound);
|
|
3596 assert (!UNBOUNDP (str));
|
|
3597 return str;
|
|
3598 }
|
|
3599
|
826
|
3600 DEFUN ("make-composite-char", Fmake_composite_char, 1, 1, 0, /*
|
771
|
3601 Convert a string into a single composite character.
|
|
3602 The character is the result of overstriking all the characters in
|
|
3603 the string.
|
|
3604 */
|
|
3605 (string))
|
|
3606 {
|
|
3607 CHECK_STRING (string);
|
|
3608 return make_char (lookup_composite_char (XSTRING_DATA (string),
|
|
3609 XSTRING_LENGTH (string)));
|
|
3610 }
|
|
3611
|
826
|
3612 DEFUN ("composite-char-string", Fcomposite_char_string, 1, 1, 0, /*
|
771
|
3613 Return a string of the characters comprising a composite character.
|
|
3614 */
|
|
3615 (ch))
|
|
3616 {
|
|
3617 Emchar emch;
|
|
3618
|
|
3619 CHECK_CHAR (ch);
|
|
3620 emch = XCHAR (ch);
|
826
|
3621 if (emchar_leading_byte (emch) != LEADING_BYTE_COMPOSITE)
|
771
|
3622 invalid_argument ("Must be composite char", ch);
|
|
3623 return composite_char_string (emch);
|
|
3624 }
|
|
3625 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
3626
|
|
3627
|
|
3628 /************************************************************************/
|
|
3629 /* initialization */
|
|
3630 /************************************************************************/
|
|
3631
|
|
3632 void
|
814
|
3633 reinit_eistring_once_early (void)
|
771
|
3634 {
|
|
3635 the_eistring_malloc_zero_init = the_eistring_zero_init;
|
|
3636 the_eistring_malloc_zero_init.mallocp_ = 1;
|
|
3637 }
|
|
3638
|
|
3639 void
|
814
|
3640 init_eistring_once_early (void)
|
|
3641 {
|
|
3642 reinit_eistring_once_early ();
|
|
3643 }
|
|
3644
|
|
3645 void
|
771
|
3646 syms_of_text (void)
|
|
3647 {
|
|
3648 DEFSUBR (Fmake_char);
|
|
3649
|
|
3650 #ifdef MULE
|
|
3651 DEFSUBR (Fchar_charset);
|
|
3652 DEFSUBR (Fchar_octet);
|
|
3653 DEFSUBR (Fsplit_char);
|
|
3654
|
|
3655 #ifdef ENABLE_COMPOSITE_CHARS
|
|
3656 DEFSUBR (Fmake_composite_char);
|
|
3657 DEFSUBR (Fcomposite_char_string);
|
|
3658 #endif
|
|
3659 #endif /* MULE */
|
|
3660 }
|
|
3661
|
|
3662 void
|
|
3663 reinit_vars_of_text (void)
|
|
3664 {
|
|
3665 int i;
|
|
3666
|
|
3667 conversion_in_dynarr_list = Dynarr_new2 (Intbyte_dynarr_dynarr,
|
|
3668 Intbyte_dynarr *);
|
|
3669 conversion_out_dynarr_list = Dynarr_new2 (Extbyte_dynarr_dynarr,
|
|
3670 Extbyte_dynarr *);
|
|
3671
|
|
3672 /* #### Olivier, why does this need to be reinitted? */
|
|
3673 for (i = 0; i <= MAX_BYTEBPOS_GAP_SIZE_3; i++)
|
|
3674 three_to_one_table[i] = i / 3;
|
|
3675 }
|
|
3676
|
|
3677 void
|
|
3678 vars_of_text (void)
|
|
3679 {
|
|
3680 reinit_vars_of_text ();
|
|
3681
|
|
3682 #ifdef ENABLE_COMPOSITE_CHARS
|
|
3683 /* #### not dumped properly */
|
|
3684 composite_char_row_next = 32;
|
|
3685 composite_char_col_next = 32;
|
|
3686
|
|
3687 Vcomposite_char_string2char_hash_table =
|
|
3688 make_lisp_hash_table (500, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL);
|
|
3689 Vcomposite_char_char2string_hash_table =
|
|
3690 make_lisp_hash_table (500, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
|
|
3691 staticpro (&Vcomposite_char_string2char_hash_table);
|
|
3692 staticpro (&Vcomposite_char_char2string_hash_table);
|
|
3693 #endif /* ENABLE_COMPOSITE_CHARS */
|
|
3694 }
|