Mercurial > hg > xemacs-beta
annotate src/file-coding.c @ 5126:2a462149bd6a ben-lisp-object
merge
author | Ben Wing <ben@xemacs.org> |
---|---|
date | Wed, 24 Feb 2010 19:04:27 -0600 |
parents | b5df3737028a 9410323e4b0d |
children | a9c41067dd88 |
rev | line source |
---|---|
771 | 1 /* Text encoding conversion functions; coding-system object. |
2 #### rename me to coding-system.c or coding.c | |
428 | 3 Copyright (C) 1991, 1995 Free Software Foundation, Inc. |
4 Copyright (C) 1995 Sun Microsystems, Inc. | |
3025 | 5 Copyright (C) 2000, 2001, 2002, 2003, 2005 Ben Wing. |
428 | 6 |
7 This file is part of XEmacs. | |
8 | |
9 XEmacs is free software; you can redistribute it and/or modify it | |
10 under the terms of the GNU General Public License as published by the | |
11 Free Software Foundation; either version 2, or (at your option) any | |
12 later version. | |
13 | |
14 XEmacs is distributed in the hope that it will be useful, but WITHOUT | |
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
17 for more details. | |
18 | |
19 You should have received a copy of the GNU General Public License | |
20 along with XEmacs; see the file COPYING. If not, write to | |
21 the Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
22 Boston, MA 02111-1307, USA. */ | |
23 | |
771 | 24 /* Synched up with: Not in FSF. */ |
25 | |
26 /* Authorship: | |
27 | |
28 Current primary author: Ben Wing <ben@xemacs.org> | |
29 | |
30 Rewritten by Ben Wing <ben@xemacs.org>, based originally on coding.c | |
31 from Mule 2.? but probably does not share one line of code with that | |
32 original source. Rewriting work started around Dec. 1994. or Jan. 1995. | |
33 Proceeded in earnest till Nov. 1995. | |
34 | |
35 Around Feb. 17, 1998, Andy Piper renamed what was then mule-coding.c to | |
36 file-coding.c, with the intention of using it to do end-of-line conversion | |
37 on non-MULE machines (specifically, on Windows machines). He separated | |
38 out the MULE stuff from non-MULE using ifdef's, and searched throughout | |
39 the rest of the source tree looking for coding-system-related code that | |
40 was ifdef MULE but should be ifdef HAVE_CODING_SYSTEMS. | |
41 | |
42 Sept. 4 - 8, 1998, Tomohiko Morioka added the UCS_4 and UTF_8 coding system | |
43 types, providing a primitive means of decoding and encoding externally- | |
44 formatted Unicode/UCS_4 and Unicode/UTF_8 data. | |
45 | |
46 January 25, 2000, Martin Buchholz redid and fleshed out the coding | |
47 system alias handling that was first added in prototype form by | |
48 Hrjove Niksic, April 15, 1999. | |
49 | |
50 April to May 2000, Ben Wing: More major reorganization. Adding features | |
51 needed for MS Windows (multibyte, unicode, unicode-to-multibyte), the | |
52 "chain" coding system for chaining two together, and doing a lot of | |
53 reorganization in preparation for properly abstracting out the different | |
54 coding system types. | |
55 | |
56 June 2001, Ben Wing: Added Unicode support. Eliminated previous | |
57 junky Unicode translation support. | |
58 | |
59 August 2001, Ben Wing: Moved Unicode support to unicode.c. Finished | |
60 abstracting everything except detection, which is hard to abstract (see | |
61 just below). | |
62 | |
63 September 2001, Ben Wing: Moved Mule code to mule-coding.c, Windows code | |
64 to intl-win32.c. Lots more rewriting; very little code is untouched | |
65 from before April 2000. Abstracted the detection code, added multiple | |
66 levels of likelihood to increase the reliability of the algorithm. | |
67 | |
68 October 2001, Ben Wing: HAVE_CODING_SYSTEMS is always now defined. | |
69 Removed the conditionals. | |
70 */ | |
71 | |
428 | 72 #include <config.h> |
73 #include "lisp.h" | |
74 | |
75 #include "buffer.h" | |
76 #include "elhash.h" | |
77 #include "insdel.h" | |
78 #include "lstream.h" | |
440 | 79 #include "opaque.h" |
771 | 80 #include "file-coding.h" |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
81 #include "extents.h" |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
82 #include "rangetab.h" |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
83 #include "chartab.h" |
771 | 84 |
85 #ifdef HAVE_ZLIB | |
86 #include "zlib.h" | |
428 | 87 #endif |
88 | |
89 Lisp_Object Vkeyboard_coding_system; | |
90 Lisp_Object Vterminal_coding_system; | |
91 Lisp_Object Vcoding_system_for_read; | |
92 Lisp_Object Vcoding_system_for_write; | |
93 Lisp_Object Vfile_name_coding_system; | |
94 | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
95 Lisp_Object Qaliases, Qcharset_skip_chars_string; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
96 |
771 | 97 #ifdef DEBUG_XEMACS |
98 Lisp_Object Vdebug_coding_detection; | |
440 | 99 #endif |
771 | 100 |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
101 #ifdef MULE |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
102 extern Lisp_Object Vcharset_ascii, Vcharset_control_1, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
103 Vcharset_latin_iso8859_1; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
104 #endif |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
105 |
771 | 106 typedef struct coding_system_type_entry |
107 { | |
108 struct coding_system_methods *meths; | |
109 } coding_system_type_entry; | |
110 | |
111 typedef struct | |
112 { | |
113 Dynarr_declare (coding_system_type_entry); | |
114 } coding_system_type_entry_dynarr; | |
115 | |
116 static coding_system_type_entry_dynarr *the_coding_system_type_entry_dynarr; | |
117 | |
1204 | 118 static const struct memory_description cste_description_1[] = { |
2551 | 119 { XD_BLOCK_PTR, offsetof (coding_system_type_entry, meths), 1, |
120 { &coding_system_methods_description } }, | |
771 | 121 { XD_END } |
122 }; | |
123 | |
1204 | 124 static const struct sized_memory_description cste_description = { |
771 | 125 sizeof (coding_system_type_entry), |
126 cste_description_1 | |
127 }; | |
128 | |
1204 | 129 static const struct memory_description csted_description_1[] = { |
771 | 130 XD_DYNARR_DESC (coding_system_type_entry_dynarr, &cste_description), |
428 | 131 { XD_END } |
132 }; | |
133 | |
1204 | 134 static const struct sized_memory_description csted_description = { |
771 | 135 sizeof (coding_system_type_entry_dynarr), |
136 csted_description_1 | |
137 }; | |
138 | |
139 static Lisp_Object Vcoding_system_type_list; | |
140 | |
141 /* Coding system currently associated with each coding category. */ | |
142 Lisp_Object coding_category_system[MAX_DETECTOR_CATEGORIES]; | |
143 | |
144 /* Table of all coding categories in decreasing order of priority. | |
145 This describes a permutation of the possible coding categories. */ | |
146 int coding_category_by_priority[MAX_DETECTOR_CATEGORIES]; | |
147 | |
148 /* Value used with to give a unique name to nameless coding systems */ | |
149 int coding_system_tick; | |
150 | |
151 int coding_detector_count; | |
152 int coding_detector_category_count; | |
153 | |
154 detector_dynarr *all_coding_detectors; | |
155 | |
1204 | 156 static const struct memory_description struct_detector_category_description_1[] |
771 | 157 = |
158 { | |
159 { XD_LISP_OBJECT, offsetof (struct detector_category, sym) }, | |
160 { XD_END } | |
161 }; | |
162 | |
1204 | 163 static const struct sized_memory_description struct_detector_category_description = |
771 | 164 { |
165 sizeof (struct detector_category), | |
166 struct_detector_category_description_1 | |
428 | 167 }; |
168 | |
1204 | 169 static const struct memory_description detector_category_dynarr_description_1[] = |
771 | 170 { |
171 XD_DYNARR_DESC (detector_category_dynarr, | |
172 &struct_detector_category_description), | |
173 { XD_END } | |
174 }; | |
175 | |
1204 | 176 static const struct sized_memory_description detector_category_dynarr_description = { |
771 | 177 sizeof (detector_category_dynarr), |
178 detector_category_dynarr_description_1 | |
179 }; | |
180 | |
1204 | 181 static const struct memory_description struct_detector_description_1[] |
771 | 182 = |
183 { | |
2367 | 184 { XD_BLOCK_PTR, offsetof (struct detector, cats), 1, |
2551 | 185 { &detector_category_dynarr_description } }, |
771 | 186 { XD_END } |
187 }; | |
188 | |
1204 | 189 static const struct sized_memory_description struct_detector_description = |
771 | 190 { |
191 sizeof (struct detector), | |
192 struct_detector_description_1 | |
193 }; | |
194 | |
1204 | 195 static const struct memory_description detector_dynarr_description_1[] = |
771 | 196 { |
197 XD_DYNARR_DESC (detector_dynarr, &struct_detector_description), | |
198 { XD_END } | |
199 }; | |
200 | |
1204 | 201 static const struct sized_memory_description detector_dynarr_description = { |
771 | 202 sizeof (detector_dynarr), |
203 detector_dynarr_description_1 | |
204 }; | |
428 | 205 |
206 Lisp_Object Qcoding_systemp; | |
207 | |
771 | 208 Lisp_Object Qraw_text; |
428 | 209 |
210 Lisp_Object Qmnemonic, Qeol_type; | |
211 Lisp_Object Qcr, Qcrlf, Qlf; | |
212 Lisp_Object Qeol_cr, Qeol_crlf, Qeol_lf; | |
213 Lisp_Object Qpost_read_conversion; | |
214 Lisp_Object Qpre_write_conversion; | |
215 | |
771 | 216 Lisp_Object Qtranslation_table_for_decode; |
217 Lisp_Object Qtranslation_table_for_encode; | |
218 Lisp_Object Qsafe_chars; | |
219 Lisp_Object Qsafe_charsets; | |
220 Lisp_Object Qmime_charset; | |
221 Lisp_Object Qvalid_codes; | |
222 | |
223 Lisp_Object Qno_conversion; | |
224 Lisp_Object Qconvert_eol; | |
440 | 225 Lisp_Object Qescape_quoted; |
771 | 226 Lisp_Object Qencode, Qdecode; |
227 | |
228 Lisp_Object Qconvert_eol_lf, Qconvert_eol_cr, Qconvert_eol_crlf; | |
229 Lisp_Object Qconvert_eol_autodetect; | |
230 | |
231 Lisp_Object Qnear_certainty, Qquite_probable, Qsomewhat_likely; | |
1494 | 232 Lisp_Object Qslightly_likely; |
771 | 233 Lisp_Object Qas_likely_as_unlikely, Qsomewhat_unlikely, Qquite_improbable; |
234 Lisp_Object Qnearly_impossible; | |
235 | |
236 Lisp_Object Qdo_eol, Qdo_coding; | |
237 | |
238 Lisp_Object Qcanonicalize_after_coding; | |
239 | |
1347 | 240 Lisp_Object QScoding_system_cookie; |
241 | |
4303 | 242 Lisp_Object Qposix_charset_to_coding_system_hash; |
243 | |
771 | 244 /* This is used to convert autodetected coding systems into existing |
245 systems. For example, the chain undecided->convert-eol-autodetect may | |
246 have its separate parts detected as mswindows-multibyte and | |
247 convert-eol-crlf, and the result needs to be mapped to | |
248 mswindows-multibyte-dos. */ | |
249 /* #### It's not clear we need this whole chain-canonicalize mechanism | |
250 any more. */ | |
251 static Lisp_Object Vchain_canonicalize_hash_table; | |
252 | |
253 #ifdef HAVE_ZLIB | |
254 Lisp_Object Qgzip; | |
428 | 255 #endif |
771 | 256 |
2297 | 257 /* Maps symbols (coding system names) to either coding system objects or |
258 (for aliases) other names. */ | |
771 | 259 static Lisp_Object Vcoding_system_hash_table; |
428 | 260 |
261 int enable_multibyte_characters; | |
262 | |
263 EXFUN (Fcopy_coding_system, 2); | |
264 | |
265 | |
266 /************************************************************************/ | |
771 | 267 /* Coding system object methods */ |
428 | 268 /************************************************************************/ |
269 | |
270 static Lisp_Object | |
271 mark_coding_system (Lisp_Object obj) | |
272 { | |
273 Lisp_Coding_System *codesys = XCODING_SYSTEM (obj); | |
274 | |
1204 | 275 #define MARKED_SLOT(x) mark_object (codesys->x); |
276 #include "coding-system-slots.h" | |
771 | 277 |
278 MAYBE_CODESYSMETH (codesys, mark, (obj)); | |
428 | 279 |
1204 | 280 return Qnil; |
428 | 281 } |
282 | |
283 static void | |
771 | 284 print_coding_system_properties (Lisp_Object obj, Lisp_Object printcharfun) |
285 { | |
286 Lisp_Coding_System *c = XCODING_SYSTEM (obj); | |
287 print_internal (c->methods->type, printcharfun, 1); | |
288 MAYBE_CODESYSMETH (c, print, (obj, printcharfun, 1)); | |
289 if (CODING_SYSTEM_EOL_TYPE (c) != EOL_AUTODETECT) | |
290 write_fmt_string_lisp (printcharfun, " eol-type=%s", | |
291 1, Fcoding_system_property (obj, Qeol_type)); | |
292 } | |
293 | |
294 static void | |
428 | 295 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun, |
2286 | 296 int UNUSED (escapeflag)) |
428 | 297 { |
298 Lisp_Coding_System *c = XCODING_SYSTEM (obj); | |
299 if (print_readably) | |
4846 | 300 printing_unreadable_lcrecord (obj, 0); |
771 | 301 |
302 write_fmt_string_lisp (printcharfun, "#<coding-system %s ", 1, c->name); | |
303 print_coding_system_properties (obj, printcharfun); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
304 write_ascstring (printcharfun, ">"); |
428 | 305 } |
306 | |
771 | 307 /* Print an abbreviated version of a coding system (but still containing |
308 all the information), for use within a coding system print method. */ | |
309 | |
310 static void | |
311 print_coding_system_in_print_method (Lisp_Object cs, Lisp_Object printcharfun, | |
2286 | 312 int UNUSED (escapeflag)) |
771 | 313 { |
800 | 314 write_fmt_string_lisp (printcharfun, "%s[", 1, XCODING_SYSTEM_NAME (cs)); |
771 | 315 print_coding_system_properties (cs, printcharfun); |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
316 write_ascstring (printcharfun, "]"); |
771 | 317 } |
318 | |
3263 | 319 #ifndef NEW_GC |
428 | 320 static void |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
321 finalize_coding_system (void *header) |
428 | 322 { |
771 | 323 Lisp_Object cs = wrap_coding_system ((Lisp_Coding_System *) header); |
428 | 324 /* Since coding systems never go away, this function is not |
325 necessary. But it would be necessary if we changed things | |
326 so that coding systems could go away. */ | |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
327 MAYBE_XCODESYSMETH (cs, finalize, (cs)); |
771 | 328 } |
3263 | 329 #endif /* not NEW_GC */ |
771 | 330 |
331 static Bytecount | |
332 sizeof_coding_system (const void *header) | |
333 { | |
334 const Lisp_Coding_System *p = (const Lisp_Coding_System *) header; | |
335 return offsetof (Lisp_Coding_System, data) + p->methods->extra_data_size; | |
428 | 336 } |
337 | |
1204 | 338 static const struct memory_description coding_system_methods_description_1[] |
771 | 339 = { |
340 { XD_LISP_OBJECT, | |
341 offsetof (struct coding_system_methods, type) }, | |
342 { XD_LISP_OBJECT, | |
343 offsetof (struct coding_system_methods, predicate_symbol) }, | |
344 { XD_END } | |
345 }; | |
346 | |
1204 | 347 const struct sized_memory_description coding_system_methods_description = { |
771 | 348 sizeof (struct coding_system_methods), |
349 coding_system_methods_description_1 | |
350 }; | |
351 | |
1204 | 352 static const struct sized_memory_description coding_system_extra_description_map[] = |
353 { | |
354 { offsetof (Lisp_Coding_System, methods) }, | |
355 { offsetof (struct coding_system_methods, extra_description) }, | |
356 { -1 }, | |
771 | 357 }; |
358 | |
1204 | 359 static const struct memory_description coding_system_description[] = |
428 | 360 { |
2367 | 361 { XD_BLOCK_PTR, offsetof (Lisp_Coding_System, methods), 1, |
2551 | 362 { &coding_system_methods_description } }, |
1204 | 363 #define MARKED_SLOT(x) { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, x) }, |
364 #define MARKED_SLOT_ARRAY(slot, size) \ | |
365 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Coding_System, slot), size }, | |
366 #include "coding-system-slots.h" | |
2367 | 367 { XD_BLOCK_ARRAY, offsetof (Lisp_Coding_System, data), 1, |
2551 | 368 { coding_system_extra_description_map } }, |
1204 | 369 { XD_END } |
771 | 370 }; |
371 | |
1204 | 372 static const struct memory_description coding_system_empty_extra_description_1[] = |
373 { | |
374 { XD_END } | |
375 }; | |
376 | |
377 const struct sized_memory_description coding_system_empty_extra_description = { | |
378 0, coding_system_empty_extra_description_1 | |
379 }; | |
380 | |
3263 | 381 #ifdef NEW_GC |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
382 DEFINE_DUMPABLE_SIZABLE_LISP_OBJECT ("coding-system", coding_system, |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
383 mark_coding_system, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
384 print_coding_system, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
385 0, 0, 0, coding_system_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
386 sizeof_coding_system, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
387 Lisp_Coding_System); |
3263 | 388 #else /* not NEW_GC */ |
5118
e0db3c197671
merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
diff
changeset
|
389 DEFINE_DUMPABLE_SIZABLE_LISP_OBJECT ("coding-system", coding_system, |
5124
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
390 mark_coding_system, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
391 print_coding_system, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
392 finalize_coding_system, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
393 0, 0, coding_system_description, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
394 sizeof_coding_system, |
623d57b7fbe8
separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents:
5120
diff
changeset
|
395 Lisp_Coding_System); |
3263 | 396 #endif /* not NEW_GC */ |
771 | 397 |
398 /************************************************************************/ | |
399 /* Creating coding systems */ | |
400 /************************************************************************/ | |
401 | |
402 static struct coding_system_methods * | |
403 decode_coding_system_type (Lisp_Object type, Error_Behavior errb) | |
428 | 404 { |
771 | 405 int i; |
406 | |
407 for (i = 0; i < Dynarr_length (the_coding_system_type_entry_dynarr); i++) | |
428 | 408 { |
771 | 409 if (EQ (type, |
410 Dynarr_at (the_coding_system_type_entry_dynarr, i).meths->type)) | |
411 return Dynarr_at (the_coding_system_type_entry_dynarr, i).meths; | |
428 | 412 } |
771 | 413 |
414 maybe_invalid_constant ("Invalid coding system type", type, | |
415 Qcoding_system, errb); | |
416 | |
417 return 0; | |
428 | 418 } |
419 | |
771 | 420 static int |
421 valid_coding_system_type_p (Lisp_Object type) | |
428 | 422 { |
771 | 423 return decode_coding_system_type (type, ERROR_ME_NOT) != 0; |
424 } | |
425 | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
426 #ifdef MULE |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
427 static Lisp_Object Vdefault_query_coding_region_chartab_cache; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
428 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
429 /* Non-static because it's used in INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA. */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
430 Lisp_Object |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
431 default_query_method (Lisp_Object codesys, struct buffer *buf, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
432 Charbpos end, int flags) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
433 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
434 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:
4647
diff
changeset
|
435 Charbpos pos_byte = BYTE_BUF_PT (buf); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
436 Lisp_Object safe_charsets = XCODING_SYSTEM_SAFE_CHARSETS (codesys); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
437 Lisp_Object safe_chars = XCODING_SYSTEM_SAFE_CHARS (codesys), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
438 result = Qnil; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
439 enum query_coding_failure_reasons failed_reason, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
440 previous_failed_reason = query_coding_succeeded; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
441 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
442 /* safe-charsets of t means the coding system can encode everything. */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
443 if (EQ (Qnil, safe_chars)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
444 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
445 if (EQ (Qt, safe_charsets)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
446 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
447 return Qnil; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
448 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
449 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
450 /* If we've no information on what characters the coding system can |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
451 encode, give up. */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
452 if (EQ (Qnil, safe_charsets) && EQ (Qnil, safe_chars)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
453 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
454 return Qunbound; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
455 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
456 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
457 safe_chars = Fgethash (safe_charsets, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
458 Vdefault_query_coding_region_chartab_cache, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
459 Qnil); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
460 if (NILP (safe_chars)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
461 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
462 safe_chars = Fmake_char_table (Qgeneric); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
463 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
464 EXTERNAL_LIST_LOOP_2 (safe_charset, safe_charsets) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
465 Fput_char_table (safe_charset, Qt, safe_chars); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
466 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
467 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
468 Fputhash (safe_charsets, safe_chars, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
469 Vdefault_query_coding_region_chartab_cache); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
470 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
471 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
472 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
473 if (flags & QUERY_METHOD_HIGHLIGHT && |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
474 /* 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:
4647
diff
changeset
|
475 cleared properly: */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
476 !(UNBOUNDP (XSYMBOL (Qquery_coding_clear_highlights)->function))) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
477 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
478 /* 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:
4647
diff
changeset
|
479 allocated up to this point is safe_chars, and that's |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
480 reachable from its entry in |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
481 Vdefault_query_coding_region_chartab_cache */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
482 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:
4647
diff
changeset
|
483 wrap_buffer (buf)); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
484 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
485 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
486 while (pos < end) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
487 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
488 Ichar ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
489 if (!EQ (Qnil, get_char_table (ch, safe_chars))) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
490 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
491 pos++; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
492 INC_BYTEBPOS (buf, pos_byte); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
493 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
494 else |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
495 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
496 fail_range_start = pos; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
497 while ((pos < end) && |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
498 (EQ (Qnil, get_char_table (ch, safe_chars)) |
4839
5f1c6ca4d05e
fix bad change to default_query_method, rewrite conditional for more correctness
Ben Wing <ben@xemacs.org>
parents:
4830
diff
changeset
|
499 && (failed_reason = query_coding_unencodable, |
5f1c6ca4d05e
fix bad change to default_query_method, rewrite conditional for more correctness
Ben Wing <ben@xemacs.org>
parents:
4830
diff
changeset
|
500 (previous_failed_reason == query_coding_succeeded |
5f1c6ca4d05e
fix bad change to default_query_method, rewrite conditional for more correctness
Ben Wing <ben@xemacs.org>
parents:
4830
diff
changeset
|
501 || previous_failed_reason == failed_reason)))) |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
502 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
503 pos++; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
504 INC_BYTEBPOS (buf, pos_byte); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
505 ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
506 previous_failed_reason = failed_reason; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
507 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
508 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
509 if (fail_range_start == pos) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
510 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
511 /* The character can actually be encoded; move on. */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
512 pos++; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
513 INC_BYTEBPOS (buf, pos_byte); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
514 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
515 else |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
516 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
517 assert (previous_failed_reason == query_coding_unencodable); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
518 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
519 if (flags & QUERY_METHOD_ERRORP) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
520 { |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
521 signal_error_2 |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
522 (Qtext_conversion_error, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
523 "Cannot encode using coding system", |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
524 make_string_from_buffer (buf, fail_range_start, |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
525 pos - fail_range_start), |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
526 XCODING_SYSTEM_NAME (codesys)); |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
527 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
528 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
529 if (NILP (result)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
530 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
531 result = Fmake_range_table (Qstart_closed_end_open); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
532 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
533 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
534 fail_range_end = pos; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
535 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
536 Fput_range_table (make_int (fail_range_start), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
537 make_int (fail_range_end), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
538 Qunencodable, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
539 result); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
540 previous_failed_reason = query_coding_succeeded; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
541 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
542 if (flags & QUERY_METHOD_HIGHLIGHT) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
543 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
544 Lisp_Object extent |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
545 = Fmake_extent (make_int (fail_range_start), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
546 make_int (fail_range_end), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
547 wrap_buffer (buf)); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
548 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
549 Fset_extent_priority |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
550 (extent, make_int (2 + mouse_highlight_priority)); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
551 Fset_extent_face (extent, Qquery_coding_warning_face); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
552 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
553 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
554 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
555 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
556 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
557 return result; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
558 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
559 #else |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
560 Lisp_Object |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
561 default_query_method (Lisp_Object UNUSED (codesys), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
562 struct buffer * UNUSED (buf), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
563 Charbpos UNUSED (end), int UNUSED (flags)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
564 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
565 return Qnil; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
566 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
567 #endif /* defined MULE */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
568 |
771 | 569 DEFUN ("valid-coding-system-type-p", Fvalid_coding_system_type_p, 1, 1, 0, /* |
570 Given a CODING-SYSTEM-TYPE, return non-nil if it is valid. | |
571 Valid types depend on how XEmacs was compiled but may include | |
3025 | 572 `undecided', `chain', `integer', `ccl', `iso2022', `big5', `shift-jis', |
573 `utf-16', `ucs-4', `utf-8', etc. | |
771 | 574 */ |
575 (coding_system_type)) | |
576 { | |
577 return valid_coding_system_type_p (coding_system_type) ? Qt : Qnil; | |
578 } | |
579 | |
580 DEFUN ("coding-system-type-list", Fcoding_system_type_list, 0, 0, 0, /* | |
581 Return a list of valid coding system types. | |
582 */ | |
583 ()) | |
584 { | |
585 return Fcopy_sequence (Vcoding_system_type_list); | |
586 } | |
587 | |
588 void | |
589 add_entry_to_coding_system_type_list (struct coding_system_methods *meths) | |
590 { | |
591 struct coding_system_type_entry entry; | |
592 | |
593 entry.meths = meths; | |
594 Dynarr_add (the_coding_system_type_entry_dynarr, entry); | |
595 Vcoding_system_type_list = Fcons (meths->type, Vcoding_system_type_list); | |
428 | 596 } |
597 | |
598 DEFUN ("coding-system-p", Fcoding_system_p, 1, 1, 0, /* | |
599 Return t if OBJECT is a coding system. | |
600 A coding system is an object that defines how text containing multiple | |
601 character sets is encoded into a stream of (typically 8-bit) bytes. | |
602 The coding system is used to decode the stream into a series of | |
603 characters (which may be from multiple charsets) when the text is read | |
604 from a file or process, and is used to encode the text back into the | |
605 same format when it is written out to a file or process. | |
606 | |
607 For example, many ISO2022-compliant coding systems (such as Compound | |
608 Text, which is used for inter-client data under the X Window System) | |
609 use escape sequences to switch between different charsets -- Japanese | |
610 Kanji, for example, is invoked with "ESC $ ( B"; ASCII is invoked | |
611 with "ESC ( B"; and Cyrillic is invoked with "ESC - L". See | |
612 `make-coding-system' for more information. | |
613 | |
614 Coding systems are normally identified using a symbol, and the | |
615 symbol is accepted in place of the actual coding system object whenever | |
616 a coding system is called for. (This is similar to how faces work.) | |
617 */ | |
618 (object)) | |
619 { | |
620 return CODING_SYSTEMP (object) ? Qt : Qnil; | |
621 } | |
622 | |
4303 | 623 static Lisp_Object |
624 find_coding_system (Lisp_Object coding_system_or_name, | |
625 int do_autoloads) | |
626 { | |
627 Lisp_Object lookup; | |
628 | |
629 if (NILP (coding_system_or_name)) | |
630 coding_system_or_name = Qbinary; | |
631 else if (CODING_SYSTEMP (coding_system_or_name)) | |
632 return coding_system_or_name; | |
633 else | |
634 CHECK_SYMBOL (coding_system_or_name); | |
635 | |
636 while (1) | |
637 { | |
638 lookup = | |
639 Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil); | |
640 | |
641 if (CONSP (lookup) && do_autoloads) | |
642 { | |
643 struct gcpro gcpro1; | |
644 int length; | |
645 DECLARE_EISTRING (desired_base); | |
646 DECLARE_EISTRING (warning_info); | |
647 | |
648 eicpy_lstr (desired_base, XSYMBOL_NAME (coding_system_or_name)); | |
649 | |
650 /* Work out the name of the base coding system. */ | |
651 length = eilen (desired_base); | |
652 if (length > (int)(sizeof ("-unix") - 1)) | |
653 { | |
654 if (0 == qxestrcmp ((UAscbyte *)"-unix", (eidata (desired_base)) | |
655 + (length - (sizeof ("-unix") - 1)))) | |
656 { | |
657 eidel (desired_base, length - (sizeof ("-unix") - 1), | |
658 -1, 5, 5); | |
659 } | |
660 } | |
661 else if (length > (int)(sizeof ("-dos") - 1)) | |
662 { | |
663 if ((0 == qxestrcmp ((UAscbyte *)"-dos", (eidata (desired_base)) | |
664 + (length - (sizeof ("-dos") - 1)))) || | |
665 (0 == qxestrcmp ((UAscbyte *)"-mac", (eidata (desired_base)) | |
666 + (length - (sizeof ("-mac") - 1))))) | |
667 { | |
668 eidel (desired_base, length - (sizeof ("-dos") - 1), -1, | |
669 4, 4); | |
670 } | |
671 } | |
672 | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
673 coding_system_or_name = intern_istring (eidata (desired_base)); |
4303 | 674 |
675 /* Remove this coding system and its subsidiary coding | |
676 systems from the hash, to avoid calling this code recursively. */ | |
677 Fremhash (coding_system_or_name, Vcoding_system_hash_table); | |
678 Fremhash (add_suffix_to_symbol(coding_system_or_name, "-unix"), | |
679 Vcoding_system_hash_table); | |
680 Fremhash (add_suffix_to_symbol(coding_system_or_name, "-dos"), | |
681 Vcoding_system_hash_table); | |
682 Fremhash (add_suffix_to_symbol(coding_system_or_name, "-mac"), | |
683 Vcoding_system_hash_table); | |
684 | |
685 eicpy_ascii (warning_info, "Error autoloading coding system "); | |
686 eicat_lstr (warning_info, XSYMBOL_NAME (coding_system_or_name)); | |
687 | |
688 /* Keep around the form so it doesn't disappear from under | |
689 #'eval's feet. */ | |
690 GCPRO1 (lookup); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
691 call1_trapping_problems ((const CIbyte *) eidata (warning_info), |
4303 | 692 Qeval, lookup, 0); |
693 UNGCPRO; | |
694 | |
695 lookup = | |
696 Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil); | |
697 } | |
698 | |
699 if (CODING_SYSTEMP (lookup) || NILP (lookup)) | |
700 return lookup; | |
701 | |
702 coding_system_or_name = lookup; | |
703 } | |
704 } | |
705 | |
428 | 706 DEFUN ("find-coding-system", Ffind_coding_system, 1, 1, 0, /* |
707 Retrieve the coding system of the given name. | |
708 | |
709 If CODING-SYSTEM-OR-NAME is a coding-system object, it is simply | |
710 returned. Otherwise, CODING-SYSTEM-OR-NAME should be a symbol. | |
711 If there is no such coding system, nil is returned. Otherwise the | |
712 associated coding system object is returned. | |
713 */ | |
714 (coding_system_or_name)) | |
715 { | |
4303 | 716 return find_coding_system(coding_system_or_name, 1); |
717 } | |
718 | |
719 DEFUN ("autoload-coding-system", Fautoload_coding_system, 2, 2, 0, /* | |
720 Define SYMBOL as a coding-system that is loaded on demand. | |
721 | |
722 FORM is a form to evaluate to define the coding-system. | |
723 */ | |
724 (symbol, form)) | |
725 { | |
726 Lisp_Object lookup; | |
727 | |
728 CHECK_SYMBOL (symbol); | |
729 CHECK_CONS (form); | |
730 | |
731 lookup = find_coding_system (symbol, 0); | |
732 | |
733 if (!NILP (lookup) && | |
734 /* Allow autoloads to be redefined. */ | |
735 !CONSP (lookup)) | |
440 | 736 { |
4303 | 737 invalid_operation ("Cannot redefine existing coding system", |
738 symbol); | |
440 | 739 } |
4303 | 740 |
741 Fputhash (symbol, form, Vcoding_system_hash_table); | |
742 Fputhash (add_suffix_to_symbol(symbol, "-unix"), form, | |
743 Vcoding_system_hash_table); | |
744 Fputhash (add_suffix_to_symbol(symbol, "-dos"), form, | |
745 Vcoding_system_hash_table); | |
746 Fputhash (add_suffix_to_symbol(symbol, "-mac"), form, | |
747 Vcoding_system_hash_table); | |
748 | |
749 /* Tell the POSIX locale infrastructure about this coding system (though | |
750 unfortunately it'll be too late for the startup locale sniffing. */ | |
751 if (!UNBOUNDP (Qposix_charset_to_coding_system_hash)) | |
752 { | |
753 Lisp_Object val = Fsymbol_value (Qposix_charset_to_coding_system_hash); | |
754 DECLARE_EISTRING (minimal_name); | |
755 Ibyte *full_name; | |
756 int len = XSTRING_LENGTH (XSYMBOL_NAME (symbol)), i; | |
757 | |
758 if (!NILP (val)) | |
759 { | |
760 full_name = XSTRING_DATA (XSYMBOL_NAME (symbol)); | |
761 for (i = 0; i < len; ++i) | |
762 { | |
763 if (full_name[i] >= '0' && full_name[i] <= '9') | |
764 { | |
765 eicat_ch (minimal_name, full_name[i]); | |
766 } | |
767 else if (full_name[i] >= 'a' && full_name[i] <= 'z') | |
768 { | |
769 eicat_ch (minimal_name, full_name[i]); | |
770 } | |
771 else if (full_name[i] >= 'A' && full_name[i] <= 'Z') | |
772 { | |
773 eicat_ch (minimal_name, full_name[i] + | |
774 ('a' - 'A')); | |
775 } | |
776 } | |
777 | |
778 if (eilen (minimal_name)) | |
779 { | |
780 CHECK_HASH_TABLE (val); | |
781 Fputhash (eimake_string(minimal_name), symbol, val); | |
782 } | |
783 } | |
784 } | |
785 | |
786 return Qt; | |
428 | 787 } |
788 | |
789 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /* | |
790 Retrieve the coding system of the given name. | |
791 Same as `find-coding-system' except that if there is no such | |
792 coding system, an error is signaled instead of returning nil. | |
793 */ | |
794 (name)) | |
795 { | |
796 Lisp_Object coding_system = Ffind_coding_system (name); | |
797 | |
798 if (NILP (coding_system)) | |
563 | 799 invalid_argument ("No such coding system", name); |
428 | 800 return coding_system; |
801 } | |
802 | |
771 | 803 int |
804 coding_system_is_binary (Lisp_Object coding_system) | |
805 { | |
806 Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system); | |
807 return | |
808 (EQ (CODING_SYSTEM_TYPE (cs), Qno_conversion) && | |
809 CODING_SYSTEM_EOL_TYPE (cs) == EOL_LF && | |
810 EQ (CODING_SYSTEM_POST_READ_CONVERSION (cs), Qnil) && | |
811 EQ (CODING_SYSTEM_PRE_WRITE_CONVERSION (cs), Qnil)); | |
812 } | |
813 | |
814 static Lisp_Object | |
815 coding_system_real_canonical (Lisp_Object cs) | |
816 { | |
817 if (!NILP (XCODING_SYSTEM_CANONICAL (cs))) | |
818 return XCODING_SYSTEM_CANONICAL (cs); | |
819 return cs; | |
820 } | |
821 | |
822 /* Return true if coding system is of the "standard" type that decodes | |
823 bytes into characters (suitable for decoding a text file). */ | |
824 int | |
825 coding_system_is_for_text_file (Lisp_Object coding_system) | |
826 { | |
827 return (XCODESYSMETH_OR_GIVEN | |
828 (coding_system, conversion_end_type, | |
829 (coding_system_real_canonical (coding_system)), | |
830 DECODES_BYTE_TO_CHARACTER) == | |
831 DECODES_BYTE_TO_CHARACTER); | |
832 } | |
833 | |
834 static int | |
835 decoding_source_sink_type_is_char (Lisp_Object cs, enum source_or_sink sex) | |
836 { | |
837 enum source_sink_type type = | |
838 XCODESYSMETH_OR_GIVEN (cs, conversion_end_type, | |
839 (coding_system_real_canonical (cs)), | |
840 DECODES_BYTE_TO_CHARACTER); | |
841 if (sex == CODING_SOURCE) | |
842 return (type == DECODES_CHARACTER_TO_CHARACTER || | |
843 type == DECODES_CHARACTER_TO_BYTE); | |
844 else | |
845 return (type == DECODES_CHARACTER_TO_CHARACTER || | |
846 type == DECODES_BYTE_TO_CHARACTER); | |
847 } | |
848 | |
849 static int | |
850 encoding_source_sink_type_is_char (Lisp_Object cs, enum source_or_sink sex) | |
851 { | |
852 return decoding_source_sink_type_is_char (cs, | |
853 /* Sex change */ | |
854 sex == CODING_SOURCE ? | |
855 CODING_SINK : CODING_SOURCE); | |
856 } | |
857 | |
858 /* Like Ffind_coding_system() but check that the coding system is of the | |
859 "standard" type that decodes bytes into characters (suitable for | |
860 decoding a text file), and if not, returns an appropriate wrapper that | |
861 does. Also, if EOL_WRAP is non-zero, check whether this coding system | |
862 wants EOL auto-detection, and if so, wrap with a convert-eol coding | |
863 system to do this. */ | |
864 | |
865 Lisp_Object | |
866 find_coding_system_for_text_file (Lisp_Object name, int eol_wrap) | |
867 { | |
868 Lisp_Object coding_system = Ffind_coding_system (name); | |
869 Lisp_Object wrapper = coding_system; | |
870 | |
871 if (NILP (coding_system)) | |
872 return Qnil; | |
873 if (!coding_system_is_for_text_file (coding_system)) | |
874 { | |
875 wrapper = XCODING_SYSTEM_TEXT_FILE_WRAPPER (coding_system); | |
876 if (NILP (wrapper)) | |
877 { | |
878 Lisp_Object chain; | |
879 if (!decoding_source_sink_type_is_char (coding_system, CODING_SINK)) | |
880 chain = list2 (coding_system, Qbinary); | |
881 else | |
882 chain = list1 (coding_system); | |
883 if (decoding_source_sink_type_is_char (coding_system, CODING_SOURCE)) | |
884 chain = Fcons (Qbinary, chain); | |
885 wrapper = | |
886 make_internal_coding_system | |
887 (coding_system, | |
888 "internal-text-file-wrapper", | |
889 Qchain, | |
890 Qunbound, list4 (Qchain, chain, | |
891 Qcanonicalize_after_coding, coding_system)); | |
892 XCODING_SYSTEM_TEXT_FILE_WRAPPER (coding_system) = wrapper; | |
893 } | |
894 } | |
895 | |
896 if (!eol_wrap || XCODING_SYSTEM_EOL_TYPE (coding_system) != EOL_AUTODETECT) | |
897 return wrapper; | |
898 | |
899 coding_system = wrapper; | |
900 wrapper = XCODING_SYSTEM_AUTO_EOL_WRAPPER (coding_system); | |
901 if (!NILP (wrapper)) | |
902 return wrapper; | |
903 wrapper = | |
904 make_internal_coding_system | |
905 (coding_system, | |
906 "internal-auto-eol-wrapper", | |
907 Qundecided, Qunbound, | |
908 list4 (Qcoding_system, coding_system, | |
909 Qdo_eol, Qt)); | |
910 XCODING_SYSTEM_AUTO_EOL_WRAPPER (coding_system) = wrapper; | |
911 return wrapper; | |
912 } | |
913 | |
914 /* Like Fget_coding_system() but verify that the coding system is of the | |
915 "standard" type that decodes bytes into characters (suitable for | |
916 decoding a text file), and if not, returns an appropriate wrapper that | |
917 does. Also, if EOL_WRAP is non-zero, check whether this coding system | |
918 wants EOL auto-detection, and if so, wrap with a convert-eol coding | |
919 system to do this. */ | |
920 | |
921 Lisp_Object | |
922 get_coding_system_for_text_file (Lisp_Object name, int eol_wrap) | |
923 { | |
924 Lisp_Object coding_system = find_coding_system_for_text_file (name, | |
925 eol_wrap); | |
926 if (NILP (coding_system)) | |
927 invalid_argument ("No such coding system", name); | |
928 return coding_system; | |
929 } | |
930 | |
931 /* We store the coding systems in hash tables with the names as the | |
932 key and the actual coding system object as the value. Occasionally | |
933 we need to use them in a list format. These routines provide us | |
934 with that. */ | |
428 | 935 struct coding_system_list_closure |
936 { | |
937 Lisp_Object *coding_system_list; | |
771 | 938 int normal; |
939 int internal; | |
428 | 940 }; |
941 | |
942 static int | |
4303 | 943 add_coding_system_to_list_mapper (Lisp_Object key, Lisp_Object value, |
428 | 944 void *coding_system_list_closure) |
945 { | |
946 /* This function can GC */ | |
947 struct coding_system_list_closure *cscl = | |
948 (struct coding_system_list_closure *) coding_system_list_closure; | |
949 Lisp_Object *coding_system_list = cscl->coding_system_list; | |
950 | |
771 | 951 /* We can't just use VALUE because KEY might be an alias, and we need |
4303 | 952 the real coding system object. |
953 | |
954 Autoloaded coding systems have conses for their values, and can't be | |
955 internal coding systems, or coding system aliases. */ | |
956 if (CONSP (value) || | |
957 (XCODING_SYSTEM (Ffind_coding_system (key))->internal_p ? | |
958 cscl->internal : cscl->normal)) | |
771 | 959 *coding_system_list = Fcons (key, *coding_system_list); |
428 | 960 return 0; |
961 } | |
962 | |
2297 | 963 /* #### should we specify a conventional for "all coding systems"? */ |
771 | 964 DEFUN ("coding-system-list", Fcoding_system_list, 0, 1, 0, /* |
428 | 965 Return a list of the names of all defined coding systems. |
771 | 966 If INTERNAL is nil, only the normal (non-internal) coding systems are |
967 included. (Internal coding systems are created for various internal | |
968 purposes, such as implementing EOL types of CRLF and CR; generally, you do | |
969 not want to see these.) If it is t, only the internal coding systems are | |
970 included. If it is any other non-nil value both normal and internal are | |
971 included. | |
428 | 972 */ |
771 | 973 (internal)) |
428 | 974 { |
975 Lisp_Object coding_system_list = Qnil; | |
976 struct gcpro gcpro1; | |
977 struct coding_system_list_closure coding_system_list_closure; | |
978 | |
979 GCPRO1 (coding_system_list); | |
980 coding_system_list_closure.coding_system_list = &coding_system_list; | |
771 | 981 coding_system_list_closure.normal = !EQ (internal, Qt); |
982 coding_system_list_closure.internal = !NILP (internal); | |
428 | 983 elisp_maphash (add_coding_system_to_list_mapper, Vcoding_system_hash_table, |
984 &coding_system_list_closure); | |
985 UNGCPRO; | |
986 | |
987 return coding_system_list; | |
988 } | |
989 | |
990 DEFUN ("coding-system-name", Fcoding_system_name, 1, 1, 0, /* | |
991 Return the name of the given coding system. | |
992 */ | |
993 (coding_system)) | |
994 { | |
995 coding_system = Fget_coding_system (coding_system); | |
996 return XCODING_SYSTEM_NAME (coding_system); | |
997 } | |
998 | |
999 static Lisp_Coding_System * | |
771 | 1000 allocate_coding_system (struct coding_system_methods *codesys_meths, |
1001 Bytecount data_size, | |
1002 Lisp_Object name) | |
428 | 1003 { |
771 | 1004 Bytecount total_size = offsetof (Lisp_Coding_System, data) + data_size; |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1005 Lisp_Object obj = ALLOC_SIZED_LISP_OBJECT (total_size, coding_system); |
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
1006 Lisp_Coding_System *codesys = XCODING_SYSTEM (obj); |
1204 | 1007 |
771 | 1008 codesys->methods = codesys_meths; |
1204 | 1009 #define MARKED_SLOT(x) codesys->x = Qnil; |
1010 #include "coding-system-slots.h" | |
1011 | |
771 | 1012 CODING_SYSTEM_EOL_TYPE (codesys) = EOL_LF; |
1013 CODING_SYSTEM_NAME (codesys) = name; | |
1014 | |
1015 MAYBE_CODESYSMETH (codesys, init, (wrap_coding_system (codesys))); | |
428 | 1016 |
1017 return codesys; | |
1018 } | |
1019 | |
771 | 1020 static enum eol_type |
1021 symbol_to_eol_type (Lisp_Object symbol) | |
1022 { | |
1023 CHECK_SYMBOL (symbol); | |
1024 if (NILP (symbol)) return EOL_AUTODETECT; | |
1025 if (EQ (symbol, Qlf)) return EOL_LF; | |
1026 if (EQ (symbol, Qcrlf)) return EOL_CRLF; | |
1027 if (EQ (symbol, Qcr)) return EOL_CR; | |
1028 | |
1029 invalid_constant ("Unrecognized eol type", symbol); | |
1204 | 1030 RETURN_NOT_REACHED (EOL_AUTODETECT); |
771 | 1031 } |
1032 | |
1033 static Lisp_Object | |
1034 eol_type_to_symbol (enum eol_type type) | |
1035 { | |
1036 switch (type) | |
1037 { | |
2500 | 1038 default: ABORT (); |
771 | 1039 case EOL_LF: return Qlf; |
1040 case EOL_CRLF: return Qcrlf; | |
1041 case EOL_CR: return Qcr; | |
1042 case EOL_AUTODETECT: return Qnil; | |
1043 } | |
1044 } | |
1045 | |
1046 struct subsidiary_type | |
1047 { | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1048 const Ascbyte *extension; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1049 const Ascbyte *mnemonic_ext; |
771 | 1050 enum eol_type eol; |
1051 }; | |
1052 | |
1053 static struct subsidiary_type coding_subsidiary_list[] = | |
1054 { { "-unix", "", EOL_LF }, | |
1055 { "-dos", ":T", EOL_CRLF }, | |
1056 { "-mac", ":t", EOL_CR } }; | |
1057 | |
1058 /* kludge */ | |
428 | 1059 static void |
771 | 1060 setup_eol_coding_systems (Lisp_Object codesys) |
428 | 1061 { |
793 | 1062 int len = XSTRING_LENGTH (XSYMBOL (XCODING_SYSTEM_NAME (codesys))->name); |
2367 | 1063 Ibyte *codesys_name = alloca_ibytes (len + 7); |
771 | 1064 int mlen = -1; |
867 | 1065 Ibyte *codesys_mnemonic = 0; |
771 | 1066 Lisp_Object codesys_name_sym, sub_codesys; |
1067 int i; | |
1068 | |
1069 memcpy (codesys_name, | |
793 | 1070 XSTRING_DATA (XSYMBOL (XCODING_SYSTEM_NAME (codesys))->name), len); |
771 | 1071 |
1072 if (STRINGP (XCODING_SYSTEM_MNEMONIC (codesys))) | |
428 | 1073 { |
771 | 1074 mlen = XSTRING_LENGTH (XCODING_SYSTEM_MNEMONIC (codesys)); |
2367 | 1075 codesys_mnemonic = alloca_ibytes (mlen + 7); |
771 | 1076 memcpy (codesys_mnemonic, |
1077 XSTRING_DATA (XCODING_SYSTEM_MNEMONIC (codesys)), mlen); | |
1078 } | |
1079 | |
1080 /* Create three "subsidiary" coding systems, decoding data encoded using | |
1081 each of the three EOL types. We do this for each subsidiary by | |
1082 copying the original coding system, setting the EOL type | |
1083 appropriately, and setting the CANONICAL member of the new coding | |
1084 system to be a chain consisting of the original coding system followed | |
1085 by a convert-eol coding system to do the EOL decoding. For EOL type | |
1086 LF, however, we don't need any decoding, so we skip creating a | |
1087 CANONICAL. | |
1088 | |
1089 If the original coding system is not a text-type coding system | |
1090 (decodes byte->char), we need to coerce it to one by the appropriate | |
1091 wrapping in CANONICAL. */ | |
1092 | |
1093 for (i = 0; i < countof (coding_subsidiary_list); i++) | |
1094 { | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1095 const Ascbyte *extension = coding_subsidiary_list[i].extension; |
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1096 const Ascbyte *mnemonic_ext = coding_subsidiary_list[i].mnemonic_ext; |
771 | 1097 enum eol_type eol = coding_subsidiary_list[i].eol; |
1098 | |
2367 | 1099 qxestrcpy_ascii (codesys_name + len, extension); |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1100 codesys_name_sym = intern_istring (codesys_name); |
771 | 1101 if (mlen != -1) |
2367 | 1102 qxestrcpy_ascii (codesys_mnemonic + mlen, mnemonic_ext); |
771 | 1103 |
1104 sub_codesys = Fcopy_coding_system (codesys, codesys_name_sym); | |
1105 if (mlen != -1) | |
1106 XCODING_SYSTEM_MNEMONIC (sub_codesys) = | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1107 build_istring (codesys_mnemonic); |
771 | 1108 |
1109 if (eol != EOL_LF) | |
1110 { | |
1111 Lisp_Object chain = list2 (get_coding_system_for_text_file | |
1112 (codesys, 0), | |
1113 eol == EOL_CR ? Qconvert_eol_cr : | |
1114 Qconvert_eol_crlf); | |
1115 Lisp_Object canon = | |
1116 make_internal_coding_system | |
1117 (sub_codesys, "internal-subsidiary-eol-wrapper", | |
1118 Qchain, Qunbound, | |
1119 mlen != -1 ? | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1120 list6 (Qmnemonic, build_istring (codesys_mnemonic), |
771 | 1121 Qchain, chain, |
1122 Qcanonicalize_after_coding, sub_codesys) : | |
1123 list4 (Qchain, chain, | |
1124 Qcanonicalize_after_coding, sub_codesys)); | |
1125 XCODING_SYSTEM_CANONICAL (sub_codesys) = canon; | |
1126 } | |
1127 XCODING_SYSTEM_EOL_TYPE (sub_codesys) = eol; | |
1128 XCODING_SYSTEM_SUBSIDIARY_PARENT (sub_codesys) = codesys; | |
1129 XCODING_SYSTEM (codesys)->eol[eol] = sub_codesys; | |
428 | 1130 } |
1131 } | |
1132 | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1133 DEFUN ("coding-system-canonical-name-p", Fcoding_system_canonical_name_p, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1134 1, 1, 0, /* |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1135 Return t if OBJECT names a coding system, and is not a coding system alias. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1136 */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1137 (object)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1138 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1139 return CODING_SYSTEMP (Fgethash (object, Vcoding_system_hash_table, Qnil)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1140 ? Qt : Qnil; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1141 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1142 |
771 | 1143 /* Basic function to create new coding systems. For `make-coding-system', |
1144 NAME-OR-EXISTING is the NAME argument, PREFIX is null, and TYPE, | |
1145 DESCRIPTION, and PROPS are the same. All created coding systems are put | |
1146 in a hash table indexed by NAME. | |
1147 | |
1148 If PREFIX is a string, NAME-OR-EXISTING should specify an existing | |
1149 coding system (or nil), and an internal coding system will be created. | |
1150 The name of the coding system will be constructed by combining PREFIX | |
1151 with the name of the existing coding system (if given), and a number | |
1152 will be appended to insure uniqueness. In such a case, if Qunbound is | |
1153 given for DESCRIPTION, the description gets created based on the | |
1154 generated name. Also, if no mnemonic is given in the properties list, a | |
1155 mnemonic is created based on the generated name. | |
1156 | |
1157 For internal coding systems, the coding system is marked as internal | |
1158 (see `coding-system-list'), and no subsidiaries will be created or | |
1159 eol-wrapping will happen. Otherwise: | |
1160 | |
1161 -- if the eol-type property is `lf' or t, the coding system is merely | |
1162 created and returned. (For t, the coding system will be wrapped with | |
1163 an EOL autodetector when it's used to read a file.) | |
1164 | |
1165 -- if eol-type is `crlf' or `cr', after the coding system object is | |
1166 created, it will be wrapped in a chain with the appropriate | |
1167 convert-eol coding system (either `convert-eol-crlf' or | |
1168 `convert-eol-cr'), so that CRLF->LF or CR->LF conversion is done at | |
1169 decoding time, and the opposite at encoding time. The resulting | |
1170 chain becomes the CANONICAL field of the coding system object. | |
1171 | |
1172 -- if eol-type is nil or omitted, "subsidiaries" are generated: Three | |
1173 coding systems where the original coding system (before wrapping with | |
1174 convert-eol-autodetect) is either unwrapped or wrapped with | |
1175 convert-eol-crlf or convert-eol-cr, respectively, so that coding systems | |
1176 to handle LF, CRLF, and CR end-of-line indicators are created. (This | |
1177 crazy crap is based on existing behavior in other Mule versions, | |
1178 including FSF Emacs.) | |
1179 */ | |
428 | 1180 |
1181 static Lisp_Object | |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1182 make_coding_system_1 (Lisp_Object name_or_existing, const Ascbyte *prefix, |
771 | 1183 Lisp_Object type, Lisp_Object description, |
1184 Lisp_Object props) | |
428 | 1185 { |
771 | 1186 Lisp_Coding_System *cs; |
1187 int need_to_setup_eol_systems = 1; | |
1188 enum eol_type eol_wrapper = EOL_AUTODETECT; | |
1189 struct coding_system_methods *meths; | |
1190 Lisp_Object csobj; | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1191 Lisp_Object defmnem = Qnil, aliases = Qnil; |
771 | 1192 |
1193 if (NILP (type)) | |
1194 type = Qundecided; | |
1195 meths = decode_coding_system_type (type, ERROR_ME); | |
1196 | |
1197 if (prefix) | |
428 | 1198 { |
867 | 1199 Ibyte *newname = |
771 | 1200 emacs_sprintf_malloc (NULL, "%s-%s-%d", |
1201 prefix, | |
867 | 1202 NILP (name_or_existing) ? (Ibyte *) "nil" : |
771 | 1203 XSTRING_DATA (Fsymbol_name (XCODING_SYSTEM_NAME |
1204 (name_or_existing))), | |
1205 ++coding_system_tick); | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1206 name_or_existing = intern_istring (newname); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
1207 xfree (newname); |
771 | 1208 |
1209 if (UNBOUNDP (description)) | |
1210 { | |
1211 newname = | |
1212 emacs_sprintf_malloc | |
1213 (NULL, "For Internal Use (%s)", | |
1214 XSTRING_DATA (Fsymbol_name (name_or_existing))); | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1215 description = build_istring (newname); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
1216 xfree (newname); |
771 | 1217 } |
1218 | |
1219 newname = emacs_sprintf_malloc (NULL, "Int%d", coding_system_tick); | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1220 defmnem = build_istring (newname); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
1221 xfree (newname); |
428 | 1222 } |
771 | 1223 else |
1224 CHECK_SYMBOL (name_or_existing); | |
1225 | |
4303 | 1226 /* See is there an entry for name_or_existing in the defined coding system |
1227 hash table. */ | |
1228 csobj = find_coding_system (name_or_existing, 0); | |
1229 /* Error if it's there and not an autoload form. */ | |
1230 if (!NILP (csobj) && !CONSP (csobj)) | |
771 | 1231 invalid_operation ("Cannot redefine existing coding system", |
4303 | 1232 name_or_existing); |
771 | 1233 |
1234 cs = allocate_coding_system (meths, meths->extra_data_size, | |
1235 name_or_existing); | |
793 | 1236 csobj = wrap_coding_system (cs); |
771 | 1237 |
1238 cs->internal_p = !!prefix; | |
1239 | |
1240 if (NILP (description)) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
1241 description = build_ascstring (""); |
771 | 1242 else |
1243 CHECK_STRING (description); | |
1244 CODING_SYSTEM_DESCRIPTION (cs) = description; | |
1245 | |
1246 if (!NILP (defmnem)) | |
1247 CODING_SYSTEM_MNEMONIC (cs) = defmnem; | |
1248 | |
1249 { | |
1250 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, props) | |
1251 { | |
1252 int recognized = 1; | |
1253 | |
1254 if (EQ (key, Qmnemonic)) | |
1255 { | |
1256 if (!NILP (value)) | |
1257 CHECK_STRING (value); | |
1258 CODING_SYSTEM_MNEMONIC (cs) = value; | |
1259 } | |
1260 | |
1261 else if (EQ (key, Qdocumentation)) | |
1262 { | |
1263 if (!NILP (value)) | |
1264 CHECK_STRING (value); | |
1265 CODING_SYSTEM_DOCUMENTATION (cs) = value; | |
1266 } | |
1267 | |
1268 else if (EQ (key, Qeol_type)) | |
1269 { | |
1270 need_to_setup_eol_systems = NILP (value); | |
1271 if (EQ (value, Qt)) | |
1272 value = Qnil; | |
1273 eol_wrapper = symbol_to_eol_type (value); | |
1274 } | |
1275 | |
1276 else if (EQ (key, Qpost_read_conversion)) | |
1277 CODING_SYSTEM_POST_READ_CONVERSION (cs) = value; | |
1278 else if (EQ (key, Qpre_write_conversion)) | |
1279 CODING_SYSTEM_PRE_WRITE_CONVERSION (cs) = value; | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1280 else if (EQ (key, Qaliases)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1281 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1282 EXTERNAL_LIST_LOOP_2 (alias, value) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1283 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1284 CHECK_SYMBOL (alias); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1285 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1286 if (!NILP (Fcoding_system_canonical_name_p (alias))) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1287 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1288 invalid_change ("Symbol is the canonical name of a " |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1289 "coding system and cannot be redefined", |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1290 alias); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1291 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1292 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1293 aliases = value; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1294 } |
771 | 1295 /* FSF compatibility */ |
1296 else if (EQ (key, Qtranslation_table_for_decode)) | |
1297 ; | |
1298 else if (EQ (key, Qtranslation_table_for_encode)) | |
1299 ; | |
1300 else if (EQ (key, Qsafe_chars)) | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1301 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1302 CHECK_CHAR_TABLE (value); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1303 CODING_SYSTEM_SAFE_CHARS (cs) = value; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1304 } |
771 | 1305 else if (EQ (key, Qsafe_charsets)) |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1306 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1307 if (!EQ (Qt, value) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1308 /* Would be nice to actually do this check, but there are |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1309 some order conflicts with japanese.el and |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1310 mule-coding.el */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1311 && 0) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1312 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1313 #ifdef MULE |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1314 EXTERNAL_LIST_LOOP_2 (safe_charset, value) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1315 CHECK_CHARSET (Ffind_charset (safe_charset)); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1316 #endif |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1317 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1318 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1319 CODING_SYSTEM_SAFE_CHARSETS (cs) = value; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1320 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1321 else if (EQ (key, Qcategory)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1322 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1323 Fput (name_or_existing, intern ("coding-system-property"), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1324 Fplist_put (Fget (name_or_existing, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1325 intern ("coding-system-property"), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1326 Qnil), |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1327 Qcategory, value)); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1328 } |
771 | 1329 else if (EQ (key, Qmime_charset)) |
1330 ; | |
1331 else if (EQ (key, Qvalid_codes)) | |
1332 ; | |
1333 else | |
1334 recognized = CODESYSMETH_OR_GIVEN (cs, putprop, | |
1335 (csobj, key, value), 0); | |
1336 | |
1337 if (!recognized) | |
1338 invalid_constant ("Unrecognized property", key); | |
1339 } | |
1340 } | |
1341 | |
1342 { | |
1343 XCODING_SYSTEM_CANONICAL (csobj) = | |
1344 CODESYSMETH_OR_GIVEN (cs, canonicalize, (csobj), Qnil); | |
1345 XCODING_SYSTEM_EOL_TYPE (csobj) = EOL_AUTODETECT; /* for copy-coding-system | |
1346 below */ | |
1347 | |
4303 | 1348 Fputhash (name_or_existing, csobj, Vcoding_system_hash_table); |
1349 | |
771 | 1350 if (need_to_setup_eol_systems && !cs->internal_p) |
1351 setup_eol_coding_systems (csobj); | |
1352 else if (eol_wrapper == EOL_CR || eol_wrapper == EOL_CRLF) | |
1353 { | |
1354 /* If a specific eol-type (other than LF) was specified, we handle | |
1355 this by converting the coding system into a chain that wraps the | |
1356 coding system along with a convert-eol system after it, in | |
1357 exactly that same switcheroo fashion that the normal | |
1358 canonicalize method works -- BUT we will run into a problem if | |
1359 we do it the obvious way, because when `chain' creates its | |
1360 substreams, the substream containing the coding system we're | |
1361 creating will have canonicalization expansion done on it, | |
1362 leading to infinite recursion. So we have to generate a new, | |
1363 internal coding system with the previous value of CANONICAL. */ | |
867 | 1364 Ibyte *newname = |
771 | 1365 emacs_sprintf_malloc |
1366 (NULL, "internal-eol-copy-%s-%d", | |
1367 XSTRING_DATA (Fsymbol_name (name_or_existing)), | |
1368 ++coding_system_tick); | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
1369 Lisp_Object newnamesym = intern_istring (newname); |
771 | 1370 Lisp_Object copied = Fcopy_coding_system (csobj, newnamesym); |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
1371 xfree (newname); |
771 | 1372 |
1373 XCODING_SYSTEM_CANONICAL (csobj) = | |
1374 make_internal_coding_system | |
1375 (csobj, | |
1376 "internal-eol-wrapper", | |
1377 Qchain, Qunbound, | |
1378 list4 (Qchain, | |
1379 list2 (copied, | |
1380 eol_wrapper == EOL_CR ? | |
1381 Qconvert_eol_cr : | |
1382 Qconvert_eol_crlf), | |
1383 Qcanonicalize_after_coding, | |
1384 csobj)); | |
1385 } | |
1386 XCODING_SYSTEM_EOL_TYPE (csobj) = eol_wrapper; | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1387 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1388 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1389 EXTERNAL_LIST_LOOP_2 (alias, aliases) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1390 Fdefine_coding_system_alias (alias, csobj); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1391 } |
771 | 1392 } |
1393 | |
1394 return csobj; | |
428 | 1395 } |
1396 | |
771 | 1397 Lisp_Object |
4528
726060ee587c
First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents:
4522
diff
changeset
|
1398 make_internal_coding_system (Lisp_Object existing, const Ascbyte *prefix, |
771 | 1399 Lisp_Object type, Lisp_Object description, |
1400 Lisp_Object props) | |
1401 { | |
1402 return make_coding_system_1 (existing, prefix, type, description, props); | |
1403 } | |
428 | 1404 |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1405 DEFUN ("make-coding-system-internal", Fmake_coding_system_internal, 2, 4, 0, /* |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1406 See `make-coding-system'. This does much of the work of that function. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1407 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1408 Without Mule support, it does all the work of that function, and an alias |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1409 exists, mapping `make-coding-system' to |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1410 `make-coding-system-internal'. You'll need a non-Mule XEmacs to read the |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1411 complete docstring. Or you can just read it in make-coding-system.el; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1412 something like the following should work: |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1413 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
1414 \\[find-function-other-window] find-file RET \\[find-file] mule/make-coding-system.el RET |
771 | 1415 |
428 | 1416 */ |
771 | 1417 (name, type, description, props)) |
428 | 1418 { |
771 | 1419 return make_coding_system_1 (name, 0, type, description, props); |
428 | 1420 } |
1421 | |
1422 DEFUN ("copy-coding-system", Fcopy_coding_system, 2, 2, 0, /* | |
1423 Copy OLD-CODING-SYSTEM to NEW-NAME. | |
1424 If NEW-NAME does not name an existing coding system, a new one will | |
1425 be created. | |
771 | 1426 If you are using this function to create an alias, think again: |
1427 Use `define-coding-system-alias' instead. | |
428 | 1428 */ |
1429 (old_coding_system, new_name)) | |
1430 { | |
1431 Lisp_Object new_coding_system; | |
1432 old_coding_system = Fget_coding_system (old_coding_system); | |
771 | 1433 new_coding_system = |
4303 | 1434 UNBOUNDP (new_name) ? Qnil : find_coding_system (new_name, 0); |
428 | 1435 if (NILP (new_coding_system)) |
1436 { | |
793 | 1437 new_coding_system = |
1438 wrap_coding_system | |
1439 (allocate_coding_system | |
1440 (XCODING_SYSTEM (old_coding_system)->methods, | |
1441 XCODING_SYSTEM (old_coding_system)->methods->extra_data_size, | |
1442 new_name)); | |
771 | 1443 if (!UNBOUNDP (new_name)) |
1444 Fputhash (new_name, new_coding_system, Vcoding_system_hash_table); | |
428 | 1445 } |
771 | 1446 else if (XCODING_SYSTEM (old_coding_system)->methods != |
1447 XCODING_SYSTEM (new_coding_system)->methods) | |
1448 invalid_operation_2 ("Coding systems not same type", | |
1449 old_coding_system, new_coding_system); | |
428 | 1450 |
1451 { | |
1452 Lisp_Coding_System *to = XCODING_SYSTEM (new_coding_system); | |
1453 Lisp_Coding_System *from = XCODING_SYSTEM (old_coding_system); | |
5120
d1247f3cc363
latest work on lisp-object workspace;
Ben Wing <ben@xemacs.org>
parents:
5118
diff
changeset
|
1454 COPY_SIZED_LISP_OBJECT (to, from, sizeof_coding_system (from)); |
428 | 1455 to->name = new_name; |
1456 } | |
1457 return new_coding_system; | |
1458 } | |
1459 | |
2297 | 1460 /* #### Shouldn't this really be a find/get pair? */ |
1461 | |
440 | 1462 DEFUN ("coding-system-alias-p", Fcoding_system_alias_p, 1, 1, 0, /* |
1463 Return t if OBJECT is a coding system alias. | |
1464 All coding system aliases are created by `define-coding-system-alias'. | |
1465 */ | |
1466 (object)) | |
428 | 1467 { |
440 | 1468 return SYMBOLP (Fgethash (object, Vcoding_system_hash_table, Qzero)) |
1469 ? Qt : Qnil; | |
1470 } | |
1471 | |
1472 DEFUN ("coding-system-aliasee", Fcoding_system_aliasee, 1, 1, 0, /* | |
1473 Return the coding-system symbol for which symbol ALIAS is an alias. | |
1474 */ | |
1475 (alias)) | |
1476 { | |
1477 Lisp_Object aliasee = Fgethash (alias, Vcoding_system_hash_table, Qnil); | |
1478 if (SYMBOLP (aliasee)) | |
1479 return aliasee; | |
1480 else | |
563 | 1481 invalid_argument ("Symbol is not a coding system alias", alias); |
1204 | 1482 RETURN_NOT_REACHED (Qnil); |
440 | 1483 } |
1484 | |
1485 /* A maphash function, for removing dangling coding system aliases. */ | |
1486 static int | |
2286 | 1487 dangling_coding_system_alias_p (Lisp_Object UNUSED (alias), |
440 | 1488 Lisp_Object aliasee, |
1489 void *dangling_aliases) | |
1490 { | |
1491 if (SYMBOLP (aliasee) | |
1492 && NILP (Fgethash (aliasee, Vcoding_system_hash_table, Qnil))) | |
428 | 1493 { |
440 | 1494 (*(int *) dangling_aliases)++; |
1495 return 1; | |
428 | 1496 } |
440 | 1497 else |
1498 return 0; | |
1499 } | |
1500 | |
1501 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, 2, 2, 0, /* | |
1502 Define symbol ALIAS as an alias for coding system ALIASEE. | |
1503 | |
1504 You can use this function to redefine an alias that has already been defined, | |
1505 but you cannot redefine a name which is the canonical name for a coding system. | |
1506 \(a canonical name of a coding system is what is returned when you call | |
1507 `coding-system-name' on a coding system). | |
1508 | |
1509 ALIASEE itself can be an alias, which allows you to define nested aliases. | |
1510 | |
1511 You are forbidden, however, from creating alias loops or `dangling' aliases. | |
1512 These will be detected, and an error will be signaled if you attempt to do so. | |
1513 | |
1514 If ALIASEE is nil, then ALIAS will simply be undefined. | |
1515 | |
1516 See also `coding-system-alias-p', `coding-system-aliasee', | |
1517 and `coding-system-canonical-name-p'. | |
1518 */ | |
1519 (alias, aliasee)) | |
1520 { | |
2286 | 1521 Lisp_Object probe; |
440 | 1522 |
1523 CHECK_SYMBOL (alias); | |
1524 | |
1525 if (!NILP (Fcoding_system_canonical_name_p (alias))) | |
563 | 1526 invalid_change |
440 | 1527 ("Symbol is the canonical name of a coding system and cannot be redefined", |
1528 alias); | |
1529 | |
1530 if (NILP (aliasee)) | |
1531 { | |
771 | 1532 Lisp_Object subsidiary_unix = add_suffix_to_symbol (alias, "-unix"); |
1533 Lisp_Object subsidiary_dos = add_suffix_to_symbol (alias, "-dos"); | |
1534 Lisp_Object subsidiary_mac = add_suffix_to_symbol (alias, "-mac"); | |
440 | 1535 |
1536 Fremhash (alias, Vcoding_system_hash_table); | |
1537 | |
1538 /* Undefine subsidiary aliases, | |
1539 presumably created by a previous call to this function */ | |
1540 if (! NILP (Fcoding_system_alias_p (subsidiary_unix)) && | |
1541 ! NILP (Fcoding_system_alias_p (subsidiary_dos)) && | |
1542 ! NILP (Fcoding_system_alias_p (subsidiary_mac))) | |
1543 { | |
1544 Fdefine_coding_system_alias (subsidiary_unix, Qnil); | |
1545 Fdefine_coding_system_alias (subsidiary_dos, Qnil); | |
1546 Fdefine_coding_system_alias (subsidiary_mac, Qnil); | |
1547 } | |
1548 | |
1549 /* Undefine dangling coding system aliases. */ | |
1550 { | |
1551 int dangling_aliases; | |
1552 | |
1553 do { | |
1554 dangling_aliases = 0; | |
1555 elisp_map_remhash (dangling_coding_system_alias_p, | |
1556 Vcoding_system_hash_table, | |
1557 &dangling_aliases); | |
1558 } while (dangling_aliases > 0); | |
1559 } | |
1560 | |
1561 return Qnil; | |
1562 } | |
1563 | |
1564 if (CODING_SYSTEMP (aliasee)) | |
1565 aliasee = XCODING_SYSTEM_NAME (aliasee); | |
1566 | |
1567 /* Checks that aliasee names a coding-system */ | |
2286 | 1568 (void) Fget_coding_system (aliasee); |
440 | 1569 |
1570 /* Check for coding system alias loops */ | |
1571 if (EQ (alias, aliasee)) | |
563 | 1572 alias_loop: invalid_operation_2 |
440 | 1573 ("Attempt to create a coding system alias loop", alias, aliasee); |
1574 | |
1575 for (probe = aliasee; | |
1576 SYMBOLP (probe); | |
1577 probe = Fgethash (probe, Vcoding_system_hash_table, Qzero)) | |
1578 { | |
1579 if (EQ (probe, alias)) | |
1580 goto alias_loop; | |
1581 } | |
1582 | |
1583 Fputhash (alias, aliasee, Vcoding_system_hash_table); | |
1584 | |
1585 /* Set up aliases for subsidiaries. | |
2297 | 1586 #### There must be a better way to handle subsidiary coding systems. |
1587 Inquiring Minds Want To Know: shouldn't they always be chains? */ | |
440 | 1588 { |
1589 static const char *suffixes[] = { "-unix", "-dos", "-mac" }; | |
1590 int i; | |
1591 for (i = 0; i < countof (suffixes); i++) | |
1592 { | |
1593 Lisp_Object alias_subsidiary = | |
771 | 1594 add_suffix_to_symbol (alias, suffixes[i]); |
440 | 1595 Lisp_Object aliasee_subsidiary = |
771 | 1596 add_suffix_to_symbol (aliasee, suffixes[i]); |
440 | 1597 |
1598 if (! NILP (Ffind_coding_system (aliasee_subsidiary))) | |
1599 Fdefine_coding_system_alias (alias_subsidiary, aliasee_subsidiary); | |
1600 } | |
1601 } | |
428 | 1602 /* FSF return value is a vector of [ALIAS-unix ALIAS-dos ALIAS-mac], |
1603 but it doesn't look intentional, so I'd rather return something | |
1604 meaningful or nothing at all. */ | |
1605 return Qnil; | |
1606 } | |
1607 | |
1608 static Lisp_Object | |
771 | 1609 subsidiary_coding_system (Lisp_Object coding_system, enum eol_type type) |
428 | 1610 { |
1611 Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system); | |
1612 Lisp_Object new_coding_system; | |
1613 | |
1614 switch (type) | |
1615 { | |
1616 case EOL_AUTODETECT: return coding_system; | |
1617 case EOL_LF: new_coding_system = CODING_SYSTEM_EOL_LF (cs); break; | |
1618 case EOL_CR: new_coding_system = CODING_SYSTEM_EOL_CR (cs); break; | |
1619 case EOL_CRLF: new_coding_system = CODING_SYSTEM_EOL_CRLF (cs); break; | |
2500 | 1620 default: ABORT (); return Qnil; |
428 | 1621 } |
1622 | |
1623 return NILP (new_coding_system) ? coding_system : new_coding_system; | |
1624 } | |
1625 | |
1626 DEFUN ("subsidiary-coding-system", Fsubsidiary_coding_system, 2, 2, 0, /* | |
1627 Return the subsidiary coding system of CODING-SYSTEM with eol type EOL-TYPE. | |
771 | 1628 The logically opposite operation is `coding-system-base'. |
428 | 1629 */ |
1630 (coding_system, eol_type)) | |
1631 { | |
771 | 1632 coding_system = get_coding_system_for_text_file (coding_system, 0); |
428 | 1633 |
1634 return subsidiary_coding_system (coding_system, | |
1635 symbol_to_eol_type (eol_type)); | |
1636 } | |
1637 | |
771 | 1638 DEFUN ("coding-system-base", Fcoding_system_base, |
1639 1, 1, 0, /* | |
1640 Return the base coding system of CODING-SYSTEM. | |
1641 If CODING-SYSTEM is a subsidiary, this returns its parent; otherwise, it | |
1642 returns CODING-SYSTEM. | |
1643 The logically opposite operation is `subsidiary-coding-system'. | |
1644 */ | |
1645 (coding_system)) | |
1646 { | |
1647 Lisp_Object base; | |
1648 | |
1649 coding_system = Fget_coding_system (coding_system); | |
1650 if (EQ (XCODING_SYSTEM_NAME (coding_system), Qbinary)) | |
1651 return Fget_coding_system (Qraw_text); /* hack! */ | |
1652 base = XCODING_SYSTEM_SUBSIDIARY_PARENT (coding_system); | |
1653 if (!NILP (base)) | |
1654 return base; | |
1655 return coding_system; | |
1656 } | |
1657 | |
1658 DEFUN ("coding-system-used-for-io", Fcoding_system_used_for_io, | |
1659 1, 1, 0, /* | |
1660 Return the coding system actually used for I/O. | |
1661 In some cases (e.g. when a particular EOL type is specified) this won't be | |
2297 | 1662 the coding system itself. This can be useful when trying to determine |
1663 precisely how data was decoded. | |
771 | 1664 */ |
1665 (coding_system)) | |
1666 { | |
1667 Lisp_Object canon; | |
1668 | |
1669 coding_system = Fget_coding_system (coding_system); | |
1670 canon = XCODING_SYSTEM_CANONICAL (coding_system); | |
1671 if (!NILP (canon)) | |
1672 return canon; | |
1673 return coding_system; | |
1674 } | |
1675 | |
428 | 1676 |
1677 /************************************************************************/ | |
1678 /* Coding system accessors */ | |
1679 /************************************************************************/ | |
1680 | |
771 | 1681 DEFUN ("coding-system-description", Fcoding_system_description, 1, 1, 0, /* |
1682 Return the description for CODING-SYSTEM. | |
1683 The `description' of a coding system is a short English phrase giving the | |
1684 name rendered according to English punctuation rules, plus possibly some | |
1685 explanatory text (typically in the form of a parenthetical phrase). The | |
1686 description is intended to be short enough that it can appear as a menu item, | |
1687 and clear enough to be recognizable even to someone who is assumed to have | |
1688 some basic familiarity with different encodings but may not know all the | |
1689 technical names; thus, for `cn-gb-2312' is described as "Chinese EUC" and | |
1690 `hz-gb-2312' is described as "Hz/ZW (Chinese)", where the actual name of | |
1691 the encoding is given, followed by a note that this is a Chinese encoding, | |
1692 because the great majority of people encountering this would have no idea | |
1693 what it is, and giving the language indicates whether the encoding should | |
1694 just be ignored or (conceivably) investigated more thoroughly. | |
428 | 1695 */ |
1696 (coding_system)) | |
1697 { | |
1698 coding_system = Fget_coding_system (coding_system); | |
771 | 1699 return XCODING_SYSTEM_DESCRIPTION (coding_system); |
428 | 1700 } |
1701 | |
1702 DEFUN ("coding-system-type", Fcoding_system_type, 1, 1, 0, /* | |
1703 Return the type of CODING-SYSTEM. | |
1704 */ | |
1705 (coding_system)) | |
1706 { | |
771 | 1707 coding_system = Fget_coding_system (coding_system); |
1708 return XCODING_SYSTEM_TYPE (coding_system); | |
428 | 1709 } |
1710 | |
1711 DEFUN ("coding-system-property", Fcoding_system_property, 2, 2, 0, /* | |
1712 Return the PROP property of CODING-SYSTEM. | |
1713 */ | |
1714 (coding_system, prop)) | |
1715 { | |
1716 coding_system = Fget_coding_system (coding_system); | |
1717 CHECK_SYMBOL (prop); | |
1718 | |
1719 if (EQ (prop, Qname)) | |
1720 return XCODING_SYSTEM_NAME (coding_system); | |
1721 else if (EQ (prop, Qtype)) | |
1722 return Fcoding_system_type (coding_system); | |
771 | 1723 else if (EQ (prop, Qdescription)) |
1724 return XCODING_SYSTEM_DESCRIPTION (coding_system); | |
428 | 1725 else if (EQ (prop, Qmnemonic)) |
1726 return XCODING_SYSTEM_MNEMONIC (coding_system); | |
771 | 1727 else if (EQ (prop, Qdocumentation)) |
1728 return XCODING_SYSTEM_DOCUMENTATION (coding_system); | |
428 | 1729 else if (EQ (prop, Qeol_type)) |
771 | 1730 return eol_type_to_symbol (XCODING_SYSTEM_EOL_TYPE |
1731 (coding_system)); | |
428 | 1732 else if (EQ (prop, Qeol_lf)) |
1733 return XCODING_SYSTEM_EOL_LF (coding_system); | |
1734 else if (EQ (prop, Qeol_crlf)) | |
1735 return XCODING_SYSTEM_EOL_CRLF (coding_system); | |
1736 else if (EQ (prop, Qeol_cr)) | |
1737 return XCODING_SYSTEM_EOL_CR (coding_system); | |
1738 else if (EQ (prop, Qpost_read_conversion)) | |
1739 return XCODING_SYSTEM_POST_READ_CONVERSION (coding_system); | |
1740 else if (EQ (prop, Qpre_write_conversion)) | |
1741 return XCODING_SYSTEM_PRE_WRITE_CONVERSION (coding_system); | |
4568
1d74a1d115ee
Add #'query-coding-region tests; do the work necessary to get them running.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4303
diff
changeset
|
1742 else if (EQ (prop, Qsafe_charsets)) |
1d74a1d115ee
Add #'query-coding-region tests; do the work necessary to get them running.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4303
diff
changeset
|
1743 return XCODING_SYSTEM_SAFE_CHARSETS (coding_system); |
1d74a1d115ee
Add #'query-coding-region tests; do the work necessary to get them running.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4303
diff
changeset
|
1744 else if (EQ (prop, Qsafe_chars)) |
1d74a1d115ee
Add #'query-coding-region tests; do the work necessary to get them running.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4303
diff
changeset
|
1745 return XCODING_SYSTEM_SAFE_CHARS (coding_system); |
771 | 1746 else |
1747 { | |
1748 Lisp_Object value = CODESYSMETH_OR_GIVEN (XCODING_SYSTEM (coding_system), | |
1749 getprop, | |
1750 (coding_system, prop), | |
1751 Qunbound); | |
1752 if (UNBOUNDP (value)) | |
1753 invalid_constant ("Unrecognized property", prop); | |
1754 return value; | |
1755 } | |
1756 } | |
1757 | |
1758 | |
1759 /************************************************************************/ | |
1760 /* Coding stream functions */ | |
1761 /************************************************************************/ | |
1762 | |
1763 /* A coding stream is a stream used for encoding or decoding text. The | |
1764 coding-stream object keeps track of the actual coding system, the stream | |
1765 that is at the other end, and data that needs to be persistent across | |
1766 the lifetime of the stream. */ | |
1767 | |
1204 | 1768 extern const struct sized_memory_description chain_coding_stream_description; |
1769 extern const struct sized_memory_description undecided_coding_stream_description; | |
1770 | |
1771 static const struct memory_description coding_stream_data_description_1 []= { | |
2551 | 1772 { XD_BLOCK_PTR, chain_coding_system, 1, |
1773 { &chain_coding_stream_description } }, | |
1774 { XD_BLOCK_PTR, undecided_coding_system, 1, | |
1775 { &undecided_coding_stream_description } }, | |
1204 | 1776 { XD_END } |
1777 }; | |
1778 | |
1779 static const struct sized_memory_description coding_stream_data_description = { | |
1780 sizeof (void *), coding_stream_data_description_1 | |
1781 }; | |
1782 | |
1783 static const struct memory_description coding_lstream_description[] = { | |
1784 { XD_INT, offsetof (struct coding_stream, type) }, | |
1785 { XD_LISP_OBJECT, offsetof (struct coding_stream, orig_codesys) }, | |
1786 { XD_LISP_OBJECT, offsetof (struct coding_stream, codesys) }, | |
1787 { XD_LISP_OBJECT, offsetof (struct coding_stream, other_end) }, | |
1788 { XD_UNION, offsetof (struct coding_stream, data), | |
2551 | 1789 XD_INDIRECT (0, 0), { &coding_stream_data_description } }, |
1204 | 1790 { XD_END } |
1791 }; | |
1792 | |
1793 DEFINE_LSTREAM_IMPLEMENTATION_WITH_DATA ("coding", coding); | |
771 | 1794 |
1795 /* Encoding and decoding are parallel operations, so we create just one | |
1796 stream for both. "Decoding" may involve the extra step of autodetection | |
1797 of the data format, but that's only because of the conventional | |
1798 definition of decoding as converting from external- to | |
1799 internal-formatted data. | |
1800 | |
2297 | 1801 [[ REWRITE ME! ]] |
1802 | |
771 | 1803 #### We really need to abstract out the concept of "data formats" and |
1804 define "converters" that convert from and to specified formats, | |
1805 eliminating the idea of decoding and encoding. When specifying a | |
1806 conversion process, we need to give the data formats themselves, not the | |
1807 conversion processes -- e.g. a coding system called "Unicode->multibyte" | |
1808 converts in both directions, and we could auto-detect the format of data | |
1809 at either end. */ | |
1810 | |
1811 static Bytecount | |
1812 coding_reader (Lstream *stream, unsigned char *data, Bytecount size) | |
1813 { | |
1814 unsigned char *orig_data = data; | |
1815 Bytecount read_size; | |
1816 int error_occurred = 0; | |
1817 struct coding_stream *str = CODING_STREAM_DATA (stream); | |
1818 | |
1819 /* We need to interface to coding_{de,en}code_1(), which expects to take | |
1820 some amount of data and store the result into a Dynarr. We have | |
1821 coding_{de,en}code_1() store into c->runoff, and take data from there | |
1822 as necessary. */ | |
1823 | |
1824 /* We loop until we have enough data, reading chunks from the other | |
1825 end and converting it. */ | |
1826 while (1) | |
1827 { | |
1828 /* Take data from convert_to if we can. Make sure to take at | |
1829 most SIZE bytes, and delete the data from convert_to. */ | |
1830 if (Dynarr_length (str->convert_to) > 0) | |
1831 { | |
1832 Bytecount chunk = | |
1833 min (size, (Bytecount) Dynarr_length (str->convert_to)); | |
4967 | 1834 memcpy (data, Dynarr_begin (str->convert_to), chunk); |
771 | 1835 Dynarr_delete_many (str->convert_to, 0, chunk); |
1836 data += chunk; | |
1837 size -= chunk; | |
1838 } | |
1839 | |
1840 if (size == 0) | |
1841 break; /* No more room for data */ | |
1842 | |
1843 if (str->eof) | |
1844 break; | |
1845 | |
1846 { | |
1847 /* Exhausted convert_to, so get some more. Read into convert_from, | |
1848 after existing "rejected" data from the last conversion. */ | |
1849 Bytecount rejected = Dynarr_length (str->convert_from); | |
1850 /* #### 1024 is arbitrary; we really need to separate 0 from EOF, | |
1851 and when we get 0, keep taking more data until we don't get 0 -- | |
1852 we don't know how much data the conversion routine might need | |
2297 | 1853 before it can generate any data of its own (eg, bzip2). */ |
814 | 1854 Bytecount readmore = |
1855 str->one_byte_at_a_time ? (Bytecount) 1 : | |
1856 max (size, (Bytecount) 1024); | |
771 | 1857 |
1858 Dynarr_add_many (str->convert_from, 0, readmore); | |
1859 read_size = Lstream_read (str->other_end, | |
1860 Dynarr_atp (str->convert_from, rejected), | |
1861 readmore); | |
1862 /* Trim size down to how much we actually got */ | |
5038 | 1863 Dynarr_set_lengthr (str->convert_from, rejected + max (0, read_size)); |
771 | 1864 } |
1865 | |
1866 if (read_size < 0) /* LSTREAM_ERROR */ | |
1867 { | |
1868 error_occurred = 1; | |
1869 break; | |
1870 } | |
1871 if (read_size == 0) /* LSTREAM_EOF */ | |
1872 /* There might be some more end data produced in the translation, | |
1873 so we set a flag and call the conversion method once more to | |
1874 output any final stuff it may be holding, any "go back to a sane | |
1875 state" escape sequences, etc. The conversion method is free to | |
1876 look at this flag, and we use it above to stop looping. */ | |
1877 str->eof = 1; | |
1878 { | |
1879 Bytecount processed; | |
1880 Bytecount to_process = Dynarr_length (str->convert_from); | |
1881 | |
1882 /* Convert the data, and save any rejected data in convert_from */ | |
1883 processed = | |
1884 XCODESYSMETH (str->codesys, convert, | |
4967 | 1885 (str, Dynarr_begin (str->convert_from), |
771 | 1886 str->convert_to, to_process)); |
1887 if (processed < 0) | |
1888 { | |
1889 error_occurred = 1; | |
1890 break; | |
1891 } | |
1892 assert (processed <= to_process); | |
1893 if (processed < to_process) | |
4967 | 1894 memmove (Dynarr_begin (str->convert_from), |
771 | 1895 Dynarr_atp (str->convert_from, processed), |
1896 to_process - processed); | |
5038 | 1897 Dynarr_set_lengthr (str->convert_from, to_process - processed); |
771 | 1898 } |
1899 } | |
1900 | |
1901 if (data - orig_data == 0) | |
1902 return error_occurred ? -1 : 0; | |
1903 else | |
1904 return data - orig_data; | |
1905 } | |
1906 | |
1907 static Bytecount | |
1908 coding_writer (Lstream *stream, const unsigned char *data, Bytecount size) | |
1909 { | |
1910 struct coding_stream *str = CODING_STREAM_DATA (stream); | |
1911 | |
1912 /* Convert all our data into convert_to, and then attempt to write | |
1913 it all out to the other end. */ | |
1914 Dynarr_reset (str->convert_to); | |
1915 size = XCODESYSMETH (str->codesys, convert, | |
1916 (str, data, str->convert_to, size)); | |
4967 | 1917 if (Lstream_write (str->other_end, Dynarr_begin (str->convert_to), |
771 | 1918 Dynarr_length (str->convert_to)) < 0) |
1919 return -1; | |
1920 else | |
1921 /* The return value indicates how much of the incoming data was | |
1922 processed, not how many bytes were written. */ | |
1923 return size; | |
1924 } | |
1925 | |
1926 static int | |
1927 encode_decode_source_sink_type_is_char (Lisp_Object cs, | |
1928 enum source_or_sink sex, | |
1929 enum encode_decode direction) | |
1930 { | |
1931 return (direction == CODING_DECODE ? | |
1932 decoding_source_sink_type_is_char (cs, sex) : | |
1933 encoding_source_sink_type_is_char (cs, sex)); | |
1934 } | |
1935 | |
1936 /* Ensure that the convert methods only get full characters sent to them to | |
1937 convert if the source of that conversion is characters; and that no such | |
1938 full-character checking happens when the source is bytes. Keep in mind | |
1939 that (1) the conversion_end_type return values take the perspective of | |
1940 encoding; (2) the source for decoding is the same as the sink for | |
1941 encoding; (3) when writing, the data is given to us, and we set our own | |
1942 stream to be character mode or not; (4) when reading, the data comes | |
1943 from the other_end stream, and we set that one to be character mode or | |
1944 not. This is consistent with the comment above the prototype for | |
1945 Lstream_set_character_mode(), which lays out rules for who is allowed to | |
1946 modify the character type mode on a stream. | |
1947 | |
814 | 1948 If we're a read stream, we're always setting character mode on the |
1949 source, but we also set it on ourselves consistent with the flag that | |
1950 can disable this (see again the comment above | |
1951 Lstream_set_character_mode()). | |
1952 */ | |
771 | 1953 |
1954 static void | |
1955 set_coding_character_mode (Lstream *stream) | |
1956 { | |
1957 struct coding_stream *str = CODING_STREAM_DATA (stream); | |
1958 Lstream *stream_to_set = | |
1959 stream->flags & LSTREAM_FL_WRITE ? stream : str->other_end; | |
1960 if (encode_decode_source_sink_type_is_char | |
1961 (str->codesys, CODING_SOURCE, str->direction)) | |
1962 Lstream_set_character_mode (stream_to_set); | |
1963 else | |
1964 Lstream_unset_character_mode (stream_to_set); | |
814 | 1965 if (str->set_char_mode_on_us_when_reading && |
1966 (stream->flags & LSTREAM_FL_READ)) | |
1967 { | |
1968 if (encode_decode_source_sink_type_is_char | |
1969 (str->codesys, CODING_SINK, str->direction)) | |
1970 Lstream_set_character_mode (stream); | |
1971 else | |
1972 Lstream_unset_character_mode (stream); | |
1973 } | |
771 | 1974 } |
1975 | |
1976 static Lisp_Object | |
1977 coding_marker (Lisp_Object stream) | |
1978 { | |
1979 struct coding_stream *str = CODING_STREAM_DATA (XLSTREAM (stream)); | |
1980 | |
1981 mark_object (str->orig_codesys); | |
1982 mark_object (str->codesys); | |
1983 MAYBE_XCODESYSMETH (str->codesys, mark_coding_stream, (str)); | |
1984 return wrap_lstream (str->other_end); | |
1985 } | |
1986 | |
1987 static int | |
1988 coding_rewinder (Lstream *stream) | |
1989 { | |
1990 struct coding_stream *str = CODING_STREAM_DATA (stream); | |
1991 MAYBE_XCODESYSMETH (str->codesys, rewind_coding_stream, (str)); | |
1992 | |
1993 str->ch = 0; | |
1994 Dynarr_reset (str->convert_to); | |
1995 Dynarr_reset (str->convert_from); | |
1996 return Lstream_rewind (str->other_end); | |
1997 } | |
1998 | |
1999 static int | |
2000 coding_seekable_p (Lstream *stream) | |
2001 { | |
2002 struct coding_stream *str = CODING_STREAM_DATA (stream); | |
2003 return Lstream_seekable_p (str->other_end); | |
2004 } | |
2005 | |
2006 static int | |
2007 coding_flusher (Lstream *stream) | |
2008 { | |
2009 struct coding_stream *str = CODING_STREAM_DATA (stream); | |
2010 return Lstream_flush (str->other_end); | |
2011 } | |
2012 | |
2013 static int | |
2014 coding_closer (Lstream *stream) | |
2015 { | |
2016 struct coding_stream *str = CODING_STREAM_DATA (stream); | |
2017 if (stream->flags & LSTREAM_FL_WRITE) | |
2018 { | |
2019 str->eof = 1; | |
2020 coding_writer (stream, 0, 0); | |
2021 str->eof = 0; | |
2022 } | |
2023 /* It's safe to free the runoff dynarrs now because they are used only | |
2024 during conversion. We need to keep the type-specific data around, | |
2025 though, because of canonicalize_after_coding. */ | |
2026 if (str->convert_to) | |
2027 { | |
2028 Dynarr_free (str->convert_to); | |
2029 str->convert_to = 0; | |
2030 } | |
2031 if (str->convert_from) | |
428 | 2032 { |
771 | 2033 Dynarr_free (str->convert_from); |
2034 str->convert_from = 0; | |
2035 } | |
2036 | |
800 | 2037 if (str->no_close_other) |
2038 return Lstream_flush (str->other_end); | |
2039 else | |
2040 return Lstream_close (str->other_end); | |
771 | 2041 } |
2042 | |
2043 static void | |
2044 coding_finalizer (Lstream *stream) | |
2045 { | |
2046 struct coding_stream *str = CODING_STREAM_DATA (stream); | |
2047 | |
2048 assert (!str->finalized); | |
2049 MAYBE_XCODESYSMETH (str->codesys, finalize_coding_stream, (str)); | |
2050 if (str->data) | |
2051 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2052 xfree (str->data); |
771 | 2053 str->data = 0; |
2054 } | |
2055 str->finalized = 1; | |
2056 } | |
2057 | |
2058 static Lisp_Object | |
2059 coding_stream_canonicalize_after_coding (Lstream *stream) | |
2060 { | |
2061 struct coding_stream *str = CODING_STREAM_DATA (stream); | |
2062 | |
2063 return XCODESYSMETH_OR_GIVEN (str->codesys, canonicalize_after_coding, | |
2064 (str), str->codesys); | |
2065 } | |
2066 | |
2067 Lisp_Object | |
2068 coding_stream_detected_coding_system (Lstream *stream) | |
2069 { | |
2070 Lisp_Object codesys = | |
2071 coding_stream_canonicalize_after_coding (stream); | |
2072 if (NILP (codesys)) | |
2073 return Fget_coding_system (Qidentity); | |
2074 return codesys; | |
2075 } | |
2076 | |
2077 Lisp_Object | |
2078 coding_stream_coding_system (Lstream *stream) | |
2079 { | |
2080 return CODING_STREAM_DATA (stream)->codesys; | |
2081 } | |
2082 | |
2083 /* Change the coding system associated with a stream. */ | |
2084 | |
2085 void | |
2086 set_coding_stream_coding_system (Lstream *lstr, Lisp_Object codesys) | |
2087 { | |
2088 struct coding_stream *str = CODING_STREAM_DATA (lstr); | |
2089 if (EQ (str->orig_codesys, codesys)) | |
2090 return; | |
2091 /* We do the equivalent of closing the stream, destroying it, and | |
2092 reinitializing it. This includes flushing out the data and signalling | |
2093 EOF, if we're a writing stream; we also replace the type-specific data | |
2094 with the data appropriate for the new coding system. */ | |
2095 if (!NILP (str->codesys)) | |
2096 { | |
2097 if (lstr->flags & LSTREAM_FL_WRITE) | |
2098 { | |
2099 Lstream_flush (lstr); | |
2100 str->eof = 1; | |
2101 coding_writer (lstr, 0, 0); | |
2102 str->eof = 0; | |
2103 } | |
2104 MAYBE_XCODESYSMETH (str->codesys, finalize_coding_stream, (str)); | |
2105 } | |
2106 str->orig_codesys = codesys; | |
2107 str->codesys = coding_system_real_canonical (codesys); | |
2108 | |
2109 if (str->data) | |
2110 { | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2111 xfree (str->data); |
771 | 2112 str->data = 0; |
428 | 2113 } |
771 | 2114 if (XCODING_SYSTEM_METHODS (str->codesys)->coding_data_size) |
1204 | 2115 { |
2116 str->data = | |
2117 xmalloc_and_zero (XCODING_SYSTEM_METHODS (str->codesys)-> | |
2118 coding_data_size); | |
2119 str->type = XCODING_SYSTEM_METHODS (str->codesys)->enumtype; | |
2120 } | |
771 | 2121 MAYBE_XCODESYSMETH (str->codesys, init_coding_stream, (str)); |
2122 /* The new coding system may have different ideas regarding whether its | |
2123 ends are characters or bytes. */ | |
2124 set_coding_character_mode (lstr); | |
2125 } | |
2126 | |
2127 /* WARNING WARNING WARNING WARNING!!!!! If you open up a coding | |
2128 stream for writing, no automatic code detection will be performed. | |
2129 The reason for this is that automatic code detection requires a | |
2130 seekable input. Things will also fail if you open a coding | |
2131 stream for reading using a non-fully-specified coding system and | |
2132 a non-seekable input stream. */ | |
2133 | |
2134 static Lisp_Object | |
2135 make_coding_stream_1 (Lstream *stream, Lisp_Object codesys, | |
800 | 2136 const char *mode, enum encode_decode direction, |
802 | 2137 int flags) |
771 | 2138 { |
2139 Lstream *lstr = Lstream_new (lstream_coding, mode); | |
2140 struct coding_stream *str = CODING_STREAM_DATA (lstr); | |
2141 | |
2142 codesys = Fget_coding_system (codesys); | |
2143 xzero (*str); | |
2144 str->codesys = Qnil; | |
2145 str->orig_codesys = Qnil; | |
2146 str->us = lstr; | |
2147 str->other_end = stream; | |
2148 str->convert_to = Dynarr_new (unsigned_char); | |
2149 str->convert_from = Dynarr_new (unsigned_char); | |
2150 str->direction = direction; | |
814 | 2151 if (flags & LSTREAM_FL_NO_CLOSE_OTHER) |
802 | 2152 str->no_close_other = 1; |
814 | 2153 if (flags & LSTREAM_FL_READ_ONE_BYTE_AT_A_TIME) |
802 | 2154 str->one_byte_at_a_time = 1; |
814 | 2155 if (!(flags & LSTREAM_FL_NO_INIT_CHAR_MODE_WHEN_READING)) |
2156 str->set_char_mode_on_us_when_reading = 1; | |
802 | 2157 |
771 | 2158 set_coding_stream_coding_system (lstr, codesys); |
793 | 2159 return wrap_lstream (lstr); |
771 | 2160 } |
2161 | |
814 | 2162 /* FLAGS: |
2163 | |
2164 LSTREAM_FL_NO_CLOSE_OTHER | |
2165 Don't close STREAM (the stream at the other end) when this stream is | |
2166 closed. | |
2167 | |
2168 LSTREAM_FL_READ_ONE_BYTE_AT_A_TIME | |
2169 When reading from STREAM, read and process one byte at a time rather | |
2170 than in large chunks. This is for reading from TTY's, so we don't | |
2171 block. #### We should instead create a non-blocking filedesc stream | |
2172 that emulates the behavior as necessary using select(), when the | |
2173 fcntls don't work. (As seems to be the case on Cygwin.) | |
2174 | |
2175 LSTREAM_FL_NO_INIT_CHAR_MODE_WHEN_READING | |
2176 When reading from STREAM, read and process one byte at a time rather | |
2177 than in large chunks. This is for reading from TTY's, so we don't | |
2178 block. #### We should instead create a non-blocking filedesc stream | |
2179 that emulates the behavior as necessary using select(), when the | |
2180 fcntls don't work. (As seems to be the case on Cygwin.) | |
2181 */ | |
771 | 2182 Lisp_Object |
2183 make_coding_input_stream (Lstream *stream, Lisp_Object codesys, | |
802 | 2184 enum encode_decode direction, int flags) |
771 | 2185 { |
800 | 2186 return make_coding_stream_1 (stream, codesys, "r", direction, |
802 | 2187 flags); |
771 | 2188 } |
2189 | |
814 | 2190 /* FLAGS: |
2191 | |
2192 LSTREAM_FL_NO_CLOSE_OTHER | |
2193 Don't close STREAM (the stream at the other end) when this stream is | |
2194 closed. | |
2195 */ | |
771 | 2196 Lisp_Object |
2197 make_coding_output_stream (Lstream *stream, Lisp_Object codesys, | |
802 | 2198 enum encode_decode direction, int flags) |
771 | 2199 { |
800 | 2200 return make_coding_stream_1 (stream, codesys, "w", direction, |
802 | 2201 flags); |
771 | 2202 } |
2203 | |
2204 static Lisp_Object | |
2205 encode_decode_coding_region (Lisp_Object start, Lisp_Object end, | |
2206 Lisp_Object coding_system, Lisp_Object buffer, | |
2207 enum encode_decode direction) | |
2208 { | |
2209 Charbpos b, e; | |
2210 struct buffer *buf = decode_buffer (buffer, 0); | |
2211 Lisp_Object instream = Qnil, to_outstream = Qnil, outstream = Qnil; | |
2212 Lisp_Object from_outstream = Qnil, auto_outstream = Qnil; | |
2213 Lisp_Object lb_outstream = Qnil; | |
2214 Lisp_Object next; | |
2215 Lstream *istr, *ostr; | |
2216 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5; | |
2217 struct gcpro ngcpro1; | |
2218 int source_char, sink_char; | |
2219 | |
2220 get_buffer_range_char (buf, start, end, &b, &e, 0); | |
2221 barf_if_buffer_read_only (buf, b, e); | |
2222 | |
2223 GCPRO5 (instream, to_outstream, outstream, from_outstream, lb_outstream); | |
2224 NGCPRO1 (auto_outstream); | |
2225 | |
2226 coding_system = Fget_coding_system (coding_system); | |
2227 source_char = encode_decode_source_sink_type_is_char (coding_system, | |
2228 CODING_SOURCE, | |
2229 direction); | |
2230 sink_char = encode_decode_source_sink_type_is_char (coding_system, | |
2231 CODING_SINK, | |
2232 direction); | |
2233 | |
2234 /* Order is IN <---> [TO] -> OUT -> [FROM] -> [AUTODETECT-EOL] -> LB */ | |
2235 instream = make_lisp_buffer_input_stream (buf, b, e, 0); | |
2236 next = lb_outstream = make_lisp_buffer_output_stream (buf, b, 0); | |
2237 | |
2238 if (direction == CODING_DECODE && | |
2239 XCODING_SYSTEM_EOL_TYPE (coding_system) == EOL_AUTODETECT) | |
2240 next = auto_outstream = | |
2241 make_coding_output_stream | |
800 | 2242 (XLSTREAM (next), Fget_coding_system (Qconvert_eol_autodetect), |
2243 CODING_DECODE, 0); | |
771 | 2244 |
2245 if (!sink_char) | |
2246 next = from_outstream = | |
800 | 2247 make_coding_output_stream (XLSTREAM (next), Qbinary, CODING_DECODE, 0); |
771 | 2248 outstream = make_coding_output_stream (XLSTREAM (next), coding_system, |
800 | 2249 direction, 0); |
771 | 2250 if (!source_char) |
428 | 2251 { |
771 | 2252 to_outstream = |
2253 make_coding_output_stream (XLSTREAM (outstream), | |
800 | 2254 Qbinary, CODING_ENCODE, 0); |
771 | 2255 ostr = XLSTREAM (to_outstream); |
2256 } | |
2257 else | |
2258 ostr = XLSTREAM (outstream); | |
2259 istr = XLSTREAM (instream); | |
2260 | |
2261 /* The chain of streams looks like this: | |
2262 | |
2297 | 2263 [BUFFER] <----- (( read from/send to loop )) |
771 | 2264 ------> [CHAR->BYTE i.e. ENCODE AS BINARY if source is |
2265 in bytes] | |
2266 ------> [ENCODE/DECODE AS SPECIFIED] | |
2267 ------> [BYTE->CHAR i.e. DECODE AS BINARY | |
2268 if sink is in bytes] | |
2269 ------> [AUTODETECT EOL if | |
2270 we're decoding and | |
2271 coding system calls | |
2272 for this] | |
2273 ------> [BUFFER] | |
2274 */ | |
2367 | 2275 |
2276 /* #### See comment | |
2277 | |
2278 EFFICIENCY OF CODING CONVERSION WITH MULTIPLE COPIES/CHAINS | |
2279 | |
2280 in text.c. | |
2281 */ | |
2282 | |
771 | 2283 while (1) |
2284 { | |
2285 char tempbuf[1024]; /* some random amount */ | |
2286 Charbpos newpos, even_newer_pos; | |
2287 Charbpos oldpos = lisp_buffer_stream_startpos (istr); | |
2288 Bytecount size_in_bytes = | |
2289 Lstream_read (istr, tempbuf, sizeof (tempbuf)); | |
2290 | |
2291 if (!size_in_bytes) | |
2292 break; | |
2293 newpos = lisp_buffer_stream_startpos (istr); | |
2294 Lstream_write (ostr, tempbuf, size_in_bytes); | |
2295 even_newer_pos = lisp_buffer_stream_startpos (istr); | |
2296 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos), | |
2297 even_newer_pos, 0); | |
428 | 2298 } |
771 | 2299 |
2300 { | |
2301 Charcount retlen = | |
2302 lisp_buffer_stream_startpos (XLSTREAM (instream)) - b; | |
2303 Lstream_close (istr); | |
2304 Lstream_close (ostr); | |
2305 NUNGCPRO; | |
2306 UNGCPRO; | |
2307 Lstream_delete (istr); | |
2308 if (!NILP (from_outstream)) | |
2309 Lstream_delete (XLSTREAM (from_outstream)); | |
2310 Lstream_delete (XLSTREAM (outstream)); | |
2311 if (!NILP (to_outstream)) | |
2312 Lstream_delete (XLSTREAM (to_outstream)); | |
2313 if (!NILP (auto_outstream)) | |
2314 Lstream_delete (XLSTREAM (auto_outstream)); | |
2315 Lstream_delete (XLSTREAM (lb_outstream)); | |
2316 return make_int (retlen); | |
2317 } | |
2318 } | |
2319 | |
3302 | 2320 DEFUN ("decode-coding-region", Fdecode_coding_region, 3, 4, |
2321 "*r\nzDecode from coding system: \ni", /* | |
771 | 2322 Decode the text between START and END which is encoded in CODING-SYSTEM. |
2323 This is useful if you've read in encoded text from a file without decoding | |
2324 it (e.g. you read in a JIS-formatted file but used the `binary' or | |
2325 `no-conversion' coding system, so that it shows up as "^[$B!<!+^[(B"). | |
2326 Return length of decoded text. | |
3302 | 2327 BUFFER defaults to the current buffer if unspecified, and when interactive. |
771 | 2328 */ |
2329 (start, end, coding_system, buffer)) | |
2330 { | |
2331 return encode_decode_coding_region (start, end, coding_system, buffer, | |
2332 CODING_DECODE); | |
2333 } | |
2334 | |
3302 | 2335 DEFUN ("encode-coding-region", Fencode_coding_region, 3, 4, |
2336 "*r\nzEncode to coding system: \ni", /* | |
771 | 2337 Encode the text between START and END using CODING-SYSTEM. |
2338 This will, for example, convert Japanese characters into stuff such as | |
3302 | 2339 "^[$B!<!+^[(B" if you use the JIS encoding. Return length of encoded text. |
2340 BUFFER defaults to the current buffer if unspecified, and when interactive. | |
771 | 2341 */ |
2342 (start, end, coding_system, buffer)) | |
2343 { | |
2344 return encode_decode_coding_region (start, end, coding_system, buffer, | |
2345 CODING_ENCODE); | |
428 | 2346 } |
2347 | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2348 DEFUN ("query-coding-region", Fquery_coding_region, 3, 7, 0, /* |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2349 Work out whether CODING-SYSTEM can losslessly encode a region. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2350 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2351 START and END are the beginning and end of the region to check. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2352 CODING-SYSTEM is the coding system to try. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2353 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2354 Optional argument BUFFER is the buffer to check, and defaults to the current |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2355 buffer. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2356 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2357 IGNORE-INVALID-SEQUENCESP, also an optional argument, says to treat XEmacs |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2358 characters which have an unambiguous encoded representation, despite being |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2359 undefined in what they represent, as encodable. These chiefly arise with |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2360 variable-length encodings like UTF-8 and UTF-16, where an invalid sequence |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2361 is passed through to XEmacs as a sequence of characters with a defined |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2362 correspondence to the octets on disk, but no non-error semantics; see the |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2363 `invalid-sequence-coding-system' argument to `set-language-info'. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2364 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2365 They can also arise with fixed-length encodings like ISO 8859-7, where |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2366 certain octets on disk have undefined values, and treating them as |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2367 corresponding to the ISO 8859-1 characters with the same numerical values |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2368 may lead to data that is not understood by other applications. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2369 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2370 Optional argument ERRORP says to signal a `text-conversion-error' if some |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2371 character in the region cannot be encoded, and defaults to nil. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2372 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2373 Optional argument HIGHLIGHT says to display unencodable characters in the |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2374 region using `query-coding-warning-face'. It defaults to nil. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2375 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2376 This function can return multiple values; the intention is that callers use |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2377 `multiple-value-bind' or the related CL multiple value functions to deal |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2378 with it. The first result is `t' if the region can be encoded using |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2379 CODING-SYSTEM, or `nil' if not. If the region cannot be encoded using |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2380 CODING-SYSTEM, the second result is a range table describing the positions |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2381 of the unencodable characters. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2382 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2383 Ranges that describe characters that would be ignored were |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2384 IGNORE-INVALID-SEQUENCESP non-nil map to the symbol `invalid-sequence'; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2385 other ranges map to the symbol `unencodable'. If IGNORE-INVALID-SEQUENCESP |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2386 is non-nil, all ranges will map to the symbol `unencodable'. See |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2387 `make-range-table' for more details of range tables. |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2388 */ |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2389 (start, end, coding_system, buffer, ignore_invalid_sequencesp, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2390 errorp, highlight)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2391 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2392 Charbpos b, e; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2393 struct buffer *buf = decode_buffer (buffer, 1); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2394 Lisp_Object result; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2395 int flags = 0, speccount = specpdl_depth (); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2396 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2397 coding_system = Fget_coding_system (coding_system); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2398 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2399 get_buffer_range_char (buf, start, end, &b, &e, 0); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2400 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2401 if (buf != current_buffer) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2402 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2403 record_unwind_protect (save_current_buffer_restore, Fcurrent_buffer ()); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2404 set_buffer_internal (buf); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2405 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2406 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2407 record_unwind_protect (save_excursion_restore, save_excursion_save ()); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2408 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2409 BUF_SET_PT (buf, b); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2410 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2411 if (!NILP (ignore_invalid_sequencesp)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2412 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2413 flags |= QUERY_METHOD_IGNORE_INVALID_SEQUENCES; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2414 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2415 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2416 if (!NILP (errorp)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2417 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2418 flags |= QUERY_METHOD_ERRORP; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2419 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2420 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2421 if (!NILP (highlight)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2422 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2423 flags |= QUERY_METHOD_HIGHLIGHT; |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2424 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2425 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2426 result = XCODESYSMETH_OR_GIVEN (coding_system, query, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2427 (coding_system, buf, e, flags), Qunbound); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2428 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2429 if (UNBOUNDP (result)) |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2430 { |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2431 signal_error (Qtext_conversion_error, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2432 "Coding system doesn't say what it can encode", |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2433 XCODING_SYSTEM_NAME (coding_system)); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2434 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2435 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2436 result = (NILP (result)) ? Qt : values2 (Qnil, result); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2437 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2438 return unbind_to_1 (speccount, result); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2439 } |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2440 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
2441 |
428 | 2442 |
2443 /************************************************************************/ | |
771 | 2444 /* Chain methods */ |
428 | 2445 /************************************************************************/ |
2446 | |
771 | 2447 /* #### Need a way to create "opposite-direction" coding systems. */ |
2448 | |
2449 /* Chain two or more coding systems together to make a combination coding | |
2450 system. */ | |
2451 | |
2452 struct chain_coding_system | |
2453 { | |
2454 /* List of coding systems, in decode order */ | |
2455 Lisp_Object *chain; | |
2456 /* Number of coding systems in list */ | |
2457 int count; | |
2458 /* Coding system to return as a result of canonicalize-after-coding */ | |
2459 Lisp_Object canonicalize_after_coding; | |
2460 }; | |
2461 | |
2462 struct chain_coding_stream | |
2463 { | |
2464 int initted; | |
2465 /* Lstreams for chain coding system */ | |
2466 Lisp_Object *lstreams; | |
2467 int lstream_count; | |
2468 }; | |
2469 | |
1204 | 2470 static const struct memory_description chain_coding_system_description[] = { |
2471 { XD_INT, offsetof (struct chain_coding_system, count) }, | |
2367 | 2472 { XD_BLOCK_PTR, offsetof (struct chain_coding_system, chain), |
2551 | 2473 XD_INDIRECT (0, 0), { &lisp_object_description } }, |
1204 | 2474 { XD_LISP_OBJECT, offsetof (struct chain_coding_system, |
2475 canonicalize_after_coding) }, | |
771 | 2476 { XD_END } |
2477 }; | |
2478 | |
1204 | 2479 static const struct memory_description chain_coding_stream_description_1 [] = { |
2480 { XD_INT, offsetof (struct chain_coding_stream, lstream_count) }, | |
2367 | 2481 { XD_BLOCK_PTR, offsetof (struct chain_coding_stream, lstreams), |
2551 | 2482 XD_INDIRECT (0, 0), { &lisp_object_description } }, |
771 | 2483 { XD_END } |
2484 }; | |
2485 | |
1204 | 2486 const struct sized_memory_description chain_coding_stream_description = { |
2487 sizeof (struct chain_coding_stream), chain_coding_stream_description_1 | |
2488 }; | |
2489 | |
2490 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (chain); | |
2491 | |
771 | 2492 static Lisp_Object |
2493 chain_canonicalize (Lisp_Object codesys) | |
2494 { | |
2495 /* We make use of the fact that this method is called at init time, after | |
2496 properties have been parsed. init_method is called too early. */ | |
2497 /* #### It's not clear we need this whole chain-canonicalize mechanism | |
2498 any more. */ | |
2499 Lisp_Object chain = Flist (XCODING_SYSTEM_CHAIN_COUNT (codesys), | |
2500 XCODING_SYSTEM_CHAIN_CHAIN (codesys)); | |
2501 chain = Fcons (XCODING_SYSTEM_PRE_WRITE_CONVERSION (codesys), | |
2502 Fcons (XCODING_SYSTEM_POST_READ_CONVERSION (codesys), | |
2503 chain)); | |
2504 Fputhash (chain, codesys, Vchain_canonicalize_hash_table); | |
2505 return codesys; | |
2506 } | |
2507 | |
2508 static Lisp_Object | |
2509 chain_canonicalize_after_coding (struct coding_stream *str) | |
2510 { | |
2511 Lisp_Object cac = | |
2512 XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (str->codesys); | |
2513 if (!NILP (cac)) | |
2514 return cac; | |
2515 return str->codesys; | |
2516 #if 0 | |
2517 struct chain_coding_stream *data = CODING_STREAM_TYPE_DATA (str, chain); | |
2518 Lisp_Object us = str->codesys, codesys; | |
2519 int i; | |
2520 Lisp_Object chain; | |
2521 Lisp_Object tail; | |
2522 int changed = 0; | |
2523 | |
2524 /* #### It's not clear we need this whole chain-canonicalize mechanism | |
2525 any more. */ | |
2526 if (str->direction == CODING_ENCODE || !data->initted) | |
2527 return us; | |
2528 | |
2529 chain = Flist (XCODING_SYSTEM_CHAIN_COUNT (us), | |
2530 XCODING_SYSTEM_CHAIN_CHAIN (us)); | |
2531 | |
2532 tail = chain; | |
2533 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (us); i++) | |
2534 { | |
2535 codesys = (coding_stream_canonicalize_after_coding | |
2536 (XLSTREAM (data->lstreams[i]))); | |
2537 if (!EQ (codesys, XCAR (tail))) | |
2538 changed = 1; | |
2539 XCAR (tail) = codesys; | |
2540 tail = XCDR (tail); | |
2541 } | |
2542 | |
2543 if (!changed) | |
2544 return us; | |
2545 | |
2546 chain = delq_no_quit (Qnil, chain); | |
2547 | |
2548 if (NILP (XCODING_SYSTEM_PRE_WRITE_CONVERSION (us)) && | |
2549 NILP (XCODING_SYSTEM_POST_READ_CONVERSION (us))) | |
2550 { | |
2551 if (NILP (chain)) | |
2552 return Qnil; | |
2553 if (NILP (XCDR (chain))) | |
2554 return XCAR (chain); | |
2555 } | |
2556 | |
2557 codesys = Fgethash (Fcons (XCODING_SYSTEM_PRE_WRITE_CONVERSION (us), | |
2558 Fcons (XCODING_SYSTEM_POST_READ_CONVERSION (us), | |
2559 chain)), Vchain_canonicalize_hash_table, | |
2560 Qnil); | |
2561 if (!NILP (codesys)) | |
2562 return codesys; | |
2563 return make_internal_coding_system | |
2564 (us, "internal-chain-canonicalizer-wrapper", | |
2565 Qchain, Qunbound, list2 (Qchain, chain)); | |
2566 #endif /* 0 */ | |
2567 } | |
2568 | |
2569 static void | |
2570 chain_init (Lisp_Object codesys) | |
2571 { | |
2572 XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (codesys) = Qnil; | |
2573 } | |
2574 | |
2575 static void | |
2576 chain_mark (Lisp_Object codesys) | |
2577 { | |
2578 int i; | |
2579 | |
2580 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (codesys); i++) | |
2581 mark_object (XCODING_SYSTEM_CHAIN_CHAIN (codesys)[i]); | |
2582 mark_object (XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (codesys)); | |
2583 } | |
2584 | |
2585 static void | |
2586 chain_mark_coding_stream_1 (struct chain_coding_stream *data) | |
2587 { | |
2588 int i; | |
2589 | |
2590 for (i = 0; i < data->lstream_count; i++) | |
2591 mark_object (data->lstreams[i]); | |
2592 } | |
2593 | |
2594 static void | |
2595 chain_mark_coding_stream (struct coding_stream *str) | |
2596 { | |
2597 chain_mark_coding_stream_1 (CODING_STREAM_TYPE_DATA (str, chain)); | |
2598 } | |
2599 | |
2600 static void | |
2601 chain_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag) | |
2602 { | |
2603 int i; | |
2604 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2605 write_ascstring (printcharfun, "("); |
771 | 2606 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (cs); i++) |
2607 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2608 write_ascstring (printcharfun, i == 0 ? "" : "->"); |
771 | 2609 print_coding_system_in_print_method (XCODING_SYSTEM_CHAIN_CHAIN (cs)[i], |
2610 printcharfun, escapeflag); | |
2611 } | |
2612 { | |
2613 Lisp_Object cac = XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (cs); | |
2614 if (!NILP (cac)) | |
2615 { | |
2616 if (i > 0) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2617 write_ascstring (printcharfun, " "); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2618 write_ascstring (printcharfun, "canonicalize-after-coding="); |
771 | 2619 print_coding_system_in_print_method (cac, printcharfun, escapeflag); |
2620 } | |
2621 } | |
2622 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
2623 write_ascstring (printcharfun, ")"); |
771 | 2624 } |
2625 | |
2626 static void | |
2627 chain_rewind_coding_stream_1 (struct chain_coding_stream *data) | |
2628 { | |
2629 /* Each will rewind the next; there is always at least one stream (the | |
2630 dynarr stream at the end) if we're initted */ | |
2631 if (data->initted) | |
2632 Lstream_rewind (XLSTREAM (data->lstreams[0])); | |
2633 } | |
2634 | |
2635 static void | |
2636 chain_rewind_coding_stream (struct coding_stream *str) | |
2637 { | |
2638 chain_rewind_coding_stream_1 (CODING_STREAM_TYPE_DATA (str, chain)); | |
2639 } | |
2640 | |
2641 static void | |
2642 chain_init_coding_streams_1 (struct chain_coding_stream *data, | |
2643 unsigned_char_dynarr *dst, | |
2644 int ncodesys, Lisp_Object *codesys, | |
2645 enum encode_decode direction) | |
2646 { | |
2647 int i; | |
2648 Lisp_Object lstream_out; | |
2649 | |
2650 data->lstream_count = ncodesys + 1; | |
2651 data->lstreams = xnew_array (Lisp_Object, data->lstream_count); | |
2652 | |
2653 lstream_out = make_dynarr_output_stream (dst); | |
2654 Lstream_set_buffering (XLSTREAM (lstream_out), LSTREAM_UNBUFFERED, 0); | |
2655 data->lstreams[data->lstream_count - 1] = lstream_out; | |
2656 | |
2657 for (i = ncodesys - 1; i >= 0; i--) | |
2658 { | |
2659 data->lstreams[i] = | |
2660 make_coding_output_stream | |
2661 (XLSTREAM (lstream_out), | |
2662 codesys[direction == CODING_ENCODE ? ncodesys - (i + 1) : i], | |
800 | 2663 direction, 0); |
771 | 2664 lstream_out = data->lstreams[i]; |
2665 Lstream_set_buffering (XLSTREAM (lstream_out), LSTREAM_UNBUFFERED, | |
2666 0); | |
2667 } | |
2668 data->initted = 1; | |
2669 } | |
2670 | |
2671 static Bytecount | |
2672 chain_convert (struct coding_stream *str, const UExtbyte *src, | |
2673 unsigned_char_dynarr *dst, Bytecount n) | |
2674 { | |
2675 struct chain_coding_stream *data = CODING_STREAM_TYPE_DATA (str, chain); | |
2676 | |
2677 if (str->eof) | |
2678 { | |
2679 /* Each will close the next; there is always at least one stream (the | |
2680 dynarr stream at the end) if we're initted. We need to close now | |
2681 because more data may be generated. */ | |
2682 if (data->initted) | |
2683 Lstream_close (XLSTREAM (data->lstreams[0])); | |
2684 return n; | |
2685 } | |
2686 | |
2687 if (!data->initted) | |
2688 chain_init_coding_streams_1 | |
2689 (data, dst, XCODING_SYSTEM_CHAIN_COUNT (str->codesys), | |
2690 XCODING_SYSTEM_CHAIN_CHAIN (str->codesys), str->direction); | |
2691 | |
2692 if (Lstream_write (XLSTREAM (data->lstreams[0]), src, n) < 0) | |
2693 return -1; | |
2694 return n; | |
2695 } | |
2696 | |
2697 static void | |
2698 chain_finalize_coding_stream_1 (struct chain_coding_stream *data) | |
2699 { | |
2700 if (data->lstreams) | |
2701 { | |
2297 | 2702 /* During GC, these objects are unmarked, and are about to be freed. |
2703 We do NOT want them on the free list, and that will cause lots of | |
2704 nastiness including crashes. Just let them be freed normally. */ | |
771 | 2705 if (!gc_in_progress) |
2706 { | |
2707 int i; | |
2297 | 2708 /* Order of deletion is important here! Delete from the head of |
2709 the chain and work your way towards the tail. In general, | |
2710 when you delete an object, there should be *NO* pointers to it | |
2711 anywhere. Deleting back-to-front would be a problem because | |
2712 there are pointers going forward. If there were pointers in | |
2713 both directions, you'd have to disconnect the pointers to a | |
2714 particular object before deleting it. */ | |
771 | 2715 for (i = 0; i < data->lstream_count; i++) |
2716 Lstream_delete (XLSTREAM ((data->lstreams)[i])); | |
2717 } | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2718 xfree (data->lstreams); |
771 | 2719 } |
2720 } | |
2721 | |
2722 static void | |
2723 chain_finalize_coding_stream (struct coding_stream *str) | |
2724 { | |
2725 chain_finalize_coding_stream_1 (CODING_STREAM_TYPE_DATA (str, chain)); | |
2726 } | |
2727 | |
2728 static void | |
2729 chain_finalize (Lisp_Object c) | |
2730 { | |
2731 if (XCODING_SYSTEM_CHAIN_CHAIN (c)) | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
2732 xfree (XCODING_SYSTEM_CHAIN_CHAIN (c)); |
771 | 2733 } |
2734 | |
428 | 2735 static int |
771 | 2736 chain_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value) |
2737 { | |
2738 if (EQ (key, Qchain)) | |
2739 { | |
2740 Lisp_Object *cslist; | |
2741 int count = 0; | |
2742 int i; | |
2743 | |
2367 | 2744 { |
2745 EXTERNAL_LIST_LOOP_2 (elt, value) | |
2746 { | |
2747 Fget_coding_system (elt); | |
2748 count++; | |
2749 } | |
2750 } | |
771 | 2751 |
2752 cslist = xnew_array (Lisp_Object, count); | |
2753 XCODING_SYSTEM_CHAIN_CHAIN (codesys) = cslist; | |
2754 | |
2755 count = 0; | |
2367 | 2756 { |
2757 EXTERNAL_LIST_LOOP_2 (elt, value) | |
2758 { | |
2759 cslist[count] = Fget_coding_system (elt); | |
2760 count++; | |
2761 } | |
2762 } | |
771 | 2763 |
2764 XCODING_SYSTEM_CHAIN_COUNT (codesys) = count; | |
2765 | |
2766 for (i = 0; i < count - 1; i++) | |
2767 { | |
2768 if (decoding_source_sink_type_is_char (cslist[i], CODING_SINK) != | |
2769 decoding_source_sink_type_is_char (cslist[i + 1], CODING_SOURCE)) | |
2770 invalid_argument_2 ("Sink of first must match source of second", | |
2771 cslist[i], cslist[i + 1]); | |
2772 } | |
2773 } | |
2774 else if (EQ (key, Qcanonicalize_after_coding)) | |
2775 XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (codesys) = | |
2776 Fget_coding_system (value); | |
2777 else | |
2778 return 0; | |
2779 return 1; | |
2780 } | |
2781 | |
2782 static Lisp_Object | |
2783 chain_getprop (Lisp_Object coding_system, Lisp_Object prop) | |
2784 { | |
2785 if (EQ (prop, Qchain)) | |
2786 { | |
2787 Lisp_Object result = Qnil; | |
2788 int i; | |
2789 | |
2790 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (coding_system); i++) | |
2791 result = Fcons (XCODING_SYSTEM_CHAIN_CHAIN (coding_system)[i], | |
2792 result); | |
2793 | |
2794 return Fnreverse (result); | |
2795 } | |
2796 else if (EQ (prop, Qcanonicalize_after_coding)) | |
2797 return XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (coding_system); | |
2798 else | |
2799 return Qunbound; | |
2800 } | |
2801 | |
2802 static enum source_sink_type | |
2803 chain_conversion_end_type (Lisp_Object codesys) | |
2804 { | |
2805 Lisp_Object *cslist = XCODING_SYSTEM_CHAIN_CHAIN (codesys); | |
2806 int n = XCODING_SYSTEM_CHAIN_COUNT (codesys); | |
2807 int charp_source, charp_sink; | |
2808 | |
2809 if (n == 0) | |
2810 return DECODES_BYTE_TO_BYTE; /* arbitrary */ | |
2811 charp_source = decoding_source_sink_type_is_char (cslist[0], CODING_SOURCE); | |
2812 charp_sink = decoding_source_sink_type_is_char (cslist[n - 1], CODING_SINK); | |
2813 | |
2814 switch (charp_source * 2 + charp_sink) | |
2815 { | |
2816 case 0: return DECODES_BYTE_TO_BYTE; | |
2817 case 1: return DECODES_BYTE_TO_CHARACTER; | |
2818 case 2: return DECODES_CHARACTER_TO_BYTE; | |
2819 case 3: return DECODES_CHARACTER_TO_CHARACTER; | |
2820 } | |
2821 | |
2500 | 2822 ABORT (); |
771 | 2823 return DECODES_BYTE_TO_BYTE; |
2824 } | |
2825 | |
2826 | |
2827 /************************************************************************/ | |
2828 /* No-conversion methods */ | |
2829 /************************************************************************/ | |
2830 | |
2831 /* "No conversion"; used for binary files. We use quotes because there | |
2832 really is some conversion being applied (it does byte<->char | |
2833 conversion), but it appears to the user as if the text is read in | |
2297 | 2834 without conversion. |
2835 | |
2836 #### Shouldn't we _call_ it that, then? And while we're at it, | |
2837 separate it into "to_internal" and "to_external"? */ | |
771 | 2838 DEFINE_CODING_SYSTEM_TYPE (no_conversion); |
2839 | |
2840 /* This is used when reading in "binary" files -- i.e. files that may | |
2841 contain all 256 possible byte values and that are not to be | |
2842 interpreted as being in any particular encoding. */ | |
2843 static Bytecount | |
2844 no_conversion_convert (struct coding_stream *str, | |
2845 const UExtbyte *src, | |
2846 unsigned_char_dynarr *dst, Bytecount n) | |
2847 { | |
2848 UExtbyte c; | |
2849 unsigned int ch = str->ch; | |
2850 Bytecount orign = n; | |
2851 | |
2852 if (str->direction == CODING_DECODE) | |
2853 { | |
2854 while (n--) | |
2855 { | |
2856 c = *src++; | |
2857 | |
2858 DECODE_ADD_BINARY_CHAR (c, dst); | |
2859 } | |
2860 | |
2861 if (str->eof) | |
2862 DECODE_OUTPUT_PARTIAL_CHAR (ch, dst); | |
2863 } | |
2864 else | |
2865 { | |
2866 | |
2867 while (n--) | |
2868 { | |
2869 c = *src++; | |
826 | 2870 if (byte_ascii_p (c)) |
771 | 2871 { |
2872 assert (ch == 0); | |
2873 Dynarr_add (dst, c); | |
2874 } | |
2875 #ifdef MULE | |
867 | 2876 else if (ibyte_leading_byte_p (c)) |
771 | 2877 { |
2878 assert (ch == 0); | |
2879 if (c == LEADING_BYTE_LATIN_ISO8859_1 || | |
2880 c == LEADING_BYTE_CONTROL_1) | |
2881 ch = c; | |
2882 else | |
2297 | 2883 /* #### This is just plain unacceptable. */ |
771 | 2884 Dynarr_add (dst, '~'); /* untranslatable character */ |
2885 } | |
2886 else | |
2887 { | |
2888 if (ch == LEADING_BYTE_LATIN_ISO8859_1) | |
2889 Dynarr_add (dst, c); | |
2890 else if (ch == LEADING_BYTE_CONTROL_1) | |
2891 { | |
2892 assert (c < 0xC0); | |
2893 Dynarr_add (dst, c - 0x20); | |
2894 } | |
2895 /* else it should be the second or third byte of an | |
2896 untranslatable character, so ignore it */ | |
2897 ch = 0; | |
2898 } | |
2899 #endif /* MULE */ | |
2900 | |
2901 } | |
2902 } | |
2903 | |
2904 str->ch = ch; | |
2905 return orign; | |
2906 } | |
2907 | |
2908 DEFINE_DETECTOR (no_conversion); | |
2909 DEFINE_DETECTOR_CATEGORY (no_conversion, no_conversion); | |
2910 | |
2911 struct no_conversion_detector | |
2912 { | |
2913 int dummy; | |
2914 }; | |
2915 | |
2916 static void | |
2286 | 2917 no_conversion_detect (struct detection_state *st, const UExtbyte *UNUSED (src), |
2918 Bytecount UNUSED (n)) | |
771 | 2919 { |
2920 /* Hack until we get better handling of this stuff! */ | |
2921 DET_RESULT (st, no_conversion) = DET_SLIGHTLY_LIKELY; | |
2922 } | |
2923 | |
2924 | |
2925 /************************************************************************/ | |
2926 /* Convert-eol methods */ | |
2927 /************************************************************************/ | |
2928 | |
2929 /* This is used to handle end-of-line (EOL) differences. It is | |
2819 | 2930 character-to-character, and works (when encoding) *BEFORE* sending data to |
2931 the main encoding routine -- thus, that routine must handle different EOL | |
2932 types itself if it does line-oriented type processing. This is unavoidable | |
2933 because we don't know whether the output of the main encoding routine is | |
2934 ASCII compatible (UTF-16 is definitely not, for example). [[ sjt sez this | |
2935 is bogus. There should be _no_ EOL processing (or processing of any kind) | |
2936 after conversion to external. ]] | |
771 | 2937 |
793 | 2938 There is one parameter: `subtype', either `cr', `lf', `crlf', or nil. |
771 | 2939 */ |
2940 | |
2941 struct convert_eol_coding_system | |
2942 { | |
2943 enum eol_type subtype; | |
2132 | 2944 int dummy; /* On some architectures (eg ia64) the portable dumper can |
2945 produce unaligned access errors without this field. Probably | |
2946 because the combined structure of this structure and | |
2947 Lisp_Coding_System is not properly aligned. */ | |
771 | 2948 }; |
2949 | |
2950 #define CODING_SYSTEM_CONVERT_EOL_SUBTYPE(codesys) \ | |
2951 (CODING_SYSTEM_TYPE_DATA (codesys, convert_eol)->subtype) | |
2952 #define XCODING_SYSTEM_CONVERT_EOL_SUBTYPE(codesys) \ | |
2953 (XCODING_SYSTEM_TYPE_DATA (codesys, convert_eol)->subtype) | |
2954 | |
2955 struct convert_eol_coding_stream | |
2956 { | |
2957 enum eol_type actual; | |
2958 }; | |
2959 | |
1204 | 2960 static const struct memory_description |
771 | 2961 convert_eol_coding_system_description[] = { |
2962 { XD_END } | |
2963 }; | |
2964 | |
1204 | 2965 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (convert_eol); |
2966 | |
771 | 2967 static void |
2286 | 2968 convert_eol_print (Lisp_Object cs, Lisp_Object printcharfun, |
2969 int UNUSED (escapeflag)) | |
771 | 2970 { |
2971 struct convert_eol_coding_system *data = | |
2972 XCODING_SYSTEM_TYPE_DATA (cs, convert_eol); | |
2973 | |
2974 write_fmt_string (printcharfun, "(%s)", | |
2975 data->subtype == EOL_LF ? "lf" : | |
2976 data->subtype == EOL_CRLF ? "crlf" : | |
2977 data->subtype == EOL_CR ? "cr" : | |
793 | 2978 data->subtype == EOL_AUTODETECT ? "nil" : |
2500 | 2979 (ABORT(), "")); |
771 | 2980 } |
2981 | |
2982 static enum source_sink_type | |
2286 | 2983 convert_eol_conversion_end_type (Lisp_Object UNUSED (codesys)) |
771 | 2984 { |
2985 return DECODES_CHARACTER_TO_CHARACTER; | |
2986 } | |
2987 | |
2988 static int | |
2989 convert_eol_putprop (Lisp_Object codesys, | |
2990 Lisp_Object key, | |
2991 Lisp_Object value) | |
2992 { | |
2993 struct convert_eol_coding_system *data = | |
2994 XCODING_SYSTEM_TYPE_DATA (codesys, convert_eol); | |
2995 | |
2996 if (EQ (key, Qsubtype)) | |
2997 { | |
2998 if (EQ (value, Qlf) /* || EQ (value, Qunix) */) | |
2999 data->subtype = EOL_LF; | |
3000 else if (EQ (value, Qcrlf) /* || EQ (value, Qdos) */) | |
3001 data->subtype = EOL_CRLF; | |
3002 else if (EQ (value, Qcr) /* || EQ (value, Qmac) */) | |
3003 data->subtype = EOL_CR; | |
793 | 3004 else if (EQ (value, Qnil)) |
771 | 3005 data->subtype = EOL_AUTODETECT; |
3006 else invalid_constant ("Unrecognized eol type", value); | |
3007 } | |
3008 else | |
3009 return 0; | |
3010 return 1; | |
3011 } | |
3012 | |
3013 static Lisp_Object | |
3014 convert_eol_getprop (Lisp_Object coding_system, Lisp_Object prop) | |
3015 { | |
3016 struct convert_eol_coding_system *data = | |
3017 XCODING_SYSTEM_TYPE_DATA (coding_system, convert_eol); | |
3018 | |
3019 if (EQ (prop, Qsubtype)) | |
3020 { | |
3021 switch (data->subtype) | |
3022 { | |
3023 case EOL_LF: return Qlf; | |
3024 case EOL_CRLF: return Qcrlf; | |
3025 case EOL_CR: return Qcr; | |
793 | 3026 case EOL_AUTODETECT: return Qnil; |
2500 | 3027 default: ABORT (); |
771 | 3028 } |
3029 } | |
3030 | |
3031 return Qunbound; | |
3032 } | |
3033 | |
3034 static void | |
3035 convert_eol_init_coding_stream (struct coding_stream *str) | |
3036 { | |
3037 struct convert_eol_coding_stream *data = | |
3038 CODING_STREAM_TYPE_DATA (str, convert_eol); | |
3039 data->actual = XCODING_SYSTEM_CONVERT_EOL_SUBTYPE (str->codesys); | |
3040 } | |
3041 | |
3042 static Bytecount | |
867 | 3043 convert_eol_convert (struct coding_stream *str, const Ibyte *src, |
771 | 3044 unsigned_char_dynarr *dst, Bytecount n) |
3045 { | |
3046 if (str->direction == CODING_DECODE) | |
3047 { | |
3048 struct convert_eol_coding_stream *data = | |
3049 CODING_STREAM_TYPE_DATA (str, convert_eol); | |
3050 | |
3051 if (data->actual == EOL_AUTODETECT) | |
3052 { | |
3053 Bytecount n2 = n; | |
867 | 3054 const Ibyte *src2 = src; |
771 | 3055 |
3056 for (; n2; n2--) | |
3057 { | |
867 | 3058 Ibyte c = *src2++; |
771 | 3059 if (c == '\n') |
3060 { | |
3061 data->actual = EOL_LF; | |
3062 break; | |
3063 } | |
3064 else if (c == '\r') | |
3065 { | |
3066 if (n2 == 1) | |
3067 { | |
3068 /* If we're seeing a '\r' at the end of the data, then | |
3069 reject the '\r' right now so it doesn't become an | |
3070 issue in the code below -- unless we're at the end of | |
3071 the stream, in which case we can't do that (because | |
3072 then the '\r' will never get written out), and in any | |
3073 case we should be recognizing it at EOL_CR format. */ | |
3074 if (str->eof) | |
3075 data->actual = EOL_CR; | |
3076 else | |
3077 n--; | |
3078 break; | |
3079 } | |
3080 else if (*src2 == '\n') | |
3081 data->actual = EOL_CRLF; | |
3082 else | |
3083 data->actual = EOL_CR; | |
3084 break; | |
3085 } | |
3086 } | |
3087 } | |
3088 | |
3089 /* str->eof is set, the caller reached EOF on the other end and has | |
3090 no new data to give us. The only data we get is the data we | |
3091 rejected from last time. */ | |
3092 if (data->actual == EOL_LF || data->actual == EOL_AUTODETECT || | |
3093 (str->eof)) | |
3094 Dynarr_add_many (dst, src, n); | |
3095 else | |
3096 { | |
867 | 3097 const Ibyte *end = src + n; |
771 | 3098 while (1) |
3099 { | |
3100 /* Find the next section with no \r and add it. */ | |
867 | 3101 const Ibyte *runstart = src; |
3102 src = (Ibyte *) memchr (src, '\r', end - src); | |
771 | 3103 if (!src) |
3104 src = end; | |
3105 Dynarr_add_many (dst, runstart, src - runstart); | |
3106 /* Stop if at end ... */ | |
3107 if (src == end) | |
3108 break; | |
3109 /* ... else, translate as necessary. */ | |
3110 src++; | |
3111 if (data->actual == EOL_CR) | |
3112 Dynarr_add (dst, '\n'); | |
3113 /* We need to be careful here with CRLF. If we see a CR at the | |
3114 end of the data, we don't know if it's part of a CRLF, so we | |
3115 reject it. Otherwise: If it's part of a CRLF, eat it and | |
3116 loop; the following LF gets added next time around. If it's | |
3117 not part of a CRLF, add the CR and loop. The following | |
3118 character will be processed in the next loop iteration. This | |
3119 correctly handles a sequence like CR+CR+LF. */ | |
3120 else if (src == end) | |
3121 return n - 1; /* reject the CR at the end; we'll get it again | |
3122 next time the convert method is called */ | |
3123 else if (*src != '\n') | |
3124 Dynarr_add (dst, '\r'); | |
3125 } | |
3126 } | |
3127 | |
3128 return n; | |
3129 } | |
3130 else | |
3131 { | |
3132 enum eol_type subtype = | |
3133 XCODING_SYSTEM_CONVERT_EOL_SUBTYPE (str->codesys); | |
867 | 3134 const Ibyte *end = src + n; |
771 | 3135 |
3136 /* We try to be relatively efficient here. */ | |
3137 if (subtype == EOL_LF) | |
3138 Dynarr_add_many (dst, src, n); | |
3139 else | |
3140 { | |
3141 while (1) | |
3142 { | |
3143 /* Find the next section with no \n and add it. */ | |
867 | 3144 const Ibyte *runstart = src; |
3145 src = (Ibyte *) memchr (src, '\n', end - src); | |
771 | 3146 if (!src) |
3147 src = end; | |
3148 Dynarr_add_many (dst, runstart, src - runstart); | |
3149 /* Stop if at end ... */ | |
3150 if (src == end) | |
3151 break; | |
3152 /* ... else, skip over \n and add its translation. */ | |
3153 src++; | |
3154 Dynarr_add (dst, '\r'); | |
3155 if (subtype == EOL_CRLF) | |
3156 Dynarr_add (dst, '\n'); | |
3157 } | |
3158 } | |
3159 | |
3160 return n; | |
3161 } | |
3162 } | |
3163 | |
3164 static Lisp_Object | |
3165 convert_eol_canonicalize_after_coding (struct coding_stream *str) | |
3166 { | |
3167 struct convert_eol_coding_stream *data = | |
3168 CODING_STREAM_TYPE_DATA (str, convert_eol); | |
3169 | |
3170 if (str->direction == CODING_ENCODE) | |
3171 return str->codesys; | |
3172 | |
3173 switch (data->actual) | |
3174 { | |
3175 case EOL_LF: return Fget_coding_system (Qconvert_eol_lf); | |
3176 case EOL_CRLF: return Fget_coding_system (Qconvert_eol_crlf); | |
3177 case EOL_CR: return Fget_coding_system (Qconvert_eol_cr); | |
3178 case EOL_AUTODETECT: return str->codesys; | |
2500 | 3179 default: ABORT (); return Qnil; |
771 | 3180 } |
3181 } | |
3182 | |
3183 | |
3184 /************************************************************************/ | |
3185 /* Undecided methods */ | |
3186 /************************************************************************/ | |
3187 | |
3188 /* Do autodetection. We can autodetect the EOL type only, the coding | |
3189 system only, or both. We only do autodetection when decoding; when | |
3190 encoding, we just pass the data through. | |
3191 | |
3192 When doing just EOL detection, a coding system can be specified; if so, | |
3193 we will decode this data through the coding system before doing EOL | |
3194 detection. The reason for specifying this is so that | |
3195 canonicalize-after-coding works: We will canonicalize the specified | |
3196 coding system into the appropriate EOL type. When doing both coding and | |
3197 EOL detection, we do similar canonicalization, and also catch situations | |
3198 where the EOL type is overspecified, i.e. the detected coding system | |
3199 specifies an EOL type, and either switch to the equivalent | |
3200 non-EOL-processing coding system (if possible), or terminate EOL | |
3201 detection and use the specified EOL type. This prevents data from being | |
3202 EOL-processed twice. | |
3203 */ | |
3204 | |
3205 struct undecided_coding_system | |
3206 { | |
3207 int do_eol, do_coding; | |
3208 Lisp_Object cs; | |
3209 }; | |
3210 | |
3211 struct undecided_coding_stream | |
3212 { | |
3213 Lisp_Object actual; | |
3214 /* Either 2 or 3 lstreams here; see undecided_convert */ | |
3215 struct chain_coding_stream c; | |
3216 | |
3217 struct detection_state *st; | |
3218 }; | |
3219 | |
1204 | 3220 static const struct memory_description undecided_coding_system_description[] = { |
3221 { XD_LISP_OBJECT, offsetof (struct undecided_coding_system, cs) }, | |
771 | 3222 { XD_END } |
3223 }; | |
3224 | |
1204 | 3225 static const struct memory_description undecided_coding_stream_description_1 [] = { |
3226 { XD_LISP_OBJECT, offsetof (struct undecided_coding_stream, actual) }, | |
2367 | 3227 { XD_BLOCK_ARRAY, offsetof (struct undecided_coding_stream, c), |
2551 | 3228 1, { &chain_coding_stream_description } }, |
1204 | 3229 { XD_END } |
3230 }; | |
3231 | |
3232 const struct sized_memory_description undecided_coding_stream_description = { | |
3233 sizeof (struct undecided_coding_stream), undecided_coding_stream_description_1 | |
3234 }; | |
3235 | |
3236 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (undecided); | |
3237 | |
771 | 3238 static void |
3239 undecided_init (Lisp_Object codesys) | |
3240 { | |
3241 struct undecided_coding_system *data = | |
3242 XCODING_SYSTEM_TYPE_DATA (codesys, undecided); | |
3243 | |
3244 data->cs = Qnil; | |
3245 } | |
3246 | |
3247 static void | |
3248 undecided_mark (Lisp_Object codesys) | |
3249 { | |
3250 struct undecided_coding_system *data = | |
3251 XCODING_SYSTEM_TYPE_DATA (codesys, undecided); | |
3252 | |
3253 mark_object (data->cs); | |
3254 } | |
3255 | |
3256 static void | |
3257 undecided_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag) | |
3258 { | |
3259 struct undecided_coding_system *data = | |
3260 XCODING_SYSTEM_TYPE_DATA (cs, undecided); | |
3261 int need_space = 0; | |
3262 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3263 write_ascstring (printcharfun, "("); |
771 | 3264 if (data->do_eol) |
3265 { | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3266 write_ascstring (printcharfun, "do-eol"); |
771 | 3267 need_space = 1; |
3268 } | |
3269 if (data->do_coding) | |
3270 { | |
3271 if (need_space) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3272 write_ascstring (printcharfun, " "); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3273 write_ascstring (printcharfun, "do-coding"); |
771 | 3274 need_space = 1; |
3275 } | |
3276 if (!NILP (data->cs)) | |
3277 { | |
3278 if (need_space) | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3279 write_ascstring (printcharfun, " "); |
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3280 write_ascstring (printcharfun, "coding-system="); |
771 | 3281 print_coding_system_in_print_method (data->cs, printcharfun, escapeflag); |
3282 } | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
3283 write_ascstring (printcharfun, ")"); |
771 | 3284 } |
3285 | |
3286 static void | |
3287 undecided_mark_coding_stream (struct coding_stream *str) | |
3288 { | |
1204 | 3289 mark_object (CODING_STREAM_TYPE_DATA (str, undecided)->actual); |
771 | 3290 chain_mark_coding_stream_1 (&CODING_STREAM_TYPE_DATA (str, undecided)->c); |
3291 } | |
3292 | |
3293 static int | |
3294 undecided_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value) | |
3295 { | |
3296 struct undecided_coding_system *data = | |
3297 XCODING_SYSTEM_TYPE_DATA (codesys, undecided); | |
3298 | |
3299 if (EQ (key, Qdo_eol)) | |
3300 data->do_eol = 1; | |
3301 else if (EQ (key, Qdo_coding)) | |
3302 data->do_coding = 1; | |
3303 else if (EQ (key, Qcoding_system)) | |
3304 data->cs = get_coding_system_for_text_file (value, 0); | |
3305 else | |
3306 return 0; | |
3307 return 1; | |
3308 } | |
3309 | |
3310 static Lisp_Object | |
3311 undecided_getprop (Lisp_Object codesys, Lisp_Object prop) | |
3312 { | |
3313 struct undecided_coding_system *data = | |
3314 XCODING_SYSTEM_TYPE_DATA (codesys, undecided); | |
3315 | |
3316 if (EQ (prop, Qdo_eol)) | |
3317 return data->do_eol ? Qt : Qnil; | |
3318 if (EQ (prop, Qdo_coding)) | |
3319 return data->do_coding ? Qt : Qnil; | |
3320 if (EQ (prop, Qcoding_system)) | |
3321 return data->cs; | |
3322 return Qunbound; | |
3323 } | |
3324 | |
3325 static struct detection_state * | |
3326 allocate_detection_state (void) | |
3327 { | |
3328 int i; | |
3329 Bytecount size = MAX_ALIGN_SIZE (sizeof (struct detection_state)); | |
3330 struct detection_state *block; | |
3331 | |
3332 for (i = 0; i < coding_detector_count; i++) | |
3333 size += MAX_ALIGN_SIZE (Dynarr_at (all_coding_detectors, i).data_size); | |
3334 | |
3335 block = (struct detection_state *) xmalloc_and_zero (size); | |
3336 | |
3337 size = MAX_ALIGN_SIZE (sizeof (struct detection_state)); | |
3338 for (i = 0; i < coding_detector_count; i++) | |
3339 { | |
3340 block->data_offset[i] = size; | |
3341 size += MAX_ALIGN_SIZE (Dynarr_at (all_coding_detectors, i).data_size); | |
3342 } | |
3343 | |
3344 return block; | |
3345 } | |
3346 | |
3347 static void | |
3348 free_detection_state (struct detection_state *st) | |
3349 { | |
3350 int i; | |
3351 | |
3352 for (i = 0; i < coding_detector_count; i++) | |
3353 { | |
3354 if (Dynarr_at (all_coding_detectors, i).finalize_detection_state_method) | |
3355 Dynarr_at (all_coding_detectors, i).finalize_detection_state_method | |
3356 (st); | |
3357 } | |
3358 | |
4976
16112448d484
Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents:
4967
diff
changeset
|
3359 xfree (st); |
771 | 3360 } |
3361 | |
3362 static int | |
3363 coding_category_symbol_to_id (Lisp_Object symbol) | |
428 | 3364 { |
3365 int i; | |
3366 | |
3367 CHECK_SYMBOL (symbol); | |
771 | 3368 for (i = 0; i < coding_detector_count; i++) |
3369 { | |
3370 detector_category_dynarr *cats = | |
3371 Dynarr_at (all_coding_detectors, i).cats; | |
3372 int j; | |
3373 | |
3374 for (j = 0; j < Dynarr_length (cats); j++) | |
3375 if (EQ (Dynarr_at (cats, j).sym, symbol)) | |
3376 return Dynarr_at (cats, j).id; | |
3377 } | |
3378 | |
563 | 3379 invalid_constant ("Unrecognized coding category", symbol); |
1204 | 3380 RETURN_NOT_REACHED (0); |
428 | 3381 } |
3382 | |
771 | 3383 static Lisp_Object |
3384 coding_category_id_to_symbol (int id) | |
428 | 3385 { |
3386 int i; | |
771 | 3387 |
3388 for (i = 0; i < coding_detector_count; i++) | |
3389 { | |
3390 detector_category_dynarr *cats = | |
3391 Dynarr_at (all_coding_detectors, i).cats; | |
3392 int j; | |
3393 | |
3394 for (j = 0; j < Dynarr_length (cats); j++) | |
3395 if (id == Dynarr_at (cats, j).id) | |
3396 return Dynarr_at (cats, j).sym; | |
3397 } | |
3398 | |
2500 | 3399 ABORT (); |
771 | 3400 return Qnil; /* (usually) not reached */ |
428 | 3401 } |
3402 | |
771 | 3403 static Lisp_Object |
3404 detection_result_number_to_symbol (enum detection_result result) | |
428 | 3405 { |
1494 | 3406 /* let compiler warn if not all enumerators are handled */ |
3407 switch (result) { | |
3408 #define FROB(sym, num) case num: return (sym) | |
771 | 3409 FROB (Qnear_certainty, DET_NEAR_CERTAINTY); |
3410 FROB (Qquite_probable, DET_QUITE_PROBABLE); | |
3411 FROB (Qsomewhat_likely, DET_SOMEWHAT_LIKELY); | |
1494 | 3412 FROB (Qslightly_likely, DET_SLIGHTLY_LIKELY); |
771 | 3413 FROB (Qas_likely_as_unlikely, DET_AS_LIKELY_AS_UNLIKELY); |
3414 FROB (Qsomewhat_unlikely, DET_SOMEWHAT_UNLIKELY); | |
3415 FROB (Qquite_improbable, DET_QUITE_IMPROBABLE); | |
3416 FROB (Qnearly_impossible, DET_NEARLY_IMPOSSIBLE); | |
3417 #undef FROB | |
1494 | 3418 } |
771 | 3419 |
2500 | 3420 ABORT (); |
771 | 3421 return Qnil; /* (usually) not reached */ |
3422 } | |
3423 | |
778 | 3424 #if 0 /* not used */ |
771 | 3425 static enum detection_result |
3426 detection_result_symbol_to_number (Lisp_Object symbol) | |
3427 { | |
1494 | 3428 /* using switch here would be bad style, and doesn't help */ |
771 | 3429 #define FROB(sym, num) if (EQ (symbol, sym)) return (num) |
3430 FROB (Qnear_certainty, DET_NEAR_CERTAINTY); | |
3431 FROB (Qquite_probable, DET_QUITE_PROBABLE); | |
3432 FROB (Qsomewhat_likely, DET_SOMEWHAT_LIKELY); | |
1494 | 3433 FROB (Qslightly_likely, DET_SLIGHTLY_LIKELY); |
771 | 3434 FROB (Qas_likely_as_unlikely, DET_AS_LIKELY_AS_UNLIKELY); |
3435 FROB (Qsomewhat_unlikely, DET_SOMEWHAT_UNLIKELY); | |
3436 FROB (Qquite_improbable, DET_QUITE_IMPROBABLE); | |
3437 FROB (Qnearly_impossible, DET_NEARLY_IMPOSSIBLE); | |
3438 #undef FROB | |
3439 | |
3440 invalid_constant ("Unrecognized detection result", symbol); | |
3441 return ((enum detection_result) 0); /* not reached */ | |
3442 } | |
778 | 3443 #endif /* 0 */ |
771 | 3444 |
3445 /* Set all detection results for a given detector to a specified value. */ | |
3446 void | |
3447 set_detection_results (struct detection_state *st, int detector, int given) | |
3448 { | |
3449 detector_category_dynarr *cats = | |
3450 Dynarr_at (all_coding_detectors, detector).cats; | |
3451 int i; | |
3452 | |
3453 for (i = 0; i < Dynarr_length (cats); i++) | |
3454 st->categories[Dynarr_at (cats, i).id] = given; | |
3455 } | |
428 | 3456 |
3457 static int | |
3458 acceptable_control_char_p (int c) | |
3459 { | |
3460 switch (c) | |
3461 { | |
3462 /* Allow and ignore control characters that you might | |
3463 reasonably see in a text file */ | |
3464 case '\r': | |
3465 case '\n': | |
3466 case '\t': | |
3467 case 7: /* bell */ | |
3468 case 8: /* backspace */ | |
3469 case 11: /* vertical tab */ | |
3470 case 12: /* form feed */ | |
3471 case 26: /* MS-DOS C-z junk */ | |
3472 case 31: /* '^_' -- for info */ | |
3473 return 1; | |
3474 default: | |
3475 return 0; | |
3476 } | |
3477 } | |
3478 | |
771 | 3479 #ifdef DEBUG_XEMACS |
3480 | |
3481 static UExtbyte | |
3482 hex_digit_to_char (int digit) | |
428 | 3483 { |
771 | 3484 if (digit < 10) |
3485 return digit + '0'; | |
3486 else | |
3487 return digit - 10 + 'A'; | |
428 | 3488 } |
3489 | |
771 | 3490 static void |
3491 output_bytes_in_ascii_and_hex (const UExtbyte *src, Bytecount n) | |
428 | 3492 { |
3425 | 3493 Extbyte *ascii = alloca_array (Extbyte, n + 1); |
3494 Extbyte *hex = alloca_array (Extbyte, 3 * n + 1); | |
771 | 3495 int i; |
3413 | 3496 DECLARE_EISTRING (eistr_ascii); |
3497 DECLARE_EISTRING (eistr_hex); | |
771 | 3498 |
3499 for (i = 0; i < n; i++) | |
428 | 3500 { |
3425 | 3501 Extbyte c = src[i]; |
771 | 3502 if (c < 0x20) |
3503 ascii[i] = '.'; | |
428 | 3504 else |
771 | 3505 ascii[i] = c; |
3506 hex[3 * i] = hex_digit_to_char (c >> 4); | |
3507 hex[3 * i + 1] = hex_digit_to_char (c & 0xF); | |
3508 hex[3 * i + 2] = ' '; | |
428 | 3509 } |
771 | 3510 ascii[i] = '\0'; |
3511 hex[3 * i - 1] = '\0'; | |
3413 | 3512 |
3513 eicpy_ext(eistr_hex, hex, Qbinary); | |
3514 eicpy_ext(eistr_ascii, ascii, Qbinary); | |
3515 | |
3425 | 3516 stderr_out ("%s %s", eidata(eistr_ascii), eidata(eistr_hex)); |
428 | 3517 } |
3518 | |
771 | 3519 #endif /* DEBUG_XEMACS */ |
3520 | |
3521 /* Attempt to determine the encoding of the given text. Before calling | |
3522 this function for the first time, you must zero out the detection state. | |
428 | 3523 |
3524 Returns: | |
3525 | |
771 | 3526 0 == keep going |
3527 1 == stop | |
428 | 3528 */ |
3529 | |
3530 static int | |
771 | 3531 detect_coding_type (struct detection_state *st, const UExtbyte *src, |
3532 Bytecount n) | |
428 | 3533 { |
771 | 3534 Bytecount n2 = n; |
3535 const UExtbyte *src2 = src; | |
3536 int i; | |
3537 | |
3538 #ifdef DEBUG_XEMACS | |
3539 if (!NILP (Vdebug_coding_detection)) | |
3540 { | |
3541 int bytes = min (16, n); | |
3542 stderr_out ("detect_coding_type: processing %ld bytes\n", n); | |
3543 stderr_out ("First %d: ", bytes); | |
3544 output_bytes_in_ascii_and_hex (src, bytes); | |
3545 stderr_out ("\nLast %d: ", bytes); | |
3546 output_bytes_in_ascii_and_hex (src + n - bytes, bytes); | |
3547 stderr_out ("\n"); | |
3548 } | |
3549 #endif /* DEBUG_XEMACS */ | |
428 | 3550 if (!st->seen_non_ascii) |
3551 { | |
771 | 3552 for (; n2; n2--, src2++) |
428 | 3553 { |
771 | 3554 UExtbyte c = *src2; |
428 | 3555 if ((c < 0x20 && !acceptable_control_char_p (c)) || c >= 0x80) |
3556 { | |
3557 st->seen_non_ascii = 1; | |
3558 break; | |
3559 } | |
3560 } | |
3561 } | |
3562 | |
771 | 3563 for (i = 0; i < coding_detector_count; i++) |
3564 Dynarr_at (all_coding_detectors, i).detect_method (st, src, n); | |
3565 | |
3566 st->bytes_seen += n; | |
3567 | |
3568 #ifdef DEBUG_XEMACS | |
3569 if (!NILP (Vdebug_coding_detection)) | |
3570 { | |
3571 stderr_out ("seen_non_ascii: %d\n", st->seen_non_ascii); | |
1494 | 3572 if (coding_detector_category_count <= 0) |
3573 stderr_out ("found %d detector categories\n", | |
3574 coding_detector_category_count); | |
771 | 3575 for (i = 0; i < coding_detector_category_count; i++) |
3576 stderr_out_lisp | |
3577 ("%s: %s\n", | |
3578 2, | |
3579 coding_category_id_to_symbol (i), | |
3580 detection_result_number_to_symbol ((enum detection_result) | |
3581 st->categories[i])); | |
3582 } | |
3583 #endif /* DEBUG_XEMACS */ | |
3584 | |
3585 { | |
3586 int not_unlikely = 0; | |
3587 int retval; | |
3588 | |
3589 for (i = 0; i < coding_detector_category_count; i++) | |
3590 if (st->categories[i] >= 0) | |
3591 not_unlikely++; | |
3592 | |
3593 retval = (not_unlikely <= 1 | |
3594 #if 0 /* this is bogus */ | |
3595 || st->bytes_seen >= MAX_BYTES_PROCESSED_FOR_DETECTION | |
428 | 3596 #endif |
771 | 3597 ); |
3598 | |
3599 #ifdef DEBUG_XEMACS | |
3600 if (!NILP (Vdebug_coding_detection)) | |
3601 stderr_out ("detect_coding_type: returning %d (%s)\n", | |
3602 retval, retval ? "stop" : "keep going"); | |
3603 #endif /* DEBUG_XEMACS */ | |
3604 | |
3605 return retval; | |
428 | 3606 } |
3607 } | |
3608 | |
3609 static Lisp_Object | |
771 | 3610 detected_coding_system (struct detection_state *st) |
428 | 3611 { |
771 | 3612 int i; |
3613 int even = 1; | |
3614 | |
3615 if (st->seen_non_ascii) | |
3616 { | |
3617 for (i = 0; i < coding_detector_category_count; i++) | |
3618 if (st->categories[i] != DET_AS_LIKELY_AS_UNLIKELY) | |
3619 { | |
3620 even = 0; | |
3621 break; | |
3622 } | |
3623 } | |
3624 | |
3625 /* #### Here we are ignoring the results of detection when it's all | |
3626 ASCII. This is obviously a bad thing. But we need to fix up the | |
3627 existing detection methods somewhat before we can switch. */ | |
3628 if (even) | |
428 | 3629 { |
3630 /* If the file was entirely or basically ASCII, use the | |
3631 default value of `buffer-file-coding-system'. */ | |
3632 Lisp_Object retval = | |
3633 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system; | |
3634 if (!NILP (retval)) | |
3635 { | |
771 | 3636 retval = find_coding_system_for_text_file (retval, 0); |
428 | 3637 if (NILP (retval)) |
3638 { | |
3639 warn_when_safe | |
3640 (Qbad_variable, Qwarning, | |
3641 "Invalid `default-buffer-file-coding-system', set to nil"); | |
3642 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system = Qnil; | |
3643 } | |
3644 } | |
3645 if (NILP (retval)) | |
4100 | 3646 retval = Fget_coding_system (Qbinary); |
428 | 3647 return retval; |
3648 } | |
3649 else | |
3650 { | |
771 | 3651 int likelihood; |
3652 Lisp_Object retval = Qnil; | |
3653 | |
3654 /* Look through the coding categories first by likelihood and then by | |
3655 priority and find the first one that is allowed. */ | |
3656 | |
3657 for (likelihood = DET_HIGHEST; likelihood >= DET_LOWEST; likelihood--) | |
428 | 3658 { |
771 | 3659 for (i = 0; i < coding_detector_category_count; i++) |
3660 { | |
3661 int cat = coding_category_by_priority[i]; | |
3662 if (st->categories[cat] == likelihood && | |
3663 !NILP (coding_category_system[cat])) | |
3664 { | |
3665 retval = (get_coding_system_for_text_file | |
3666 (coding_category_system[cat], 0)); | |
3667 if (likelihood < DET_AS_LIKELY_AS_UNLIKELY) | |
3668 warn_when_safe_lispobj | |
3669 (intern ("detection"), | |
793 | 3670 Qwarning, |
771 | 3671 emacs_sprintf_string_lisp |
3672 ( | |
3673 "Detected coding %s is unlikely to be correct (likelihood == `%s')", | |
3674 Qnil, 2, XCODING_SYSTEM_NAME (retval), | |
3675 detection_result_number_to_symbol | |
3676 ((enum detection_result) likelihood))); | |
3677 return retval; | |
3678 } | |
3679 } | |
428 | 3680 } |
771 | 3681 |
3682 return Fget_coding_system (Qraw_text); | |
428 | 3683 } |
3684 } | |
3685 | |
1347 | 3686 /* Look for a coding system in the string (skipping over leading |
3687 blanks). If found, return it, otherwise nil. */ | |
3688 | |
3689 static Lisp_Object | |
2531 | 3690 snarf_coding_system (const UExtbyte *p, Bytecount len) |
1347 | 3691 { |
3692 Bytecount n; | |
2531 | 3693 UExtbyte *name; |
1347 | 3694 |
3695 while (*p == ' ' || *p == '\t') p++, len--; | |
3696 len = min (len, 1000); | |
3697 name = alloca_ibytes (len + 1); | |
3698 memcpy (name, p, len); | |
3699 name[len] = '\0'; | |
3700 | |
3701 /* Get coding system name */ | |
3702 /* Characters valid in a MIME charset name (rfc 1521), | |
3703 and in a Lisp symbol name. */ | |
3704 n = qxestrspn (name, | |
3705 "ABCDEFGHIJKLMNOPQRSTUVWXYZ" | |
3706 "abcdefghijklmnopqrstuvwxyz" | |
3707 "0123456789" | |
3708 "!$%&*+-.^_{|}~"); | |
3709 if (n > 0) | |
3710 { | |
3711 name[n] = '\0'; | |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3712 /* This call to intern_istring() is OK because we already verified that |
2531 | 3713 there are only ASCII characters in the string */ |
4953
304aebb79cd3
function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents:
4952
diff
changeset
|
3714 return find_coding_system_for_text_file (intern_istring ((Ibyte *) name), 0); |
1347 | 3715 } |
3716 | |
3717 return Qnil; | |
3718 } | |
3719 | |
428 | 3720 /* Given a seekable read stream and potential coding system and EOL type |
3721 as specified, do any autodetection that is called for. If the | |
3722 coding system and/or EOL type are not `autodetect', they will be left | |
3723 alone; but this function will never return an autodetect coding system | |
3724 or EOL type. | |
3725 | |
3726 This function does not automatically fetch subsidiary coding systems; | |
3727 that should be unnecessary with the explicit eol-type argument. */ | |
3728 | |
3729 #define LENGTH(string_constant) (sizeof (string_constant) - 1) | |
3730 | |
771 | 3731 static Lisp_Object |
3732 unwind_free_detection_state (Lisp_Object opaque) | |
3733 { | |
3734 struct detection_state *st = | |
3735 (struct detection_state *) get_opaque_ptr (opaque); | |
3736 free_detection_state (st); | |
3737 free_opaque_ptr (opaque); | |
3738 return Qnil; | |
3739 } | |
3740 | |
1347 | 3741 /* #### This duplicates code in `find-coding-system-magic-cookie-in-file' |
3742 in files.el. Look into combining them. */ | |
3743 | |
771 | 3744 static Lisp_Object |
3745 look_for_coding_system_magic_cookie (const UExtbyte *data, Bytecount len) | |
428 | 3746 { |
771 | 3747 const UExtbyte *p; |
3748 const UExtbyte *scan_end; | |
2531 | 3749 Bytecount cookie_len; |
771 | 3750 |
3751 /* Look for initial "-*-"; mode line prefix */ | |
3752 for (p = data, | |
3753 scan_end = data + len - LENGTH ("-*-coding:?-*-"); | |
3754 p <= scan_end | |
3755 && *p != '\n' | |
3756 && *p != '\r'; | |
3757 p++) | |
3758 if (*p == '-' && *(p+1) == '*' && *(p+2) == '-') | |
3759 { | |
3760 const UExtbyte *local_vars_beg = p + 3; | |
3761 /* Look for final "-*-"; mode line suffix */ | |
3762 for (p = local_vars_beg, | |
3763 scan_end = data + len - LENGTH ("-*-"); | |
3764 p <= scan_end | |
428 | 3765 && *p != '\n' |
3766 && *p != '\r'; | |
771 | 3767 p++) |
3768 if (*p == '-' && *(p+1) == '*' && *(p+2) == '-') | |
3769 { | |
3770 const UExtbyte *suffix = p; | |
3771 /* Look for "coding:" */ | |
3772 for (p = local_vars_beg, | |
3773 scan_end = suffix - LENGTH ("coding:?"); | |
3774 p <= scan_end; | |
3775 p++) | |
3776 if (memcmp ("coding:", p, LENGTH ("coding:")) == 0 | |
3777 && (p == local_vars_beg | |
3778 || (*(p-1) == ' ' || | |
3779 *(p-1) == '\t' || | |
3780 *(p-1) == ';'))) | |
3781 { | |
3782 p += LENGTH ("coding:"); | |
1347 | 3783 return snarf_coding_system (p, suffix - p); |
771 | 3784 break; |
3785 } | |
3786 break; | |
3787 } | |
3788 break; | |
3789 } | |
3790 | |
2531 | 3791 /* Look for ;;;###coding system */ |
3792 | |
3793 cookie_len = LENGTH (";;;###coding system: "); | |
3794 | |
3795 for (p = data, | |
3796 scan_end = data + len - cookie_len; | |
3797 p <= scan_end; | |
3798 p++) | |
1347 | 3799 { |
2531 | 3800 if (*p == ';' && !memcmp (p, ";;;###coding system: ", cookie_len)) |
3801 { | |
3802 const UExtbyte *suffix; | |
3803 | |
3804 p += cookie_len; | |
3805 suffix = p; | |
3806 while (suffix < scan_end && !isspace (*suffix)) | |
3807 suffix++; | |
3808 return snarf_coding_system (p, suffix - p); | |
3809 } | |
1347 | 3810 } |
3811 | |
3812 return Qnil; | |
771 | 3813 } |
3814 | |
3815 static Lisp_Object | |
3816 determine_real_coding_system (Lstream *stream) | |
3817 { | |
3818 struct detection_state *st = allocate_detection_state (); | |
3819 int depth = record_unwind_protect (unwind_free_detection_state, | |
3820 make_opaque_ptr (st)); | |
3821 UExtbyte buf[4096]; | |
3822 Bytecount nread = Lstream_read (stream, buf, sizeof (buf)); | |
3823 Lisp_Object coding_system = look_for_coding_system_magic_cookie (buf, nread); | |
3824 | |
3825 if (NILP (coding_system)) | |
3826 { | |
3827 while (1) | |
3828 { | |
3829 if (detect_coding_type (st, buf, nread)) | |
428 | 3830 break; |
771 | 3831 nread = Lstream_read (stream, buf, sizeof (buf)); |
3832 if (nread == 0) | |
3833 break; | |
428 | 3834 } |
771 | 3835 |
3836 coding_system = detected_coding_system (st); | |
428 | 3837 } |
3838 | |
3839 Lstream_rewind (stream); | |
771 | 3840 |
3841 unbind_to (depth); | |
3842 return coding_system; | |
3843 } | |
3844 | |
3845 static void | |
3846 undecided_init_coding_stream (struct coding_stream *str) | |
3847 { | |
3848 struct undecided_coding_stream *data = | |
3849 CODING_STREAM_TYPE_DATA (str, undecided); | |
3850 struct undecided_coding_system *csdata = | |
3851 XCODING_SYSTEM_TYPE_DATA (str->codesys, undecided); | |
3852 | |
3853 data->actual = Qnil; | |
3854 | |
3855 if (str->direction == CODING_DECODE) | |
3856 { | |
3857 Lstream *lst = str->other_end; | |
3858 | |
3859 if ((lst->flags & LSTREAM_FL_READ) && | |
3860 Lstream_seekable_p (lst) && | |
3861 csdata->do_coding) | |
3862 /* We can determine the coding system now. */ | |
3863 data->actual = determine_real_coding_system (lst); | |
3864 } | |
1494 | 3865 |
3866 #ifdef DEBUG_XEMACS | |
3867 if (!NILP (Vdebug_coding_detection)) | |
3868 stderr_out_lisp ("detected coding system: %s\n", 1, data->actual); | |
3869 #endif /* DEBUG_XEMACS */ | |
771 | 3870 } |
3871 | |
3872 static void | |
3873 undecided_rewind_coding_stream (struct coding_stream *str) | |
3874 { | |
3875 chain_rewind_coding_stream_1 (&CODING_STREAM_TYPE_DATA (str, undecided)->c); | |
3876 } | |
3877 | |
3878 static void | |
3879 undecided_finalize_coding_stream (struct coding_stream *str) | |
3880 { | |
3881 struct undecided_coding_stream *data = | |
3882 CODING_STREAM_TYPE_DATA (str, undecided); | |
3883 | |
3884 chain_finalize_coding_stream_1 | |
3885 (&CODING_STREAM_TYPE_DATA (str, undecided)->c); | |
3886 if (data->st) | |
3887 free_detection_state (data->st); | |
3888 } | |
3889 | |
3890 static Lisp_Object | |
3891 undecided_canonicalize (Lisp_Object codesys) | |
3892 { | |
3893 struct undecided_coding_system *csdata = | |
3894 XCODING_SYSTEM_TYPE_DATA (codesys, undecided); | |
3895 if (!csdata->do_eol && !csdata->do_coding) | |
3896 return NILP (csdata->cs) ? Fget_coding_system (Qbinary) : csdata->cs; | |
3897 if (csdata->do_eol && !csdata->do_coding && NILP (csdata->cs)) | |
3898 return Fget_coding_system (Qconvert_eol_autodetect); | |
3899 return codesys; | |
3900 } | |
3901 | |
3902 static Bytecount | |
3903 undecided_convert (struct coding_stream *str, const UExtbyte *src, | |
3904 unsigned_char_dynarr *dst, Bytecount n) | |
3905 { | |
3906 int first_time = 0; | |
3907 | |
3908 if (str->direction == CODING_DECODE) | |
3909 { | |
3910 /* At this point, we have only the following possibilities: | |
3911 | |
3912 do_eol && do_coding | |
3913 do_coding only | |
3914 do_eol only and a coding system was specified | |
3915 | |
3916 Other possibilities are removed during undecided_canonicalize. | |
3917 | |
3918 Therefore, our substreams are either | |
3919 | |
3920 lstream_coding -> lstream_dynarr, or | |
3921 lstream_coding -> lstream_eol -> lstream_dynarr. | |
3922 */ | |
3923 struct undecided_coding_system *csdata = | |
3924 XCODING_SYSTEM_TYPE_DATA (str->codesys, undecided); | |
3925 struct undecided_coding_stream *data = | |
3926 CODING_STREAM_TYPE_DATA (str, undecided); | |
3927 | |
3928 if (str->eof) | |
3929 { | |
3930 /* Each will close the next. We need to close now because more | |
3931 data may be generated. */ | |
3932 if (data->c.initted) | |
3933 Lstream_close (XLSTREAM (data->c.lstreams[0])); | |
3934 return n; | |
3935 } | |
3936 | |
3937 if (!data->c.initted) | |
3938 { | |
3939 data->c.lstream_count = csdata->do_eol ? 3 : 2; | |
3940 data->c.lstreams = xnew_array (Lisp_Object, data->c.lstream_count); | |
3941 | |
3942 data->c.lstreams[data->c.lstream_count - 1] = | |
3943 make_dynarr_output_stream (dst); | |
3944 Lstream_set_buffering | |
3945 (XLSTREAM (data->c.lstreams[data->c.lstream_count - 1]), | |
3946 LSTREAM_UNBUFFERED, 0); | |
3947 if (csdata->do_eol) | |
3948 { | |
3949 data->c.lstreams[1] = | |
3950 make_coding_output_stream | |
3951 (XLSTREAM (data->c.lstreams[data->c.lstream_count - 1]), | |
3952 Fget_coding_system (Qconvert_eol_autodetect), | |
800 | 3953 CODING_DECODE, 0); |
771 | 3954 Lstream_set_buffering |
3955 (XLSTREAM (data->c.lstreams[1]), | |
3956 LSTREAM_UNBUFFERED, 0); | |
3957 } | |
3958 | |
3959 data->c.lstreams[0] = | |
3960 make_coding_output_stream | |
3961 (XLSTREAM (data->c.lstreams[1]), | |
3962 /* Substitute binary if we need to detect the encoding */ | |
3963 csdata->do_coding ? Qbinary : csdata->cs, | |
800 | 3964 CODING_DECODE, 0); |
771 | 3965 Lstream_set_buffering (XLSTREAM (data->c.lstreams[0]), |
3966 LSTREAM_UNBUFFERED, 0); | |
3967 | |
3968 first_time = 1; | |
3969 data->c.initted = 1; | |
3970 } | |
3971 | |
3972 /* If necessary, do encoding-detection now. We do this when we're a | |
3973 writing stream or a non-seekable reading stream, meaning that we | |
3974 can't just process the whole input, rewind, and start over. */ | |
3975 | |
3976 if (csdata->do_coding) | |
3977 { | |
3978 int actual_was_nil = NILP (data->actual); | |
3979 if (NILP (data->actual)) | |
3980 { | |
3981 if (!data->st) | |
3982 data->st = allocate_detection_state (); | |
3983 if (first_time) | |
3984 /* #### This is cheesy. What we really ought to do is buffer | |
3985 up a certain minimum amount of data to get a better result. | |
3986 */ | |
3987 data->actual = look_for_coding_system_magic_cookie (src, n); | |
3988 if (NILP (data->actual)) | |
3989 { | |
3990 /* #### This is cheesy. What we really ought to do is buffer | |
3991 up a certain minimum amount of data so as to get a less | |
3992 random result when doing subprocess detection. */ | |
3993 detect_coding_type (data->st, src, n); | |
3994 data->actual = detected_coding_system (data->st); | |
4100 | 3995 /* kludge to prevent infinite recursion */ |
3996 if (XCODING_SYSTEM(data->actual)->methods->enumtype == undecided_coding_system) | |
3997 data->actual = Fget_coding_system (Qbinary); | |
771 | 3998 } |
3999 } | |
4000 /* We need to set the detected coding system if we actually have | |
4001 such a coding system but didn't before. That is the case | |
4002 either when we just detected it in the previous code or when | |
4003 it was detected during undecided_init_coding_stream(). We | |
4004 can check for that using first_time. */ | |
4005 if (!NILP (data->actual) && (actual_was_nil || first_time)) | |
4006 { | |
4007 /* If the detected coding system doesn't allow for EOL | |
4008 autodetection, try to get the equivalent that does; | |
4009 otherwise, disable EOL detection (overriding whatever | |
4010 may already have been detected). */ | |
4011 if (XCODING_SYSTEM_EOL_TYPE (data->actual) != EOL_AUTODETECT) | |
4012 { | |
4013 if (!NILP (XCODING_SYSTEM_SUBSIDIARY_PARENT (data->actual))) | |
4014 data->actual = | |
4015 XCODING_SYSTEM_SUBSIDIARY_PARENT (data->actual); | |
4016 else if (data->c.lstream_count == 3) | |
4017 set_coding_stream_coding_system | |
4018 (XLSTREAM (data->c.lstreams[1]), | |
4019 Fget_coding_system (Qidentity)); | |
4020 } | |
4021 set_coding_stream_coding_system | |
4022 (XLSTREAM (data->c.lstreams[0]), data->actual); | |
4023 } | |
4024 } | |
4025 | |
4026 if (Lstream_write (XLSTREAM (data->c.lstreams[0]), src, n) < 0) | |
4027 return -1; | |
4028 return n; | |
4029 } | |
4030 else | |
4031 return no_conversion_convert (str, src, dst, n); | |
4032 } | |
4033 | |
4034 static Lisp_Object | |
4035 undecided_canonicalize_after_coding (struct coding_stream *str) | |
4036 { | |
4037 struct undecided_coding_stream *data = | |
4038 CODING_STREAM_TYPE_DATA (str, undecided); | |
4039 Lisp_Object ret, eolret; | |
4040 | |
4041 if (str->direction == CODING_ENCODE) | |
4042 return str->codesys; | |
4043 | |
4044 if (!data->c.initted) | |
4647
e4ed58cb0e5b
Fix bugs with #'find-file, 0-length files, & coding-system-for-read specified.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4569
diff
changeset
|
4045 return str->codesys; |
771 | 4046 |
4047 ret = coding_stream_canonicalize_after_coding | |
4048 (XLSTREAM (data->c.lstreams[0])); | |
4049 if (NILP (ret)) | |
4647
e4ed58cb0e5b
Fix bugs with #'find-file, 0-length files, & coding-system-for-read specified.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4569
diff
changeset
|
4050 ret = str->codesys; |
771 | 4051 if (XCODING_SYSTEM_EOL_TYPE (ret) != EOL_AUTODETECT) |
4052 return ret; | |
4053 eolret = coding_stream_canonicalize_after_coding | |
4054 (XLSTREAM (data->c.lstreams[1])); | |
4055 if (!EQ (XCODING_SYSTEM_TYPE (eolret), Qconvert_eol)) | |
4056 return ret; | |
4057 return | |
4058 Fsubsidiary_coding_system (ret, Fcoding_system_property (eolret, | |
4059 Qsubtype)); | |
4060 } | |
4061 | |
4062 | |
4063 /************************************************************************/ | |
4064 /* Lisp interface: Coding category functions and detection */ | |
4065 /************************************************************************/ | |
4066 | |
4067 DEFUN ("coding-category-list", Fcoding_category_list, 0, 0, 0, /* | |
4068 Return a list of all recognized coding categories. | |
4069 */ | |
4070 ()) | |
4071 { | |
4072 int i; | |
4073 Lisp_Object list = Qnil; | |
4074 | |
4075 for (i = 0; i < coding_detector_count; i++) | |
4076 { | |
4077 detector_category_dynarr *cats = | |
4078 Dynarr_at (all_coding_detectors, i).cats; | |
4079 int j; | |
4080 | |
4081 for (j = 0; j < Dynarr_length (cats); j++) | |
4082 list = Fcons (Dynarr_at (cats, j).sym, list); | |
4083 } | |
4084 | |
4085 return Fnreverse (list); | |
4086 } | |
4087 | |
4088 DEFUN ("set-coding-priority-list", Fset_coding_priority_list, 1, 1, 0, /* | |
4089 Change the priority order of the coding categories. | |
4090 LIST should be list of coding categories, in descending order of | |
4091 priority. Unspecified coding categories will be lower in priority | |
4092 than all specified ones, in the same relative order they were in | |
4093 previously. | |
4094 */ | |
4095 (list)) | |
4096 { | |
4097 int *category_to_priority = | |
4098 alloca_array (int, coding_detector_category_count); | |
4099 int i, j; | |
4100 | |
4101 /* First generate a list that maps coding categories to priorities. */ | |
4102 | |
4103 for (i = 0; i < coding_detector_category_count; i++) | |
4104 category_to_priority[i] = -1; | |
4105 | |
4106 /* Highest priority comes from the specified list. */ | |
4107 i = 0; | |
2367 | 4108 { |
4109 EXTERNAL_LIST_LOOP_2 (elt, list) | |
4110 { | |
4111 int cat = coding_category_symbol_to_id (elt); | |
4112 | |
4113 if (category_to_priority[cat] >= 0) | |
4114 sferror ("Duplicate coding category in list", elt); | |
4115 category_to_priority[cat] = i++; | |
4116 } | |
4117 } | |
771 | 4118 |
4119 /* Now go through the existing categories by priority to retrieve | |
4120 the categories not yet specified and preserve their priority | |
4121 order. */ | |
4122 for (j = 0; j < coding_detector_category_count; j++) | |
4123 { | |
4124 int cat = coding_category_by_priority[j]; | |
4125 if (category_to_priority[cat] < 0) | |
4126 category_to_priority[cat] = i++; | |
4127 } | |
4128 | |
4129 /* Now we need to construct the inverse of the mapping we just | |
4130 constructed. */ | |
4131 | |
4132 for (i = 0; i < coding_detector_category_count; i++) | |
4133 coding_category_by_priority[category_to_priority[i]] = i; | |
4134 | |
4135 /* Phew! That was confusing. */ | |
4136 return Qnil; | |
4137 } | |
4138 | |
4139 DEFUN ("coding-priority-list", Fcoding_priority_list, 0, 0, 0, /* | |
4140 Return a list of coding categories in descending order of priority. | |
4141 */ | |
4142 ()) | |
4143 { | |
4144 int i; | |
4145 Lisp_Object list = Qnil; | |
4146 | |
4147 for (i = 0; i < coding_detector_category_count; i++) | |
4148 list = | |
4149 Fcons (coding_category_id_to_symbol (coding_category_by_priority[i]), | |
4150 list); | |
4151 return Fnreverse (list); | |
4152 } | |
4153 | |
4154 DEFUN ("set-coding-category-system", Fset_coding_category_system, 2, 2, 0, /* | |
4155 Change the coding system associated with a coding category. | |
4156 */ | |
4157 (coding_category, coding_system)) | |
4158 { | |
4159 coding_category_system[coding_category_symbol_to_id (coding_category)] = | |
4160 Fget_coding_system (coding_system); | |
4161 return Qnil; | |
4162 } | |
4163 | |
4164 DEFUN ("coding-category-system", Fcoding_category_system, 1, 1, 0, /* | |
4165 Return the coding system associated with a coding category. | |
4166 */ | |
4167 (coding_category)) | |
4168 { | |
4169 Lisp_Object sys = | |
4170 coding_category_system[coding_category_symbol_to_id (coding_category)]; | |
4171 | |
4172 if (!NILP (sys)) | |
4173 return XCODING_SYSTEM_NAME (sys); | |
4174 return Qnil; | |
4175 } | |
4176 | |
800 | 4177 /* Detect the encoding of STREAM. Assumes stream is at the begnning and will |
4178 read through to the end of STREAM, leaving it there but open. */ | |
4179 | |
771 | 4180 Lisp_Object |
4181 detect_coding_stream (Lisp_Object stream) | |
4182 { | |
4183 Lisp_Object val = Qnil; | |
4184 struct gcpro gcpro1, gcpro2, gcpro3; | |
4185 UExtbyte random_buffer[65536]; | |
4186 Lisp_Object binary_instream = | |
4187 make_coding_input_stream | |
4188 (XLSTREAM (stream), Qbinary, | |
814 | 4189 CODING_ENCODE, LSTREAM_FL_NO_CLOSE_OTHER); |
771 | 4190 Lisp_Object decstream = |
4191 make_coding_input_stream | |
4192 (XLSTREAM (binary_instream), | |
800 | 4193 Qundecided, CODING_DECODE, 0); |
771 | 4194 Lstream *decstr = XLSTREAM (decstream); |
4195 | |
4196 GCPRO3 (decstream, stream, binary_instream); | |
4197 /* Read and discard all data; detection happens as a side effect of this, | |
4198 and we examine what was detected afterwards. */ | |
4199 while (Lstream_read (decstr, random_buffer, sizeof (random_buffer)) > 0) | |
4200 ; | |
4201 | |
4202 val = coding_stream_detected_coding_system (decstr); | |
4203 Lstream_close (decstr); | |
4204 Lstream_delete (decstr); | |
4205 Lstream_delete (XLSTREAM (binary_instream)); | |
4206 UNGCPRO; | |
4207 return val; | |
428 | 4208 } |
4209 | |
4210 DEFUN ("detect-coding-region", Fdetect_coding_region, 2, 3, 0, /* | |
4211 Detect coding system of the text in the region between START and END. | |
444 | 4212 Return a list of possible coding systems ordered by priority. |
3025 | 4213 If only ASCII characters are found, return `undecided' or one of |
428 | 4214 its subsidiary coding systems according to a detected end-of-line |
4215 type. Optional arg BUFFER defaults to the current buffer. | |
4216 */ | |
4217 (start, end, buffer)) | |
4218 { | |
4219 Lisp_Object val = Qnil; | |
4220 struct buffer *buf = decode_buffer (buffer, 0); | |
665 | 4221 Charbpos b, e; |
771 | 4222 Lisp_Object lb_instream; |
428 | 4223 |
4224 get_buffer_range_char (buf, start, end, &b, &e, 0); | |
4225 lb_instream = make_lisp_buffer_input_stream (buf, b, e, 0); | |
771 | 4226 |
4227 val = detect_coding_stream (lb_instream); | |
4228 Lstream_delete (XLSTREAM (lb_instream)); | |
428 | 4229 return val; |
4230 } | |
4231 | |
4232 | |
771 | 4233 |
4234 #ifdef DEBUG_XEMACS | |
4235 | |
428 | 4236 /************************************************************************/ |
771 | 4237 /* Internal methods */ |
4238 /************************************************************************/ | |
4239 | |
4240 /* Raw (internally-formatted) data. */ | |
4241 DEFINE_CODING_SYSTEM_TYPE (internal); | |
428 | 4242 |
665 | 4243 static Bytecount |
2286 | 4244 internal_convert (struct coding_stream *UNUSED (str), const UExtbyte *src, |
771 | 4245 unsigned_char_dynarr *dst, Bytecount n) |
4246 { | |
4247 Bytecount orign = n; | |
4248 Dynarr_add_many (dst, src, n); | |
4249 return orign; | |
4250 } | |
4251 | |
4252 #endif /* DEBUG_XEMACS */ | |
4253 | |
4254 | |
4255 | |
4256 #ifdef HAVE_ZLIB | |
4257 | |
4258 /************************************************************************/ | |
4259 /* Gzip methods */ | |
4260 /************************************************************************/ | |
4261 | |
4262 struct gzip_coding_system | |
428 | 4263 { |
771 | 4264 int level; /* 0 through 9, or -1 for default */ |
4265 }; | |
4266 | |
4267 #define CODING_SYSTEM_GZIP_LEVEL(codesys) \ | |
4268 (CODING_SYSTEM_TYPE_DATA (codesys, gzip)->level) | |
4269 #define XCODING_SYSTEM_GZIP_LEVEL(codesys) \ | |
4270 (XCODING_SYSTEM_TYPE_DATA (codesys, gzip)->level) | |
4271 | |
4272 struct gzip_coding_stream | |
428 | 4273 { |
771 | 4274 z_stream stream; |
4275 int stream_initted; | |
4276 int reached_eof; /* #### this should be handled by the caller, once we | |
4277 return LSTREAM_EOF */ | |
4278 }; | |
4279 | |
1204 | 4280 static const struct memory_description |
771 | 4281 gzip_coding_system_description[] = { |
4282 { XD_END } | |
4283 }; | |
4284 | |
1204 | 4285 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (gzip); |
4286 | |
771 | 4287 enum source_sink_type |
4288 gzip_conversion_end_type (Lisp_Object codesys) | |
4289 { | |
4290 return DECODES_BYTE_TO_BYTE; | |
428 | 4291 } |
4292 | |
4293 static void | |
771 | 4294 gzip_init (Lisp_Object codesys) |
4295 { | |
4296 struct gzip_coding_system *data = XCODING_SYSTEM_TYPE_DATA (codesys, gzip); | |
4297 data->level = -1; | |
4298 } | |
4299 | |
4300 static void | |
4301 gzip_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag) | |
428 | 4302 { |
771 | 4303 struct gzip_coding_system *data = XCODING_SYSTEM_TYPE_DATA (cs, gzip); |
4304 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4305 write_ascstring (printcharfun, "("); |
771 | 4306 if (data->level == -1) |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4307 write_ascstring (printcharfun, "default"); |
771 | 4308 else |
4309 print_internal (make_int (data->level), printcharfun, 0); | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4310 write_ascstring (printcharfun, ")"); |
428 | 4311 } |
4312 | |
4313 static int | |
771 | 4314 gzip_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value) |
428 | 4315 { |
771 | 4316 struct gzip_coding_system *data = XCODING_SYSTEM_TYPE_DATA (codesys, gzip); |
4317 | |
4318 if (EQ (key, Qlevel)) | |
428 | 4319 { |
771 | 4320 if (EQ (value, Qdefault)) |
4321 data->level = -1; | |
4322 else | |
428 | 4323 { |
771 | 4324 CHECK_INT (value); |
4325 check_int_range (XINT (value), 0, 9); | |
4326 data->level = XINT (value); | |
428 | 4327 } |
4328 } | |
4329 else | |
771 | 4330 return 0; |
4331 return 1; | |
428 | 4332 } |
4333 | |
4334 static Lisp_Object | |
771 | 4335 gzip_getprop (Lisp_Object coding_system, Lisp_Object prop) |
428 | 4336 { |
771 | 4337 struct gzip_coding_system *data = |
4338 XCODING_SYSTEM_TYPE_DATA (coding_system, gzip); | |
4339 | |
4340 if (EQ (prop, Qlevel)) | |
428 | 4341 { |
771 | 4342 if (data->level == -1) |
4343 return Qdefault; | |
4344 return make_int (data->level); | |
428 | 4345 } |
771 | 4346 |
4347 return Qunbound; | |
428 | 4348 } |
4349 | |
4350 static void | |
771 | 4351 gzip_init_coding_stream (struct coding_stream *str) |
428 | 4352 { |
771 | 4353 struct gzip_coding_stream *data = CODING_STREAM_TYPE_DATA (str, gzip); |
4354 if (data->stream_initted) | |
428 | 4355 { |
771 | 4356 if (str->direction == CODING_DECODE) |
4357 inflateEnd (&data->stream); | |
4358 else | |
4359 deflateEnd (&data->stream); | |
4360 data->stream_initted = 0; | |
428 | 4361 } |
771 | 4362 data->reached_eof = 0; |
428 | 4363 } |
4364 | |
4365 static void | |
771 | 4366 gzip_rewind_coding_stream (struct coding_stream *str) |
428 | 4367 { |
771 | 4368 gzip_init_coding_stream (str); |
428 | 4369 } |
4370 | |
771 | 4371 static Bytecount |
4372 gzip_convert (struct coding_stream *str, | |
4373 const UExtbyte *src, | |
4374 unsigned_char_dynarr *dst, Bytecount n) | |
428 | 4375 { |
771 | 4376 struct gzip_coding_stream *data = CODING_STREAM_TYPE_DATA (str, gzip); |
4377 int zerr; | |
4378 if (str->direction == CODING_DECODE) | |
428 | 4379 { |
771 | 4380 if (data->reached_eof) |
4381 return n; /* eat the data */ | |
4382 | |
4383 if (!data->stream_initted) | |
428 | 4384 { |
771 | 4385 xzero (data->stream); |
4386 if (inflateInit (&data->stream) != Z_OK) | |
4387 return LSTREAM_ERROR; | |
4388 data->stream_initted = 1; | |
428 | 4389 } |
771 | 4390 |
4391 data->stream.next_in = (Bytef *) src; | |
4392 data->stream.avail_in = n; | |
4393 | |
4394 /* Normally we stop when we've fed all data to the decompressor; but | |
4395 if we're at the end of the input, and the decompressor hasn't | |
4396 reported EOF, we need to keep going, as there might be more output | |
4397 to generate. Z_OK from the decompressor means input was processed | |
4398 or output was generated; if neither, we break out of the loop. | |
4399 Other return values are: | |
4400 | |
4401 Z_STREAM_END EOF from decompressor | |
4402 Z_DATA_ERROR Corrupted data | |
4403 Z_BUF_ERROR No progress possible (this should happen if | |
4404 we try to feed it an incomplete file) | |
4405 Z_MEM_ERROR Out of memory | |
4406 Z_STREAM_ERROR (should never happen) | |
4407 Z_NEED_DICT (#### when will this happen?) | |
4408 */ | |
4409 while (data->stream.avail_in > 0 || str->eof) | |
4410 { | |
4411 /* Reserve an output buffer of the same size as the input buffer; | |
4412 if that's not enough, we keep reserving the same size. */ | |
4413 Bytecount reserved = n; | |
4414 Dynarr_add_many (dst, 0, reserved); | |
4415 /* Careful here! Don't retrieve the pointer until after | |
4416 reserving the space, or it might be bogus */ | |
4417 data->stream.next_out = | |
4418 Dynarr_atp (dst, Dynarr_length (dst) - reserved); | |
4419 data->stream.avail_out = reserved; | |
4420 zerr = inflate (&data->stream, Z_NO_FLUSH); | |
4421 /* Lop off the unused portion */ | |
5038 | 4422 Dynarr_set_lengthr (dst, Dynarr_length (dst) - data->stream.avail_out); |
771 | 4423 if (zerr != Z_OK) |
4424 break; | |
4425 } | |
4426 | |
4427 if (zerr == Z_STREAM_END) | |
4428 data->reached_eof = 1; | |
4429 | |
4430 if ((Bytecount) data->stream.avail_in < n) | |
4431 return n - data->stream.avail_in; | |
4432 | |
4433 if (zerr == Z_OK || zerr == Z_STREAM_END) | |
4434 return 0; | |
4435 | |
4436 return LSTREAM_ERROR; | |
428 | 4437 } |
4438 else | |
4439 { | |
771 | 4440 if (!data->stream_initted) |
4441 { | |
4442 int level = XCODING_SYSTEM_GZIP_LEVEL (str->codesys); | |
4443 xzero (data->stream); | |
4444 if (deflateInit (&data->stream, | |
4445 level == -1 ? Z_DEFAULT_COMPRESSION : level) != | |
4446 Z_OK) | |
4447 return LSTREAM_ERROR; | |
4448 data->stream_initted = 1; | |
428 | 4449 } |
771 | 4450 |
4451 data->stream.next_in = (Bytef *) src; | |
4452 data->stream.avail_in = n; | |
4453 | |
4454 /* Normally we stop when we've fed all data to the compressor; but if | |
4455 we're at the end of the input, and the compressor hasn't reported | |
4456 EOF, we need to keep going, as there might be more output to | |
4457 generate. (To signal EOF on our end, we set the FLUSH parameter | |
4458 to Z_FINISH; when all data is output, Z_STREAM_END will be | |
4459 returned.) Z_OK from the compressor means input was processed or | |
4460 output was generated; if neither, we break out of the loop. Other | |
4461 return values are: | |
4462 | |
4463 Z_STREAM_END EOF from compressor | |
4464 Z_BUF_ERROR No progress possible (should never happen) | |
4465 Z_STREAM_ERROR (should never happen) | |
4466 */ | |
4467 while (data->stream.avail_in > 0 || str->eof) | |
4468 { | |
4469 /* Reserve an output buffer of the same size as the input buffer; | |
4470 if that's not enough, we keep reserving the same size. */ | |
4471 Bytecount reserved = n; | |
4472 Dynarr_add_many (dst, 0, reserved); | |
4473 /* Careful here! Don't retrieve the pointer until after | |
4474 reserving the space, or it might be bogus */ | |
4475 data->stream.next_out = | |
4476 Dynarr_atp (dst, Dynarr_length (dst) - reserved); | |
4477 data->stream.avail_out = reserved; | |
4478 zerr = | |
4479 deflate (&data->stream, | |
4480 str->eof ? Z_FINISH : Z_NO_FLUSH); | |
4481 /* Lop off the unused portion */ | |
5038 | 4482 Dynarr_set_lengthr (dst, Dynarr_length (dst) - data->stream.avail_out); |
771 | 4483 if (zerr != Z_OK) |
4484 break; | |
4485 } | |
4486 | |
4487 if ((Bytecount) data->stream.avail_in < n) | |
4488 return n - data->stream.avail_in; | |
4489 | |
4490 if (zerr == Z_OK || zerr == Z_STREAM_END) | |
4491 return 0; | |
4492 | |
4493 return LSTREAM_ERROR; | |
428 | 4494 } |
4495 } | |
4496 | |
771 | 4497 #endif /* HAVE_ZLIB */ |
428 | 4498 |
4499 | |
4500 /************************************************************************/ | |
4501 /* Initialization */ | |
4502 /************************************************************************/ | |
4503 | |
4504 void | |
4505 syms_of_file_coding (void) | |
4506 { | |
5117
3742ea8250b5
Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents:
3025
diff
changeset
|
4507 INIT_LISP_OBJECT (coding_system); |
442 | 4508 |
771 | 4509 DEFSUBR (Fvalid_coding_system_type_p); |
4510 DEFSUBR (Fcoding_system_type_list); | |
428 | 4511 DEFSUBR (Fcoding_system_p); |
4303 | 4512 DEFSUBR (Fautoload_coding_system); |
428 | 4513 DEFSUBR (Ffind_coding_system); |
4514 DEFSUBR (Fget_coding_system); | |
4515 DEFSUBR (Fcoding_system_list); | |
4516 DEFSUBR (Fcoding_system_name); | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4517 DEFSUBR (Fmake_coding_system_internal); |
428 | 4518 DEFSUBR (Fcopy_coding_system); |
440 | 4519 DEFSUBR (Fcoding_system_canonical_name_p); |
4520 DEFSUBR (Fcoding_system_alias_p); | |
4521 DEFSUBR (Fcoding_system_aliasee); | |
428 | 4522 DEFSUBR (Fdefine_coding_system_alias); |
4523 DEFSUBR (Fsubsidiary_coding_system); | |
771 | 4524 DEFSUBR (Fcoding_system_base); |
4525 DEFSUBR (Fcoding_system_used_for_io); | |
428 | 4526 |
4527 DEFSUBR (Fcoding_system_type); | |
771 | 4528 DEFSUBR (Fcoding_system_description); |
428 | 4529 DEFSUBR (Fcoding_system_property); |
4530 | |
4531 DEFSUBR (Fcoding_category_list); | |
4532 DEFSUBR (Fset_coding_priority_list); | |
4533 DEFSUBR (Fcoding_priority_list); | |
4534 DEFSUBR (Fset_coding_category_system); | |
4535 DEFSUBR (Fcoding_category_system); | |
4536 | |
4537 DEFSUBR (Fdetect_coding_region); | |
4538 DEFSUBR (Fdecode_coding_region); | |
4539 DEFSUBR (Fencode_coding_region); | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4540 DEFSUBR (Fquery_coding_region); |
563 | 4541 DEFSYMBOL_MULTIWORD_PREDICATE (Qcoding_systemp); |
4542 DEFSYMBOL (Qno_conversion); | |
771 | 4543 DEFSYMBOL (Qconvert_eol); |
4544 DEFSYMBOL (Qconvert_eol_autodetect); | |
4545 DEFSYMBOL (Qconvert_eol_lf); | |
4546 DEFSYMBOL (Qconvert_eol_cr); | |
4547 DEFSYMBOL (Qconvert_eol_crlf); | |
563 | 4548 DEFSYMBOL (Qraw_text); |
771 | 4549 |
563 | 4550 DEFSYMBOL (Qmnemonic); |
4551 DEFSYMBOL (Qeol_type); | |
4552 DEFSYMBOL (Qpost_read_conversion); | |
4553 DEFSYMBOL (Qpre_write_conversion); | |
4554 | |
771 | 4555 DEFSYMBOL (Qtranslation_table_for_decode); |
4556 DEFSYMBOL (Qtranslation_table_for_encode); | |
4557 DEFSYMBOL (Qsafe_chars); | |
4558 DEFSYMBOL (Qsafe_charsets); | |
4559 DEFSYMBOL (Qmime_charset); | |
4560 DEFSYMBOL (Qvalid_codes); | |
4561 | |
563 | 4562 DEFSYMBOL (Qcr); |
4563 DEFSYMBOL (Qlf); | |
4564 DEFSYMBOL (Qcrlf); | |
4565 DEFSYMBOL (Qeol_cr); | |
4566 DEFSYMBOL (Qeol_lf); | |
4567 DEFSYMBOL (Qeol_crlf); | |
4568 DEFSYMBOL (Qencode); | |
4569 DEFSYMBOL (Qdecode); | |
428 | 4570 |
771 | 4571 DEFSYMBOL (Qnear_certainty); |
4572 DEFSYMBOL (Qquite_probable); | |
4573 DEFSYMBOL (Qsomewhat_likely); | |
1494 | 4574 DEFSYMBOL (Qslightly_likely); |
771 | 4575 DEFSYMBOL (Qas_likely_as_unlikely); |
4576 DEFSYMBOL (Qsomewhat_unlikely); | |
4577 DEFSYMBOL (Qquite_improbable); | |
4578 DEFSYMBOL (Qnearly_impossible); | |
4579 | |
4580 DEFSYMBOL (Qdo_eol); | |
4581 DEFSYMBOL (Qdo_coding); | |
4582 | |
4583 DEFSYMBOL (Qcanonicalize_after_coding); | |
4584 | |
4303 | 4585 DEFSYMBOL (Qposix_charset_to_coding_system_hash); |
4586 | |
771 | 4587 DEFSYMBOL (Qescape_quoted); |
4588 | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4589 DEFSYMBOL (Qquery_coding_warning_face); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4590 DEFSYMBOL (Qaliases); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4591 DEFSYMBOL (Qcharset_skip_chars_string); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4592 |
771 | 4593 #ifdef HAVE_ZLIB |
4594 DEFSYMBOL (Qgzip); | |
4595 #endif | |
4596 | |
428 | 4597 } |
4598 | |
4599 void | |
4600 lstream_type_create_file_coding (void) | |
4601 { | |
771 | 4602 LSTREAM_HAS_METHOD (coding, reader); |
4603 LSTREAM_HAS_METHOD (coding, writer); | |
4604 LSTREAM_HAS_METHOD (coding, rewinder); | |
4605 LSTREAM_HAS_METHOD (coding, seekable_p); | |
4606 LSTREAM_HAS_METHOD (coding, marker); | |
4607 LSTREAM_HAS_METHOD (coding, flusher); | |
4608 LSTREAM_HAS_METHOD (coding, closer); | |
4609 LSTREAM_HAS_METHOD (coding, finalizer); | |
4610 } | |
4611 | |
4612 void | |
4613 coding_system_type_create (void) | |
4614 { | |
4615 int i; | |
4616 | |
4617 staticpro (&Vcoding_system_hash_table); | |
4618 Vcoding_system_hash_table = | |
4619 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ); | |
4620 | |
4621 the_coding_system_type_entry_dynarr = Dynarr_new (coding_system_type_entry); | |
2367 | 4622 dump_add_root_block_ptr (&the_coding_system_type_entry_dynarr, |
771 | 4623 &csted_description); |
4624 | |
4625 Vcoding_system_type_list = Qnil; | |
4626 staticpro (&Vcoding_system_type_list); | |
4627 | |
4628 /* Initialize to something reasonable ... */ | |
4629 for (i = 0; i < MAX_DETECTOR_CATEGORIES; i++) | |
4630 { | |
4631 coding_category_system[i] = Qnil; | |
1204 | 4632 dump_add_root_lisp_object (&coding_category_system[i]); |
771 | 4633 coding_category_by_priority[i] = i; |
4634 } | |
4635 | |
4636 dump_add_opaque (coding_category_by_priority, | |
4637 sizeof (coding_category_by_priority)); | |
4638 | |
4639 all_coding_detectors = Dynarr_new2 (detector_dynarr, struct detector); | |
2367 | 4640 dump_add_root_block_ptr (&all_coding_detectors, |
771 | 4641 &detector_dynarr_description); |
4642 | |
4643 dump_add_opaque_int (&coding_system_tick); | |
4644 dump_add_opaque_int (&coding_detector_count); | |
4645 dump_add_opaque_int (&coding_detector_category_count); | |
4646 | |
4647 INITIALIZE_CODING_SYSTEM_TYPE (no_conversion, | |
4648 "no-conversion-coding-system-p"); | |
4649 CODING_SYSTEM_HAS_METHOD (no_conversion, convert); | |
4650 | |
4651 INITIALIZE_DETECTOR (no_conversion); | |
4652 DETECTOR_HAS_METHOD (no_conversion, detect); | |
4653 INITIALIZE_DETECTOR_CATEGORY (no_conversion, no_conversion); | |
4654 | |
4655 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (convert_eol, | |
4656 "convert-eol-coding-system-p"); | |
4657 CODING_SYSTEM_HAS_METHOD (convert_eol, print); | |
4658 CODING_SYSTEM_HAS_METHOD (convert_eol, convert); | |
4659 CODING_SYSTEM_HAS_METHOD (convert_eol, getprop); | |
4660 CODING_SYSTEM_HAS_METHOD (convert_eol, putprop); | |
4661 CODING_SYSTEM_HAS_METHOD (convert_eol, conversion_end_type); | |
4662 CODING_SYSTEM_HAS_METHOD (convert_eol, canonicalize_after_coding); | |
4663 CODING_SYSTEM_HAS_METHOD (convert_eol, init_coding_stream); | |
4664 | |
4665 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (undecided, | |
4666 "undecided-coding-system-p"); | |
4667 CODING_SYSTEM_HAS_METHOD (undecided, init); | |
4668 CODING_SYSTEM_HAS_METHOD (undecided, mark); | |
4669 CODING_SYSTEM_HAS_METHOD (undecided, print); | |
4670 CODING_SYSTEM_HAS_METHOD (undecided, convert); | |
4671 CODING_SYSTEM_HAS_METHOD (undecided, putprop); | |
4672 CODING_SYSTEM_HAS_METHOD (undecided, getprop); | |
4673 CODING_SYSTEM_HAS_METHOD (undecided, init_coding_stream); | |
4674 CODING_SYSTEM_HAS_METHOD (undecided, rewind_coding_stream); | |
4675 CODING_SYSTEM_HAS_METHOD (undecided, finalize_coding_stream); | |
4676 CODING_SYSTEM_HAS_METHOD (undecided, mark_coding_stream); | |
4677 CODING_SYSTEM_HAS_METHOD (undecided, canonicalize); | |
4678 CODING_SYSTEM_HAS_METHOD (undecided, canonicalize_after_coding); | |
4679 | |
4680 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (chain, "chain-coding-system-p"); | |
4681 | |
4682 CODING_SYSTEM_HAS_METHOD (chain, print); | |
4683 CODING_SYSTEM_HAS_METHOD (chain, canonicalize); | |
4684 CODING_SYSTEM_HAS_METHOD (chain, init); | |
4685 CODING_SYSTEM_HAS_METHOD (chain, mark); | |
4686 CODING_SYSTEM_HAS_METHOD (chain, mark_coding_stream); | |
4687 CODING_SYSTEM_HAS_METHOD (chain, convert); | |
4688 CODING_SYSTEM_HAS_METHOD (chain, rewind_coding_stream); | |
4689 CODING_SYSTEM_HAS_METHOD (chain, finalize_coding_stream); | |
4690 CODING_SYSTEM_HAS_METHOD (chain, finalize); | |
4691 CODING_SYSTEM_HAS_METHOD (chain, putprop); | |
4692 CODING_SYSTEM_HAS_METHOD (chain, getprop); | |
4693 CODING_SYSTEM_HAS_METHOD (chain, conversion_end_type); | |
4694 CODING_SYSTEM_HAS_METHOD (chain, canonicalize_after_coding); | |
4695 | |
4696 #ifdef DEBUG_XEMACS | |
4697 INITIALIZE_CODING_SYSTEM_TYPE (internal, "internal-coding-system-p"); | |
4698 CODING_SYSTEM_HAS_METHOD (internal, convert); | |
4699 #endif | |
4700 | |
4701 #ifdef HAVE_ZLIB | |
4702 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (gzip, "gzip-coding-system-p"); | |
4703 CODING_SYSTEM_HAS_METHOD (gzip, conversion_end_type); | |
4704 CODING_SYSTEM_HAS_METHOD (gzip, convert); | |
4705 CODING_SYSTEM_HAS_METHOD (gzip, init); | |
4706 CODING_SYSTEM_HAS_METHOD (gzip, print); | |
4707 CODING_SYSTEM_HAS_METHOD (gzip, init_coding_stream); | |
4708 CODING_SYSTEM_HAS_METHOD (gzip, rewind_coding_stream); | |
4709 CODING_SYSTEM_HAS_METHOD (gzip, putprop); | |
4710 CODING_SYSTEM_HAS_METHOD (gzip, getprop); | |
4711 #endif | |
4712 } | |
4713 | |
4714 void | |
4715 reinit_coding_system_type_create (void) | |
4716 { | |
4717 REINITIALIZE_CODING_SYSTEM_TYPE (no_conversion); | |
4718 REINITIALIZE_CODING_SYSTEM_TYPE (convert_eol); | |
4719 REINITIALIZE_CODING_SYSTEM_TYPE (undecided); | |
4720 REINITIALIZE_CODING_SYSTEM_TYPE (chain); | |
4721 #if 0 | |
4722 REINITIALIZE_CODING_SYSTEM_TYPE (text_file_wrapper); | |
4723 #endif /* 0 */ | |
4724 #ifdef DEBUG_XEMACS | |
4725 REINITIALIZE_CODING_SYSTEM_TYPE (internal); | |
4726 #endif | |
4727 #ifdef HAVE_ZLIB | |
4728 REINITIALIZE_CODING_SYSTEM_TYPE (gzip); | |
4729 #endif | |
4730 } | |
4731 | |
4732 void | |
4733 reinit_vars_of_file_coding (void) | |
4734 { | |
428 | 4735 } |
4736 | |
4737 void | |
4738 vars_of_file_coding (void) | |
4739 { | |
771 | 4740 /* We always have file-coding support */ |
428 | 4741 Fprovide (intern ("file-coding")); |
4742 | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4743 QScoding_system_cookie = build_ascstring (";;;###coding system: "); |
1347 | 4744 staticpro (&QScoding_system_cookie); |
4745 | |
1242 | 4746 #ifdef HAVE_DEFAULT_EOL_DETECTION |
2297 | 4747 /* #### Find a more appropriate place for this comment. |
4748 WARNING: The existing categories are intimately tied to the function | |
1242 | 4749 `coding-system-category' in coding.el. If you change a category, or |
4750 change the layout of any coding system associated with a category, you | |
4751 need to check that function and make sure it's written properly. */ | |
4752 | |
4753 Fprovide (intern ("unix-default-eol-detection")); | |
4754 #endif | |
4755 | |
428 | 4756 DEFVAR_LISP ("keyboard-coding-system", &Vkeyboard_coding_system /* |
3142 | 4757 Default coding system used for TTY and X11 keyboard input. |
4758 Under X11, used only to interpet the character for a key event when that | |
4759 event has a KeySym of NoSymbol but does have an associated string keysym, | |
4760 something that's seen with input methods. | |
4761 | |
4762 If you need to set these things to different coding systems, call the | |
4763 function `set-console-tty-coding-system' for the TTY and use this variable | |
4764 for X11. | |
428 | 4765 */ ); |
4766 Vkeyboard_coding_system = Qnil; | |
4767 | |
4768 DEFVAR_LISP ("terminal-coding-system", &Vterminal_coding_system /* | |
4769 Coding system used for TTY display output. | |
4770 Not used under a windowing system. | |
4771 */ ); | |
4772 Vterminal_coding_system = Qnil; | |
4773 | |
4774 DEFVAR_LISP ("coding-system-for-read", &Vcoding_system_for_read /* | |
440 | 4775 Overriding coding system used when reading from a file or process. |
4776 You should bind this variable with `let', but do not set it globally. | |
4777 If this is non-nil, it specifies the coding system that will be used | |
4778 to decode input on read operations, such as from a file or process. | |
4779 It overrides `buffer-file-coding-system-for-read', | |
428 | 4780 `insert-file-contents-pre-hook', etc. Use those variables instead of |
440 | 4781 this one for permanent changes to the environment. */ ); |
428 | 4782 Vcoding_system_for_read = Qnil; |
4783 | |
4784 DEFVAR_LISP ("coding-system-for-write", | |
4785 &Vcoding_system_for_write /* | |
440 | 4786 Overriding coding system used when writing to a file or process. |
4787 You should bind this variable with `let', but do not set it globally. | |
4788 If this is non-nil, it specifies the coding system that will be used | |
4789 to encode output for write operations, such as to a file or process. | |
4790 It overrides `buffer-file-coding-system', `write-region-pre-hook', etc. | |
4791 Use those variables instead of this one for permanent changes to the | |
4792 environment. */ ); | |
428 | 4793 Vcoding_system_for_write = Qnil; |
4794 | |
4795 DEFVAR_LISP ("file-name-coding-system", &Vfile_name_coding_system /* | |
4796 Coding system used to convert pathnames when accessing files. | |
4797 */ ); | |
4798 Vfile_name_coding_system = Qnil; | |
4799 | |
4800 DEFVAR_BOOL ("enable-multibyte-characters", &enable_multibyte_characters /* | |
771 | 4801 Setting this has no effect. It is purely for FSF compatibility. |
428 | 4802 */ ); |
4803 enable_multibyte_characters = 1; | |
771 | 4804 |
4805 Vchain_canonicalize_hash_table = | |
4806 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL); | |
4807 staticpro (&Vchain_canonicalize_hash_table); | |
4808 | |
4809 #ifdef DEBUG_XEMACS | |
4810 DEFVAR_LISP ("debug-coding-detection", &Vdebug_coding_detection /* | |
4811 If non-nil, display debug information about detection operations in progress. | |
4812 Information is displayed on stderr. | |
4813 */ ); | |
4814 Vdebug_coding_detection = Qnil; | |
4815 #endif | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4816 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4817 #ifdef MULE |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4818 Vdefault_query_coding_region_chartab_cache |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4819 = make_lisp_hash_table (25, HASH_TABLE_NON_WEAK, HASH_TABLE_EQUAL); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4820 staticpro (&Vdefault_query_coding_region_chartab_cache); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4821 #endif |
428 | 4822 } |
4823 | |
2297 | 4824 /* #### reformat this for consistent appearance? */ |
4825 | |
428 | 4826 void |
4827 complex_vars_of_file_coding (void) | |
4828 { | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4829 Fmake_coding_system_internal |
771 | 4830 (Qconvert_eol_cr, Qconvert_eol, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4831 build_defer_string ("Convert CR to LF"), |
771 | 4832 nconc2 (list6 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4833 build_defer_string ( |
771 | 4834 "Converts CR (used to mark the end of a line on Macintosh systems) to LF\n" |
4835 "(used internally and under Unix to mark the end of a line)."), | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4836 Qmnemonic, build_ascstring ("CR->LF"), |
771 | 4837 Qsubtype, Qcr), |
4838 /* VERY IMPORTANT! Tell make-coding-system not to generate | |
4839 subsidiaries -- it needs the coding systems we're creating | |
4840 to do so! */ | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4841 list4 (Qeol_type, Qlf, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4842 Qsafe_charsets, Qt))); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4843 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4844 Fmake_coding_system_internal |
771 | 4845 (Qconvert_eol_lf, Qconvert_eol, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4846 build_defer_string ("Convert LF to LF (do nothing)"), |
771 | 4847 nconc2 (list6 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4848 build_defer_string ( |
771 | 4849 "Do nothing."), |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4850 Qmnemonic, build_ascstring ("LF->LF"), |
771 | 4851 Qsubtype, Qlf), |
4852 /* VERY IMPORTANT! Tell make-coding-system not to generate | |
4853 subsidiaries -- it needs the coding systems we're creating | |
4854 to do so! */ | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4855 list4 (Qeol_type, Qlf, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4856 Qsafe_charsets, Qt))); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4857 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4858 Fmake_coding_system_internal |
771 | 4859 (Qconvert_eol_crlf, Qconvert_eol, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4860 build_defer_string ("Convert CRLF to LF"), |
771 | 4861 nconc2 (list6 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4862 build_defer_string ( |
771 | 4863 "Converts CR+LF (used to mark the end of a line on Macintosh systems) to LF\n" |
4864 "(used internally and under Unix to mark the end of a line)."), | |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4865 Qmnemonic, build_ascstring ("CRLF->LF"), |
771 | 4866 Qsubtype, Qcrlf), |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4867 |
771 | 4868 /* VERY IMPORTANT! Tell make-coding-system not to generate |
4869 subsidiaries -- it needs the coding systems we're creating | |
4870 to do so! */ | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4871 list4 (Qeol_type, Qlf, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4872 Qsafe_charsets, Qt))); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4873 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4874 Fmake_coding_system_internal |
771 | 4875 (Qconvert_eol_autodetect, Qconvert_eol, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4876 build_defer_string ("Autodetect EOL type"), |
771 | 4877 nconc2 (list6 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4878 build_defer_string ( |
771 | 4879 "Autodetect the end-of-line type."), |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4880 Qmnemonic, build_ascstring ("Auto-EOL"), |
793 | 4881 Qsubtype, Qnil), |
771 | 4882 /* VERY IMPORTANT! Tell make-coding-system not to generate |
4883 subsidiaries -- it needs the coding systems we're creating | |
4884 to do so! */ | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4885 list4 (Qeol_type, Qlf, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4886 Qsafe_charsets, Qt))); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4887 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4888 Fmake_coding_system_internal |
771 | 4889 (Qundecided, Qundecided, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4890 build_defer_string ("Undecided (auto-detect)"), |
771 | 4891 nconc2 (list4 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4892 build_defer_string |
771 | 4893 ("Automatically detects the correct encoding."), |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4894 Qmnemonic, build_ascstring ("Auto")), |
771 | 4895 list6 (Qdo_eol, Qt, Qdo_coding, Qt, |
4896 /* We do EOL detection ourselves so we don't need to be | |
4897 wrapped in an EOL detector. (It doesn't actually hurt, | |
4898 though, I don't think.) */ | |
4899 Qeol_type, Qlf))); | |
4900 | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4901 Fmake_coding_system_internal |
771 | 4902 (intern ("undecided-dos"), Qundecided, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4903 build_defer_string ("Undecided (auto-detect) (CRLF)"), |
771 | 4904 nconc2 (list4 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4905 build_defer_string |
771 | 4906 ("Automatically detects the correct encoding; EOL type of CRLF forced."), |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4907 Qmnemonic, build_ascstring ("Auto")), |
771 | 4908 list4 (Qdo_coding, Qt, |
4909 Qeol_type, Qcrlf))); | |
4910 | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4911 Fmake_coding_system_internal |
771 | 4912 (intern ("undecided-unix"), Qundecided, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4913 build_defer_string ("Undecided (auto-detect) (LF)"), |
771 | 4914 nconc2 (list4 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4915 build_defer_string |
771 | 4916 ("Automatically detects the correct encoding; EOL type of LF forced."), |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4917 Qmnemonic, build_ascstring ("Auto")), |
771 | 4918 list4 (Qdo_coding, Qt, |
4919 Qeol_type, Qlf))); | |
4920 | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4921 Fmake_coding_system_internal |
771 | 4922 (intern ("undecided-mac"), Qundecided, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4923 build_defer_string ("Undecided (auto-detect) (CR)"), |
771 | 4924 nconc2 (list4 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4925 build_defer_string |
771 | 4926 ("Automatically detects the correct encoding; EOL type of CR forced."), |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4927 Qmnemonic, build_ascstring ("Auto")), |
771 | 4928 list4 (Qdo_coding, Qt, |
4929 Qeol_type, Qcr))); | |
4930 | |
428 | 4931 /* Need to create this here or we're really screwed. */ |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4932 Fmake_coding_system_internal |
428 | 4933 (Qraw_text, Qno_conversion, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4934 build_defer_string ("Raw Text"), |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4935 nconc2 (list4 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4936 build_defer_string ("Raw text converts only line-break " |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4937 "codes, and acts otherwise like " |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4938 "`binary'."), |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4939 Qmnemonic, build_ascstring ("Raw")), |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4940 #ifdef MULE |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4941 list2 (Qsafe_charsets, list3 (Vcharset_ascii, Vcharset_control_1, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4942 Vcharset_latin_iso8859_1)))); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4943 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4944 #else |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4945 Qnil)); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4946 #endif |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4947 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4948 Fmake_coding_system_internal |
428 | 4949 (Qbinary, Qno_conversion, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4950 build_defer_string ("Binary"), |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4951 nconc2 (list6 (Qdocumentation, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4952 build_defer_string ( |
771 | 4953 "This coding system is as close as it comes to doing no conversion.\n" |
4954 "On input, each byte is converted directly into the character\n" | |
4955 "with the corresponding code -- i.e. from the `ascii', `control-1',\n" | |
4956 "or `latin-1' character sets. On output, these characters are\n" | |
4957 "converted back to the corresponding bytes, and other characters\n" | |
4958 "are converted to the default character, i.e. `~'."), | |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4959 Qeol_type, Qlf, |
4952
19a72041c5ed
Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents:
4846
diff
changeset
|
4960 Qmnemonic, build_ascstring ("Binary")), |
4690
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4961 #ifdef MULE |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4962 list2 (Qsafe_charsets, list3 (Vcharset_ascii, Vcharset_control_1, |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4963 Vcharset_latin_iso8859_1)))); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4964 |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4965 #else |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4966 Qnil)); |
257b468bf2ca
Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents:
4647
diff
changeset
|
4967 #endif |
428 | 4968 |
771 | 4969 /* Formerly aliased to raw-text! Completely bogus and not even the same |
4970 as FSF Emacs. */ | |
4971 Fdefine_coding_system_alias (Qno_conversion, Qbinary); | |
4972 Fdefine_coding_system_alias (intern ("no-conversion-unix"), | |
4973 intern ("raw-text-unix")); | |
4974 Fdefine_coding_system_alias (intern ("no-conversion-dos"), | |
4975 intern ("raw-text-dos")); | |
4976 Fdefine_coding_system_alias (intern ("no-conversion-mac"), | |
4977 intern ("raw-text-mac")); | |
4978 | |
1318 | 4979 /* These three below will get their defaults set correctly |
4980 in code-init.el. We init them now so we can handle stuff at dump | |
771 | 4981 time before we get to code-init.el. */ |
1318 | 4982 Fdefine_coding_system_alias (Qnative, Qbinary); |
440 | 4983 Fdefine_coding_system_alias (Qterminal, Qbinary); |
4984 Fdefine_coding_system_alias (Qkeyboard, Qbinary); | |
4985 | |
1318 | 4986 Fdefine_coding_system_alias (Qfile_name, Qnative); |
771 | 4987 Fdefine_coding_system_alias (Qidentity, Qconvert_eol_lf); |
4988 | |
428 | 4989 /* Need this for bootstrapping */ |
771 | 4990 coding_category_system[detector_category_no_conversion] = |
428 | 4991 Fget_coding_system (Qraw_text); |
4992 } |