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