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