annotate src/file-coding.c @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents a86b2b5e0111
children b8cc9ab3f761
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1 /* Code conversion functions.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2 Copyright (C) 1991, 1995 Free Software Foundation, Inc.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5 This file is part of XEmacs.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
6
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
10 later version.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
11
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
15 for more details.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
16
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
21
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
22 /* Synched up with: Mule 2.3. Not in FSF. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
23
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 272
diff changeset
24 /* Rewritten by Ben Wing <ben@xemacs.org>. */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
25
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
26 #include <config.h>
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
27 #include "lisp.h"
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
28
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
29 #include "buffer.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
30 #include "elhash.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
31 #include "insdel.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
32 #include "lstream.h"
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
33 #include "opaque.h"
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
34 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
35 #include "mule-ccl.h"
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
36 #include "chartab.h"
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
37 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
38 #include "file-coding.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
39
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
40 Lisp_Object Qcoding_system_error;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
41
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
42 Lisp_Object Vkeyboard_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
43 Lisp_Object Vterminal_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
44 Lisp_Object Vcoding_system_for_read;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
45 Lisp_Object Vcoding_system_for_write;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
46 Lisp_Object Vfile_name_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
47
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
48 /* Table of symbols identifying each coding category. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
49 Lisp_Object coding_category_symbol[CODING_CATEGORY_LAST + 1];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
50
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
51
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
52
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
53 struct file_coding_dump {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
54 /* Coding system currently associated with each coding category. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
55 Lisp_Object coding_category_system[CODING_CATEGORY_LAST + 1];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
56
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
57 /* Table of all coding categories in decreasing order of priority.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
58 This describes a permutation of the possible coding categories. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
59 int coding_category_by_priority[CODING_CATEGORY_LAST + 1];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
60
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
61 #ifdef MULE
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
62 Lisp_Object ucs_to_mule_table[65536];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
63 #endif
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
64 } *fcd;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
65
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
66 static const struct lrecord_description fcd_description_1[] = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
67 { XD_LISP_OBJECT_ARRAY, offsetof (struct file_coding_dump, coding_category_system), CODING_CATEGORY_LAST + 1 },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
68 #ifdef MULE
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
69 { XD_LISP_OBJECT_ARRAY, offsetof (struct file_coding_dump, ucs_to_mule_table), 65536 },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
70 #endif
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
71 { XD_END }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
72 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
73
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
74 static const struct struct_description fcd_description = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
75 sizeof (struct file_coding_dump),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
76 fcd_description_1
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
77 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
78
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
79 Lisp_Object mule_to_ucs_table;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
80
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
81 Lisp_Object Qcoding_systemp;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
82
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
83 Lisp_Object Qraw_text, Qno_conversion, Qccl, Qiso2022;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
84 /* Qinternal in general.c */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
85
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
86 Lisp_Object Qmnemonic, Qeol_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
87 Lisp_Object Qcr, Qcrlf, Qlf;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
88 Lisp_Object Qeol_cr, Qeol_crlf, Qeol_lf;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
89 Lisp_Object Qpost_read_conversion;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
90 Lisp_Object Qpre_write_conversion;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
91
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
92 #ifdef MULE
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
93 Lisp_Object Qucs4, Qutf8;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
94 Lisp_Object Qbig5, Qshift_jis;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
95 Lisp_Object Qcharset_g0, Qcharset_g1, Qcharset_g2, Qcharset_g3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
96 Lisp_Object Qforce_g0_on_output, Qforce_g1_on_output;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
97 Lisp_Object Qforce_g2_on_output, Qforce_g3_on_output;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
98 Lisp_Object Qno_iso6429;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
99 Lisp_Object Qinput_charset_conversion, Qoutput_charset_conversion;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
100 Lisp_Object Qescape_quoted;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
101 Lisp_Object Qshort, Qno_ascii_eol, Qno_ascii_cntl, Qseven, Qlock_shift;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
102 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
103 Lisp_Object Qencode, Qdecode;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
104
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
105 Lisp_Object Vcoding_system_hash_table;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
106
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
107 int enable_multibyte_characters;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
108
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
109 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
110 /* Additional information used by the ISO2022 decoder and detector. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
111 struct iso2022_decoder
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
112 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
113 /* CHARSET holds the character sets currently assigned to the G0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
114 through G3 variables. It is initialized from the array
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
115 INITIAL_CHARSET in CODESYS. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
116 Lisp_Object charset[4];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
117
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
118 /* Which registers are currently invoked into the left (GL) and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
119 right (GR) halves of the 8-bit encoding space? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
120 int register_left, register_right;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
121
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
122 /* ISO_ESC holds a value indicating part of an escape sequence
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
123 that has already been seen. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
124 enum iso_esc_flag esc;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
125
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
126 /* This records the bytes we've seen so far in an escape sequence,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
127 in case the sequence is invalid (we spit out the bytes unchanged). */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
128 unsigned char esc_bytes[8];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
129
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
130 /* Index for next byte to store in ISO escape sequence. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
131 int esc_bytes_index;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
132
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
133 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
134 /* Stuff seen so far when composing a string. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
135 unsigned_char_dynarr *composite_chars;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
136 #endif
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
137
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
138 /* If we saw an invalid designation sequence for a particular
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
139 register, we flag it here and switch to ASCII. The next time we
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
140 see a valid designation for this register, we turn off the flag
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
141 and do the designation normally, but pretend the sequence was
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
142 invalid. The effect of all this is that (most of the time) the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
143 escape sequences for both the switch to the unknown charset, and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
144 the switch back to the known charset, get inserted literally into
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
145 the buffer and saved out as such. The hope is that we can
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
146 preserve the escape sequences so that the resulting written out
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
147 file makes sense. If we don't do any of this, the designation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
148 to the invalid charset will be preserved but that switch back
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
149 to the known charset will probably get eaten because it was
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
150 the same charset that was already present in the register. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
151 unsigned char invalid_designated[4];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
152
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
153 /* We try to do similar things as above for direction-switching
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
154 sequences. If we encountered a direction switch while an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
155 invalid designation was present, or an invalid designation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
156 just after a direction switch (i.e. no valid designation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
157 encountered yet), we insert the direction-switch escape
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
158 sequence literally into the output stream, and later on
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
159 insert the corresponding direction-restoring escape sequence
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
160 literally also. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
161 unsigned int switched_dir_and_no_valid_charset_yet :1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
162 unsigned int invalid_switch_dir :1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
163
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
164 /* Tells the decoder to output the escape sequence literally
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
165 even though it was valid. Used in the games we play to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
166 avoid lossage when we encounter invalid designations. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
167 unsigned int output_literally :1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
168 /* We encountered a direction switch followed by an invalid
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
169 designation. We didn't output the direction switch
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
170 literally because we didn't know about the invalid designation;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
171 but we have to do so now. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
172 unsigned int output_direction_sequence :1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
173 };
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
174 #endif /* MULE */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
175 EXFUN (Fcopy_coding_system, 2);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
176 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
177 struct detection_state;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
178 static int detect_coding_sjis (struct detection_state *st,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
179 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
180 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
181 static void decode_coding_sjis (Lstream *decoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
182 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
183 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
184 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
185 static void encode_coding_sjis (Lstream *encoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
186 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
187 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
188 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
189 static int detect_coding_big5 (struct detection_state *st,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
190 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
191 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
192 static void decode_coding_big5 (Lstream *decoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
193 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
194 unsigned_char_dynarr *dst, unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
195 static void encode_coding_big5 (Lstream *encoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
196 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
197 unsigned_char_dynarr *dst, unsigned int n);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
198 static int detect_coding_ucs4 (struct detection_state *st,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
199 const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
200 unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
201 static void decode_coding_ucs4 (Lstream *decoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
202 const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
203 unsigned_char_dynarr *dst, unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
204 static void encode_coding_ucs4 (Lstream *encoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
205 const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
206 unsigned_char_dynarr *dst, unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
207 static int detect_coding_utf8 (struct detection_state *st,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
208 const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
209 unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
210 static void decode_coding_utf8 (Lstream *decoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
211 const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
212 unsigned_char_dynarr *dst, unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
213 static void encode_coding_utf8 (Lstream *encoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
214 const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
215 unsigned_char_dynarr *dst, unsigned int n);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
216 static int postprocess_iso2022_mask (int mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
217 static void reset_iso2022 (Lisp_Object coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
218 struct iso2022_decoder *iso);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
219 static int detect_coding_iso2022 (struct detection_state *st,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
220 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
221 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
222 static void decode_coding_iso2022 (Lstream *decoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
223 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
224 unsigned_char_dynarr *dst, unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
225 static void encode_coding_iso2022 (Lstream *encoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
226 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
227 unsigned_char_dynarr *dst, unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
228 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
229 static void decode_coding_no_conversion (Lstream *decoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
230 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
231 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
232 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
233 static void encode_coding_no_conversion (Lstream *encoding,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
234 const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
235 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
236 unsigned int n);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
237 static void mule_decode (Lstream *decoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
238 unsigned_char_dynarr *dst, unsigned int n);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
239 static void mule_encode (Lstream *encoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
240 unsigned_char_dynarr *dst, unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
241
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
242 typedef struct codesys_prop codesys_prop;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
243 struct codesys_prop
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
244 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
245 Lisp_Object sym;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
246 int prop_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
247 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
248
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
249 typedef struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
250 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
251 Dynarr_declare (codesys_prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
252 } codesys_prop_dynarr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
253
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
254 static const struct lrecord_description codesys_prop_description_1[] = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
255 { XD_LISP_OBJECT, offsetof (codesys_prop, sym) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
256 { XD_END }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
257 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
258
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
259 static const struct struct_description codesys_prop_description = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
260 sizeof (codesys_prop),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
261 codesys_prop_description_1
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
262 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
263
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
264 static const struct lrecord_description codesys_prop_dynarr_description_1[] = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
265 XD_DYNARR_DESC (codesys_prop_dynarr, &codesys_prop_description),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
266 { XD_END }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
267 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
268
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
269 static const struct struct_description codesys_prop_dynarr_description = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
270 sizeof (codesys_prop_dynarr),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
271 codesys_prop_dynarr_description_1
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
272 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
273
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
274 codesys_prop_dynarr *the_codesys_prop_dynarr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
275
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
276 enum codesys_prop_enum
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
277 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
278 CODESYS_PROP_ALL_OK,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
279 CODESYS_PROP_ISO2022,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
280 CODESYS_PROP_CCL
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
281 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
282
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
283
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
284 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
285 /* Coding system functions */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
286 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
287
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
288 static Lisp_Object mark_coding_system (Lisp_Object);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
289 static void print_coding_system (Lisp_Object, Lisp_Object, int);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
290 static void finalize_coding_system (void *header, int for_disksave);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
291
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
292 #ifdef MULE
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
293 static const struct lrecord_description ccs_description_1[] = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
294 { XD_LISP_OBJECT, offsetof (charset_conversion_spec, from_charset) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
295 { XD_LISP_OBJECT, offsetof (charset_conversion_spec, to_charset) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
296 { XD_END }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
297 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
298
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
299 static const struct struct_description ccs_description = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
300 sizeof (charset_conversion_spec),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
301 ccs_description_1
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
302 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
303
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
304 static const struct lrecord_description ccsd_description_1[] = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
305 XD_DYNARR_DESC (charset_conversion_spec_dynarr, &ccs_description),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
306 { XD_END }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
307 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
308
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
309 static const struct struct_description ccsd_description = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
310 sizeof (charset_conversion_spec_dynarr),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
311 ccsd_description_1
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
312 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
313 #endif
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
314
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
315 static const struct lrecord_description coding_system_description[] = {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
316 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, name) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
317 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, doc_string) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
318 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, mnemonic) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
319 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, post_read_conversion) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
320 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, pre_write_conversion) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
321 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, eol_lf) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
322 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, eol_crlf) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
323 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, eol_cr) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
324 #ifdef MULE
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
325 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Coding_System, iso2022.initial_charset), 4 },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
326 { XD_STRUCT_PTR, offsetof (Lisp_Coding_System, iso2022.input_conv), 1, &ccsd_description },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
327 { XD_STRUCT_PTR, offsetof (Lisp_Coding_System, iso2022.output_conv), 1, &ccsd_description },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
328 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, ccl.decode) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
329 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, ccl.encode) },
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
330 #endif
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
331 { XD_END }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
332 };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
333
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
334 DEFINE_LRECORD_IMPLEMENTATION ("coding-system", coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
335 mark_coding_system, print_coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
336 finalize_coding_system,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
337 0, 0, coding_system_description,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
338 Lisp_Coding_System);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
339
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
340 static Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
341 mark_coding_system (Lisp_Object obj)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
342 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
343 Lisp_Coding_System *codesys = XCODING_SYSTEM (obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
344
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
345 mark_object (CODING_SYSTEM_NAME (codesys));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
346 mark_object (CODING_SYSTEM_DOC_STRING (codesys));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
347 mark_object (CODING_SYSTEM_MNEMONIC (codesys));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
348 mark_object (CODING_SYSTEM_EOL_LF (codesys));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
349 mark_object (CODING_SYSTEM_EOL_CRLF (codesys));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
350 mark_object (CODING_SYSTEM_EOL_CR (codesys));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
351
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
352 switch (CODING_SYSTEM_TYPE (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
353 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
354 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
355 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
356 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
357 for (i = 0; i < 4; i++)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
358 mark_object (CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
359 if (codesys->iso2022.input_conv)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
360 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
361 for (i = 0; i < Dynarr_length (codesys->iso2022.input_conv); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
362 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
363 struct charset_conversion_spec *ccs =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
364 Dynarr_atp (codesys->iso2022.input_conv, i);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
365 mark_object (ccs->from_charset);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
366 mark_object (ccs->to_charset);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
367 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
368 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
369 if (codesys->iso2022.output_conv)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
370 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
371 for (i = 0; i < Dynarr_length (codesys->iso2022.output_conv); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
372 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
373 struct charset_conversion_spec *ccs =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
374 Dynarr_atp (codesys->iso2022.output_conv, i);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
375 mark_object (ccs->from_charset);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
376 mark_object (ccs->to_charset);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
377 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
378 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
379 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
380
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
381 case CODESYS_CCL:
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
382 mark_object (CODING_SYSTEM_CCL_DECODE (codesys));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
383 mark_object (CODING_SYSTEM_CCL_ENCODE (codesys));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
384 break;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
385 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
386 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
387 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
388 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
389
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
390 mark_object (CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
391 return CODING_SYSTEM_POST_READ_CONVERSION (codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
392 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
393
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
394 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
395 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
396 int escapeflag)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
397 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
398 Lisp_Coding_System *c = XCODING_SYSTEM (obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
399 if (print_readably)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
400 error ("printing unreadable object #<coding_system 0x%x>",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
401 c->header.uid);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
402
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
403 write_c_string ("#<coding_system ", printcharfun);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
404 print_internal (c->name, printcharfun, 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
405 write_c_string (">", printcharfun);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
406 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
407
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
408 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
409 finalize_coding_system (void *header, int for_disksave)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
410 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
411 Lisp_Coding_System *c = (Lisp_Coding_System *) header;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
412 /* Since coding systems never go away, this function is not
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
413 necessary. But it would be necessary if we changed things
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
414 so that coding systems could go away. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
415 if (!for_disksave) /* see comment in lstream.c */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
416 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
417 switch (CODING_SYSTEM_TYPE (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
418 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
419 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
420 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
421 if (c->iso2022.input_conv)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
422 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
423 Dynarr_free (c->iso2022.input_conv);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
424 c->iso2022.input_conv = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
425 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
426 if (c->iso2022.output_conv)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
427 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
428 Dynarr_free (c->iso2022.output_conv);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
429 c->iso2022.output_conv = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
430 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
431 break;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
432 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
433 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
434 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
435 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
436 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
437 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
438
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
439 static eol_type_t
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
440 symbol_to_eol_type (Lisp_Object symbol)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
441 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
442 CHECK_SYMBOL (symbol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
443 if (NILP (symbol)) return EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
444 if (EQ (symbol, Qlf)) return EOL_LF;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
445 if (EQ (symbol, Qcrlf)) return EOL_CRLF;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
446 if (EQ (symbol, Qcr)) return EOL_CR;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
447
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
448 signal_simple_error ("Unrecognized eol type", symbol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
449 return EOL_AUTODETECT; /* not reached */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
450 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
451
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
452 static Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
453 eol_type_to_symbol (eol_type_t type)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
454 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
455 switch (type)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
456 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
457 default: abort ();
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
458 case EOL_LF: return Qlf;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
459 case EOL_CRLF: return Qcrlf;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
460 case EOL_CR: return Qcr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
461 case EOL_AUTODETECT: return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
462 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
463 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
464
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
465 static void
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
466 setup_eol_coding_systems (Lisp_Coding_System *codesys)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
467 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
468 Lisp_Object codesys_obj;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
469 int len = string_length (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
470 char *codesys_name = (char *) alloca (len + 7);
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
471 int mlen = -1;
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 263
diff changeset
472 char *codesys_mnemonic=0;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
473
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
474 Lisp_Object codesys_name_sym, sub_codesys_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
475
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
476 /* kludge */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
477
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
478 XSETCODING_SYSTEM (codesys_obj, codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
479
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
480 memcpy (codesys_name,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
481 string_data (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name), len);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
482
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
483 if (STRINGP (CODING_SYSTEM_MNEMONIC (codesys)))
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
484 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
485 mlen = XSTRING_LENGTH (CODING_SYSTEM_MNEMONIC (codesys));
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
486 codesys_mnemonic = (char *) alloca (mlen + 7);
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
487 memcpy (codesys_mnemonic,
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
488 XSTRING_DATA (CODING_SYSTEM_MNEMONIC (codesys)), mlen);
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
489 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
490
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
491 #define DEFINE_SUB_CODESYS(op_sys, op_sys_abbr, Type) do { \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
492 strcpy (codesys_name + len, "-" op_sys); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
493 if (mlen != -1) \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
494 strcpy (codesys_mnemonic + mlen, op_sys_abbr); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
495 codesys_name_sym = intern (codesys_name); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
496 sub_codesys_obj = Fcopy_coding_system (codesys_obj, codesys_name_sym); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
497 XCODING_SYSTEM_EOL_TYPE (sub_codesys_obj) = Type; \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
498 if (mlen != -1) \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
499 XCODING_SYSTEM_MNEMONIC(sub_codesys_obj) = \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
500 build_string (codesys_mnemonic); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
501 CODING_SYSTEM_##Type (codesys) = sub_codesys_obj; \
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
502 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
503
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
504 DEFINE_SUB_CODESYS("unix", "", EOL_LF);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
505 DEFINE_SUB_CODESYS("dos", ":T", EOL_CRLF);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
506 DEFINE_SUB_CODESYS("mac", ":t", EOL_CR);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
507 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
508
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
509 DEFUN ("coding-system-p", Fcoding_system_p, 1, 1, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
510 Return t if OBJECT is a coding system.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
511 A coding system is an object that defines how text containing multiple
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
512 character sets is encoded into a stream of (typically 8-bit) bytes.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
513 The coding system is used to decode the stream into a series of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
514 characters (which may be from multiple charsets) when the text is read
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
515 from a file or process, and is used to encode the text back into the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
516 same format when it is written out to a file or process.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
517
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
518 For example, many ISO2022-compliant coding systems (such as Compound
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
519 Text, which is used for inter-client data under the X Window System)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
520 use escape sequences to switch between different charsets -- Japanese
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
521 Kanji, for example, is invoked with "ESC $ ( B"; ASCII is invoked
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
522 with "ESC ( B"; and Cyrillic is invoked with "ESC - L". See
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
523 `make-coding-system' for more information.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
524
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
525 Coding systems are normally identified using a symbol, and the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
526 symbol is accepted in place of the actual coding system object whenever
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
527 a coding system is called for. (This is similar to how faces work.)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
528 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
529 (object))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
530 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
531 return CODING_SYSTEMP (object) ? Qt : Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
532 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
533
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
534 DEFUN ("find-coding-system", Ffind_coding_system, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
535 Retrieve the coding system of the given name.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
536
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
537 If CODING-SYSTEM-OR-NAME is a coding-system object, it is simply
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
538 returned. Otherwise, CODING-SYSTEM-OR-NAME should be a symbol.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
539 If there is no such coding system, nil is returned. Otherwise the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
540 associated coding system object is returned.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
541 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
542 (coding_system_or_name))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
543 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
544 if (NILP (coding_system_or_name))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
545 coding_system_or_name = Qbinary;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
546 else if (CODING_SYSTEMP (coding_system_or_name))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
547 return coding_system_or_name;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
548 else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
549 CHECK_SYMBOL (coding_system_or_name);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
550
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
551 while (1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
552 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
553 coding_system_or_name =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
554 Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
555
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
556 if (CODING_SYSTEMP (coding_system_or_name) || NILP (coding_system_or_name))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
557 return coding_system_or_name;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
558 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
559 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
560
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
561 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
562 Retrieve the coding system of the given name.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
563 Same as `find-coding-system' except that if there is no such
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
564 coding system, an error is signaled instead of returning nil.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
565 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
566 (name))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
567 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
568 Lisp_Object coding_system = Ffind_coding_system (name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
569
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
570 if (NILP (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
571 signal_simple_error ("No such coding system", name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
572 return coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
573 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
574
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
575 /* We store the coding systems in hash tables with the names as the key and the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
576 actual coding system object as the value. Occasionally we need to use them
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
577 in a list format. These routines provide us with that. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
578 struct coding_system_list_closure
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
579 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
580 Lisp_Object *coding_system_list;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
581 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
582
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
583 static int
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
584 add_coding_system_to_list_mapper (Lisp_Object key, Lisp_Object value,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
585 void *coding_system_list_closure)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
586 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
587 /* This function can GC */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
588 struct coding_system_list_closure *cscl =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
589 (struct coding_system_list_closure *) coding_system_list_closure;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
590 Lisp_Object *coding_system_list = cscl->coding_system_list;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
591
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
592 *coding_system_list = Fcons (key, *coding_system_list);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
593 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
594 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
595
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
596 DEFUN ("coding-system-list", Fcoding_system_list, 0, 0, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
597 Return a list of the names of all defined coding systems.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
598 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
599 ())
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
600 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
601 Lisp_Object coding_system_list = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
602 struct gcpro gcpro1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
603 struct coding_system_list_closure coding_system_list_closure;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
604
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
605 GCPRO1 (coding_system_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
606 coding_system_list_closure.coding_system_list = &coding_system_list;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
607 elisp_maphash (add_coding_system_to_list_mapper, Vcoding_system_hash_table,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
608 &coding_system_list_closure);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
609 UNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
610
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
611 return coding_system_list;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
612 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
613
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
614 DEFUN ("coding-system-name", Fcoding_system_name, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
615 Return the name of the given coding system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
616 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
617 (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
618 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
619 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
620 return XCODING_SYSTEM_NAME (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
621 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
622
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
623 static Lisp_Coding_System *
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
624 allocate_coding_system (enum coding_system_type type, Lisp_Object name)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
625 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
626 Lisp_Coding_System *codesys =
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
627 alloc_lcrecord_type (Lisp_Coding_System, &lrecord_coding_system);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
628
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
629 zero_lcrecord (codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
630 CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
631 CODING_SYSTEM_POST_READ_CONVERSION (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
632 CODING_SYSTEM_EOL_TYPE (codesys) = EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
633 CODING_SYSTEM_EOL_CRLF (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
634 CODING_SYSTEM_EOL_CR (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
635 CODING_SYSTEM_EOL_LF (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
636 CODING_SYSTEM_TYPE (codesys) = type;
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
637 CODING_SYSTEM_MNEMONIC (codesys) = Qnil;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
638 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
639 if (type == CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
640 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
641 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
642 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
643 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
644 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
645 else if (type == CODESYS_CCL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
646 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
647 CODING_SYSTEM_CCL_DECODE (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
648 CODING_SYSTEM_CCL_ENCODE (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
649 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
650 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
651 CODING_SYSTEM_NAME (codesys) = name;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
652
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
653 return codesys;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
654 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
655
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
656 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
657 /* Given a list of charset conversion specs as specified in a Lisp
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
658 program, parse it into STORE_HERE. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
659
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
660 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
661 parse_charset_conversion_specs (charset_conversion_spec_dynarr *store_here,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
662 Lisp_Object spec_list)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
663 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
664 Lisp_Object rest;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
665
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
666 EXTERNAL_LIST_LOOP (rest, spec_list)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
667 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
668 Lisp_Object car = XCAR (rest);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
669 Lisp_Object from, to;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
670 struct charset_conversion_spec spec;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
671
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
672 if (!CONSP (car) || !CONSP (XCDR (car)) || !NILP (XCDR (XCDR (car))))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
673 signal_simple_error ("Invalid charset conversion spec", car);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
674 from = Fget_charset (XCAR (car));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
675 to = Fget_charset (XCAR (XCDR (car)));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
676 if (XCHARSET_TYPE (from) != XCHARSET_TYPE (to))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
677 signal_simple_error_2
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
678 ("Attempted conversion between different charset types",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
679 from, to);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
680 spec.from_charset = from;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
681 spec.to_charset = to;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
682
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
683 Dynarr_add (store_here, spec);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
684 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
685 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
686
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
687 /* Given a dynarr LOAD_HERE of internally-stored charset conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
688 specs, return the equivalent as the Lisp programmer would see it.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
689
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
690 If LOAD_HERE is 0, return Qnil. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
691
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
692 static Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
693 unparse_charset_conversion_specs (charset_conversion_spec_dynarr *load_here)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
694 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
695 int i;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
696 Lisp_Object result;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
697
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
698 if (!load_here)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
699 return Qnil;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
700 for (i = 0, result = Qnil; i < Dynarr_length (load_here); i++)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
701 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
702 struct charset_conversion_spec *ccs = Dynarr_atp (load_here, i);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
703 result = Fcons (list2 (ccs->from_charset, ccs->to_charset), result);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
704 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
705
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
706 return Fnreverse (result);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
707 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
708
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
709 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
710
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
711 DEFUN ("make-coding-system", Fmake_coding_system, 2, 4, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
712 Register symbol NAME as a coding system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
713
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
714 TYPE describes the conversion method used and should be one of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
715
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
716 nil or 'undecided
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
717 Automatic conversion. XEmacs attempts to detect the coding system
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
718 used in the file.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
719 'no-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
720 No conversion. Use this for binary files and such. On output,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
721 graphic characters that are not in ASCII or Latin-1 will be
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
722 replaced by a ?. (For a no-conversion-encoded buffer, these
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
723 characters will only be present if you explicitly insert them.)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
724 'shift-jis
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
725 Shift-JIS (a Japanese encoding commonly used in PC operating systems).
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
726 'ucs-4
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
727 ISO 10646 UCS-4 encoding.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
728 'utf-8
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
729 ISO 10646 UTF-8 encoding.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
730 'iso2022
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
731 Any ISO2022-compliant encoding. Among other things, this includes
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
732 JIS (the Japanese encoding commonly used for e-mail), EUC (the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
733 standard Unix encoding for Japanese and other languages), and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
734 Compound Text (the encoding used in X11). You can specify more
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
735 specific information about the conversion with the FLAGS argument.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
736 'big5
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
737 Big5 (the encoding commonly used for Taiwanese).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
738 'ccl
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
739 The conversion is performed using a user-written pseudo-code
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
740 program. CCL (Code Conversion Language) is the name of this
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
741 pseudo-code.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
742 'internal
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
743 Write out or read in the raw contents of the memory representing
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
744 the buffer's text. This is primarily useful for debugging
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
745 purposes, and is only enabled when XEmacs has been compiled with
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
746 DEBUG_XEMACS defined (via the --debug configure option).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
747 WARNING: Reading in a file using 'internal conversion can result
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
748 in an internal inconsistency in the memory representing a
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
749 buffer's text, which will produce unpredictable results and may
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
750 cause XEmacs to crash. Under normal circumstances you should
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
751 never use 'internal conversion.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
752
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
753 DOC-STRING is a string describing the coding system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
754
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
755 PROPS is a property list, describing the specific nature of the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
756 character set. Recognized properties are:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
757
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
758 'mnemonic
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
759 String to be displayed in the modeline when this coding system is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
760 active.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
761
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
762 'eol-type
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
763 End-of-line conversion to be used. It should be one of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
764
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
765 nil
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
766 Automatically detect the end-of-line type (LF, CRLF,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
767 or CR). Also generate subsidiary coding systems named
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
768 `NAME-unix', `NAME-dos', and `NAME-mac', that are
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
769 identical to this coding system but have an EOL-TYPE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
770 value of 'lf, 'crlf, and 'cr, respectively.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
771 'lf
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
772 The end of a line is marked externally using ASCII LF.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
773 Since this is also the way that XEmacs represents an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
774 end-of-line internally, specifying this option results
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
775 in no end-of-line conversion. This is the standard
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
776 format for Unix text files.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
777 'crlf
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
778 The end of a line is marked externally using ASCII
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
779 CRLF. This is the standard format for MS-DOS text
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
780 files.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
781 'cr
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
782 The end of a line is marked externally using ASCII CR.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
783 This is the standard format for Macintosh text files.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
784 t
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
785 Automatically detect the end-of-line type but do not
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
786 generate subsidiary coding systems. (This value is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
787 converted to nil when stored internally, and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
788 `coding-system-property' will return nil.)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
789
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
790 'post-read-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
791 Function called after a file has been read in, to perform the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
792 decoding. Called with two arguments, BEG and END, denoting
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
793 a region of the current buffer to be decoded.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
794
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
795 'pre-write-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
796 Function called before a file is written out, to perform the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
797 encoding. Called with two arguments, BEG and END, denoting
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
798 a region of the current buffer to be encoded.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
799
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
800
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
801 The following additional properties are recognized if TYPE is 'iso2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
802
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
803 'charset-g0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
804 'charset-g1
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
805 'charset-g2
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
806 'charset-g3
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
807 The character set initially designated to the G0 - G3 registers.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
808 The value should be one of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
809
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
810 -- A charset object (designate that character set)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
811 -- nil (do not ever use this register)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
812 -- t (no character set is initially designated to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
813 the register, but may be later on; this automatically
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
814 sets the corresponding `force-g*-on-output' property)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
815
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
816 'force-g0-on-output
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
817 'force-g1-on-output
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
818 'force-g2-on-output
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
819 'force-g2-on-output
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
820 If non-nil, send an explicit designation sequence on output before
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
821 using the specified register.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
822
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
823 'short
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
824 If non-nil, use the short forms "ESC $ @", "ESC $ A", and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
825 "ESC $ B" on output in place of the full designation sequences
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
826 "ESC $ ( @", "ESC $ ( A", and "ESC $ ( B".
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
827
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
828 'no-ascii-eol
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
829 If non-nil, don't designate ASCII to G0 at each end of line on output.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
830 Setting this to non-nil also suppresses other state-resetting that
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
831 normally happens at the end of a line.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
832
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
833 'no-ascii-cntl
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
834 If non-nil, don't designate ASCII to G0 before control chars on output.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
835
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
836 'seven
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
837 If non-nil, use 7-bit environment on output. Otherwise, use 8-bit
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
838 environment.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
839
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
840 'lock-shift
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
841 If non-nil, use locking-shift (SO/SI) instead of single-shift
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
842 or designation by escape sequence.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
843
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
844 'no-iso6429
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
845 If non-nil, don't use ISO6429's direction specification.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
846
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
847 'escape-quoted
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
848 If non-nil, literal control characters that are the same as
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
849 the beginning of a recognized ISO2022 or ISO6429 escape sequence
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
850 (in particular, ESC (0x1B), SO (0x0E), SI (0x0F), SS2 (0x8E),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
851 SS3 (0x8F), and CSI (0x9B)) are "quoted" with an escape character
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
852 so that they can be properly distinguished from an escape sequence.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
853 (Note that doing this results in a non-portable encoding.) This
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
854 encoding flag is used for byte-compiled files. Note that ESC
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
855 is a good choice for a quoting character because there are no
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
856 escape sequences whose second byte is a character from the Control-0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
857 or Control-1 character sets; this is explicitly disallowed by the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
858 ISO2022 standard.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
859
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
860 'input-charset-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
861 A list of conversion specifications, specifying conversion of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
862 characters in one charset to another when decoding is performed.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
863 Each specification is a list of two elements: the source charset,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
864 and the destination charset.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
865
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
866 'output-charset-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
867 A list of conversion specifications, specifying conversion of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
868 characters in one charset to another when encoding is performed.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
869 The form of each specification is the same as for
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
870 'input-charset-conversion.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
871
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
872
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
873 The following additional properties are recognized (and required)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
874 if TYPE is 'ccl:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
875
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
876 'decode
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
877 CCL program used for decoding (converting to internal format).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
878
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
879 'encode
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
880 CCL program used for encoding (converting to external format).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
881 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
882 (name, type, doc_string, props))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
883 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
884 Lisp_Coding_System *codesys;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
885 Lisp_Object rest, key, value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
886 enum coding_system_type ty;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
887 int need_to_setup_eol_systems = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
888
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
889 /* Convert type to constant */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
890 if (NILP (type) || EQ (type, Qundecided))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
891 { ty = CODESYS_AUTODETECT; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
892 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
893 else if (EQ (type, Qshift_jis)) { ty = CODESYS_SHIFT_JIS; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
894 else if (EQ (type, Qiso2022)) { ty = CODESYS_ISO2022; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
895 else if (EQ (type, Qbig5)) { ty = CODESYS_BIG5; }
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
896 else if (EQ (type, Qucs4)) { ty = CODESYS_UCS4; }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
897 else if (EQ (type, Qutf8)) { ty = CODESYS_UTF8; }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
898 else if (EQ (type, Qccl)) { ty = CODESYS_CCL; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
899 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
900 else if (EQ (type, Qno_conversion)) { ty = CODESYS_NO_CONVERSION; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
901 #ifdef DEBUG_XEMACS
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
902 else if (EQ (type, Qinternal)) { ty = CODESYS_INTERNAL; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
903 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
904 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
905 signal_simple_error ("Invalid coding system type", type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
906
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
907 CHECK_SYMBOL (name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
908
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
909 codesys = allocate_coding_system (ty, name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
910
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
911 if (NILP (doc_string))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
912 doc_string = build_string ("");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
913 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
914 CHECK_STRING (doc_string);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
915 CODING_SYSTEM_DOC_STRING (codesys) = doc_string;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
916
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
917 EXTERNAL_PROPERTY_LIST_LOOP (rest, key, value, props)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
918 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
919 if (EQ (key, Qmnemonic))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
920 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
921 if (!NILP (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
922 CHECK_STRING (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
923 CODING_SYSTEM_MNEMONIC (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
924 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
925
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
926 else if (EQ (key, Qeol_type))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
927 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
928 need_to_setup_eol_systems = NILP (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
929 if (EQ (value, Qt))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
930 value = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
931 CODING_SYSTEM_EOL_TYPE (codesys) = symbol_to_eol_type (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
932 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
933
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
934 else if (EQ (key, Qpost_read_conversion)) CODING_SYSTEM_POST_READ_CONVERSION (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
935 else if (EQ (key, Qpre_write_conversion)) CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
936 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
937 else if (ty == CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
938 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
939 #define FROB_INITIAL_CHARSET(charset_num) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
940 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, charset_num) = \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
941 ((EQ (value, Qt) || EQ (value, Qnil)) ? value : Fget_charset (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
942
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
943 if (EQ (key, Qcharset_g0)) FROB_INITIAL_CHARSET (0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
944 else if (EQ (key, Qcharset_g1)) FROB_INITIAL_CHARSET (1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
945 else if (EQ (key, Qcharset_g2)) FROB_INITIAL_CHARSET (2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
946 else if (EQ (key, Qcharset_g3)) FROB_INITIAL_CHARSET (3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
947
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
948 #define FROB_FORCE_CHARSET(charset_num) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
949 CODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT (codesys, charset_num) = !NILP (value)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
950
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
951 else if (EQ (key, Qforce_g0_on_output)) FROB_FORCE_CHARSET (0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
952 else if (EQ (key, Qforce_g1_on_output)) FROB_FORCE_CHARSET (1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
953 else if (EQ (key, Qforce_g2_on_output)) FROB_FORCE_CHARSET (2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
954 else if (EQ (key, Qforce_g3_on_output)) FROB_FORCE_CHARSET (3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
955
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
956 #define FROB_BOOLEAN_PROPERTY(prop) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
957 CODING_SYSTEM_ISO2022_##prop (codesys) = !NILP (value)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
958
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
959 else if (EQ (key, Qshort)) FROB_BOOLEAN_PROPERTY (SHORT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
960 else if (EQ (key, Qno_ascii_eol)) FROB_BOOLEAN_PROPERTY (NO_ASCII_EOL);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
961 else if (EQ (key, Qno_ascii_cntl)) FROB_BOOLEAN_PROPERTY (NO_ASCII_CNTL);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
962 else if (EQ (key, Qseven)) FROB_BOOLEAN_PROPERTY (SEVEN);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
963 else if (EQ (key, Qlock_shift)) FROB_BOOLEAN_PROPERTY (LOCK_SHIFT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
964 else if (EQ (key, Qno_iso6429)) FROB_BOOLEAN_PROPERTY (NO_ISO6429);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
965 else if (EQ (key, Qescape_quoted)) FROB_BOOLEAN_PROPERTY (ESCAPE_QUOTED);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
966
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
967 else if (EQ (key, Qinput_charset_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
968 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
969 codesys->iso2022.input_conv =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
970 Dynarr_new (charset_conversion_spec);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
971 parse_charset_conversion_specs (codesys->iso2022.input_conv,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
972 value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
973 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
974 else if (EQ (key, Qoutput_charset_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
975 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
976 codesys->iso2022.output_conv =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
977 Dynarr_new (charset_conversion_spec);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
978 parse_charset_conversion_specs (codesys->iso2022.output_conv,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
979 value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
980 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
981 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
982 signal_simple_error ("Unrecognized property", key);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
983 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
984 else if (EQ (type, Qccl))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
985 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
986 if (EQ (key, Qdecode))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
987 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
988 CHECK_VECTOR (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
989 CODING_SYSTEM_CCL_DECODE (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
990 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
991 else if (EQ (key, Qencode))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
992 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
993 CHECK_VECTOR (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
994 CODING_SYSTEM_CCL_ENCODE (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
995 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
996 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
997 signal_simple_error ("Unrecognized property", key);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
998 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
999 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1000 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1001 signal_simple_error ("Unrecognized property", key);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1002 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1003
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1004 if (need_to_setup_eol_systems)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1005 setup_eol_coding_systems (codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1006
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1007 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1008 Lisp_Object codesys_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1009 XSETCODING_SYSTEM (codesys_obj, codesys);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
1010 Fputhash (name, codesys_obj, Vcoding_system_hash_table);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1011 return codesys_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1012 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1013 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1014
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1015 DEFUN ("copy-coding-system", Fcopy_coding_system, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1016 Copy OLD-CODING-SYSTEM to NEW-NAME.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1017 If NEW-NAME does not name an existing coding system, a new one will
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1018 be created.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1019 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1020 (old_coding_system, new_name))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1021 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1022 Lisp_Object new_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1023 old_coding_system = Fget_coding_system (old_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1024 new_coding_system = Ffind_coding_system (new_name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1025 if (NILP (new_coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1026 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1027 XSETCODING_SYSTEM (new_coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1028 allocate_coding_system
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1029 (XCODING_SYSTEM_TYPE (old_coding_system),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1030 new_name));
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
1031 Fputhash (new_name, new_coding_system, Vcoding_system_hash_table);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1032 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1033
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1034 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1035 Lisp_Coding_System *to = XCODING_SYSTEM (new_coding_system);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1036 Lisp_Coding_System *from = XCODING_SYSTEM (old_coding_system);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1037 memcpy (((char *) to ) + sizeof (to->header),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1038 ((char *) from) + sizeof (from->header),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1039 sizeof (*from) - sizeof (from->header));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1040 to->name = new_name;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1041 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1042 return new_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1043 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1044
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1045 DEFUN ("coding-system-canonical-name-p", Fcoding_system_canonical_name_p, 1, 1, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1046 Return t if OBJECT names a coding system, and is not a coding system alias.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1047 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1048 (object))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1049 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1050 return CODING_SYSTEMP (Fgethash (object, Vcoding_system_hash_table, Qnil))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1051 ? Qt : Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1052 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1053
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1054 DEFUN ("coding-system-alias-p", Fcoding_system_alias_p, 1, 1, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1055 Return t if OBJECT is a coding system alias.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1056 All coding system aliases are created by `define-coding-system-alias'.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1057 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1058 (object))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1059 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1060 return SYMBOLP (Fgethash (object, Vcoding_system_hash_table, Qzero))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1061 ? Qt : Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1062 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1063
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1064 DEFUN ("coding-system-aliasee", Fcoding_system_aliasee, 1, 1, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1065 Return the coding-system symbol for which symbol ALIAS is an alias.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1066 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1067 (alias))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1068 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1069 Lisp_Object aliasee = Fgethash (alias, Vcoding_system_hash_table, Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1070 if (SYMBOLP (aliasee))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1071 return aliasee;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1072 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1073 signal_simple_error ("Symbol is not a coding system alias", alias);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1074 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1075
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1076 static Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1077 append_suffix_to_symbol (Lisp_Object symbol, const char *ascii_string)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1078 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1079 return Fintern (concat2 (Fsymbol_name (symbol), build_string (ascii_string)),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1080 Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1081 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1082
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1083 /* A maphash function, for removing dangling coding system aliases. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1084 static int
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1085 dangling_coding_system_alias_p (Lisp_Object alias,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1086 Lisp_Object aliasee,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1087 void *dangling_aliases)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1088 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1089 if (SYMBOLP (aliasee)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1090 && NILP (Fgethash (aliasee, Vcoding_system_hash_table, Qnil)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1091 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1092 (*(int *) dangling_aliases)++;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1093 return 1;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1094 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1095 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1096 return 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1097 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1098
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1099 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, 2, 2, 0, /*
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1100 Define symbol ALIAS as an alias for coding system ALIASEE.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1101
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1102 You can use this function to redefine an alias that has already been defined,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1103 but you cannot redefine a name which is the canonical name for a coding system.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1104 \(a canonical name of a coding system is what is returned when you call
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1105 `coding-system-name' on a coding system).
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1106
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1107 ALIASEE itself can be an alias, which allows you to define nested aliases.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1108
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1109 You are forbidden, however, from creating alias loops or `dangling' aliases.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1110 These will be detected, and an error will be signaled if you attempt to do so.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1111
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1112 If ALIASEE is nil, then ALIAS will simply be undefined.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1113
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1114 See also `coding-system-alias-p', `coding-system-aliasee',
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1115 and `coding-system-canonical-name-p'.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1116 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1117 (alias, aliasee))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1118 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1119 Lisp_Object real_coding_system, probe;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1120
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1121 CHECK_SYMBOL (alias);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1122
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1123 if (!NILP (Fcoding_system_canonical_name_p (alias)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1124 signal_simple_error
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1125 ("Symbol is the canonical name of a coding system and cannot be redefined",
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1126 alias);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1127
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1128 if (NILP (aliasee))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1129 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1130 Lisp_Object subsidiary_unix = append_suffix_to_symbol (alias, "-unix");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1131 Lisp_Object subsidiary_dos = append_suffix_to_symbol (alias, "-dos");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1132 Lisp_Object subsidiary_mac = append_suffix_to_symbol (alias, "-mac");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1133
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1134 Fremhash (alias, Vcoding_system_hash_table);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1135
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1136 /* Undefine subsidiary aliases,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1137 presumably created by a previous call to this function */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1138 if (! NILP (Fcoding_system_alias_p (subsidiary_unix)) &&
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1139 ! NILP (Fcoding_system_alias_p (subsidiary_dos)) &&
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1140 ! NILP (Fcoding_system_alias_p (subsidiary_mac)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1141 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1142 Fdefine_coding_system_alias (subsidiary_unix, Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1143 Fdefine_coding_system_alias (subsidiary_dos, Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1144 Fdefine_coding_system_alias (subsidiary_mac, Qnil);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1145 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1146
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1147 /* Undefine dangling coding system aliases. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1148 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1149 int dangling_aliases;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1150
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1151 do {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1152 dangling_aliases = 0;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1153 elisp_map_remhash (dangling_coding_system_alias_p,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1154 Vcoding_system_hash_table,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1155 &dangling_aliases);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1156 } while (dangling_aliases > 0);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1157 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1158
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1159 return Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1160 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1161
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1162 if (CODING_SYSTEMP (aliasee))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1163 aliasee = XCODING_SYSTEM_NAME (aliasee);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1164
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1165 /* Checks that aliasee names a coding-system */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1166 real_coding_system = Fget_coding_system (aliasee);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1167
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1168 /* Check for coding system alias loops */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1169 if (EQ (alias, aliasee))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1170 alias_loop: signal_simple_error_2
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1171 ("Attempt to create a coding system alias loop", alias, aliasee);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1172
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1173 for (probe = aliasee;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1174 SYMBOLP (probe);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1175 probe = Fgethash (probe, Vcoding_system_hash_table, Qzero))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1176 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1177 if (EQ (probe, alias))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1178 goto alias_loop;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1179 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1180
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1181 Fputhash (alias, aliasee, Vcoding_system_hash_table);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1182
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1183 /* Set up aliases for subsidiaries.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1184 #### There must be a better way to handle subsidiary coding systems. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1185 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1186 static const char *suffixes[] = { "-unix", "-dos", "-mac" };
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1187 int i;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1188 for (i = 0; i < countof (suffixes); i++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1189 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1190 Lisp_Object alias_subsidiary =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1191 append_suffix_to_symbol (alias, suffixes[i]);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1192 Lisp_Object aliasee_subsidiary =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1193 append_suffix_to_symbol (aliasee, suffixes[i]);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1194
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1195 if (! NILP (Ffind_coding_system (aliasee_subsidiary)))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1196 Fdefine_coding_system_alias (alias_subsidiary, aliasee_subsidiary);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1197 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1198 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1199 /* FSF return value is a vector of [ALIAS-unix ALIAS-dos ALIAS-mac],
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1200 but it doesn't look intentional, so I'd rather return something
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1201 meaningful or nothing at all. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1202 return Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1203 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1204
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1205 static Lisp_Object
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1206 subsidiary_coding_system (Lisp_Object coding_system, eol_type_t type)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1207 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1208 Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1209 Lisp_Object new_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1210
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1211 if (CODING_SYSTEM_EOL_TYPE (cs) != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1212 return coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1213
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1214 switch (type)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1215 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1216 case EOL_AUTODETECT: return coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1217 case EOL_LF: new_coding_system = CODING_SYSTEM_EOL_LF (cs); break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1218 case EOL_CR: new_coding_system = CODING_SYSTEM_EOL_CR (cs); break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1219 case EOL_CRLF: new_coding_system = CODING_SYSTEM_EOL_CRLF (cs); break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1220 default: abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1221 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1222
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1223 return NILP (new_coding_system) ? coding_system : new_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1224 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1225
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1226 DEFUN ("subsidiary-coding-system", Fsubsidiary_coding_system, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1227 Return the subsidiary coding system of CODING-SYSTEM with eol type EOL-TYPE.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1228 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1229 (coding_system, eol_type))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1230 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1231 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1232
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1233 return subsidiary_coding_system (coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1234 symbol_to_eol_type (eol_type));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1235 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1236
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1237
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1238 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1239 /* Coding system accessors */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1240 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1241
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1242 DEFUN ("coding-system-doc-string", Fcoding_system_doc_string, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1243 Return the doc string for CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1244 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1245 (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1246 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1247 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1248 return XCODING_SYSTEM_DOC_STRING (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1249 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1250
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1251 DEFUN ("coding-system-type", Fcoding_system_type, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1252 Return the type of CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1253 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1254 (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1255 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1256 switch (XCODING_SYSTEM_TYPE (Fget_coding_system (coding_system)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1257 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
1258 default: abort ();
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1259 case CODESYS_AUTODETECT: return Qundecided;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1260 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1261 case CODESYS_SHIFT_JIS: return Qshift_jis;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1262 case CODESYS_ISO2022: return Qiso2022;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1263 case CODESYS_BIG5: return Qbig5;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1264 case CODESYS_UCS4: return Qucs4;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1265 case CODESYS_UTF8: return Qutf8;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1266 case CODESYS_CCL: return Qccl;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1267 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1268 case CODESYS_NO_CONVERSION: return Qno_conversion;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1269 #ifdef DEBUG_XEMACS
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1270 case CODESYS_INTERNAL: return Qinternal;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1271 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1272 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1273 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1274
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1275 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1276 static
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1277 Lisp_Object coding_system_charset (Lisp_Object coding_system, int gnum)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1278 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1279 Lisp_Object cs
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1280 = XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, gnum);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1281
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1282 return CHARSETP (cs) ? XCHARSET_NAME (cs) : Qnil;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1283 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1284
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1285 DEFUN ("coding-system-charset", Fcoding_system_charset, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1286 Return initial charset of CODING-SYSTEM designated to GNUM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1287 GNUM allows 0 .. 3.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1288 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1289 (coding_system, gnum))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1290 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1291 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1292 CHECK_INT (gnum);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1293
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1294 return coding_system_charset (coding_system, XINT (gnum));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1295 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1296 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1297
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1298 DEFUN ("coding-system-property", Fcoding_system_property, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1299 Return the PROP property of CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1300 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1301 (coding_system, prop))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1302 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1303 int i, ok = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1304 enum coding_system_type type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1305
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1306 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1307 CHECK_SYMBOL (prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1308 type = XCODING_SYSTEM_TYPE (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1309
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1310 for (i = 0; !ok && i < Dynarr_length (the_codesys_prop_dynarr); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1311 if (EQ (Dynarr_at (the_codesys_prop_dynarr, i).sym, prop))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1312 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1313 ok = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1314 switch (Dynarr_at (the_codesys_prop_dynarr, i).prop_type)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1315 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1316 case CODESYS_PROP_ALL_OK:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1317 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1318 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1319 case CODESYS_PROP_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1320 if (type != CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1321 signal_simple_error
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1322 ("Property only valid in ISO2022 coding systems",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1323 prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1324 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1325
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1326 case CODESYS_PROP_CCL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1327 if (type != CODESYS_CCL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1328 signal_simple_error
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1329 ("Property only valid in CCL coding systems",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1330 prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1331 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1332 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1333 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1334 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1335 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1336 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1337
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1338 if (!ok)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1339 signal_simple_error ("Unrecognized property", prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1340
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1341 if (EQ (prop, Qname))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1342 return XCODING_SYSTEM_NAME (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1343 else if (EQ (prop, Qtype))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1344 return Fcoding_system_type (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1345 else if (EQ (prop, Qdoc_string))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1346 return XCODING_SYSTEM_DOC_STRING (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1347 else if (EQ (prop, Qmnemonic))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1348 return XCODING_SYSTEM_MNEMONIC (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1349 else if (EQ (prop, Qeol_type))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1350 return eol_type_to_symbol (XCODING_SYSTEM_EOL_TYPE (coding_system));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1351 else if (EQ (prop, Qeol_lf))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1352 return XCODING_SYSTEM_EOL_LF (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1353 else if (EQ (prop, Qeol_crlf))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1354 return XCODING_SYSTEM_EOL_CRLF (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1355 else if (EQ (prop, Qeol_cr))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1356 return XCODING_SYSTEM_EOL_CR (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1357 else if (EQ (prop, Qpost_read_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1358 return XCODING_SYSTEM_POST_READ_CONVERSION (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1359 else if (EQ (prop, Qpre_write_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1360 return XCODING_SYSTEM_PRE_WRITE_CONVERSION (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1361 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1362 else if (type == CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1363 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1364 if (EQ (prop, Qcharset_g0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1365 return coding_system_charset (coding_system, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1366 else if (EQ (prop, Qcharset_g1))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1367 return coding_system_charset (coding_system, 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1368 else if (EQ (prop, Qcharset_g2))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1369 return coding_system_charset (coding_system, 2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1370 else if (EQ (prop, Qcharset_g3))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1371 return coding_system_charset (coding_system, 3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1372
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1373 #define FORCE_CHARSET(charset_num) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1374 (XCODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1375 (coding_system, charset_num) ? Qt : Qnil)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1376
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1377 else if (EQ (prop, Qforce_g0_on_output)) return FORCE_CHARSET (0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1378 else if (EQ (prop, Qforce_g1_on_output)) return FORCE_CHARSET (1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1379 else if (EQ (prop, Qforce_g2_on_output)) return FORCE_CHARSET (2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1380 else if (EQ (prop, Qforce_g3_on_output)) return FORCE_CHARSET (3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1381
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1382 #define LISP_BOOLEAN(prop) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1383 (XCODING_SYSTEM_ISO2022_##prop (coding_system) ? Qt : Qnil)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1384
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1385 else if (EQ (prop, Qshort)) return LISP_BOOLEAN (SHORT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1386 else if (EQ (prop, Qno_ascii_eol)) return LISP_BOOLEAN (NO_ASCII_EOL);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1387 else if (EQ (prop, Qno_ascii_cntl)) return LISP_BOOLEAN (NO_ASCII_CNTL);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1388 else if (EQ (prop, Qseven)) return LISP_BOOLEAN (SEVEN);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1389 else if (EQ (prop, Qlock_shift)) return LISP_BOOLEAN (LOCK_SHIFT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1390 else if (EQ (prop, Qno_iso6429)) return LISP_BOOLEAN (NO_ISO6429);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1391 else if (EQ (prop, Qescape_quoted)) return LISP_BOOLEAN (ESCAPE_QUOTED);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1392
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1393 else if (EQ (prop, Qinput_charset_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1394 return
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1395 unparse_charset_conversion_specs
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1396 (XCODING_SYSTEM (coding_system)->iso2022.input_conv);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1397 else if (EQ (prop, Qoutput_charset_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1398 return
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1399 unparse_charset_conversion_specs
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1400 (XCODING_SYSTEM (coding_system)->iso2022.output_conv);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1401 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1402 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1403 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1404 else if (type == CODESYS_CCL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1405 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1406 if (EQ (prop, Qdecode))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1407 return XCODING_SYSTEM_CCL_DECODE (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1408 else if (EQ (prop, Qencode))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1409 return XCODING_SYSTEM_CCL_ENCODE (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1410 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1411 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1412 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1413 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1414 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1415 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1416
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1417 return Qnil; /* not reached */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1418 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1419
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1420
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1421 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1422 /* Coding category functions */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1423 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1424
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1425 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1426 decode_coding_category (Lisp_Object symbol)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1427 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1428 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1429
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1430 CHECK_SYMBOL (symbol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1431 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1432 if (EQ (coding_category_symbol[i], symbol))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1433 return i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1434
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1435 signal_simple_error ("Unrecognized coding category", symbol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1436 return 0; /* not reached */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1437 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1438
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1439 DEFUN ("coding-category-list", Fcoding_category_list, 0, 0, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1440 Return a list of all recognized coding categories.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1441 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1442 ())
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1443 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1444 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1445 Lisp_Object list = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1446
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1447 for (i = CODING_CATEGORY_LAST; i >= 0; i--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1448 list = Fcons (coding_category_symbol[i], list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1449 return list;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1450 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1451
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1452 DEFUN ("set-coding-priority-list", Fset_coding_priority_list, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1453 Change the priority order of the coding categories.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1454 LIST should be list of coding categories, in descending order of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1455 priority. Unspecified coding categories will be lower in priority
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1456 than all specified ones, in the same relative order they were in
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1457 previously.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1458 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1459 (list))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1460 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1461 int category_to_priority[CODING_CATEGORY_LAST + 1];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1462 int i, j;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1463 Lisp_Object rest;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1464
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1465 /* First generate a list that maps coding categories to priorities. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1466
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1467 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1468 category_to_priority[i] = -1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1469
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1470 /* Highest priority comes from the specified list. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1471 i = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1472 EXTERNAL_LIST_LOOP (rest, list)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1473 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1474 int cat = decode_coding_category (XCAR (rest));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1475
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1476 if (category_to_priority[cat] >= 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1477 signal_simple_error ("Duplicate coding category in list", XCAR (rest));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1478 category_to_priority[cat] = i++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1479 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1480
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1481 /* Now go through the existing categories by priority to retrieve
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1482 the categories not yet specified and preserve their priority
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1483 order. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1484 for (j = 0; j <= CODING_CATEGORY_LAST; j++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1485 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1486 int cat = fcd->coding_category_by_priority[j];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1487 if (category_to_priority[cat] < 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1488 category_to_priority[cat] = i++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1489 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1490
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1491 /* Now we need to construct the inverse of the mapping we just
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1492 constructed. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1493
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1494 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1495 fcd->coding_category_by_priority[category_to_priority[i]] = i;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1496
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1497 /* Phew! That was confusing. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1498 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1499 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1500
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1501 DEFUN ("coding-priority-list", Fcoding_priority_list, 0, 0, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1502 Return a list of coding categories in descending order of priority.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1503 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1504 ())
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1505 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1506 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1507 Lisp_Object list = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1508
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1509 for (i = CODING_CATEGORY_LAST; i >= 0; i--)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1510 list = Fcons (coding_category_symbol[fcd->coding_category_by_priority[i]],
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1511 list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1512 return list;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1513 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1514
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1515 DEFUN ("set-coding-category-system", Fset_coding_category_system, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1516 Change the coding system associated with a coding category.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1517 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1518 (coding_category, coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1519 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1520 int cat = decode_coding_category (coding_category);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1521
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1522 coding_system = Fget_coding_system (coding_system);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1523 fcd->coding_category_system[cat] = coding_system;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1524 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1525 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1526
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1527 DEFUN ("coding-category-system", Fcoding_category_system, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1528 Return the coding system associated with a coding category.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1529 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1530 (coding_category))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1531 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1532 int cat = decode_coding_category (coding_category);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1533 Lisp_Object sys = fcd->coding_category_system[cat];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1534
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1535 if (!NILP (sys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1536 return XCODING_SYSTEM_NAME (sys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1537 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1538 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1539
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1540
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1541 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1542 /* Detecting the encoding of data */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1543 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1544
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1545 struct detection_state
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1546 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1547 eol_type_t eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1548 int seen_non_ascii;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1549 int mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1550 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1551 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1552 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1553 int mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1554 int in_second_byte;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1555 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1556 big5;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1557
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1558 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1559 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1560 int mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1561 int in_second_byte;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1562 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1563 shift_jis;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1564
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1565 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1566 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1567 int mask;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1568 int in_byte;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1569 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1570 ucs4;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1571
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1572 struct
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1573 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1574 int mask;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1575 int in_byte;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1576 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1577 utf8;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1578
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1579 struct
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1580 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1581 int mask;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1582 int initted;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1583 struct iso2022_decoder iso;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1584 unsigned int flags;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1585 int high_byte_count;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1586 unsigned int saw_single_shift:1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1587 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1588 iso2022;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1589 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1590 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1591 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1592 int seen_anything;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1593 int just_saw_cr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1594 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1595 eol;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1596 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1597
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1598 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1599 acceptable_control_char_p (int c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1600 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1601 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1602 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1603 /* Allow and ignore control characters that you might
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1604 reasonably see in a text file */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1605 case '\r':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1606 case '\n':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1607 case '\t':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1608 case 7: /* bell */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1609 case 8: /* backspace */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1610 case 11: /* vertical tab */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1611 case 12: /* form feed */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1612 case 26: /* MS-DOS C-z junk */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1613 case 31: /* '^_' -- for info */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1614 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1615 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1616 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1617 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1618 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1619
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1620 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1621 mask_has_at_most_one_bit_p (int mask)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1622 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1623 /* Perhaps the only thing useful you learn from intensive Microsoft
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1624 technical interviews */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1625 return (mask & (mask - 1)) == 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1626 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1627
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1628 static eol_type_t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1629 detect_eol_type (struct detection_state *st, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1630 unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1631 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1632 int c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1633
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1634 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1635 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1636 c = *src++;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1637 if (c == '\n')
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1638 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1639 if (st->eol.just_saw_cr)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1640 return EOL_CRLF;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1641 else if (st->eol.seen_anything)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1642 return EOL_LF;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1643 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1644 else if (st->eol.just_saw_cr)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1645 return EOL_CR;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1646 else if (c == '\r')
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1647 st->eol.just_saw_cr = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1648 else
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1649 st->eol.just_saw_cr = 0;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1650 st->eol.seen_anything = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1651 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1652
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1653 return EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1654 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1655
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1656 /* Attempt to determine the encoding and EOL type of the given text.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1657 Before calling this function for the first type, you must initialize
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1658 st->eol_type as appropriate and initialize st->mask to ~0.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1659
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1660 st->eol_type holds the determined EOL type, or EOL_AUTODETECT if
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1661 not yet known.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1662
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1663 st->mask holds the determined coding category mask, or ~0 if only
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1664 ASCII has been seen so far.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1665
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1666 Returns:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1667
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1668 0 == st->eol_type is EOL_AUTODETECT and/or more than coding category
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1669 is present in st->mask
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1670 1 == definitive answers are here for both st->eol_type and st->mask
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1671 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1672
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1673 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1674 detect_coding_type (struct detection_state *st, const Extbyte *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1675 unsigned int n, int just_do_eol)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1676 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1677 int c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1678
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1679 if (st->eol_type == EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1680 st->eol_type = detect_eol_type (st, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1681
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1682 if (just_do_eol)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1683 return st->eol_type != EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1684
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1685 if (!st->seen_non_ascii)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1686 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1687 for (; n; n--, src++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1688 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1689 c = *src;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1690 if ((c < 0x20 && !acceptable_control_char_p (c)) || c >= 0x80)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1691 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1692 st->seen_non_ascii = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1693 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1694 st->shift_jis.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1695 st->big5.mask = ~0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1696 st->ucs4.mask = ~0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1697 st->utf8.mask = ~0;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1698 st->iso2022.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1699 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1700 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1701 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1702 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1703 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1704
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1705 if (!n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1706 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1707 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1708 if (!mask_has_at_most_one_bit_p (st->iso2022.mask))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1709 st->iso2022.mask = detect_coding_iso2022 (st, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1710 if (!mask_has_at_most_one_bit_p (st->shift_jis.mask))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1711 st->shift_jis.mask = detect_coding_sjis (st, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1712 if (!mask_has_at_most_one_bit_p (st->big5.mask))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1713 st->big5.mask = detect_coding_big5 (st, src, n);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1714 if (!mask_has_at_most_one_bit_p (st->utf8.mask))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1715 st->utf8.mask = detect_coding_utf8 (st, src, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1716 if (!mask_has_at_most_one_bit_p (st->ucs4.mask))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1717 st->ucs4.mask = detect_coding_ucs4 (st, src, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1718
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1719 st->mask
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1720 = st->iso2022.mask | st->shift_jis.mask | st->big5.mask
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1721 | st->utf8.mask | st->ucs4.mask;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1722 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1723 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1724 int retval = mask_has_at_most_one_bit_p (st->mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1725 st->mask |= CODING_CATEGORY_NO_CONVERSION_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1726 return retval && st->eol_type != EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1727 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1728 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1729
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1730 static Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1731 coding_system_from_mask (int mask)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1732 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1733 if (mask == ~0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1734 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1735 /* If the file was entirely or basically ASCII, use the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1736 default value of `buffer-file-coding-system'. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1737 Lisp_Object retval =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1738 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1739 if (!NILP (retval))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1740 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1741 retval = Ffind_coding_system (retval);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1742 if (NILP (retval))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1743 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1744 warn_when_safe
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1745 (Qbad_variable, Qwarning,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1746 "Invalid `default-buffer-file-coding-system', set to nil");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1747 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1748 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1749 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1750 if (NILP (retval))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1751 retval = Fget_coding_system (Qraw_text);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1752 return retval;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1753 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1754 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1755 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1756 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1757 int cat = -1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1758 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1759 mask = postprocess_iso2022_mask (mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1760 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1761 /* Look through the coding categories by priority and find
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1762 the first one that is allowed. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1763 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1764 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1765 cat = fcd->coding_category_by_priority[i];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1766 if ((mask & (1 << cat)) &&
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1767 !NILP (fcd->coding_category_system[cat]))
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1768 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1769 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1770 if (cat >= 0)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1771 return fcd->coding_category_system[cat];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1772 else
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1773 return Fget_coding_system (Qraw_text);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1774 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1775 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1776
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1777 /* Given a seekable read stream and potential coding system and EOL type
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1778 as specified, do any autodetection that is called for. If the
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1779 coding system and/or EOL type are not `autodetect', they will be left
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1780 alone; but this function will never return an autodetect coding system
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1781 or EOL type.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1782
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1783 This function does not automatically fetch subsidiary coding systems;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1784 that should be unnecessary with the explicit eol-type argument. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1785
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1786 #define LENGTH(string_constant) (sizeof (string_constant) - 1)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1787
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1788 void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1789 determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1790 eol_type_t *eol_type_in_out)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1791 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1792 struct detection_state decst;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1793
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1794 if (*eol_type_in_out == EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1795 *eol_type_in_out = XCODING_SYSTEM_EOL_TYPE (*codesys_in_out);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1796
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1797 xzero (decst);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1798 decst.eol_type = *eol_type_in_out;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1799 decst.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1800
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1801 /* If autodetection is called for, do it now. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1802 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1803 || *eol_type_in_out == EOL_AUTODETECT)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1804 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1805 Extbyte buf[4096];
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1806 Lisp_Object coding_system = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1807 Extbyte *p;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1808 ssize_t nread = Lstream_read (stream, buf, sizeof (buf));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1809 Extbyte *scan_end;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1810
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1811 /* Look for initial "-*-"; mode line prefix */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1812 for (p = buf,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1813 scan_end = buf + nread - LENGTH ("-*-coding:?-*-");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1814 p <= scan_end
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1815 && *p != '\n'
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1816 && *p != '\r';
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1817 p++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1818 if (*p == '-' && *(p+1) == '*' && *(p+2) == '-')
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1819 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1820 Extbyte *local_vars_beg = p + 3;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1821 /* Look for final "-*-"; mode line suffix */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1822 for (p = local_vars_beg,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1823 scan_end = buf + nread - LENGTH ("-*-");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1824 p <= scan_end
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1825 && *p != '\n'
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1826 && *p != '\r';
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1827 p++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1828 if (*p == '-' && *(p+1) == '*' && *(p+2) == '-')
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1829 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1830 Extbyte *suffix = p;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1831 /* Look for "coding:" */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1832 for (p = local_vars_beg,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1833 scan_end = suffix - LENGTH ("coding:?");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1834 p <= scan_end;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1835 p++)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1836 if (memcmp ("coding:", p, LENGTH ("coding:")) == 0
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1837 && (p == local_vars_beg
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1838 || (*(p-1) == ' ' ||
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1839 *(p-1) == '\t' ||
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1840 *(p-1) == ';')))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1841 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1842 Extbyte save;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1843 int n;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1844 p += LENGTH ("coding:");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1845 while (*p == ' ' || *p == '\t') p++;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1846
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1847 /* Get coding system name */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1848 save = *suffix; *suffix = '\0';
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1849 /* Characters valid in a MIME charset name (rfc 1521),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1850 and in a Lisp symbol name. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1851 n = strspn ( (char *) p,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1852 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1853 "abcdefghijklmnopqrstuvwxyz"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1854 "0123456789"
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1855 "!$%&*+-.^_{|}~");
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1856 *suffix = save;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1857 if (n > 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1858 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1859 save = p[n]; p[n] = '\0';
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1860 coding_system =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1861 Ffind_coding_system (intern ((char *) p));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1862 p[n] = save;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1863 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1864 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1865 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1866 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1867 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1868 break;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1869 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1870
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1871 if (NILP (coding_system))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1872 do
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1873 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1874 if (detect_coding_type (&decst, buf, nread,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1875 XCODING_SYSTEM_TYPE (*codesys_in_out)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1876 != CODESYS_AUTODETECT))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1877 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1878 nread = Lstream_read (stream, buf, sizeof (buf));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1879 if (nread == 0)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1880 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1881 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1882 while (1);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1883
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1884 else if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1885 && XCODING_SYSTEM_EOL_TYPE (coding_system) == EOL_AUTODETECT)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1886 do
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1887 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1888 if (detect_coding_type (&decst, buf, nread, 1))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1889 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1890 nread = Lstream_read (stream, buf, sizeof (buf));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1891 if (!nread)
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1892 break;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1893 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1894 while (1);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1895
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1896 *eol_type_in_out = decst.eol_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1897 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1898 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1899 if (NILP (coding_system))
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1900 *codesys_in_out = coding_system_from_mask (decst.mask);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1901 else
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1902 *codesys_in_out = coding_system;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1903 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1904 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1905
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1906 /* If we absolutely can't determine the EOL type, just assume LF. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1907 if (*eol_type_in_out == EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1908 *eol_type_in_out = EOL_LF;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1909
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1910 Lstream_rewind (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1911 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1912
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1913 DEFUN ("detect-coding-region", Fdetect_coding_region, 2, 3, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1914 Detect coding system of the text in the region between START and END.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1915 Returned a list of possible coding systems ordered by priority.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1916 If only ASCII characters are found, it returns 'undecided or one of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1917 its subsidiary coding systems according to a detected end-of-line
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1918 type. Optional arg BUFFER defaults to the current buffer.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1919 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1920 (start, end, buffer))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1921 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1922 Lisp_Object val = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1923 struct buffer *buf = decode_buffer (buffer, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1924 Bufpos b, e;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1925 Lisp_Object instream, lb_instream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1926 Lstream *istr, *lb_istr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1927 struct detection_state decst;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1928 struct gcpro gcpro1, gcpro2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1929
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1930 get_buffer_range_char (buf, start, end, &b, &e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1931 lb_instream = make_lisp_buffer_input_stream (buf, b, e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1932 lb_istr = XLSTREAM (lb_instream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1933 instream = make_encoding_input_stream (lb_istr, Fget_coding_system (Qbinary));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1934 istr = XLSTREAM (instream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1935 GCPRO2 (instream, lb_instream);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1936 xzero (decst);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1937 decst.eol_type = EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1938 decst.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1939 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1940 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1941 unsigned char random_buffer[4096];
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1942 ssize_t nread = Lstream_read (istr, random_buffer, sizeof (random_buffer));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1943
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1944 if (!nread)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1945 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1946 if (detect_coding_type (&decst, random_buffer, nread, 0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1947 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1948 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1949
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1950 if (decst.mask == ~0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1951 val = subsidiary_coding_system (Fget_coding_system (Qundecided),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1952 decst.eol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1953 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1954 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1955 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1956
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1957 val = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1958 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1959 decst.mask = postprocess_iso2022_mask (decst.mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1960 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1961 for (i = CODING_CATEGORY_LAST; i >= 0; i--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1962 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1963 int sys = fcd->coding_category_by_priority[i];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1964 if (decst.mask & (1 << sys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1965 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1966 Lisp_Object codesys = fcd->coding_category_system[sys];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1967 if (!NILP (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1968 codesys = subsidiary_coding_system (codesys, decst.eol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1969 val = Fcons (codesys, val);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1970 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1971 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1972 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1973 Lstream_close (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1974 UNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1975 Lstream_delete (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1976 Lstream_delete (lb_istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1977 return val;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1978 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1979
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1980
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1981 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1982 /* Converting to internal Mule format ("decoding") */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1983 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1984
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1985 /* A decoding stream is a stream used for decoding text (i.e.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1986 converting from some external format to internal format).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1987 The decoding-stream object keeps track of the actual coding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1988 stream, the stream that is at the other end, and data that
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1989 needs to be persistent across the lifetime of the stream. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1990
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1991 /* Handle the EOL stuff related to just-read-in character C.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1992 EOL_TYPE is the EOL type of the coding stream.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1993 FLAGS is the current value of FLAGS in the coding stream, and may
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1994 be modified by this macro. (The macro only looks at the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1995 CODING_STATE_CR flag.) DST is the Dynarr to which the decoded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1996 bytes are to be written. You need to also define a local goto
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1997 label "label_continue_loop" that is at the end of the main
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1998 character-reading loop.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1999
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2000 If C is a CR character, then this macro handles it entirely and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2001 jumps to label_continue_loop. Otherwise, this macro does not add
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2002 anything to DST, and continues normally. You should continue
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2003 processing C normally after this macro. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2004
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2005 #define DECODE_HANDLE_EOL_TYPE(eol_type, c, flags, dst) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2006 do { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2007 if (c == '\r') \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2008 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2009 if (eol_type == EOL_CR) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2010 Dynarr_add (dst, '\n'); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2011 else if (eol_type != EOL_CRLF || flags & CODING_STATE_CR) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2012 Dynarr_add (dst, c); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2013 else \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2014 flags |= CODING_STATE_CR; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2015 goto label_continue_loop; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2016 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2017 else if (flags & CODING_STATE_CR) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2018 { /* eol_type == CODING_SYSTEM_EOL_CRLF */ \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2019 if (c != '\n') \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2020 Dynarr_add (dst, '\r'); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2021 flags &= ~CODING_STATE_CR; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2022 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2023 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2024
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2025 /* C should be a binary character in the range 0 - 255; convert
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2026 to internal format and add to Dynarr DST. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2027
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2028 #define DECODE_ADD_BINARY_CHAR(c, dst) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2029 do { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2030 if (BYTE_ASCII_P (c)) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2031 Dynarr_add (dst, c); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2032 else if (BYTE_C1_P (c)) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2033 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2034 Dynarr_add (dst, LEADING_BYTE_CONTROL_1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2035 Dynarr_add (dst, c + 0x20); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2036 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2037 else \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2038 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2039 Dynarr_add (dst, LEADING_BYTE_LATIN_ISO8859_1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2040 Dynarr_add (dst, c); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2041 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2042 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2043
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2044 #define DECODE_OUTPUT_PARTIAL_CHAR(ch) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2045 do { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2046 if (ch) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2047 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2048 DECODE_ADD_BINARY_CHAR (ch, dst); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2049 ch = 0; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2050 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2051 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2052
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2053 #define DECODE_HANDLE_END_OF_CONVERSION(flags, ch, dst) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2054 do { \
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2055 if (flags & CODING_STATE_END) \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2056 { \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2057 DECODE_OUTPUT_PARTIAL_CHAR (ch); \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2058 if (flags & CODING_STATE_CR) \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2059 Dynarr_add (dst, '\r'); \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2060 } \
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2061 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2062
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2063 #define DECODING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, decoding)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2064
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2065 struct decoding_stream
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2066 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2067 /* Coding system that governs the conversion. */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2068 Lisp_Coding_System *codesys;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2069
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2070 /* Stream that we read the encoded data from or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2071 write the decoded data to. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2072 Lstream *other_end;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2073
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2074 /* If we are reading, then we can return only a fixed amount of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2075 data, so if the conversion resulted in too much data, we store it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2076 here for retrieval the next time around. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2077 unsigned_char_dynarr *runoff;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2078
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2079 /* FLAGS holds flags indicating the current state of the decoding.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2080 Some of these flags are dependent on the coding system. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2081 unsigned int flags;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2082
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2083 /* CH holds a partially built-up character. Since we only deal
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2084 with one- and two-byte characters at the moment, we only use
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2085 this to store the first byte of a two-byte character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2086 unsigned int ch;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2087
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2088 /* EOL_TYPE specifies the type of end-of-line conversion that
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2089 currently applies. We need to keep this separate from the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2090 EOL type stored in CODESYS because the latter might indicate
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2091 automatic EOL-type detection while the former will always
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2092 indicate a particular EOL type. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2093 eol_type_t eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2094 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2095 /* Additional ISO2022 information. We define the structure above
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2096 because it's also needed by the detection routines. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2097 struct iso2022_decoder iso2022;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2098
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2099 /* Additional information (the state of the running CCL program)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2100 used by the CCL decoder. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2101 struct ccl_program ccl;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2102
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2103 /* counter for UTF-8 or UCS-4 */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2104 unsigned char counter;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2105 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2106 struct detection_state decst;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2107 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2108
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2109 static ssize_t decoding_reader (Lstream *stream,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2110 unsigned char *data, size_t size);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2111 static ssize_t decoding_writer (Lstream *stream,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2112 const unsigned char *data, size_t size);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2113 static int decoding_rewinder (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2114 static int decoding_seekable_p (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2115 static int decoding_flusher (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2116 static int decoding_closer (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2117
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2118 static Lisp_Object decoding_marker (Lisp_Object stream);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2119
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2120 DEFINE_LSTREAM_IMPLEMENTATION ("decoding", lstream_decoding,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2121 sizeof (struct decoding_stream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2122
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2123 static Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2124 decoding_marker (Lisp_Object stream)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2125 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2126 Lstream *str = DECODING_STREAM_DATA (XLSTREAM (stream))->other_end;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2127 Lisp_Object str_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2128
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2129 /* We do not need to mark the coding systems or charsets stored
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2130 within the stream because they are stored in a global list
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2131 and automatically marked. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2132
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2133 XSETLSTREAM (str_obj, str);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2134 mark_object (str_obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2135 if (str->imp->marker)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2136 return (str->imp->marker) (str_obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2137 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2138 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2139 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2140
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2141 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2142 so we read data from the other end, decode it, and store it into DATA. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2143
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2144 static ssize_t
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2145 decoding_reader (Lstream *stream, unsigned char *data, size_t size)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2146 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2147 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2148 unsigned char *orig_data = data;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2149 ssize_t read_size;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2150 int error_occurred = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2151
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2152 /* We need to interface to mule_decode(), which expects to take some
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2153 amount of data and store the result into a Dynarr. We have
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2154 mule_decode() store into str->runoff, and take data from there
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2155 as necessary. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2156
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2157 /* We loop until we have enough data, reading chunks from the other
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2158 end and decoding it. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2159 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2160 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2161 /* Take data from the runoff if we can. Make sure to take at
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2162 most SIZE bytes, and delete the data from the runoff. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2163 if (Dynarr_length (str->runoff) > 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2164 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2165 size_t chunk = min (size, (size_t) Dynarr_length (str->runoff));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2166 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2167 Dynarr_delete_many (str->runoff, 0, chunk);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2168 data += chunk;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2169 size -= chunk;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2170 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2171
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2172 if (size == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2173 break; /* No more room for data */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2174
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2175 if (str->flags & CODING_STATE_END)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2176 /* This means that on the previous iteration, we hit the EOF on
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2177 the other end. We loop once more so that mule_decode() can
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2178 output any final stuff it may be holding, or any "go back
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2179 to a sane state" escape sequences. (This latter makes sense
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2180 during encoding.) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2181 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2182
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2183 /* Exhausted the runoff, so get some more. DATA has at least
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2184 SIZE bytes left of storage in it, so it's OK to read directly
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2185 into it. (We'll be overwriting above, after we've decoded it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2186 into the runoff.) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2187 read_size = Lstream_read (str->other_end, data, size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2188 if (read_size < 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2189 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2190 error_occurred = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2191 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2192 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2193 if (read_size == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2194 /* There might be some more end data produced in the translation.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2195 See the comment above. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2196 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2197 mule_decode (stream, data, str->runoff, read_size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2198 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2199
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2200 if (data - orig_data == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2201 return error_occurred ? -1 : 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2202 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2203 return data - orig_data;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2204 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2205
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2206 static ssize_t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2207 decoding_writer (Lstream *stream, const unsigned char *data, size_t size)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2208 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2209 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2210 ssize_t retval;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2211
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2212 /* Decode all our data into the runoff, and then attempt to write
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2213 it all out to the other end. Remove whatever chunk we succeeded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2214 in writing. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2215 mule_decode (stream, data, str->runoff, size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2216 retval = Lstream_write (str->other_end, Dynarr_atp (str->runoff, 0),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2217 Dynarr_length (str->runoff));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2218 if (retval > 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2219 Dynarr_delete_many (str->runoff, 0, retval);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2220 /* Do NOT return retval. The return value indicates how much
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2221 of the incoming data was written, not how many bytes were
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2222 written. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2223 return size;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2224 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2225
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2226 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2227 reset_decoding_stream (struct decoding_stream *str)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2228 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2229 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2230 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2231 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2232 Lisp_Object coding_system;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2233 XSETCODING_SYSTEM (coding_system, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2234 reset_iso2022 (coding_system, &str->iso2022);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2235 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2236 else if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_CCL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2237 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2238 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_DECODE (str->codesys));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2239 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2240 str->counter = 0;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2241 #endif /* MULE */
404
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2242 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2243 || CODING_SYSTEM_EOL_TYPE (str->codesys) == EOL_AUTODETECT)
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2244 {
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2245 xzero (str->decst);
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2246 str->decst.eol_type = EOL_AUTODETECT;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2247 str->decst.mask = ~0;
2f8bb876ab1d Import from CVS: tag r21-2-32
cvs
parents: 400
diff changeset
2248 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2249 str->flags = str->ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2250 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2251
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2252 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2253 decoding_rewinder (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2254 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2255 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2256 reset_decoding_stream (str);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2257 Dynarr_reset (str->runoff);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2258 return Lstream_rewind (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2259 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2260
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2261 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2262 decoding_seekable_p (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2263 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2264 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2265 return Lstream_seekable_p (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2266 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2267
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2268 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2269 decoding_flusher (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2270 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2271 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2272 return Lstream_flush (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2273 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2274
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2275 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2276 decoding_closer (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2277 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2278 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2279 if (stream->flags & LSTREAM_FL_WRITE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2280 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2281 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2282 decoding_writer (stream, 0, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2283 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2284 Dynarr_free (str->runoff);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2285 #ifdef MULE
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2286 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2287 if (str->iso2022.composite_chars)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2288 Dynarr_free (str->iso2022.composite_chars);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2289 #endif
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2290 #endif
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2291 return Lstream_close (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2292 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2293
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2294 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2295 decoding_stream_coding_system (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2296 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2297 Lisp_Object coding_system;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2298 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2299
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2300 XSETCODING_SYSTEM (coding_system, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2301 return subsidiary_coding_system (coding_system, str->eol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2302 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2303
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2304 void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2305 set_decoding_stream_coding_system (Lstream *lstr, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2306 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2307 Lisp_Coding_System *cs = XCODING_SYSTEM (codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2308 struct decoding_stream *str = DECODING_STREAM_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2309 str->codesys = cs;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2310 if (CODING_SYSTEM_EOL_TYPE (cs) != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2311 str->eol_type = CODING_SYSTEM_EOL_TYPE (cs);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2312 reset_decoding_stream (str);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2313 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2314
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2315 /* WARNING WARNING WARNING WARNING!!!!! If you open up a decoding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2316 stream for writing, no automatic code detection will be performed.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2317 The reason for this is that automatic code detection requires a
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2318 seekable input. Things will also fail if you open a decoding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2319 stream for reading using a non-fully-specified coding system and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2320 a non-seekable input stream. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2321
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2322 static Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2323 make_decoding_stream_1 (Lstream *stream, Lisp_Object codesys,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2324 const char *mode)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2325 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2326 Lstream *lstr = Lstream_new (lstream_decoding, mode);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2327 struct decoding_stream *str = DECODING_STREAM_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2328 Lisp_Object obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2329
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2330 xzero (*str);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2331 str->other_end = stream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2332 str->runoff = (unsigned_char_dynarr *) Dynarr_new (unsigned_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2333 str->eol_type = EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2334 if (!strcmp (mode, "r")
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2335 && Lstream_seekable_p (stream))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2336 /* We can determine the coding system now. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2337 determine_real_coding_system (stream, &codesys, &str->eol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2338 set_decoding_stream_coding_system (lstr, codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2339 str->decst.eol_type = str->eol_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2340 str->decst.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2341 XSETLSTREAM (obj, lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2342 return obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2343 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2344
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2345 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2346 make_decoding_input_stream (Lstream *stream, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2347 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2348 return make_decoding_stream_1 (stream, codesys, "r");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2349 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2350
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2351 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2352 make_decoding_output_stream (Lstream *stream, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2353 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2354 return make_decoding_stream_1 (stream, codesys, "w");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2355 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2356
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2357 /* Note: the decode_coding_* functions all take the same
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2358 arguments as mule_decode(), which is to say some SRC data of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2359 size N, which is to be stored into dynamic array DST.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2360 DECODING is the stream within which the decoding is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2361 taking place, but no data is actually read from or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2362 written to that stream; that is handled in decoding_reader()
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2363 or decoding_writer(). This allows the same functions to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2364 be used for both reading and writing. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2365
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2366 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2367 mule_decode (Lstream *decoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2368 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2369 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2370 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2371
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2372 /* If necessary, do encoding-detection now. We do this when
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2373 we're a writing stream or a non-seekable reading stream,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2374 meaning that we can't just process the whole input,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2375 rewind, and start over. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2376
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2377 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2378 str->eol_type == EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2379 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2380 Lisp_Object codesys;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2381
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2382 XSETCODING_SYSTEM (codesys, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2383 detect_coding_type (&str->decst, src, n,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2384 CODING_SYSTEM_TYPE (str->codesys) !=
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2385 CODESYS_AUTODETECT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2386 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2387 str->decst.mask != ~0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2388 /* #### This is cheesy. What we really ought to do is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2389 buffer up a certain amount of data so as to get a
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2390 less random result. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2391 codesys = coding_system_from_mask (str->decst.mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2392 str->eol_type = str->decst.eol_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2393 if (XCODING_SYSTEM (codesys) != str->codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2394 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2395 /* Preserve the CODING_STATE_END flag in case it was set.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2396 If we erase it, bad things might happen. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2397 int was_end = str->flags & CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2398 set_decoding_stream_coding_system (decoding, codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2399 if (was_end)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2400 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2401 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2402 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2403
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2404 switch (CODING_SYSTEM_TYPE (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2405 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2406 #ifdef DEBUG_XEMACS
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2407 case CODESYS_INTERNAL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2408 Dynarr_add_many (dst, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2409 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2410 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2411 case CODESYS_AUTODETECT:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2412 /* If we got this far and still haven't decided on the coding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2413 system, then do no conversion. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2414 case CODESYS_NO_CONVERSION:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2415 decode_coding_no_conversion (decoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2416 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2417 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2418 case CODESYS_SHIFT_JIS:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2419 decode_coding_sjis (decoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2420 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2421 case CODESYS_BIG5:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2422 decode_coding_big5 (decoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2423 break;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2424 case CODESYS_UCS4:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2425 decode_coding_ucs4 (decoding, src, dst, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2426 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2427 case CODESYS_UTF8:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2428 decode_coding_utf8 (decoding, src, dst, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2429 break;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2430 case CODESYS_CCL:
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2431 str->ccl.last_block = str->flags & CODING_STATE_END;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2432 ccl_driver (&str->ccl, src, dst, n, 0, CCL_MODE_DECODING);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2433 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2434 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2435 decode_coding_iso2022 (decoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2436 break;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2437 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2438 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2439 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2440 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2441 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2442
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2443 DEFUN ("decode-coding-region", Fdecode_coding_region, 3, 4, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2444 Decode the text between START and END which is encoded in CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2445 This is useful if you've read in encoded text from a file without decoding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2446 it (e.g. you read in a JIS-formatted file but used the `binary' or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2447 `no-conversion' coding system, so that it shows up as "^[$B!<!+^[(B").
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2448 Return length of decoded text.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2449 BUFFER defaults to the current buffer if unspecified.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2450 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2451 (start, end, coding_system, buffer))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2452 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2453 Bufpos b, e;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2454 struct buffer *buf = decode_buffer (buffer, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2455 Lisp_Object instream, lb_outstream, de_outstream, outstream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2456 Lstream *istr, *ostr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2457 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2458
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2459 get_buffer_range_char (buf, start, end, &b, &e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2460
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2461 barf_if_buffer_read_only (buf, b, e);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2462
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2463 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2464 instream = make_lisp_buffer_input_stream (buf, b, e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2465 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2466 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2467 coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2468 outstream = make_encoding_output_stream (XLSTREAM (de_outstream),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2469 Fget_coding_system (Qbinary));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2470 istr = XLSTREAM (instream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2471 ostr = XLSTREAM (outstream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2472 GCPRO4 (instream, lb_outstream, de_outstream, outstream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2473
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2474 /* The chain of streams looks like this:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2475
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2476 [BUFFER] <----- send through
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2477 ------> [ENCODE AS BINARY]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2478 ------> [DECODE AS SPECIFIED]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2479 ------> [BUFFER]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2480 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2481
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2482 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2483 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2484 char tempbuf[1024]; /* some random amount */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2485 Bufpos newpos, even_newer_pos;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2486 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2487 ssize_t size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2488
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2489 if (!size_in_bytes)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2490 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2491 newpos = lisp_buffer_stream_startpos (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2492 Lstream_write (ostr, tempbuf, size_in_bytes);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2493 even_newer_pos = lisp_buffer_stream_startpos (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2494 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2495 even_newer_pos, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2496 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2497 Lstream_close (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2498 Lstream_close (ostr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2499 UNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2500 Lstream_delete (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2501 Lstream_delete (ostr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2502 Lstream_delete (XLSTREAM (de_outstream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2503 Lstream_delete (XLSTREAM (lb_outstream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2504 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2505 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2506
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2507
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2508 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2509 /* Converting to an external encoding ("encoding") */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2510 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2511
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2512 /* An encoding stream is an output stream. When you create the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2513 stream, you specify the coding system that governs the encoding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2514 and another stream that the resulting encoded data is to be
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2515 sent to, and then start sending data to it. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2516
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2517 #define ENCODING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, encoding)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2518
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2519 struct encoding_stream
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2520 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2521 /* Coding system that governs the conversion. */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2522 Lisp_Coding_System *codesys;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2523
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2524 /* Stream that we read the encoded data from or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2525 write the decoded data to. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2526 Lstream *other_end;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2527
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2528 /* If we are reading, then we can return only a fixed amount of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2529 data, so if the conversion resulted in too much data, we store it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2530 here for retrieval the next time around. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2531 unsigned_char_dynarr *runoff;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2532
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2533 /* FLAGS holds flags indicating the current state of the encoding.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2534 Some of these flags are dependent on the coding system. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2535 unsigned int flags;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2536
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2537 /* CH holds a partially built-up character. Since we only deal
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2538 with one- and two-byte characters at the moment, we only use
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2539 this to store the first byte of a two-byte character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2540 unsigned int ch;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2541 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2542 /* Additional information used by the ISO2022 encoder. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2543 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2544 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2545 /* CHARSET holds the character sets currently assigned to the G0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2546 through G3 registers. It is initialized from the array
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2547 INITIAL_CHARSET in CODESYS. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2548 Lisp_Object charset[4];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2549
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2550 /* Which registers are currently invoked into the left (GL) and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2551 right (GR) halves of the 8-bit encoding space? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2552 int register_left, register_right;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2553
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2554 /* Whether we need to explicitly designate the charset in the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2555 G? register before using it. It is initialized from the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2556 array FORCE_CHARSET_ON_OUTPUT in CODESYS. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2557 unsigned char force_charset_on_output[4];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2558
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2559 /* Other state variables that need to be preserved across
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2560 invocations. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2561 Lisp_Object current_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2562 int current_half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2563 int current_char_boundary;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2564 } iso2022;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2565
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2566 /* Additional information (the state of the running CCL program)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2567 used by the CCL encoder. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2568 struct ccl_program ccl;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2569 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2570 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2571
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2572 static ssize_t encoding_reader (Lstream *stream, unsigned char *data, size_t size);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2573 static ssize_t encoding_writer (Lstream *stream, const unsigned char *data,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2574 size_t size);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2575 static int encoding_rewinder (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2576 static int encoding_seekable_p (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2577 static int encoding_flusher (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2578 static int encoding_closer (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2579
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2580 static Lisp_Object encoding_marker (Lisp_Object stream);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2581
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2582 DEFINE_LSTREAM_IMPLEMENTATION ("encoding", lstream_encoding,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2583 sizeof (struct encoding_stream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2584
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2585 static Lisp_Object
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2586 encoding_marker (Lisp_Object stream)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2587 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2588 Lstream *str = ENCODING_STREAM_DATA (XLSTREAM (stream))->other_end;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2589 Lisp_Object str_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2590
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2591 /* We do not need to mark the coding systems or charsets stored
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2592 within the stream because they are stored in a global list
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2593 and automatically marked. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2594
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2595 XSETLSTREAM (str_obj, str);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2596 mark_object (str_obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2597 if (str->imp->marker)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2598 return (str->imp->marker) (str_obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2599 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2600 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2601 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2602
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2603 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2604 so we read data from the other end, encode it, and store it into DATA. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2605
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2606 static ssize_t
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2607 encoding_reader (Lstream *stream, unsigned char *data, size_t size)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2608 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2609 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2610 unsigned char *orig_data = data;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2611 ssize_t read_size;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2612 int error_occurred = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2613
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2614 /* We need to interface to mule_encode(), which expects to take some
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2615 amount of data and store the result into a Dynarr. We have
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2616 mule_encode() store into str->runoff, and take data from there
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2617 as necessary. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2618
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2619 /* We loop until we have enough data, reading chunks from the other
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2620 end and encoding it. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2621 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2622 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2623 /* Take data from the runoff if we can. Make sure to take at
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2624 most SIZE bytes, and delete the data from the runoff. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2625 if (Dynarr_length (str->runoff) > 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2626 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2627 int chunk = min ((int) size, Dynarr_length (str->runoff));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2628 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2629 Dynarr_delete_many (str->runoff, 0, chunk);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2630 data += chunk;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2631 size -= chunk;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2632 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2633
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2634 if (size == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2635 break; /* No more room for data */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2636
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2637 if (str->flags & CODING_STATE_END)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2638 /* This means that on the previous iteration, we hit the EOF on
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2639 the other end. We loop once more so that mule_encode() can
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2640 output any final stuff it may be holding, or any "go back
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2641 to a sane state" escape sequences. (This latter makes sense
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2642 during encoding.) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2643 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2644
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2645 /* Exhausted the runoff, so get some more. DATA at least SIZE bytes
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2646 left of storage in it, so it's OK to read directly into it.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2647 (We'll be overwriting above, after we've encoded it into the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2648 runoff.) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2649 read_size = Lstream_read (str->other_end, data, size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2650 if (read_size < 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2651 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2652 error_occurred = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2653 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2654 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2655 if (read_size == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2656 /* There might be some more end data produced in the translation.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2657 See the comment above. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2658 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2659 mule_encode (stream, data, str->runoff, read_size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2660 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2661
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2662 if (data == orig_data)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2663 return error_occurred ? -1 : 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2664 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2665 return data - orig_data;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2666 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2667
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2668 static ssize_t
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2669 encoding_writer (Lstream *stream, const unsigned char *data, size_t size)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2670 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2671 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2672 ssize_t retval;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2673
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2674 /* Encode all our data into the runoff, and then attempt to write
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2675 it all out to the other end. Remove whatever chunk we succeeded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2676 in writing. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2677 mule_encode (stream, data, str->runoff, size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2678 retval = Lstream_write (str->other_end, Dynarr_atp (str->runoff, 0),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2679 Dynarr_length (str->runoff));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2680 if (retval > 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2681 Dynarr_delete_many (str->runoff, 0, retval);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2682 /* Do NOT return retval. The return value indicates how much
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2683 of the incoming data was written, not how many bytes were
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2684 written. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2685 return size;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2686 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2687
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2688 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2689 reset_encoding_stream (struct encoding_stream *str)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2690 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2691 #ifdef MULE
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2692 switch (CODING_SYSTEM_TYPE (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2693 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2694 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2695 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2696 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2697
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2698 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2699 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2700 str->iso2022.charset[i] =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2701 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (str->codesys, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2702 str->iso2022.force_charset_on_output[i] =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2703 CODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT (str->codesys, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2704 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2705 str->iso2022.register_left = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2706 str->iso2022.register_right = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2707 str->iso2022.current_charset = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2708 str->iso2022.current_half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2709 str->iso2022.current_char_boundary = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2710 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2711 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2712 case CODESYS_CCL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2713 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_ENCODE (str->codesys));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2714 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2715 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2716 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2717 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2718 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2719
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2720 str->flags = str->ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2721 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2722
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2723 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2724 encoding_rewinder (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2725 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2726 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2727 reset_encoding_stream (str);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2728 Dynarr_reset (str->runoff);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2729 return Lstream_rewind (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2730 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2731
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2732 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2733 encoding_seekable_p (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2734 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2735 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2736 return Lstream_seekable_p (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2737 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2738
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2739 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2740 encoding_flusher (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2741 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2742 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2743 return Lstream_flush (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2744 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2745
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2746 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2747 encoding_closer (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2748 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2749 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2750 if (stream->flags & LSTREAM_FL_WRITE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2751 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2752 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2753 encoding_writer (stream, 0, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2754 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2755 Dynarr_free (str->runoff);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2756 return Lstream_close (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2757 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2758
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2759 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2760 encoding_stream_coding_system (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2761 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2762 Lisp_Object coding_system;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2763 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2764
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2765 XSETCODING_SYSTEM (coding_system, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2766 return coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2767 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2768
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2769 void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2770 set_encoding_stream_coding_system (Lstream *lstr, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2771 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2772 Lisp_Coding_System *cs = XCODING_SYSTEM (codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2773 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2774 str->codesys = cs;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2775 reset_encoding_stream (str);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2776 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2777
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2778 static Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2779 make_encoding_stream_1 (Lstream *stream, Lisp_Object codesys,
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2780 const char *mode)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2781 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2782 Lstream *lstr = Lstream_new (lstream_encoding, mode);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2783 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2784 Lisp_Object obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2785
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2786 xzero (*str);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2787 str->runoff = Dynarr_new (unsigned_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2788 str->other_end = stream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2789 set_encoding_stream_coding_system (lstr, codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2790 XSETLSTREAM (obj, lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2791 return obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2792 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2793
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2794 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2795 make_encoding_input_stream (Lstream *stream, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2796 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2797 return make_encoding_stream_1 (stream, codesys, "r");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2798 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2799
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2800 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2801 make_encoding_output_stream (Lstream *stream, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2802 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2803 return make_encoding_stream_1 (stream, codesys, "w");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2804 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2805
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2806 /* Convert N bytes of internally-formatted data stored in SRC to an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2807 external format, according to the encoding stream ENCODING.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2808 Store the encoded data into DST. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2809
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2810 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2811 mule_encode (Lstream *encoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2812 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2813 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2814 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2815
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2816 switch (CODING_SYSTEM_TYPE (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2817 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2818 #ifdef DEBUG_XEMACS
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2819 case CODESYS_INTERNAL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2820 Dynarr_add_many (dst, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2821 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2822 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2823 case CODESYS_AUTODETECT:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2824 /* If we got this far and still haven't decided on the coding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2825 system, then do no conversion. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2826 case CODESYS_NO_CONVERSION:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2827 encode_coding_no_conversion (encoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2828 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2829 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2830 case CODESYS_SHIFT_JIS:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2831 encode_coding_sjis (encoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2832 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2833 case CODESYS_BIG5:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2834 encode_coding_big5 (encoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2835 break;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2836 case CODESYS_UCS4:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2837 encode_coding_ucs4 (encoding, src, dst, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2838 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2839 case CODESYS_UTF8:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2840 encode_coding_utf8 (encoding, src, dst, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2841 break;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2842 case CODESYS_CCL:
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2843 str->ccl.last_block = str->flags & CODING_STATE_END;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2844 ccl_driver (&str->ccl, src, dst, n, 0, CCL_MODE_ENCODING);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2845 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2846 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2847 encode_coding_iso2022 (encoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2848 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2849 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2850 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2851 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2852 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2853 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2854
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2855 DEFUN ("encode-coding-region", Fencode_coding_region, 3, 4, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2856 Encode the text between START and END using CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2857 This will, for example, convert Japanese characters into stuff such as
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2858 "^[$B!<!+^[(B" if you use the JIS encoding. Return length of encoded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2859 text. BUFFER defaults to the current buffer if unspecified.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2860 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2861 (start, end, coding_system, buffer))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2862 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2863 Bufpos b, e;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2864 struct buffer *buf = decode_buffer (buffer, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2865 Lisp_Object instream, lb_outstream, de_outstream, outstream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2866 Lstream *istr, *ostr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2867 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2868
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2869 get_buffer_range_char (buf, start, end, &b, &e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2870
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2871 barf_if_buffer_read_only (buf, b, e);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2872
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2873 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2874 instream = make_lisp_buffer_input_stream (buf, b, e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2875 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2876 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2877 Fget_coding_system (Qbinary));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2878 outstream = make_encoding_output_stream (XLSTREAM (de_outstream),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2879 coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2880 istr = XLSTREAM (instream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2881 ostr = XLSTREAM (outstream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2882 GCPRO4 (instream, outstream, de_outstream, lb_outstream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2883 /* The chain of streams looks like this:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2884
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2885 [BUFFER] <----- send through
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2886 ------> [ENCODE AS SPECIFIED]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2887 ------> [DECODE AS BINARY]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2888 ------> [BUFFER]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2889 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2890 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2891 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2892 char tempbuf[1024]; /* some random amount */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2893 Bufpos newpos, even_newer_pos;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2894 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2895 ssize_t size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2896
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2897 if (!size_in_bytes)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2898 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2899 newpos = lisp_buffer_stream_startpos (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2900 Lstream_write (ostr, tempbuf, size_in_bytes);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2901 even_newer_pos = lisp_buffer_stream_startpos (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2902 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2903 even_newer_pos, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2904 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2905
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2906 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2907 Charcount retlen =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2908 lisp_buffer_stream_startpos (XLSTREAM (instream)) - b;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2909 Lstream_close (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2910 Lstream_close (ostr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2911 UNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2912 Lstream_delete (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2913 Lstream_delete (ostr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2914 Lstream_delete (XLSTREAM (de_outstream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2915 Lstream_delete (XLSTREAM (lb_outstream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2916 return make_int (retlen);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2917 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2918 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2919
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2920 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2921
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2922 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2923 /* Shift-JIS methods */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2924 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2925
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2926 /* Shift-JIS is a coding system encoding three character sets: ASCII, right
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2927 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2928 as is. A character of JISX0201-Kana (DIMENSION1_CHARS94 character set) is
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2929 encoded by "position-code + 0x80". A character of JISX0208
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2930 (DIMENSION2_CHARS94 character set) is encoded in 2-byte but two
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2931 position-codes are divided and shifted so that it fit in the range
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2932 below.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2933
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2934 --- CODE RANGE of Shift-JIS ---
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2935 (character set) (range)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2936 ASCII 0x00 .. 0x7F
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2937 JISX0201-Kana 0xA0 .. 0xDF
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2938 JISX0208 (1st byte) 0x80 .. 0x9F and 0xE0 .. 0xEF
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2939 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2940 -------------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2941
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2942 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2943
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2944 /* Is this the first byte of a Shift-JIS two-byte char? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2945
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2946 #define BYTE_SJIS_TWO_BYTE_1_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2947 (((c) >= 0x81 && (c) <= 0x9F) || ((c) >= 0xE0 && (c) <= 0xEF))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2948
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2949 /* Is this the second byte of a Shift-JIS two-byte char? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2950
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2951 #define BYTE_SJIS_TWO_BYTE_2_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2952 (((c) >= 0x40 && (c) <= 0x7E) || ((c) >= 0x80 && (c) <= 0xFC))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2953
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2954 #define BYTE_SJIS_KATAKANA_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2955 ((c) >= 0xA1 && (c) <= 0xDF)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2956
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2957 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2958 detect_coding_sjis (struct detection_state *st, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2959 unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2960 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2961 int c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2962
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2963 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2964 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2965 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2966 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2967 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2968 if (st->shift_jis.in_second_byte)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2969 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2970 st->shift_jis.in_second_byte = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2971 if (c < 0x40)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2972 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2973 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2974 else if ((c >= 0x80 && c < 0xA0) || c >= 0xE0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2975 st->shift_jis.in_second_byte = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2976 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2977 return CODING_CATEGORY_SHIFT_JIS_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2978 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2979
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2980 /* Convert Shift-JIS data to internal format. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2981
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2982 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
2983 decode_coding_sjis (Lstream *decoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2984 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2985 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2986 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2987 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2988 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2989 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2990 eol_type_t eol_type = str->eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2991
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2992 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2993 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2994 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2995
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2996 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2997 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2998 /* Previous character was first byte of Shift-JIS Kanji char. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2999 if (BYTE_SJIS_TWO_BYTE_2_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3000 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3001 unsigned char e1, e2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3002
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3003 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3004 DECODE_SJIS (ch, c, e1, e2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3005 Dynarr_add (dst, e1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3006 Dynarr_add (dst, e2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3007 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3008 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3009 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3010 DECODE_ADD_BINARY_CHAR (ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3011 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3012 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3013 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3014 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3015 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3016 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3017 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3018 if (BYTE_SJIS_TWO_BYTE_1_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3019 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3020 else if (BYTE_SJIS_KATAKANA_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3021 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3022 Dynarr_add (dst, LEADING_BYTE_KATAKANA_JISX0201);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3023 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3024 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3025 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3026 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3027 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3028 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3029 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3030
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3031 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3032
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3033 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3034 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3035 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3036
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3037 /* Convert internally-formatted data to Shift-JIS. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3038
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3039 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3040 encode_coding_sjis (Lstream *encoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3041 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3042 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3043 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3044 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3045 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3046 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3047 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3048
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3049 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3050 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3051 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3052 if (c == '\n')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3053 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3054 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3055 Dynarr_add (dst, '\r');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3056 if (eol_type != EOL_CR)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3057 Dynarr_add (dst, '\n');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3058 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3059 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3060 else if (BYTE_ASCII_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3061 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3062 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3063 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3064 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3065 else if (BUFBYTE_LEADING_BYTE_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3066 ch = (c == LEADING_BYTE_KATAKANA_JISX0201 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3067 c == LEADING_BYTE_JAPANESE_JISX0208_1978 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3068 c == LEADING_BYTE_JAPANESE_JISX0208) ? c : 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3069 else if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3070 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3071 if (ch == LEADING_BYTE_KATAKANA_JISX0201)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3072 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3073 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3074 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3075 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3076 else if (ch == LEADING_BYTE_JAPANESE_JISX0208_1978 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3077 ch == LEADING_BYTE_JAPANESE_JISX0208)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3078 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3079 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3080 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3081 unsigned char j1, j2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3082 ENCODE_SJIS (ch, c, j1, j2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3083 Dynarr_add (dst, j1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3084 Dynarr_add (dst, j2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3085 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3086 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3087 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3088 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3089
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3090 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3091 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3092 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3093
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3094 DEFUN ("decode-shift-jis-char", Fdecode_shift_jis_char, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3095 Decode a JISX0208 character of Shift-JIS coding-system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3096 CODE is the character code in Shift-JIS as a cons of type bytes.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3097 Return the corresponding character.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3098 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3099 (code))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3100 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3101 unsigned char c1, c2, s1, s2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3102
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3103 CHECK_CONS (code);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3104 CHECK_INT (XCAR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3105 CHECK_INT (XCDR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3106 s1 = XINT (XCAR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3107 s2 = XINT (XCDR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3108 if (BYTE_SJIS_TWO_BYTE_1_P (s1) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3109 BYTE_SJIS_TWO_BYTE_2_P (s2))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3110 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3111 DECODE_SJIS (s1, s2, c1, c2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3112 return make_char (MAKE_CHAR (Vcharset_japanese_jisx0208,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3113 c1 & 0x7F, c2 & 0x7F));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3114 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3115 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3116 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3117 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3118
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3119 DEFUN ("encode-shift-jis-char", Fencode_shift_jis_char, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3120 Encode a JISX0208 character CHAR to SHIFT-JIS coding-system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3121 Return the corresponding character code in SHIFT-JIS as a cons of two bytes.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3122 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3123 (ch))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3124 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3125 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3126 int c1, c2, s1, s2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3127
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3128 CHECK_CHAR_COERCE_INT (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3129 BREAKUP_CHAR (XCHAR (ch), charset, c1, c2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3130 if (EQ (charset, Vcharset_japanese_jisx0208))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3131 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3132 ENCODE_SJIS (c1 | 0x80, c2 | 0x80, s1, s2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3133 return Fcons (make_int (s1), make_int (s2));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3134 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3135 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3136 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3137 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3138
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3139
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3140 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3141 /* Big5 methods */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3142 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3143
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3144 /* BIG5 is a coding system encoding two character sets: ASCII and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3145 Big5. An ASCII character is encoded as is. Big5 is a two-byte
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3146 character set and is encoded in two-byte.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3147
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3148 --- CODE RANGE of BIG5 ---
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3149 (character set) (range)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3150 ASCII 0x00 .. 0x7F
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3151 Big5 (1st byte) 0xA1 .. 0xFE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3152 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3153 --------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3154
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3155 Since the number of characters in Big5 is larger than maximum
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3156 characters in Emacs' charset (96x96), it can't be handled as one
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
3157 charset. So, in Emacs, Big5 is divided into two: `charset-big5-1'
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3158 and `charset-big5-2'. Both <type>s are DIMENSION2_CHARS94. The former
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3159 contains frequently used characters and the latter contains less
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3160 frequently used characters. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3161
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3162 #define BYTE_BIG5_TWO_BYTE_1_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3163 ((c) >= 0xA1 && (c) <= 0xFE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3164
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3165 /* Is this the second byte of a Shift-JIS two-byte char? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3166
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3167 #define BYTE_BIG5_TWO_BYTE_2_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3168 (((c) >= 0x40 && (c) <= 0x7E) || ((c) >= 0xA1 && (c) <= 0xFE))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3169
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3170 /* Number of Big5 characters which have the same code in 1st byte. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3171
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3172 #define BIG5_SAME_ROW (0xFF - 0xA1 + 0x7F - 0x40)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3173
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3174 /* Code conversion macros. These are macros because they are used in
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3175 inner loops during code conversion.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3176
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3177 Note that temporary variables in macros introduce the classic
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3178 dynamic-scoping problems with variable names. We use capital-
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3179 lettered variables in the assumption that XEmacs does not use
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3180 capital letters in variables except in a very formalized way
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3181 (e.g. Qstring). */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3182
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3183 /* Convert Big5 code (b1, b2) into its internal string representation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3184 (lb, c1, c2). */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3185
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3186 /* There is a much simpler way to split the Big5 charset into two.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3187 For the moment I'm going to leave the algorithm as-is because it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3188 claims to separate out the most-used characters into a single
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3189 charset, which perhaps will lead to optimizations in various
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3190 places.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3191
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3192 The way the algorithm works is something like this:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3193
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3194 Big5 can be viewed as a 94x157 charset, where the row is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3195 encoded into the bytes 0xA1 .. 0xFE and the column is encoded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3196 into the bytes 0x40 .. 0x7E and 0xA1 .. 0xFE. As for frequency,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3197 the split between low and high column numbers is apparently
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3198 meaningless; ascending rows produce less and less frequent chars.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3199 Therefore, we assign the lower half of rows (0xA1 .. 0xC8) to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3200 the first charset, and the upper half (0xC9 .. 0xFE) to the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3201 second. To do the conversion, we convert the character into
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3202 a single number where 0 .. 156 is the first row, 157 .. 313
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3203 is the second, etc. That way, the characters are ordered by
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3204 decreasing frequency. Then we just chop the space in two
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3205 and coerce the result into a 94x94 space.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3206 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3207
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3208 #define DECODE_BIG5(b1, b2, lb, c1, c2) do \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3209 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3210 int B1 = b1, B2 = b2; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3211 unsigned int I \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3212 = (B1 - 0xA1) * BIG5_SAME_ROW + B2 - (B2 < 0x7F ? 0x40 : 0x62); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3213 \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3214 if (B1 < 0xC9) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3215 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3216 lb = LEADING_BYTE_CHINESE_BIG5_1; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3217 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3218 else \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3219 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3220 lb = LEADING_BYTE_CHINESE_BIG5_2; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3221 I -= (BIG5_SAME_ROW) * (0xC9 - 0xA1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3222 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3223 c1 = I / (0xFF - 0xA1) + 0xA1; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3224 c2 = I % (0xFF - 0xA1) + 0xA1; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3225 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3226
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3227 /* Convert the internal string representation of a Big5 character
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3228 (lb, c1, c2) into Big5 code (b1, b2). */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3229
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3230 #define ENCODE_BIG5(lb, c1, c2, b1, b2) do \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3231 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3232 unsigned int I = ((c1) - 0xA1) * (0xFF - 0xA1) + ((c2) - 0xA1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3233 \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3234 if (lb == LEADING_BYTE_CHINESE_BIG5_2) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3235 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3236 I += BIG5_SAME_ROW * (0xC9 - 0xA1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3237 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3238 b1 = I / BIG5_SAME_ROW + 0xA1; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3239 b2 = I % BIG5_SAME_ROW; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3240 b2 += b2 < 0x3F ? 0x40 : 0x62; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3241 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3242
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3243 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3244 detect_coding_big5 (struct detection_state *st, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3245 unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3246 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3247 int c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3248
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3249 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3250 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3251 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3252 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3253 (c >= 0x80 && c <= 0xA0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3254 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3255 if (st->big5.in_second_byte)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3256 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3257 st->big5.in_second_byte = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3258 if (c < 0x40 || (c >= 0x80 && c <= 0xA0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3259 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3260 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3261 else if (c >= 0xA1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3262 st->big5.in_second_byte = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3263 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3264 return CODING_CATEGORY_BIG5_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3265 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3266
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3267 /* Convert Big5 data to internal format. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3268
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3269 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3270 decode_coding_big5 (Lstream *decoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3271 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3272 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3273 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3274 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3275 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3276 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3277 eol_type_t eol_type = str->eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3278
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3279 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3280 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3281 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3282 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3283 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3284 /* Previous character was first byte of Big5 char. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3285 if (BYTE_BIG5_TWO_BYTE_2_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3286 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3287 unsigned char b1, b2, b3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3288 DECODE_BIG5 (ch, c, b1, b2, b3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3289 Dynarr_add (dst, b1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3290 Dynarr_add (dst, b2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3291 Dynarr_add (dst, b3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3292 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3293 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3294 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3295 DECODE_ADD_BINARY_CHAR (ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3296 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3297 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3298 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3299 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3300 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3301 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3302 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3303 if (BYTE_BIG5_TWO_BYTE_1_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3304 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3305 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3306 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3307 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3308 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3309 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3310
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3311 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3312
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3313 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3314 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3315 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3316
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3317 /* Convert internally-formatted data to Big5. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3318
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3319 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3320 encode_coding_big5 (Lstream *encoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3321 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3322 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3323 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3324 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3325 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3326 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3327 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3328
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3329 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3330 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3331 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3332 if (c == '\n')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3333 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3334 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3335 Dynarr_add (dst, '\r');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3336 if (eol_type != EOL_CR)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3337 Dynarr_add (dst, '\n');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3338 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3339 else if (BYTE_ASCII_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3340 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3341 /* ASCII. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3342 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3343 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3344 else if (BUFBYTE_LEADING_BYTE_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3345 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3346 if (c == LEADING_BYTE_CHINESE_BIG5_1 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3347 c == LEADING_BYTE_CHINESE_BIG5_2)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3348 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3349 /* A recognized leading byte. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3350 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3351 continue; /* not done with this character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3352 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3353 /* otherwise just ignore this character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3354 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3355 else if (ch == LEADING_BYTE_CHINESE_BIG5_1 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3356 ch == LEADING_BYTE_CHINESE_BIG5_2)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3357 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3358 /* Previous char was a recognized leading byte. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3359 ch = (ch << 8) | c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3360 continue; /* not done with this character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3361 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3362 else if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3363 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3364 /* Encountering second byte of a Big5 character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3365 unsigned char b1, b2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3366
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3367 ENCODE_BIG5 (ch >> 8, ch & 0xFF, c, b1, b2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3368 Dynarr_add (dst, b1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3369 Dynarr_add (dst, b2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3370 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3371
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3372 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3373 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3374
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3375 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3376 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3377 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3378
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3379
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3380 DEFUN ("decode-big5-char", Fdecode_big5_char, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3381 Decode a Big5 character CODE of BIG5 coding-system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3382 CODE is the character code in BIG5, a cons of two integers.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3383 Return the corresponding character.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3384 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3385 (code))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3386 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3387 unsigned char c1, c2, b1, b2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3388
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3389 CHECK_CONS (code);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3390 CHECK_INT (XCAR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3391 CHECK_INT (XCDR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3392 b1 = XINT (XCAR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3393 b2 = XINT (XCDR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3394 if (BYTE_BIG5_TWO_BYTE_1_P (b1) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3395 BYTE_BIG5_TWO_BYTE_2_P (b2))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3396 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3397 int leading_byte;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3398 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3399 DECODE_BIG5 (b1, b2, leading_byte, c1, c2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3400 charset = CHARSET_BY_LEADING_BYTE (leading_byte);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3401 return make_char (MAKE_CHAR (charset, c1 & 0x7F, c2 & 0x7F));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3402 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3403 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3404 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3405 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3406
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3407 DEFUN ("encode-big5-char", Fencode_big5_char, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3408 Encode the Big5 character CH to BIG5 coding-system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3409 Return the corresponding character code in Big5.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3410 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3411 (ch))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3412 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3413 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3414 int c1, c2, b1, b2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3415
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3416 CHECK_CHAR_COERCE_INT (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3417 BREAKUP_CHAR (XCHAR (ch), charset, c1, c2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3418 if (EQ (charset, Vcharset_chinese_big5_1) ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3419 EQ (charset, Vcharset_chinese_big5_2))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3420 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3421 ENCODE_BIG5 (XCHARSET_LEADING_BYTE (charset), c1 | 0x80, c2 | 0x80,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3422 b1, b2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3423 return Fcons (make_int (b1), make_int (b2));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3424 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3425 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3426 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3427 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3428
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3429
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3430 /************************************************************************/
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3431 /* UCS-4 methods */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3432 /* */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3433 /* UCS-4 character codes are implemented as nonnegative integers. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3434 /* */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3435 /************************************************************************/
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3436
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3437
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3438 DEFUN ("set-ucs-char", Fset_ucs_char, 2, 2, 0, /*
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3439 Map UCS-4 code CODE to Mule character CHARACTER.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3440
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3441 Return T on success, NIL on failure.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3442 */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3443 (code, character))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3444 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3445 unsigned int c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3446
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3447 CHECK_CHAR (character);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3448 CHECK_INT (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3449 c = XINT (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3450
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3451 if (c < sizeof (fcd->ucs_to_mule_table))
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3452 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3453 fcd->ucs_to_mule_table[c] = character;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3454 return Qt;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3455 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3456 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3457 return Qnil;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3458 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3459
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3460 static Lisp_Object
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3461 ucs_to_char (unsigned long code)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3462 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3463 if (code < sizeof (fcd->ucs_to_mule_table))
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3464 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3465 return fcd->ucs_to_mule_table[code];
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3466 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3467 else if ((0xe00000 <= code) && (code <= 0xe00000 + 94 * 94 * 14))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3468 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3469 unsigned int c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3470
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3471 code -= 0xe00000;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3472 c = code % (94 * 94);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3473 return make_char
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3474 (MAKE_CHAR (CHARSET_BY_ATTRIBUTES
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3475 (CHARSET_TYPE_94X94, code / (94 * 94) + '@',
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3476 CHARSET_LEFT_TO_RIGHT),
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3477 c / 94 + 33, c % 94 + 33));
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3478 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3479 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3480 return Qnil;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3481 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3482
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3483 DEFUN ("ucs-char", Fucs_char, 1, 1, 0, /*
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3484 Return Mule character corresponding to UCS code CODE (a positive integer).
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3485 */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3486 (code))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3487 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3488 CHECK_NATNUM (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3489 return ucs_to_char (XINT (code));
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3490 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3491
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3492 DEFUN ("set-char-ucs", Fset_char_ucs, 2, 2, 0, /*
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3493 Map Mule character CHARACTER to UCS code CODE (a positive integer).
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3494 */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3495 (character, code))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3496 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3497 /* #### Isn't this gilding the lily? Fput_char_table checks its args.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3498 Fset_char_ucs is more restrictive on index arg, but should
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3499 check code arg in a char_table method. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3500 CHECK_CHAR (character);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3501 CHECK_NATNUM (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3502 return Fput_char_table (character, code, mule_to_ucs_table);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3503 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3504
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3505 DEFUN ("char-ucs", Fchar_ucs, 1, 1, 0, /*
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3506 Return the UCS code (a positive integer) corresponding to CHARACTER.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3507 */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3508 (character))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3509 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3510 return Fget_char_table (character, mule_to_ucs_table);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3511 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3512
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3513 /* Decode a UCS-4 character into a buffer. If the lookup fails, use
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3514 <GETA MARK> (U+3013) of JIS X 0208, which means correct character
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3515 is not found, instead.
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3516 #### do something more appropriate (use blob?)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3517 Danger, Will Robinson! Data loss. Should we signal user? */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3518 static void
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3519 decode_ucs4 (unsigned long ch, unsigned_char_dynarr *dst)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3520 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3521 Lisp_Object chr = ucs_to_char (ch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3522
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3523 if (! NILP (chr))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3524 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3525 Bufbyte work[MAX_EMCHAR_LEN];
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3526 int len;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3527
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3528 ch = XCHAR (chr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3529 len = (ch < 128) ?
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3530 simple_set_charptr_emchar (work, ch) :
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3531 non_ascii_set_charptr_emchar (work, ch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3532 Dynarr_add_many (dst, work, len);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3533 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3534 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3535 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3536 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3537 Dynarr_add (dst, 34 + 128);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3538 Dynarr_add (dst, 46 + 128);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3539 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3540 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3541
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3542 static unsigned long
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3543 mule_char_to_ucs4 (Lisp_Object charset,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3544 unsigned char h, unsigned char l)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3545 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3546 Lisp_Object code
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3547 = Fget_char_table (make_char (MAKE_CHAR (charset, h & 127, l & 127)),
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3548 mule_to_ucs_table);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3549
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3550 if (INTP (code))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3551 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3552 return XINT (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3553 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3554 else if ( (XCHARSET_DIMENSION (charset) == 2) &&
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3555 (XCHARSET_CHARS (charset) == 94) )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3556 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3557 unsigned char final = XCHARSET_FINAL (charset);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3558
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3559 if ( ('@' <= final) && (final < 0x7f) )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3560 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3561 return 0xe00000 + (final - '@') * 94 * 94
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3562 + ((h & 127) - 33) * 94 + (l & 127) - 33;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3563 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3564 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3565 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3566 return '?';
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3567 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3568 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3569 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3570 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3571 return '?';
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3572 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3573 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3574
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3575 static void
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3576 encode_ucs4 (Lisp_Object charset,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3577 unsigned char h, unsigned char l, unsigned_char_dynarr *dst)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3578 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3579 unsigned long code = mule_char_to_ucs4 (charset, h, l);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3580 Dynarr_add (dst, code >> 24);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3581 Dynarr_add (dst, (code >> 16) & 255);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3582 Dynarr_add (dst, (code >> 8) & 255);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3583 Dynarr_add (dst, code & 255);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3584 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3585
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3586 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3587 detect_coding_ucs4 (struct detection_state *st, const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3588 unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3589 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3590 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3591 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3592 int c = *src++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3593 switch (st->ucs4.in_byte)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3594 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3595 case 0:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3596 if (c >= 128)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3597 return 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3598 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3599 st->ucs4.in_byte++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3600 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3601 case 3:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3602 st->ucs4.in_byte = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3603 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3604 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3605 st->ucs4.in_byte++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3606 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3607 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3608 return CODING_CATEGORY_UCS4_MASK;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3609 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3610
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3611 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3612 decode_coding_ucs4 (Lstream *decoding, const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3613 unsigned_char_dynarr *dst, unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3614 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3615 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3616 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3617 unsigned int ch = str->ch;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3618 unsigned char counter = str->counter;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3619
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3620 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3621 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3622 unsigned char c = *src++;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3623 switch (counter)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3624 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3625 case 0:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3626 ch = c;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3627 counter = 3;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3628 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3629 case 1:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3630 decode_ucs4 ( ( ch << 8 ) | c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3631 ch = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3632 counter = 0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3633 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3634 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3635 ch = ( ch << 8 ) | c;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3636 counter--;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3637 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3638 }
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3639 if (counter & CODING_STATE_END)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3640 DECODE_OUTPUT_PARTIAL_CHAR (ch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3641
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3642 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3643 str->ch = ch;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3644 str->counter = counter;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3645 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3646
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3647 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3648 encode_coding_ucs4 (Lstream *encoding, const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3649 unsigned_char_dynarr *dst, unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3650 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3651 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3652 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3653 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3654 unsigned char char_boundary = str->iso2022.current_char_boundary;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3655 Lisp_Object charset = str->iso2022.current_charset;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3656
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3657 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3658 /* flags for handling composite chars. We do a little switcharoo
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3659 on the source while we're outputting the composite char. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3660 unsigned int saved_n = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3661 const unsigned char *saved_src = NULL;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3662 int in_composite = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3663
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3664 back_to_square_n:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3665 #endif
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3666
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3667 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3668 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3669 unsigned char c = *src++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3670
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3671 if (BYTE_ASCII_P (c))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3672 { /* Processing ASCII character */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3673 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3674 encode_ucs4 (Vcharset_ascii, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3675 char_boundary = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3676 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3677 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3678 { /* Processing Leading Byte */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3679 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3680 charset = CHARSET_BY_LEADING_BYTE (c);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3681 if (LEADING_BYTE_PREFIX_P(c))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3682 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3683 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3684 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3685 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3686 { /* Processing Non-ASCII character */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3687 char_boundary = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3688 if (EQ (charset, Vcharset_control_1))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3689 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3690 encode_ucs4 (Vcharset_control_1, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3691 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3692 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3693 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3694 switch (XCHARSET_REP_BYTES (charset))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3695 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3696 case 2:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3697 encode_ucs4 (charset, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3698 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3699 case 3:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3700 if (XCHARSET_PRIVATE_P (charset))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3701 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3702 encode_ucs4 (charset, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3703 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3704 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3705 else if (ch)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3706 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3707 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3708 if (EQ (charset, Vcharset_composite))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3709 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3710 if (in_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3711 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3712 /* #### Bother! We don't know how to
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3713 handle this yet. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3714 Dynarr_add (dst, 0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3715 Dynarr_add (dst, 0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3716 Dynarr_add (dst, 0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3717 Dynarr_add (dst, '~');
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3718 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3719 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3720 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3721 Emchar emch = MAKE_CHAR (Vcharset_composite,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3722 ch & 0x7F, c & 0x7F);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3723 Lisp_Object lstr = composite_char_string (emch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3724 saved_n = n;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3725 saved_src = src;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3726 in_composite = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3727 src = XSTRING_DATA (lstr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3728 n = XSTRING_LENGTH (lstr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3729 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3730 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3731 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3732 #endif /* ENABLE_COMPOSITE_CHARS */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3733 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3734 encode_ucs4(charset, ch, c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3735 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3736 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3737 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3738 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3739 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3740 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3741 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3742 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3743 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3744 case 4:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3745 if (ch)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3746 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3747 encode_ucs4 (charset, ch, c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3748 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3749 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3750 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3751 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3752 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3753 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3754 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3755 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3756 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3757 abort ();
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3758 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3759 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3760 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3761 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3762
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3763 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3764 if (in_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3765 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3766 n = saved_n;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3767 src = saved_src;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3768 in_composite = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3769 goto back_to_square_n; /* Wheeeeeeeee ..... */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3770 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3771 #endif /* ENABLE_COMPOSITE_CHARS */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3772
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3773 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3774 str->ch = ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3775 str->iso2022.current_char_boundary = char_boundary;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3776 str->iso2022.current_charset = charset;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3777
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3778 /* Verbum caro factum est! */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3779 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3780
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3781
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3782 /************************************************************************/
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3783 /* UTF-8 methods */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3784 /************************************************************************/
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3785
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3786 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3787 detect_coding_utf8 (struct detection_state *st, const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3788 unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3789 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3790 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3791 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3792 unsigned char c = *src++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3793 switch (st->utf8.in_byte)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3794 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3795 case 0:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3796 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3797 return 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3798 else if (c >= 0xfc)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3799 st->utf8.in_byte = 5;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3800 else if (c >= 0xf8)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3801 st->utf8.in_byte = 4;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3802 else if (c >= 0xf0)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3803 st->utf8.in_byte = 3;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3804 else if (c >= 0xe0)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3805 st->utf8.in_byte = 2;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3806 else if (c >= 0xc0)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3807 st->utf8.in_byte = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3808 else if (c >= 0x80)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3809 return 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3810 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3811 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3812 if ((c & 0xc0) != 0x80)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3813 return 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3814 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3815 st->utf8.in_byte--;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3816 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3817 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3818 return CODING_CATEGORY_UTF8_MASK;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3819 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3820
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3821 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3822 decode_coding_utf8 (Lstream *decoding, const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3823 unsigned_char_dynarr *dst, unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3824 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3825 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3826 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3827 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3828 eol_type_t eol_type = str->eol_type;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3829 unsigned char counter = str->counter;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3830
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3831 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3832 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3833 unsigned char c = *src++;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3834 switch (counter)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3835 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3836 case 0:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3837 if ( c >= 0xfc )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3838 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3839 ch = c & 0x01;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3840 counter = 5;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3841 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3842 else if ( c >= 0xf8 )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3843 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3844 ch = c & 0x03;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3845 counter = 4;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3846 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3847 else if ( c >= 0xf0 )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3848 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3849 ch = c & 0x07;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3850 counter = 3;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3851 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3852 else if ( c >= 0xe0 )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3853 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3854 ch = c & 0x0f;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3855 counter = 2;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3856 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3857 else if ( c >= 0xc0 )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3858 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3859 ch = c & 0x1f;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3860 counter = 1;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3861 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3862 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3863 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3864 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3865 decode_ucs4 (c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3866 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3867 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3868 case 1:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3869 ch = ( ch << 6 ) | ( c & 0x3f );
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3870 decode_ucs4 (ch, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3871 ch = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3872 counter = 0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3873 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3874 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3875 ch = ( ch << 6 ) | ( c & 0x3f );
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3876 counter--;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3877 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3878 label_continue_loop:;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3879 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3880
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3881 if (flags & CODING_STATE_END)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3882 DECODE_OUTPUT_PARTIAL_CHAR (ch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3883
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3884 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3885 str->ch = ch;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3886 str->counter = counter;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3887 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3888
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3889 static void
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3890 encode_utf8 (Lisp_Object charset,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3891 unsigned char h, unsigned char l, unsigned_char_dynarr *dst)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3892 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3893 unsigned long code = mule_char_to_ucs4 (charset, h, l);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3894 if ( code <= 0x7f )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3895 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3896 Dynarr_add (dst, code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3897 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3898 else if ( code <= 0x7ff )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3899 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3900 Dynarr_add (dst, (code >> 6) | 0xc0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3901 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3902 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3903 else if ( code <= 0xffff )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3904 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3905 Dynarr_add (dst, (code >> 12) | 0xe0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3906 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3907 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3908 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3909 else if ( code <= 0x1fffff )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3910 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3911 Dynarr_add (dst, (code >> 18) | 0xf0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3912 Dynarr_add (dst, ((code >> 12) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3913 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3914 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3915 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3916 else if ( code <= 0x3ffffff )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3917 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3918 Dynarr_add (dst, (code >> 24) | 0xf8);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3919 Dynarr_add (dst, ((code >> 18) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3920 Dynarr_add (dst, ((code >> 12) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3921 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3922 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3923 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3924 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3925 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3926 Dynarr_add (dst, (code >> 30) | 0xfc);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3927 Dynarr_add (dst, ((code >> 24) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3928 Dynarr_add (dst, ((code >> 18) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3929 Dynarr_add (dst, ((code >> 12) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3930 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3931 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3932 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3933 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3934
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3935 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3936 encode_coding_utf8 (Lstream *encoding, const unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3937 unsigned_char_dynarr *dst, unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3938 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3939 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3940 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3941 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3942 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3943 unsigned char char_boundary = str->iso2022.current_char_boundary;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3944 Lisp_Object charset = str->iso2022.current_charset;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3945
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3946 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3947 /* flags for handling composite chars. We do a little switcharoo
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3948 on the source while we're outputting the composite char. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3949 unsigned int saved_n = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3950 const unsigned char *saved_src = NULL;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3951 int in_composite = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3952
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3953 back_to_square_n:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3954 #endif /* ENABLE_COMPOSITE_CHARS */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3955
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3956 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3957 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3958 unsigned char c = *src++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3959
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3960 if (BYTE_ASCII_P (c))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3961 { /* Processing ASCII character */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3962 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3963 if (c == '\n')
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3964 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3965 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3966 Dynarr_add (dst, '\r');
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3967 if (eol_type != EOL_CR)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3968 Dynarr_add (dst, c);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3969 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3970 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3971 encode_utf8 (Vcharset_ascii, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3972 char_boundary = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3973 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3974 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3975 { /* Processing Leading Byte */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3976 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3977 charset = CHARSET_BY_LEADING_BYTE (c);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3978 if (LEADING_BYTE_PREFIX_P(c))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3979 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3980 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3981 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3982 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3983 { /* Processing Non-ASCII character */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3984 char_boundary = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3985 if (EQ (charset, Vcharset_control_1))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3986 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3987 encode_utf8 (Vcharset_control_1, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3988 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3989 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3990 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3991 switch (XCHARSET_REP_BYTES (charset))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3992 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3993 case 2:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3994 encode_utf8 (charset, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3995 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3996 case 3:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3997 if (XCHARSET_PRIVATE_P (charset))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3998 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3999 encode_utf8 (charset, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4000 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4001 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4002 else if (ch)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4003 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4004 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4005 if (EQ (charset, Vcharset_composite))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4006 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4007 if (in_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4008 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4009 /* #### Bother! We don't know how to
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4010 handle this yet. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4011 encode_utf8 (Vcharset_ascii, '~', 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4012 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4013 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4014 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4015 Emchar emch = MAKE_CHAR (Vcharset_composite,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4016 ch & 0x7F, c & 0x7F);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4017 Lisp_Object lstr = composite_char_string (emch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4018 saved_n = n;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4019 saved_src = src;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4020 in_composite = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4021 src = XSTRING_DATA (lstr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4022 n = XSTRING_LENGTH (lstr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4023 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4024 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4025 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4026 #endif /* ENABLE_COMPOSITE_CHARS */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4027 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4028 encode_utf8 (charset, ch, c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4029 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4030 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4031 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4032 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4033 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4034 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4035 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4036 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4037 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4038 case 4:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4039 if (ch)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4040 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4041 encode_utf8 (charset, ch, c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4042 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4043 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4044 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4045 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4046 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4047 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4048 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4049 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4050 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4051 abort ();
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4052 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4053 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4054 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4055 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4056
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4057 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4058 if (in_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4059 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4060 n = saved_n;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4061 src = saved_src;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4062 in_composite = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4063 goto back_to_square_n; /* Wheeeeeeeee ..... */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4064 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4065 #endif
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4066
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4067 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4068 str->ch = ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4069 str->iso2022.current_char_boundary = char_boundary;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4070 str->iso2022.current_charset = charset;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4071
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4072 /* Verbum caro factum est! */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4073 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4074
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4075
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4076 /************************************************************************/
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4077 /* ISO2022 methods */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4078 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4079
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4080 /* The following note describes the coding system ISO2022 briefly.
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4081 Since the intention of this note is to help understand the
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4082 functions in this file, some parts are NOT ACCURATE or OVERLY
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4083 SIMPLIFIED. For thorough understanding, please refer to the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4084 original document of ISO2022.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4085
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4086 ISO2022 provides many mechanisms to encode several character sets
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4087 in 7-bit and 8-bit environments. For 7-bit environments, all text
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4088 is encoded using bytes less than 128. This may make the encoded
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4089 text a little bit longer, but the text passes more easily through
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4090 several gateways, some of which strip off MSB (Most Signigant Bit).
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4091
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4092 There are two kinds of character sets: control character set and
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4093 graphic character set. The former contains control characters such
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4094 as `newline' and `escape' to provide control functions (control
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4095 functions are also provided by escape sequences). The latter
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4096 contains graphic characters such as 'A' and '-'. Emacs recognizes
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4097 two control character sets and many graphic character sets.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4098
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4099 Graphic character sets are classified into one of the following
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4100 four classes, according to the number of bytes (DIMENSION) and
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4101 number of characters in one dimension (CHARS) of the set:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4102 - DIMENSION1_CHARS94
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4103 - DIMENSION1_CHARS96
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4104 - DIMENSION2_CHARS94
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4105 - DIMENSION2_CHARS96
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4106
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4107 In addition, each character set is assigned an identification tag,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4108 unique for each set, called "final character" (denoted as <F>
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4109 hereafter). The <F> of each character set is decided by ECMA(*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4110 when it is registered in ISO. The code range of <F> is 0x30..0x7F
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4111 (0x30..0x3F are for private use only).
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4112
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4113 Note (*): ECMA = European Computer Manufacturers Association
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4114
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4115 Here are examples of graphic character set [NAME(<F>)]:
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4116 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ...
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4117 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ...
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4118 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ...
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4119 o DIMENSION2_CHARS96 -- none for the moment
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4120
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4121 A code area (1 byte = 8 bits) is divided into 4 areas, C0, GL, C1, and GR.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4122 C0 [0x00..0x1F] -- control character plane 0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4123 GL [0x20..0x7F] -- graphic character plane 0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4124 C1 [0x80..0x9F] -- control character plane 1
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4125 GR [0xA0..0xFF] -- graphic character plane 1
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4126
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4127 A control character set is directly designated and invoked to C0 or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4128 C1 by an escape sequence. The most common case is that:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4129 - ISO646's control character set is designated/invoked to C0, and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4130 - ISO6429's control character set is designated/invoked to C1,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4131 and usually these designations/invocations are omitted in encoded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4132 text. In a 7-bit environment, only C0 can be used, and a control
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4133 character for C1 is encoded by an appropriate escape sequence to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4134 fit into the environment. All control characters for C1 are
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4135 defined to have corresponding escape sequences.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4136
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4137 A graphic character set is at first designated to one of four
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4138 graphic registers (G0 through G3), then these graphic registers are
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4139 invoked to GL or GR. These designations and invocations can be
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4140 done independently. The most common case is that G0 is invoked to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4141 GL, G1 is invoked to GR, and ASCII is designated to G0. Usually
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4142 these invocations and designations are omitted in encoded text.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4143 In a 7-bit environment, only GL can be used.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4144
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4145 When a graphic character set of CHARS94 is invoked to GL, codes
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4146 0x20 and 0x7F of the GL area work as control characters SPACE and
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4147 DEL respectively, and codes 0xA0 and 0xFF of the GR area should not
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4148 be used.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4149
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4150 There are two ways of invocation: locking-shift and single-shift.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4151 With locking-shift, the invocation lasts until the next different
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4152 invocation, whereas with single-shift, the invocation affects the
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4153 following character only and doesn't affect the locking-shift
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4154 state. Invocations are done by the following control characters or
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4155 escape sequences:
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4156
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4157 ----------------------------------------------------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4158 abbrev function cntrl escape seq description
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4159 ----------------------------------------------------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4160 SI/LS0 (shift-in) 0x0F none invoke G0 into GL
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4161 SO/LS1 (shift-out) 0x0E none invoke G1 into GL
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4162 LS2 (locking-shift-2) none ESC 'n' invoke G2 into GL
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4163 LS3 (locking-shift-3) none ESC 'o' invoke G3 into GL
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4164 LS1R (locking-shift-1 right) none ESC '~' invoke G1 into GR (*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4165 LS2R (locking-shift-2 right) none ESC '}' invoke G2 into GR (*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4166 LS3R (locking-shift 3 right) none ESC '|' invoke G3 into GR (*)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4167 SS2 (single-shift-2) 0x8E ESC 'N' invoke G2 for one char
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4168 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4169 ----------------------------------------------------------------------
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4170 (*) These are not used by any known coding system.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4171
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4172 Control characters for these functions are defined by macros
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4173 ISO_CODE_XXX in `coding.h'.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4174
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4175 Designations are done by the following escape sequences:
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4176 ----------------------------------------------------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4177 escape sequence description
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4178 ----------------------------------------------------------------------
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4179 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4180 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4181 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4182 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4183 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4184 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4185 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4186 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4187 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4188 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4189 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4190 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4191 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4192 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4193 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4194 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4195 ----------------------------------------------------------------------
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4196
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4197 In this list, "DIMENSION1_CHARS94<F>" means a graphic character set
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4198 of dimension 1, chars 94, and final character <F>, etc...
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4199
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4200 Note (*): Although these designations are not allowed in ISO2022,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4201 Emacs accepts them on decoding, and produces them on encoding
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4202 CHARS96 character sets in a coding system which is characterized as
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4203 7-bit environment, non-locking-shift, and non-single-shift.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4204
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4205 Note (**): If <F> is '@', 'A', or 'B', the intermediate character
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4206 '(' can be omitted. We refer to this as "short-form" hereafter.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4207
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4208 Now you may notice that there are a lot of ways for encoding the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4209 same multilingual text in ISO2022. Actually, there exist many
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4210 coding systems such as Compound Text (used in X11's inter client
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4211 communication, ISO-2022-JP (used in Japanese internet), ISO-2022-KR
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4212 (used in Korean internet), EUC (Extended UNIX Code, used in Asian
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4213 localized platforms), and all of these are variants of ISO2022.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4214
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4215 In addition to the above, Emacs handles two more kinds of escape
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4216 sequences: ISO6429's direction specification and Emacs' private
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4217 sequence for specifying character composition.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4218
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4219 ISO6429's direction specification takes the following form:
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4220 o CSI ']' -- end of the current direction
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4221 o CSI '0' ']' -- end of the current direction
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4222 o CSI '1' ']' -- start of left-to-right text
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4223 o CSI '2' ']' -- start of right-to-left text
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4224 The control character CSI (0x9B: control sequence introducer) is
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4225 abbreviated to the escape sequence ESC '[' in a 7-bit environment.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4226
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4227 Character composition specification takes the following form:
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4228 o ESC '0' -- start character composition
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4229 o ESC '1' -- end character composition
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4230 Since these are not standard escape sequences of any ISO standard,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4231 their use with these meanings is restricted to Emacs only. */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4232
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4233 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4234 reset_iso2022 (Lisp_Object coding_system, struct iso2022_decoder *iso)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4235 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4236 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4237
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4238 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4239 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4240 if (!NILP (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4241 iso->charset[i] =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4242 XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4243 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4244 iso->charset[i] = Qt;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4245 iso->invalid_designated[i] = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4246 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4247 iso->esc = ISO_ESC_NOTHING;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4248 iso->esc_bytes_index = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4249 iso->register_left = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4250 iso->register_right = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4251 iso->switched_dir_and_no_valid_charset_yet = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4252 iso->invalid_switch_dir = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4253 iso->output_direction_sequence = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4254 iso->output_literally = 0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4255 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4256 if (iso->composite_chars)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4257 Dynarr_reset (iso->composite_chars);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4258 #endif
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4259 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4260
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4261 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4262 fit_to_be_escape_quoted (unsigned char c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4263 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4264 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4265 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4266 case ISO_CODE_ESC:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4267 case ISO_CODE_CSI:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4268 case ISO_CODE_SS2:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4269 case ISO_CODE_SS3:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4270 case ISO_CODE_SO:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4271 case ISO_CODE_SI:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4272 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4273
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4274 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4275 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4276 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4277 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4278
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4279 /* Parse one byte of an ISO2022 escape sequence.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4280 If the result is an invalid escape sequence, return 0 and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4281 do not change anything in STR. Otherwise, if the result is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4282 an incomplete escape sequence, update ISO2022.ESC and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4283 ISO2022.ESC_BYTES and return -1. Otherwise, update
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4284 all the state variables (but not ISO2022.ESC_BYTES) and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4285 return 1.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4286
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4287 If CHECK_INVALID_CHARSETS is non-zero, check for designation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4288 or invocation of an invalid character set and treat that as
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4289 an unrecognized escape sequence. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4290
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4291 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4292 parse_iso2022_esc (Lisp_Object codesys, struct iso2022_decoder *iso,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4293 unsigned char c, unsigned int *flags,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4294 int check_invalid_charsets)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4295 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4296 /* (1) If we're at the end of a designation sequence, CS is the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4297 charset being designated and REG is the register to designate
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4298 it to.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4299
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4300 (2) If we're at the end of a locking-shift sequence, REG is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4301 the register to invoke and HALF (0 == left, 1 == right) is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4302 the half to invoke it into.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4303
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4304 (3) If we're at the end of a single-shift sequence, REG is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4305 the register to invoke. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4306 Lisp_Object cs = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4307 int reg, half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4308
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4309 /* NOTE: This code does goto's all over the fucking place.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4310 The reason for this is that we're basically implementing
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4311 a state machine here, and hierarchical languages like C
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4312 don't really provide a clean way of doing this. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4313
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4314 if (! (*flags & CODING_STATE_ESCAPE))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4315 /* At beginning of escape sequence; we need to reset our
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4316 escape-state variables. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4317 iso->esc = ISO_ESC_NOTHING;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4318
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4319 iso->output_literally = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4320 iso->output_direction_sequence = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4321
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4322 switch (iso->esc)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4323 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4324 case ISO_ESC_NOTHING:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4325 iso->esc_bytes_index = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4326 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4327 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4328 case ISO_CODE_ESC: /* Start escape sequence */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4329 *flags |= CODING_STATE_ESCAPE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4330 iso->esc = ISO_ESC;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4331 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4332
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4333 case ISO_CODE_CSI: /* ISO6429 (specifying directionality) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4334 *flags |= CODING_STATE_ESCAPE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4335 iso->esc = ISO_ESC_5_11;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4336 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4337
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4338 case ISO_CODE_SO: /* locking shift 1 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4339 reg = 1; half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4340 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4341 case ISO_CODE_SI: /* locking shift 0 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4342 reg = 0; half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4343 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4344
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4345 case ISO_CODE_SS2: /* single shift */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4346 reg = 2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4347 goto single_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4348 case ISO_CODE_SS3: /* single shift */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4349 reg = 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4350 goto single_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4351
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4352 default: /* Other control characters */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4353 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4354 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4355
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4356 case ISO_ESC:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4357 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4358 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4359 /**** single shift ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4360
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4361 case 'N': /* single shift 2 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4362 reg = 2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4363 goto single_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4364 case 'O': /* single shift 3 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4365 reg = 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4366 goto single_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4367
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4368 /**** locking shift ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4369
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4370 case '~': /* locking shift 1 right */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4371 reg = 1; half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4372 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4373 case 'n': /* locking shift 2 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4374 reg = 2; half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4375 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4376 case '}': /* locking shift 2 right */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4377 reg = 2; half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4378 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4379 case 'o': /* locking shift 3 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4380 reg = 3; half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4381 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4382 case '|': /* locking shift 3 right */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4383 reg = 3; half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4384 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4385
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4386 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4387 /**** composite ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4388
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4389 case '0':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4390 iso->esc = ISO_ESC_START_COMPOSITE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4391 *flags = (*flags & CODING_STATE_ISO2022_LOCK) |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4392 CODING_STATE_COMPOSITE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4393 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4394
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4395 case '1':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4396 iso->esc = ISO_ESC_END_COMPOSITE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4397 *flags = (*flags & CODING_STATE_ISO2022_LOCK) &
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4398 ~CODING_STATE_COMPOSITE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4399 return 1;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4400 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4401
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4402 /**** directionality ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4403
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4404 case '[':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4405 iso->esc = ISO_ESC_5_11;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4406 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4407
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4408 /**** designation ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4409
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4410 case '$': /* multibyte charset prefix */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4411 iso->esc = ISO_ESC_2_4;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4412 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4413
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4414 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4415 if (0x28 <= c && c <= 0x2F)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4416 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4417 iso->esc = (enum iso_esc_flag) (c - 0x28 + ISO_ESC_2_8);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4418 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4419 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4420
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4421 /* This function is called with CODESYS equal to nil when
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4422 doing coding-system detection. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4423 if (!NILP (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4424 && XCODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4425 && fit_to_be_escape_quoted (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4426 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4427 iso->esc = ISO_ESC_LITERAL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4428 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4429 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4430 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4431
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4432 /* bzzzt! */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4433 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4434 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4435
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4436
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4437
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4438 /**** directionality ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4439
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4440 case ISO_ESC_5_11: /* ISO6429 direction control */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4441 if (c == ']')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4442 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4443 *flags &= (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4444 goto directionality;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4445 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4446 if (c == '0') iso->esc = ISO_ESC_5_11_0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4447 else if (c == '1') iso->esc = ISO_ESC_5_11_1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4448 else if (c == '2') iso->esc = ISO_ESC_5_11_2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4449 else return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4450 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4451
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4452 case ISO_ESC_5_11_0:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4453 if (c == ']')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4454 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4455 *flags &= (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4456 goto directionality;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4457 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4458 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4459
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4460 case ISO_ESC_5_11_1:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4461 if (c == ']')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4462 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4463 *flags = (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4464 goto directionality;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4465 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4466 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4467
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4468 case ISO_ESC_5_11_2:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4469 if (c == ']')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4470 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4471 *flags = (*flags & CODING_STATE_ISO2022_LOCK) | CODING_STATE_R2L;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4472 goto directionality;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4473 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4474 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4475
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4476 directionality:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4477 iso->esc = ISO_ESC_DIRECTIONALITY;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4478 /* Various junk here to attempt to preserve the direction sequences
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4479 literally in the text if they would otherwise be swallowed due
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4480 to invalid designations that don't show up as actual charset
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4481 changes in the text. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4482 if (iso->invalid_switch_dir)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4483 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4484 /* We already inserted a direction switch literally into the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4485 text. We assume (#### this may not be right) that the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4486 next direction switch is the one going the other way,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4487 and we need to output that literally as well. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4488 iso->output_literally = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4489 iso->invalid_switch_dir = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4490 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4491 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4492 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4493 int jj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4494
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4495 /* If we are in the thrall of an invalid designation,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4496 then stick the directionality sequence literally into the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4497 output stream so it ends up in the original text again. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4498 for (jj = 0; jj < 4; jj++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4499 if (iso->invalid_designated[jj])
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4500 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4501 if (jj < 4)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4502 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4503 iso->output_literally = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4504 iso->invalid_switch_dir = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4505 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4506 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4507 /* Indicate that we haven't yet seen a valid designation,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4508 so that if a switch-dir is directly followed by an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4509 invalid designation, both get inserted literally. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4510 iso->switched_dir_and_no_valid_charset_yet = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4511 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4512 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4513
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4514
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4515 /**** designation ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4516
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4517 case ISO_ESC_2_4:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4518 if (0x28 <= c && c <= 0x2F)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4519 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4520 iso->esc = (enum iso_esc_flag) (c - 0x28 + ISO_ESC_2_4_8);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4521 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4522 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4523 if (0x40 <= c && c <= 0x42)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4524 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4525 cs = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_94X94, c,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4526 *flags & CODING_STATE_R2L ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4527 CHARSET_RIGHT_TO_LEFT :
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4528 CHARSET_LEFT_TO_RIGHT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4529 reg = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4530 goto designated;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4531 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4532 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4533
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4534 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4535 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4536 int type =-1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4537
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4538 if (c < '0' || c > '~')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4539 return 0; /* bad final byte */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4540
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4541 if (iso->esc >= ISO_ESC_2_8 &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4542 iso->esc <= ISO_ESC_2_15)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4543 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4544 type = ((iso->esc >= ISO_ESC_2_12) ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4545 CHARSET_TYPE_96 : CHARSET_TYPE_94);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4546 reg = (iso->esc - ISO_ESC_2_8) & 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4547 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4548 else if (iso->esc >= ISO_ESC_2_4_8 &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4549 iso->esc <= ISO_ESC_2_4_15)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4550 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4551 type = ((iso->esc >= ISO_ESC_2_4_12) ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4552 CHARSET_TYPE_96X96 : CHARSET_TYPE_94X94);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4553 reg = (iso->esc - ISO_ESC_2_4_8) & 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4554 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4555 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4556 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4557 /* Can this ever be reached? -slb */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4558 abort();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4559 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4560
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4561 cs = CHARSET_BY_ATTRIBUTES (type, c,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4562 *flags & CODING_STATE_R2L ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4563 CHARSET_RIGHT_TO_LEFT :
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4564 CHARSET_LEFT_TO_RIGHT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4565 goto designated;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4566 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4567 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4568
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4569 not_done:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4570 iso->esc_bytes[iso->esc_bytes_index++] = (unsigned char) c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4571 return -1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4572
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4573 single_shift:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4574 if (check_invalid_charsets && !CHARSETP (iso->charset[reg]))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4575 /* can't invoke something that ain't there. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4576 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4577 iso->esc = ISO_ESC_SINGLE_SHIFT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4578 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4579 if (reg == 2)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4580 *flags |= CODING_STATE_SS2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4581 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4582 *flags |= CODING_STATE_SS3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4583 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4584
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4585 locking_shift:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4586 if (check_invalid_charsets &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4587 !CHARSETP (iso->charset[reg]))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4588 /* can't invoke something that ain't there. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4589 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4590 if (half)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4591 iso->register_right = reg;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4592 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4593 iso->register_left = reg;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4594 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4595 iso->esc = ISO_ESC_LOCKING_SHIFT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4596 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4597
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4598 designated:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4599 if (NILP (cs) && check_invalid_charsets)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4600 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4601 iso->invalid_designated[reg] = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4602 iso->charset[reg] = Vcharset_ascii;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4603 iso->esc = ISO_ESC_DESIGNATE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4604 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4605 iso->output_literally = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4606 if (iso->switched_dir_and_no_valid_charset_yet)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4607 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4608 /* We encountered a switch-direction followed by an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4609 invalid designation. Ensure that the switch-direction
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4610 gets outputted; otherwise it will probably get eaten
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4611 when the text is written out again. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4612 iso->switched_dir_and_no_valid_charset_yet = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4613 iso->output_direction_sequence = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4614 /* And make sure that the switch-dir going the other
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4615 way gets outputted, as well. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4616 iso->invalid_switch_dir = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4617 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4618 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4619 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4620 /* This function is called with CODESYS equal to nil when
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4621 doing coding-system detection. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4622 if (!NILP (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4623 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4624 charset_conversion_spec_dynarr *dyn =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4625 XCODING_SYSTEM (codesys)->iso2022.input_conv;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4626
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4627 if (dyn)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4628 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4629 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4630
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4631 for (i = 0; i < Dynarr_length (dyn); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4632 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4633 struct charset_conversion_spec *spec = Dynarr_atp (dyn, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4634 if (EQ (cs, spec->from_charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4635 cs = spec->to_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4636 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4637 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4638 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4639
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4640 iso->charset[reg] = cs;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4641 iso->esc = ISO_ESC_DESIGNATE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4642 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4643 if (iso->invalid_designated[reg])
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4644 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4645 iso->invalid_designated[reg] = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4646 iso->output_literally = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4647 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4648 if (iso->switched_dir_and_no_valid_charset_yet)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4649 iso->switched_dir_and_no_valid_charset_yet = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4650 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4651 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4652
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4653 static int
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
4654 detect_coding_iso2022 (struct detection_state *st, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4655 unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4656 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4657 int mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4658
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4659 /* #### There are serious deficiencies in the recognition mechanism
388
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4660 here. This needs to be much smarter if it's going to cut it.
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4661 The sequence "\xff\x0f" is currently detected as LOCK_SHIFT while
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4662 it should be detected as Latin-1.
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4663 All the ISO2022 stuff in this file should be synced up with the
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4664 code from FSF Emacs-20.4, in which Mule should be more or less stable.
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4665 Perhaps we should wait till R2L works in FSF Emacs? */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4666
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4667 if (!st->iso2022.initted)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4668 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4669 reset_iso2022 (Qnil, &st->iso2022.iso);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4670 st->iso2022.mask = (CODING_CATEGORY_ISO_7_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4671 CODING_CATEGORY_ISO_8_DESIGNATE_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4672 CODING_CATEGORY_ISO_8_1_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4673 CODING_CATEGORY_ISO_8_2_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4674 CODING_CATEGORY_ISO_LOCK_SHIFT_MASK);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4675 st->iso2022.flags = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4676 st->iso2022.high_byte_count = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4677 st->iso2022.saw_single_shift = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4678 st->iso2022.initted = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4679 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4680
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4681 mask = st->iso2022.mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4682
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4683 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4684 {
388
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4685 int c = *src++;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4686 if (c >= 0xA0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4687 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4688 mask &= ~CODING_CATEGORY_ISO_7_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4689 st->iso2022.high_byte_count++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4690 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4691 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4692 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4693 if (st->iso2022.high_byte_count && !st->iso2022.saw_single_shift)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4694 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4695 if (st->iso2022.high_byte_count & 1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4696 /* odd number of high bytes; assume not iso-8-2 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4697 mask &= ~CODING_CATEGORY_ISO_8_2_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4698 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4699 st->iso2022.high_byte_count = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4700 st->iso2022.saw_single_shift = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4701 if (c > 0x80)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4702 mask &= ~CODING_CATEGORY_ISO_7_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4703 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4704 if (!(st->iso2022.flags & CODING_STATE_ESCAPE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4705 && (BYTE_C0_P (c) || BYTE_C1_P (c)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4706 { /* control chars */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4707 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4708 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4709 /* Allow and ignore control characters that you might
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4710 reasonably see in a text file */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4711 case '\r':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4712 case '\n':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4713 case '\t':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4714 case 7: /* bell */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4715 case 8: /* backspace */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4716 case 11: /* vertical tab */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4717 case 12: /* form feed */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4718 case 26: /* MS-DOS C-z junk */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4719 case 31: /* '^_' -- for info */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4720 goto label_continue_loop;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4721
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4722 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4723 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4724 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4725 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4726
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4727 if ((st->iso2022.flags & CODING_STATE_ESCAPE) || BYTE_C0_P (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4728 || BYTE_C1_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4729 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4730 if (parse_iso2022_esc (Qnil, &st->iso2022.iso, c,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4731 &st->iso2022.flags, 0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4732 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4733 switch (st->iso2022.iso.esc)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4734 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4735 case ISO_ESC_DESIGNATE:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4736 mask &= ~CODING_CATEGORY_ISO_8_1_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4737 mask &= ~CODING_CATEGORY_ISO_8_2_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4738 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4739 case ISO_ESC_LOCKING_SHIFT:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4740 mask = CODING_CATEGORY_ISO_LOCK_SHIFT_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4741 goto ran_out_of_chars;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4742 case ISO_ESC_SINGLE_SHIFT:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4743 mask &= ~CODING_CATEGORY_ISO_8_DESIGNATE_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4744 st->iso2022.saw_single_shift = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4745 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4746 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4747 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4748 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4749 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4750 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4751 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4752 mask = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4753 goto ran_out_of_chars;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4754 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4755 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4756 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4757 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4758
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4759 ran_out_of_chars:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4760
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4761 return mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4762 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4763
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4764 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4765 postprocess_iso2022_mask (int mask)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4766 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4767 /* #### kind of cheesy */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4768 /* If seven-bit ISO is allowed, then assume that the encoding is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4769 entirely seven-bit and turn off the eight-bit ones. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4770 if (mask & CODING_CATEGORY_ISO_7_MASK)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4771 mask &= ~ (CODING_CATEGORY_ISO_8_DESIGNATE_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4772 CODING_CATEGORY_ISO_8_1_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4773 CODING_CATEGORY_ISO_8_2_MASK);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4774 return mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4775 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4776
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4777 /* If FLAGS is a null pointer or specifies right-to-left motion,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4778 output a switch-dir-to-left-to-right sequence to DST.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4779 Also update FLAGS if it is not a null pointer.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4780 If INTERNAL_P is set, we are outputting in internal format and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4781 need to handle the CSI differently. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4782
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4783 static void
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4784 restore_left_to_right_direction (Lisp_Coding_System *codesys,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4785 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4786 unsigned int *flags,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4787 int internal_p)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4788 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4789 if (!flags || (*flags & CODING_STATE_R2L))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4790 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4791 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4792 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4793 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4794 Dynarr_add (dst, '[');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4795 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4796 else if (internal_p)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4797 DECODE_ADD_BINARY_CHAR (ISO_CODE_CSI, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4798 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4799 Dynarr_add (dst, ISO_CODE_CSI);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4800 Dynarr_add (dst, '0');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4801 Dynarr_add (dst, ']');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4802 if (flags)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4803 *flags &= ~CODING_STATE_R2L;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4804 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4805 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4806
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4807 /* If FLAGS is a null pointer or specifies a direction different from
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4808 DIRECTION (which should be either CHARSET_RIGHT_TO_LEFT or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4809 CHARSET_LEFT_TO_RIGHT), output the appropriate switch-dir escape
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4810 sequence to DST. Also update FLAGS if it is not a null pointer.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4811 If INTERNAL_P is set, we are outputting in internal format and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4812 need to handle the CSI differently. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4813
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4814 static void
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4815 ensure_correct_direction (int direction, Lisp_Coding_System *codesys,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4816 unsigned_char_dynarr *dst, unsigned int *flags,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4817 int internal_p)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4818 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4819 if ((!flags || (*flags & CODING_STATE_R2L)) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4820 direction == CHARSET_LEFT_TO_RIGHT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4821 restore_left_to_right_direction (codesys, dst, flags, internal_p);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4822 else if (!CODING_SYSTEM_ISO2022_NO_ISO6429 (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4823 && (!flags || !(*flags & CODING_STATE_R2L)) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4824 direction == CHARSET_RIGHT_TO_LEFT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4825 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4826 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4827 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4828 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4829 Dynarr_add (dst, '[');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4830 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4831 else if (internal_p)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4832 DECODE_ADD_BINARY_CHAR (ISO_CODE_CSI, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4833 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4834 Dynarr_add (dst, ISO_CODE_CSI);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4835 Dynarr_add (dst, '2');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4836 Dynarr_add (dst, ']');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4837 if (flags)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4838 *flags |= CODING_STATE_R2L;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4839 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4840 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4841
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4842 /* Convert ISO2022-format data to internal format. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4843
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4844 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
4845 decode_coding_iso2022 (Lstream *decoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4846 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4847 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4848 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4849 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4850 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4851 eol_type_t eol_type = str->eol_type;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4852 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4853 unsigned_char_dynarr *real_dst = dst;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4854 #endif
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4855 Lisp_Object coding_system;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4856
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4857 XSETCODING_SYSTEM (coding_system, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4858
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4859 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4860 if (flags & CODING_STATE_COMPOSITE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4861 dst = str->iso2022.composite_chars;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4862 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4863
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4864 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4865 {
388
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4866 unsigned char c = *src++;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4867 if (flags & CODING_STATE_ESCAPE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4868 { /* Within ESC sequence */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4869 int retval = parse_iso2022_esc (coding_system, &str->iso2022,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4870 c, &flags, 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4871
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4872 if (retval)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4873 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4874 switch (str->iso2022.esc)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4875 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4876 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4877 case ISO_ESC_START_COMPOSITE:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4878 if (str->iso2022.composite_chars)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4879 Dynarr_reset (str->iso2022.composite_chars);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4880 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4881 str->iso2022.composite_chars = Dynarr_new (unsigned_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4882 dst = str->iso2022.composite_chars;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4883 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4884 case ISO_ESC_END_COMPOSITE:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4885 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4886 Bufbyte comstr[MAX_EMCHAR_LEN];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4887 Bytecount len;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4888 Emchar emch = lookup_composite_char (Dynarr_atp (dst, 0),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4889 Dynarr_length (dst));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4890 dst = real_dst;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4891 len = set_charptr_emchar (comstr, emch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4892 Dynarr_add_many (dst, comstr, len);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4893 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4894 }
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4895 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4896
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4897 case ISO_ESC_LITERAL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4898 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4899 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4900
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4901 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4902 /* Everything else handled already */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4903 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4904 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4905 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4906
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4907 /* Attempted error recovery. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4908 if (str->iso2022.output_direction_sequence)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4909 ensure_correct_direction (flags & CODING_STATE_R2L ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4910 CHARSET_RIGHT_TO_LEFT :
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4911 CHARSET_LEFT_TO_RIGHT,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4912 str->codesys, dst, 0, 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4913 /* More error recovery. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4914 if (!retval || str->iso2022.output_literally)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4915 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4916 /* Output the (possibly invalid) sequence */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4917 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4918 for (i = 0; i < str->iso2022.esc_bytes_index; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4919 DECODE_ADD_BINARY_CHAR (str->iso2022.esc_bytes[i], dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4920 flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4921 if (!retval)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4922 n++, src--;/* Repeat the loop with the same character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4923 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4924 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4925 /* No sense in reprocessing the final byte of the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4926 escape sequence; it could mess things up anyway.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4927 Just add it now. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4928 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4929 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4930 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4931 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4932 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4933 else if (BYTE_C0_P (c) || BYTE_C1_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4934 { /* Control characters */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4935
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4936 /***** Error-handling *****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4937
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4938 /* If we were in the middle of a character, dump out the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4939 partial character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4940 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4941
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4942 /* If we just saw a single-shift character, dump it out.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4943 This may dump out the wrong sort of single-shift character,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4944 but least it will give an indication that something went
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4945 wrong. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4946 if (flags & CODING_STATE_SS2)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4947 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4948 DECODE_ADD_BINARY_CHAR (ISO_CODE_SS2, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4949 flags &= ~CODING_STATE_SS2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4950 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4951 if (flags & CODING_STATE_SS3)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4952 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4953 DECODE_ADD_BINARY_CHAR (ISO_CODE_SS3, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4954 flags &= ~CODING_STATE_SS3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4955 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4956
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4957 /***** Now handle the control characters. *****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4958
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4959 /* Handle CR/LF */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4960 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4961
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4962 flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4963
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4964 if (!parse_iso2022_esc (coding_system, &str->iso2022, c, &flags, 1))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4965 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4966 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4967 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4968 { /* Graphic characters */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4969 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4970 int lb;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4971 int reg;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4972
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4973 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4974
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4975 /* Now determine the charset. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4976 reg = ((flags & CODING_STATE_SS2) ? 2
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4977 : (flags & CODING_STATE_SS3) ? 3
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4978 : !BYTE_ASCII_P (c) ? str->iso2022.register_right
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4979 : str->iso2022.register_left);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4980 charset = str->iso2022.charset[reg];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4981
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4982 /* Error checking: */
388
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4983 if (! CHARSETP (charset)
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4984 || str->iso2022.invalid_designated[reg]
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4985 || (((c & 0x7F) == ' ' || (c & 0x7F) == ISO_CODE_DEL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4986 && XCHARSET_CHARS (charset) == 94))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4987 /* Mrmph. We are trying to invoke a register that has no
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4988 or an invalid charset in it, or trying to add a character
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4989 outside the range of the charset. Insert that char literally
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4990 to preserve it for the output. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4991 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4992 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4993 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4994 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4995
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4996 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4997 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4998 /* Things are probably hunky-dorey. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4999
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5000 /* Fetch reverse charset, maybe. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5001 if (((flags & CODING_STATE_R2L) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5002 XCHARSET_DIRECTION (charset) == CHARSET_LEFT_TO_RIGHT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5003 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5004 (!(flags & CODING_STATE_R2L) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5005 XCHARSET_DIRECTION (charset) == CHARSET_RIGHT_TO_LEFT))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5006 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5007 Lisp_Object new_charset =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5008 XCHARSET_REVERSE_DIRECTION_CHARSET (charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5009 if (!NILP (new_charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5010 charset = new_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5011 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5012
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5013 lb = XCHARSET_LEADING_BYTE (charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5014 switch (XCHARSET_REP_BYTES (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5015 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5016 case 1: /* ASCII */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5017 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5018 Dynarr_add (dst, c & 0x7F);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5019 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5020
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5021 case 2: /* one-byte official */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5022 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5023 Dynarr_add (dst, lb);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5024 Dynarr_add (dst, c | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5025 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5026
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5027 case 3: /* one-byte private or two-byte official */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5028 if (XCHARSET_PRIVATE_P (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5029 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5030 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5031 Dynarr_add (dst, PRE_LEADING_BYTE_PRIVATE_1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5032 Dynarr_add (dst, lb);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5033 Dynarr_add (dst, c | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5034 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5035 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5036 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5037 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5038 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5039 Dynarr_add (dst, lb);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5040 Dynarr_add (dst, ch | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5041 Dynarr_add (dst, c | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5042 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5043 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5044 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5045 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5046 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5047 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5048
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5049 default: /* two-byte private */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5050 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5051 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5052 Dynarr_add (dst, PRE_LEADING_BYTE_PRIVATE_2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5053 Dynarr_add (dst, lb);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5054 Dynarr_add (dst, ch | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5055 Dynarr_add (dst, c | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5056 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5057 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5058 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5059 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5060 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5061 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5062
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5063 if (!ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5064 flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5065 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5066
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5067 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5068 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5069
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5070 if (flags & CODING_STATE_END)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5071 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5072
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5073 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5074 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5075 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5076
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5077
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5078 /***** ISO2022 encoder *****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5079
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5080 /* Designate CHARSET into register REG. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5081
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5082 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5083 iso2022_designate (Lisp_Object charset, unsigned char reg,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5084 struct encoding_stream *str, unsigned_char_dynarr *dst)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5085 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5086 static const char inter94[] = "()*+";
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5087 static const char inter96[] = ",-./";
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
5088 unsigned int type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5089 unsigned char final;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5090 Lisp_Object old_charset = str->iso2022.charset[reg];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5091
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5092 str->iso2022.charset[reg] = charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5093 if (!CHARSETP (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5094 /* charset might be an initial nil or t. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5095 return;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5096 type = XCHARSET_TYPE (charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5097 final = XCHARSET_FINAL (charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5098 if (!str->iso2022.force_charset_on_output[reg] &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5099 CHARSETP (old_charset) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5100 XCHARSET_TYPE (old_charset) == type &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5101 XCHARSET_FINAL (old_charset) == final)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5102 return;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5103
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5104 str->iso2022.force_charset_on_output[reg] = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5105
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5106 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5107 charset_conversion_spec_dynarr *dyn =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5108 str->codesys->iso2022.output_conv;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5109
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5110 if (dyn)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5111 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5112 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5113
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5114 for (i = 0; i < Dynarr_length (dyn); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5115 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5116 struct charset_conversion_spec *spec = Dynarr_atp (dyn, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5117 if (EQ (charset, spec->from_charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5118 charset = spec->to_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5119 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5120 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5121 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5122
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5123 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5124 switch (type)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5125 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5126 case CHARSET_TYPE_94:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5127 Dynarr_add (dst, inter94[reg]);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5128 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5129 case CHARSET_TYPE_96:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5130 Dynarr_add (dst, inter96[reg]);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5131 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5132 case CHARSET_TYPE_94X94:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5133 Dynarr_add (dst, '$');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5134 if (reg != 0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5135 || !(CODING_SYSTEM_ISO2022_SHORT (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5136 || final < '@'
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5137 || final > 'B')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5138 Dynarr_add (dst, inter94[reg]);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5139 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5140 case CHARSET_TYPE_96X96:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5141 Dynarr_add (dst, '$');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5142 Dynarr_add (dst, inter96[reg]);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5143 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5144 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5145 Dynarr_add (dst, final);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5146 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5147
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5148 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5149 ensure_normal_shift (struct encoding_stream *str, unsigned_char_dynarr *dst)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5150 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5151 if (str->iso2022.register_left != 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5152 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5153 Dynarr_add (dst, ISO_CODE_SI);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5154 str->iso2022.register_left = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5155 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5156 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5157
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5158 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5159 ensure_shift_out (struct encoding_stream *str, unsigned_char_dynarr *dst)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5160 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5161 if (str->iso2022.register_left != 1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5162 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5163 Dynarr_add (dst, ISO_CODE_SO);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5164 str->iso2022.register_left = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5165 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5166 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5167
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5168 /* Convert internally-formatted data to ISO2022 format. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5169
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5170 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5171 encode_coding_iso2022 (Lstream *encoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5172 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5173 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5174 unsigned char charmask, c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5175 unsigned char char_boundary;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5176 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5177 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5178 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5179 Lisp_Coding_System *codesys = str->codesys;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5180 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5181 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5182 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5183 int half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5184
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5185 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5186 /* flags for handling composite chars. We do a little switcharoo
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5187 on the source while we're outputting the composite char. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5188 unsigned int saved_n = 0;
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5189 const unsigned char *saved_src = NULL;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5190 int in_composite = 0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5191 #endif /* ENABLE_COMPOSITE_CHARS */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5192
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5193 char_boundary = str->iso2022.current_char_boundary;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5194 charset = str->iso2022.current_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5195 half = str->iso2022.current_half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5196
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5197 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5198 back_to_square_n:
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5199 #endif
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5200 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5201 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5202 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5203
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5204 if (BYTE_ASCII_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5205 { /* Processing ASCII character */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5206 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5207
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5208 restore_left_to_right_direction (codesys, dst, &flags, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5209
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5210 /* Make sure G0 contains ASCII */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5211 if ((c > ' ' && c < ISO_CODE_DEL) ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5212 !CODING_SYSTEM_ISO2022_NO_ASCII_CNTL (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5213 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5214 ensure_normal_shift (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5215 iso2022_designate (Vcharset_ascii, 0, str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5216 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5217
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5218 /* If necessary, restore everything to the default state
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5219 at end-of-line */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5220 if (c == '\n' &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5221 !(CODING_SYSTEM_ISO2022_NO_ASCII_EOL (codesys)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5222 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5223 restore_left_to_right_direction (codesys, dst, &flags, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5224
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5225 ensure_normal_shift (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5226
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5227 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5228 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5229 Lisp_Object initial_charset =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5230 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5231 iso2022_designate (initial_charset, i, str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5232 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5233 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5234 if (c == '\n')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5235 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5236 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5237 Dynarr_add (dst, '\r');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5238 if (eol_type != EOL_CR)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5239 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5240 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5241 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5242 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5243 if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5244 && fit_to_be_escape_quoted (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5245 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5246 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5247 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5248 char_boundary = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5249 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5250
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5251 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5252 { /* Processing Leading Byte */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5253 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5254 charset = CHARSET_BY_LEADING_BYTE (c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5255 if (LEADING_BYTE_PREFIX_P(c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5256 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5257 else if (!EQ (charset, Vcharset_control_1)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5258 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5259 && !EQ (charset, Vcharset_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5260 #endif
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5261 )
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5262 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5263 int reg;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5264
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5265 ensure_correct_direction (XCHARSET_DIRECTION (charset),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5266 codesys, dst, &flags, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5267
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5268 /* Now determine which register to use. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5269 reg = -1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5270 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5271 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5272 if (EQ (charset, str->iso2022.charset[i]) ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5273 EQ (charset,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5274 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5275 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5276 reg = i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5277 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5278 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5279 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5280
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5281 if (reg == -1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5282 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5283 if (XCHARSET_GRAPHIC (charset) != 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5284 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5285 if (!NILP (str->iso2022.charset[1]) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5286 (!CODING_SYSTEM_ISO2022_SEVEN (codesys) ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5287 CODING_SYSTEM_ISO2022_LOCK_SHIFT (codesys)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5288 reg = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5289 else if (!NILP (str->iso2022.charset[2]))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5290 reg = 2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5291 else if (!NILP (str->iso2022.charset[3]))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5292 reg = 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5293 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5294 reg = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5295 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5296 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5297 reg = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5298 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5299
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5300 iso2022_designate (charset, reg, str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5301
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5302 /* Now invoke that register. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5303 switch (reg)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5304 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5305 case 0:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5306 ensure_normal_shift (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5307 half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5308 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5309
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5310 case 1:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5311 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5312 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5313 ensure_shift_out (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5314 half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5315 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5316 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5317 half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5318 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5319
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5320 case 2:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5321 if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5322 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5323 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5324 Dynarr_add (dst, 'N');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5325 half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5326 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5327 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5328 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5329 Dynarr_add (dst, ISO_CODE_SS2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5330 half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5331 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5332 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5333
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5334 case 3:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5335 if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5336 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5337 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5338 Dynarr_add (dst, 'O');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5339 half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5340 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5341 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5342 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5343 Dynarr_add (dst, ISO_CODE_SS3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5344 half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5345 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5346 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5347
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5348 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5349 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5350 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5351 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5352 char_boundary = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5353 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5354 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5355 { /* Processing Non-ASCII character */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5356 charmask = (half == 0 ? 0x7F : 0xFF);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5357 char_boundary = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5358 if (EQ (charset, Vcharset_control_1))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5359 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5360 if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5361 && fit_to_be_escape_quoted (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5362 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5363 /* you asked for it ... */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5364 Dynarr_add (dst, c - 0x20);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5365 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5366 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5367 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5368 switch (XCHARSET_REP_BYTES (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5369 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5370 case 2:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5371 Dynarr_add (dst, c & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5372 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5373 case 3:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5374 if (XCHARSET_PRIVATE_P (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5375 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5376 Dynarr_add (dst, c & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5377 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5378 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5379 else if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5380 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5381 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5382 if (EQ (charset, Vcharset_composite))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5383 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5384 if (in_composite)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5385 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5386 /* #### Bother! We don't know how to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5387 handle this yet. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5388 Dynarr_add (dst, '~');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5389 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5390 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5391 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5392 Emchar emch = MAKE_CHAR (Vcharset_composite,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5393 ch & 0x7F, c & 0x7F);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5394 Lisp_Object lstr = composite_char_string (emch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5395 saved_n = n;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5396 saved_src = src;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5397 in_composite = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5398 src = XSTRING_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5399 n = XSTRING_LENGTH (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5400 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5401 Dynarr_add (dst, '0'); /* start composing */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5402 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5403 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5404 else
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5405 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5406 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5407 Dynarr_add (dst, ch & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5408 Dynarr_add (dst, c & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5409 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5410 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5411 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5412 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5413 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5414 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5415 char_boundary = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5416 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5417 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5418 case 4:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5419 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5420 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5421 Dynarr_add (dst, ch & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5422 Dynarr_add (dst, c & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5423 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5424 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5425 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5426 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5427 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5428 char_boundary = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5429 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5430 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5431 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5432 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5433 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5434 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5435 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5436 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5437
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5438 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5439 if (in_composite)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5440 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5441 n = saved_n;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5442 src = saved_src;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5443 in_composite = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5444 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5445 Dynarr_add (dst, '1'); /* end composing */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5446 goto back_to_square_n; /* Wheeeeeeeee ..... */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5447 }
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5448 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5449
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5450 if (char_boundary && flags & CODING_STATE_END)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5451 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5452 restore_left_to_right_direction (codesys, dst, &flags, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5453 ensure_normal_shift (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5454 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5455 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5456 Lisp_Object initial_charset =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5457 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5458 iso2022_designate (initial_charset, i, str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5459 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5460 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5461
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5462 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5463 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5464 str->iso2022.current_char_boundary = char_boundary;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5465 str->iso2022.current_charset = charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5466 str->iso2022.current_half = half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5467
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5468 /* Verbum caro factum est! */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5469 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5470 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5471
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5472 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5473 /* No-conversion methods */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5474 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5475
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5476 /* This is used when reading in "binary" files -- i.e. files that may
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5477 contain all 256 possible byte values and that are not to be
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5478 interpreted as being in any particular decoding. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5479 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5480 decode_coding_no_conversion (Lstream *decoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5481 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5482 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5483 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5484 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5485 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5486 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5487 eol_type_t eol_type = str->eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5488
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5489 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5490 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5491 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5492
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5493 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5494 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5495 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5496 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5497
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5498 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5499
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5500 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5501 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5502 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5503
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5504 static void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5505 encode_coding_no_conversion (Lstream *encoding, const unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5506 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5507 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5508 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5509 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5510 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5511 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5512 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5513
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5514 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5515 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5516 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5517 if (c == '\n')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5518 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5519 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5520 Dynarr_add (dst, '\r');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5521 if (eol_type != EOL_CR)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5522 Dynarr_add (dst, '\n');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5523 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5524 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5525 else if (BYTE_ASCII_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5526 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5527 assert (ch == 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5528 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5529 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5530 else if (BUFBYTE_LEADING_BYTE_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5531 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5532 assert (ch == 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5533 if (c == LEADING_BYTE_LATIN_ISO8859_1 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5534 c == LEADING_BYTE_CONTROL_1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5535 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5536 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5537 Dynarr_add (dst, '~'); /* untranslatable character */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5538 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5539 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5540 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5541 if (ch == LEADING_BYTE_LATIN_ISO8859_1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5542 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5543 else if (ch == LEADING_BYTE_CONTROL_1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5544 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5545 assert (c < 0xC0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5546 Dynarr_add (dst, c - 0x20);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5547 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5548 /* else it should be the second or third byte of an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5549 untranslatable character, so ignore it */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5550 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5551 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5552 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5553
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5554 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5555 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5556 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5557
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5558
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5559
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5560 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5561 /* Initialization */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5562 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5563
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5564 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5565 syms_of_file_coding (void)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5566 {
400
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
5567 INIT_LRECORD_IMPLEMENTATION (coding_system);
a86b2b5e0111 Import from CVS: tag r21-2-30
cvs
parents: 398
diff changeset
5568
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5569 deferror (&Qcoding_system_error, "coding-system-error",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5570 "Coding-system error", Qio_error);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5571
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5572 DEFSUBR (Fcoding_system_p);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5573 DEFSUBR (Ffind_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5574 DEFSUBR (Fget_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5575 DEFSUBR (Fcoding_system_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5576 DEFSUBR (Fcoding_system_name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5577 DEFSUBR (Fmake_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5578 DEFSUBR (Fcopy_coding_system);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5579 DEFSUBR (Fcoding_system_canonical_name_p);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5580 DEFSUBR (Fcoding_system_alias_p);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5581 DEFSUBR (Fcoding_system_aliasee);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5582 DEFSUBR (Fdefine_coding_system_alias);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5583 DEFSUBR (Fsubsidiary_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5584
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5585 DEFSUBR (Fcoding_system_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5586 DEFSUBR (Fcoding_system_doc_string);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5587 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5588 DEFSUBR (Fcoding_system_charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5589 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5590 DEFSUBR (Fcoding_system_property);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5591
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5592 DEFSUBR (Fcoding_category_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5593 DEFSUBR (Fset_coding_priority_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5594 DEFSUBR (Fcoding_priority_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5595 DEFSUBR (Fset_coding_category_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5596 DEFSUBR (Fcoding_category_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5597
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5598 DEFSUBR (Fdetect_coding_region);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5599 DEFSUBR (Fdecode_coding_region);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5600 DEFSUBR (Fencode_coding_region);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5601 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5602 DEFSUBR (Fdecode_shift_jis_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5603 DEFSUBR (Fencode_shift_jis_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5604 DEFSUBR (Fdecode_big5_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5605 DEFSUBR (Fencode_big5_char);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5606 DEFSUBR (Fset_ucs_char);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5607 DEFSUBR (Fucs_char);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5608 DEFSUBR (Fset_char_ucs);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5609 DEFSUBR (Fchar_ucs);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5610 #endif /* MULE */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5611 defsymbol (&Qcoding_systemp, "coding-system-p");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5612 defsymbol (&Qno_conversion, "no-conversion");
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5613 defsymbol (&Qraw_text, "raw-text");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5614 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5615 defsymbol (&Qbig5, "big5");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5616 defsymbol (&Qshift_jis, "shift-jis");
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5617 defsymbol (&Qucs4, "ucs-4");
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5618 defsymbol (&Qutf8, "utf-8");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5619 defsymbol (&Qccl, "ccl");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5620 defsymbol (&Qiso2022, "iso2022");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5621 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5622 defsymbol (&Qmnemonic, "mnemonic");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5623 defsymbol (&Qeol_type, "eol-type");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5624 defsymbol (&Qpost_read_conversion, "post-read-conversion");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5625 defsymbol (&Qpre_write_conversion, "pre-write-conversion");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5626
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5627 defsymbol (&Qcr, "cr");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5628 defsymbol (&Qlf, "lf");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5629 defsymbol (&Qcrlf, "crlf");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5630 defsymbol (&Qeol_cr, "eol-cr");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5631 defsymbol (&Qeol_lf, "eol-lf");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5632 defsymbol (&Qeol_crlf, "eol-crlf");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5633 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5634 defsymbol (&Qcharset_g0, "charset-g0");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5635 defsymbol (&Qcharset_g1, "charset-g1");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5636 defsymbol (&Qcharset_g2, "charset-g2");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5637 defsymbol (&Qcharset_g3, "charset-g3");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5638 defsymbol (&Qforce_g0_on_output, "force-g0-on-output");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5639 defsymbol (&Qforce_g1_on_output, "force-g1-on-output");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5640 defsymbol (&Qforce_g2_on_output, "force-g2-on-output");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5641 defsymbol (&Qforce_g3_on_output, "force-g3-on-output");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5642 defsymbol (&Qno_iso6429, "no-iso6429");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5643 defsymbol (&Qinput_charset_conversion, "input-charset-conversion");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5644 defsymbol (&Qoutput_charset_conversion, "output-charset-conversion");
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
5645
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5646 defsymbol (&Qshort, "short");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5647 defsymbol (&Qno_ascii_eol, "no-ascii-eol");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5648 defsymbol (&Qno_ascii_cntl, "no-ascii-cntl");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5649 defsymbol (&Qseven, "seven");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5650 defsymbol (&Qlock_shift, "lock-shift");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5651 defsymbol (&Qescape_quoted, "escape-quoted");
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
5652 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5653 defsymbol (&Qencode, "encode");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5654 defsymbol (&Qdecode, "decode");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5655
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5656 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5657 defsymbol (&coding_category_symbol[CODING_CATEGORY_SHIFT_JIS],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5658 "shift-jis");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5659 defsymbol (&coding_category_symbol[CODING_CATEGORY_BIG5],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5660 "big5");
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5661 defsymbol (&coding_category_symbol[CODING_CATEGORY_UCS4],
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5662 "ucs-4");
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5663 defsymbol (&coding_category_symbol[CODING_CATEGORY_UTF8],
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5664 "utf-8");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5665 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_7],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5666 "iso-7");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5667 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_DESIGNATE],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5668 "iso-8-designate");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5669 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_1],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5670 "iso-8-1");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5671 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_2],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5672 "iso-8-2");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5673 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_LOCK_SHIFT],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5674 "iso-lock-shift");
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
5675 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5676 defsymbol (&coding_category_symbol[CODING_CATEGORY_NO_CONVERSION],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5677 "no-conversion");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5678 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5679
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5680 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5681 lstream_type_create_file_coding (void)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5682 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5683 LSTREAM_HAS_METHOD (decoding, reader);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5684 LSTREAM_HAS_METHOD (decoding, writer);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5685 LSTREAM_HAS_METHOD (decoding, rewinder);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5686 LSTREAM_HAS_METHOD (decoding, seekable_p);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5687 LSTREAM_HAS_METHOD (decoding, flusher);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5688 LSTREAM_HAS_METHOD (decoding, closer);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5689 LSTREAM_HAS_METHOD (decoding, marker);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5690
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5691 LSTREAM_HAS_METHOD (encoding, reader);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5692 LSTREAM_HAS_METHOD (encoding, writer);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5693 LSTREAM_HAS_METHOD (encoding, rewinder);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5694 LSTREAM_HAS_METHOD (encoding, seekable_p);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5695 LSTREAM_HAS_METHOD (encoding, flusher);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5696 LSTREAM_HAS_METHOD (encoding, closer);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5697 LSTREAM_HAS_METHOD (encoding, marker);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5698 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5699
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5700 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5701 vars_of_file_coding (void)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5702 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5703 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5704
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5705 fcd = xnew (struct file_coding_dump);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5706 dumpstruct (&fcd, &fcd_description);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5707
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5708 /* Initialize to something reasonable ... */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5709 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5710 {
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5711 fcd->coding_category_system[i] = Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5712 fcd->coding_category_by_priority[i] = i;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5713 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5714
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5715 Fprovide (intern ("file-coding"));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5716
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5717 DEFVAR_LISP ("keyboard-coding-system", &Vkeyboard_coding_system /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5718 Coding system used for TTY keyboard input.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5719 Not used under a windowing system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5720 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5721 Vkeyboard_coding_system = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5722
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5723 DEFVAR_LISP ("terminal-coding-system", &Vterminal_coding_system /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5724 Coding system used for TTY display output.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5725 Not used under a windowing system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5726 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5727 Vterminal_coding_system = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5728
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5729 DEFVAR_LISP ("coding-system-for-read", &Vcoding_system_for_read /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5730 Overriding coding system used when reading from a file or process.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5731 You should bind this variable with `let', but do not set it globally.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5732 If this is non-nil, it specifies the coding system that will be used
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5733 to decode input on read operations, such as from a file or process.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5734 It overrides `buffer-file-coding-system-for-read',
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5735 `insert-file-contents-pre-hook', etc. Use those variables instead of
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5736 this one for permanent changes to the environment. */ );
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5737 Vcoding_system_for_read = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5738
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5739 DEFVAR_LISP ("coding-system-for-write",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5740 &Vcoding_system_for_write /*
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5741 Overriding coding system used when writing to a file or process.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5742 You should bind this variable with `let', but do not set it globally.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5743 If this is non-nil, it specifies the coding system that will be used
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5744 to encode output for write operations, such as to a file or process.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5745 It overrides `buffer-file-coding-system', `write-region-pre-hook', etc.
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5746 Use those variables instead of this one for permanent changes to the
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5747 environment. */ );
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5748 Vcoding_system_for_write = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5749
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5750 DEFVAR_LISP ("file-name-coding-system", &Vfile_name_coding_system /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5751 Coding system used to convert pathnames when accessing files.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5752 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5753 Vfile_name_coding_system = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5754
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5755 DEFVAR_BOOL ("enable-multibyte-characters", &enable_multibyte_characters /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5756 Non-nil means the buffer contents are regarded as multi-byte form
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5757 of characters, not a binary code. This affects the display, file I/O,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5758 and behaviors of various editing commands.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5759
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5760 Setting this to nil does not do anything.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5761 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5762 enable_multibyte_characters = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5763 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5764
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5765 void
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5766 complex_vars_of_file_coding (void)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5767 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
5768 staticpro (&Vcoding_system_hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
5769 Vcoding_system_hash_table =
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
5770 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5771
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5772 the_codesys_prop_dynarr = Dynarr_new (codesys_prop);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5773 dumpstruct (&the_codesys_prop_dynarr, &codesys_prop_dynarr_description);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5774
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5775 #define DEFINE_CODESYS_PROP(Prop_Type, Sym) do \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5776 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5777 struct codesys_prop csp; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5778 csp.sym = (Sym); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5779 csp.prop_type = (Prop_Type); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5780 Dynarr_add (the_codesys_prop_dynarr, csp); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5781 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5782
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5783 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qmnemonic);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5784 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5785 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_cr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5786 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_crlf);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5787 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_lf);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5788 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qpost_read_conversion);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5789 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qpre_write_conversion);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5790 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5791 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5792 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5793 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5794 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5795 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g0_on_output);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5796 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g1_on_output);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5797 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g2_on_output);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5798 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g3_on_output);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5799 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qshort);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5800 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_ascii_eol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5801 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_ascii_cntl);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5802 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qseven);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5803 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qlock_shift);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5804 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_iso6429);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5805 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qescape_quoted);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5806 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qinput_charset_conversion);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5807 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qoutput_charset_conversion);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5808
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5809 DEFINE_CODESYS_PROP (CODESYS_PROP_CCL, Qencode);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5810 DEFINE_CODESYS_PROP (CODESYS_PROP_CCL, Qdecode);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5811 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5812 /* Need to create this here or we're really screwed. */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5813 Fmake_coding_system
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5814 (Qraw_text, Qno_conversion,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5815 build_string ("Raw text, which means it converts only line-break-codes."),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5816 list2 (Qmnemonic, build_string ("Raw")));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5817
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5818 Fmake_coding_system
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5819 (Qbinary, Qno_conversion,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5820 build_string ("Binary, which means it does not convert anything."),
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5821 list4 (Qeol_type, Qlf,
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5822 Qmnemonic, build_string ("Binary")));
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5823
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5824 Fdefine_coding_system_alias (Qno_conversion, Qraw_text);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5825
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5826 Fdefine_coding_system_alias (Qfile_name, Qbinary);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5827
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5828 Fdefine_coding_system_alias (Qterminal, Qbinary);
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5829 Fdefine_coding_system_alias (Qkeyboard, Qbinary);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5830
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5831 /* Need this for bootstrapping */
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5832 fcd->coding_category_system[CODING_CATEGORY_NO_CONVERSION] =
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5833 Fget_coding_system (Qraw_text);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5834
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5835 #ifdef MULE
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5836 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5837 unsigned int i;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5838
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5839 for (i = 0; i < 65536; i++)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5840 fcd->ucs_to_mule_table[i] = Qnil;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5841 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5842 staticpro (&mule_to_ucs_table);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5843 mule_to_ucs_table = Fmake_char_table(Qgeneric);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5844 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5845 }