Mercurial > hg > xemacs-beta
annotate src/unicode.c @ 5338:8608eadee6ba
Move #'delq, #'delete to Lisp, adding support for sequences.
src/ChangeLog addition:
2011-01-11 Aidan Kehoe <kehoea@parhasard.net>
* device-msw.c (Fmswindows_printer_list): Remove a Fdelete ()
call here, remove the necessity for it.
* fns.c (Fdelete, Fdelq):
* lisp.h:
Move #'delete, #'delq to Lisp, implemented in terms of #'delete*
* select.c (Fown_selection_internal):
* select.c (handle_selection_clear):
Use delq_no_quit() in these functions, don't reimplement it or use
Fdelq(), which is now gone.
lisp/ChangeLog addition:
2011-01-11 Aidan Kehoe <kehoea@parhasard.net>
* subr.el (delete, delq, remove, remq): Move #'remove, #'remq
here, they don't belong in cl-seq.el; move #'delete, #'delq here
from fns.c, implement them in terms of #'delete*, allowing support
for sequences generally.
* update-elc.el (do-autoload-commands): Use #'delete*, not #'delq
here, now the latter's no longer dumped.
* cl-macs.el (delete, delq): Add compiler macros transforming
#'delete and #'delq to #'delete* calls.
| author | Aidan Kehoe <kehoea@parhasard.net> |
|---|---|
| date | Fri, 14 Jan 2011 23:35:29 +0000 |
| parents | c096d8051f89 |
| children | db326b8fe982 8d29f1c4bb98 |
| rev | line source |
|---|---|
| 771 | 1 /* Code to handle Unicode conversion. |
|
4834
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
2 Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2010 Ben Wing. |
| 771 | 3 |
| 4 This file is part of XEmacs. | |
| 5 | |
| 6 XEmacs is free software; you can redistribute it and/or modify it | |
| 7 under the terms of the GNU General Public License as published by the | |
| 8 Free Software Foundation; either version 2, or (at your option) any | |
| 9 later version. | |
| 10 | |
| 11 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
| 12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
| 13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
| 14 for more details. | |
| 15 | |
| 16 You should have received a copy of the GNU General Public License | |
| 17 along with XEmacs; see the file COPYING. If not, write to | |
| 18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
| 19 Boston, MA 02111-1307, USA. */ | |
| 20 | |
| 21 /* Synched up with: FSF 20.3. Not in FSF. */ | |
| 22 | |
| 23 /* Authorship: | |
| 24 | |
| 25 Current primary author: Ben Wing <ben@xemacs.org> | |
| 26 | |
| 27 Written by Ben Wing <ben@xemacs.org>, June, 2001. | |
| 28 Separated out into this file, August, 2001. | |
| 29 Includes Unicode coding systems, some parts of which have been written | |
| 877 | 30 by someone else. #### Morioka and Hayashi, I think. |
| 771 | 31 |
| 32 As of September 2001, the detection code is here and abstraction of the | |
| 877 | 33 detection system is finished. The unicode detectors have been rewritten |
| 771 | 34 to include multiple levels of likelihood. |
| 35 */ | |
| 36 | |
| 37 #include <config.h> | |
| 38 #include "lisp.h" | |
| 39 | |
| 40 #include "charset.h" | |
| 41 #include "file-coding.h" | |
| 42 #include "opaque.h" | |
| 43 | |
|
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
44 #include "buffer.h" |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
45 #include "rangetab.h" |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
46 #include "extents.h" |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
47 |
| 771 | 48 #include "sysfile.h" |
| 49 | |
| 2367 | 50 /* For more info about how Unicode works under Windows, see intl-win32.c. */ |
| 51 | |
| 52 /* Info about Unicode translation tables [ben]: | |
| 53 | |
| 54 FORMAT: | |
| 55 ------- | |
| 56 | |
| 57 We currently use the following format for tables: | |
| 58 | |
| 59 If dimension == 1, to_unicode_table is a 96-element array of ints | |
| 60 (Unicode code points); else, it's a 96-element array of int * pointers, | |
| 61 each of which points to a 96-element array of ints. If no elements in a | |
| 62 row have been filled in, the pointer will point to a default empty | |
| 63 table; that way, memory usage is more reasonable but lookup still fast. | |
| 64 | |
| 65 -- If from_unicode_levels == 1, from_unicode_table is a 256-element | |
| 66 array of shorts (octet 1 in high byte, octet 2 in low byte; we don't | |
| 67 store Ichars directly to save space). | |
| 68 | |
| 69 -- If from_unicode_levels == 2, from_unicode_table is a 256-element | |
| 70 array of short * pointers, each of which points to a 256-element array | |
| 71 of shorts. | |
| 72 | |
| 73 -- If from_unicode_levels == 3, from_unicode_table is a 256-element | |
| 74 array of short ** pointers, each of which points to a 256-element array | |
| 75 of short * pointers, each of which points to a 256-element array of | |
| 76 shorts. | |
| 77 | |
| 78 -- If from_unicode_levels == 4, same thing but one level deeper. | |
| 79 | |
| 80 Just as for to_unicode_table, we use default tables to fill in all | |
| 81 entries with no values in them. | |
| 82 | |
| 83 #### An obvious space-saving optimization is to use variable-sized | |
| 84 tables, where each table instead of just being a 256-element array, is a | |
| 85 structure with a start value, an end value, and a variable number of | |
| 86 entries (END - START + 1). Only 8 bits are needed for END and START, | |
| 87 and could be stored at the end to avoid alignment problems. However, | |
| 88 before charging off and implementing this, we need to consider whether | |
| 89 it's worth it: | |
| 90 | |
| 91 (1) Most tables will be highly localized in which code points are | |
| 92 defined, heavily reducing the possible memory waste. Before doing any | |
| 93 rewriting, write some code to see how much memory is actually being | |
| 94 wasted (i.e. ratio of empty entries to total # of entries) and only | |
| 95 start rewriting if it's unacceptably high. You have to check over all | |
| 96 charsets. | |
| 97 | |
| 98 (2) Since entries are usually added one at a time, you have to be very | |
| 99 careful when creating the tables to avoid realloc()/free() thrashing in | |
| 100 the common case when you are in an area of high localization and are | |
| 101 going to end up using most entries in the table. You'd certainly want | |
| 102 to allow only certain sizes, not arbitrary ones (probably powers of 2, | |
| 103 where you want the entire block including the START/END values to fit | |
| 104 into a power of 2, minus any malloc overhead if there is any -- there's | |
| 105 none under gmalloc.c, and probably most system malloc() functions are | |
| 106 quite smart nowadays and also have no overhead). You could optimize | |
| 107 somewhat during the in-C initializations, because you can compute the | |
| 108 actual usage of various tables by scanning the entries you're going to | |
| 109 add in a separate pass before adding them. (You could actually do the | |
| 110 same thing when entries are added on the Lisp level by making the | |
| 111 assumption that all the entries will come in one after another before | |
| 112 any use is made of the data. So as they're coming in, you just store | |
| 113 them in a big long list, and the first time you need to retrieve an | |
| 114 entry, you compute the whole table at once.) You'd still have to deal | |
| 115 with the possibility of later entries coming in, though. | |
| 116 | |
| 117 (3) You do lose some speed using START/END values, since you need a | |
| 118 couple of comparisons at each level. This could easily make each single | |
| 119 lookup become 3-4 times slower. The Unicode book considers this a big | |
| 120 issue, and recommends against variable-sized tables for this reason; | |
| 121 however, they almost certainly have in mind applications that primarily | |
| 122 involve conversion of large amounts of data. Most Unicode strings that | |
| 123 are translated in XEmacs are fairly small. The only place where this | |
| 124 might matter is in loading large files -- e.g. a 3-megabyte | |
| 125 Unicode-encoded file. So think about this, and maybe do a trial | |
| 126 implementation where you don't worry too much about the intricacies of | |
| 127 (2) and just implement some basic "multiply by 1.5" trick or something | |
| 128 to do the resizing. There is a very good FAQ on Unicode called | |
| 129 something like the Linux-Unicode How-To (it should be part of the Linux | |
| 130 How-To's, I think), that lists the url of a guy with a whole bunch of | |
| 131 unicode files you can use to stress-test your implementations, and he's | |
| 132 highly likely to have a good multi-megabyte Unicode-encoded file (with | |
| 133 normal text in it -- if you created your own just by creating repeated | |
| 134 strings of letters and numbers, you probably wouldn't get accurate | |
| 135 results). | |
| 136 | |
| 137 INITIALIZATION: | |
| 138 --------------- | |
| 139 | |
| 140 There are advantages and disadvantages to loading the tables at | |
| 141 run-time. | |
| 142 | |
| 143 Advantages: | |
| 144 | |
| 145 They're big, and it's very fast to recreate them (a fraction of a second | |
| 146 on modern processors). | |
| 147 | |
| 148 Disadvantages: | |
| 149 | |
| 150 (1) User-defined charsets: It would be inconvenient to require all | |
| 151 dumped user-defined charsets to be reloaded at init time. | |
| 152 | |
| 153 NB With run-time loading, we load in init-mule-at-startup, in | |
| 154 mule-cmds.el. This is called from startup.el, which is quite late in | |
| 155 the initialization process -- but data-directory isn't set until then. | |
| 156 With dump-time loading, you still can't dump in a Japanese directory | |
| 157 (again, until we move to Unicode internally), but this is not such an | |
| 158 imposition. | |
| 159 | |
| 160 | |
| 161 */ | |
| 162 | |
| 771 | 163 /* #### WARNING! The current sledgehammer routines have a fundamental |
| 164 problem in that they can't handle two characters mapping to a | |
| 165 single Unicode codepoint or vice-versa in a single charset table. | |
| 166 It's not clear there is any way to handle this and still make the | |
| 877 | 167 sledgehammer routines useful. |
| 168 | |
| 169 Inquiring Minds Want To Know Dept: does the above WARNING mean that | |
| 170 _if_ it happens, then it will signal error, or then it will do | |
| 171 something evil and unpredictable? Signaling an error is OK: for | |
| 172 all national standards, the national to Unicode map is an inclusion | |
| 173 (1-to-1). Any character set that does not behave that way is | |
| 1318 | 174 broken according to the Unicode standard. |
| 175 | |
| 2500 | 176 Answer: You will get an ABORT(), since the purpose of the sledgehammer |
| 1318 | 177 routines is self-checking. The above problem with non-1-to-1 mapping |
| 178 occurs in the Big5 tables, as provided by the Unicode Consortium. */ | |
| 877 | 179 |
| 771 | 180 /* #define SLEDGEHAMMER_CHECK_UNICODE */ |
| 181 | |
| 182 /* When MULE is not defined, we may still need some Unicode support -- | |
| 183 in particular, some Windows API's always want Unicode, and the way | |
| 184 we've set up the Unicode encapsulation, we may as well go ahead and | |
| 185 always use the Unicode versions of split API's. (It would be | |
| 186 trickier to not use them, and pointless -- under NT, the ANSI API's | |
| 187 call the Unicode ones anyway, so in the case of structures, we'd be | |
| 188 converting from Unicode to ANSI structures, only to have the OS | |
| 189 convert them back.) */ | |
| 190 | |
| 191 Lisp_Object Qunicode; | |
| 4096 | 192 Lisp_Object Qutf_16, Qutf_8, Qucs_4, Qutf_7, Qutf_32; |
| 771 | 193 Lisp_Object Qneed_bom; |
| 194 | |
| 195 Lisp_Object Qutf_16_little_endian, Qutf_16_bom; | |
| 196 Lisp_Object Qutf_16_little_endian_bom; | |
| 197 | |
| 985 | 198 Lisp_Object Qutf_8_bom; |
| 199 | |
|
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
200 #ifdef MULE |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
201 /* These range tables are not directly accessible from Lisp: */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
202 static Lisp_Object Vunicode_invalid_and_query_skip_chars; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
203 static Lisp_Object Vutf_8_invalid_and_query_skip_chars; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
204 static Lisp_Object Vunicode_query_skip_chars; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
205 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
206 static Lisp_Object Vunicode_query_string, Vunicode_invalid_string, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
207 Vutf_8_invalid_string; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
208 #endif /* MULE */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
209 |
| 3952 | 210 /* See the Unicode FAQ, http://www.unicode.org/faq/utf_bom.html#35 for this |
| 211 algorithm. | |
| 212 | |
| 213 (They also give another, really verbose one, as part of their explanation | |
| 214 of the various planes of the encoding, but we won't use that.) */ | |
| 215 | |
| 216 #define UTF_16_LEAD_OFFSET (0xD800 - (0x10000 >> 10)) | |
| 217 #define UTF_16_SURROGATE_OFFSET (0x10000 - (0xD800 << 10) - 0xDC00) | |
| 218 | |
| 219 #define utf_16_surrogates_to_code(lead, trail) \ | |
| 220 (((lead) << 10) + (trail) + UTF_16_SURROGATE_OFFSET) | |
| 221 | |
| 222 #define CODE_TO_UTF_16_SURROGATES(codepoint, lead, trail) do { \ | |
| 223 int __ctu16s_code = (codepoint); \ | |
| 224 lead = UTF_16_LEAD_OFFSET + (__ctu16s_code >> 10); \ | |
| 225 trail = 0xDC00 + (__ctu16s_code & 0x3FF); \ | |
| 226 } while (0) | |
| 227 | |
| 771 | 228 #ifdef MULE |
| 229 | |
| 3352 | 230 /* Using ints for to_unicode is OK (as long as they are >= 32 bits). |
| 231 In from_unicode, we're converting from Mule characters, which means | |
| 232 that the values being converted to are only 96x96, and we can save | |
| 233 space by using shorts (signedness doesn't matter). */ | |
| 771 | 234 static int *to_unicode_blank_1; |
| 235 static int **to_unicode_blank_2; | |
| 236 | |
| 237 static short *from_unicode_blank_1; | |
| 238 static short **from_unicode_blank_2; | |
| 239 static short ***from_unicode_blank_3; | |
| 240 static short ****from_unicode_blank_4; | |
| 241 | |
| 1204 | 242 static const struct memory_description to_unicode_level_0_desc_1[] = { |
| 771 | 243 { XD_END } |
| 244 }; | |
| 245 | |
| 1204 | 246 static const struct sized_memory_description to_unicode_level_0_desc = { |
| 247 sizeof (int), to_unicode_level_0_desc_1 | |
| 771 | 248 }; |
| 249 | |
| 1204 | 250 static const struct memory_description to_unicode_level_1_desc_1[] = { |
| 2551 | 251 { XD_BLOCK_PTR, 0, 96, { &to_unicode_level_0_desc } }, |
| 771 | 252 { XD_END } |
| 253 }; | |
| 254 | |
| 1204 | 255 static const struct sized_memory_description to_unicode_level_1_desc = { |
| 256 sizeof (void *), to_unicode_level_1_desc_1 | |
| 771 | 257 }; |
| 258 | |
| 1204 | 259 static const struct memory_description to_unicode_description_1[] = { |
| 2551 | 260 { XD_BLOCK_PTR, 1, 96, { &to_unicode_level_0_desc } }, |
| 261 { XD_BLOCK_PTR, 2, 96, { &to_unicode_level_1_desc } }, | |
| 771 | 262 { XD_END } |
| 263 }; | |
| 264 | |
| 265 /* Not static because each charset has a set of to and from tables and | |
| 266 needs to describe them to pdump. */ | |
| 1204 | 267 const struct sized_memory_description to_unicode_description = { |
| 268 sizeof (void *), to_unicode_description_1 | |
| 269 }; | |
| 270 | |
| 2367 | 271 /* Used only for to_unicode_blank_2 */ |
| 272 static const struct memory_description to_unicode_level_2_desc_1[] = { | |
| 2551 | 273 { XD_BLOCK_PTR, 0, 96, { &to_unicode_level_1_desc } }, |
| 2367 | 274 { XD_END } |
| 275 }; | |
| 276 | |
| 1204 | 277 static const struct memory_description from_unicode_level_0_desc_1[] = { |
| 771 | 278 { XD_END } |
| 279 }; | |
| 280 | |
| 1204 | 281 static const struct sized_memory_description from_unicode_level_0_desc = { |
| 282 sizeof (short), from_unicode_level_0_desc_1 | |
| 771 | 283 }; |
| 284 | |
| 1204 | 285 static const struct memory_description from_unicode_level_1_desc_1[] = { |
| 2551 | 286 { XD_BLOCK_PTR, 0, 256, { &from_unicode_level_0_desc } }, |
| 771 | 287 { XD_END } |
| 288 }; | |
| 289 | |
| 1204 | 290 static const struct sized_memory_description from_unicode_level_1_desc = { |
| 291 sizeof (void *), from_unicode_level_1_desc_1 | |
| 771 | 292 }; |
| 293 | |
| 1204 | 294 static const struct memory_description from_unicode_level_2_desc_1[] = { |
| 2551 | 295 { XD_BLOCK_PTR, 0, 256, { &from_unicode_level_1_desc } }, |
| 771 | 296 { XD_END } |
| 297 }; | |
| 298 | |
| 1204 | 299 static const struct sized_memory_description from_unicode_level_2_desc = { |
| 300 sizeof (void *), from_unicode_level_2_desc_1 | |
| 771 | 301 }; |
| 302 | |
| 1204 | 303 static const struct memory_description from_unicode_level_3_desc_1[] = { |
| 2551 | 304 { XD_BLOCK_PTR, 0, 256, { &from_unicode_level_2_desc } }, |
| 771 | 305 { XD_END } |
| 306 }; | |
| 307 | |
| 1204 | 308 static const struct sized_memory_description from_unicode_level_3_desc = { |
| 309 sizeof (void *), from_unicode_level_3_desc_1 | |
| 771 | 310 }; |
| 311 | |
| 1204 | 312 static const struct memory_description from_unicode_description_1[] = { |
| 2551 | 313 { XD_BLOCK_PTR, 1, 256, { &from_unicode_level_0_desc } }, |
| 314 { XD_BLOCK_PTR, 2, 256, { &from_unicode_level_1_desc } }, | |
| 315 { XD_BLOCK_PTR, 3, 256, { &from_unicode_level_2_desc } }, | |
| 316 { XD_BLOCK_PTR, 4, 256, { &from_unicode_level_3_desc } }, | |
| 771 | 317 { XD_END } |
| 318 }; | |
| 319 | |
| 320 /* Not static because each charset has a set of to and from tables and | |
| 321 needs to describe them to pdump. */ | |
| 1204 | 322 const struct sized_memory_description from_unicode_description = { |
| 323 sizeof (void *), from_unicode_description_1 | |
| 771 | 324 }; |
| 325 | |
| 2367 | 326 /* Used only for from_unicode_blank_4 */ |
| 327 static const struct memory_description from_unicode_level_4_desc_1[] = { | |
| 2551 | 328 { XD_BLOCK_PTR, 0, 256, { &from_unicode_level_3_desc } }, |
| 2367 | 329 { XD_END } |
| 330 }; | |
| 331 | |
| 771 | 332 static Lisp_Object_dynarr *unicode_precedence_dynarr; |
| 333 | |
| 1204 | 334 static const struct memory_description lod_description_1[] = { |
| 335 XD_DYNARR_DESC (Lisp_Object_dynarr, &lisp_object_description), | |
| 771 | 336 { XD_END } |
| 337 }; | |
| 338 | |
| 1204 | 339 static const struct sized_memory_description lisp_object_dynarr_description = { |
| 771 | 340 sizeof (Lisp_Object_dynarr), |
| 341 lod_description_1 | |
| 342 }; | |
| 343 | |
| 344 Lisp_Object Vlanguage_unicode_precedence_list; | |
| 345 Lisp_Object Vdefault_unicode_precedence_list; | |
| 346 | |
| 347 Lisp_Object Qignore_first_column; | |
| 348 | |
| 3439 | 349 Lisp_Object Vcurrent_jit_charset; |
| 350 Lisp_Object Qlast_allocated_character; | |
| 351 Lisp_Object Qccl_encode_to_ucs_2; | |
| 352 | |
| 4268 | 353 Lisp_Object Vnumber_of_jit_charsets; |
| 354 Lisp_Object Vlast_jit_charset_final; | |
| 355 Lisp_Object Vcharset_descr; | |
| 356 | |
| 357 | |
| 771 | 358 |
| 359 /************************************************************************/ | |
| 360 /* Unicode implementation */ | |
| 361 /************************************************************************/ | |
| 362 | |
| 363 #define BREAKUP_UNICODE_CODE(val, u1, u2, u3, u4, levels) \ | |
| 364 do { \ | |
| 365 int buc_val = (val); \ | |
| 366 \ | |
| 367 (u1) = buc_val >> 24; \ | |
| 368 (u2) = (buc_val >> 16) & 255; \ | |
| 369 (u3) = (buc_val >> 8) & 255; \ | |
| 370 (u4) = buc_val & 255; \ | |
| 371 (levels) = (buc_val <= 0xFF ? 1 : \ | |
| 372 buc_val <= 0xFFFF ? 2 : \ | |
| 373 buc_val <= 0xFFFFFF ? 3 : \ | |
| 374 4); \ | |
| 375 } while (0) | |
| 376 | |
| 377 static void | |
| 378 init_blank_unicode_tables (void) | |
| 379 { | |
| 380 int i; | |
| 381 | |
| 382 from_unicode_blank_1 = xnew_array (short, 256); | |
| 383 from_unicode_blank_2 = xnew_array (short *, 256); | |
| 384 from_unicode_blank_3 = xnew_array (short **, 256); | |
| 385 from_unicode_blank_4 = xnew_array (short ***, 256); | |
| 386 for (i = 0; i < 256; i++) | |
| 387 { | |
| 877 | 388 /* #### IMWTK: Why does using -1 here work? Simply because there are |
| 1318 | 389 no existing 96x96 charsets? |
| 390 | |
| 391 Answer: I don't understand the concern. -1 indicates there is no | |
| 392 entry for this particular codepoint, which is always the case for | |
| 393 blank tables. */ | |
| 771 | 394 from_unicode_blank_1[i] = (short) -1; |
| 395 from_unicode_blank_2[i] = from_unicode_blank_1; | |
| 396 from_unicode_blank_3[i] = from_unicode_blank_2; | |
| 397 from_unicode_blank_4[i] = from_unicode_blank_3; | |
| 398 } | |
| 399 | |
| 400 to_unicode_blank_1 = xnew_array (int, 96); | |
| 401 to_unicode_blank_2 = xnew_array (int *, 96); | |
| 402 for (i = 0; i < 96; i++) | |
| 403 { | |
| 877 | 404 /* Here -1 is guaranteed OK. */ |
| 771 | 405 to_unicode_blank_1[i] = -1; |
| 406 to_unicode_blank_2[i] = to_unicode_blank_1; | |
| 407 } | |
| 408 } | |
| 409 | |
| 410 static void * | |
| 411 create_new_from_unicode_table (int level) | |
| 412 { | |
| 413 switch (level) | |
| 414 { | |
| 415 /* WARNING: If you are thinking of compressing these, keep in | |
| 416 mind that sizeof (short) does not equal sizeof (short *). */ | |
| 417 case 1: | |
| 418 { | |
| 419 short *newtab = xnew_array (short, 256); | |
| 420 memcpy (newtab, from_unicode_blank_1, 256 * sizeof (short)); | |
| 421 return newtab; | |
| 422 } | |
| 423 case 2: | |
| 424 { | |
| 425 short **newtab = xnew_array (short *, 256); | |
| 426 memcpy (newtab, from_unicode_blank_2, 256 * sizeof (short *)); | |
| 427 return newtab; | |
| 428 } | |
| 429 case 3: | |
| 430 { | |
| 431 short ***newtab = xnew_array (short **, 256); | |
| 432 memcpy (newtab, from_unicode_blank_3, 256 * sizeof (short **)); | |
| 433 return newtab; | |
| 434 } | |
| 435 case 4: | |
| 436 { | |
| 437 short ****newtab = xnew_array (short ***, 256); | |
| 438 memcpy (newtab, from_unicode_blank_4, 256 * sizeof (short ***)); | |
| 439 return newtab; | |
| 440 } | |
| 441 default: | |
| 2500 | 442 ABORT (); |
| 771 | 443 return 0; |
| 444 } | |
| 445 } | |
| 446 | |
| 877 | 447 /* Allocate and blank the tables. |
| 1318 | 448 Loading them up is done by load-unicode-mapping-table. */ |
| 771 | 449 void |
| 450 init_charset_unicode_tables (Lisp_Object charset) | |
| 451 { | |
| 452 if (XCHARSET_DIMENSION (charset) == 1) | |
| 453 { | |
| 454 int *to_table = xnew_array (int, 96); | |
| 455 memcpy (to_table, to_unicode_blank_1, 96 * sizeof (int)); | |
| 456 XCHARSET_TO_UNICODE_TABLE (charset) = to_table; | |
| 457 } | |
| 458 else | |
| 459 { | |
| 460 int **to_table = xnew_array (int *, 96); | |
| 461 memcpy (to_table, to_unicode_blank_2, 96 * sizeof (int *)); | |
| 462 XCHARSET_TO_UNICODE_TABLE (charset) = to_table; | |
| 463 } | |
| 464 | |
| 465 { | |
| 2367 | 466 XCHARSET_FROM_UNICODE_TABLE (charset) = |
| 467 create_new_from_unicode_table (1); | |
| 771 | 468 XCHARSET_FROM_UNICODE_LEVELS (charset) = 1; |
| 469 } | |
| 470 } | |
| 471 | |
| 472 static void | |
| 473 free_from_unicode_table (void *table, int level) | |
| 474 { | |
| 475 int i; | |
| 476 | |
| 477 switch (level) | |
| 478 { | |
| 479 case 2: | |
| 480 { | |
| 481 short **tab = (short **) table; | |
| 482 for (i = 0; i < 256; i++) | |
| 483 { | |
| 484 if (tab[i] != from_unicode_blank_1) | |
| 485 free_from_unicode_table (tab[i], 1); | |
| 486 } | |
| 487 break; | |
| 488 } | |
| 489 case 3: | |
| 490 { | |
| 491 short ***tab = (short ***) table; | |
| 492 for (i = 0; i < 256; i++) | |
| 493 { | |
| 494 if (tab[i] != from_unicode_blank_2) | |
| 495 free_from_unicode_table (tab[i], 2); | |
| 496 } | |
| 497 break; | |
| 498 } | |
| 499 case 4: | |
| 500 { | |
| 501 short ****tab = (short ****) table; | |
| 502 for (i = 0; i < 256; i++) | |
| 503 { | |
| 504 if (tab[i] != from_unicode_blank_3) | |
| 505 free_from_unicode_table (tab[i], 3); | |
| 506 } | |
| 507 break; | |
| 508 } | |
| 509 } | |
| 510 | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
511 xfree (table); |
| 771 | 512 } |
| 513 | |
| 514 static void | |
| 515 free_to_unicode_table (void *table, int level) | |
| 516 { | |
| 517 if (level == 2) | |
| 518 { | |
| 519 int i; | |
| 520 int **tab = (int **) table; | |
| 521 | |
| 522 for (i = 0; i < 96; i++) | |
| 523 { | |
| 524 if (tab[i] != to_unicode_blank_1) | |
| 525 free_to_unicode_table (tab[i], 1); | |
| 526 } | |
| 527 } | |
| 528 | |
|
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4953
diff
changeset
|
529 xfree (table); |
| 771 | 530 } |
| 531 | |
| 532 void | |
| 533 free_charset_unicode_tables (Lisp_Object charset) | |
| 534 { | |
| 535 free_to_unicode_table (XCHARSET_TO_UNICODE_TABLE (charset), | |
| 536 XCHARSET_DIMENSION (charset)); | |
| 537 free_from_unicode_table (XCHARSET_FROM_UNICODE_TABLE (charset), | |
| 538 XCHARSET_FROM_UNICODE_LEVELS (charset)); | |
| 539 } | |
| 540 | |
| 541 #ifdef MEMORY_USAGE_STATS | |
| 542 | |
| 543 static Bytecount | |
| 544 compute_from_unicode_table_size_1 (void *table, int level, | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
545 struct usage_stats *stats) |
| 771 | 546 { |
| 547 int i; | |
| 548 Bytecount size = 0; | |
| 549 | |
| 550 switch (level) | |
| 551 { | |
| 552 case 2: | |
| 553 { | |
| 554 short **tab = (short **) table; | |
| 555 for (i = 0; i < 256; i++) | |
| 556 { | |
| 557 if (tab[i] != from_unicode_blank_1) | |
| 558 size += compute_from_unicode_table_size_1 (tab[i], 1, stats); | |
| 559 } | |
| 560 break; | |
| 561 } | |
| 562 case 3: | |
| 563 { | |
| 564 short ***tab = (short ***) table; | |
| 565 for (i = 0; i < 256; i++) | |
| 566 { | |
| 567 if (tab[i] != from_unicode_blank_2) | |
| 568 size += compute_from_unicode_table_size_1 (tab[i], 2, stats); | |
| 569 } | |
| 570 break; | |
| 571 } | |
| 572 case 4: | |
| 573 { | |
| 574 short ****tab = (short ****) table; | |
| 575 for (i = 0; i < 256; i++) | |
| 576 { | |
| 577 if (tab[i] != from_unicode_blank_3) | |
| 578 size += compute_from_unicode_table_size_1 (tab[i], 3, stats); | |
| 579 } | |
| 580 break; | |
| 581 } | |
| 582 } | |
| 583 | |
| 3024 | 584 size += malloced_storage_size (table, |
| 771 | 585 256 * (level == 1 ? sizeof (short) : |
| 586 sizeof (void *)), | |
| 587 stats); | |
| 588 return size; | |
| 589 } | |
| 590 | |
| 591 static Bytecount | |
| 592 compute_to_unicode_table_size_1 (void *table, int level, | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
593 struct usage_stats *stats) |
| 771 | 594 { |
| 595 Bytecount size = 0; | |
| 596 | |
| 597 if (level == 2) | |
| 598 { | |
| 599 int i; | |
| 600 int **tab = (int **) table; | |
| 601 | |
| 602 for (i = 0; i < 96; i++) | |
| 603 { | |
| 604 if (tab[i] != to_unicode_blank_1) | |
| 605 size += compute_to_unicode_table_size_1 (tab[i], 1, stats); | |
| 606 } | |
| 607 } | |
| 608 | |
| 3024 | 609 size += malloced_storage_size (table, |
| 771 | 610 96 * (level == 1 ? sizeof (int) : |
| 611 sizeof (void *)), | |
| 612 stats); | |
| 613 return size; | |
| 614 } | |
| 615 | |
| 616 Bytecount | |
| 617 compute_from_unicode_table_size (Lisp_Object charset, | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
618 struct usage_stats *stats) |
| 771 | 619 { |
| 620 return (compute_from_unicode_table_size_1 | |
| 621 (XCHARSET_FROM_UNICODE_TABLE (charset), | |
| 622 XCHARSET_FROM_UNICODE_LEVELS (charset), | |
| 623 stats)); | |
| 624 } | |
| 625 | |
| 626 Bytecount | |
| 627 compute_to_unicode_table_size (Lisp_Object charset, | |
|
5157
1fae11d56ad2
redo memory-usage mechanism, add way of dynamically initializing Lisp objects
Ben Wing <ben@xemacs.org>
parents:
4976
diff
changeset
|
628 struct usage_stats *stats) |
| 771 | 629 { |
| 630 return (compute_to_unicode_table_size_1 | |
| 631 (XCHARSET_TO_UNICODE_TABLE (charset), | |
| 632 XCHARSET_DIMENSION (charset), | |
| 633 stats)); | |
| 634 } | |
| 635 | |
| 636 #endif | |
| 637 | |
| 638 #ifdef SLEDGEHAMMER_CHECK_UNICODE | |
| 639 | |
| 640 /* "Sledgehammer checks" are checks that verify the self-consistency | |
| 641 of an entire structure every time a change is about to be made or | |
| 642 has been made to the structure. Not fast but a pretty much | |
| 643 sure-fire way of flushing out any incorrectnesses in the algorithms | |
| 644 that create the structure. | |
| 645 | |
| 646 Checking only after a change has been made will speed things up by | |
| 647 a factor of 2, but it doesn't absolutely prove that the code just | |
| 648 checked caused the problem; perhaps it happened elsewhere, either | |
| 649 in some code you forgot to sledgehammer check or as a result of | |
| 650 data corruption. */ | |
| 651 | |
| 652 static void | |
| 653 assert_not_any_blank_table (void *tab) | |
| 654 { | |
| 655 assert (tab != from_unicode_blank_1); | |
| 656 assert (tab != from_unicode_blank_2); | |
| 657 assert (tab != from_unicode_blank_3); | |
| 658 assert (tab != from_unicode_blank_4); | |
| 659 assert (tab != to_unicode_blank_1); | |
| 660 assert (tab != to_unicode_blank_2); | |
| 661 assert (tab); | |
| 662 } | |
| 663 | |
| 664 static void | |
| 665 sledgehammer_check_from_table (Lisp_Object charset, void *table, int level, | |
| 666 int codetop) | |
| 667 { | |
| 668 int i; | |
| 669 | |
| 670 switch (level) | |
| 671 { | |
| 672 case 1: | |
| 673 { | |
| 674 short *tab = (short *) table; | |
| 675 for (i = 0; i < 256; i++) | |
| 676 { | |
| 677 if (tab[i] != -1) | |
| 678 { | |
| 679 Lisp_Object char_charset; | |
| 680 int c1, c2; | |
| 681 | |
| 867 | 682 assert (valid_ichar_p (tab[i])); |
| 683 BREAKUP_ICHAR (tab[i], char_charset, c1, c2); | |
| 771 | 684 assert (EQ (charset, char_charset)); |
| 685 if (XCHARSET_DIMENSION (charset) == 1) | |
| 686 { | |
| 687 int *to_table = | |
| 688 (int *) XCHARSET_TO_UNICODE_TABLE (charset); | |
| 689 assert_not_any_blank_table (to_table); | |
| 690 assert (to_table[c1 - 32] == (codetop << 8) + i); | |
| 691 } | |
| 692 else | |
| 693 { | |
| 694 int **to_table = | |
| 695 (int **) XCHARSET_TO_UNICODE_TABLE (charset); | |
| 696 assert_not_any_blank_table (to_table); | |
| 697 assert_not_any_blank_table (to_table[c1 - 32]); | |
| 698 assert (to_table[c1 - 32][c2 - 32] == (codetop << 8) + i); | |
| 699 } | |
| 700 } | |
| 701 } | |
| 702 break; | |
| 703 } | |
| 704 case 2: | |
| 705 { | |
| 706 short **tab = (short **) table; | |
| 707 for (i = 0; i < 256; i++) | |
| 708 { | |
| 709 if (tab[i] != from_unicode_blank_1) | |
| 710 sledgehammer_check_from_table (charset, tab[i], 1, | |
| 711 (codetop << 8) + i); | |
| 712 } | |
| 713 break; | |
| 714 } | |
| 715 case 3: | |
| 716 { | |
| 717 short ***tab = (short ***) table; | |
| 718 for (i = 0; i < 256; i++) | |
| 719 { | |
| 720 if (tab[i] != from_unicode_blank_2) | |
| 721 sledgehammer_check_from_table (charset, tab[i], 2, | |
| 722 (codetop << 8) + i); | |
| 723 } | |
| 724 break; | |
| 725 } | |
| 726 case 4: | |
| 727 { | |
| 728 short ****tab = (short ****) table; | |
| 729 for (i = 0; i < 256; i++) | |
| 730 { | |
| 731 if (tab[i] != from_unicode_blank_3) | |
| 732 sledgehammer_check_from_table (charset, tab[i], 3, | |
| 733 (codetop << 8) + i); | |
| 734 } | |
| 735 break; | |
| 736 } | |
| 737 default: | |
| 2500 | 738 ABORT (); |
| 771 | 739 } |
| 740 } | |
| 741 | |
| 742 static void | |
| 743 sledgehammer_check_to_table (Lisp_Object charset, void *table, int level, | |
| 744 int codetop) | |
| 745 { | |
| 746 int i; | |
| 747 | |
| 748 switch (level) | |
| 749 { | |
| 750 case 1: | |
| 751 { | |
| 752 int *tab = (int *) table; | |
| 753 | |
| 754 if (XCHARSET_CHARS (charset) == 94) | |
| 755 { | |
| 756 assert (tab[0] == -1); | |
| 757 assert (tab[95] == -1); | |
| 758 } | |
| 759 | |
| 760 for (i = 0; i < 96; i++) | |
| 761 { | |
| 762 if (tab[i] != -1) | |
| 763 { | |
| 764 int u4, u3, u2, u1, levels; | |
| 867 | 765 Ichar ch; |
| 766 Ichar this_ch; | |
| 771 | 767 short val; |
| 768 void *frtab = XCHARSET_FROM_UNICODE_TABLE (charset); | |
| 769 | |
| 770 if (XCHARSET_DIMENSION (charset) == 1) | |
| 867 | 771 this_ch = make_ichar (charset, i + 32, 0); |
| 771 | 772 else |
| 867 | 773 this_ch = make_ichar (charset, codetop + 32, i + 32); |
| 771 | 774 |
| 775 assert (tab[i] >= 0); | |
| 776 BREAKUP_UNICODE_CODE (tab[i], u4, u3, u2, u1, levels); | |
| 777 assert (levels <= XCHARSET_FROM_UNICODE_LEVELS (charset)); | |
| 778 | |
| 779 switch (XCHARSET_FROM_UNICODE_LEVELS (charset)) | |
| 780 { | |
| 781 case 1: val = ((short *) frtab)[u1]; break; | |
| 782 case 2: val = ((short **) frtab)[u2][u1]; break; | |
| 783 case 3: val = ((short ***) frtab)[u3][u2][u1]; break; | |
| 784 case 4: val = ((short ****) frtab)[u4][u3][u2][u1]; break; | |
| 2500 | 785 default: ABORT (); |
| 771 | 786 } |
| 787 | |
| 867 | 788 ch = make_ichar (charset, val >> 8, val & 0xFF); |
| 771 | 789 assert (ch == this_ch); |
| 790 | |
| 791 switch (XCHARSET_FROM_UNICODE_LEVELS (charset)) | |
| 792 { | |
| 793 case 4: | |
| 794 assert_not_any_blank_table (frtab); | |
| 795 frtab = ((short ****) frtab)[u4]; | |
| 796 /* fall through */ | |
| 797 case 3: | |
| 798 assert_not_any_blank_table (frtab); | |
| 799 frtab = ((short ***) frtab)[u3]; | |
| 800 /* fall through */ | |
| 801 case 2: | |
| 802 assert_not_any_blank_table (frtab); | |
| 803 frtab = ((short **) frtab)[u2]; | |
| 804 /* fall through */ | |
| 805 case 1: | |
| 806 assert_not_any_blank_table (frtab); | |
| 807 break; | |
| 2500 | 808 default: ABORT (); |
| 771 | 809 } |
| 810 } | |
| 811 } | |
| 812 break; | |
| 813 } | |
| 814 case 2: | |
| 815 { | |
| 816 int **tab = (int **) table; | |
| 817 | |
| 818 if (XCHARSET_CHARS (charset) == 94) | |
| 819 { | |
| 820 assert (tab[0] == to_unicode_blank_1); | |
| 821 assert (tab[95] == to_unicode_blank_1); | |
| 822 } | |
| 823 | |
| 824 for (i = 0; i < 96; i++) | |
| 825 { | |
| 826 if (tab[i] != to_unicode_blank_1) | |
| 827 sledgehammer_check_to_table (charset, tab[i], 1, i); | |
| 828 } | |
| 829 break; | |
| 830 } | |
| 831 default: | |
| 2500 | 832 ABORT (); |
| 771 | 833 } |
| 834 } | |
| 835 | |
| 836 static void | |
| 837 sledgehammer_check_unicode_tables (Lisp_Object charset) | |
| 838 { | |
| 839 /* verify that the blank tables have not been modified */ | |
| 840 int i; | |
| 841 int from_level = XCHARSET_FROM_UNICODE_LEVELS (charset); | |
| 842 int to_level = XCHARSET_FROM_UNICODE_LEVELS (charset); | |
| 843 | |
| 844 for (i = 0; i < 256; i++) | |
| 845 { | |
| 846 assert (from_unicode_blank_1[i] == (short) -1); | |
| 847 assert (from_unicode_blank_2[i] == from_unicode_blank_1); | |
| 848 assert (from_unicode_blank_3[i] == from_unicode_blank_2); | |
| 849 assert (from_unicode_blank_4[i] == from_unicode_blank_3); | |
| 850 } | |
| 851 | |
| 852 for (i = 0; i < 96; i++) | |
| 853 { | |
| 854 assert (to_unicode_blank_1[i] == -1); | |
| 855 assert (to_unicode_blank_2[i] == to_unicode_blank_1); | |
| 856 } | |
| 857 | |
| 858 assert (from_level >= 1 && from_level <= 4); | |
| 859 | |
| 860 sledgehammer_check_from_table (charset, | |
| 861 XCHARSET_FROM_UNICODE_TABLE (charset), | |
| 862 from_level, 0); | |
| 863 | |
| 864 sledgehammer_check_to_table (charset, | |
| 865 XCHARSET_TO_UNICODE_TABLE (charset), | |
| 866 XCHARSET_DIMENSION (charset), 0); | |
| 867 } | |
| 868 | |
| 869 #endif /* SLEDGEHAMMER_CHECK_UNICODE */ | |
| 870 | |
| 871 static void | |
| 867 | 872 set_unicode_conversion (Ichar chr, int code) |
| 771 | 873 { |
| 874 Lisp_Object charset; | |
| 875 int c1, c2; | |
| 876 | |
| 867 | 877 BREAKUP_ICHAR (chr, charset, c1, c2); |
| 771 | 878 |
| 877 | 879 /* I tried an assert on code > 255 || chr == code, but that fails because |
| 880 Mule gives many Latin characters separate code points for different | |
| 881 ISO 8859 coded character sets. Obvious in hindsight.... */ | |
| 882 assert (!EQ (charset, Vcharset_ascii) || chr == code); | |
| 883 assert (!EQ (charset, Vcharset_latin_iso8859_1) || chr == code); | |
| 884 assert (!EQ (charset, Vcharset_control_1) || chr == code); | |
| 885 | |
| 886 /* This assert is needed because it is simply unimplemented. */ | |
| 771 | 887 assert (!EQ (charset, Vcharset_composite)); |
| 888 | |
| 889 #ifdef SLEDGEHAMMER_CHECK_UNICODE | |
| 890 sledgehammer_check_unicode_tables (charset); | |
| 891 #endif | |
| 892 | |
| 2704 | 893 if (EQ(charset, Vcharset_ascii) || EQ(charset, Vcharset_control_1)) |
| 894 return; | |
| 895 | |
| 771 | 896 /* First, the char -> unicode translation */ |
| 897 | |
| 898 if (XCHARSET_DIMENSION (charset) == 1) | |
| 899 { | |
| 900 int *to_table = (int *) XCHARSET_TO_UNICODE_TABLE (charset); | |
| 901 to_table[c1 - 32] = code; | |
| 902 } | |
| 903 else | |
| 904 { | |
| 905 int **to_table_2 = (int **) XCHARSET_TO_UNICODE_TABLE (charset); | |
| 906 int *to_table_1; | |
| 907 | |
| 908 assert (XCHARSET_DIMENSION (charset) == 2); | |
| 909 to_table_1 = to_table_2[c1 - 32]; | |
| 910 if (to_table_1 == to_unicode_blank_1) | |
| 911 { | |
| 912 to_table_1 = xnew_array (int, 96); | |
| 913 memcpy (to_table_1, to_unicode_blank_1, 96 * sizeof (int)); | |
| 914 to_table_2[c1 - 32] = to_table_1; | |
| 915 } | |
| 916 to_table_1[c2 - 32] = code; | |
| 917 } | |
| 918 | |
| 919 /* Then, unicode -> char: much harder */ | |
| 920 | |
| 921 { | |
| 922 int charset_levels; | |
| 923 int u4, u3, u2, u1; | |
| 924 int code_levels; | |
| 925 BREAKUP_UNICODE_CODE (code, u4, u3, u2, u1, code_levels); | |
| 926 | |
| 927 charset_levels = XCHARSET_FROM_UNICODE_LEVELS (charset); | |
| 928 | |
| 929 /* Make sure the charset's tables have at least as many levels as | |
| 930 the code point has: Note that the charset is guaranteed to have | |
| 931 at least one level, because it was created that way */ | |
| 932 if (charset_levels < code_levels) | |
| 933 { | |
| 934 int i; | |
| 935 | |
| 936 assert (charset_levels > 0); | |
| 937 for (i = 2; i <= code_levels; i++) | |
| 938 { | |
| 939 if (charset_levels < i) | |
| 940 { | |
| 941 void *old_table = XCHARSET_FROM_UNICODE_TABLE (charset); | |
| 942 void *table = create_new_from_unicode_table (i); | |
| 943 XCHARSET_FROM_UNICODE_TABLE (charset) = table; | |
| 944 | |
| 945 switch (i) | |
| 946 { | |
| 947 case 2: | |
| 948 ((short **) table)[0] = (short *) old_table; | |
| 949 break; | |
| 950 case 3: | |
| 951 ((short ***) table)[0] = (short **) old_table; | |
| 952 break; | |
| 953 case 4: | |
| 954 ((short ****) table)[0] = (short ***) old_table; | |
| 955 break; | |
| 2500 | 956 default: ABORT (); |
| 771 | 957 } |
| 958 } | |
| 959 } | |
| 960 | |
| 961 charset_levels = code_levels; | |
| 962 XCHARSET_FROM_UNICODE_LEVELS (charset) = code_levels; | |
| 963 } | |
| 964 | |
| 965 /* Now, make sure there is a non-default table at each level */ | |
| 966 { | |
| 967 int i; | |
| 968 void *table = XCHARSET_FROM_UNICODE_TABLE (charset); | |
| 969 | |
| 970 for (i = charset_levels; i >= 2; i--) | |
| 971 { | |
| 972 switch (i) | |
| 973 { | |
| 974 case 4: | |
| 975 if (((short ****) table)[u4] == from_unicode_blank_3) | |
| 976 ((short ****) table)[u4] = | |
| 977 ((short ***) create_new_from_unicode_table (3)); | |
| 978 table = ((short ****) table)[u4]; | |
| 979 break; | |
| 980 case 3: | |
| 981 if (((short ***) table)[u3] == from_unicode_blank_2) | |
| 982 ((short ***) table)[u3] = | |
| 983 ((short **) create_new_from_unicode_table (2)); | |
| 984 table = ((short ***) table)[u3]; | |
| 985 break; | |
| 986 case 2: | |
| 987 if (((short **) table)[u2] == from_unicode_blank_1) | |
| 988 ((short **) table)[u2] = | |
| 989 ((short *) create_new_from_unicode_table (1)); | |
| 990 table = ((short **) table)[u2]; | |
| 991 break; | |
| 2500 | 992 default: ABORT (); |
| 771 | 993 } |
| 994 } | |
| 995 } | |
| 996 | |
| 997 /* Finally, set the character */ | |
| 998 | |
| 999 { | |
| 1000 void *table = XCHARSET_FROM_UNICODE_TABLE (charset); | |
| 1001 switch (charset_levels) | |
| 1002 { | |
| 1003 case 1: ((short *) table)[u1] = (c1 << 8) + c2; break; | |
| 1004 case 2: ((short **) table)[u2][u1] = (c1 << 8) + c2; break; | |
| 1005 case 3: ((short ***) table)[u3][u2][u1] = (c1 << 8) + c2; break; | |
| 1006 case 4: ((short ****) table)[u4][u3][u2][u1] = (c1 << 8) + c2; break; | |
| 2500 | 1007 default: ABORT (); |
| 771 | 1008 } |
| 1009 } | |
| 1010 } | |
| 1011 | |
| 1012 #ifdef SLEDGEHAMMER_CHECK_UNICODE | |
| 1013 sledgehammer_check_unicode_tables (charset); | |
| 1014 #endif | |
| 1015 } | |
| 1016 | |
| 788 | 1017 int |
| 867 | 1018 ichar_to_unicode (Ichar chr) |
| 771 | 1019 { |
| 1020 Lisp_Object charset; | |
| 1021 int c1, c2; | |
| 1022 | |
| 867 | 1023 type_checking_assert (valid_ichar_p (chr)); |
| 877 | 1024 /* This shortcut depends on the representation of an Ichar, see text.c. */ |
| 771 | 1025 if (chr < 256) |
| 1026 return (int) chr; | |
| 1027 | |
| 867 | 1028 BREAKUP_ICHAR (chr, charset, c1, c2); |
| 771 | 1029 if (EQ (charset, Vcharset_composite)) |
| 1030 return -1; /* #### don't know how to handle */ | |
| 1031 else if (XCHARSET_DIMENSION (charset) == 1) | |
| 1032 return ((int *) XCHARSET_TO_UNICODE_TABLE (charset))[c1 - 32]; | |
| 1033 else | |
| 1034 return ((int **) XCHARSET_TO_UNICODE_TABLE (charset))[c1 - 32][c2 - 32]; | |
| 1035 } | |
| 1036 | |
| 867 | 1037 static Ichar |
| 3439 | 1038 get_free_codepoint(Lisp_Object charset) |
| 1039 { | |
| 1040 Lisp_Object name = Fcharset_name(charset); | |
| 1041 Lisp_Object zeichen = Fget(name, Qlast_allocated_character, Qnil); | |
| 1042 Ichar res; | |
| 1043 | |
| 1044 /* Only allow this with the 96x96 character sets we are using for | |
| 1045 temporary Unicode support. */ | |
| 1046 assert(2 == XCHARSET_DIMENSION(charset) && 96 == XCHARSET_CHARS(charset)); | |
| 1047 | |
| 1048 if (!NILP(zeichen)) | |
| 1049 { | |
| 1050 int c1, c2; | |
| 1051 | |
| 1052 BREAKUP_ICHAR(XCHAR(zeichen), charset, c1, c2); | |
| 1053 | |
| 1054 if (127 == c1 && 127 == c2) | |
| 1055 { | |
| 1056 /* We've already used the hightest-numbered character in this | |
| 1057 set--tell our caller to create another. */ | |
| 1058 return -1; | |
| 1059 } | |
| 1060 | |
| 1061 if (127 == c2) | |
| 1062 { | |
| 1063 ++c1; | |
| 1064 c2 = 0x20; | |
| 1065 } | |
| 1066 else | |
| 1067 { | |
| 1068 ++c2; | |
| 1069 } | |
| 1070 | |
| 1071 res = make_ichar(charset, c1, c2); | |
| 1072 Fput(name, Qlast_allocated_character, make_char(res)); | |
| 1073 } | |
| 1074 else | |
| 1075 { | |
| 1076 res = make_ichar(charset, 32, 32); | |
| 1077 Fput(name, Qlast_allocated_character, make_char(res)); | |
| 1078 } | |
| 1079 return res; | |
| 1080 } | |
| 1081 | |
| 1082 /* The just-in-time creation of XEmacs characters that correspond to unknown | |
| 1083 Unicode code points happens when: | |
| 1084 | |
| 1085 1. The lookup would otherwise fail. | |
| 1086 | |
| 1087 2. The charsets array is the nil or the default. | |
| 1088 | |
| 1089 If there are no free code points in the just-in-time Unicode character | |
| 1090 set, and the charsets array is the default unicode precedence list, | |
| 1091 create a new just-in-time Unicode character set, add it at the end of the | |
| 1092 unicode precedence list, create the XEmacs character in that character | |
| 1093 set, and return it. */ | |
| 1094 | |
| 1095 static Ichar | |
| 877 | 1096 unicode_to_ichar (int code, Lisp_Object_dynarr *charsets) |
| 771 | 1097 { |
| 1098 int u1, u2, u3, u4; | |
| 1099 int code_levels; | |
| 1100 int i; | |
| 1101 int n = Dynarr_length (charsets); | |
| 1102 | |
| 1103 type_checking_assert (code >= 0); | |
| 877 | 1104 /* This shortcut depends on the representation of an Ichar, see text.c. |
| 1105 Note that it may _not_ be extended to U+00A0 to U+00FF (many ISO 8859 | |
| 893 | 1106 coded character sets have points that map into that region, so this |
| 1107 function is many-valued). */ | |
| 877 | 1108 if (code < 0xA0) |
| 867 | 1109 return (Ichar) code; |
| 771 | 1110 |
| 1111 BREAKUP_UNICODE_CODE (code, u4, u3, u2, u1, code_levels); | |
| 1112 | |
| 1113 for (i = 0; i < n; i++) | |
| 1114 { | |
| 1115 Lisp_Object charset = Dynarr_at (charsets, i); | |
| 1116 int charset_levels = XCHARSET_FROM_UNICODE_LEVELS (charset); | |
| 1117 if (charset_levels >= code_levels) | |
| 1118 { | |
| 1119 void *table = XCHARSET_FROM_UNICODE_TABLE (charset); | |
| 1120 short retval; | |
| 1121 | |
| 1122 switch (charset_levels) | |
| 1123 { | |
| 1124 case 1: retval = ((short *) table)[u1]; break; | |
| 1125 case 2: retval = ((short **) table)[u2][u1]; break; | |
| 1126 case 3: retval = ((short ***) table)[u3][u2][u1]; break; | |
| 1127 case 4: retval = ((short ****) table)[u4][u3][u2][u1]; break; | |
| 2500 | 1128 default: ABORT (); retval = 0; |
| 771 | 1129 } |
| 1130 | |
| 1131 if (retval != -1) | |
| 867 | 1132 return make_ichar (charset, retval >> 8, retval & 0xFF); |
| 771 | 1133 } |
| 1134 } | |
| 3439 | 1135 |
| 1136 /* Only do the magic just-in-time assignment if we're using the default | |
| 1137 list. */ | |
| 1138 if (unicode_precedence_dynarr == charsets) | |
| 1139 { | |
| 1140 if (NILP (Vcurrent_jit_charset) || | |
| 1141 (-1 == (i = get_free_codepoint(Vcurrent_jit_charset)))) | |
| 1142 { | |
| 3452 | 1143 Ibyte setname[32]; |
| 4268 | 1144 int number_of_jit_charsets = XINT (Vnumber_of_jit_charsets); |
| 1145 Ascbyte last_jit_charset_final = XCHAR (Vlast_jit_charset_final); | |
| 1146 | |
| 1147 /* This final byte shit is, umm, not that cool. */ | |
| 1148 assert (last_jit_charset_final >= 0x30); | |
| 3439 | 1149 |
| 3452 | 1150 /* Assertion added partly because our Win32 layer doesn't |
| 1151 support snprintf; with this, we're sure it won't overflow | |
| 1152 the buffer. */ | |
| 1153 assert(100 > number_of_jit_charsets); | |
| 1154 | |
| 4268 | 1155 qxesprintf(setname, "jit-ucs-charset-%d", number_of_jit_charsets); |
| 1156 | |
| 3439 | 1157 Vcurrent_jit_charset = Fmake_charset |
|
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1158 (intern_istring (setname), Vcharset_descr, |
| 3439 | 1159 /* Set encode-as-utf-8 to t, to have this character set written |
| 1160 using UTF-8 escapes in escape-quoted and ctext. This | |
| 1161 sidesteps the fact that our internal character -> Unicode | |
| 1162 mapping is not stable from one invocation to the next. */ | |
| 1163 nconc2 (list2(Qencode_as_utf_8, Qt), | |
| 1164 nconc2 (list6(Qcolumns, make_int(1), Qchars, make_int(96), | |
| 1165 Qdimension, make_int(2)), | |
| 3659 | 1166 list6(Qregistries, Qunicode_registries, |
| 4268 | 1167 Qfinal, make_char(last_jit_charset_final), |
| 3439 | 1168 /* This CCL program is initialised in |
| 1169 unicode.el. */ | |
| 1170 Qccl_program, Qccl_encode_to_ucs_2)))); | |
| 4268 | 1171 |
| 1172 /* Record for the Unicode infrastructure that we've created | |
| 1173 this character set. */ | |
| 1174 Vnumber_of_jit_charsets = make_int (number_of_jit_charsets + 1); | |
| 1175 Vlast_jit_charset_final = make_char (last_jit_charset_final + 1); | |
| 3439 | 1176 |
| 1177 i = get_free_codepoint(Vcurrent_jit_charset); | |
| 1178 } | |
| 1179 | |
| 1180 if (-1 != i) | |
| 1181 { | |
| 1182 set_unicode_conversion((Ichar)i, code); | |
| 1183 /* No need to add the charset to the end of the list; it's done | |
| 1184 automatically. */ | |
| 1185 } | |
| 1186 } | |
| 1187 return (Ichar) i; | |
| 771 | 1188 } |
| 1189 | |
| 877 | 1190 /* Add charsets to precedence list. |
| 1191 LIST must be a list of charsets. Charsets which are in the list more | |
| 1192 than once are given the precedence implied by their earliest appearance. | |
| 1193 Later appearances are ignored. */ | |
| 771 | 1194 static void |
| 1195 add_charsets_to_precedence_list (Lisp_Object list, int *lbs, | |
| 1196 Lisp_Object_dynarr *dynarr) | |
| 1197 { | |
| 1198 { | |
| 1199 EXTERNAL_LIST_LOOP_2 (elt, list) | |
| 1200 { | |
| 1201 Lisp_Object charset = Fget_charset (elt); | |
| 778 | 1202 int lb = XCHARSET_LEADING_BYTE (charset); |
| 771 | 1203 if (lbs[lb - MIN_LEADING_BYTE] == 0) |
| 1204 { | |
| 877 | 1205 Dynarr_add (dynarr, charset); |
| 771 | 1206 lbs[lb - MIN_LEADING_BYTE] = 1; |
| 1207 } | |
| 1208 } | |
| 1209 } | |
| 1210 } | |
| 1211 | |
| 877 | 1212 /* Rebuild the charset precedence array. |
| 1213 The "charsets preferred for the current language" get highest precedence, | |
| 1214 followed by the "charsets preferred by default", ordered as in | |
| 1215 Vlanguage_unicode_precedence_list and Vdefault_unicode_precedence_list, | |
| 1216 respectively. All remaining charsets follow in an arbitrary order. */ | |
| 771 | 1217 void |
| 1218 recalculate_unicode_precedence (void) | |
| 1219 { | |
| 1220 int lbs[NUM_LEADING_BYTES]; | |
| 1221 int i; | |
| 1222 | |
| 1223 for (i = 0; i < NUM_LEADING_BYTES; i++) | |
| 1224 lbs[i] = 0; | |
| 1225 | |
| 1226 Dynarr_reset (unicode_precedence_dynarr); | |
| 1227 | |
| 1228 add_charsets_to_precedence_list (Vlanguage_unicode_precedence_list, | |
| 1229 lbs, unicode_precedence_dynarr); | |
| 1230 add_charsets_to_precedence_list (Vdefault_unicode_precedence_list, | |
| 1231 lbs, unicode_precedence_dynarr); | |
| 1232 | |
| 1233 for (i = 0; i < NUM_LEADING_BYTES; i++) | |
| 1234 { | |
| 1235 if (lbs[i] == 0) | |
| 1236 { | |
| 826 | 1237 Lisp_Object charset = charset_by_leading_byte (i + MIN_LEADING_BYTE); |
| 771 | 1238 if (!NILP (charset)) |
| 1239 Dynarr_add (unicode_precedence_dynarr, charset); | |
| 1240 } | |
| 1241 } | |
| 1242 } | |
| 1243 | |
| 877 | 1244 DEFUN ("unicode-precedence-list", |
| 1245 Funicode_precedence_list, | |
| 1246 0, 0, 0, /* | |
| 1247 Return the precedence order among charsets used for Unicode decoding. | |
| 1248 | |
| 1249 Value is a list of charsets, which are searched in order for a translation | |
| 1250 matching a given Unicode character. | |
| 1251 | |
| 1252 The highest precedence is given to the language-specific precedence list of | |
| 1253 charsets, defined by `set-language-unicode-precedence-list'. These are | |
| 1254 followed by charsets in the default precedence list, defined by | |
| 1255 `set-default-unicode-precedence-list'. Charsets occurring multiple times are | |
| 1256 given precedence according to their first occurrance in either list. These | |
| 1257 are followed by the remaining charsets, in some arbitrary order. | |
| 771 | 1258 |
| 1259 The language-specific precedence list is meant to be set as part of the | |
| 1260 language environment initialization; the default precedence list is meant | |
| 1261 to be set by the user. | |
| 1318 | 1262 |
| 1263 #### NOTE: This interface may be changed. | |
| 771 | 1264 */ |
| 877 | 1265 ()) |
| 1266 { | |
| 1267 int i; | |
| 1268 Lisp_Object list = Qnil; | |
| 1269 | |
| 1270 for (i = Dynarr_length (unicode_precedence_dynarr) - 1; i >= 0; i--) | |
| 1271 list = Fcons (Dynarr_at (unicode_precedence_dynarr, i), list); | |
| 1272 return list; | |
| 1273 } | |
| 1274 | |
| 1275 | |
| 1276 /* #### This interface is wrong. Cyrillic users and Chinese users are going | |
| 1277 to have varying opinions about whether ISO Cyrillic, KOI8-R, or Windows | |
| 1278 1251 should take precedence, and whether Big Five or CNS should take | |
| 1279 precedence, respectively. This means that users are sometimes going to | |
| 1280 want to set Vlanguage_unicode_precedence_list. | |
| 1281 Furthermore, this should be language-local (buffer-local would be a | |
| 1318 | 1282 reasonable approximation). |
| 1283 | |
| 1284 Answer: You are right, this needs rethinking. */ | |
| 877 | 1285 DEFUN ("set-language-unicode-precedence-list", |
| 1286 Fset_language_unicode_precedence_list, | |
| 1287 1, 1, 0, /* | |
| 1288 Set the language-specific precedence of charsets in Unicode decoding. | |
| 1289 LIST is a list of charsets. | |
| 1290 See `unicode-precedence-list' for more information. | |
| 1318 | 1291 |
| 1292 #### NOTE: This interface may be changed. | |
| 877 | 1293 */ |
| 771 | 1294 (list)) |
| 1295 { | |
| 1296 { | |
| 1297 EXTERNAL_LIST_LOOP_2 (elt, list) | |
| 1298 Fget_charset (elt); | |
| 1299 } | |
| 1300 | |
| 1301 Vlanguage_unicode_precedence_list = list; | |
| 1302 recalculate_unicode_precedence (); | |
| 1303 return Qnil; | |
| 1304 } | |
| 1305 | |
| 1306 DEFUN ("language-unicode-precedence-list", | |
| 1307 Flanguage_unicode_precedence_list, | |
| 1308 0, 0, 0, /* | |
| 1309 Return the language-specific precedence list used for Unicode decoding. | |
| 877 | 1310 See `unicode-precedence-list' for more information. |
| 1318 | 1311 |
| 1312 #### NOTE: This interface may be changed. | |
| 771 | 1313 */ |
| 1314 ()) | |
| 1315 { | |
| 1316 return Vlanguage_unicode_precedence_list; | |
| 1317 } | |
| 1318 | |
| 1319 DEFUN ("set-default-unicode-precedence-list", | |
| 1320 Fset_default_unicode_precedence_list, | |
| 1321 1, 1, 0, /* | |
| 1322 Set the default precedence list used for Unicode decoding. | |
| 877 | 1323 This is intended to be set by the user. See |
| 1324 `unicode-precedence-list' for more information. | |
| 1318 | 1325 |
| 1326 #### NOTE: This interface may be changed. | |
| 771 | 1327 */ |
| 1328 (list)) | |
| 1329 { | |
| 1330 { | |
| 1331 EXTERNAL_LIST_LOOP_2 (elt, list) | |
| 1332 Fget_charset (elt); | |
| 1333 } | |
| 1334 | |
| 1335 Vdefault_unicode_precedence_list = list; | |
| 1336 recalculate_unicode_precedence (); | |
| 1337 return Qnil; | |
| 1338 } | |
| 1339 | |
| 1340 DEFUN ("default-unicode-precedence-list", | |
| 1341 Fdefault_unicode_precedence_list, | |
| 1342 0, 0, 0, /* | |
| 1343 Return the default precedence list used for Unicode decoding. | |
| 877 | 1344 See `unicode-precedence-list' for more information. |
| 1318 | 1345 |
| 1346 #### NOTE: This interface may be changed. | |
| 771 | 1347 */ |
| 1348 ()) | |
| 1349 { | |
| 1350 return Vdefault_unicode_precedence_list; | |
| 1351 } | |
| 1352 | |
| 1353 DEFUN ("set-unicode-conversion", Fset_unicode_conversion, | |
| 1354 2, 2, 0, /* | |
| 1355 Add conversion information between Unicode codepoints and characters. | |
| 877 | 1356 Conversions for U+0000 to U+00FF are hardwired to ASCII, Control-1, and |
| 1357 Latin-1. Attempts to set these values will raise an error. | |
| 1358 | |
| 771 | 1359 CHARACTER is one of the following: |
| 1360 | |
| 1361 -- A character (in which case CODE must be a non-negative integer; values | |
| 1362 above 2^20 - 1 are allowed for the purpose of specifying private | |
| 877 | 1363 characters, but are illegal in standard Unicode---they will cause errors |
| 1364 when converted to utf-16) | |
| 771 | 1365 -- A vector of characters (in which case CODE must be a vector of integers |
| 1366 of the same length) | |
| 1367 */ | |
| 1368 (character, code)) | |
| 1369 { | |
| 1370 Lisp_Object charset; | |
| 877 | 1371 int ichar, unicode; |
| 771 | 1372 |
| 1373 CHECK_CHAR (character); | |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5157
diff
changeset
|
1374 |
|
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5157
diff
changeset
|
1375 check_integer_range (code, Qzero, make_integer (EMACS_INT_MAX)); |
| 771 | 1376 |
| 877 | 1377 unicode = XINT (code); |
| 1378 ichar = XCHAR (character); | |
| 1379 charset = ichar_charset (ichar); | |
| 1380 | |
| 1381 /* The translations of ASCII, Control-1, and Latin-1 code points are | |
| 1382 hard-coded in ichar_to_unicode and unicode_to_ichar. | |
| 1383 | |
| 1384 Checking unicode < 256 && ichar != unicode is wrong because Mule gives | |
| 1385 many Latin characters code points in a few different character sets. */ | |
| 1386 if ((EQ (charset, Vcharset_ascii) || | |
| 1387 EQ (charset, Vcharset_control_1) || | |
| 1388 EQ (charset, Vcharset_latin_iso8859_1)) | |
| 1389 && unicode != ichar) | |
| 893 | 1390 signal_error (Qinvalid_argument, "Can't change Unicode translation for ASCII, Control-1 or Latin-1 character", |
| 771 | 1391 character); |
| 1392 | |
| 877 | 1393 /* #### Composite characters are not properly implemented yet. */ |
| 1394 if (EQ (charset, Vcharset_composite)) | |
| 1395 signal_error (Qinvalid_argument, "Can't set Unicode translation for Composite char", | |
| 1396 character); | |
| 1397 | |
| 1398 set_unicode_conversion (ichar, unicode); | |
| 771 | 1399 return Qnil; |
| 1400 } | |
| 1401 | |
| 1402 #endif /* MULE */ | |
| 1403 | |
| 800 | 1404 DEFUN ("char-to-unicode", Fchar_to_unicode, 1, 1, 0, /* |
| 771 | 1405 Convert character to Unicode codepoint. |
| 3025 | 1406 When there is no international support (i.e. the `mule' feature is not |
| 877 | 1407 present), this function simply does `char-to-int'. |
| 771 | 1408 */ |
| 1409 (character)) | |
| 1410 { | |
| 1411 CHECK_CHAR (character); | |
| 1412 #ifdef MULE | |
| 867 | 1413 return make_int (ichar_to_unicode (XCHAR (character))); |
| 771 | 1414 #else |
| 1415 return Fchar_to_int (character); | |
| 1416 #endif /* MULE */ | |
| 1417 } | |
| 1418 | |
| 800 | 1419 DEFUN ("unicode-to-char", Funicode_to_char, 1, 2, 0, /* |
| 771 | 1420 Convert Unicode codepoint to character. |
| 1421 CODE should be a non-negative integer. | |
| 1422 If CHARSETS is given, it should be a list of charsets, and only those | |
| 1423 charsets will be consulted, in the given order, for a translation. | |
| 1424 Otherwise, the default ordering of all charsets will be given (see | |
| 1425 `set-unicode-charset-precedence'). | |
| 1426 | |
| 3025 | 1427 When there is no international support (i.e. the `mule' feature is not |
| 877 | 1428 present), this function simply does `int-to-char' and ignores the CHARSETS |
| 1429 argument. | |
| 2622 | 1430 |
| 3439 | 1431 If the CODE would not otherwise be converted to an XEmacs character, and the |
| 1432 list of character sets to be consulted is nil or the default, a new XEmacs | |
| 1433 character will be created for it in one of the `jit-ucs-charset' Mule | |
| 4268 | 1434 character sets, and that character will be returned. |
| 1435 | |
| 1436 This is limited to around 400,000 characters per XEmacs session, though, so | |
| 1437 while normal usage will not be problematic, things like: | |
| 1438 | |
| 1439 \(dotimes (i #x110000) (decode-char 'ucs i)) | |
| 1440 | |
| 1441 will eventually error. The long-term solution to this is Unicode as an | |
| 1442 internal encoding. | |
| 771 | 1443 */ |
| 2333 | 1444 (code, USED_IF_MULE (charsets))) |
| 771 | 1445 { |
| 1446 #ifdef MULE | |
| 1447 Lisp_Object_dynarr *dyn; | |
| 1448 int lbs[NUM_LEADING_BYTES]; | |
| 1449 int c; | |
| 1450 | |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5157
diff
changeset
|
1451 check_integer_range (code, Qzero, make_integer (EMACS_INT_MAX)); |
| 771 | 1452 c = XINT (code); |
| 1453 { | |
| 1454 EXTERNAL_LIST_LOOP_2 (elt, charsets) | |
| 1455 Fget_charset (elt); | |
| 1456 } | |
| 1457 | |
| 1458 if (NILP (charsets)) | |
| 1459 { | |
| 877 | 1460 Ichar ret = unicode_to_ichar (c, unicode_precedence_dynarr); |
| 771 | 1461 if (ret == -1) |
| 1462 return Qnil; | |
| 1463 return make_char (ret); | |
| 1464 } | |
| 1465 | |
| 1466 dyn = Dynarr_new (Lisp_Object); | |
| 1467 memset (lbs, 0, NUM_LEADING_BYTES * sizeof (int)); | |
| 1468 add_charsets_to_precedence_list (charsets, lbs, dyn); | |
| 1469 { | |
| 877 | 1470 Ichar ret = unicode_to_ichar (c, dyn); |
| 771 | 1471 Dynarr_free (dyn); |
| 1472 if (ret == -1) | |
| 1473 return Qnil; | |
| 1474 return make_char (ret); | |
| 1475 } | |
| 1476 #else | |
|
5307
c096d8051f89
Have NATNUMP give t for positive bignums; check limits appropriately.
Aidan Kehoe <kehoea@parhasard.net>
parents:
5157
diff
changeset
|
1477 check_integer_range (code, Qzero, make_integer (EMACS_INT_MAX)); |
| 771 | 1478 return Fint_to_char (code); |
| 1479 #endif /* MULE */ | |
| 1480 } | |
| 1481 | |
| 872 | 1482 #ifdef MULE |
| 1483 | |
| 771 | 1484 static Lisp_Object |
| 1485 cerrar_el_fulano (Lisp_Object fulano) | |
| 1486 { | |
| 1487 FILE *file = (FILE *) get_opaque_ptr (fulano); | |
| 1488 retry_fclose (file); | |
| 1489 return Qnil; | |
| 1490 } | |
| 1491 | |
| 1318 | 1492 DEFUN ("load-unicode-mapping-table", Fload_unicode_mapping_table, |
| 771 | 1493 2, 6, 0, /* |
| 877 | 1494 Load Unicode tables with the Unicode mapping data in FILENAME for CHARSET. |
| 771 | 1495 Data is text, in the form of one translation per line -- charset |
| 1496 codepoint followed by Unicode codepoint. Numbers are decimal or hex | |
| 1497 \(preceded by 0x). Comments are marked with a #. Charset codepoints | |
| 877 | 1498 for two-dimensional charsets have the first octet stored in the |
| 771 | 1499 high 8 bits of the hex number and the second in the low 8 bits. |
| 1500 | |
| 1501 If START and END are given, only charset codepoints within the given | |
| 877 | 1502 range will be processed. (START and END apply to the codepoints in the |
| 1503 file, before OFFSET is applied.) | |
| 771 | 1504 |
| 877 | 1505 If OFFSET is given, that value will be added to all charset codepoints |
| 1506 in the file to obtain the internal charset codepoint. \(We assume | |
| 1507 that octets in the table are in the range 33 to 126 or 32 to 127. If | |
| 1508 you have a table in ku-ten form, with octets in the range 1 to 94, you | |
| 1509 will have to use an offset of 5140, i.e. 0x2020.) | |
| 771 | 1510 |
| 1511 FLAGS, if specified, control further how the tables are interpreted | |
| 877 | 1512 and are used to special-case certain known format deviations in the |
| 1513 Unicode tables or in the charset: | |
| 771 | 1514 |
| 1515 `ignore-first-column' | |
| 877 | 1516 The JIS X 0208 tables have 3 columns of data instead of 2. The first |
| 1517 column contains the Shift-JIS codepoint, which we ignore. | |
| 771 | 1518 `big5' |
| 877 | 1519 The charset codepoints are Big Five codepoints; convert it to the |
| 1520 hacked-up Mule codepoint in `chinese-big5-1' or `chinese-big5-2'. | |
| 771 | 1521 */ |
| 1522 (filename, charset, start, end, offset, flags)) | |
| 1523 { | |
| 1524 int st = 0, en = INT_MAX, of = 0; | |
| 1525 FILE *file; | |
| 1526 struct gcpro gcpro1; | |
| 1527 char line[1025]; | |
| 1528 int fondo = specpdl_depth (); | |
| 1529 int ignore_first_column = 0; | |
| 1530 int big5 = 0; | |
| 1531 | |
| 1532 CHECK_STRING (filename); | |
| 1533 charset = Fget_charset (charset); | |
| 1534 if (!NILP (start)) | |
| 1535 { | |
| 1536 CHECK_INT (start); | |
| 1537 st = XINT (start); | |
| 1538 } | |
| 1539 if (!NILP (end)) | |
| 1540 { | |
| 1541 CHECK_INT (end); | |
| 1542 en = XINT (end); | |
| 1543 } | |
| 1544 if (!NILP (offset)) | |
| 1545 { | |
| 1546 CHECK_INT (offset); | |
| 1547 of = XINT (offset); | |
| 1548 } | |
| 1549 | |
| 1550 if (!LISTP (flags)) | |
| 1551 flags = list1 (flags); | |
| 1552 | |
| 1553 { | |
| 1554 EXTERNAL_LIST_LOOP_2 (elt, flags) | |
| 1555 { | |
| 1556 if (EQ (elt, Qignore_first_column)) | |
| 1557 ignore_first_column = 1; | |
| 1558 else if (EQ (elt, Qbig5)) | |
| 1559 big5 = 1; | |
| 1560 else | |
| 1561 invalid_constant | |
| 1318 | 1562 ("Unrecognized `load-unicode-mapping-table' flag", elt); |
| 771 | 1563 } |
| 1564 } | |
| 1565 | |
| 1566 GCPRO1 (filename); | |
| 1567 filename = Fexpand_file_name (filename, Qnil); | |
| 1568 file = qxe_fopen (XSTRING_DATA (filename), READ_TEXT); | |
| 1569 if (!file) | |
| 1570 report_file_error ("Cannot open", filename); | |
| 1571 record_unwind_protect (cerrar_el_fulano, make_opaque_ptr (file)); | |
| 1572 while (fgets (line, sizeof (line), file)) | |
| 1573 { | |
| 1574 char *p = line; | |
| 1575 int cp1, cp2, endcount; | |
| 1576 int cp1high, cp1low; | |
| 1577 int dummy; | |
| 1578 | |
| 1579 while (*p) /* erase all comments out of the line */ | |
| 1580 { | |
| 1581 if (*p == '#') | |
| 1582 *p = '\0'; | |
| 1583 else | |
| 1584 p++; | |
| 1585 } | |
| 1586 /* see if line is nothing but whitespace and skip if so */ | |
| 1587 p = line + strspn (line, " \t\n\r\f"); | |
| 1588 if (!*p) | |
| 1589 continue; | |
| 1590 /* NOTE: It appears that MS Windows and Newlib sscanf() have | |
| 1591 different interpretations for whitespace (== "skip all whitespace | |
| 1592 at processing point"): Newlib requires at least one corresponding | |
| 1593 whitespace character in the input, but MS allows none. The | |
| 1594 following would be easier to write if we could count on the MS | |
| 1595 interpretation. | |
| 1596 | |
| 1597 Also, the return value does NOT include %n storage. */ | |
| 1598 if ((!ignore_first_column ? | |
| 1599 sscanf (p, "%i %i%n", &cp1, &cp2, &endcount) < 2 : | |
| 1600 sscanf (p, "%i %i %i%n", &dummy, &cp1, &cp2, &endcount) < 3) | |
| 2367 | 1601 /* #### Temporary code! Cygwin newlib fucked up scanf() handling |
| 1602 of numbers beginning 0x0... starting in 04/2004, in an attempt | |
| 1603 to fix another bug. A partial fix for this was put in in | |
| 1604 06/2004, but as of 10/2004 the value of ENDCOUNT returned in | |
| 1605 such case is still wrong. If this gets fixed soon, remove | |
| 1606 this code. --ben */ | |
| 1607 #ifndef CYGWIN_SCANF_BUG | |
| 1608 || *(p + endcount + strspn (p + endcount, " \t\n\r\f")) | |
| 1609 #endif | |
| 1610 ) | |
| 771 | 1611 { |
| 793 | 1612 warn_when_safe (Qunicode, Qwarning, |
| 771 | 1613 "Unrecognized line in translation file %s:\n%s", |
| 1614 XSTRING_DATA (filename), line); | |
| 1615 continue; | |
| 1616 } | |
| 1617 if (cp1 >= st && cp1 <= en) | |
| 1618 { | |
| 1619 cp1 += of; | |
| 1620 if (cp1 < 0 || cp1 >= 65536) | |
| 1621 { | |
| 1622 out_of_range: | |
| 793 | 1623 warn_when_safe (Qunicode, Qwarning, |
| 1624 "Out of range first codepoint 0x%x in " | |
| 1625 "translation file %s:\n%s", | |
| 771 | 1626 cp1, XSTRING_DATA (filename), line); |
| 1627 continue; | |
| 1628 } | |
| 1629 | |
| 1630 cp1high = cp1 >> 8; | |
| 1631 cp1low = cp1 & 255; | |
| 1632 | |
| 1633 if (big5) | |
| 1634 { | |
| 867 | 1635 Ichar ch = decode_big5_char (cp1high, cp1low); |
| 771 | 1636 if (ch == -1) |
| 793 | 1637 |
| 1638 warn_when_safe (Qunicode, Qwarning, | |
| 1639 "Out of range Big5 codepoint 0x%x in " | |
| 1640 "translation file %s:\n%s", | |
| 771 | 1641 cp1, XSTRING_DATA (filename), line); |
| 1642 else | |
| 1643 set_unicode_conversion (ch, cp2); | |
| 1644 } | |
| 1645 else | |
| 1646 { | |
| 1647 int l1, h1, l2, h2; | |
| 867 | 1648 Ichar emch; |
| 771 | 1649 |
| 1650 switch (XCHARSET_TYPE (charset)) | |
| 1651 { | |
| 1652 case CHARSET_TYPE_94: l1 = 33; h1 = 126; l2 = 0; h2 = 0; break; | |
| 1653 case CHARSET_TYPE_96: l1 = 32; h1 = 127; l2 = 0; h2 = 0; break; | |
| 1654 case CHARSET_TYPE_94X94: l1 = 33; h1 = 126; l2 = 33; h2 = 126; | |
| 1655 break; | |
| 1656 case CHARSET_TYPE_96X96: l1 = 32; h1 = 127; l2 = 32; h2 = 127; | |
| 1657 break; | |
| 2500 | 1658 default: ABORT (); l1 = 0; h1 = 0; l2 = 0; h2 = 0; |
| 771 | 1659 } |
| 1660 | |
| 1661 if (cp1high < l2 || cp1high > h2 || cp1low < l1 || cp1low > h1) | |
| 1662 goto out_of_range; | |
| 1663 | |
| 867 | 1664 emch = (cp1high == 0 ? make_ichar (charset, cp1low, 0) : |
| 1665 make_ichar (charset, cp1high, cp1low)); | |
| 771 | 1666 set_unicode_conversion (emch, cp2); |
| 1667 } | |
| 1668 } | |
| 1669 } | |
| 1670 | |
| 1671 if (ferror (file)) | |
| 1672 report_file_error ("IO error when reading", filename); | |
| 1673 | |
| 1674 unbind_to (fondo); /* close file */ | |
| 1675 UNGCPRO; | |
| 1676 return Qnil; | |
| 1677 } | |
| 1678 | |
| 1679 #endif /* MULE */ | |
| 1680 | |
| 1681 | |
| 1682 /************************************************************************/ | |
| 1683 /* Unicode coding system */ | |
| 1684 /************************************************************************/ | |
| 1685 | |
| 1686 struct unicode_coding_system | |
| 1687 { | |
| 1688 enum unicode_type type; | |
| 1887 | 1689 unsigned int little_endian :1; |
| 1690 unsigned int need_bom :1; | |
| 771 | 1691 }; |
| 1692 | |
| 1693 #define CODING_SYSTEM_UNICODE_TYPE(codesys) \ | |
| 1694 (CODING_SYSTEM_TYPE_DATA (codesys, unicode)->type) | |
| 1695 #define XCODING_SYSTEM_UNICODE_TYPE(codesys) \ | |
| 1696 CODING_SYSTEM_UNICODE_TYPE (XCODING_SYSTEM (codesys)) | |
| 1697 #define CODING_SYSTEM_UNICODE_LITTLE_ENDIAN(codesys) \ | |
| 1698 (CODING_SYSTEM_TYPE_DATA (codesys, unicode)->little_endian) | |
| 1699 #define XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN(codesys) \ | |
| 1700 CODING_SYSTEM_UNICODE_LITTLE_ENDIAN (XCODING_SYSTEM (codesys)) | |
| 1701 #define CODING_SYSTEM_UNICODE_NEED_BOM(codesys) \ | |
| 1702 (CODING_SYSTEM_TYPE_DATA (codesys, unicode)->need_bom) | |
| 1703 #define XCODING_SYSTEM_UNICODE_NEED_BOM(codesys) \ | |
| 1704 CODING_SYSTEM_UNICODE_NEED_BOM (XCODING_SYSTEM (codesys)) | |
| 1705 | |
| 1706 struct unicode_coding_stream | |
| 1707 { | |
| 1708 /* decode */ | |
| 1709 unsigned char counter; | |
| 4096 | 1710 unsigned char indicated_length; |
| 771 | 1711 int seen_char; |
| 1712 /* encode */ | |
| 1713 Lisp_Object current_charset; | |
| 1714 int current_char_boundary; | |
| 1715 int wrote_bom; | |
| 1716 }; | |
| 1717 | |
| 1204 | 1718 static const struct memory_description unicode_coding_system_description[] = { |
| 771 | 1719 { XD_END } |
| 1720 }; | |
| 1721 | |
| 1204 | 1722 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (unicode); |
| 1723 | |
| 771 | 1724 static void |
| 1725 decode_unicode_char (int ch, unsigned_char_dynarr *dst, | |
| 1887 | 1726 struct unicode_coding_stream *data, |
| 1727 unsigned int ignore_bom) | |
| 771 | 1728 { |
| 1729 if (ch == 0xFEFF && !data->seen_char && ignore_bom) | |
| 1730 ; | |
| 1731 else | |
| 1732 { | |
| 1733 #ifdef MULE | |
| 877 | 1734 Ichar chr = unicode_to_ichar (ch, unicode_precedence_dynarr); |
| 771 | 1735 |
| 1736 if (chr != -1) | |
| 1737 { | |
| 867 | 1738 Ibyte work[MAX_ICHAR_LEN]; |
| 771 | 1739 int len; |
| 1740 | |
| 867 | 1741 len = set_itext_ichar (work, chr); |
| 771 | 1742 Dynarr_add_many (dst, work, len); |
| 1743 } | |
| 1744 else | |
| 1745 { | |
| 1746 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208); | |
| 1747 Dynarr_add (dst, 34 + 128); | |
| 1748 Dynarr_add (dst, 46 + 128); | |
| 1749 } | |
| 1750 #else | |
| 867 | 1751 Dynarr_add (dst, (Ibyte) ch); |
| 771 | 1752 #endif /* MULE */ |
| 1753 } | |
| 1754 | |
| 1755 data->seen_char = 1; | |
| 1756 } | |
| 1757 | |
| 4096 | 1758 #define DECODE_ERROR_OCTET(octet, dst, data, ignore_bom) \ |
| 1759 decode_unicode_char ((octet) + UNICODE_ERROR_OCTET_RANGE_START, \ | |
| 1760 dst, data, ignore_bom) | |
| 1761 | |
| 1762 static inline void | |
| 1763 indicate_invalid_utf_8 (unsigned char indicated_length, | |
| 1764 unsigned char counter, | |
| 1765 int ch, unsigned_char_dynarr *dst, | |
| 1766 struct unicode_coding_stream *data, | |
| 1767 unsigned int ignore_bom) | |
| 1768 { | |
| 1769 Binbyte stored = indicated_length - counter; | |
| 1770 Binbyte mask = "\x00\x00\xC0\xE0\xF0\xF8\xFC"[indicated_length]; | |
| 1771 | |
| 1772 while (stored > 0) | |
| 1773 { | |
| 1774 DECODE_ERROR_OCTET (((ch >> (6 * (stored - 1))) & 0x3f) | mask, | |
| 1775 dst, data, ignore_bom); | |
| 1776 mask = 0x80, stored--; | |
| 1777 } | |
| 1778 } | |
| 1779 | |
| 771 | 1780 static void |
| 1781 encode_unicode_char_1 (int code, unsigned_char_dynarr *dst, | |
| 4096 | 1782 enum unicode_type type, unsigned int little_endian, |
| 1783 int write_error_characters_as_such) | |
| 771 | 1784 { |
| 1785 switch (type) | |
| 1786 { | |
| 1787 case UNICODE_UTF_16: | |
| 1788 if (little_endian) | |
| 1789 { | |
| 3952 | 1790 if (code < 0x10000) { |
| 1791 Dynarr_add (dst, (unsigned char) (code & 255)); | |
| 1792 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255)); | |
| 4096 | 1793 } else if (write_error_characters_as_such && |
| 1794 code >= UNICODE_ERROR_OCTET_RANGE_START && | |
| 1795 code < (UNICODE_ERROR_OCTET_RANGE_START + 0x100)) | |
| 1796 { | |
| 1797 Dynarr_add (dst, (unsigned char) ((code & 0xFF))); | |
| 1798 } | |
| 1799 else if (code < 0x110000) | |
| 1800 { | |
| 1801 /* Little endian; least significant byte first. */ | |
| 1802 int first, second; | |
| 1803 | |
| 1804 CODE_TO_UTF_16_SURROGATES(code, first, second); | |
| 1805 | |
| 1806 Dynarr_add (dst, (unsigned char) (first & 255)); | |
| 1807 Dynarr_add (dst, (unsigned char) ((first >> 8) & 255)); | |
| 1808 | |
| 1809 Dynarr_add (dst, (unsigned char) (second & 255)); | |
| 1810 Dynarr_add (dst, (unsigned char) ((second >> 8) & 255)); | |
| 1811 } | |
| 1812 else | |
| 1813 { | |
| 1814 /* Not valid Unicode. Pass U+FFFD, least significant byte | |
| 1815 first. */ | |
| 1816 Dynarr_add (dst, (unsigned char) 0xFD); | |
| 1817 Dynarr_add (dst, (unsigned char) 0xFF); | |
| 1818 } | |
| 771 | 1819 } |
| 1820 else | |
| 1821 { | |
| 3952 | 1822 if (code < 0x10000) { |
| 1823 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255)); | |
| 1824 Dynarr_add (dst, (unsigned char) (code & 255)); | |
| 4096 | 1825 } else if (write_error_characters_as_such && |
| 1826 code >= UNICODE_ERROR_OCTET_RANGE_START && | |
| 1827 code < (UNICODE_ERROR_OCTET_RANGE_START + 0x100)) | |
| 1828 { | |
| 1829 Dynarr_add (dst, (unsigned char) ((code & 0xFF))); | |
| 1830 } | |
| 1831 else if (code < 0x110000) | |
| 1832 { | |
| 1833 /* Big endian; most significant byte first. */ | |
| 1834 int first, second; | |
| 1835 | |
| 1836 CODE_TO_UTF_16_SURROGATES(code, first, second); | |
| 1837 | |
| 1838 Dynarr_add (dst, (unsigned char) ((first >> 8) & 255)); | |
| 1839 Dynarr_add (dst, (unsigned char) (first & 255)); | |
| 1840 | |
| 1841 Dynarr_add (dst, (unsigned char) ((second >> 8) & 255)); | |
| 1842 Dynarr_add (dst, (unsigned char) (second & 255)); | |
| 1843 } | |
| 1844 else | |
| 1845 { | |
| 1846 /* Not valid Unicode. Pass U+FFFD, most significant byte | |
| 1847 first. */ | |
| 1848 Dynarr_add (dst, (unsigned char) 0xFF); | |
| 1849 Dynarr_add (dst, (unsigned char) 0xFD); | |
| 1850 } | |
| 771 | 1851 } |
| 1852 break; | |
| 1853 | |
| 1854 case UNICODE_UCS_4: | |
| 4096 | 1855 case UNICODE_UTF_32: |
| 771 | 1856 if (little_endian) |
| 1857 { | |
| 4096 | 1858 if (write_error_characters_as_such && |
| 1859 code >= UNICODE_ERROR_OCTET_RANGE_START && | |
| 1860 code < (UNICODE_ERROR_OCTET_RANGE_START + 0x100)) | |
| 1861 { | |
| 1862 Dynarr_add (dst, (unsigned char) ((code & 0xFF))); | |
| 1863 } | |
| 1864 else | |
| 1865 { | |
| 1866 /* We generate and accept incorrect sequences here, which is | |
| 1867 okay, in the interest of preservation of the user's | |
| 1868 data. */ | |
| 1869 Dynarr_add (dst, (unsigned char) (code & 255)); | |
| 1870 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255)); | |
| 1871 Dynarr_add (dst, (unsigned char) ((code >> 16) & 255)); | |
| 1872 Dynarr_add (dst, (unsigned char) (code >> 24)); | |
| 1873 } | |
| 771 | 1874 } |
| 1875 else | |
| 1876 { | |
| 4096 | 1877 if (write_error_characters_as_such && |
| 1878 code >= UNICODE_ERROR_OCTET_RANGE_START && | |
| 1879 code < (UNICODE_ERROR_OCTET_RANGE_START + 0x100)) | |
| 1880 { | |
| 1881 Dynarr_add (dst, (unsigned char) ((code & 0xFF))); | |
| 1882 } | |
| 1883 else | |
| 1884 { | |
| 1885 /* We generate and accept incorrect sequences here, which is okay, | |
| 1886 in the interest of preservation of the user's data. */ | |
| 1887 Dynarr_add (dst, (unsigned char) (code >> 24)); | |
| 1888 Dynarr_add (dst, (unsigned char) ((code >> 16) & 255)); | |
| 1889 Dynarr_add (dst, (unsigned char) ((code >> 8) & 255)); | |
| 1890 Dynarr_add (dst, (unsigned char) (code & 255)); | |
| 1891 } | |
| 771 | 1892 } |
| 1893 break; | |
| 1894 | |
| 1895 case UNICODE_UTF_8: | |
| 1896 if (code <= 0x7f) | |
| 1897 { | |
| 1898 Dynarr_add (dst, (unsigned char) code); | |
| 1899 } | |
| 1900 else if (code <= 0x7ff) | |
| 1901 { | |
| 1902 Dynarr_add (dst, (unsigned char) ((code >> 6) | 0xc0)); | |
| 1903 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80)); | |
| 1904 } | |
| 1905 else if (code <= 0xffff) | |
| 1906 { | |
| 1907 Dynarr_add (dst, (unsigned char) ((code >> 12) | 0xe0)); | |
| 1908 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80)); | |
| 1909 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80)); | |
| 1910 } | |
| 1911 else if (code <= 0x1fffff) | |
| 1912 { | |
| 1913 Dynarr_add (dst, (unsigned char) ((code >> 18) | 0xf0)); | |
| 1914 Dynarr_add (dst, (unsigned char) (((code >> 12) & 0x3f) | 0x80)); | |
| 1915 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80)); | |
| 1916 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80)); | |
| 1917 } | |
| 1918 else if (code <= 0x3ffffff) | |
| 1919 { | |
| 4096 | 1920 |
| 1921 #if !(UNICODE_ERROR_OCTET_RANGE_START > 0x1fffff \ | |
| 1922 && UNICODE_ERROR_OCTET_RANGE_START < 0x3ffffff) | |
| 1923 #error "This code needs to be rewritten. " | |
| 1924 #endif | |
| 1925 if (write_error_characters_as_such && | |
| 1926 code >= UNICODE_ERROR_OCTET_RANGE_START && | |
| 1927 code < (UNICODE_ERROR_OCTET_RANGE_START + 0x100)) | |
| 1928 { | |
| 1929 Dynarr_add (dst, (unsigned char) ((code & 0xFF))); | |
| 1930 } | |
| 1931 else | |
| 1932 { | |
| 1933 Dynarr_add (dst, (unsigned char) ((code >> 24) | 0xf8)); | |
| 1934 Dynarr_add (dst, (unsigned char) (((code >> 18) & 0x3f) | 0x80)); | |
| 1935 Dynarr_add (dst, (unsigned char) (((code >> 12) & 0x3f) | 0x80)); | |
| 1936 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80)); | |
| 1937 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80)); | |
| 1938 } | |
| 771 | 1939 } |
| 1940 else | |
| 1941 { | |
| 1942 Dynarr_add (dst, (unsigned char) ((code >> 30) | 0xfc)); | |
| 1943 Dynarr_add (dst, (unsigned char) (((code >> 24) & 0x3f) | 0x80)); | |
| 1944 Dynarr_add (dst, (unsigned char) (((code >> 18) & 0x3f) | 0x80)); | |
| 1945 Dynarr_add (dst, (unsigned char) (((code >> 12) & 0x3f) | 0x80)); | |
| 1946 Dynarr_add (dst, (unsigned char) (((code >> 6) & 0x3f) | 0x80)); | |
| 1947 Dynarr_add (dst, (unsigned char) ((code & 0x3f) | 0x80)); | |
| 1948 } | |
| 1949 break; | |
| 1950 | |
| 2500 | 1951 case UNICODE_UTF_7: ABORT (); |
| 771 | 1952 |
| 2500 | 1953 default: ABORT (); |
| 771 | 1954 } |
| 1955 } | |
| 1956 | |
| 3439 | 1957 /* Also used in mule-coding.c for UTF-8 handling in ISO 2022-oriented |
| 1958 encodings. */ | |
| 1959 void | |
| 2333 | 1960 encode_unicode_char (Lisp_Object USED_IF_MULE (charset), int h, |
| 1961 int USED_IF_MULE (l), unsigned_char_dynarr *dst, | |
| 4096 | 1962 enum unicode_type type, unsigned int little_endian, |
| 1963 int write_error_characters_as_such) | |
| 771 | 1964 { |
| 1965 #ifdef MULE | |
| 867 | 1966 int code = ichar_to_unicode (make_ichar (charset, h & 127, l & 127)); |
| 771 | 1967 |
| 1968 if (code == -1) | |
| 1969 { | |
| 1970 if (type != UNICODE_UTF_16 && | |
| 1971 XCHARSET_DIMENSION (charset) == 2 && | |
| 1972 XCHARSET_CHARS (charset) == 94) | |
| 1973 { | |
| 1974 unsigned char final = XCHARSET_FINAL (charset); | |
| 1975 | |
| 1976 if (('@' <= final) && (final < 0x7f)) | |
| 1977 code = (0xe00000 + (final - '@') * 94 * 94 | |
| 1978 + ((h & 127) - 33) * 94 + (l & 127) - 33); | |
| 1979 else | |
| 1980 code = '?'; | |
| 1981 } | |
| 1982 else | |
| 1983 code = '?'; | |
| 1984 } | |
| 1985 #else | |
| 1986 int code = h; | |
| 1987 #endif /* MULE */ | |
| 1988 | |
| 4096 | 1989 encode_unicode_char_1 (code, dst, type, little_endian, |
| 1990 write_error_characters_as_such); | |
| 771 | 1991 } |
| 1992 | |
| 1993 static Bytecount | |
| 1994 unicode_convert (struct coding_stream *str, const UExtbyte *src, | |
| 1995 unsigned_char_dynarr *dst, Bytecount n) | |
| 1996 { | |
| 1997 unsigned int ch = str->ch; | |
| 1998 struct unicode_coding_stream *data = CODING_STREAM_TYPE_DATA (str, unicode); | |
| 1999 enum unicode_type type = | |
| 2000 XCODING_SYSTEM_UNICODE_TYPE (str->codesys); | |
| 1887 | 2001 unsigned int little_endian = |
| 2002 XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (str->codesys); | |
| 2003 unsigned int ignore_bom = XCODING_SYSTEM_UNICODE_NEED_BOM (str->codesys); | |
| 771 | 2004 Bytecount orign = n; |
| 2005 | |
| 2006 if (str->direction == CODING_DECODE) | |
| 2007 { | |
| 2008 unsigned char counter = data->counter; | |
| 4096 | 2009 unsigned char indicated_length |
| 2010 = data->indicated_length; | |
| 771 | 2011 |
| 2012 while (n--) | |
| 2013 { | |
| 2014 UExtbyte c = *src++; | |
| 2015 | |
| 2016 switch (type) | |
| 2017 { | |
| 2018 case UNICODE_UTF_8: | |
| 4096 | 2019 if (0 == counter) |
| 2020 { | |
| 2021 if (0 == (c & 0x80)) | |
| 2022 { | |
| 2023 /* ASCII. */ | |
| 2024 decode_unicode_char (c, dst, data, ignore_bom); | |
| 2025 } | |
| 2026 else if (0 == (c & 0x40)) | |
| 2027 { | |
| 2028 /* Highest bit set, second highest not--there's | |
| 2029 something wrong. */ | |
| 2030 DECODE_ERROR_OCTET (c, dst, data, ignore_bom); | |
| 2031 } | |
| 2032 else if (0 == (c & 0x20)) | |
| 2033 { | |
| 2034 ch = c & 0x1f; | |
| 2035 counter = 1; | |
| 2036 indicated_length = 2; | |
| 2037 } | |
| 2038 else if (0 == (c & 0x10)) | |
| 2039 { | |
| 2040 ch = c & 0x0f; | |
| 2041 counter = 2; | |
| 2042 indicated_length = 3; | |
| 2043 } | |
| 2044 else if (0 == (c & 0x08)) | |
| 2045 { | |
| 2046 ch = c & 0x0f; | |
| 2047 counter = 3; | |
| 2048 indicated_length = 4; | |
| 2049 } | |
| 2050 else | |
| 2051 { | |
| 2052 /* We don't supports lengths longer than 4 in | |
| 2053 external-format data. */ | |
| 2054 DECODE_ERROR_OCTET (c, dst, data, ignore_bom); | |
| 2055 | |
| 2056 } | |
| 2057 } | |
| 2058 else | |
| 2059 { | |
| 2060 /* counter != 0 */ | |
| 2061 if ((0 == (c & 0x80)) || (0 != (c & 0x40))) | |
| 2062 { | |
| 2063 indicate_invalid_utf_8(indicated_length, | |
| 2064 counter, | |
| 2065 ch, dst, data, ignore_bom); | |
| 2066 if (c & 0x80) | |
| 2067 { | |
| 2068 DECODE_ERROR_OCTET (c, dst, data, ignore_bom); | |
| 2069 } | |
| 2070 else | |
| 2071 { | |
| 2072 /* The character just read is ASCII. Treat it as | |
| 2073 such. */ | |
| 2074 decode_unicode_char (c, dst, data, ignore_bom); | |
| 2075 } | |
| 2076 ch = 0; | |
| 2077 counter = 0; | |
| 2078 } | |
| 2079 else | |
| 2080 { | |
| 2081 ch = (ch << 6) | (c & 0x3f); | |
| 2082 counter--; | |
| 2083 /* Just processed the final byte. Emit the character. */ | |
| 2084 if (!counter) | |
| 2085 { | |
| 2086 /* Don't accept over-long sequences, surrogates, | |
| 2087 or codes above #x10FFFF. */ | |
| 2088 if ((ch < 0x80) || | |
| 2089 ((ch < 0x800) && indicated_length > 2) || | |
| 2090 ((ch < 0x10000) && indicated_length > 3) || | |
| 2091 valid_utf_16_surrogate(ch) || (ch > 0x110000)) | |
| 2092 { | |
| 2093 indicate_invalid_utf_8(indicated_length, | |
| 2094 counter, | |
| 2095 ch, dst, data, | |
| 2096 ignore_bom); | |
| 2097 } | |
| 2098 else | |
| 2099 { | |
| 2100 decode_unicode_char (ch, dst, data, ignore_bom); | |
| 2101 } | |
| 2102 ch = 0; | |
| 2103 } | |
| 2104 } | |
| 771 | 2105 } |
| 2106 break; | |
| 2107 | |
| 2108 case UNICODE_UTF_16: | |
| 3952 | 2109 |
| 771 | 2110 if (little_endian) |
| 2111 ch = (c << counter) | ch; | |
| 2112 else | |
| 2113 ch = (ch << 8) | c; | |
| 4096 | 2114 |
| 771 | 2115 counter += 8; |
| 3952 | 2116 |
| 4096 | 2117 if (16 == counter) |
| 2118 { | |
| 771 | 2119 int tempch = ch; |
| 4096 | 2120 |
| 2121 if (valid_utf_16_first_surrogate(ch)) | |
| 2122 { | |
| 2123 break; | |
| 2124 } | |
| 771 | 2125 ch = 0; |
| 2126 counter = 0; | |
| 2127 decode_unicode_char (tempch, dst, data, ignore_bom); | |
| 2128 } | |
| 4096 | 2129 else if (32 == counter) |
| 3952 | 2130 { |
| 2131 int tempch; | |
| 4096 | 2132 |
|
4583
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2133 if (little_endian) |
| 4096 | 2134 { |
|
4583
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2135 if (!valid_utf_16_last_surrogate(ch >> 16)) |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2136 { |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2137 DECODE_ERROR_OCTET (ch & 0xFF, dst, data, |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2138 ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2139 DECODE_ERROR_OCTET ((ch >> 8) & 0xFF, dst, data, |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2140 ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2141 DECODE_ERROR_OCTET ((ch >> 16) & 0xFF, dst, data, |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2142 ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2143 DECODE_ERROR_OCTET ((ch >> 24) & 0xFF, dst, data, |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2144 ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2145 } |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2146 else |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2147 { |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2148 tempch = utf_16_surrogates_to_code((ch & 0xffff), |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2149 (ch >> 16)); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2150 decode_unicode_char(tempch, dst, data, ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2151 } |
| 4096 | 2152 } |
|
4583
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2153 else |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2154 { |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2155 if (!valid_utf_16_last_surrogate(ch & 0xFFFF)) |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2156 { |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2157 DECODE_ERROR_OCTET ((ch >> 24) & 0xFF, dst, data, |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2158 ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2159 DECODE_ERROR_OCTET ((ch >> 16) & 0xFF, dst, data, |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2160 ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2161 DECODE_ERROR_OCTET ((ch >> 8) & 0xFF, dst, data, |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2162 ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2163 DECODE_ERROR_OCTET (ch & 0xFF, dst, data, |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2164 ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2165 } |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2166 else |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2167 { |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2168 tempch = utf_16_surrogates_to_code((ch >> 16), |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2169 (ch & 0xffff)); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2170 decode_unicode_char(tempch, dst, data, ignore_bom); |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2171 } |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2172 } |
|
2669b1b7e33b
Correct little-endian UTF-16 surrogate handling.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4270
diff
changeset
|
2173 |
| 3952 | 2174 ch = 0; |
| 2175 counter = 0; | |
| 4096 | 2176 } |
| 2177 else | |
| 2178 assert(8 == counter || 24 == counter); | |
| 771 | 2179 break; |
| 2180 | |
| 2181 case UNICODE_UCS_4: | |
| 4096 | 2182 case UNICODE_UTF_32: |
| 771 | 2183 if (little_endian) |
| 2184 ch = (c << counter) | ch; | |
| 2185 else | |
| 2186 ch = (ch << 8) | c; | |
| 2187 counter += 8; | |
| 2188 if (counter == 32) | |
| 2189 { | |
| 4096 | 2190 if (ch > 0x10ffff) |
| 2191 { | |
| 2192 /* ch is not a legal Unicode character. We're fine | |
| 2193 with that in UCS-4, though not in UTF-32. */ | |
| 2194 if (UNICODE_UCS_4 == type && ch < 0x80000000) | |
| 2195 { | |
| 2196 decode_unicode_char (ch, dst, data, ignore_bom); | |
| 2197 } | |
| 2198 else if (little_endian) | |
| 2199 { | |
| 2200 DECODE_ERROR_OCTET (ch & 0xFF, dst, data, | |
| 2201 ignore_bom); | |
| 2202 DECODE_ERROR_OCTET ((ch >> 8) & 0xFF, dst, data, | |
| 2203 ignore_bom); | |
| 2204 DECODE_ERROR_OCTET ((ch >> 16) & 0xFF, dst, data, | |
| 2205 ignore_bom); | |
| 2206 DECODE_ERROR_OCTET ((ch >> 24) & 0xFF, dst, data, | |
| 2207 ignore_bom); | |
| 2208 } | |
| 2209 else | |
| 2210 { | |
| 2211 DECODE_ERROR_OCTET ((ch >> 24) & 0xFF, dst, data, | |
| 2212 ignore_bom); | |
| 2213 DECODE_ERROR_OCTET ((ch >> 16) & 0xFF, dst, data, | |
| 2214 ignore_bom); | |
| 2215 DECODE_ERROR_OCTET ((ch >> 8) & 0xFF, dst, data, | |
| 2216 ignore_bom); | |
| 2217 DECODE_ERROR_OCTET (ch & 0xFF, dst, data, | |
| 2218 ignore_bom); | |
| 2219 } | |
| 2220 } | |
| 2221 else | |
| 2222 { | |
| 2223 decode_unicode_char (ch, dst, data, ignore_bom); | |
| 2224 } | |
| 771 | 2225 ch = 0; |
| 2226 counter = 0; | |
| 2227 } | |
| 2228 break; | |
| 2229 | |
| 2230 case UNICODE_UTF_7: | |
| 2500 | 2231 ABORT (); |
| 771 | 2232 break; |
| 2233 | |
| 2500 | 2234 default: ABORT (); |
| 771 | 2235 } |
| 2236 | |
| 2237 } | |
| 4096 | 2238 |
|
4688
7e54adf407a1
Fix a bug with Unicode error sequences and very short input strings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4583
diff
changeset
|
2239 if (str->eof && counter) |
| 4096 | 2240 { |
| 2241 switch (type) | |
| 2242 { | |
| 2243 case UNICODE_UTF_8: | |
| 2244 indicate_invalid_utf_8(indicated_length, | |
| 2245 counter, ch, dst, data, | |
| 2246 ignore_bom); | |
| 2247 break; | |
| 2248 | |
| 2249 case UNICODE_UTF_16: | |
| 2250 case UNICODE_UCS_4: | |
| 2251 case UNICODE_UTF_32: | |
| 2252 if (8 == counter) | |
| 2253 { | |
| 2254 DECODE_ERROR_OCTET (ch, dst, data, ignore_bom); | |
| 2255 } | |
| 2256 else if (16 == counter) | |
| 2257 { | |
| 2258 if (little_endian) | |
| 2259 { | |
| 2260 DECODE_ERROR_OCTET (ch & 0xFF, dst, data, ignore_bom); | |
| 2261 DECODE_ERROR_OCTET ((ch >> 8) & 0xFF, dst, data, | |
| 2262 ignore_bom); | |
| 2263 } | |
| 2264 else | |
| 2265 { | |
| 2266 DECODE_ERROR_OCTET ((ch >> 8) & 0xFF, dst, data, | |
| 2267 ignore_bom); | |
| 2268 DECODE_ERROR_OCTET (ch & 0xFF, dst, data, ignore_bom); | |
| 2269 } | |
| 2270 } | |
| 2271 else if (24 == counter) | |
| 2272 { | |
| 2273 if (little_endian) | |
| 2274 { | |
| 2275 DECODE_ERROR_OCTET ((ch >> 16) & 0xFF, dst, data, | |
| 2276 ignore_bom); | |
| 2277 DECODE_ERROR_OCTET (ch & 0xFF, dst, data, ignore_bom); | |
| 2278 DECODE_ERROR_OCTET ((ch >> 8) & 0xFF, dst, data, | |
| 2279 ignore_bom); | |
| 2280 } | |
| 2281 else | |
| 2282 { | |
| 2283 DECODE_ERROR_OCTET ((ch >> 16) & 0xFF, dst, data, | |
| 2284 ignore_bom); | |
| 2285 DECODE_ERROR_OCTET ((ch >> 8) & 0xFF, dst, data, | |
| 2286 ignore_bom); | |
| 2287 DECODE_ERROR_OCTET (ch & 0xFF, dst, data, | |
| 2288 ignore_bom); | |
| 2289 } | |
| 2290 } | |
| 2291 else assert(0); | |
| 2292 break; | |
| 2293 } | |
| 2294 ch = 0; | |
|
4688
7e54adf407a1
Fix a bug with Unicode error sequences and very short input strings.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4583
diff
changeset
|
2295 counter = 0; |
| 4096 | 2296 } |
| 771 | 2297 |
| 2298 data->counter = counter; | |
| 4096 | 2299 data->indicated_length = indicated_length; |
| 771 | 2300 } |
| 2301 else | |
| 2302 { | |
| 2303 unsigned char char_boundary = data->current_char_boundary; | |
| 2304 Lisp_Object charset = data->current_charset; | |
| 2305 | |
| 2306 #ifdef ENABLE_COMPOSITE_CHARS | |
| 2307 /* flags for handling composite chars. We do a little switcheroo | |
| 2308 on the source while we're outputting the composite char. */ | |
| 2309 Bytecount saved_n = 0; | |
| 867 | 2310 const Ibyte *saved_src = NULL; |
| 771 | 2311 int in_composite = 0; |
| 2312 | |
| 2313 back_to_square_n: | |
| 2314 #endif /* ENABLE_COMPOSITE_CHARS */ | |
| 2315 | |
| 2316 if (XCODING_SYSTEM_UNICODE_NEED_BOM (str->codesys) && !data->wrote_bom) | |
| 2317 { | |
| 4096 | 2318 encode_unicode_char_1 (0xFEFF, dst, type, little_endian, 1); |
| 771 | 2319 data->wrote_bom = 1; |
| 2320 } | |
| 2321 | |
| 2322 while (n--) | |
| 2323 { | |
| 867 | 2324 Ibyte c = *src++; |
| 771 | 2325 |
| 2326 #ifdef MULE | |
| 826 | 2327 if (byte_ascii_p (c)) |
| 771 | 2328 #endif /* MULE */ |
| 2329 { /* Processing ASCII character */ | |
| 2330 ch = 0; | |
| 2331 encode_unicode_char (Vcharset_ascii, c, 0, dst, type, | |
| 4096 | 2332 little_endian, 1); |
| 771 | 2333 |
| 2334 char_boundary = 1; | |
| 2335 } | |
| 2336 #ifdef MULE | |
| 867 | 2337 else if (ibyte_leading_byte_p (c) || ibyte_leading_byte_p (ch)) |
| 771 | 2338 { /* Processing Leading Byte */ |
| 2339 ch = 0; | |
| 826 | 2340 charset = charset_by_leading_byte (c); |
| 2341 if (leading_byte_prefix_p(c)) | |
| 771 | 2342 ch = c; |
| 2343 char_boundary = 0; | |
| 2344 } | |
| 2345 else | |
| 2346 { /* Processing Non-ASCII character */ | |
| 2347 char_boundary = 1; | |
| 2348 if (EQ (charset, Vcharset_control_1)) | |
| 2704 | 2349 /* See: |
| 2350 | |
| 2351 (Info-goto-node "(internals)Internal String Encoding") | |
| 2352 | |
| 2353 for the rationale behind subtracting #xa0 from the | |
| 2354 character's code. */ | |
| 2355 encode_unicode_char (Vcharset_control_1, c - 0xa0, 0, dst, | |
| 4096 | 2356 type, little_endian, 1); |
| 771 | 2357 else |
| 2358 { | |
| 2359 switch (XCHARSET_REP_BYTES (charset)) | |
| 2360 { | |
| 2361 case 2: | |
| 2362 encode_unicode_char (charset, c, 0, dst, type, | |
| 4096 | 2363 little_endian, 1); |
| 771 | 2364 break; |
| 2365 case 3: | |
| 2366 if (XCHARSET_PRIVATE_P (charset)) | |
| 2367 { | |
| 2368 encode_unicode_char (charset, c, 0, dst, type, | |
| 4096 | 2369 little_endian, 1); |
| 771 | 2370 ch = 0; |
| 2371 } | |
| 2372 else if (ch) | |
| 2373 { | |
| 2374 #ifdef ENABLE_COMPOSITE_CHARS | |
| 2375 if (EQ (charset, Vcharset_composite)) | |
| 2376 { | |
| 2377 if (in_composite) | |
| 2378 { | |
| 2379 /* #### Bother! We don't know how to | |
| 2380 handle this yet. */ | |
| 2381 encode_unicode_char (Vcharset_ascii, '~', 0, | |
| 2382 dst, type, | |
| 4096 | 2383 little_endian, 1); |
| 771 | 2384 } |
| 2385 else | |
| 2386 { | |
| 867 | 2387 Ichar emch = make_ichar (Vcharset_composite, |
| 771 | 2388 ch & 0x7F, |
| 2389 c & 0x7F); | |
| 2390 Lisp_Object lstr = | |
| 2391 composite_char_string (emch); | |
| 2392 saved_n = n; | |
| 2393 saved_src = src; | |
| 2394 in_composite = 1; | |
| 2395 src = XSTRING_DATA (lstr); | |
| 2396 n = XSTRING_LENGTH (lstr); | |
| 2397 } | |
| 2398 } | |
| 2399 else | |
| 2400 #endif /* ENABLE_COMPOSITE_CHARS */ | |
| 2401 encode_unicode_char (charset, ch, c, dst, type, | |
| 4096 | 2402 little_endian, 1); |
| 771 | 2403 ch = 0; |
| 2404 } | |
| 2405 else | |
| 2406 { | |
| 2407 ch = c; | |
| 2408 char_boundary = 0; | |
| 2409 } | |
| 2410 break; | |
| 2411 case 4: | |
| 2412 if (ch) | |
| 2413 { | |
| 2414 encode_unicode_char (charset, ch, c, dst, type, | |
| 4096 | 2415 little_endian, 1); |
| 771 | 2416 ch = 0; |
| 2417 } | |
| 2418 else | |
| 2419 { | |
| 2420 ch = c; | |
| 2421 char_boundary = 0; | |
| 2422 } | |
| 2423 break; | |
| 2424 default: | |
| 2500 | 2425 ABORT (); |
| 771 | 2426 } |
| 2427 } | |
| 2428 } | |
| 2429 #endif /* MULE */ | |
| 2430 } | |
| 2431 | |
| 2432 #ifdef ENABLE_COMPOSITE_CHARS | |
| 2433 if (in_composite) | |
| 2434 { | |
| 2435 n = saved_n; | |
| 2436 src = saved_src; | |
| 2437 in_composite = 0; | |
| 2438 goto back_to_square_n; /* Wheeeeeeeee ..... */ | |
| 2439 } | |
| 2440 #endif /* ENABLE_COMPOSITE_CHARS */ | |
| 2441 | |
| 2442 data->current_char_boundary = char_boundary; | |
| 2443 data->current_charset = charset; | |
| 2444 | |
| 2445 /* La palabra se hizo carne! */ | |
| 2446 /* A palavra fez-se carne! */ | |
| 2447 /* Whatever. */ | |
| 2448 } | |
| 2449 | |
| 2450 str->ch = ch; | |
| 2451 return orign; | |
| 2452 } | |
| 2453 | |
| 2454 /* DEFINE_DETECTOR (utf_7); */ | |
| 2455 DEFINE_DETECTOR (utf_8); | |
| 2456 DEFINE_DETECTOR_CATEGORY (utf_8, utf_8); | |
| 985 | 2457 DEFINE_DETECTOR_CATEGORY (utf_8, utf_8_bom); |
| 771 | 2458 DEFINE_DETECTOR (ucs_4); |
| 2459 DEFINE_DETECTOR_CATEGORY (ucs_4, ucs_4); | |
| 2460 DEFINE_DETECTOR (utf_16); | |
| 2461 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16); | |
| 2462 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian); | |
| 2463 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16_bom); | |
| 2464 DEFINE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian_bom); | |
| 2465 | |
| 2466 struct ucs_4_detector | |
| 2467 { | |
| 2468 int in_ucs_4_byte; | |
| 2469 }; | |
| 2470 | |
| 2471 static void | |
| 2472 ucs_4_detect (struct detection_state *st, const UExtbyte *src, | |
| 2473 Bytecount n) | |
| 2474 { | |
| 2475 struct ucs_4_detector *data = DETECTION_STATE_DATA (st, ucs_4); | |
| 2476 | |
| 2477 while (n--) | |
| 2478 { | |
| 2479 UExtbyte c = *src++; | |
| 2480 switch (data->in_ucs_4_byte) | |
| 2481 { | |
| 2482 case 0: | |
| 2483 if (c >= 128) | |
| 2484 { | |
| 2485 DET_RESULT (st, ucs_4) = DET_NEARLY_IMPOSSIBLE; | |
| 2486 return; | |
| 2487 } | |
| 2488 else | |
| 2489 data->in_ucs_4_byte++; | |
| 2490 break; | |
| 2491 case 3: | |
| 2492 data->in_ucs_4_byte = 0; | |
| 2493 break; | |
| 2494 default: | |
| 2495 data->in_ucs_4_byte++; | |
| 2496 } | |
| 2497 } | |
| 2498 | |
| 2499 /* !!#### write this for real */ | |
| 2500 DET_RESULT (st, ucs_4) = DET_AS_LIKELY_AS_UNLIKELY; | |
| 2501 } | |
| 2502 | |
| 2503 struct utf_16_detector | |
| 2504 { | |
| 2505 unsigned int seen_ffff:1; | |
| 2506 unsigned int seen_forward_bom:1; | |
| 2507 unsigned int seen_rev_bom:1; | |
| 2508 int byteno; | |
| 2509 int prev_char; | |
| 2510 int text, rev_text; | |
| 1267 | 2511 int sep, rev_sep; |
| 2512 int num_ascii; | |
| 771 | 2513 }; |
| 2514 | |
| 2515 static void | |
| 2516 utf_16_detect (struct detection_state *st, const UExtbyte *src, | |
| 2517 Bytecount n) | |
| 2518 { | |
| 2519 struct utf_16_detector *data = DETECTION_STATE_DATA (st, utf_16); | |
| 2520 | |
| 2521 while (n--) | |
| 2522 { | |
| 2523 UExtbyte c = *src++; | |
| 2524 int prevc = data->prev_char; | |
| 2525 if (data->byteno == 1 && c == 0xFF && prevc == 0xFE) | |
| 2526 data->seen_forward_bom = 1; | |
| 2527 else if (data->byteno == 1 && c == 0xFE && prevc == 0xFF) | |
| 2528 data->seen_rev_bom = 1; | |
| 2529 | |
| 2530 if (data->byteno & 1) | |
| 2531 { | |
| 2532 if (c == 0xFF && prevc == 0xFF) | |
| 2533 data->seen_ffff = 1; | |
| 2534 if (prevc == 0 | |
| 2535 && (c == '\r' || c == '\n' | |
| 2536 || (c >= 0x20 && c <= 0x7E))) | |
| 2537 data->text++; | |
| 2538 if (c == 0 | |
| 2539 && (prevc == '\r' || prevc == '\n' | |
| 2540 || (prevc >= 0x20 && prevc <= 0x7E))) | |
| 2541 data->rev_text++; | |
| 1267 | 2542 /* #### 0x2028 is LINE SEPARATOR and 0x2029 is PARAGRAPH SEPARATOR. |
| 2543 I used to count these in text and rev_text but that is very bad, | |
| 2544 as 0x2028 is also space + left-paren in ASCII, which is extremely | |
| 2545 common. So, what do we do with these? */ | |
| 771 | 2546 if (prevc == 0x20 && (c == 0x28 || c == 0x29)) |
| 1267 | 2547 data->sep++; |
| 771 | 2548 if (c == 0x20 && (prevc == 0x28 || prevc == 0x29)) |
| 1267 | 2549 data->rev_sep++; |
| 771 | 2550 } |
| 2551 | |
| 1267 | 2552 if ((c >= ' ' && c <= '~') || c == '\n' || c == '\r' || c == '\t' || |
| 2553 c == '\f' || c == '\v') | |
| 2554 data->num_ascii++; | |
| 771 | 2555 data->byteno++; |
| 2556 data->prev_char = c; | |
| 2557 } | |
| 2558 | |
| 2559 { | |
| 2560 int variance_indicates_big_endian = | |
| 2561 (data->text >= 10 | |
| 2562 && (data->rev_text == 0 | |
| 2563 || data->text / data->rev_text >= 10)); | |
| 2564 int variance_indicates_little_endian = | |
| 2565 (data->rev_text >= 10 | |
| 2566 && (data->text == 0 | |
| 2567 || data->rev_text / data->text >= 10)); | |
| 2568 | |
| 2569 if (data->seen_ffff) | |
| 2570 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE); | |
| 2571 else if (data->seen_forward_bom) | |
| 2572 { | |
| 2573 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE); | |
| 2574 if (variance_indicates_big_endian) | |
| 2575 DET_RESULT (st, utf_16_bom) = DET_NEAR_CERTAINTY; | |
| 2576 else if (variance_indicates_little_endian) | |
| 2577 DET_RESULT (st, utf_16_bom) = DET_SOMEWHAT_LIKELY; | |
| 2578 else | |
| 2579 DET_RESULT (st, utf_16_bom) = DET_QUITE_PROBABLE; | |
| 2580 } | |
| 2581 else if (data->seen_forward_bom) | |
| 2582 { | |
| 2583 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE); | |
| 2584 if (variance_indicates_big_endian) | |
| 2585 DET_RESULT (st, utf_16_bom) = DET_NEAR_CERTAINTY; | |
| 2586 else if (variance_indicates_little_endian) | |
| 2587 /* #### may need to rethink */ | |
| 2588 DET_RESULT (st, utf_16_bom) = DET_SOMEWHAT_LIKELY; | |
| 2589 else | |
| 2590 /* #### may need to rethink */ | |
| 2591 DET_RESULT (st, utf_16_bom) = DET_QUITE_PROBABLE; | |
| 2592 } | |
| 2593 else if (data->seen_rev_bom) | |
| 2594 { | |
| 2595 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE); | |
| 2596 if (variance_indicates_little_endian) | |
| 2597 DET_RESULT (st, utf_16_little_endian_bom) = DET_NEAR_CERTAINTY; | |
| 2598 else if (variance_indicates_big_endian) | |
| 2599 /* #### may need to rethink */ | |
| 2600 DET_RESULT (st, utf_16_little_endian_bom) = DET_SOMEWHAT_LIKELY; | |
| 2601 else | |
| 2602 /* #### may need to rethink */ | |
| 2603 DET_RESULT (st, utf_16_little_endian_bom) = DET_QUITE_PROBABLE; | |
| 2604 } | |
| 2605 else if (variance_indicates_big_endian) | |
| 2606 { | |
| 2607 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE); | |
| 2608 DET_RESULT (st, utf_16) = DET_SOMEWHAT_LIKELY; | |
| 2609 DET_RESULT (st, utf_16_little_endian) = DET_SOMEWHAT_UNLIKELY; | |
| 2610 } | |
| 2611 else if (variance_indicates_little_endian) | |
| 2612 { | |
| 2613 SET_DET_RESULTS (st, utf_16, DET_NEARLY_IMPOSSIBLE); | |
| 2614 DET_RESULT (st, utf_16) = DET_SOMEWHAT_UNLIKELY; | |
| 2615 DET_RESULT (st, utf_16_little_endian) = DET_SOMEWHAT_LIKELY; | |
| 2616 } | |
| 2617 else | |
| 1267 | 2618 { |
| 2619 /* #### FUCKME! There should really be an ASCII detector. This | |
| 2620 would rule out the need to have this built-in here as | |
| 2621 well. --ben */ | |
| 1292 | 2622 int pct_ascii = data->byteno ? (100 * data->num_ascii) / data->byteno |
| 2623 : 100; | |
| 1267 | 2624 |
| 2625 if (pct_ascii > 90) | |
| 2626 SET_DET_RESULTS (st, utf_16, DET_QUITE_IMPROBABLE); | |
| 2627 else if (pct_ascii > 75) | |
| 2628 SET_DET_RESULTS (st, utf_16, DET_SOMEWHAT_UNLIKELY); | |
| 2629 else | |
| 2630 SET_DET_RESULTS (st, utf_16, DET_AS_LIKELY_AS_UNLIKELY); | |
| 2631 } | |
| 771 | 2632 } |
| 2633 } | |
| 2634 | |
| 2635 struct utf_8_detector | |
| 2636 { | |
| 985 | 2637 int byteno; |
| 2638 int first_byte; | |
| 2639 int second_byte; | |
| 1267 | 2640 int prev_byte; |
| 771 | 2641 int in_utf_8_byte; |
| 1267 | 2642 int recent_utf_8_sequence; |
| 2643 int seen_bogus_utf8; | |
| 2644 int seen_really_bogus_utf8; | |
| 2645 int seen_2byte_sequence; | |
| 2646 int seen_longer_sequence; | |
| 2647 int seen_iso2022_esc; | |
| 2648 int seen_iso_shift; | |
| 1887 | 2649 unsigned int seen_utf_bom:1; |
| 771 | 2650 }; |
| 2651 | |
| 2652 static void | |
| 2653 utf_8_detect (struct detection_state *st, const UExtbyte *src, | |
| 2654 Bytecount n) | |
| 2655 { | |
| 2656 struct utf_8_detector *data = DETECTION_STATE_DATA (st, utf_8); | |
| 2657 | |
| 2658 while (n--) | |
| 2659 { | |
| 2660 UExtbyte c = *src++; | |
| 985 | 2661 switch (data->byteno) |
| 2662 { | |
| 2663 case 0: | |
| 2664 data->first_byte = c; | |
| 2665 break; | |
| 2666 case 1: | |
| 2667 data->second_byte = c; | |
| 2668 break; | |
| 2669 case 2: | |
| 2670 if (data->first_byte == 0xef && | |
| 2671 data->second_byte == 0xbb && | |
| 2672 c == 0xbf) | |
| 1267 | 2673 data->seen_utf_bom = 1; |
| 985 | 2674 break; |
| 2675 } | |
| 2676 | |
| 771 | 2677 switch (data->in_utf_8_byte) |
| 2678 { | |
| 2679 case 0: | |
| 1267 | 2680 if (data->prev_byte == ISO_CODE_ESC && c >= 0x28 && c <= 0x2F) |
| 2681 data->seen_iso2022_esc++; | |
| 2682 else if (c == ISO_CODE_SI || c == ISO_CODE_SO) | |
| 2683 data->seen_iso_shift++; | |
| 771 | 2684 else if (c >= 0xfc) |
| 2685 data->in_utf_8_byte = 5; | |
| 2686 else if (c >= 0xf8) | |
| 2687 data->in_utf_8_byte = 4; | |
| 2688 else if (c >= 0xf0) | |
| 2689 data->in_utf_8_byte = 3; | |
| 2690 else if (c >= 0xe0) | |
| 2691 data->in_utf_8_byte = 2; | |
| 2692 else if (c >= 0xc0) | |
| 2693 data->in_utf_8_byte = 1; | |
| 2694 else if (c >= 0x80) | |
| 1267 | 2695 data->seen_bogus_utf8++; |
| 2696 if (data->in_utf_8_byte > 0) | |
| 2697 data->recent_utf_8_sequence = data->in_utf_8_byte; | |
| 771 | 2698 break; |
| 2699 default: | |
| 2700 if ((c & 0xc0) != 0x80) | |
| 1267 | 2701 data->seen_really_bogus_utf8++; |
| 2702 else | |
| 771 | 2703 { |
| 1267 | 2704 data->in_utf_8_byte--; |
| 2705 if (data->in_utf_8_byte == 0) | |
| 2706 { | |
| 2707 if (data->recent_utf_8_sequence == 1) | |
| 2708 data->seen_2byte_sequence++; | |
| 2709 else | |
| 2710 { | |
| 2711 assert (data->recent_utf_8_sequence >= 2); | |
| 2712 data->seen_longer_sequence++; | |
| 2713 } | |
| 2714 } | |
| 771 | 2715 } |
| 2716 } | |
| 985 | 2717 |
| 2718 data->byteno++; | |
| 1267 | 2719 data->prev_byte = c; |
| 771 | 2720 } |
| 1267 | 2721 |
| 2722 /* either BOM or no BOM, but not both */ | |
| 2723 SET_DET_RESULTS (st, utf_8, DET_NEARLY_IMPOSSIBLE); | |
| 2724 | |
| 2725 | |
| 2726 if (data->seen_utf_bom) | |
| 2727 DET_RESULT (st, utf_8_bom) = DET_NEAR_CERTAINTY; | |
| 2728 else | |
| 2729 { | |
| 2730 if (data->seen_really_bogus_utf8 || | |
| 2731 data->seen_bogus_utf8 >= 2) | |
| 2732 ; /* bogus */ | |
| 2733 else if (data->seen_bogus_utf8) | |
| 2734 DET_RESULT (st, utf_8) = DET_SOMEWHAT_UNLIKELY; | |
| 2735 else if ((data->seen_longer_sequence >= 5 || | |
| 2736 data->seen_2byte_sequence >= 10) && | |
| 2737 (!(data->seen_iso2022_esc + data->seen_iso_shift) || | |
| 2738 (data->seen_longer_sequence * 2 + data->seen_2byte_sequence) / | |
| 2739 (data->seen_iso2022_esc + data->seen_iso_shift) >= 10)) | |
| 2740 /* heuristics, heuristics, we love heuristics */ | |
| 2741 DET_RESULT (st, utf_8) = DET_QUITE_PROBABLE; | |
| 2742 else if (data->seen_iso2022_esc || | |
| 2743 data->seen_iso_shift >= 3) | |
| 2744 DET_RESULT (st, utf_8) = DET_SOMEWHAT_UNLIKELY; | |
| 2745 else if (data->seen_longer_sequence || | |
| 2746 data->seen_2byte_sequence) | |
| 2747 DET_RESULT (st, utf_8) = DET_SOMEWHAT_LIKELY; | |
| 2748 else if (data->seen_iso_shift) | |
| 2749 DET_RESULT (st, utf_8) = DET_SOMEWHAT_UNLIKELY; | |
| 2750 else | |
| 2751 DET_RESULT (st, utf_8) = DET_AS_LIKELY_AS_UNLIKELY; | |
| 2752 } | |
| 771 | 2753 } |
| 2754 | |
| 2755 static void | |
| 2756 unicode_init_coding_stream (struct coding_stream *str) | |
| 2757 { | |
| 2758 struct unicode_coding_stream *data = | |
| 2759 CODING_STREAM_TYPE_DATA (str, unicode); | |
| 2760 xzero (*data); | |
| 2761 data->current_charset = Qnil; | |
| 2762 } | |
| 2763 | |
| 2764 static void | |
| 2765 unicode_rewind_coding_stream (struct coding_stream *str) | |
| 2766 { | |
| 2767 unicode_init_coding_stream (str); | |
| 2768 } | |
| 2769 | |
| 2770 static int | |
| 2771 unicode_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value) | |
| 2772 { | |
| 3767 | 2773 if (EQ (key, Qunicode_type)) |
| 771 | 2774 { |
| 2775 enum unicode_type type; | |
| 2776 | |
| 2777 if (EQ (value, Qutf_8)) | |
| 2778 type = UNICODE_UTF_8; | |
| 2779 else if (EQ (value, Qutf_16)) | |
| 2780 type = UNICODE_UTF_16; | |
| 2781 else if (EQ (value, Qutf_7)) | |
| 2782 type = UNICODE_UTF_7; | |
| 2783 else if (EQ (value, Qucs_4)) | |
| 2784 type = UNICODE_UCS_4; | |
| 4096 | 2785 else if (EQ (value, Qutf_32)) |
| 2786 type = UNICODE_UTF_32; | |
| 771 | 2787 else |
| 2788 invalid_constant ("Invalid Unicode type", key); | |
| 2789 | |
| 2790 XCODING_SYSTEM_UNICODE_TYPE (codesys) = type; | |
| 2791 } | |
| 2792 else if (EQ (key, Qlittle_endian)) | |
| 2793 XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (codesys) = !NILP (value); | |
| 2794 else if (EQ (key, Qneed_bom)) | |
| 2795 XCODING_SYSTEM_UNICODE_NEED_BOM (codesys) = !NILP (value); | |
| 2796 else | |
| 2797 return 0; | |
| 2798 return 1; | |
| 2799 } | |
| 2800 | |
| 2801 static Lisp_Object | |
| 2802 unicode_getprop (Lisp_Object coding_system, Lisp_Object prop) | |
| 2803 { | |
| 3767 | 2804 if (EQ (prop, Qunicode_type)) |
| 771 | 2805 { |
| 2806 switch (XCODING_SYSTEM_UNICODE_TYPE (coding_system)) | |
| 2807 { | |
| 2808 case UNICODE_UTF_16: return Qutf_16; | |
| 2809 case UNICODE_UTF_8: return Qutf_8; | |
| 2810 case UNICODE_UTF_7: return Qutf_7; | |
| 2811 case UNICODE_UCS_4: return Qucs_4; | |
| 4096 | 2812 case UNICODE_UTF_32: return Qutf_32; |
| 2500 | 2813 default: ABORT (); |
| 771 | 2814 } |
| 2815 } | |
| 2816 else if (EQ (prop, Qlittle_endian)) | |
| 2817 return XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (coding_system) ? Qt : Qnil; | |
| 2818 else if (EQ (prop, Qneed_bom)) | |
| 2819 return XCODING_SYSTEM_UNICODE_NEED_BOM (coding_system) ? Qt : Qnil; | |
| 2820 return Qunbound; | |
| 2821 } | |
| 2822 | |
| 2823 static void | |
| 2286 | 2824 unicode_print (Lisp_Object cs, Lisp_Object printcharfun, |
| 2825 int UNUSED (escapeflag)) | |
| 771 | 2826 { |
| 3767 | 2827 write_fmt_string_lisp (printcharfun, "(%s", 1, |
| 2828 unicode_getprop (cs, Qunicode_type)); | |
| 771 | 2829 if (XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (cs)) |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
2830 write_ascstring (printcharfun, ", little-endian"); |
| 771 | 2831 if (XCODING_SYSTEM_UNICODE_NEED_BOM (cs)) |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
2832 write_ascstring (printcharfun, ", need-bom"); |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
2833 write_ascstring (printcharfun, ")"); |
| 771 | 2834 } |
| 2835 | |
|
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2836 #ifdef MULE |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2837 DEFUN ("set-unicode-query-skip-chars-args", Fset_unicode_query_skip_chars_args, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2838 3, 3, 0, /* |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2839 Specify strings as matching characters known to Unicode coding systems. |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2840 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2841 QUERY-STRING is a string matching characters that can unequivocally be |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2842 encoded by the Unicode coding systems. |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2843 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2844 INVALID-STRING is a string to match XEmacs characters that represent known |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2845 octets on disk, but that are invalid sequences according to Unicode. |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2846 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2847 UTF-8-INVALID-STRING is a more restrictive string to match XEmacs characters |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2848 that are invalid UTF-8 octets. |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2849 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2850 All three strings are in the format accepted by `skip-chars-forward'. |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2851 */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2852 (query_string, invalid_string, utf_8_invalid_string)) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2853 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2854 CHECK_STRING (query_string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2855 CHECK_STRING (invalid_string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2856 CHECK_STRING (utf_8_invalid_string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2857 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2858 Vunicode_query_string = query_string; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2859 Vunicode_invalid_string = invalid_string; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2860 Vutf_8_invalid_string = utf_8_invalid_string; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2861 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2862 return Qnil; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2863 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2864 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2865 static void |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2866 add_lisp_string_to_skip_chars_range (Lisp_Object string, Lisp_Object rtab, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2867 Lisp_Object value) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2868 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2869 Ibyte *p, *pend; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2870 Ichar c; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2871 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2872 p = XSTRING_DATA (string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2873 pend = p + XSTRING_LENGTH (string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2874 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2875 while (p != pend) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2876 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2877 c = itext_ichar (p); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2878 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2879 INC_IBYTEPTR (p); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2880 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2881 if (c == '\\') |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2882 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2883 if (p == pend) break; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2884 c = itext_ichar (p); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2885 INC_IBYTEPTR (p); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2886 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2887 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2888 if (p != pend && *p == '-') |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2889 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2890 Ichar cend; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2891 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2892 /* Skip over the dash. */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2893 p++; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2894 if (p == pend) break; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2895 cend = itext_ichar (p); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2896 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2897 Fput_range_table (make_int (c), make_int (cend), value, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2898 rtab); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2899 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2900 INC_IBYTEPTR (p); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2901 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2902 else |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2903 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2904 Fput_range_table (make_int (c), make_int (c), value, rtab); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2905 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2906 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2907 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2908 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2909 /* This function wouldn't be necessary if initialised range tables were |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2910 dumped properly; see |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2911 http://mid.gmane.org/18179.49815.622843.336527@parhasard.net . */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2912 static void |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2913 initialize_unicode_query_range_tables_from_strings (void) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2914 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2915 CHECK_STRING (Vunicode_query_string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2916 CHECK_STRING (Vunicode_invalid_string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2917 CHECK_STRING (Vutf_8_invalid_string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2918 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2919 Vunicode_query_skip_chars = Fmake_range_table (Qstart_closed_end_closed); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2920 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2921 add_lisp_string_to_skip_chars_range (Vunicode_query_string, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2922 Vunicode_query_skip_chars, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2923 Qsucceeded); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2924 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2925 Vunicode_invalid_and_query_skip_chars |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2926 = Fcopy_range_table (Vunicode_query_skip_chars); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2927 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2928 add_lisp_string_to_skip_chars_range (Vunicode_invalid_string, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2929 Vunicode_invalid_and_query_skip_chars, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2930 Qinvalid_sequence); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2931 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2932 Vutf_8_invalid_and_query_skip_chars |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2933 = Fcopy_range_table (Vunicode_query_skip_chars); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2934 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2935 add_lisp_string_to_skip_chars_range (Vutf_8_invalid_string, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2936 Vutf_8_invalid_and_query_skip_chars, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2937 Qinvalid_sequence); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2938 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2939 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2940 static Lisp_Object |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2941 unicode_query (Lisp_Object codesys, struct buffer *buf, Charbpos end, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2942 int flags) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2943 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2944 Charbpos pos = BUF_PT (buf), fail_range_start, fail_range_end; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2945 Charbpos pos_byte = BYTE_BUF_PT (buf); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2946 Lisp_Object skip_chars_range_table, result = Qnil; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2947 enum query_coding_failure_reasons failed_reason, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2948 previous_failed_reason = query_coding_succeeded; |
|
4824
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4770
diff
changeset
|
2949 int checked_unicode, |
|
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4770
diff
changeset
|
2950 invalid_lower_limit = UNICODE_ERROR_OCTET_RANGE_START, |
|
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4770
diff
changeset
|
2951 invalid_upper_limit = -1, |
|
c12b646d84ee
changes to get things to compile under latest cygwin
Ben Wing <ben@xemacs.org>
parents:
4770
diff
changeset
|
2952 unicode_type = XCODING_SYSTEM_UNICODE_TYPE (codesys); |
|
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2953 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2954 if (flags & QUERY_METHOD_HIGHLIGHT && |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2955 /* If we're being called really early, live without highlights getting |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2956 cleared properly: */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2957 !(UNBOUNDP (XSYMBOL (Qquery_coding_clear_highlights)->function))) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2958 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2959 /* It's okay to call Lisp here, the only non-stack object we may have |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2960 allocated up to this point is skip_chars_range_table, and that's |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2961 reachable from its entry in Vfixed_width_query_ranges_cache. */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2962 call3 (Qquery_coding_clear_highlights, make_int (pos), make_int (end), |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2963 wrap_buffer (buf)); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2964 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2965 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2966 if (NILP (Vunicode_query_skip_chars)) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2967 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2968 initialize_unicode_query_range_tables_from_strings(); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2969 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2970 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2971 if (flags & QUERY_METHOD_IGNORE_INVALID_SEQUENCES) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2972 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2973 switch (unicode_type) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2974 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2975 case UNICODE_UTF_8: |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2976 skip_chars_range_table = Vutf_8_invalid_and_query_skip_chars; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2977 break; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2978 case UNICODE_UTF_7: |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2979 /* #### See above. */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2980 return Qunbound; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2981 break; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2982 default: |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2983 skip_chars_range_table = Vunicode_invalid_and_query_skip_chars; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2984 break; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2985 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2986 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2987 else |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2988 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2989 switch (unicode_type) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2990 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2991 case UNICODE_UTF_8: |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2992 invalid_lower_limit = UNICODE_ERROR_OCTET_RANGE_START + 0x80; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2993 invalid_upper_limit = UNICODE_ERROR_OCTET_RANGE_START + 0xFF; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2994 break; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2995 case UNICODE_UTF_7: |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2996 /* #### Work out what to do here in reality, read the spec and decide |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2997 which octets are invalid. */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2998 return Qunbound; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
2999 break; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3000 default: |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3001 invalid_lower_limit = UNICODE_ERROR_OCTET_RANGE_START; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3002 invalid_upper_limit = UNICODE_ERROR_OCTET_RANGE_START + 0xFF; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3003 break; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3004 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3005 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3006 skip_chars_range_table = Vunicode_query_skip_chars; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3007 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3008 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3009 while (pos < end) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3010 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3011 Ichar ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3012 if ((ch < 0x100 ? 1 : |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3013 (!EQ (Qnil, Fget_range_table (make_int (ch), skip_chars_range_table, |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3014 Qnil))))) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3015 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3016 pos++; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3017 INC_BYTEBPOS (buf, pos_byte); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3018 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3019 else |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3020 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3021 fail_range_start = pos; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3022 while ((pos < end) && |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3023 ((checked_unicode = ichar_to_unicode (ch), |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3024 -1 == checked_unicode |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3025 && (failed_reason = query_coding_unencodable)) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3026 || (!(flags & QUERY_METHOD_IGNORE_INVALID_SEQUENCES) && |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3027 (invalid_lower_limit <= checked_unicode) && |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3028 (checked_unicode <= invalid_upper_limit) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3029 && (failed_reason = query_coding_invalid_sequence))) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3030 && (previous_failed_reason == query_coding_succeeded |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3031 || previous_failed_reason == failed_reason)) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3032 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3033 pos++; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3034 INC_BYTEBPOS (buf, pos_byte); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3035 ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3036 previous_failed_reason = failed_reason; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3037 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3038 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3039 if (fail_range_start == pos) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3040 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3041 /* The character can actually be encoded; move on. */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3042 pos++; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3043 INC_BYTEBPOS (buf, pos_byte); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3044 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3045 else |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3046 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3047 assert (previous_failed_reason == query_coding_invalid_sequence |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3048 || previous_failed_reason == query_coding_unencodable); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3049 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3050 if (flags & QUERY_METHOD_ERRORP) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3051 { |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3052 signal_error_2 |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3053 (Qtext_conversion_error, |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3054 "Cannot encode using coding system", |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3055 make_string_from_buffer (buf, fail_range_start, |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3056 pos - fail_range_start), |
|
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3057 XCODING_SYSTEM_NAME (codesys)); |
|
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3058 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3059 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3060 if (NILP (result)) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3061 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3062 result = Fmake_range_table (Qstart_closed_end_open); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3063 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3064 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3065 fail_range_end = pos; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3066 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3067 Fput_range_table (make_int (fail_range_start), |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3068 make_int (fail_range_end), |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3069 (previous_failed_reason |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3070 == query_coding_unencodable ? |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3071 Qunencodable : Qinvalid_sequence), |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3072 result); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3073 previous_failed_reason = query_coding_succeeded; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3074 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3075 if (flags & QUERY_METHOD_HIGHLIGHT) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3076 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3077 Lisp_Object extent |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3078 = Fmake_extent (make_int (fail_range_start), |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3079 make_int (fail_range_end), |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3080 wrap_buffer (buf)); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3081 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3082 Fset_extent_priority |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3083 (extent, make_int (2 + mouse_highlight_priority)); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3084 Fset_extent_face (extent, Qquery_coding_warning_face); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3085 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3086 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3087 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3088 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3089 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3090 return result; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3091 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3092 #else /* !MULE */ |
|
4770
b9aaf2a18957
Add missing return value type to unicode_query.
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4690
diff
changeset
|
3093 static Lisp_Object |
|
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3094 unicode_query (Lisp_Object UNUSED (codesys), |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3095 struct buffer * UNUSED (buf), |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3096 Charbpos UNUSED (end), int UNUSED (flags)) |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3097 { |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3098 return Qnil; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3099 } |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3100 #endif |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3101 |
| 771 | 3102 int |
| 2286 | 3103 dfc_coding_system_is_unicode ( |
| 3104 #ifdef WIN32_ANY | |
| 3105 Lisp_Object codesys | |
| 3106 #else | |
| 3107 Lisp_Object UNUSED (codesys) | |
| 3108 #endif | |
| 3109 ) | |
| 771 | 3110 { |
| 1315 | 3111 #ifdef WIN32_ANY |
| 771 | 3112 codesys = Fget_coding_system (codesys); |
| 3113 return (EQ (XCODING_SYSTEM_TYPE (codesys), Qunicode) && | |
| 3114 XCODING_SYSTEM_UNICODE_TYPE (codesys) == UNICODE_UTF_16 && | |
| 3115 XCODING_SYSTEM_UNICODE_LITTLE_ENDIAN (codesys)); | |
| 3116 | |
| 3117 #else | |
| 3118 return 0; | |
| 3119 #endif | |
| 3120 } | |
| 3121 | |
| 3122 | |
| 3123 /************************************************************************/ | |
| 3124 /* Initialization */ | |
| 3125 /************************************************************************/ | |
| 3126 | |
| 3127 void | |
| 3128 syms_of_unicode (void) | |
| 3129 { | |
| 3130 #ifdef MULE | |
| 877 | 3131 DEFSUBR (Funicode_precedence_list); |
| 771 | 3132 DEFSUBR (Fset_language_unicode_precedence_list); |
| 3133 DEFSUBR (Flanguage_unicode_precedence_list); | |
| 3134 DEFSUBR (Fset_default_unicode_precedence_list); | |
| 3135 DEFSUBR (Fdefault_unicode_precedence_list); | |
| 3136 DEFSUBR (Fset_unicode_conversion); | |
| 3137 | |
| 1318 | 3138 DEFSUBR (Fload_unicode_mapping_table); |
| 771 | 3139 |
|
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3140 DEFSUBR (Fset_unicode_query_skip_chars_args); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3141 |
| 3439 | 3142 DEFSYMBOL (Qccl_encode_to_ucs_2); |
| 3143 DEFSYMBOL (Qlast_allocated_character); | |
| 771 | 3144 DEFSYMBOL (Qignore_first_column); |
| 3659 | 3145 |
| 3146 DEFSYMBOL (Qunicode_registries); | |
| 771 | 3147 #endif /* MULE */ |
| 3148 | |
| 800 | 3149 DEFSUBR (Fchar_to_unicode); |
| 3150 DEFSUBR (Funicode_to_char); | |
| 771 | 3151 |
| 3152 DEFSYMBOL (Qunicode); | |
| 3153 DEFSYMBOL (Qucs_4); | |
| 3154 DEFSYMBOL (Qutf_16); | |
| 4096 | 3155 DEFSYMBOL (Qutf_32); |
| 771 | 3156 DEFSYMBOL (Qutf_8); |
| 3157 DEFSYMBOL (Qutf_7); | |
| 3158 | |
| 3159 DEFSYMBOL (Qneed_bom); | |
| 3160 | |
| 3161 DEFSYMBOL (Qutf_16); | |
| 3162 DEFSYMBOL (Qutf_16_little_endian); | |
| 3163 DEFSYMBOL (Qutf_16_bom); | |
| 3164 DEFSYMBOL (Qutf_16_little_endian_bom); | |
| 985 | 3165 |
| 3166 DEFSYMBOL (Qutf_8); | |
| 3167 DEFSYMBOL (Qutf_8_bom); | |
| 771 | 3168 } |
| 3169 | |
| 3170 void | |
| 3171 coding_system_type_create_unicode (void) | |
| 3172 { | |
| 3173 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (unicode, "unicode-coding-system-p"); | |
| 3174 CODING_SYSTEM_HAS_METHOD (unicode, print); | |
| 3175 CODING_SYSTEM_HAS_METHOD (unicode, convert); | |
|
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3176 CODING_SYSTEM_HAS_METHOD (unicode, query); |
| 771 | 3177 CODING_SYSTEM_HAS_METHOD (unicode, init_coding_stream); |
| 3178 CODING_SYSTEM_HAS_METHOD (unicode, rewind_coding_stream); | |
| 3179 CODING_SYSTEM_HAS_METHOD (unicode, putprop); | |
| 3180 CODING_SYSTEM_HAS_METHOD (unicode, getprop); | |
| 3181 | |
| 3182 INITIALIZE_DETECTOR (utf_8); | |
| 3183 DETECTOR_HAS_METHOD (utf_8, detect); | |
| 3184 INITIALIZE_DETECTOR_CATEGORY (utf_8, utf_8); | |
| 985 | 3185 INITIALIZE_DETECTOR_CATEGORY (utf_8, utf_8_bom); |
| 771 | 3186 |
| 3187 INITIALIZE_DETECTOR (ucs_4); | |
| 3188 DETECTOR_HAS_METHOD (ucs_4, detect); | |
| 3189 INITIALIZE_DETECTOR_CATEGORY (ucs_4, ucs_4); | |
| 3190 | |
| 3191 INITIALIZE_DETECTOR (utf_16); | |
| 3192 DETECTOR_HAS_METHOD (utf_16, detect); | |
| 3193 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16); | |
| 3194 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian); | |
| 3195 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16_bom); | |
| 3196 INITIALIZE_DETECTOR_CATEGORY (utf_16, utf_16_little_endian_bom); | |
| 3197 } | |
| 3198 | |
| 3199 void | |
| 3200 reinit_coding_system_type_create_unicode (void) | |
| 3201 { | |
| 3202 REINITIALIZE_CODING_SYSTEM_TYPE (unicode); | |
| 3203 } | |
| 3204 | |
| 3205 void | |
| 3206 vars_of_unicode (void) | |
| 3207 { | |
| 3208 Fprovide (intern ("unicode")); | |
| 3209 | |
| 3210 #ifdef MULE | |
| 4270 | 3211 staticpro (&Vnumber_of_jit_charsets); |
| 3212 Vnumber_of_jit_charsets = make_int (0); | |
| 3213 staticpro (&Vlast_jit_charset_final); | |
| 3214 Vlast_jit_charset_final = make_char (0x30); | |
| 3215 staticpro (&Vcharset_descr); | |
| 3216 Vcharset_descr | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3217 = build_defer_string ("Mule charset for otherwise unknown Unicode code points."); |
| 4270 | 3218 |
| 771 | 3219 staticpro (&Vlanguage_unicode_precedence_list); |
| 3220 Vlanguage_unicode_precedence_list = Qnil; | |
| 3221 | |
| 3222 staticpro (&Vdefault_unicode_precedence_list); | |
| 3223 Vdefault_unicode_precedence_list = Qnil; | |
| 3224 | |
| 3225 unicode_precedence_dynarr = Dynarr_new (Lisp_Object); | |
| 2367 | 3226 dump_add_root_block_ptr (&unicode_precedence_dynarr, |
| 771 | 3227 &lisp_object_dynarr_description); |
| 2367 | 3228 |
| 3659 | 3229 |
| 3230 | |
| 2367 | 3231 init_blank_unicode_tables (); |
| 3232 | |
| 3439 | 3233 staticpro (&Vcurrent_jit_charset); |
| 3234 Vcurrent_jit_charset = Qnil; | |
| 3235 | |
| 2367 | 3236 /* Note that the "block" we are describing is a single pointer, and hence |
| 3237 we could potentially use dump_add_root_block_ptr(). However, given | |
| 3238 the way the descriptions are written, we couldn't use them, and would | |
| 3239 have to write new descriptions for each of the pointers below, since | |
| 3240 we would have to make use of a description with an XD_BLOCK_ARRAY | |
| 3241 in it. */ | |
| 3242 | |
| 3243 dump_add_root_block (&to_unicode_blank_1, sizeof (void *), | |
| 3244 to_unicode_level_1_desc_1); | |
| 3245 dump_add_root_block (&to_unicode_blank_2, sizeof (void *), | |
| 3246 to_unicode_level_2_desc_1); | |
| 3247 | |
| 3248 dump_add_root_block (&from_unicode_blank_1, sizeof (void *), | |
| 3249 from_unicode_level_1_desc_1); | |
| 3250 dump_add_root_block (&from_unicode_blank_2, sizeof (void *), | |
| 3251 from_unicode_level_2_desc_1); | |
| 3252 dump_add_root_block (&from_unicode_blank_3, sizeof (void *), | |
| 3253 from_unicode_level_3_desc_1); | |
| 3254 dump_add_root_block (&from_unicode_blank_4, sizeof (void *), | |
| 3255 from_unicode_level_4_desc_1); | |
| 3659 | 3256 |
| 3257 DEFVAR_LISP ("unicode-registries", &Qunicode_registries /* | |
| 3258 Vector describing the X11 registries searched when using fallback fonts. | |
| 3259 | |
| 3260 "Fallback fonts" here includes by default those fonts used by redisplay when | |
| 3261 displaying charsets for which the `encode-as-utf-8' property is true, and | |
| 3262 those used when no font matching the charset's registries property has been | |
| 3263 found (that is, they're probably Mule-specific charsets like Ethiopic or | |
| 3264 IPA.) | |
| 3265 */ ); | |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3266 Qunicode_registries = vector1(build_ascstring("iso10646-1")); |
|
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3267 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3268 /* Initialised in lisp/mule/general-late.el, by a call to |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3269 #'set-unicode-query-skip-chars-args. Or at least they would be, but we |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3270 can't do this at dump time right now, initialised range tables aren't |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3271 dumped properly. */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3272 staticpro (&Vunicode_invalid_and_query_skip_chars); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3273 Vunicode_invalid_and_query_skip_chars = Qnil; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3274 staticpro (&Vutf_8_invalid_and_query_skip_chars); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3275 Vutf_8_invalid_and_query_skip_chars = Qnil; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3276 staticpro (&Vunicode_query_skip_chars); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3277 Vunicode_query_skip_chars = Qnil; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3278 |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3279 /* If we could dump the range table above these wouldn't be necessary: */ |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3280 staticpro (&Vunicode_query_string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3281 Vunicode_query_string = Qnil; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3282 staticpro (&Vunicode_invalid_string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3283 Vunicode_invalid_string = Qnil; |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3284 staticpro (&Vutf_8_invalid_string); |
|
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4688
diff
changeset
|
3285 Vutf_8_invalid_string = Qnil; |
| 771 | 3286 #endif /* MULE */ |
| 3287 } | |
|
4834
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3288 |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3289 void |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3290 complex_vars_of_unicode (void) |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3291 { |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3292 /* We used to define this in unicode.el. But we need it early for |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3293 Cygwin 1.7 -- used in LOCAL_FILE_FORMAT_TO_TSTR() et al. */ |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3294 Fmake_coding_system_internal |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3295 (Qutf_8, Qunicode, |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3296 build_defer_string ("UTF-8"), |
|
4834
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3297 nconc2 (list4 (Qdocumentation, |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3298 build_defer_string ( |
|
4834
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3299 "UTF-8 Unicode encoding -- ASCII-compatible 8-bit variable-width encoding\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3300 "sharing the following principles with the Mule-internal encoding:\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3301 "\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3302 " -- All ASCII characters (codepoints 0 through 127) are represented\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3303 " by themselves (i.e. using one byte, with the same value as the\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3304 " ASCII codepoint), and these bytes are disjoint from bytes\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3305 " representing non-ASCII characters.\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3306 "\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3307 " This means that any 8-bit clean application can safely process\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3308 " UTF-8-encoded text as it were ASCII, with no corruption (e.g. a\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3309 " '/' byte is always a slash character, never the second byte of\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3310 " some other character, as with Big5, so a pathname encoded in\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3311 " UTF-8 can safely be split up into components and reassembled\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3312 " again using standard ASCII processes).\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3313 "\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3314 " -- Leading bytes and non-leading bytes in the encoding of a\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3315 " character are disjoint, so moving backwards is easy.\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3316 "\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3317 " -- Given only the leading byte, you know how many following bytes\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3318 " are present.\n" |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3319 ), |
|
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4834
diff
changeset
|
3320 Qmnemonic, build_ascstring ("UTF8")), |
|
4834
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3321 list2 (Qunicode_type, Qutf_8))); |
|
b3ea9c582280
Use new cygwin_conv_path API with Cygwin 1.7 for converting names between Win32 and POSIX, UTF-8-aware, with attendant changes elsewhere
Ben Wing <ben@xemacs.org>
parents:
4824
diff
changeset
|
3322 } |
