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