annotate src/mule-coding.c @ 213:78f53ef88e17 r20-4b5

Import from CVS: tag r20-4b5
author cvs
date Mon, 13 Aug 2007 10:06:47 +0200
parents 41ff10fd062f
children f955c73f5258
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1 /* Code conversion functions.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2 Copyright (C) 1991, 1995 Free Software Foundation, Inc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
5 This file is part of XEmacs.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
6
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
10 later version.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
11
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
15 for more details.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
16
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
21
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
22 /* Synched up with: Mule 2.3. Not in FSF. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
23
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
24 /* Rewritten by Ben Wing <wing@666.com>. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
25
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
26 #include <config.h>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
27 #include "lisp.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
28
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
29 #include "buffer.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
30 #include "elhash.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
31 #include "insdel.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
32 #include "lstream.h"
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
33 #include "mule-ccl.h"
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
34 #include "mule-coding.h"
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
35
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 96
diff changeset
36 Lisp_Object Qbuffer_file_coding_system, Qcoding_system_error;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
37
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
38 Lisp_Object Vkeyboard_coding_system;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
39 Lisp_Object Vterminal_coding_system;
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
40 Lisp_Object Vcoding_system_for_read;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
41 Lisp_Object Vcoding_system_for_write;
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
42 Lisp_Object Vfile_name_coding_system;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
43
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
44 /* Table of symbols identifying each coding category. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
45 Lisp_Object coding_category_symbol[CODING_CATEGORY_LAST + 1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
46
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
47 /* Coding system currently associated with each coding category. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
48 Lisp_Object coding_category_system[CODING_CATEGORY_LAST + 1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
49
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
50 /* Table of all coding categories in decreasing order of priority.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
51 This describes a permutation of the possible coding categories. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
52 int coding_category_by_priority[CODING_CATEGORY_LAST + 1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
53
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
54 Lisp_Object Qcoding_system_p;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
55
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
56 Lisp_Object Qbig5, Qshift_jis, Qno_conversion, Qccl, Qiso2022;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
57 /* Qinternal in general.c */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
58
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
59 Lisp_Object Qmnemonic, Qeol_type;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
60 Lisp_Object Qcr, Qcrlf, Qlf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
61 Lisp_Object Qeol_cr, Qeol_crlf, Qeol_lf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
62 Lisp_Object Qpost_read_conversion;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
63 Lisp_Object Qpre_write_conversion;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
64
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
65 Lisp_Object Qcharset_g0, Qcharset_g1, Qcharset_g2, Qcharset_g3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
66 Lisp_Object Qforce_g0_on_output, Qforce_g1_on_output;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
67 Lisp_Object Qforce_g2_on_output, Qforce_g3_on_output;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
68 Lisp_Object Qshort, Qno_ascii_eol, Qno_ascii_cntl, Qseven, Qlock_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
69 Lisp_Object Qno_iso6429, Qescape_quoted;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
70 Lisp_Object Qinput_charset_conversion, Qoutput_charset_conversion;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
71
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
72 Lisp_Object Qencode, Qdecode;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
73
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
74 Lisp_Object Qctext;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
75
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
76 Lisp_Object Vcoding_system_hashtable;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
77
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
78 int enable_multibyte_characters;
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
79
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
80 /* Additional information used by the ISO2022 decoder and detector. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
81 struct iso2022_decoder
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
82 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
83 /* CHARSET holds the character sets currently assigned to the G0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
84 through G3 variables. It is initialized from the array
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
85 INITIAL_CHARSET in CODESYS. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
86 Lisp_Object charset[4];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
87
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
88 /* Which registers are currently invoked into the left (GL) and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
89 right (GR) halves of the 8-bit encoding space? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
90 int register_left, register_right;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
91
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
92 /* ISO_ESC holds a value indicating part of an escape sequence
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
93 that has already been seen. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
94 enum iso_esc_flag esc;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
95
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
96 /* This records the bytes we've seen so far in an escape sequence,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
97 in case the sequence is invalid (we spit out the bytes unchanged). */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
98 unsigned char esc_bytes[8];
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
99
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
100 /* Index for next byte to store in ISO escape sequence. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
101 int esc_bytes_index;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
102
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
103 /* Stuff seen so far when composing a string. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
104 unsigned_char_dynarr *composite_chars;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
105
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
106 /* If we saw an invalid designation sequence for a particular
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
107 register, we flag it here and switch to ASCII. The next time we
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
108 see a valid designation for this register, we turn off the flag
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
109 and do the designation normally, but pretend the sequence was
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
110 invalid. The effect of all this is that (most of the time) the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
111 escape sequences for both the switch to the unknown charset, and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
112 the switch back to the known charset, get inserted literally into
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
113 the buffer and saved out as such. The hope is that we can
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
114 preserve the escape sequences so that the resulting written out
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
115 file makes sense. If we don't do any of this, the designation
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
116 to the invalid charset will be preserved but that switch back
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
117 to the known charset will probably get eaten because it was
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
118 the same charset that was already present in the register. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
119 unsigned char invalid_designated[4];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
120
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
121 /* We try to do similar things as above for direction-switching
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
122 sequences. If we encountered a direction switch while an
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
123 invalid designation was present, or an invalid designation
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
124 just after a direction switch (i.e. no valid designation
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
125 encountered yet), we insert the direction-switch escape
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
126 sequence literally into the output stream, and later on
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
127 insert the corresponding direction-restoring escape sequence
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
128 literally also. */
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
129 unsigned int switched_dir_and_no_valid_charset_yet :1;
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
130 unsigned int invalid_switch_dir :1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
131
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
132 /* Tells the decoder to output the escape sequence literally
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
133 even though it was valid. Used in the games we play to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
134 avoid lossage when we encounter invalid designations. */
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
135 unsigned int output_literally :1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
136 /* We encountered a direction switch followed by an invalid
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
137 designation. We didn't output the direction switch
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
138 literally because we didn't know about the invalid designation;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
139 but we have to do so now. */
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
140 unsigned int output_direction_sequence :1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
141 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
142
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
143 Lisp_Object Fcopy_coding_system (Lisp_Object old_coding_system,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
144 Lisp_Object new_name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
145 struct detection_state;
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
146 static int detect_coding_sjis (struct detection_state *st,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
147 CONST unsigned char *src,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
148 unsigned int n);
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
149 static void decode_coding_sjis (Lstream *decoding,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
150 CONST unsigned char *src,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
151 unsigned_char_dynarr *dst,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
152 unsigned int n);
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
153 static void encode_coding_sjis (Lstream *encoding,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
154 CONST unsigned char *src,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
155 unsigned_char_dynarr *dst,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
156 unsigned int n);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
157 static int detect_coding_big5 (struct detection_state *st,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
158 CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
159 unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
160 static void decode_coding_big5 (Lstream *decoding,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
161 CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
162 unsigned_char_dynarr *dst, unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
163 static void encode_coding_big5 (Lstream *encoding,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
164 CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
165 unsigned_char_dynarr *dst, unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
166 static int postprocess_iso2022_mask (int mask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
167 static void reset_iso2022 (Lisp_Object coding_system,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
168 struct iso2022_decoder *iso);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
169 static int detect_coding_iso2022 (struct detection_state *st,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
170 CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
171 unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
172 static void decode_coding_iso2022 (Lstream *decoding,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
173 CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
174 unsigned_char_dynarr *dst, unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
175 static void encode_coding_iso2022 (Lstream *encoding,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
176 CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
177 unsigned_char_dynarr *dst, unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
178 static void decode_coding_no_conversion (Lstream *decoding,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
179 CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
180 unsigned_char_dynarr *dst,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
181 unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
182 static void encode_coding_no_conversion (Lstream *encoding,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
183 CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
184 unsigned_char_dynarr *dst,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
185 unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
186 static void mule_decode (Lstream *decoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
187 unsigned_char_dynarr *dst, unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
188 static void mule_encode (Lstream *encoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
189 unsigned_char_dynarr *dst, unsigned int n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
190
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
191 typedef struct codesys_prop codesys_prop;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
192 struct codesys_prop
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
193 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
194 Lisp_Object sym;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
195 int prop_type;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
196 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
197
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
198 typedef struct
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
199 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
200 Dynarr_declare (codesys_prop);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
201 } codesys_prop_dynarr;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
202
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
203 codesys_prop_dynarr *the_codesys_prop_dynarr;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
204
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
205 enum codesys_prop_enum
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
206 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
207 CODESYS_PROP_ALL_OK,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
208 CODESYS_PROP_ISO2022,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
209 CODESYS_PROP_CCL
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
210 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
211
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
212
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
213 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
214 /* Coding system functions */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
215 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
216
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
217 static Lisp_Object mark_coding_system (Lisp_Object, void (*) (Lisp_Object));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
218 static void print_coding_system (Lisp_Object, Lisp_Object, int);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
219 static void finalize_coding_system (void *header, int for_disksave);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
220
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
221 DEFINE_LRECORD_IMPLEMENTATION ("coding-system", coding_system,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
222 mark_coding_system, print_coding_system,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
223 finalize_coding_system,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
224 0, 0, struct Lisp_Coding_System);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
225
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
226 static Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
227 mark_coding_system (Lisp_Object obj, void (*markobj) (Lisp_Object))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
228 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
229 struct Lisp_Coding_System *codesys = XCODING_SYSTEM (obj);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
230
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
231 (markobj) (CODING_SYSTEM_NAME (codesys));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
232 (markobj) (CODING_SYSTEM_DOC_STRING (codesys));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
233 (markobj) (CODING_SYSTEM_MNEMONIC (codesys));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
234 (markobj) (CODING_SYSTEM_EOL_LF (codesys));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
235 (markobj) (CODING_SYSTEM_EOL_CRLF (codesys));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
236 (markobj) (CODING_SYSTEM_EOL_CR (codesys));
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
237
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
238 switch (CODING_SYSTEM_TYPE (codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
239 {
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
240 int i;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
241 case CODESYS_ISO2022:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
242 for (i = 0; i < 4; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
243 (markobj) (CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
244 if (codesys->iso2022.input_conv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
245 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
246 for (i = 0; i < Dynarr_length (codesys->iso2022.input_conv); i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
247 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
248 struct charset_conversion_spec *ccs =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
249 Dynarr_atp (codesys->iso2022.input_conv, i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
250 (markobj) (ccs->from_charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
251 (markobj) (ccs->to_charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
252 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
253 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
254 if (codesys->iso2022.output_conv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
255 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
256 for (i = 0; i < Dynarr_length (codesys->iso2022.output_conv); i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
257 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
258 struct charset_conversion_spec *ccs =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
259 Dynarr_atp (codesys->iso2022.output_conv, i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
260 (markobj) (ccs->from_charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
261 (markobj) (ccs->to_charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
262 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
263 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
264 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
265
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
266 case CODESYS_CCL:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
267 (markobj) (CODING_SYSTEM_CCL_DECODE (codesys));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
268 (markobj) (CODING_SYSTEM_CCL_ENCODE (codesys));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
269 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
270 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
271 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
272 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
273
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
274 (markobj) (CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
275 return CODING_SYSTEM_POST_READ_CONVERSION (codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
276 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
277
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
278 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
279 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
280 int escapeflag)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
281 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
282 struct Lisp_Coding_System *c = XCODING_SYSTEM (obj);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
283 if (print_readably)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
284 error ("printing unreadable object #<coding_system 0x%x>",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
285 c->header.uid);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
286
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
287 write_c_string ("#<coding_system ", printcharfun);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
288 print_internal (c->name, printcharfun, 1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
289 write_c_string (">", printcharfun);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
290 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
291
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
292 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
293 finalize_coding_system (void *header, int for_disksave)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
294 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
295 struct Lisp_Coding_System *c = (struct Lisp_Coding_System *) header;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
296 /* Since coding systems never go away, this function is not
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
297 necessary. But it would be necessary if we changed things
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
298 so that coding systems could go away. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
299 if (!for_disksave) /* see comment in lstream.c */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
300 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
301 switch (CODING_SYSTEM_TYPE (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
302 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
303 case CODESYS_ISO2022:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
304 if (c->iso2022.input_conv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
305 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
306 Dynarr_free (c->iso2022.input_conv);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
307 c->iso2022.input_conv = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
308 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
309 if (c->iso2022.output_conv)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
310 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
311 Dynarr_free (c->iso2022.output_conv);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
312 c->iso2022.output_conv = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
313 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
314 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
315
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
316 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
317 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
318 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
319 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
320 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
321
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
322 static enum eol_type
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
323 symbol_to_eol_type (Lisp_Object symbol)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
324 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
325 CHECK_SYMBOL (symbol);
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
326 if (NILP (symbol)) return EOL_AUTODETECT;
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
327 if (EQ (symbol, Qlf)) return EOL_LF;
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
328 if (EQ (symbol, Qcrlf)) return EOL_CRLF;
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
329 if (EQ (symbol, Qcr)) return EOL_CR;
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
330
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
331 signal_simple_error ("Unrecognized eol type", symbol);
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
332 return EOL_AUTODETECT; /* not reached */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
333 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
334
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
335 static Lisp_Object
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
336 eol_type_to_symbol (enum eol_type type)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
337 {
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
338 switch (type)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
339 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
340 case EOL_LF: return Qlf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
341 case EOL_CRLF: return Qcrlf;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
342 case EOL_CR: return Qcr;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
343 case EOL_AUTODETECT: return Qnil;
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
344 default: abort (); return Qnil; /* not reached */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
345 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
346 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
347
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
348 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
349 setup_eol_coding_systems (struct Lisp_Coding_System *codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
350 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
351 Lisp_Object codesys_obj = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
352 int len = string_length (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
353 char *codesys_name = (char *) alloca (len + 7);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
354 Lisp_Object codesys_name_sym, sub_codesys_obj;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
355
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
356 /* kludge */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
357
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
358 XSETCODING_SYSTEM (codesys_obj, codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
359
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
360 memcpy (codesys_name,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
361 string_data (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name), len);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
362
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
363 #define DEFINE_SUB_CODESYS(op_sys, Type) do { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
364 strcpy (codesys_name + len, "-" op_sys); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
365 codesys_name_sym = intern (codesys_name); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
366 sub_codesys_obj = Fcopy_coding_system (codesys_obj, codesys_name_sym); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
367 XCODING_SYSTEM_EOL_TYPE (sub_codesys_obj) = Type; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
368 CODING_SYSTEM_##Type (codesys) = sub_codesys_obj; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
369 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
370
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
371 DEFINE_SUB_CODESYS("unix", EOL_LF);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
372 DEFINE_SUB_CODESYS("dos", EOL_CRLF);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
373 DEFINE_SUB_CODESYS("mac", EOL_CR);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
374 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
375
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
376 DEFUN ("coding-system-p", Fcoding_system_p, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
377 T if OBJECT is a coding system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
378 A coding system is an object that defines how text containing multiple
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
379 character sets is encoded into a stream of (typically 8-bit) bytes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
380 The coding system is used to decode the stream into a series of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
381 characters (which may be from multiple charsets) when the text is read
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
382 from a file or process, and is used to encode the text back into the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
383 same format when it is written out to a file or process.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
384
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
385 For example, many ISO2022-compliant coding systems (such as Compound
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
386 Text, which is used for inter-client data under the X Window System)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
387 use escape sequences to switch between different charsets -- Japanese
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
388 Kanji, for example, is invoked with "ESC $ ( B"; ASCII is invoked
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
389 with "ESC ( B"; and Cyrillic is invoked with "ESC - L". See
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
390 `make-coding-system' for more information.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
391
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
392 Coding systems are normally identified using a symbol, and the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
393 symbol is accepted in place of the actual coding system object whenever
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
394 a coding system is called for. (This is similar to how faces work.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
395 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
396 (object))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
397 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
398 return CODING_SYSTEMP (object) ? Qt : Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
399 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
400
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
401 DEFUN ("find-coding-system", Ffind_coding_system, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
402 Retrieve the coding system of the given name.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
403
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
404 If CODING-SYSTEM-OR-NAME is a coding-system object, it is simply
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
405 returned. Otherwise, CODING-SYSTEM-OR-NAME should be a symbol.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
406 If there is no such coding system, nil is returned. Otherwise the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
407 associated coding system object is returned.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
408 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
409 (coding_system_or_name))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
410 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
411 if (NILP (coding_system_or_name))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
412 coding_system_or_name = Qbinary;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
413 if (CODING_SYSTEMP (coding_system_or_name))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
414 return coding_system_or_name;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
415 CHECK_SYMBOL (coding_system_or_name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
416
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
417 return Fgethash (coding_system_or_name, Vcoding_system_hashtable, Qnil);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
418 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
419
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
420 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
421 Retrieve the coding system of the given name.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
422 Same as `find-coding-system' except that if there is no such
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
423 coding system, an error is signaled instead of returning nil.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
424 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
425 (name))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
426 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
427 Lisp_Object coding_system = Ffind_coding_system (name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
428
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
429 if (NILP (coding_system))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
430 signal_simple_error ("No such coding system", name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
431 return coding_system;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
432 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
433
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
434 /* We store the coding systems in hash tables with the names as the key and the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
435 actual coding system object as the value. Occasionally we need to use them
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
436 in a list format. These routines provide us with that. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
437 struct coding_system_list_closure
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
438 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
439 Lisp_Object *coding_system_list;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
440 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
441
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
442 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
443 add_coding_system_to_list_mapper (CONST void *hash_key, void *hash_contents,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
444 void *coding_system_list_closure)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
445 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
446 /* This function can GC */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
447 Lisp_Object key, contents;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
448 Lisp_Object *coding_system_list;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
449 struct coding_system_list_closure *cscl =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
450 (struct coding_system_list_closure *) coding_system_list_closure;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
451 CVOID_TO_LISP (key, hash_key);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
452 VOID_TO_LISP (contents, hash_contents);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
453 coding_system_list = cscl->coding_system_list;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
454
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
455 *coding_system_list = Fcons (XCODING_SYSTEM (contents)->name,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
456 *coding_system_list);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
457 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
458
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
459 DEFUN ("coding-system-list", Fcoding_system_list, 0, 0, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
460 Return a list of the names of all defined coding systems.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
461 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
462 ())
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
463 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
464 Lisp_Object coding_system_list = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
465 struct gcpro gcpro1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
466 struct coding_system_list_closure coding_system_list_closure;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
467
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
468 GCPRO1 (coding_system_list);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
469 coding_system_list_closure.coding_system_list = &coding_system_list;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
470 elisp_maphash (add_coding_system_to_list_mapper, Vcoding_system_hashtable,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
471 &coding_system_list_closure);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
472 UNGCPRO;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
473
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
474 return coding_system_list;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
475 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
476
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
477 DEFUN ("coding-system-name", Fcoding_system_name, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
478 Return the name of the given coding system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
479 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
480 (coding_system))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
481 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
482 coding_system = Fget_coding_system (coding_system);
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
483 return XCODING_SYSTEM_NAME (coding_system);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
484 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
485
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
486 static struct Lisp_Coding_System *
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
487 allocate_coding_system (enum coding_system_type type, Lisp_Object name)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
488 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
489 struct Lisp_Coding_System *codesys =
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
490 alloc_lcrecord_type (struct Lisp_Coding_System, lrecord_coding_system);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
491
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
492 zero_lcrecord (codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
493 CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
494 CODING_SYSTEM_POST_READ_CONVERSION (codesys) = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
495 CODING_SYSTEM_EOL_TYPE (codesys) = EOL_AUTODETECT;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
496 CODING_SYSTEM_EOL_CRLF (codesys) = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
497 CODING_SYSTEM_EOL_CR (codesys) = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
498 CODING_SYSTEM_EOL_LF (codesys) = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
499 CODING_SYSTEM_TYPE (codesys) = type;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
500
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
501 if (type == CODESYS_ISO2022)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
502 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
503 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
504 for (i = 0; i < 4; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
505 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i) = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
506 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
507 else if (type == CODESYS_CCL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
508 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
509 CODING_SYSTEM_CCL_DECODE (codesys) = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
510 CODING_SYSTEM_CCL_ENCODE (codesys) = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
511 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
512
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
513 CODING_SYSTEM_NAME (codesys) = name;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
514
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
515 return codesys;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
516 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
517
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
518 /* Given a list of charset conversion specs as specified in a Lisp
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
519 program, parse it into STORE_HERE. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
520
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
521 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
522 parse_charset_conversion_specs (charset_conversion_spec_dynarr *store_here,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
523 Lisp_Object spec_list)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
524 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
525 Lisp_Object rest;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
526
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
527 EXTERNAL_LIST_LOOP (rest, spec_list)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
528 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
529 Lisp_Object car = XCAR (rest);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
530 Lisp_Object from, to;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
531 struct charset_conversion_spec spec;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
532
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
533 if (!CONSP (car) || !CONSP (XCDR (car)) || !NILP (XCDR (XCDR (car))))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
534 signal_simple_error ("Invalid charset conversion spec", car);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
535 from = Fget_charset (XCAR (car));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
536 to = Fget_charset (XCAR (XCDR (car)));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
537 if (XCHARSET_TYPE (from) != XCHARSET_TYPE (to))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
538 signal_simple_error_2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
539 ("Attempted conversion between different charset types",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
540 from, to);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
541 spec.from_charset = from;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
542 spec.to_charset = to;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
543
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
544 Dynarr_add (store_here, spec);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
545 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
546 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
547
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
548 /* Given a dynarr LOAD_HERE of internally-stored charset conversion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
549 specs, return the equivalent as the Lisp programmer would see it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
550
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
551 If LOAD_HERE is 0, return Qnil. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
552
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
553 static Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
554 unparse_charset_conversion_specs (charset_conversion_spec_dynarr *load_here)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
555 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
556 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
557 Lisp_Object result = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
558
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
559 if (!load_here)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
560 return Qnil;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
561 for (i = 0; i < Dynarr_length (load_here); i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
562 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
563 struct charset_conversion_spec *ccs =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
564 Dynarr_atp (load_here, i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
565 result = Fcons (list2 (ccs->from_charset, ccs->to_charset), result);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
566 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
567
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
568 return Fnreverse (result);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
569 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
570
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
571 DEFUN ("make-coding-system", Fmake_coding_system, 2, 4, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
572 Register symbol NAME as a coding system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
573
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
574 TYPE describes the conversion method used and should be one of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
575
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
576 nil or 'undecided
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
577 Automatic conversion. XEmacs attempts to detect the coding system
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
578 used in the file.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
579 'no-conversion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
580 No conversion. Use this for binary files and such. On output,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
581 graphic characters that are not in ASCII or Latin-1 will be
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
582 replaced by a ?. (For a no-conversion-encoded buffer, these
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
583 characters will only be present if you explicitly insert them.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
584 'shift-jis
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
585 Shift-JIS (a Japanese encoding commonly used in PC operating systems).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
586 'iso2022
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
587 Any ISO2022-compliant encoding. Among other things, this includes
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
588 JIS (the Japanese encoding commonly used for e-mail), EUC (the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
589 standard Unix encoding for Japanese and other languages), and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
590 Compound Text (the encoding used in X11). You can specify more
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
591 specific information about the conversion with the FLAGS argument.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
592 'big5
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
593 Big5 (the encoding commonly used for Taiwanese).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
594 'ccl
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
595 The conversion is performed using a user-written pseudo-code
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
596 program. CCL (Code Conversion Language) is the name of this
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
597 pseudo-code.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
598 'internal
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
599 Write out or read in the raw contents of the memory representing
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
600 the buffer's text. This is primarily useful for debugging
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
601 purposes, and is only enabled when XEmacs has been compiled with
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
602 DEBUG_XEMACS defined (via the --debug configure option).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
603 WARNING: Reading in a file using 'internal conversion can result
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
604 in an internal inconsistency in the memory representing a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
605 buffer's text, which will produce unpredictable results and may
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
606 cause XEmacs to crash. Under normal circumstances you should
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
607 never use 'internal conversion.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
608
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
609 DOC-STRING is a string describing the coding system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
610
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
611 PROPS is a property list, describing the specific nature of the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
612 character set. Recognized properties are:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
613
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
614 'mnemonic
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
615 String to be displayed in the modeline when this coding system is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
616 active.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
617
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
618 'eol-type
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
619 End-of-line conversion to be used. It should be one of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
620
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
621 nil
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
622 Automatically detect the end-of-line type (LF, CRLF,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
623 or CR). Also generate subsidiary coding systems named
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
624 `NAME-unix', `NAME-dos', and `NAME-mac', that are
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
625 identical to this coding system but have an EOL-TYPE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
626 value of 'lf, 'crlf, and 'cr, respectively.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
627 'lf
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
628 The end of a line is marked externally using ASCII LF.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
629 Since this is also the way that XEmacs represents an
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
630 end-of-line internally, specifying this option results
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
631 in no end-of-line conversion. This is the standard
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
632 format for Unix text files.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
633 'crlf
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
634 The end of a line is marked externally using ASCII
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
635 CRLF. This is the standard format for MS-DOS text
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
636 files.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
637 'cr
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
638 The end of a line is marked externally using ASCII CR.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
639 This is the standard format for Macintosh text files.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
640 t
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
641 Automatically detect the end-of-line type but do not
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
642 generate subsidiary coding systems. (This value is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
643 converted to nil when stored internally, and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
644 `coding-system-property' will return nil.)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
645
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
646 'post-read-conversion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
647 Function called after a file has been read in, to perform the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
648 decoding. Called with two arguments, BEG and END, denoting
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
649 a region of the current buffer to be decoded.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
650
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
651 'pre-write-conversion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
652 Function called before a file is written out, to perform the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
653 encoding. Called with two arguments, BEG and END, denoting
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
654 a region of the current buffer to be encoded.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
655
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
656
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
657 The following additional properties are recognized if TYPE is 'iso2022:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
658
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
659 'charset-g0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
660 'charset-g1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
661 'charset-g2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
662 'charset-g3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
663 The character set initially designated to the G0 - G3 registers.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
664 The value should be one of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
665
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
666 -- A charset object (designate that character set)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
667 -- nil (do not ever use this register)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
668 -- t (no character set is initially designated to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
669 the register, but may be later on; this automatically
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
670 sets the corresponding `force-g*-on-output' property)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
671
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
672 'force-g0-on-output
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
673 'force-g1-on-output
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
674 'force-g2-on-output
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
675 'force-g2-on-output
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
676 If non-nil, send an explicit designation sequence on output before
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
677 using the specified register.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
678
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
679 'short
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
680 If non-nil, use the short forms "ESC $ @", "ESC $ A", and
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
681 "ESC $ B" on output in place of the full designation sequences
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
682 "ESC $ ( @", "ESC $ ( A", and "ESC $ ( B".
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
683
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
684 'no-ascii-eol
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
685 If non-nil, don't designate ASCII to G0 at each end of line on output.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
686 Setting this to non-nil also suppresses other state-resetting that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
687 normally happens at the end of a line.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
688
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
689 'no-ascii-cntl
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
690 If non-nil, don't designate ASCII to G0 before control chars on output.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
691
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
692 'seven
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
693 If non-nil, use 7-bit environment on output. Otherwise, use 8-bit
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
694 environment.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
695
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
696 'lock-shift
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
697 If non-nil, use locking-shift (SO/SI) instead of single-shift
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
698 or designation by escape sequence.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
699
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
700 'no-iso6429
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
701 If non-nil, don't use ISO6429's direction specification.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
702
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
703 'escape-quoted
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
704 If non-nil, literal control characters that are the same as
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
705 the beginning of a recognized ISO2022 or ISO6429 escape sequence
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
706 (in particular, ESC (0x1B), SO (0x0E), SI (0x0F), SS2 (0x8E),
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
707 SS3 (0x8F), and CSI (0x9B)) are "quoted" with an escape character
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
708 so that they can be properly distinguished from an escape sequence.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
709 (Note that doing this results in a non-portable encoding.) This
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
710 encoding flag is used for byte-compiled files. Note that ESC
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
711 is a good choice for a quoting character because there are no
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
712 escape sequences whose second byte is a character from the Control-0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
713 or Control-1 character sets; this is explicitly disallowed by the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
714 ISO2022 standard.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
715
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
716 'input-charset-conversion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
717 A list of conversion specifications, specifying conversion of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
718 characters in one charset to another when decoding is performed.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
719 Each specification is a list of two elements: the source charset,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
720 and the destination charset.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
721
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
722 'output-charset-conversion
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
723 A list of conversion specifications, specifying conversion of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
724 characters in one charset to another when encoding is performed.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
725 The form of each specification is the same as for
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
726 'input-charset-conversion.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
727
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
728
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
729 The following additional properties are recognized (and required)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
730 if TYPE is 'ccl:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
731
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
732 'decode
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
733 CCL program used for decoding (converting to internal format).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
734
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
735 'encode
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
736 CCL program used for encoding (converting to external format).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
737 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
738 (name, type, doc_string, props))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
739 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
740 struct Lisp_Coding_System *codesys;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
741 Lisp_Object rest, key, value;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
742 enum coding_system_type ty;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
743 int need_to_setup_eol_systems = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
744
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
745 /* Convert type to constant */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
746 if (NILP (type) || EQ (type, Qundecided))
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
747 { ty = CODESYS_AUTODETECT; }
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
748 else if (EQ (type, Qshift_jis)) { ty = CODESYS_SHIFT_JIS; }
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
749 else if (EQ (type, Qiso2022)) { ty = CODESYS_ISO2022; }
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
750 else if (EQ (type, Qbig5)) { ty = CODESYS_BIG5; }
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
751 else if (EQ (type, Qccl)) { ty = CODESYS_CCL; }
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
752 else if (EQ (type, Qno_conversion)) { ty = CODESYS_NO_CONVERSION; }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
753 #ifdef DEBUG_XEMACS
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
754 else if (EQ (type, Qinternal)) { ty = CODESYS_INTERNAL; }
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
755 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
756 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
757 signal_simple_error ("Invalid coding system type", type);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
758
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
759 CHECK_SYMBOL (name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
760
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
761 codesys = allocate_coding_system (ty, name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
762
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
763 if (NILP (doc_string))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
764 doc_string = build_string ("");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
765 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
766 CHECK_STRING (doc_string);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
767 CODING_SYSTEM_DOC_STRING (codesys) = doc_string;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
768
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
769 EXTERNAL_PROPERTY_LIST_LOOP (rest, key, value, props)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
770 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
771 if (EQ (key, Qmnemonic))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
772 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
773 if (!NILP (value))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
774 CHECK_STRING (value);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
775 CODING_SYSTEM_MNEMONIC (codesys) = value;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
776 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
777
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
778 else if (EQ (key, Qeol_type))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
779 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
780 need_to_setup_eol_systems = NILP (value);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
781 if (EQ (value, Qt))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
782 value = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
783 CODING_SYSTEM_EOL_TYPE (codesys) = symbol_to_eol_type (value);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
784 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
785
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
786 else if (EQ (key, Qpost_read_conversion)) CODING_SYSTEM_POST_READ_CONVERSION (codesys) = value;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
787 else if (EQ (key, Qpre_write_conversion)) CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = value;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
788 else if (ty == CODESYS_ISO2022)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
789 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
790 #define FROB_INITIAL_CHARSET(charset_num) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
791 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, charset_num) = \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
792 ((EQ (value, Qt) || EQ (value, Qnil)) ? value : Fget_charset (value))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
793
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
794 if (EQ (key, Qcharset_g0)) FROB_INITIAL_CHARSET (0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
795 else if (EQ (key, Qcharset_g1)) FROB_INITIAL_CHARSET (1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
796 else if (EQ (key, Qcharset_g2)) FROB_INITIAL_CHARSET (2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
797 else if (EQ (key, Qcharset_g3)) FROB_INITIAL_CHARSET (3);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
798
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
799 #define FROB_FORCE_CHARSET(charset_num) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
800 CODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT (codesys, charset_num) = !NILP (value)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
801
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
802 else if (EQ (key, Qforce_g0_on_output)) FROB_FORCE_CHARSET (0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
803 else if (EQ (key, Qforce_g1_on_output)) FROB_FORCE_CHARSET (1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
804 else if (EQ (key, Qforce_g2_on_output)) FROB_FORCE_CHARSET (2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
805 else if (EQ (key, Qforce_g3_on_output)) FROB_FORCE_CHARSET (3);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
806
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
807 #define FROB_BOOLEAN_PROPERTY(prop) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
808 CODING_SYSTEM_ISO2022_##prop (codesys) = !NILP (value)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
809
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
810 else if (EQ (key, Qshort)) FROB_BOOLEAN_PROPERTY (SHORT);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
811 else if (EQ (key, Qno_ascii_eol)) FROB_BOOLEAN_PROPERTY (NO_ASCII_EOL);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
812 else if (EQ (key, Qno_ascii_cntl)) FROB_BOOLEAN_PROPERTY (NO_ASCII_CNTL);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
813 else if (EQ (key, Qseven)) FROB_BOOLEAN_PROPERTY (SEVEN);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
814 else if (EQ (key, Qlock_shift)) FROB_BOOLEAN_PROPERTY (LOCK_SHIFT);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
815 else if (EQ (key, Qno_iso6429)) FROB_BOOLEAN_PROPERTY (NO_ISO6429);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
816 else if (EQ (key, Qescape_quoted)) FROB_BOOLEAN_PROPERTY (ESCAPE_QUOTED);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
817
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
818 else if (EQ (key, Qinput_charset_conversion))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
819 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
820 codesys->iso2022.input_conv =
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
821 Dynarr_new (charset_conversion_spec);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
822 parse_charset_conversion_specs (codesys->iso2022.input_conv,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
823 value);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
824 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
825 else if (EQ (key, Qoutput_charset_conversion))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
826 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
827 codesys->iso2022.output_conv =
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
828 Dynarr_new (charset_conversion_spec);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
829 parse_charset_conversion_specs (codesys->iso2022.output_conv,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
830 value);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
831 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
832 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
833 signal_simple_error ("Unrecognized property", key);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
834 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
835 else if (EQ (type, Qccl))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
836 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
837 if (EQ (key, Qdecode))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
838 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
839 CHECK_VECTOR (value);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
840 CODING_SYSTEM_CCL_DECODE (codesys) = value;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
841 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
842 else if (EQ (key, Qencode))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
843 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
844 CHECK_VECTOR (value);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
845 CODING_SYSTEM_CCL_ENCODE (codesys) = value;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
846 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
847 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
848 signal_simple_error ("Unrecognized property", key);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
849 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
850 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
851 signal_simple_error ("Unrecognized property", key);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
852 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
853
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
854 if (need_to_setup_eol_systems)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
855 setup_eol_coding_systems (codesys);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
856
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
857 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
858 Lisp_Object codesys_obj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
859 XSETCODING_SYSTEM (codesys_obj, codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
860 Fputhash (name, codesys_obj, Vcoding_system_hashtable);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
861 return codesys_obj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
862 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
863 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
864
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
865 DEFUN ("copy-coding-system", Fcopy_coding_system, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
866 Copy OLD-CODING-SYSTEM to NEW-NAME.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
867 If NEW-NAME does not name an existing coding system, a new one will
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
868 be created.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
869 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
870 (old_coding_system, new_name))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
871 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
872 Lisp_Object new_coding_system;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
873 old_coding_system = Fget_coding_system (old_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
874 new_coding_system = Ffind_coding_system (new_name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
875 if (NILP (new_coding_system))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
876 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
877 XSETCODING_SYSTEM (new_coding_system,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
878 allocate_coding_system
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
879 (XCODING_SYSTEM_TYPE (old_coding_system),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
880 new_name));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
881 Fputhash (new_name, new_coding_system, Vcoding_system_hashtable);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
882 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
883
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
884 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
885 struct Lisp_Coding_System *to = XCODING_SYSTEM (new_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
886 struct Lisp_Coding_System *from = XCODING_SYSTEM (old_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
887 memcpy (((char *) to ) + sizeof (to->header),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
888 ((char *) from) + sizeof (from->header),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
889 sizeof (*from) - sizeof (from->header));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
890 to->name = new_name;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
891 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
892 return new_coding_system;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
893 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
894
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
895 static Lisp_Object
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
896 subsidiary_coding_system (Lisp_Object coding_system, enum eol_type type)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
897 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
898 struct Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
899 Lisp_Object new_coding_system;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
900
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
901 if (CODING_SYSTEM_EOL_TYPE (cs) != EOL_AUTODETECT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
902 return coding_system;
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
903
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
904 switch (type)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
905 {
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
906 case EOL_AUTODETECT: return coding_system;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
907 case EOL_LF: new_coding_system = CODING_SYSTEM_EOL_LF (cs); break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
908 case EOL_CR: new_coding_system = CODING_SYSTEM_EOL_CR (cs); break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
909 case EOL_CRLF: new_coding_system = CODING_SYSTEM_EOL_CRLF (cs); break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
910 default: abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
911 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
912
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
913 return NILP (new_coding_system) ? coding_system : new_coding_system;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
914 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
915
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
916 DEFUN ("subsidiary-coding-system", Fsubsidiary_coding_system, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
917 Return the subsidiary coding system of CODING-SYSTEM with eol type EOL-TYPE.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
918 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
919 (coding_system, eol_type))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
920 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
921 coding_system = Fget_coding_system (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
922
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
923 return subsidiary_coding_system (coding_system,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
924 symbol_to_eol_type (eol_type));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
925 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
926
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
927
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
928 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
929 /* Coding system accessors */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
930 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
931
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
932 DEFUN ("coding-system-doc-string", Fcoding_system_doc_string, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
933 Return the doc string for CODING-SYSTEM.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
934 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
935 (coding_system))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
936 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
937 coding_system = Fget_coding_system (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
938 return XCODING_SYSTEM_DOC_STRING (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
939 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
940
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
941 DEFUN ("coding-system-type", Fcoding_system_type, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
942 Return the type of CODING-SYSTEM.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
943 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
944 (coding_system))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
945 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
946 switch (XCODING_SYSTEM_TYPE (Fget_coding_system (coding_system)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
947 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
948 case CODESYS_AUTODETECT: return Qundecided;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
949 case CODESYS_SHIFT_JIS: return Qshift_jis;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
950 case CODESYS_ISO2022: return Qiso2022;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
951 case CODESYS_BIG5: return Qbig5;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
952 case CODESYS_CCL: return Qccl;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
953 case CODESYS_NO_CONVERSION: return Qno_conversion;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
954 #ifdef DEBUG_XEMACS
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
955 case CODESYS_INTERNAL: return Qinternal;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
956 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
957 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
958 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
959 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
960
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
961 return Qnil; /* not reached */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
962 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
963
209
41ff10fd062f Import from CVS: tag r20-4b3
cvs
parents: 207
diff changeset
964 Lisp_Object coding_system_charset (Lisp_Object coding_system, int gnum)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
965 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
966 Lisp_Object cs
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
967 = XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, gnum);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
968
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
969 if (CHARSETP(cs)){
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
970 return XCHARSET_NAME(cs);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
971 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
972 else {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
973 return Qnil;
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
974 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
975 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
976
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
977 DEFUN ("coding-system-charset", Fcoding_system_charset, 2, 2, 0, /*
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
978 Return initial charset of CODING-SYSTEM designated to GNUM.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
979 GNUM allows 0 .. 3.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
980 */
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
981 (coding_system, gnum))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
982 {
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
983 coding_system = Fget_coding_system (coding_system);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
984 CHECK_INT (gnum);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
985
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
986 return coding_system_charset(coding_system, XINT (gnum));
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
987 }
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
988
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
989 DEFUN ("coding-system-property", Fcoding_system_property, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
990 Return the PROP property of CODING-SYSTEM.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
991 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
992 (coding_system, prop))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
993 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
994 int i, ok = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
995 enum coding_system_type type;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
996
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
997 coding_system = Fget_coding_system (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
998 CHECK_SYMBOL (prop);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
999 type = XCODING_SYSTEM_TYPE (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1000
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1001 for (i = 0; !ok && i < Dynarr_length (the_codesys_prop_dynarr); i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1002 if (EQ (Dynarr_at (the_codesys_prop_dynarr, i).sym, prop))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1003 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1004 ok = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1005 switch (Dynarr_at (the_codesys_prop_dynarr, i).prop_type)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1006 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1007 case CODESYS_PROP_ALL_OK:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1008 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1009
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1010 case CODESYS_PROP_ISO2022:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1011 if (type != CODESYS_ISO2022)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1012 signal_simple_error
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1013 ("Property only valid in ISO2022 coding systems",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1014 prop);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1015 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1016
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1017 case CODESYS_PROP_CCL:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1018 if (type != CODESYS_CCL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1019 signal_simple_error
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1020 ("Property only valid in CCL coding systems",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1021 prop);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1022 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1023
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1024 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1025 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1026 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1027 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1028
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1029 if (!ok)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1030 signal_simple_error ("Unrecognized property", prop);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1031
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1032 if (EQ (prop, Qname))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1033 return XCODING_SYSTEM_NAME (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1034 else if (EQ (prop, Qtype))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1035 return Fcoding_system_type (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1036 else if (EQ (prop, Qdoc_string))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1037 return XCODING_SYSTEM_DOC_STRING (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1038 else if (EQ (prop, Qmnemonic))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1039 return XCODING_SYSTEM_MNEMONIC (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1040 else if (EQ (prop, Qeol_type))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1041 return eol_type_to_symbol (XCODING_SYSTEM_EOL_TYPE (coding_system));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1042 else if (EQ (prop, Qeol_lf))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1043 return XCODING_SYSTEM_EOL_LF (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1044 else if (EQ (prop, Qeol_crlf))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1045 return XCODING_SYSTEM_EOL_CRLF (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1046 else if (EQ (prop, Qeol_cr))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1047 return XCODING_SYSTEM_EOL_CR (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1048 else if (EQ (prop, Qpost_read_conversion))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1049 return XCODING_SYSTEM_POST_READ_CONVERSION (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1050 else if (EQ (prop, Qpre_write_conversion))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1051 return XCODING_SYSTEM_PRE_WRITE_CONVERSION (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1052 else if (type == CODESYS_ISO2022)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1053 {
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1054 if (EQ (prop, Qcharset_g0))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1055 return coding_system_charset (coding_system, 0);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1056 else if (EQ (prop, Qcharset_g1))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1057 return coding_system_charset (coding_system, 1);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1058 else if (EQ (prop, Qcharset_g2))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1059 return coding_system_charset (coding_system, 2);
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1060 else if (EQ (prop, Qcharset_g3))
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1061 return coding_system_charset (coding_system, 3);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1062
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1063 #define FORCE_CHARSET(charset_num) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1064 (XCODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1065 (coding_system, charset_num) ? Qt : Qnil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1066
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1067 else if (EQ (prop, Qforce_g0_on_output)) return FORCE_CHARSET (0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1068 else if (EQ (prop, Qforce_g1_on_output)) return FORCE_CHARSET (1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1069 else if (EQ (prop, Qforce_g2_on_output)) return FORCE_CHARSET (2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1070 else if (EQ (prop, Qforce_g3_on_output)) return FORCE_CHARSET (3);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1071
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1072 #define LISP_BOOLEAN(prop) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1073 (XCODING_SYSTEM_ISO2022_##prop (coding_system) ? Qt : Qnil)
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1074
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1075 else if (EQ (prop, Qshort)) return LISP_BOOLEAN (SHORT);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1076 else if (EQ (prop, Qno_ascii_eol)) return LISP_BOOLEAN (NO_ASCII_EOL);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1077 else if (EQ (prop, Qno_ascii_cntl)) return LISP_BOOLEAN (NO_ASCII_CNTL);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1078 else if (EQ (prop, Qseven)) return LISP_BOOLEAN (SEVEN);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1079 else if (EQ (prop, Qlock_shift)) return LISP_BOOLEAN (LOCK_SHIFT);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1080 else if (EQ (prop, Qno_iso6429)) return LISP_BOOLEAN (NO_ISO6429);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1081 else if (EQ (prop, Qescape_quoted)) return LISP_BOOLEAN (ESCAPE_QUOTED);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1082
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1083 else if (EQ (prop, Qinput_charset_conversion))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1084 return
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1085 unparse_charset_conversion_specs
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1086 (XCODING_SYSTEM (coding_system)->iso2022.input_conv);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1087 else if (EQ (prop, Qoutput_charset_conversion))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1088 return
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1089 unparse_charset_conversion_specs
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1090 (XCODING_SYSTEM (coding_system)->iso2022.output_conv);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1091 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1092 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1093 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1094 else if (type == CODESYS_CCL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1095 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1096 if (EQ (prop, Qdecode))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1097 return XCODING_SYSTEM_CCL_DECODE (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1098 else if (EQ (prop, Qencode))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1099 return XCODING_SYSTEM_CCL_ENCODE (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1100 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1101 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1102 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1103 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1104 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1105
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1106 return Qnil; /* not reached */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1107 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1108
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1109
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1110 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1111 /* Coding category functions */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1112 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1113
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1114 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1115 decode_coding_category (Lisp_Object symbol)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1116 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1117 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1118
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1119 CHECK_SYMBOL (symbol);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1120 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1121 if (EQ (coding_category_symbol[i], symbol))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1122 return i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1123
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1124 signal_simple_error ("Unrecognized coding category", symbol);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1125 return 0; /* not reached */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1126 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1127
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1128 DEFUN ("coding-category-list", Fcoding_category_list, 0, 0, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1129 Return a list of all recognized coding categories.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1130 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1131 ())
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1132 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1133 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1134 Lisp_Object list = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1135
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1136 for (i = CODING_CATEGORY_LAST; i >= 0; i--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1137 list = Fcons (coding_category_symbol[i], list);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1138 return list;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1139 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1140
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1141 DEFUN ("set-coding-priority-list", Fset_coding_priority_list, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1142 Change the priority order of the coding categories.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1143 LIST should be list of coding categories, in descending order of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1144 priority. Unspecified coding categories will be lower in priority
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1145 than all specified ones, in the same relative order they were in
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1146 previously.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1147 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1148 (list))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1149 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1150 int category_to_priority[CODING_CATEGORY_LAST + 1];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1151 int i, j;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1152 Lisp_Object rest;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1153
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1154 /* First generate a list that maps coding categories to priorities. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1155
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1156 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1157 category_to_priority[i] = -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1158
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1159 /* Highest priority comes from the specified list. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1160 i = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1161 EXTERNAL_LIST_LOOP (rest, list)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1162 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1163 int cat = decode_coding_category (XCAR (rest));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1164
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1165 if (category_to_priority[cat] >= 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1166 signal_simple_error ("Duplicate coding category in list", XCAR (rest));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1167 category_to_priority[cat] = i++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1168 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1169
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1170 /* Now go through the existing categories by priority to retrieve
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1171 the categories not yet specified and preserve their priority
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1172 order. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1173 for (j = 0; j <= CODING_CATEGORY_LAST; j++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1174 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1175 int cat = coding_category_by_priority[j];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1176 if (category_to_priority[cat] < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1177 category_to_priority[cat] = i++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1178 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1179
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1180 /* Now we need to construct the inverse of the mapping we just
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1181 constructed. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1182
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1183 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1184 coding_category_by_priority[category_to_priority[i]] = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1185
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1186 /* Phew! That was confusing. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1187 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1188 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1189
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1190 DEFUN ("coding-priority-list", Fcoding_priority_list, 0, 0, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1191 Return a list of coding categories in descending order of priority.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1192 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1193 ())
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1194 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1195 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1196 Lisp_Object list = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1197
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1198 for (i = CODING_CATEGORY_LAST; i >= 0; i--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1199 list = Fcons (coding_category_symbol[coding_category_by_priority[i]],
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1200 list);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1201 return list;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1202 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1203
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1204 DEFUN ("set-coding-category-system", Fset_coding_category_system, 2, 2, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1205 Change the coding system associated with a coding category.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1206 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1207 (coding_category, coding_system))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1208 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1209 int cat = decode_coding_category (coding_category);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1210
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1211 coding_system = Fget_coding_system (coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1212 coding_category_system[cat] = coding_system;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1213 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1214 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1215
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1216 DEFUN ("coding-category-system", Fcoding_category_system, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1217 Return the coding system associated with a coding category.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1218 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1219 (coding_category))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1220 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1221 int cat = decode_coding_category (coding_category);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1222 Lisp_Object sys = coding_category_system[cat];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1223
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1224 if (!NILP (sys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1225 return XCODING_SYSTEM_NAME (sys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1226 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1227 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1228
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1229
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1230 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1231 /* Detecting the encoding of data */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1232 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1233
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1234 struct detection_state
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1235 {
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
1236 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1237 int seen_non_ascii;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1238 int mask;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1239
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1240 struct
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1241 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1242 int mask;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1243 int in_second_byte;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1244 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1245 big5;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1246
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1247 struct
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1248 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1249 int mask;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1250 int in_second_byte;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1251 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1252 shift_jis;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1253
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1254 struct
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1255 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1256 int mask;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1257 int initted;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1258 struct iso2022_decoder iso;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1259 unsigned int flags;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1260 int high_byte_count;
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1261 unsigned int saw_single_shift:1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1262 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1263 iso2022;
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1264
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1265 struct
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1266 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1267 int seen_anything;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1268 int just_saw_cr;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1269 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1270 eol;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1271 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1272
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1273 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1274 acceptable_control_char_p (int c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1275 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1276 switch (c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1277 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1278 /* Allow and ignore control characters that you might
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1279 reasonably see in a text file */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1280 case '\r':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1281 case '\n':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1282 case '\t':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1283 case 7: /* bell */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1284 case 8: /* backspace */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1285 case 11: /* vertical tab */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1286 case 12: /* form feed */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1287 case 26: /* MS-DOS C-z junk */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1288 case 31: /* '^_' -- for info */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1289 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1290 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1291 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1292 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1293 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1294
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1295 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1296 mask_has_at_most_one_bit_p (int mask)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1297 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1298 /* Perhaps the only thing useful you learn from intensive Microsoft
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1299 technical interviews */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1300 return (mask & (mask - 1)) == 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1301 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1302
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
1303 static enum eol_type
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1304 detect_eol_type (struct detection_state *st, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1305 unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1306 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1307 int c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1308
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1309 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1310 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1311 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1312 if (c == '\r')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1313 st->eol.just_saw_cr = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1314 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1315 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1316 if (c == '\n')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1317 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1318 if (st->eol.just_saw_cr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1319 return EOL_CRLF;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1320 else if (st->eol.seen_anything)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1321 return EOL_LF;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1322 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1323 else if (st->eol.just_saw_cr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1324 return EOL_CR;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1325 st->eol.just_saw_cr = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1326 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1327 st->eol.seen_anything = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1328 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1329
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1330 return EOL_AUTODETECT;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1331 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1332
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1333 /* Attempt to determine the encoding and EOL type of the given text.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1334 Before calling this function for the first type, you must initialize
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1335 st->eol_type as appropriate and initialize st->mask to ~0.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1336
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1337 st->eol_type holds the determined EOL type, or EOL_AUTODETECT if
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1338 not yet known.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1339
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1340 st->mask holds the determined coding category mask, or ~0 if only
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1341 ASCII has been seen so far.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1342
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1343 Returns:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1344
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1345 0 == st->eol_type is EOL_AUTODETECT and/or more than coding category
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1346 is present in st->mask
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1347 1 == definitive answers are here for both st->eol_type and st->mask
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1348 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1349
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1350 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1351 detect_coding_type (struct detection_state *st, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1352 unsigned int n, int just_do_eol)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1353 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1354 int c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1355
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1356 if (st->eol_type == EOL_AUTODETECT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1357 st->eol_type = detect_eol_type (st, src, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1358
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1359 if (just_do_eol)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1360 return st->eol_type != EOL_AUTODETECT;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1361
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1362 if (!st->seen_non_ascii)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1363 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1364 for (; n; n--, src++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1365 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1366 c = *src;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1367 if ((c < 0x20 && !acceptable_control_char_p (c)) || c >= 0x80)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1368 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1369 st->seen_non_ascii = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1370 st->shift_jis.mask = ~0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1371 st->big5.mask = ~0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1372 st->iso2022.mask = ~0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1373 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1374 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1375 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1376 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1377
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1378 if (!n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1379 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1380
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1381 if (!mask_has_at_most_one_bit_p (st->iso2022.mask))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1382 st->iso2022.mask = detect_coding_iso2022 (st, src, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1383 if (!mask_has_at_most_one_bit_p (st->shift_jis.mask))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1384 st->shift_jis.mask = detect_coding_sjis (st, src, n);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1385 if (!mask_has_at_most_one_bit_p (st->big5.mask))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1386 st->big5.mask = detect_coding_big5 (st, src, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1387
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1388 st->mask = st->iso2022.mask | st->shift_jis.mask | st->big5.mask;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1389
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1390 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1391 int retval = mask_has_at_most_one_bit_p (st->mask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1392 st->mask |= CODING_CATEGORY_NO_CONVERSION_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1393 return retval && st->eol_type != EOL_AUTODETECT;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1394 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1395 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1396
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1397 static Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1398 coding_system_from_mask (int mask)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1399 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1400 if (mask == ~0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1401 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1402 /* If the file was entirely or basically ASCII, use the
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 96
diff changeset
1403 default value of `buffer-file-coding-system'. */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1404 Lisp_Object retval =
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 96
diff changeset
1405 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1406 if (!NILP (retval))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1407 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1408 retval = Ffind_coding_system (retval);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1409 if (NILP (retval))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1410 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1411 warn_when_safe
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1412 (Qbad_variable, Qwarning,
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 96
diff changeset
1413 "Invalid `default-buffer-file-coding-system', set to nil");
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 96
diff changeset
1414 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system = Qnil;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1415 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1416 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1417 if (NILP (retval))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1418 retval = Fget_coding_system (Qno_conversion);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1419 return retval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1420 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1421 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1422 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1423 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1424 int cat = -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1425
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1426 mask = postprocess_iso2022_mask (mask);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1427
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1428 /* Look through the coding categories by priority and find
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1429 the first one that is allowed. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1430 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1431 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1432 cat = coding_category_by_priority[i];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1433 if ((mask & (1 << cat)) &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1434 !NILP (coding_category_system[cat]))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1435 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1436 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1437 if (cat >= 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1438 return coding_category_system[cat];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1439 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1440 return Fget_coding_system (Qno_conversion);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1441 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1442 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1443
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1444 /* Given a seekable read stream and potential coding system and EOL type
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1445 as specified, do any autodetection that is called for. If the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1446 coding system and/or EOL type are not autodetect, they will be left
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1447 alone; but this function will never return an autodetect coding system
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1448 or EOL type.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1449
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1450 This function does not automatically fetch subsidiary coding systems;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1451 that should be unnecessary with the explicit eol-type argument. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1452
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1453 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1454 determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out,
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
1455 enum eol_type *eol_type_in_out)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1456 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1457 struct detection_state decst;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1458
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1459 if (*eol_type_in_out == EOL_AUTODETECT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1460 *eol_type_in_out = XCODING_SYSTEM_EOL_TYPE (*codesys_in_out);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1461
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1462 memset (&decst, 0, sizeof (decst));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1463 decst.eol_type = *eol_type_in_out;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1464 decst.mask = ~0;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1465
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1466 /* If autodetection is called for, do it now. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1467 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1468 *eol_type_in_out == EOL_AUTODETECT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1469 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1470
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1471 while (1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1472 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1473 unsigned char random_buffer[4096];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1474 int nread;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1475
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1476 nread = Lstream_read (stream, random_buffer, sizeof (random_buffer));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1477 if (!nread)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1478 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1479 if (detect_coding_type (&decst, random_buffer, nread,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1480 XCODING_SYSTEM_TYPE (*codesys_in_out) !=
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1481 CODESYS_AUTODETECT))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1482 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1483 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1484
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1485 *eol_type_in_out = decst.eol_type;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1486 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1487 *codesys_in_out = coding_system_from_mask (decst.mask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1488 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1489
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1490 /* If we absolutely can't determine the EOL type, just assume LF. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1491 if (*eol_type_in_out == EOL_AUTODETECT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1492 *eol_type_in_out = EOL_LF;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1493
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1494 Lstream_rewind (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1495 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1496
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1497 DEFUN ("detect-coding-region", Fdetect_coding_region, 2, 3, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1498 Detect coding system of the text in the region between START and END.
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1499 Returned a list of possible coding systems ordered by priority.
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1500 If only ASCII characters are found, it returns 'undecided or one of
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1501 its subsidiary coding systems according to a detected end-of-line
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1502 type. Optional arg BUFFER defaults to the current buffer.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1503 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1504 (start, end, buffer))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1505 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1506 Lisp_Object val = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1507 struct buffer *buf = decode_buffer (buffer, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1508 Bufpos b, e;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1509 Lisp_Object instream, lb_instream;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1510 Lstream *istr, *lb_istr;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1511 struct detection_state decst;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1512 struct gcpro gcpro1, gcpro2;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1513
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1514 get_buffer_range_char (buf, start, end, &b, &e, 0);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1515 lb_instream = make_lisp_buffer_input_stream (buf, b, e, 0);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1516 lb_istr = XLSTREAM (lb_instream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1517 instream = make_encoding_input_stream (lb_istr, Fget_coding_system (Qbinary));
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1518 istr = XLSTREAM (instream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1519 GCPRO2 (instream, lb_instream);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1520 memset (&decst, 0, sizeof (decst));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1521 decst.eol_type = EOL_AUTODETECT;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1522 decst.mask = ~0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1523 while (1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1524 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1525 unsigned char random_buffer[4096];
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1526 int nread = Lstream_read (istr, random_buffer, sizeof (random_buffer));
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1527
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1528 if (!nread)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1529 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1530 if (detect_coding_type (&decst, random_buffer, nread, 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1531 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1532 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1533
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1534 if (decst.mask == ~0)
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
1535 val = subsidiary_coding_system (Fget_coding_system (Qundecided),
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
1536 decst.eol_type);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1537 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1538 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1539 int i;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1540
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1541 val = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1542
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1543 decst.mask = postprocess_iso2022_mask (decst.mask);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1544
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1545 for (i = CODING_CATEGORY_LAST; i >= 0; i--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1546 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1547 int sys = coding_category_by_priority[i];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1548 if (decst.mask & (1 << sys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1549 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1550 Lisp_Object codesys = coding_category_system[sys];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1551 if (!NILP (codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1552 codesys = subsidiary_coding_system (codesys, decst.eol_type);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1553 val = Fcons (codesys, val);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1554 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1555 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1556 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1557 Lstream_close (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1558 UNGCPRO;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1559 Lstream_delete (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1560 Lstream_delete (lb_istr);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1561 return val;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1562 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1563
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1564
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1565 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1566 /* Converting to internal Mule format ("decoding") */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1567 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1568
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1569 /* A decoding stream is a stream used for decoding text (i.e.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1570 converting from some external format to internal format).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1571 The decoding-stream object keeps track of the actual coding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1572 stream, the stream that is at the other end, and data that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1573 needs to be persistent across the lifetime of the stream. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1574
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1575 /* Handle the EOL stuff related to just-read-in character C.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1576 EOL_TYPE is the EOL type of the coding stream.
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1577 FLAGS is the current value of FLAGS in the coding stream, and may
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1578 be modified by this macro. (The macro only looks at the
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1579 CODING_STATE_CR flag.) DST is the Dynarr to which the decoded
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1580 bytes are to be written. You need to also define a local goto
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1581 label "label_continue_loop" that is at the end of the main
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1582 character-reading loop.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1583
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1584 If C is a CR character, then this macro handles it entirely and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1585 jumps to label_continue_loop. Otherwise, this macro does not add
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1586 anything to DST, and continues normally. You should continue
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1587 processing C normally after this macro. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1588
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1589 #define DECODE_HANDLE_EOL_TYPE(eol_type, c, flags, dst) \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1590 do { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1591 if (c == '\r') \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1592 { \
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1593 if (eol_type == EOL_CR) \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1594 Dynarr_add (dst, '\n'); \
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1595 else if (eol_type != EOL_CRLF || flags & CODING_STATE_CR) \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1596 Dynarr_add (dst, c); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1597 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1598 flags |= CODING_STATE_CR; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1599 goto label_continue_loop; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1600 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1601 else if (flags & CODING_STATE_CR) \
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1602 { /* eol_type == CODING_SYSTEM_EOL_CRLF */ \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1603 if (c != '\n') \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1604 Dynarr_add (dst, '\r'); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1605 flags &= ~CODING_STATE_CR; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1606 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1607 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1608
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1609 /* C should be a binary character in the range 0 - 255; convert
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1610 to internal format and add to Dynarr DST. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1611
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1612 #define DECODE_ADD_BINARY_CHAR(c, dst) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1613 do { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1614 if (BYTE_ASCII_P (c)) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1615 Dynarr_add (dst, c); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1616 else if (BYTE_C1_P (c)) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1617 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1618 Dynarr_add (dst, LEADING_BYTE_CONTROL_1); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1619 Dynarr_add (dst, c + 0x20); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1620 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1621 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1622 { \
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1623 Dynarr_add (dst, LEADING_BYTE_LATIN_ISO8859_1); \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1624 Dynarr_add (dst, c); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1625 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1626 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1627
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1628 #define DECODE_OUTPUT_PARTIAL_CHAR(ch) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1629 do { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1630 if (ch) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1631 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1632 DECODE_ADD_BINARY_CHAR (ch, dst); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1633 ch = 0; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1634 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1635 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1636
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1637 #define DECODE_HANDLE_END_OF_CONVERSION(flags, ch, dst) \
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1638 do { \
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1639 DECODE_OUTPUT_PARTIAL_CHAR (ch); \
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1640 if ((flags & CODING_STATE_END) && \
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1641 (flags & CODING_STATE_CR)) \
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1642 Dynarr_add (dst, '\r'); \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1643 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1644
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1645 #define DECODING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, decoding)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1646
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1647 struct decoding_stream
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1648 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1649 /* Coding system that governs the conversion. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1650 struct Lisp_Coding_System *codesys;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1651
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1652 /* Stream that we read the encoded data from or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1653 write the decoded data to. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1654 Lstream *other_end;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1655
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1656 /* If we are reading, then we can return only a fixed amount of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1657 data, so if the conversion resulted in too much data, we store it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1658 here for retrieval the next time around. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1659 unsigned_char_dynarr *runoff;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1660
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1661 /* FLAGS holds flags indicating the current state of the decoding.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1662 Some of these flags are dependent on the coding system. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1663 unsigned int flags;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1664
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1665 /* CH holds a partially built-up character. Since we only deal
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1666 with one- and two-byte characters at the moment, we only use
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1667 this to store the first byte of a two-byte character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1668 unsigned int ch;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1669
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1670 /* EOL_TYPE specifies the type of end-of-line conversion that
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1671 currently applies. We need to keep this separate from the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1672 EOL type stored in CODESYS because the latter might indicate
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1673 automatic EOL-type detection while the former will always
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1674 indicate a particular EOL type. */
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
1675 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1676
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1677 /* Additional ISO2022 information. We define the structure above
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1678 because it's also needed by the detection routines. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1679 struct iso2022_decoder iso2022;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1680
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1681 /* Additional information (the state of the running CCL program)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1682 used by the CCL decoder. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1683 struct ccl_program ccl;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1684
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1685 struct detection_state decst;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1686 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1687
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1688 static int decoding_reader (Lstream *stream, unsigned char *data, int size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1689 static int decoding_writer (Lstream *stream, CONST unsigned char *data, int size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1690 static int decoding_rewinder (Lstream *stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1691 static int decoding_seekable_p (Lstream *stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1692 static int decoding_flusher (Lstream *stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1693 static int decoding_closer (Lstream *stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1694 static Lisp_Object decoding_marker (Lisp_Object stream,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1695 void (*markobj) (Lisp_Object));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1696
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1697 DEFINE_LSTREAM_IMPLEMENTATION ("decoding", lstream_decoding,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1698 sizeof (struct decoding_stream));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1699
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1700 static Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1701 decoding_marker (Lisp_Object stream, void (*markobj) (Lisp_Object))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1702 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1703 Lstream *str = DECODING_STREAM_DATA (XLSTREAM (stream))->other_end;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1704 Lisp_Object str_obj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1705
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1706 /* We do not need to mark the coding systems or charsets stored
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1707 within the stream because they are stored in a global list
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1708 and automatically marked. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1709
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1710 XSETLSTREAM (str_obj, str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1711 (markobj) (str_obj);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1712 if (str->imp->marker)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1713 return (str->imp->marker) (str_obj, markobj);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1714 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1715 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1716 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1717
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1718 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1719 so we read data from the other end, decode it, and store it into DATA. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1720
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1721 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1722 decoding_reader (Lstream *stream, unsigned char *data, int size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1723 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1724 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1725 unsigned char *orig_data = data;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1726 int read_size;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1727 int error_occurred = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1728
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1729 /* We need to interface to mule_decode(), which expects to take some
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1730 amount of data and store the result into a Dynarr. We have
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1731 mule_decode() store into str->runoff, and take data from there
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1732 as necessary. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1733
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1734 /* We loop until we have enough data, reading chunks from the other
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1735 end and decoding it. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1736 while (1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1737 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1738 /* Take data from the runoff if we can. Make sure to take at
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1739 most SIZE bytes, and delete the data from the runoff. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1740 if (Dynarr_length (str->runoff) > 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1741 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1742 int chunk = min (size, Dynarr_length (str->runoff));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1743 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1744 Dynarr_delete_many (str->runoff, 0, chunk);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1745 data += chunk;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1746 size -= chunk;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1747 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1748
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1749 if (size == 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1750 break; /* No more room for data */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1751
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1752 if (str->flags & CODING_STATE_END)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1753 /* This means that on the previous iteration, we hit the EOF on
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1754 the other end. We loop once more so that mule_decode() can
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1755 output any final stuff it may be holding, or any "go back
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1756 to a sane state" escape sequences. (This latter makes sense
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1757 during encoding.) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1758 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1759
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1760 /* Exhausted the runoff, so get some more. DATA has at least
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1761 SIZE bytes left of storage in it, so it's OK to read directly
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1762 into it. (We'll be overwriting above, after we've decoded it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1763 into the runoff.) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1764 read_size = Lstream_read (str->other_end, data, size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1765 if (read_size < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1766 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1767 error_occurred = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1768 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1769 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1770 if (read_size == 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1771 /* There might be some more end data produced in the translation.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1772 See the comment above. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1773 str->flags |= CODING_STATE_END;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1774 mule_decode (stream, data, str->runoff, read_size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1775 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1776
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1777 if (data - orig_data == 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1778 return error_occurred ? -1 : 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1779 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1780 return data - orig_data;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1781 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1782
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1783 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1784 decoding_writer (Lstream *stream, CONST unsigned char *data, int size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1785 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1786 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1787 int retval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1788
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1789 /* Decode all our data into the runoff, and then attempt to write
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1790 it all out to the other end. Remove whatever chunk we succeeded
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1791 in writing. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1792 mule_decode (stream, data, str->runoff, size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1793 retval = Lstream_write (str->other_end, Dynarr_atp (str->runoff, 0),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1794 Dynarr_length (str->runoff));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1795 if (retval > 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1796 Dynarr_delete_many (str->runoff, 0, retval);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1797 /* Do NOT return retval. The return value indicates how much
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1798 of the incoming data was written, not how many bytes were
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1799 written. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1800 return size;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1801 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1802
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1803 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1804 reset_decoding_stream (struct decoding_stream *str)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1805 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1806 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_ISO2022)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1807 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1808 Lisp_Object coding_system = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1809 XSETCODING_SYSTEM (coding_system, str->codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1810 reset_iso2022 (coding_system, &str->iso2022);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1811 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1812 else if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_CCL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1813 {
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
1814 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_DECODE (str->codesys));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1815 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1816
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1817 str->flags = str->ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1818 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1819
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1820 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1821 decoding_rewinder (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1822 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1823 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1824 reset_decoding_stream (str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1825 Dynarr_reset (str->runoff);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1826 return Lstream_rewind (str->other_end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1827 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1828
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1829 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1830 decoding_seekable_p (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1831 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1832 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1833 return Lstream_seekable_p (str->other_end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1834 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1835
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1836 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1837 decoding_flusher (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1838 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1839 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1840 return Lstream_flush (str->other_end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1841 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1842
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1843 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1844 decoding_closer (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1845 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1846 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1847 if (stream->flags & LSTREAM_FL_WRITE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1848 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1849 str->flags |= CODING_STATE_END;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1850 decoding_writer (stream, 0, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1851 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1852 Dynarr_free (str->runoff);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1853 if (str->iso2022.composite_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1854 Dynarr_free (str->iso2022.composite_chars);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1855 return Lstream_close (str->other_end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1856 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1857
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1858 Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1859 decoding_stream_coding_system (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1860 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1861 Lisp_Object coding_system = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1862 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1863
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1864 XSETCODING_SYSTEM (coding_system, str->codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1865 return subsidiary_coding_system (coding_system, str->eol_type);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1866 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1867
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1868 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1869 set_decoding_stream_coding_system (Lstream *lstr, Lisp_Object codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1870 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1871 struct Lisp_Coding_System *cs = XCODING_SYSTEM (codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1872 struct decoding_stream *str = DECODING_STREAM_DATA (lstr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1873 str->codesys = cs;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1874 if (CODING_SYSTEM_EOL_TYPE (cs) != EOL_AUTODETECT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1875 str->eol_type = CODING_SYSTEM_EOL_TYPE (cs);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1876 reset_decoding_stream (str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1877 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1878
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1879 /* WARNING WARNING WARNING WARNING!!!!! If you open up a decoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1880 stream for writing, no automatic code detection will be performed.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1881 The reason for this is that automatic code detection requires a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1882 seekable input. Things will also fail if you open a decoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1883 stream for reading using a non-fully-specified coding system and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1884 a non-seekable input stream. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1885
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1886 static Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1887 make_decoding_stream_1 (Lstream *stream, Lisp_Object codesys,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1888 CONST char *mode)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1889 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1890 Lstream *lstr = Lstream_new (lstream_decoding, mode);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1891 struct decoding_stream *str = DECODING_STREAM_DATA (lstr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1892 Lisp_Object obj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1893
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1894 memset (str, 0, sizeof (*str));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1895 str->other_end = stream;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
1896 str->runoff = (unsigned_char_dynarr *) Dynarr_new (unsigned_char);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1897 str->eol_type = EOL_AUTODETECT;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1898 if (!strcmp (mode, "r")
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1899 && Lstream_seekable_p (stream))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1900 /* We can determine the coding system now. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1901 determine_real_coding_system (stream, &codesys, &str->eol_type);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1902 set_decoding_stream_coding_system (lstr, codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1903 str->decst.eol_type = str->eol_type;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1904 str->decst.mask = ~0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1905 XSETLSTREAM (obj, lstr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1906 return obj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1907 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1908
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1909 Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1910 make_decoding_input_stream (Lstream *stream, Lisp_Object codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1911 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1912 return make_decoding_stream_1 (stream, codesys, "r");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1913 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1914
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1915 Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1916 make_decoding_output_stream (Lstream *stream, Lisp_Object codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1917 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1918 return make_decoding_stream_1 (stream, codesys, "w");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1919 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1920
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
1921 /* Note: the decode_coding_* functions all take the same
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1922 arguments as mule_decode(), which is to say some SRC data of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1923 size N, which is to be stored into dynamic array DST.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1924 DECODING is the stream within which the decoding is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1925 taking place, but no data is actually read from or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1926 written to that stream; that is handled in decoding_reader()
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1927 or decoding_writer(). This allows the same functions to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1928 be used for both reading and writing. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1929
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1930 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1931 mule_decode (Lstream *decoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1932 unsigned_char_dynarr *dst, unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1933 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1934 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1935
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1936 /* If necessary, do encoding-detection now. We do this when
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1937 we're a writing stream or a non-seekable reading stream,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1938 meaning that we can't just process the whole input,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1939 rewind, and start over. */
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1940
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1941 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1942 str->eol_type == EOL_AUTODETECT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1943 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1944 Lisp_Object codesys = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1945
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1946 XSETCODING_SYSTEM (codesys, str->codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1947 detect_coding_type (&str->decst, src, n,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1948 CODING_SYSTEM_TYPE (str->codesys) !=
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1949 CODESYS_AUTODETECT);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1950 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1951 str->decst.mask != ~0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1952 /* #### This is cheesy. What we really ought to do is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1953 buffer up a certain amount of data so as to get a
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1954 less random result. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1955 codesys = coding_system_from_mask (str->decst.mask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1956 str->eol_type = str->decst.eol_type;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1957 if (XCODING_SYSTEM (codesys) != str->codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1958 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1959 /* Preserve the CODING_STATE_END flag in case it was set.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1960 If we erase it, bad things might happen. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1961 int was_end = str->flags & CODING_STATE_END;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1962 set_decoding_stream_coding_system (decoding, codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1963 if (was_end)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1964 str->flags |= CODING_STATE_END;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1965 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1966 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
1967
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1968 switch (CODING_SYSTEM_TYPE (str->codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1969 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1970 #ifdef DEBUG_XEMACS
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1971 case CODESYS_INTERNAL:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1972 Dynarr_add_many (dst, src, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1973 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1974 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1975 case CODESYS_AUTODETECT:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1976 /* If we got this far and still haven't decided on the coding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1977 system, then do no conversion. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1978 case CODESYS_NO_CONVERSION:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1979 decode_coding_no_conversion (decoding, src, dst, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1980 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1981 case CODESYS_SHIFT_JIS:
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
1982 decode_coding_sjis (decoding, src, dst, n);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1983 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1984 case CODESYS_BIG5:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1985 decode_coding_big5 (decoding, src, dst, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1986 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1987 case CODESYS_CCL:
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
1988 ccl_driver (&str->ccl, src, dst, n, 0);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1989 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1990 case CODESYS_ISO2022:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1991 decode_coding_iso2022 (decoding, src, dst, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1992 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1993 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1994 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1995 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1996 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1997
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1998 DEFUN ("decode-coding-region", Fdecode_coding_region, 3, 4, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
1999 Decode the text between START and END which is encoded in CODING-SYSTEM.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2000 This is useful if you've read in encoded text from a file without decoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2001 it (e.g. you read in a JIS-formatted file but used the `binary' or
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2002 `no-conversion' coding system, so that it shows up as "^[$B!<!+^[(B").
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2003 Return length of decoded text.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2004 BUFFER defaults to the current buffer if unspecified.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2005 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2006 (start, end, coding_system, buffer))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2007 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2008 Bufpos b, e;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2009 struct buffer *buf = decode_buffer (buffer, 0);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2010 Lisp_Object instream, lb_outstream, de_outstream, outstream;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2011 Lstream *istr, *ostr;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2012 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2013
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2014 get_buffer_range_char (buf, start, end, &b, &e, 0);
96
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 74
diff changeset
2015
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 74
diff changeset
2016 barf_if_buffer_read_only (buf, b, e);
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 74
diff changeset
2017
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2018 coding_system = Fget_coding_system (coding_system);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2019 instream = make_lisp_buffer_input_stream (buf, b, e, 0);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2020 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2021 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream),
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2022 coding_system);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2023 outstream = make_encoding_output_stream (XLSTREAM (de_outstream),
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2024 Fget_coding_system (Qbinary));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2025 istr = XLSTREAM (instream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2026 ostr = XLSTREAM (outstream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2027 GCPRO4 (instream, lb_outstream, de_outstream, outstream);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2028
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2029 /* The chain of streams looks like this:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2030
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2031 [BUFFER] <----- send through
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2032 ------> [ENCODE AS BINARY]
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2033 ------> [DECODE AS SPECIFIED]
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2034 ------> [BUFFER]
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2035 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2036
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2037 while (1)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2038 {
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2039 char tempbuf[1024]; /* some random amount */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2040 Bufpos newpos, even_newer_pos;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2041 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2042 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2043
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2044 if (!size_in_bytes)
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2045 break;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2046 newpos = lisp_buffer_stream_startpos (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2047 Lstream_write (ostr, tempbuf, size_in_bytes);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2048 even_newer_pos = lisp_buffer_stream_startpos (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2049 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos),
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2050 even_newer_pos, 0);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2051 }
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2052 Lstream_close (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2053 Lstream_close (ostr);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2054 UNGCPRO;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2055 Lstream_delete (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2056 Lstream_delete (ostr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2057 Lstream_delete (XLSTREAM (de_outstream));
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2058 Lstream_delete (XLSTREAM (lb_outstream));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2059 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2060 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2061
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2062
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2063 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2064 /* Converting to an external encoding ("encoding") */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2065 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2066
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2067 /* An encoding stream is an output stream. When you create the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2068 stream, you specify the coding system that governs the encoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2069 and another stream that the resulting encoded data is to be
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2070 sent to, and then start sending data to it. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2071
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2072 #define ENCODING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, encoding)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2073
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2074 struct encoding_stream
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2075 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2076 /* Coding system that governs the conversion. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2077 struct Lisp_Coding_System *codesys;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2078
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2079 /* Stream that we read the encoded data from or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2080 write the decoded data to. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2081 Lstream *other_end;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2082
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2083 /* If we are reading, then we can return only a fixed amount of
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2084 data, so if the conversion resulted in too much data, we store it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2085 here for retrieval the next time around. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2086 unsigned_char_dynarr *runoff;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2087
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2088 /* FLAGS holds flags indicating the current state of the encoding.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2089 Some of these flags are dependent on the coding system. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2090 unsigned int flags;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2091
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2092 /* CH holds a partially built-up character. Since we only deal
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2093 with one- and two-byte characters at the moment, we only use
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2094 this to store the first byte of a two-byte character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2095 unsigned int ch;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2096
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2097 /* Additional information used by the ISO2022 encoder. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2098 struct
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2099 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2100 /* CHARSET holds the character sets currently assigned to the G0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2101 through G3 registers. It is initialized from the array
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2102 INITIAL_CHARSET in CODESYS. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2103 Lisp_Object charset[4];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2104
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2105 /* Which registers are currently invoked into the left (GL) and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2106 right (GR) halves of the 8-bit encoding space? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2107 int register_left, register_right;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2108
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2109 /* Whether we need to explicitly designate the charset in the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2110 G? register before using it. It is initialized from the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2111 array FORCE_CHARSET_ON_OUTPUT in CODESYS. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2112 unsigned char force_charset_on_output[4];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2113
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2114 /* Other state variables that need to be preserved across
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2115 invocations. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2116 Lisp_Object current_charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2117 int current_half;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2118 int current_char_boundary;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2119 } iso2022;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2120
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2121 /* Additional information (the state of the running CCL program)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2122 used by the CCL encoder. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2123 struct ccl_program ccl;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2124 };
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2125
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2126 static int encoding_reader (Lstream *stream, unsigned char *data, int size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2127 static int encoding_writer (Lstream *stream, CONST unsigned char *data,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2128 int size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2129 static int encoding_rewinder (Lstream *stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2130 static int encoding_seekable_p (Lstream *stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2131 static int encoding_flusher (Lstream *stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2132 static int encoding_closer (Lstream *stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2133 static Lisp_Object encoding_marker (Lisp_Object stream,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2134 void (*markobj) (Lisp_Object));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2135
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2136 DEFINE_LSTREAM_IMPLEMENTATION ("encoding", lstream_encoding,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2137 sizeof (struct encoding_stream));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2138
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2139 static Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2140 encoding_marker (Lisp_Object stream, void (*markobj) (Lisp_Object))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2141 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2142 Lstream *str = ENCODING_STREAM_DATA (XLSTREAM (stream))->other_end;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2143 Lisp_Object str_obj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2144
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2145 /* We do not need to mark the coding systems or charsets stored
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2146 within the stream because they are stored in a global list
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2147 and automatically marked. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2148
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2149 XSETLSTREAM (str_obj, str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2150 (markobj) (str_obj);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2151 if (str->imp->marker)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2152 return (str->imp->marker) (str_obj, markobj);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2153 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2154 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2155 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2156
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2157 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2158 so we read data from the other end, encode it, and store it into DATA. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2159
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2160 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2161 encoding_reader (Lstream *stream, unsigned char *data, int size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2162 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2163 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2164 unsigned char *orig_data = data;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2165 int read_size;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2166 int error_occurred = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2167
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2168 /* We need to interface to mule_encode(), which expects to take some
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2169 amount of data and store the result into a Dynarr. We have
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2170 mule_encode() store into str->runoff, and take data from there
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2171 as necessary. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2172
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2173 /* We loop until we have enough data, reading chunks from the other
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2174 end and encoding it. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2175 while (1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2176 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2177 /* Take data from the runoff if we can. Make sure to take at
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2178 most SIZE bytes, and delete the data from the runoff. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2179 if (Dynarr_length (str->runoff) > 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2180 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2181 int chunk = min (size, Dynarr_length (str->runoff));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2182 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2183 Dynarr_delete_many (str->runoff, 0, chunk);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2184 data += chunk;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2185 size -= chunk;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2186 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2187
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2188 if (size == 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2189 break; /* No more room for data */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2190
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2191 if (str->flags & CODING_STATE_END)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2192 /* This means that on the previous iteration, we hit the EOF on
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2193 the other end. We loop once more so that mule_encode() can
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2194 output any final stuff it may be holding, or any "go back
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2195 to a sane state" escape sequences. (This latter makes sense
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2196 during encoding.) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2197 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2198
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2199 /* Exhausted the runoff, so get some more. DATA at least SIZE bytes
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2200 left of storage in it, so it's OK to read directly into it.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2201 (We'll be overwriting above, after we've encoded it into the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2202 runoff.) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2203 read_size = Lstream_read (str->other_end, data, size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2204 if (read_size < 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2205 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2206 error_occurred = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2207 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2208 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2209 if (read_size == 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2210 /* There might be some more end data produced in the translation.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2211 See the comment above. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2212 str->flags |= CODING_STATE_END;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2213 mule_encode (stream, data, str->runoff, read_size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2214 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2215
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2216 if (data == orig_data)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2217 return error_occurred ? -1 : 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2218 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2219 return data - orig_data;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2220 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2221
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2222 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2223 encoding_writer (Lstream *stream, CONST unsigned char *data, int size)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2224 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2225 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2226 int retval;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2227
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2228 /* Encode all our data into the runoff, and then attempt to write
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2229 it all out to the other end. Remove whatever chunk we succeeded
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2230 in writing. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2231 mule_encode (stream, data, str->runoff, size);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2232 retval = Lstream_write (str->other_end, Dynarr_atp (str->runoff, 0),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2233 Dynarr_length (str->runoff));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2234 if (retval > 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2235 Dynarr_delete_many (str->runoff, 0, retval);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2236 /* Do NOT return retval. The return value indicates how much
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2237 of the incoming data was written, not how many bytes were
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2238 written. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2239 return size;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2240 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2241
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2242 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2243 reset_encoding_stream (struct encoding_stream *str)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2244 {
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2245 switch (CODING_SYSTEM_TYPE (str->codesys))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2246 {
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2247 case CODESYS_ISO2022:
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2248 {
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2249 int i;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2250
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2251 for (i = 0; i < 4; i++)
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2252 {
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2253 str->iso2022.charset[i] =
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2254 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (str->codesys, i);
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2255 str->iso2022.force_charset_on_output[i] =
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2256 CODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT (str->codesys, i);
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2257 }
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2258 str->iso2022.register_left = 0;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2259 str->iso2022.register_right = 1;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2260 str->iso2022.current_charset = Qnil;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2261 str->iso2022.current_half = 0;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2262 str->iso2022.current_char_boundary = 1;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2263 break;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2264 }
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2265 case CODESYS_CCL:
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
2266 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_ENCODE (str->codesys));
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2267 break;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2268 default:
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2269 break;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2270 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2271
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2272 str->flags = str->ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2273 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2274
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2275 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2276 encoding_rewinder (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2277 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2278 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2279 reset_encoding_stream (str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2280 Dynarr_reset (str->runoff);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2281 return Lstream_rewind (str->other_end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2282 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2283
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2284 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2285 encoding_seekable_p (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2286 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2287 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2288 return Lstream_seekable_p (str->other_end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2289 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2290
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2291 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2292 encoding_flusher (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2293 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2294 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2295 return Lstream_flush (str->other_end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2296 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2297
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2298 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2299 encoding_closer (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2300 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2301 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2302 if (stream->flags & LSTREAM_FL_WRITE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2303 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2304 str->flags |= CODING_STATE_END;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2305 encoding_writer (stream, 0, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2306 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2307 Dynarr_free (str->runoff);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2308 return Lstream_close (str->other_end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2309 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2310
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2311 Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2312 encoding_stream_coding_system (Lstream *stream)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2313 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2314 Lisp_Object coding_system = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2315 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2316
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2317 XSETCODING_SYSTEM (coding_system, str->codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2318 return coding_system;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2319 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2320
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2321 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2322 set_encoding_stream_coding_system (Lstream *lstr, Lisp_Object codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2323 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2324 struct Lisp_Coding_System *cs = XCODING_SYSTEM (codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2325 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2326 str->codesys = cs;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2327 reset_encoding_stream (str);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2328 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2329
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2330 static Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2331 make_encoding_stream_1 (Lstream *stream, Lisp_Object codesys,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2332 CONST char *mode)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2333 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2334 Lstream *lstr = Lstream_new (lstream_encoding, mode);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2335 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2336 Lisp_Object obj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2337
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2338 memset (str, 0, sizeof (*str));
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2339 str->runoff = Dynarr_new (unsigned_char);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2340 str->other_end = stream;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2341 set_encoding_stream_coding_system (lstr, codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2342 XSETLSTREAM (obj, lstr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2343 return obj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2344 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2345
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2346 Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2347 make_encoding_input_stream (Lstream *stream, Lisp_Object codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2348 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2349 return make_encoding_stream_1 (stream, codesys, "r");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2350 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2351
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2352 Lisp_Object
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2353 make_encoding_output_stream (Lstream *stream, Lisp_Object codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2354 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2355 return make_encoding_stream_1 (stream, codesys, "w");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2356 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2357
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2358 /* Convert N bytes of internally-formatted data stored in SRC to an
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2359 external format, according to the encoding stream ENCODING.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2360 Store the encoded data into DST. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2361
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2362 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2363 mule_encode (Lstream *encoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2364 unsigned_char_dynarr *dst, unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2365 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2366 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2367
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2368 switch (CODING_SYSTEM_TYPE (str->codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2369 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2370 #ifdef DEBUG_XEMACS
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2371 case CODESYS_INTERNAL:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2372 Dynarr_add_many (dst, src, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2373 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2374 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2375 case CODESYS_AUTODETECT:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2376 /* If we got this far and still haven't decided on the coding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2377 system, then do no conversion. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2378 case CODESYS_NO_CONVERSION:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2379 encode_coding_no_conversion (encoding, src, dst, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2380 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2381 case CODESYS_SHIFT_JIS:
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2382 encode_coding_sjis (encoding, src, dst, n);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2383 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2384 case CODESYS_BIG5:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2385 encode_coding_big5 (encoding, src, dst, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2386 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2387 case CODESYS_CCL:
213
78f53ef88e17 Import from CVS: tag r20-4b5
cvs
parents: 209
diff changeset
2388 ccl_driver (&str->ccl, src, dst, n, 0);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2389 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2390 case CODESYS_ISO2022:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2391 encode_coding_iso2022 (encoding, src, dst, n);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2392 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2393 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2394 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2395 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2396 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2397
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2398 DEFUN ("encode-coding-region", Fencode_coding_region, 3, 4, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2399 Encode the text between START and END using CODING-SYSTEM.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2400 This will, for example, convert Japanese characters into stuff such as
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2401 "^[$B!<!+^[(B" if you use the JIS encoding. Return length of encoded
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2402 text. BUFFER defaults to the current buffer if unspecified.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2403 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2404 (start, end, coding_system, buffer))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2405 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2406 Bufpos b, e;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2407 struct buffer *buf = decode_buffer (buffer, 0);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2408 Lisp_Object instream, lb_outstream, de_outstream, outstream;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2409 Lstream *istr, *ostr;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2410 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2411
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2412 get_buffer_range_char (buf, start, end, &b, &e, 0);
96
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 74
diff changeset
2413
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 74
diff changeset
2414 barf_if_buffer_read_only (buf, b, e);
dbb370e3c29e Import from CVS: tag r20-0final
cvs
parents: 74
diff changeset
2415
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2416 coding_system = Fget_coding_system (coding_system);
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2417 instream = make_lisp_buffer_input_stream (buf, b, e, 0);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2418 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2419 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream),
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2420 Fget_coding_system (Qbinary));
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2421 outstream = make_encoding_output_stream (XLSTREAM (de_outstream),
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2422 coding_system);
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2423 istr = XLSTREAM (instream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2424 ostr = XLSTREAM (outstream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2425 GCPRO4 (instream, outstream, de_outstream, lb_outstream);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2426 /* The chain of streams looks like this:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2427
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2428 [BUFFER] <----- send through
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2429 ------> [ENCODE AS SPECIFIED]
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2430 ------> [DECODE AS BINARY]
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2431 ------> [BUFFER]
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2432 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2433 while (1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2434 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2435 char tempbuf[1024]; /* some random amount */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2436 Bufpos newpos, even_newer_pos;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2437 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2438 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2439
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2440 if (!size_in_bytes)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2441 break;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2442 newpos = lisp_buffer_stream_startpos (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2443 Lstream_write (ostr, tempbuf, size_in_bytes);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2444 even_newer_pos = lisp_buffer_stream_startpos (istr);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2445 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2446 even_newer_pos, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2447 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2448
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2449 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2450 Charcount retlen =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2451 lisp_buffer_stream_startpos (XLSTREAM (instream)) - b;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2452 Lstream_close (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2453 Lstream_close (ostr);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2454 UNGCPRO;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2455 Lstream_delete (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2456 Lstream_delete (ostr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2457 Lstream_delete (XLSTREAM (de_outstream));
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
2458 Lstream_delete (XLSTREAM (lb_outstream));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2459 return make_int (retlen);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2460 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2461 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2462
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2463
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2464 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2465 /* Shift-JIS methods */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2466 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2467
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2468 /* Shift-JIS is a coding system encoding three character sets: ASCII, right
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2469 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2470 as is. A character of JISX0201-Kana (TYPE94 character set) is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2471 encoded by "position-code + 0x80". A character of JISX0208
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2472 (TYPE94x94 character set) is encoded in 2-byte but two
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2473 position-codes are divided and shifted so that it fit in the range
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2474 below.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2475
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2476 --- CODE RANGE of Shift-JIS ---
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2477 (character set) (range)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2478 ASCII 0x00 .. 0x7F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2479 JISX0201-Kana 0xA0 .. 0xDF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2480 JISX0208 (1st byte) 0x80 .. 0x9F and 0xE0 .. 0xEF
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2481 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2482 -------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2483
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2484 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2485
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2486 /* Is this the first byte of a Shift-JIS two-byte char? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2487
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2488 #define BYTE_SJIS_TWO_BYTE_1_P(c) \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2489 (((c) >= 0x81 && (c) <= 0x9F) || ((c) >= 0xE0 && (c) <= 0xEF))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2490
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2491 /* Is this the second byte of a Shift-JIS two-byte char? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2492
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2493 #define BYTE_SJIS_TWO_BYTE_2_P(c) \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2494 (((c) >= 0x40 && (c) <= 0x7E) || ((c) >= 0x80 && (c) <= 0xFC))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2495
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2496 #define BYTE_SJIS_KATAKANA_P(c) \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2497 ((c) >= 0xA1 && (c) <= 0xDF)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2498
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2499 static int
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2500 detect_coding_sjis (struct detection_state *st, CONST unsigned char *src,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2501 unsigned int n)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2502 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2503 int c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2504
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2505 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2506 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2507 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2508 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2509 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2510 if (st->shift_jis.in_second_byte)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2511 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2512 st->shift_jis.in_second_byte = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2513 if (c < 0x40)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2514 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2515 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2516 else if ((c >= 0x80 && c < 0xA0) || c >= 0xE0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2517 st->shift_jis.in_second_byte = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2518 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2519 return CODING_CATEGORY_SHIFT_JIS_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2520 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2521
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2522 /* Convert Shift-JIS data to internal format. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2523
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2524 static void
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2525 decode_coding_sjis (Lstream *decoding, CONST unsigned char *src,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2526 unsigned_char_dynarr *dst, unsigned int n)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2527 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2528 unsigned char c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2529 unsigned int flags, ch;
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2530 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2531 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2532
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2533 CODING_STREAM_DECOMPOSE (str, flags, ch);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2534 eol_type = str->eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2535
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2536 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2537 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2538 c = *src++;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2539
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2540 if (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2541 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2542 /* Previous character was first byte of Shift-JIS Kanji char. */
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2543 if (BYTE_SJIS_TWO_BYTE_2_P (c))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2544 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2545 unsigned char e1, e2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2546
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2547 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2548 DECODE_SJIS (ch, c, e1, e2);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2549 Dynarr_add (dst, e1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2550 Dynarr_add (dst, e2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2551 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2552 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2553 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2554 DECODE_ADD_BINARY_CHAR (ch, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2555 DECODE_ADD_BINARY_CHAR (c, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2556 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2557 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2558 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2559 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2560 {
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2561 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2562 if (BYTE_SJIS_TWO_BYTE_1_P (c))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2563 ch = c;
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2564 else if (BYTE_SJIS_KATAKANA_P (c))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2565 {
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2566 Dynarr_add (dst, LEADING_BYTE_KATAKANA_JISX0201);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2567 Dynarr_add (dst, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2568 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2569 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2570 DECODE_ADD_BINARY_CHAR (c, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2571 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2572 label_continue_loop:;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2573 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2574
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2575 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2576
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2577 CODING_STREAM_COMPOSE (str, flags, ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2578 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2579
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2580 /* Convert internally-formatted data to Shift-JIS. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2581
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2582 static void
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2583 encode_coding_sjis (Lstream *encoding, CONST unsigned char *src,
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2584 unsigned_char_dynarr *dst, unsigned int n)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2585 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2586 unsigned char c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2587 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2588 unsigned int flags, ch;
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2589 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2590
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2591 CODING_STREAM_DECOMPOSE (str, flags, ch);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2592 eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2593
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2594 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2595 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2596 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2597 if (c == '\n')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2598 {
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2599 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2600 Dynarr_add (dst, '\r');
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2601 if (eol_type != EOL_CR)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2602 Dynarr_add (dst, '\n');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2603 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2604 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2605 else if (BYTE_ASCII_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2606 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2607 Dynarr_add (dst, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2608 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2609 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2610 else if (BUFBYTE_LEADING_BYTE_P (c))
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2611 ch = (c == LEADING_BYTE_KATAKANA_JISX0201 ||
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2612 c == LEADING_BYTE_JAPANESE_JISX0208_1978 ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2613 c == LEADING_BYTE_JAPANESE_JISX0208) ? c : 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2614 else if (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2615 {
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2616 if (ch == LEADING_BYTE_KATAKANA_JISX0201)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2617 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2618 Dynarr_add (dst, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2619 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2620 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2621 else if (ch == LEADING_BYTE_JAPANESE_JISX0208_1978 ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2622 ch == LEADING_BYTE_JAPANESE_JISX0208)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2623 ch = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2624 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2625 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2626 unsigned char j1, j2;
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2627 ENCODE_SJIS (ch, c, j1, j2);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2628 Dynarr_add (dst, j1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2629 Dynarr_add (dst, j2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2630 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2631 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2632 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2633 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2634
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2635 CODING_STREAM_COMPOSE (str, flags, ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2636 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2637
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2638 DEFUN ("decode-shift-jis-char", Fdecode_shift_jis_char, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2639 Decode a JISX0208 character of Shift-JIS coding-system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2640 CODE is the character code in Shift-JIS as a cons of type bytes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2641 Return the corresponding character.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2642 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2643 (code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2644 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2645 unsigned char c1, c2, s1, s2;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2646
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2647 CHECK_CONS (code);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2648 CHECK_INT (XCAR (code));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2649 CHECK_INT (XCDR (code));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2650 s1 = XINT (XCAR (code));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2651 s2 = XINT (XCDR (code));
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2652 if (BYTE_SJIS_TWO_BYTE_1_P (s1) &&
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2653 BYTE_SJIS_TWO_BYTE_2_P (s2))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2654 {
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2655 DECODE_SJIS (s1, s2, c1, c2);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2656 return make_char (MAKE_CHAR (Vcharset_japanese_jisx0208,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2657 c1 & 0x7F, c2 & 0x7F));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2658 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2659 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2660 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2661 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2662
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2663 DEFUN ("encode-shift-jis-char", Fencode_shift_jis_char, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2664 Encode a JISX0208 character CHAR to SHIFT-JIS coding-system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2665 Return the corresponding character code in SHIFT-JIS as a cons of two bytes.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2666 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2667 (ch))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2668 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2669 Lisp_Object charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2670 int c1, c2, s1, s2;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2671
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2672 CHECK_CHAR_COERCE_INT (ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2673 BREAKUP_CHAR (XCHAR (ch), charset, c1, c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2674 if (EQ (charset, Vcharset_japanese_jisx0208))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2675 {
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
2676 ENCODE_SJIS (c1 | 0x80, c2 | 0x80, s1, s2);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2677 return Fcons (make_int (s1), make_int (s2));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2678 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2679 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2680 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2681 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2682
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2683
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2684 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2685 /* Big5 methods */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2686 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2687
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2688 /* BIG5 is a coding system encoding two character sets: ASCII and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2689 Big5. An ASCII character is encoded as is. Big5 is a two-byte
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2690 character set and is encoded in two-byte.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2691
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2692 --- CODE RANGE of BIG5 ---
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2693 (character set) (range)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2694 ASCII 0x00 .. 0x7F
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2695 Big5 (1st byte) 0xA1 .. 0xFE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2696 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2697 --------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2698
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2699 Since the number of characters in Big5 is larger than maximum
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2700 characters in Emacs' charset (96x96), it can't be handled as one
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2701 charset. So, in Emacs, Big5 is devided into two: `charset-big5-1'
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2702 and `charset-big5-2'. Both <type>s are TYPE94x94. The former
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2703 contains frequently used characters and the latter contains less
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2704 frequently used characters. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2705
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2706 #define BYTE_BIG5_TWO_BYTE_1_P(c) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2707 ((c) >= 0xA1 && (c) <= 0xFE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2708
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2709 /* Is this the second byte of a Shift-JIS two-byte char? */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2710
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2711 #define BYTE_BIG5_TWO_BYTE_2_P(c) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2712 (((c) >= 0x40 && (c) <= 0x7E) || ((c) >= 0xA1 && (c) <= 0xFE))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2713
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2714 /* Number of Big5 characters which have the same code in 1st byte. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2715
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2716 #define BIG5_SAME_ROW (0xFF - 0xA1 + 0x7F - 0x40)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2717
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2718 /* Code conversion macros. These are macros because they are used in
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2719 inner loops during code conversion.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2720
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2721 Note that temporary variables in macros introduce the classic
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2722 dynamic-scoping problems with variable names. We use capital-
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2723 lettered variables in the assumption that XEmacs does not use
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2724 capital letters in variables except in a very formalized way
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2725 (e.g. Qstring). */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2726
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2727 /* Convert Big5 code (b1, b2) into its internal string representation
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2728 (lb, c1, c2). */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2729
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2730 /* There is a much simpler way to split the Big5 charset into two.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2731 For the moment I'm going to leave the algorithm as-is because it
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2732 claims to separate out the most-used characters into a single
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2733 charset, which perhaps will lead to optimizations in various
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2734 places.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2735
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2736 The way the algorithm works is something like this:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2737
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2738 Big5 can be viewed as a 94x157 charset, where the row is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2739 encoded into the bytes 0xA1 .. 0xFE and the column is encoded
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2740 into the bytes 0x40 .. 0x7E and 0xA1 .. 0xFE. As for frequency,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2741 the split between low and high column numbers is apparently
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2742 meaningless; ascending rows produce less and less frequent chars.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2743 Therefore, we assign the lower half of rows (0xA1 .. 0xC8) to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2744 the first charset, and the upper half (0xC9 .. 0xFE) to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2745 second. To do the conversion, we convert the character into
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2746 a single number where 0 .. 156 is the first row, 157 .. 313
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2747 is the second, etc. That way, the characters are ordered by
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2748 decreasing frequency. Then we just chop the space in two
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2749 and coerce the result into a 94x94 space.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2750 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2751
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2752 #define DECODE_BIG5(b1, b2, lb, c1, c2) do \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2753 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2754 int B1 = b1, B2 = b2; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2755 unsigned int I \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2756 = (B1 - 0xA1) * BIG5_SAME_ROW + B2 - (B2 < 0x7F ? 0x40 : 0x62); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2757 \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2758 if (B1 < 0xC9) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2759 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2760 lb = LEADING_BYTE_CHINESE_BIG5_1; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2761 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2762 else \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2763 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2764 lb = LEADING_BYTE_CHINESE_BIG5_2; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2765 I -= (BIG5_SAME_ROW) * (0xC9 - 0xA1); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2766 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2767 c1 = I / (0xFF - 0xA1) + 0xA1; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2768 c2 = I % (0xFF - 0xA1) + 0xA1; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2769 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2770
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2771 /* Convert the internal string representation of a Big5 character
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2772 (lb, c1, c2) into Big5 code (b1, b2). */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2773
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2774 #define ENCODE_BIG5(lb, c1, c2, b1, b2) do \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2775 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2776 unsigned int I = ((c1) - 0xA1) * (0xFF - 0xA1) + ((c2) - 0xA1); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2777 \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2778 if (lb == LEADING_BYTE_CHINESE_BIG5_2) \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2779 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2780 I += BIG5_SAME_ROW * (0xC9 - 0xA1); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2781 } \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2782 b1 = I / BIG5_SAME_ROW + 0xA1; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2783 b2 = I % BIG5_SAME_ROW; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2784 b2 += b2 < 0x3F ? 0x40 : 0x62; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2785 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2786
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2787 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2788 detect_coding_big5 (struct detection_state *st, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2789 unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2790 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2791 int c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2792
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2793 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2794 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2795 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2796 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2797 (c >= 0x80 && c <= 0xA0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2798 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2799 if (st->big5.in_second_byte)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2800 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2801 st->big5.in_second_byte = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2802 if (c < 0x40 || (c >= 0x80 && c <= 0xA0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2803 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2804 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2805 else if (c >= 0xA1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2806 st->big5.in_second_byte = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2807 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2808 return CODING_CATEGORY_BIG5_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2809 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2810
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2811 /* Convert Big5 data to internal format. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2812
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2813 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2814 decode_coding_big5 (Lstream *decoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2815 unsigned_char_dynarr *dst, unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2816 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2817 unsigned char c;
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2818 unsigned int flags, ch;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2819 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2820 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2821
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2822 CODING_STREAM_DECOMPOSE (str, flags, ch);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2823 eol_type = str->eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2824
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2825 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2826 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2827 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2828 if (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2829 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2830 /* Previous character was first byte of Big5 char. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2831 if (BYTE_BIG5_TWO_BYTE_2_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2832 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2833 unsigned char b1, b2, b3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2834 DECODE_BIG5 (ch, c, b1, b2, b3);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2835 Dynarr_add (dst, b1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2836 Dynarr_add (dst, b2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2837 Dynarr_add (dst, b3);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2838 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2839 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2840 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2841 DECODE_ADD_BINARY_CHAR (ch, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2842 DECODE_ADD_BINARY_CHAR (c, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2843 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2844 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2845 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2846 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2847 {
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2848 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2849 if (BYTE_BIG5_TWO_BYTE_1_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2850 ch = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2851 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2852 DECODE_ADD_BINARY_CHAR (c, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2853 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2854 label_continue_loop:;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2855 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2856
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2857 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2858
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2859 CODING_STREAM_COMPOSE (str, flags, ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2860 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2861
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2862 /* Convert internally-formatted data to Big5. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2863
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2864 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2865 encode_coding_big5 (Lstream *encoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2866 unsigned_char_dynarr *dst, unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2867 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2868 unsigned char c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2869 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2870 unsigned int flags, ch;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2871 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2872
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2873 CODING_STREAM_DECOMPOSE (str, flags, ch);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2874 eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2875
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2876 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2877 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2878 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2879 if (c == '\n')
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2880 {
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2881 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2882 Dynarr_add (dst, '\r');
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
2883 if (eol_type != EOL_CR)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2884 Dynarr_add (dst, '\n');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2885 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2886 else if (BYTE_ASCII_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2887 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2888 /* ASCII. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2889 Dynarr_add (dst, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2890 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2891 else if (BUFBYTE_LEADING_BYTE_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2892 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2893 if (c == LEADING_BYTE_CHINESE_BIG5_1 ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2894 c == LEADING_BYTE_CHINESE_BIG5_2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2895 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2896 /* A recognized leading byte. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2897 ch = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2898 continue; /* not done with this character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2899 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2900 /* otherwise just ignore this character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2901 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2902 else if (ch == LEADING_BYTE_CHINESE_BIG5_1 ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2903 ch == LEADING_BYTE_CHINESE_BIG5_2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2904 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2905 /* Previous char was a recognized leading byte. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2906 ch = (ch << 8) | c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2907 continue; /* not done with this character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2908 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2909 else if (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2910 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2911 /* Encountering second byte of a Big5 character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2912 unsigned char b1, b2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2913
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2914 ENCODE_BIG5 (ch >> 8, ch & 0xFF, c, b1, b2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2915 Dynarr_add (dst, b1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2916 Dynarr_add (dst, b2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2917 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2918
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2919 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2920 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2921
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2922 CODING_STREAM_COMPOSE (str, flags, ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2923 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2924
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2925
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2926 DEFUN ("decode-big5-char", Fdecode_big5_char, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2927 Decode a Big5 character CODE of BIG5 coding-system.
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
2928 CODE is the character code in BIG5, a cons of two integers.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2929 Return the corresponding character.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2930 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2931 (code))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2932 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2933 unsigned char c1, c2, b1, b2;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2934
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2935 CHECK_CONS (code);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2936 CHECK_INT (XCAR (code));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2937 CHECK_INT (XCDR (code));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2938 b1 = XINT (XCAR (code));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2939 b2 = XINT (XCDR (code));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2940 if (BYTE_BIG5_TWO_BYTE_1_P (b1) &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2941 BYTE_BIG5_TWO_BYTE_2_P (b2))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2942 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
2943 int leading_byte;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
2944 Lisp_Object charset;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
2945 DECODE_BIG5 (b1, b2, leading_byte, c1, c2);
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
2946 charset = CHARSET_BY_LEADING_BYTE (leading_byte);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2947 return make_char (MAKE_CHAR (charset, c1 & 0x7F, c2 & 0x7F));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2948 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2949 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2950 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2951 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2952
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2953 DEFUN ("encode-big5-char", Fencode_big5_char, 1, 1, 0, /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2954 Encode the Big5 character CH to BIG5 coding-system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2955 Return the corresponding character code in Big5.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2956 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2957 (ch))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2958 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2959 Lisp_Object charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2960 int c1, c2, b1, b2;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
2961
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2962 CHECK_CHAR_COERCE_INT (ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2963 BREAKUP_CHAR (XCHAR (ch), charset, c1, c2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2964 if (EQ (charset, Vcharset_chinese_big5_1) ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2965 EQ (charset, Vcharset_chinese_big5_2))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2966 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2967 ENCODE_BIG5 (XCHARSET_LEADING_BYTE (charset), c1 | 0x80, c2 | 0x80,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2968 b1, b2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2969 return Fcons (make_int (b1), make_int (b2));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2970 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2971 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2972 return Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2973 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2974
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2975
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2976 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2977 /* ISO2022 methods */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2978 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2979
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2980 /* The following note describes the coding system ISO2022 briefly.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2981 Since the intention of this note is to help understanding of the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2982 programs in this file, some parts are NOT ACCURATE or OVERLY
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2983 SIMPLIFIED. For thorough understanding, please refer to the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2984 original document of ISO2022.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2985
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2986 ISO2022 provides many mechanisms to encode several character sets
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2987 in 7-bit and 8-bit environments. If one chooses 7-bit environment,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2988 all text is encoded by codes of less than 128. This may make the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2989 encoded text a little bit longer, but the text get more stability
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2990 to pass through several gateways (some of them strip off MSB).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2991
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2992 There are two kind of character sets: control character set and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2993 graphic character set. The former contains control characters such
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2994 as `newline' and `escape' to provide control functions (control
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2995 functions are provided also by escape sequence). The latter
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2996 contains graphic characters such as 'A' and '-'. Emacs recognizes
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2997 two control character sets and many graphic character sets.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2998
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
2999 Graphic character sets are classified into one of four types,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3000 according to the dimension and number of characters in the set:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3001 TYPE94, TYPE96, TYPE94x94, and TYPE96x96. In addition, each
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3002 character set is assigned an identification byte, unique for each
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3003 type, called "final character" (denoted as <F> hereafter). The <F>
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3004 of each character set is decided by ECMA(*) when it is registered
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3005 in ISO. Code range of <F> is 0x30..0x7F (0x30..0x3F are for
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3006 private use only).
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3007
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3008 Note (*): ECMA = European Computer Manufacturers Association
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3009
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3010 Here are examples of graphic character set [NAME(<F>)]:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3011 o TYPE94 -- ASCII('B'), right-half-of-JISX0201('I'), ...
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3012 o TYPE96 -- right-half-of-ISO8859-1('A'), ...
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3013 o TYPE94x94 -- GB2312('A'), JISX0208('B'), ...
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3014 o TYPE96x96 -- none for the moment
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3015
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3016 A code area (1byte=8bits) is divided into 4 areas, C0, GL, C1, and GR.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3017 C0 [0x00..0x1F] -- control character plane 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3018 GL [0x20..0x7F] -- graphic character plane 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3019 C1 [0x80..0x9F] -- control character plane 1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3020 GR [0xA0..0xFF] -- graphic character plane 1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3021
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3022 A control character set is directly designated and invoked to C0 or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3023 C1 by an escape sequence. The most common case is that:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3024 - ISO646's control character set is designated/invoked to C0, and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3025 - ISO6429's control character set is designated/invoked to C1,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3026 and usually these designations/invocations are omitted in encoded
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3027 text. In a 7-bit environment, only C0 can be used, and a control
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3028 character for C1 is encoded by an appropriate escape sequence to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3029 fit into the environment. All control characters for C1 are
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3030 defined to have corresponding escape sequences.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3031
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3032 A graphic character set is at first designated to one of four
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3033 graphic registers (G0 through G3), then these graphic registers are
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3034 invoked to GL or GR. These designations and invocations can be
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3035 done independently. The most common case is that G0 is invoked to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3036 GL, G1 is invoked to GR, and ASCII is designated to G0. Usually
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3037 these invocations and designations are omitted in encoded text.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3038 In a 7-bit environment, only GL can be used.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3039
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3040 When a graphic character set of TYPE94 or TYPE94x94 is invoked to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3041 GL, codes 0x20 and 0x7F of the GL area work as control characters
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3042 SPACE and DEL respectively, and code 0xA0 and 0xFF of GR area
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3043 should not be used.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3044
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3045 There are two ways of invocation: locking-shift and single-shift.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3046 With locking-shift, the invocation lasts until the next different
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3047 invocation, whereas with single-shift, the invocation works only
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3048 for the following character and doesn't affect locking-shift.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3049 Invocations are done by the following control characters or escape
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3050 sequences.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3051
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3052 ----------------------------------------------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3053 abbrev function cntrl escape seq description
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3054 ----------------------------------------------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3055 SI/LS0 (shift-in) 0x0F none invoke G0 into GL
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3056 SO/LS1 (shift-out) 0x0E none invoke G1 into GL
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3057 LS1R (locking-shift-1 right) none ESC '~' invoke G1 into GR
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3058 LS2 (locking-shift-2) none ESC 'n' invoke G2 into GL
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3059 LS2R (locking-shift-2 right) none ESC '}' invoke G2 into GR
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3060 LS3 (locking-shift-3) none ESC 'o' invoke G3 into GL
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3061 LS3R (locking-shift 3 right) none ESC '|' invoke G3 into GR
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3062 SS2 (single-shift-2) 0x8E ESC 'N' invoke G2 for one char
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3063 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3064 ----------------------------------------------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3065 The first four are for locking-shift. Control characters for these
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3066 functions are defined by macros ISO_CODE_XXX in `coding.h'.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3067
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3068 Designations are done by the following escape sequences.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3069 ----------------------------------------------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3070 escape sequence description
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3071 ----------------------------------------------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3072 ESC '(' <F> designate TYPE94<F> to G0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3073 ESC ')' <F> designate TYPE94<F> to G1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3074 ESC '*' <F> designate TYPE94<F> to G2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3075 ESC '+' <F> designate TYPE94<F> to G3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3076 ESC ',' <F> designate TYPE96<F> to G0 (*)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3077 ESC '-' <F> designate TYPE96<F> to G1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3078 ESC '.' <F> designate TYPE96<F> to G2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3079 ESC '/' <F> designate TYPE96<F> to G3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3080 ESC '$' '(' <F> designate TYPE94x94<F> to G0 (**)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3081 ESC '$' ')' <F> designate TYPE94x94<F> to G1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3082 ESC '$' '*' <F> designate TYPE94x94<F> to G2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3083 ESC '$' '+' <F> designate TYPE94x94<F> to G3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3084 ESC '$' ',' <F> designate TYPE96x96<F> to G0 (*)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3085 ESC '$' '-' <F> designate TYPE96x96<F> to G1
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3086 ESC '$' '.' <F> designate TYPE96x96<F> to G2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3087 ESC '$' '/' <F> designate TYPE96x96<F> to G3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3088 ----------------------------------------------------------------------
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3089 In this list, "TYPE94<F>" means a graphic character set of type TYPE94
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3090 and final character <F>, and etc.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3091
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3092 Note (*): Although these designations are not allowed in ISO2022,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3093 Emacs accepts them on decoding, and produces them on encoding
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3094 TYPE96 or TYPE96x96 character set in a coding system which is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3095 characterized as 7-bit environment, non-locking-shift, and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3096 non-single-shift.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3097
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3098 Note (**): If <F> is '@', 'A', or 'B', the intermediate character
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3099 '(' can be omitted. We call this as "short-form" here after.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3100
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3101 Now you may notice that there are a lot of ways for encoding the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3102 same multilingual text in ISO2022. Actually, there exist many
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3103 coding systems such as Compound Text (used in X's inter client
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3104 communication, ISO-2022-JP (used in Japanese internet), ISO-2022-KR
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3105 (used in Korean internet), EUC (Extended UNIX Code, used in Asian
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3106 localized platforms), and all of these are variants of ISO2022.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3107
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3108 In addition to the above, Emacs handles two more kinds of escape
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3109 sequences: ISO6429's direction specification and Emacs' private
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3110 sequence for specifying character composition.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3111
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3112 ISO6429's direction specification takes the following format:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3113 o CSI ']' -- end of the current direction
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3114 o CSI '0' ']' -- end of the current direction
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3115 o CSI '1' ']' -- start of left-to-right text
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3116 o CSI '2' ']' -- start of right-to-left text
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3117 The control character CSI (0x9B: control sequence introducer) is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3118 abbreviated to the escape sequence ESC '[' in 7-bit environment.
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3119
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3120 Character composition specification takes the following format:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3121 o ESC '0' -- start character composition
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3122 o ESC '1' -- end character composition
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3123 Since these are not standard escape sequences of any ISO, the use
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3124 of them for these meanings is restricted to Emacs only. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3125
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3126 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3127 reset_iso2022 (Lisp_Object coding_system, struct iso2022_decoder *iso)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3128 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3129 int i;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3130
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3131 for (i = 0; i < 4; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3132 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3133 if (!NILP (coding_system))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3134 iso->charset[i] =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3135 XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3136 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3137 iso->charset[i] = Qt;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3138 iso->invalid_designated[i] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3139 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3140 iso->esc = ISO_ESC_NOTHING;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3141 iso->esc_bytes_index = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3142 iso->register_left = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3143 iso->register_right = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3144 iso->switched_dir_and_no_valid_charset_yet = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3145 iso->invalid_switch_dir = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3146 iso->output_direction_sequence = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3147 iso->output_literally = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3148 if (iso->composite_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3149 Dynarr_reset (iso->composite_chars);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3150 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3151
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3152 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3153 fit_to_be_escape_quoted (unsigned char c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3154 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3155 switch (c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3156 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3157 case ISO_CODE_ESC:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3158 case ISO_CODE_CSI:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3159 case ISO_CODE_SS2:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3160 case ISO_CODE_SS3:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3161 case ISO_CODE_SO:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3162 case ISO_CODE_SI:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3163 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3164
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3165 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3166 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3167 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3168 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3169
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3170 /* Parse one byte of an ISO2022 escape sequence.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3171 If the result is an invalid escape sequence, return 0 and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3172 do not change anything in STR. Otherwise, if the result is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3173 an incomplete escape sequence, update ISO2022.ESC and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3174 ISO2022.ESC_BYTES and return -1. Otherwise, update
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3175 all the state variables (but not ISO2022.ESC_BYTES) and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3176 return 1.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3177
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3178 If CHECK_INVALID_CHARSETS is non-zero, check for designation
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3179 or invocation of an invalid character set and treat that as
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3180 an unrecognized escape sequence. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3181
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3182 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3183 parse_iso2022_esc (Lisp_Object codesys, struct iso2022_decoder *iso,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3184 unsigned char c, unsigned int *flags,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3185 int check_invalid_charsets)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3186 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3187 /* (1) If we're at the end of a designation sequence, CS is the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3188 charset being designated and REG is the register to designate
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3189 it to.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3190
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3191 (2) If we're at the end of a locking-shift sequence, REG is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3192 the register to invoke and HALF (0 == left, 1 == right) is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3193 the half to invoke it into.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3194
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3195 (3) If we're at the end of a single-shift sequence, REG is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3196 the register to invoke. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3197 Lisp_Object cs = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3198 int reg, half;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3199
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3200 /* NOTE: This code does goto's all over the fucking place.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3201 The reason for this is that we're basically implementing
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3202 a state machine here, and hierarchical languages like C
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3203 don't really provide a clean way of doing this. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3204
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3205 if (! (*flags & CODING_STATE_ESCAPE))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3206 /* At beginning of escape sequence; we need to reset our
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3207 escape-state variables. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3208 iso->esc = ISO_ESC_NOTHING;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3209
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3210 iso->output_literally = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3211 iso->output_direction_sequence = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3212
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3213 switch (iso->esc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3214 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3215 case ISO_ESC_NOTHING:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3216 iso->esc_bytes_index = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3217 switch (c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3218 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3219 case ISO_CODE_ESC: /* Start escape sequence */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3220 *flags |= CODING_STATE_ESCAPE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3221 iso->esc = ISO_ESC;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3222 goto not_done;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3223
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3224 case ISO_CODE_CSI: /* ISO6429 (specifying directionality) */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3225 *flags |= CODING_STATE_ESCAPE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3226 iso->esc = ISO_ESC_5_11;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3227 goto not_done;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3228
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3229 case ISO_CODE_SO: /* locking shift 1 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3230 reg = 1; half = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3231 goto locking_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3232 case ISO_CODE_SI: /* locking shift 0 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3233 reg = 0; half = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3234 goto locking_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3235
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3236 case ISO_CODE_SS2: /* single shift */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3237 reg = 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3238 goto single_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3239 case ISO_CODE_SS3: /* single shift */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3240 reg = 3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3241 goto single_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3242
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3243 default: /* Other control characters */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3244 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3245 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3246
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3247 case ISO_ESC:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3248 switch (c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3249 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3250 /**** single shift ****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3251
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3252 case 'N': /* single shift 2 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3253 reg = 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3254 goto single_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3255 case 'O': /* single shift 3 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3256 reg = 3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3257 goto single_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3258
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3259 /**** locking shift ****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3260
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3261 case '~': /* locking shift 1 right */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3262 reg = 1; half = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3263 goto locking_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3264 case 'n': /* locking shift 2 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3265 reg = 2; half = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3266 goto locking_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3267 case '}': /* locking shift 2 right */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3268 reg = 2; half = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3269 goto locking_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3270 case 'o': /* locking shift 3 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3271 reg = 3; half = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3272 goto locking_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3273 case '|': /* locking shift 3 right */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3274 reg = 3; half = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3275 goto locking_shift;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3276
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3277 /**** composite ****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3278
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3279 case '0':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3280 iso->esc = ISO_ESC_START_COMPOSITE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3281 *flags = (*flags & CODING_STATE_ISO2022_LOCK) |
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3282 CODING_STATE_COMPOSITE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3283 return 1;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3284
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3285 case '1':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3286 iso->esc = ISO_ESC_END_COMPOSITE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3287 *flags = (*flags & CODING_STATE_ISO2022_LOCK) &
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3288 ~CODING_STATE_COMPOSITE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3289 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3290
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3291 /**** directionality ****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3292
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3293 case '[':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3294 iso->esc = ISO_ESC_5_11;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3295 goto not_done;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3296
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3297 /**** designation ****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3298
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3299 case '$': /* multibyte charset prefix */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3300 iso->esc = ISO_ESC_2_4;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3301 goto not_done;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3302
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3303 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3304 if (0x28 <= c && c <= 0x2F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3305 {
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
3306 iso->esc = (enum iso_esc_flag) (c - 0x28 + ISO_ESC_2_8);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3307 goto not_done;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3308 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3309
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3310 /* This function is called with CODESYS equal to nil when
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3311 doing coding-system detection. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3312 if (!NILP (codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3313 && XCODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3314 && fit_to_be_escape_quoted (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3315 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3316 iso->esc = ISO_ESC_LITERAL;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3317 *flags &= CODING_STATE_ISO2022_LOCK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3318 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3319 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3320
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3321 /* bzzzt! */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3322 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3323 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3324
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3325
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3326
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3327 /**** directionality ****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3328
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3329 case ISO_ESC_5_11: /* ISO6429 direction control */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3330 if (c == ']')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3331 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3332 *flags &= (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3333 goto directionality;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3334 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3335 if (c == '0') iso->esc = ISO_ESC_5_11_0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3336 else if (c == '1') iso->esc = ISO_ESC_5_11_1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3337 else if (c == '2') iso->esc = ISO_ESC_5_11_2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3338 else return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3339 goto not_done;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3340
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3341 case ISO_ESC_5_11_0:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3342 if (c == ']')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3343 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3344 *flags &= (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3345 goto directionality;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3346 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3347 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3348
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3349 case ISO_ESC_5_11_1:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3350 if (c == ']')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3351 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3352 *flags = (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3353 goto directionality;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3354 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3355 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3356
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3357 case ISO_ESC_5_11_2:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3358 if (c == ']')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3359 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3360 *flags = (*flags & CODING_STATE_ISO2022_LOCK) | CODING_STATE_R2L;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3361 goto directionality;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3362 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3363 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3364
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3365 directionality:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3366 iso->esc = ISO_ESC_DIRECTIONALITY;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3367 /* Various junk here to attempt to preserve the direction sequences
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3368 literally in the text if they would otherwise be swallowed due
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3369 to invalid designations that don't show up as actual charset
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3370 changes in the text. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3371 if (iso->invalid_switch_dir)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3372 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3373 /* We already inserted a direction switch literally into the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3374 text. We assume (#### this may not be right) that the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3375 next direction switch is the one going the other way,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3376 and we need to output that literally as well. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3377 iso->output_literally = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3378 iso->invalid_switch_dir = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3379 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3380 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3381 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3382 int jj;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3383
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
3384 /* If we are in the thrall of an invalid designation,
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3385 then stick the directionality sequence literally into the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3386 output stream so it ends up in the original text again. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3387 for (jj = 0; jj < 4; jj++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3388 if (iso->invalid_designated[jj])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3389 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3390 if (jj < 4)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3391 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3392 iso->output_literally = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3393 iso->invalid_switch_dir = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3394 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3395 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3396 /* Indicate that we haven't yet seen a valid designation,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3397 so that if a switch-dir is directly followed by an
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3398 invalid designation, both get inserted literally. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3399 iso->switched_dir_and_no_valid_charset_yet = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3400 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3401 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3402
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3403
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3404 /**** designation ****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3405
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3406 case ISO_ESC_2_4:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3407 if (0x28 <= c && c <= 0x2F)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3408 {
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
3409 iso->esc = (enum iso_esc_flag) (c - 0x28 + ISO_ESC_2_4_8);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3410 goto not_done;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3411 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3412 if (0x40 <= c && c <= 0x42)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3413 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3414 cs = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_94X94, c,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3415 *flags & CODING_STATE_R2L ?
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3416 CHARSET_RIGHT_TO_LEFT :
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3417 CHARSET_LEFT_TO_RIGHT);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3418 reg = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3419 goto designated;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3420 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3421 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3422
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3423 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3424 {
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
3425 int type =-1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3426
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3427 if (c < '0' || c > '~')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3428 return 0; /* bad final byte */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3429
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3430 if (iso->esc >= ISO_ESC_2_8 &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3431 iso->esc <= ISO_ESC_2_15)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3432 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
3433 type = ((iso->esc >= ISO_ESC_2_12) ?
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
3434 CHARSET_TYPE_96 : CHARSET_TYPE_94);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3435 reg = (iso->esc - ISO_ESC_2_8) & 3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3436 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3437 else if (iso->esc >= ISO_ESC_2_4_8 &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3438 iso->esc <= ISO_ESC_2_4_15)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3439 {
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
3440 type = ((iso->esc >= ISO_ESC_2_4_12) ?
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
3441 CHARSET_TYPE_96X96 : CHARSET_TYPE_94X94);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3442 reg = (iso->esc - ISO_ESC_2_4_8) & 3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3443 }
179
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
3444 else
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
3445 {
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
3446 /* Can this ever be reached? -slb */
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
3447 abort();
9ad43877534d Import from CVS: tag r20-3b16
cvs
parents: 173
diff changeset
3448 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3449
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3450 cs = CHARSET_BY_ATTRIBUTES (type, c,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3451 *flags & CODING_STATE_R2L ?
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3452 CHARSET_RIGHT_TO_LEFT :
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3453 CHARSET_LEFT_TO_RIGHT);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3454 goto designated;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3455 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3456 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3457
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3458 not_done:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3459 iso->esc_bytes[iso->esc_bytes_index++] = (unsigned char) c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3460 return -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3461
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3462 single_shift:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3463 if (check_invalid_charsets && !CHARSETP (iso->charset[reg]))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3464 /* can't invoke something that ain't there. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3465 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3466 iso->esc = ISO_ESC_SINGLE_SHIFT;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3467 *flags &= CODING_STATE_ISO2022_LOCK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3468 if (reg == 2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3469 *flags |= CODING_STATE_SS2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3470 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3471 *flags |= CODING_STATE_SS3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3472 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3473
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3474 locking_shift:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3475 if (check_invalid_charsets &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3476 !CHARSETP (iso->charset[reg]))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3477 /* can't invoke something that ain't there. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3478 return 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3479 if (half)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3480 iso->register_right = reg;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3481 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3482 iso->register_left = reg;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3483 *flags &= CODING_STATE_ISO2022_LOCK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3484 iso->esc = ISO_ESC_LOCKING_SHIFT;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3485 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3486
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3487 designated:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3488 if (NILP (cs) && check_invalid_charsets)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3489 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3490 iso->invalid_designated[reg] = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3491 iso->charset[reg] = Vcharset_ascii;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3492 iso->esc = ISO_ESC_DESIGNATE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3493 *flags &= CODING_STATE_ISO2022_LOCK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3494 iso->output_literally = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3495 if (iso->switched_dir_and_no_valid_charset_yet)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3496 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3497 /* We encountered a switch-direction followed by an
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3498 invalid designation. Ensure that the switch-direction
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3499 gets outputted; otherwise it will probably get eaten
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3500 when the text is written out again. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3501 iso->switched_dir_and_no_valid_charset_yet = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3502 iso->output_direction_sequence = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3503 /* And make sure that the switch-dir going the other
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3504 way gets outputted, as well. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3505 iso->invalid_switch_dir = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3506 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3507 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3508 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3509 /* This function is called with CODESYS equal to nil when
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3510 doing coding-system detection. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3511 if (!NILP (codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3512 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3513 charset_conversion_spec_dynarr *dyn =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3514 XCODING_SYSTEM (codesys)->iso2022.input_conv;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3515
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3516 if (dyn)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3517 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3518 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3519
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3520 for (i = 0; i < Dynarr_length (dyn); i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3521 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3522 struct charset_conversion_spec *spec = Dynarr_atp (dyn, i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3523 if (EQ (cs, spec->from_charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3524 cs = spec->to_charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3525 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3526 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3527 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3528
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3529 iso->charset[reg] = cs;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3530 iso->esc = ISO_ESC_DESIGNATE;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3531 *flags &= CODING_STATE_ISO2022_LOCK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3532 if (iso->invalid_designated[reg])
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3533 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3534 iso->invalid_designated[reg] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3535 iso->output_literally = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3536 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3537 if (iso->switched_dir_and_no_valid_charset_yet)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3538 iso->switched_dir_and_no_valid_charset_yet = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3539 return 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3540 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3541
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3542 static int
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
3543 detect_coding_iso2022 (struct detection_state *st, CONST unsigned char *src,
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3544 unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3545 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3546 int c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3547 int mask;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3548
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3549 /* #### There are serious deficiencies in the recognition mechanism
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3550 here. This needs to be much smarter if it's going to cut it. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3551
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3552 if (!st->iso2022.initted)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3553 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3554 reset_iso2022 (Qnil, &st->iso2022.iso);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3555 st->iso2022.mask = (CODING_CATEGORY_ISO_7_MASK |
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3556 CODING_CATEGORY_ISO_8_DESIGNATE_MASK |
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3557 CODING_CATEGORY_ISO_8_1_MASK |
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3558 CODING_CATEGORY_ISO_8_2_MASK |
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3559 CODING_CATEGORY_ISO_LOCK_SHIFT_MASK);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3560 st->iso2022.flags = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3561 st->iso2022.high_byte_count = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3562 st->iso2022.saw_single_shift = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3563 st->iso2022.initted = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3564 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3565
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3566 mask = st->iso2022.mask;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3567
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3568 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3569 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3570 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3571 if (c >= 0xA0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3572 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3573 mask &= ~CODING_CATEGORY_ISO_7_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3574 st->iso2022.high_byte_count++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3575 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3576 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3577 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3578 if (st->iso2022.high_byte_count && !st->iso2022.saw_single_shift)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3579 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3580 if (st->iso2022.high_byte_count & 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3581 /* odd number of high bytes; assume not iso-8-2 */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3582 mask &= ~CODING_CATEGORY_ISO_8_2_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3583 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3584 st->iso2022.high_byte_count = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3585 st->iso2022.saw_single_shift = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3586 if (c > 0x80)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3587 mask &= ~CODING_CATEGORY_ISO_7_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3588 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3589 if (!(st->iso2022.flags & CODING_STATE_ESCAPE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3590 && (BYTE_C0_P (c) || BYTE_C1_P (c)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3591 { /* control chars */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3592 switch (c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3593 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3594 /* Allow and ignore control characters that you might
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3595 reasonably see in a text file */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3596 case '\r':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3597 case '\n':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3598 case '\t':
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3599 case 7: /* bell */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3600 case 8: /* backspace */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3601 case 11: /* vertical tab */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3602 case 12: /* form feed */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3603 case 26: /* MS-DOS C-z junk */
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
3604 case 31: /* '^_' -- for info */
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3605 goto label_continue_loop;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3606
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3607 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3608 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3609 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3610 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3611
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3612 if ((st->iso2022.flags & CODING_STATE_ESCAPE) || BYTE_C0_P (c)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3613 || BYTE_C1_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3614 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3615 if (parse_iso2022_esc (Qnil, &st->iso2022.iso, c,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3616 &st->iso2022.flags, 0))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3617 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3618 switch (st->iso2022.iso.esc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3619 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3620 case ISO_ESC_DESIGNATE:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3621 mask &= ~CODING_CATEGORY_ISO_8_1_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3622 mask &= ~CODING_CATEGORY_ISO_8_2_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3623 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3624 case ISO_ESC_LOCKING_SHIFT:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3625 mask = CODING_CATEGORY_ISO_LOCK_SHIFT_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3626 goto ran_out_of_chars;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3627 case ISO_ESC_SINGLE_SHIFT:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3628 mask &= ~CODING_CATEGORY_ISO_8_DESIGNATE_MASK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3629 st->iso2022.saw_single_shift = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3630 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3631 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3632 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3633 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3634 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3635 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3636 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3637 mask = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3638 goto ran_out_of_chars;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3639 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3640 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3641 label_continue_loop:;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3642 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3643
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3644 ran_out_of_chars:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3645
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3646 return mask;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3647 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3648
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3649 static int
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3650 postprocess_iso2022_mask (int mask)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3651 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3652 /* #### kind of cheesy */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3653 /* If seven-bit ISO is allowed, then assume that the encoding is
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3654 entirely seven-bit and turn off the eight-bit ones. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3655 if (mask & CODING_CATEGORY_ISO_7_MASK)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3656 mask &= ~ (CODING_CATEGORY_ISO_8_DESIGNATE_MASK |
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3657 CODING_CATEGORY_ISO_8_1_MASK |
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3658 CODING_CATEGORY_ISO_8_2_MASK);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3659 return mask;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3660 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3661
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3662 /* If FLAGS is a null pointer or specifies right-to-left motion,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3663 output a switch-dir-to-left-to-right sequence to DST.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3664 Also update FLAGS if it is not a null pointer.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3665 If INTERNAL_P is set, we are outputting in internal format and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3666 need to handle the CSI differently. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3667
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3668 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3669 restore_left_to_right_direction (struct Lisp_Coding_System *codesys,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3670 unsigned_char_dynarr *dst,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3671 unsigned int *flags,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3672 int internal_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3673 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3674 if (!flags || (*flags & CODING_STATE_R2L))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3675 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3676 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3677 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3678 Dynarr_add (dst, ISO_CODE_ESC);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3679 Dynarr_add (dst, '[');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3680 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3681 else if (internal_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3682 DECODE_ADD_BINARY_CHAR (ISO_CODE_CSI, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3683 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3684 Dynarr_add (dst, ISO_CODE_CSI);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3685 Dynarr_add (dst, '0');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3686 Dynarr_add (dst, ']');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3687 if (flags)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3688 *flags &= ~CODING_STATE_R2L;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3689 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3690 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3691
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3692 /* If FLAGS is a null pointer or specifies a direction different from
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3693 DIRECTION (which should be either CHARSET_RIGHT_TO_LEFT or
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3694 CHARSET_LEFT_TO_RIGHT), output the appropriate switch-dir escape
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3695 sequence to DST. Also update FLAGS if it is not a null pointer.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3696 If INTERNAL_P is set, we are outputting in internal format and
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3697 need to handle the CSI differently. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3698
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3699 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3700 ensure_correct_direction (int direction, struct Lisp_Coding_System *codesys,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3701 unsigned_char_dynarr *dst, unsigned int *flags,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3702 int internal_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3703 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3704 if ((!flags || (*flags & CODING_STATE_R2L)) &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3705 direction == CHARSET_LEFT_TO_RIGHT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3706 restore_left_to_right_direction (codesys, dst, flags, internal_p);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3707 else if (!CODING_SYSTEM_ISO2022_NO_ISO6429 (codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3708 && (!flags || !(*flags & CODING_STATE_R2L)) &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3709 direction == CHARSET_RIGHT_TO_LEFT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3710 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3711 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3712 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3713 Dynarr_add (dst, ISO_CODE_ESC);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3714 Dynarr_add (dst, '[');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3715 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3716 else if (internal_p)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3717 DECODE_ADD_BINARY_CHAR (ISO_CODE_CSI, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3718 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3719 Dynarr_add (dst, ISO_CODE_CSI);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3720 Dynarr_add (dst, '2');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3721 Dynarr_add (dst, ']');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3722 if (flags)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3723 *flags |= CODING_STATE_R2L;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3724 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3725 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3726
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3727 /* Convert ISO2022-format data to internal format. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3728
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3729 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3730 decode_coding_iso2022 (Lstream *decoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3731 unsigned_char_dynarr *dst, unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3732 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3733 unsigned char c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3734 unsigned int flags, ch;
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
3735 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3736 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3737 Lisp_Object coding_system = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3738 unsigned_char_dynarr *real_dst = dst;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3739
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3740 CODING_STREAM_DECOMPOSE (str, flags, ch);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
3741 eol_type = str->eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3742 XSETCODING_SYSTEM (coding_system, str->codesys);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3743
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3744 if (flags & CODING_STATE_COMPOSITE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3745 dst = str->iso2022.composite_chars;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3746
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3747 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3748 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3749 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3750 if (flags & CODING_STATE_ESCAPE)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3751 { /* Within ESC sequence */
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
3752 int retval = parse_iso2022_esc (coding_system, &str->iso2022,
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
3753 c, &flags, 1);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3754
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3755 if (retval)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3756 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3757 switch (str->iso2022.esc)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3758 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3759 case ISO_ESC_START_COMPOSITE:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3760 if (str->iso2022.composite_chars)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3761 Dynarr_reset (str->iso2022.composite_chars);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3762 else
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
3763 str->iso2022.composite_chars = Dynarr_new (unsigned_char);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3764 dst = str->iso2022.composite_chars;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3765 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3766 case ISO_ESC_END_COMPOSITE:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3767 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3768 Bufbyte comstr[MAX_EMCHAR_LEN];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3769 Bytecount len;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3770 Emchar emch = lookup_composite_char (Dynarr_atp (dst, 0),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3771 Dynarr_length (dst));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3772 dst = real_dst;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3773 len = set_charptr_emchar (comstr, emch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3774 Dynarr_add_many (dst, comstr, len);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3775 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3776 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3777
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3778 case ISO_ESC_LITERAL:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3779 DECODE_ADD_BINARY_CHAR (c, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3780 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3781
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3782 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3783 /* Everything else handled already */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3784 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3785 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3786 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3787
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3788 /* Attempted error recovery. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3789 if (str->iso2022.output_direction_sequence)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3790 ensure_correct_direction (flags & CODING_STATE_R2L ?
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3791 CHARSET_RIGHT_TO_LEFT :
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3792 CHARSET_LEFT_TO_RIGHT,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3793 str->codesys, dst, 0, 1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3794 /* More error recovery. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3795 if (!retval || str->iso2022.output_literally)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3796 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3797 /* Output the (possibly invalid) sequence */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3798 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3799 for (i = 0; i < str->iso2022.esc_bytes_index; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3800 DECODE_ADD_BINARY_CHAR (str->iso2022.esc_bytes[i], dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3801 flags &= CODING_STATE_ISO2022_LOCK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3802 if (!retval)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3803 n++, src--;/* Repeat the loop with the same character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3804 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3805 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3806 /* No sense in reprocessing the final byte of the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3807 escape sequence; it could mess things up anyway.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3808 Just add it now. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3809 DECODE_ADD_BINARY_CHAR (c, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3810 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3811 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3812 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3813 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3814 else if (BYTE_C0_P (c) || BYTE_C1_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3815 { /* Control characters */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3816
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3817 /***** Error-handling *****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3818
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3819 /* If we were in the middle of a character, dump out the
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3820 partial character. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3821 DECODE_OUTPUT_PARTIAL_CHAR (ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3822
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3823 /* If we just saw a single-shift character, dump it out.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3824 This may dump out the wrong sort of single-shift character,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3825 but least it will give an indication that something went
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3826 wrong. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3827 if (flags & CODING_STATE_SS2)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3828 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3829 DECODE_ADD_BINARY_CHAR (ISO_CODE_SS2, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3830 flags &= ~CODING_STATE_SS2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3831 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3832 if (flags & CODING_STATE_SS3)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3833 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3834 DECODE_ADD_BINARY_CHAR (ISO_CODE_SS3, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3835 flags &= ~CODING_STATE_SS3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3836 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3837
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3838 /***** Now handle the control characters. *****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3839
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3840 /* Handle CR/LF */
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
3841 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3842
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3843 flags &= CODING_STATE_ISO2022_LOCK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3844
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3845 if (!parse_iso2022_esc (coding_system, &str->iso2022, c, &flags, 1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3846 DECODE_ADD_BINARY_CHAR (c, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3847 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3848 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3849 { /* Graphic characters */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3850 Lisp_Object charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3851 int lb;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3852 int reg;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3853
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
3854 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3855
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3856 /* Now determine the charset. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3857 reg = ((flags & CODING_STATE_SS2) ? 2
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3858 : (flags & CODING_STATE_SS3) ? 3
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3859 : !BYTE_ASCII_P (c) ? str->iso2022.register_right
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3860 : str->iso2022.register_left);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3861 charset = str->iso2022.charset[reg];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3862
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3863 /* Error checking: */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3864 if (NILP (charset) || str->iso2022.invalid_designated[reg]
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3865 || (((c & 0x7F) == ' ' || (c & 0x7F) == ISO_CODE_DEL)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3866 && XCHARSET_CHARS (charset) == 94))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3867 /* Mrmph. We are trying to invoke a register that has no
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3868 or an invalid charset in it, or trying to add a character
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3869 outside the range of the charset. Insert that char literally
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3870 to preserve it for the output. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3871 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3872 DECODE_OUTPUT_PARTIAL_CHAR (ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3873 DECODE_ADD_BINARY_CHAR (c, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3874 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3875
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3876 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3877 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3878 /* Things are probably hunky-dorey. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3879
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3880 /* Fetch reverse charset, maybe. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3881 if (((flags & CODING_STATE_R2L) &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3882 XCHARSET_DIRECTION (charset) == CHARSET_LEFT_TO_RIGHT)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3883 ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3884 (!(flags & CODING_STATE_R2L) &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3885 XCHARSET_DIRECTION (charset) == CHARSET_RIGHT_TO_LEFT))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3886 {
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3887 Lisp_Object new_charset =
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3888 XCHARSET_REVERSE_DIRECTION_CHARSET (charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3889 if (!NILP (new_charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3890 charset = new_charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3891 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3892
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3893 lb = XCHARSET_LEADING_BYTE (charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3894 switch (XCHARSET_REP_BYTES (charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3895 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3896 case 1: /* ASCII */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3897 DECODE_OUTPUT_PARTIAL_CHAR (ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3898 Dynarr_add (dst, c & 0x7F);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3899 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3900
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3901 case 2: /* one-byte official */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3902 DECODE_OUTPUT_PARTIAL_CHAR (ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3903 Dynarr_add (dst, lb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3904 Dynarr_add (dst, c | 0x80);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3905 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3906
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3907 case 3: /* one-byte private or two-byte official */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3908 if (XCHARSET_PRIVATE_P (charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3909 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3910 DECODE_OUTPUT_PARTIAL_CHAR (ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3911 Dynarr_add (dst, PRE_LEADING_BYTE_PRIVATE_1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3912 Dynarr_add (dst, lb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3913 Dynarr_add (dst, c | 0x80);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3914 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3915 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3916 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3917 if (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3918 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3919 Dynarr_add (dst, lb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3920 Dynarr_add (dst, ch | 0x80);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3921 Dynarr_add (dst, c | 0x80);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3922 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3923 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3924 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3925 ch = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3926 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3927 break;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3928
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3929 default: /* two-byte private */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3930 if (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3931 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3932 Dynarr_add (dst, PRE_LEADING_BYTE_PRIVATE_2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3933 Dynarr_add (dst, lb);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3934 Dynarr_add (dst, ch | 0x80);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3935 Dynarr_add (dst, c | 0x80);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3936 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3937 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3938 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3939 ch = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3940 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3941 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3942
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3943 if (!ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3944 flags &= CODING_STATE_ISO2022_LOCK;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3945 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3946
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3947 label_continue_loop:;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3948 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3949
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3950 if (flags & CODING_STATE_END)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3951 DECODE_OUTPUT_PARTIAL_CHAR (ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3952
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3953 CODING_STREAM_COMPOSE (str, flags, ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3954 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3955
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3956
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3957 /***** ISO2022 encoder *****/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3958
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3959 /* Designate CHARSET into register REG. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3960
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3961 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3962 iso2022_designate (Lisp_Object charset, unsigned char reg,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3963 struct encoding_stream *str, unsigned_char_dynarr *dst)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3964 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3965 CONST char *inter94 = "()*+", *inter96= ",-./";
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3966 int type;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3967 unsigned char final;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3968 Lisp_Object old_charset = str->iso2022.charset[reg];
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3969
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3970 str->iso2022.charset[reg] = charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3971 if (!CHARSETP (charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3972 /* charset might be an initial nil or t. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3973 return;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3974 type = XCHARSET_TYPE (charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3975 final = XCHARSET_FINAL (charset);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3976 if (!str->iso2022.force_charset_on_output[reg] &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3977 CHARSETP (old_charset) &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3978 XCHARSET_TYPE (old_charset) == type &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3979 XCHARSET_FINAL (old_charset) == final)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3980 return;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3981
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3982 str->iso2022.force_charset_on_output[reg] = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3983
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3984 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3985 charset_conversion_spec_dynarr *dyn =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3986 str->codesys->iso2022.output_conv;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3987
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3988 if (dyn)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3989 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3990 int i;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
3991
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3992 for (i = 0; i < Dynarr_length (dyn); i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3993 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3994 struct charset_conversion_spec *spec = Dynarr_atp (dyn, i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3995 if (EQ (charset, spec->from_charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3996 charset = spec->to_charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3997 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3998 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
3999 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4000
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4001 Dynarr_add (dst, ISO_CODE_ESC);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4002 switch (type)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4003 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4004 case CHARSET_TYPE_94:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4005 Dynarr_add (dst, inter94[reg]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4006 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4007 case CHARSET_TYPE_96:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4008 Dynarr_add (dst, inter96[reg]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4009 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4010 case CHARSET_TYPE_94X94:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4011 Dynarr_add (dst, '$');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4012 if (reg != 0
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4013 || !(CODING_SYSTEM_ISO2022_SHORT (str->codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4014 || final < '@'
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4015 || final > 'B')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4016 Dynarr_add (dst, inter94[reg]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4017 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4018 case CHARSET_TYPE_96X96:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4019 Dynarr_add (dst, '$');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4020 Dynarr_add (dst, inter96[reg]);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4021 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4022 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4023 Dynarr_add (dst, final);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4024 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4025
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4026 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4027 ensure_normal_shift (struct encoding_stream *str, unsigned_char_dynarr *dst)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4028 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4029 if (str->iso2022.register_left != 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4030 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4031 Dynarr_add (dst, ISO_CODE_SI);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4032 str->iso2022.register_left = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4033 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4034 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4035
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4036 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4037 ensure_shift_out (struct encoding_stream *str, unsigned_char_dynarr *dst)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4038 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4039 if (str->iso2022.register_left != 1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4040 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4041 Dynarr_add (dst, ISO_CODE_SO);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4042 str->iso2022.register_left = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4043 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4044 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4045
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4046 /* Convert internally-formatted data to ISO2022 format. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4047
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4048 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4049 encode_coding_iso2022 (Lstream *encoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4050 unsigned_char_dynarr *dst, unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4051 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4052 unsigned char charmask, c;
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4053 unsigned int flags, ch;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4054 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4055 unsigned char char_boundary;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4056 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4057 struct Lisp_Coding_System *codesys = str->codesys;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4058 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4059 Lisp_Object charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4060 int half;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4061
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4062 /* flags for handling composite chars. We do a little switcharoo
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4063 on the source while we're outputting the composite char. */
173
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
4064 unsigned int saved_n = 0;
8eaf7971accc Import from CVS: tag r20-3b13
cvs
parents: 120
diff changeset
4065 CONST unsigned char *saved_src = NULL;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4066 int in_composite = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4067
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4068 CODING_STREAM_DECOMPOSE (str, flags, ch);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4069 eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4070 char_boundary = str->iso2022.current_char_boundary;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4071 charset = str->iso2022.current_charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4072 half = str->iso2022.current_half;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4073
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4074 back_to_square_n:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4075 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4076 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4077 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4078
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4079 if (BYTE_ASCII_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4080 { /* Processing ASCII character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4081 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4082
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4083 restore_left_to_right_direction (codesys, dst, &flags, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4084
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4085 /* Make sure G0 contains ASCII */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4086 if ((c > ' ' && c < ISO_CODE_DEL) ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4087 !CODING_SYSTEM_ISO2022_NO_ASCII_CNTL (codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4088 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4089 ensure_normal_shift (str, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4090 iso2022_designate (Vcharset_ascii, 0, str, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4091 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4092
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4093 /* If necessary, restore everything to the default state
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4094 at end-of-line */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4095 if (c == '\n' &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4096 !(CODING_SYSTEM_ISO2022_NO_ASCII_EOL (codesys)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4097 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4098 restore_left_to_right_direction (codesys, dst, &flags, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4099
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4100 ensure_normal_shift (str, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4101
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4102 for (i = 0; i < 4; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4103 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4104 Lisp_Object initial_charset =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4105 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4106 iso2022_designate (initial_charset, i, str, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4107 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4108 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4109 if (c == '\n')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4110 {
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4111 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4112 Dynarr_add (dst, '\r');
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4113 if (eol_type != EOL_CR)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4114 Dynarr_add (dst, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4115 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4116 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4117 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4118 if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4119 && fit_to_be_escape_quoted (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4120 Dynarr_add (dst, ISO_CODE_ESC);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4121 Dynarr_add (dst, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4122 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4123 char_boundary = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4124 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4125
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4126 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4127 { /* Processing Leading Byte */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4128 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4129 charset = CHARSET_BY_LEADING_BYTE (c);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
4130 if (LEADING_BYTE_PREFIX_P(c))
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4131 ch = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4132 else if (!EQ (charset, Vcharset_control_1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4133 && !EQ (charset, Vcharset_composite))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4134 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4135 int reg;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4136
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4137 ensure_correct_direction (XCHARSET_DIRECTION (charset),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4138 codesys, dst, &flags, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4139
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4140 /* Now determine which register to use. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4141 reg = -1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4142 for (i = 0; i < 4; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4143 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4144 if (EQ (charset, str->iso2022.charset[i]) ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4145 EQ (charset,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4146 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4147 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4148 reg = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4149 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4150 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4151 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4152
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4153 if (reg == -1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4154 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4155 if (XCHARSET_GRAPHIC (charset) != 0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4156 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4157 if (!NILP (str->iso2022.charset[1]) &&
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4158 (!CODING_SYSTEM_ISO2022_SEVEN (codesys) ||
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4159 CODING_SYSTEM_ISO2022_LOCK_SHIFT (codesys)))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4160 reg = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4161 else if (!NILP (str->iso2022.charset[2]))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4162 reg = 2;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4163 else if (!NILP (str->iso2022.charset[3]))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4164 reg = 3;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4165 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4166 reg = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4167 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4168 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4169 reg = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4170 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4171
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4172 iso2022_designate (charset, reg, str, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4173
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4174 /* Now invoke that register. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4175 switch (reg)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4176 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4177 case 0:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4178 ensure_normal_shift (str, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4179 half = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4180 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4181
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4182 case 1:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4183 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4184 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4185 ensure_shift_out (str, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4186 half = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4187 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4188 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4189 half = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4190 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4191
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4192 case 2:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4193 if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4194 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4195 Dynarr_add (dst, ISO_CODE_ESC);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4196 Dynarr_add (dst, 'N');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4197 half = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4198 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4199 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4200 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4201 Dynarr_add (dst, ISO_CODE_SS2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4202 half = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4203 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4204 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4205
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4206 case 3:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4207 if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4208 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4209 Dynarr_add (dst, ISO_CODE_ESC);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4210 Dynarr_add (dst, 'O');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4211 half = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4212 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4213 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4214 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4215 Dynarr_add (dst, ISO_CODE_SS3);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4216 half = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4217 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4218 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4219
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4220 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4221 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4222 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4223 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4224 char_boundary = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4225 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4226 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4227 { /* Processing Non-ASCII character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4228 charmask = (half == 0 ? 0x7F : 0xFF);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4229 char_boundary = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4230 if (EQ (charset, Vcharset_control_1))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4231 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4232 if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4233 && fit_to_be_escape_quoted (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4234 Dynarr_add (dst, ISO_CODE_ESC);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4235 /* you asked for it ... */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4236 Dynarr_add (dst, c - 0x20);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4237 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4238 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4239 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4240 switch (XCHARSET_REP_BYTES (charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4241 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4242 case 2:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4243 Dynarr_add (dst, c & charmask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4244 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4245 case 3:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4246 if (XCHARSET_PRIVATE_P (charset))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4247 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4248 Dynarr_add (dst, c & charmask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4249 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4250 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4251 else if (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4252 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4253 if (EQ (charset, Vcharset_composite))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4254 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4255 if (in_composite)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4256 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4257 /* #### Bother! We don't know how to
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4258 handle this yet. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4259 Dynarr_add (dst, '~');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4260 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4261 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4262 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4263 Emchar emch = MAKE_CHAR (Vcharset_composite,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4264 ch & 0x7F, c & 0x7F);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4265 Lisp_Object lstr = composite_char_string (emch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4266 saved_n = n;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4267 saved_src = src;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4268 in_composite = 1;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4269 src = XSTRING_DATA (lstr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4270 n = XSTRING_LENGTH (lstr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4271 Dynarr_add (dst, ISO_CODE_ESC);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4272 Dynarr_add (dst, '0'); /* start composing */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4273 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4274 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4275 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4276 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4277 Dynarr_add (dst, ch & charmask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4278 Dynarr_add (dst, c & charmask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4279 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4280 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4281 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4282 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4283 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4284 ch = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4285 char_boundary = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4286 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4287 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4288 case 4:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4289 if (ch)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4290 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4291 Dynarr_add (dst, ch & charmask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4292 Dynarr_add (dst, c & charmask);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4293 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4294 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4295 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4296 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4297 ch = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4298 char_boundary = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4299 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4300 break;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4301 default:
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4302 abort ();
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4303 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4304 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4305 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4306 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4307
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4308 if (in_composite)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4309 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4310 n = saved_n;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4311 src = saved_src;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4312 in_composite = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4313 Dynarr_add (dst, ISO_CODE_ESC);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4314 Dynarr_add (dst, '1'); /* end composing */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4315 goto back_to_square_n; /* Wheeeeeeeee ..... */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4316 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4317
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4318 if (char_boundary && flags & CODING_STATE_END)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4319 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4320 restore_left_to_right_direction (codesys, dst, &flags, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4321 ensure_normal_shift (str, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4322 for (i = 0; i < 4; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4323 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4324 Lisp_Object initial_charset =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4325 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4326 iso2022_designate (initial_charset, i, str, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4327 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4328 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
4329
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4330 CODING_STREAM_COMPOSE (str, flags, ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4331 str->iso2022.current_char_boundary = char_boundary;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4332 str->iso2022.current_charset = charset;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4333 str->iso2022.current_half = half;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4334
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4335 /* Verbum caro factum est! */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4336 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4337
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4338
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4339 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4340 /* No-conversion methods */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4341 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4342
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4343 /* This is used when reading in "binary" files -- i.e. files that may
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4344 contain all 256 possible byte values and that are not to be
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4345 interpreted as being in any particular decoding. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4346 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4347 decode_coding_no_conversion (Lstream *decoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4348 unsigned_char_dynarr *dst, unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4349 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4350 unsigned char c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4351 unsigned int flags, ch;
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4352 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4353 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4354
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4355 CODING_STREAM_DECOMPOSE (str, flags, ch);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4356 eol_type = str->eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4357
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4358 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4359 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4360 c = *src++;
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
4361
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4362 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4363 DECODE_ADD_BINARY_CHAR (c, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4364 label_continue_loop:;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4365 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4366
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4367 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4368
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4369 CODING_STREAM_COMPOSE (str, flags, ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4370 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4371
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4372 static void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4373 encode_coding_no_conversion (Lstream *encoding, CONST unsigned char *src,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4374 unsigned_char_dynarr *dst, unsigned int n)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4375 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4376 unsigned char c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4377 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4378 unsigned int flags, ch;
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4379 enum eol_type eol_type;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4380
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4381 CODING_STREAM_DECOMPOSE (str, flags, ch);
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4382 eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4383
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4384 while (n--)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4385 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4386 c = *src++;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4387 if (c == '\n')
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4388 {
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4389 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4390 Dynarr_add (dst, '\r');
181
bfd6434d15b3 Import from CVS: tag r20-3b17
cvs
parents: 179
diff changeset
4391 if (eol_type != EOL_CR)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4392 Dynarr_add (dst, '\n');
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4393 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4394 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4395 else if (BYTE_ASCII_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4396 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4397 assert (ch == 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4398 Dynarr_add (dst, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4399 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4400 else if (BUFBYTE_LEADING_BYTE_P (c))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4401 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4402 assert (ch == 0);
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
4403 if (c == LEADING_BYTE_LATIN_ISO8859_1 ||
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
4404 c == LEADING_BYTE_CONTROL_1)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4405 ch = c;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4406 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4407 Dynarr_add (dst, '~'); /* untranslatable character */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4408 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4409 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4410 {
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
4411 if (ch == LEADING_BYTE_LATIN_ISO8859_1)
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4412 Dynarr_add (dst, c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4413 else if (ch == LEADING_BYTE_CONTROL_1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4414 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4415 assert (c < 0xC0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4416 Dynarr_add (dst, c - 0x20);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4417 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4418 /* else it should be the second or third byte of an
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4419 untranslatable character, so ignore it */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4420 ch = 0;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4421 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4422 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4423
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4424 CODING_STREAM_COMPOSE (str, flags, ch);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4425 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4426
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4427
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4428 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4429 /* Simple internal/external functions */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4430 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4431
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4432 static Extbyte_dynarr *conversion_out_dynarr;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4433 static Bufbyte_dynarr *conversion_in_dynarr;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4434
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4435 /* Determine coding system from coding format */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4436
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4437 #define FILE_NAME_CODING_SYSTEM \
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4438 ((NILP (Vfile_name_coding_system) || \
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4439 (EQ ((Vfile_name_coding_system), Qbinary))) ? \
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4440 Qnil : Fget_coding_system (Vfile_name_coding_system))
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
4441
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4442 /* #### not correct for all values of `fmt'! */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4443 #define FMT_CODING_SYSTEM(fmt) \
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4444 (((fmt) == FORMAT_FILENAME) ? FILE_NAME_CODING_SYSTEM : \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4445 ((fmt) == FORMAT_CTEXT ) ? Fget_coding_system (Qctext) : \
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4446 ((fmt) == FORMAT_TERMINAL) ? FILE_NAME_CODING_SYSTEM : \
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4447 Qnil)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4448
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4449 extern CONST Extbyte *
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4450 convert_to_external_format (CONST Bufbyte *ptr,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4451 Bytecount len,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4452 Extcount *len_out,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4453 enum external_data_format fmt)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4454 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4455 Lisp_Object coding_system = FMT_CODING_SYSTEM (fmt);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4456
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4457 if (!conversion_out_dynarr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4458 conversion_out_dynarr = Dynarr_new (Extbyte);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4459 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4460 Dynarr_reset (conversion_out_dynarr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4461
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4462 if (NILP (coding_system))
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
4463 {
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4464 CONST Bufbyte *end = ptr + len;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4465
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4466 for (; ptr < end;)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4467 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4468 Bufbyte c =
74
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
4469 (BYTE_ASCII_P (*ptr)) ? *ptr :
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
4470 (*ptr == LEADING_BYTE_CONTROL_1) ? (*(ptr+1) - 0x20) :
54cc21c15cbb Import from CVS: tag r20-0b32
cvs
parents: 70
diff changeset
4471 (*ptr == LEADING_BYTE_LATIN_ISO8859_1) ? (*(ptr+1)) :
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4472 '~';
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4473
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4474 Dynarr_add (conversion_out_dynarr, (Extbyte) c);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4475 INC_CHARPTR (ptr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4476 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
4477
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4478 #ifdef ERROR_CHECK_BUFPOS
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4479 assert (ptr == end);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4480 #endif
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4481 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4482 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4483 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4484 Lisp_Object instream, outstream, da_outstream;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4485 Lstream *istr, *ostr;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4486 struct gcpro gcpro1, gcpro2, gcpro3;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4487 char tempbuf[1024]; /* some random amount */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4488
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4489 instream = make_fixed_buffer_input_stream ((unsigned char *) ptr, len);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4490 da_outstream = make_dynarr_output_stream
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4491 ((unsigned_char_dynarr *) conversion_out_dynarr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4492 outstream =
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4493 make_encoding_output_stream (XLSTREAM (da_outstream), coding_system);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4494 istr = XLSTREAM (instream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4495 ostr = XLSTREAM (outstream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4496 GCPRO3 (instream, outstream, da_outstream);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4497 while (1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4498 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4499 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4500 if (!size_in_bytes)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4501 break;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4502 Lstream_write (ostr, tempbuf, size_in_bytes);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4503 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4504 Lstream_close (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4505 Lstream_close (ostr);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4506 UNGCPRO;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4507 Lstream_delete (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4508 Lstream_delete (ostr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4509 Lstream_delete (XLSTREAM (da_outstream));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4510 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4511
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4512 *len_out = Dynarr_length (conversion_out_dynarr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4513 Dynarr_add (conversion_out_dynarr, 0); /* remember to zero-terminate! */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4514 return Dynarr_atp (conversion_out_dynarr, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4515 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4516
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4517 extern CONST Bufbyte *
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4518 convert_from_external_format (CONST Extbyte *ptr,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4519 Extcount len,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4520 Bytecount *len_out,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4521 enum external_data_format fmt)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4522 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4523 Lisp_Object coding_system = FMT_CODING_SYSTEM (fmt);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
4524
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4525 if (!conversion_in_dynarr)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4526 conversion_in_dynarr = Dynarr_new (Bufbyte);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4527 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4528 Dynarr_reset (conversion_in_dynarr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4529
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4530 if (NILP (coding_system))
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4531 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4532 CONST Extbyte *end = ptr + len;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4533 for (; ptr < end; ptr++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4534 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4535 Extbyte c = *ptr;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4536 DECODE_ADD_BINARY_CHAR (c, conversion_in_dynarr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4537 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4538 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4539 else
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4540 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4541 Lisp_Object instream, outstream, da_outstream;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4542 Lstream *istr, *ostr;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4543 struct gcpro gcpro1, gcpro2, gcpro3;
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4544 char tempbuf[1024]; /* some random amount */
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4545
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4546 instream = make_fixed_buffer_input_stream ((unsigned char *) ptr, len);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4547 da_outstream = make_dynarr_output_stream
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4548 ((unsigned_char_dynarr *) conversion_in_dynarr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4549 outstream =
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4550 make_decoding_output_stream (XLSTREAM (da_outstream), coding_system);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4551 istr = XLSTREAM (instream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4552 ostr = XLSTREAM (outstream);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4553 GCPRO3 (instream, outstream, da_outstream);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4554 while (1)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4555 {
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4556 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4557 if (!size_in_bytes)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4558 break;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4559 Lstream_write (ostr, tempbuf, size_in_bytes);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4560 }
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4561 Lstream_close (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4562 Lstream_close (ostr);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4563 UNGCPRO;
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4564 Lstream_delete (istr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4565 Lstream_delete (ostr);
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4566 Lstream_delete (XLSTREAM (da_outstream));
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4567 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4568
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4569 *len_out = Dynarr_length (conversion_in_dynarr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4570 Dynarr_add (conversion_in_dynarr, 0); /* remember to zero-terminate! */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4571 return Dynarr_atp (conversion_in_dynarr, 0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4572 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4573
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4574
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4575 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4576 /* Initialization */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4577 /************************************************************************/
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4578
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4579 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4580 syms_of_mule_coding (void)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4581 {
110
fe104dbd9147 Import from CVS: tag r20-1b7
cvs
parents: 96
diff changeset
4582 defsymbol (&Qbuffer_file_coding_system, "buffer-file-coding-system");
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4583 deferror (&Qcoding_system_error, "coding-system-error",
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4584 "Coding-system error", Qio_error);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4585
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4586 DEFSUBR (Fcoding_system_p);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4587 DEFSUBR (Ffind_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4588 DEFSUBR (Fget_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4589 DEFSUBR (Fcoding_system_list);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4590 DEFSUBR (Fcoding_system_name);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4591 DEFSUBR (Fmake_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4592 DEFSUBR (Fcopy_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4593 DEFSUBR (Fsubsidiary_coding_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4594
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4595 DEFSUBR (Fcoding_system_type);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4596 DEFSUBR (Fcoding_system_doc_string);
207
e45d5e7c476e Import from CVS: tag r20-4b2
cvs
parents: 197
diff changeset
4597 DEFSUBR (Fcoding_system_charset);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4598 DEFSUBR (Fcoding_system_property);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4599
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4600 DEFSUBR (Fcoding_category_list);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4601 DEFSUBR (Fset_coding_priority_list);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4602 DEFSUBR (Fcoding_priority_list);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4603 DEFSUBR (Fset_coding_category_system);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4604 DEFSUBR (Fcoding_category_system);
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
4605
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4606 DEFSUBR (Fdetect_coding_region);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4607 DEFSUBR (Fdecode_coding_region);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4608 DEFSUBR (Fencode_coding_region);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4609 DEFSUBR (Fdecode_shift_jis_char);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4610 DEFSUBR (Fencode_shift_jis_char);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4611 DEFSUBR (Fdecode_big5_char);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4612 DEFSUBR (Fencode_big5_char);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4613
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4614 defsymbol (&Qcoding_system_p, "coding-system-p");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4615
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4616 defsymbol (&Qbig5, "big5");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4617 defsymbol (&Qshift_jis, "shift-jis");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4618 defsymbol (&Qno_conversion, "no-conversion");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4619 defsymbol (&Qccl, "ccl");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4620 defsymbol (&Qiso2022, "iso2022");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4621
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4622 defsymbol (&Qmnemonic, "mnemonic");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4623 defsymbol (&Qeol_type, "eol-type");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4624 defsymbol (&Qpost_read_conversion, "post-read-conversion");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4625 defsymbol (&Qpre_write_conversion, "pre-write-conversion");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4626
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4627 defsymbol (&Qcr, "cr");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4628 defsymbol (&Qlf, "lf");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4629 defsymbol (&Qcrlf, "crlf");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4630 defsymbol (&Qeol_cr, "eol-cr");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4631 defsymbol (&Qeol_lf, "eol-lf");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4632 defsymbol (&Qeol_crlf, "eol-crlf");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4633
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4634 defsymbol (&Qcharset_g0, "charset-g0");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4635 defsymbol (&Qcharset_g1, "charset-g1");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4636 defsymbol (&Qcharset_g2, "charset-g2");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4637 defsymbol (&Qcharset_g3, "charset-g3");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4638 defsymbol (&Qforce_g0_on_output, "force-g0-on-output");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4639 defsymbol (&Qforce_g1_on_output, "force-g1-on-output");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4640 defsymbol (&Qforce_g2_on_output, "force-g2-on-output");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4641 defsymbol (&Qforce_g3_on_output, "force-g3-on-output");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4642 defsymbol (&Qshort, "short");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4643 defsymbol (&Qno_ascii_eol, "no-ascii-eol");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4644 defsymbol (&Qno_ascii_cntl, "no-ascii-cntl");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4645 defsymbol (&Qseven, "seven");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4646 defsymbol (&Qlock_shift, "lock-shift");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4647 defsymbol (&Qno_iso6429, "no-iso6429");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4648 defsymbol (&Qescape_quoted, "escape-quoted");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4649 defsymbol (&Qinput_charset_conversion, "input-charset-conversion");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4650 defsymbol (&Qoutput_charset_conversion, "output-charset-conversion");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4651
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4652 defsymbol (&Qencode, "encode");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4653 defsymbol (&Qdecode, "decode");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4654
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4655 defsymbol (&Qctext, "ctext");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4656
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4657 defsymbol (&coding_category_symbol[CODING_CATEGORY_SHIFT_JIS],
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4658 "shift-jis");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4659 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_7],
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4660 "iso-7");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4661 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_DESIGNATE],
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4662 "iso-8-designate");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4663 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_1],
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4664 "iso-8-1");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4665 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_2],
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4666 "iso-8-2");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4667 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_LOCK_SHIFT],
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4668 "iso-lock-shift");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4669 defsymbol (&coding_category_symbol[CODING_CATEGORY_BIG5],
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4670 "big5");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4671 defsymbol (&coding_category_symbol[CODING_CATEGORY_NO_CONVERSION],
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4672 "no-conversion");
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4673 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4674
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4675 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4676 lstream_type_create_mule_coding (void)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4677 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4678 LSTREAM_HAS_METHOD (decoding, reader);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4679 LSTREAM_HAS_METHOD (decoding, writer);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4680 LSTREAM_HAS_METHOD (decoding, rewinder);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4681 LSTREAM_HAS_METHOD (decoding, seekable_p);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4682 LSTREAM_HAS_METHOD (decoding, flusher);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4683 LSTREAM_HAS_METHOD (decoding, closer);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4684 LSTREAM_HAS_METHOD (decoding, marker);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4685
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4686 LSTREAM_HAS_METHOD (encoding, reader);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4687 LSTREAM_HAS_METHOD (encoding, writer);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4688 LSTREAM_HAS_METHOD (encoding, rewinder);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4689 LSTREAM_HAS_METHOD (encoding, seekable_p);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4690 LSTREAM_HAS_METHOD (encoding, flusher);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4691 LSTREAM_HAS_METHOD (encoding, closer);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4692 LSTREAM_HAS_METHOD (encoding, marker);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4693 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4694
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4695 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4696 vars_of_mule_coding (void)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4697 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4698 int i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4699
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4700 /* Initialize to something reasonable ... */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4701 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4702 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4703 coding_category_system[i] = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4704 coding_category_by_priority[i] = i;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4705 }
183
e121b013d1f0 Import from CVS: tag r20-3b18
cvs
parents: 181
diff changeset
4706
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4707 DEFVAR_LISP ("keyboard-coding-system", &Vkeyboard_coding_system /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4708 Coding system used for TTY keyboard input.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4709 Not used under a windowing system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4710 */ );
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4711 Vkeyboard_coding_system = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4712
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4713 DEFVAR_LISP ("terminal-coding-system", &Vterminal_coding_system /*
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4714 Coding system used for TTY display output.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4715 Not used under a windowing system.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4716 */ );
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4717 Vterminal_coding_system = Qnil;
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4718
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4719 DEFVAR_LISP ("coding-system-for-read", &Vcoding_system_for_read /*
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4720 Overriding coding system used when writing a file or process.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4721 You should *bind* this, not set it. If this is non-nil, it specifies
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4722 the coding system that will be used when a file or process is read
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4723 in, and overrides `buffer-file-coding-system-for-read',
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4724 `insert-file-contents-pre-hook', etc. Use those variables instead of
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4725 this one for permanent changes to the environment.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4726 */ );
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4727 Vcoding_system_for_read = Qnil;
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4728
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4729 DEFVAR_LISP ("coding-system-for-write",
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4730 &Vcoding_system_for_write /*
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4731 Overriding coding system used when writing a file or process.
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4732 You should *bind* this, not set it. If this is non-nil, it specifies
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4733 the coding system that will be used when a file or process is wrote
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4734 in, and overrides `buffer-file-coding-system',
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4735 `write-region-pre-hook', etc. Use those variables instead of this one
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4736 for permanent changes to the environment.
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4737 */ );
120
cca96a509cfe Import from CVS: tag r20-1b12
cvs
parents: 114
diff changeset
4738 Vcoding_system_for_write = Qnil;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4739
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4740 DEFVAR_LISP ("file-name-coding-system", &Vfile_name_coding_system /*
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4741 Coding system used to convert pathnames when accessing files.
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4742 */ );
197
acd284d43ca1 Import from CVS: tag r20-3b25
cvs
parents: 185
diff changeset
4743 Vfile_name_coding_system = Qnil;
114
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
4744
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
4745 DEFVAR_BOOL ("enable-multibyte-characters", &enable_multibyte_characters /*
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
4746 Non-nil means the buffer contents are regarded as multi-byte form
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
4747 of characters, not a binary code. This affects the display, file I/O,
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
4748 and behaviors of various editing commands.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
4749
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
4750 Setting this to nil does not do anything.
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
4751 */ );
8619ce7e4c50 Import from CVS: tag r20-1b9
cvs
parents: 110
diff changeset
4752 enable_multibyte_characters = 1;
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4753 }
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4754
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4755 void
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4756 complex_vars_of_mule_coding (void)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4757 {
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4758 staticpro (&Vcoding_system_hashtable);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4759 Vcoding_system_hashtable = make_lisp_hashtable (50, HASHTABLE_NONWEAK,
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4760 HASHTABLE_EQ);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4761
185
3d6bfa290dbd Import from CVS: tag r20-3b19
cvs
parents: 183
diff changeset
4762 the_codesys_prop_dynarr = Dynarr_new (codesys_prop);
70
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4763
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4764 #define DEFINE_CODESYS_PROP(Prop_Type, Sym) do \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4765 { \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4766 struct codesys_prop csp; \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4767 csp.sym = (Sym); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4768 csp.prop_type = (Prop_Type); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4769 Dynarr_add (the_codesys_prop_dynarr, csp); \
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4770 } while (0)
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4771
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4772 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qmnemonic);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4773 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_type);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4774 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_cr);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4775 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_crlf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4776 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_lf);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4777 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qpost_read_conversion);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4778 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qpre_write_conversion);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4779
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4780 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g0);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4781 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g1);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4782 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g2);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4783 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g3);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4784 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g0_on_output);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4785 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g1_on_output);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4786 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g2_on_output);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4787 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g3_on_output);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4788 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qshort);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4789 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_ascii_eol);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4790 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_ascii_cntl);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4791 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qseven);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4792 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qlock_shift);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4793 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_iso6429);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4794 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qescape_quoted);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4795 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qinput_charset_conversion);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4796 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qoutput_charset_conversion);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4797
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4798 DEFINE_CODESYS_PROP (CODESYS_PROP_CCL, Qencode);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4799 DEFINE_CODESYS_PROP (CODESYS_PROP_CCL, Qdecode);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4800
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4801 /* Need to create this here or we're really screwed. */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4802 Fmake_coding_system (Qno_conversion, Qno_conversion, build_string ("No conversion"),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4803 list2 (Qmnemonic, build_string ("Noconv")));
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4804
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4805 Fcopy_coding_system (Fcoding_system_property (Qno_conversion, Qeol_lf),
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4806 Qbinary);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4807
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4808 /* Need this for bootstrapping */
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4809 coding_category_system[CODING_CATEGORY_NO_CONVERSION] =
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4810 Fget_coding_system (Qno_conversion);
131b0175ea99 Import from CVS: tag r20-0b30
cvs
parents:
diff changeset
4811 }