annotate src/file-coding.c @ 416:ebe98a74bd68 r21-2-16

Import from CVS: tag r21-2-16
author cvs
date Mon, 13 Aug 2007 11:22:23 +0200
parents da8ed4261e83
children e804706bfb8c
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1 /* Code conversion functions.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2 Copyright (C) 1991, 1995 Free Software Foundation, Inc.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5 This file is part of XEmacs.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
6
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
10 later version.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
11
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
15 for more details.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
16
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
21
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
22 /* Synched up with: Mule 2.3. Not in FSF. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
23
298
70ad99077275 Import from CVS: tag r21-0b47
cvs
parents: 272
diff changeset
24 /* Rewritten by Ben Wing <ben@xemacs.org>. */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
25
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
26 #include <config.h>
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
27 #include "lisp.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
28 #include "buffer.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
29 #include "elhash.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
30 #include "insdel.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
31 #include "lstream.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
32 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
33 #include "mule-ccl.h"
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
34 #include "chartab.h"
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
35 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
36 #include "file-coding.h"
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
37
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
38 Lisp_Object Qbuffer_file_coding_system, Qcoding_system_error;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
39
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
40 Lisp_Object Vkeyboard_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
41 Lisp_Object Vterminal_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
42 Lisp_Object Vcoding_system_for_read;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
43 Lisp_Object Vcoding_system_for_write;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
44 Lisp_Object Vfile_name_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
45
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
46 /* Table of symbols identifying each coding category. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
47 Lisp_Object coding_category_symbol[CODING_CATEGORY_LAST + 1];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
48
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
49 /* Coding system currently associated with each coding category. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
50 Lisp_Object coding_category_system[CODING_CATEGORY_LAST + 1];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
51
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
52 /* Table of all coding categories in decreasing order of priority.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
53 This describes a permutation of the possible coding categories. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
54 int coding_category_by_priority[CODING_CATEGORY_LAST + 1];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
55
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
56 Lisp_Object Qcoding_system_p;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
57
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
58 Lisp_Object Qraw_text, Qno_conversion, Qccl, Qiso2022;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
59 /* Qinternal in general.c */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
60
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
61 Lisp_Object Qmnemonic, Qeol_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
62 Lisp_Object Qcr, Qcrlf, Qlf;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
63 Lisp_Object Qeol_cr, Qeol_crlf, Qeol_lf;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
64 Lisp_Object Qpost_read_conversion;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
65 Lisp_Object Qpre_write_conversion;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
66
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
67 #ifdef MULE
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
68 Lisp_Object Qucs4, Qutf8;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
69 Lisp_Object Qbig5, Qshift_jis;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
70 Lisp_Object Qcharset_g0, Qcharset_g1, Qcharset_g2, Qcharset_g3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
71 Lisp_Object Qforce_g0_on_output, Qforce_g1_on_output;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
72 Lisp_Object Qforce_g2_on_output, Qforce_g3_on_output;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
73 Lisp_Object Qno_iso6429;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
74 Lisp_Object Qinput_charset_conversion, Qoutput_charset_conversion;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
75 Lisp_Object Qctext, Qescape_quoted;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
76 Lisp_Object Qshort, Qno_ascii_eol, Qno_ascii_cntl, Qseven, Qlock_shift;
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
77 #endif
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
78 Lisp_Object Qencode, Qdecode;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
79
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
80 Lisp_Object Vcoding_system_hash_table;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
81
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
82 int enable_multibyte_characters;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
83
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
84 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
85 /* Additional information used by the ISO2022 decoder and detector. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
86 struct iso2022_decoder
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
87 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
88 /* CHARSET holds the character sets currently assigned to the G0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
89 through G3 variables. It is initialized from the array
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
90 INITIAL_CHARSET in CODESYS. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
91 Lisp_Object charset[4];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
92
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
93 /* Which registers are currently invoked into the left (GL) and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
94 right (GR) halves of the 8-bit encoding space? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
95 int register_left, register_right;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
96
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
97 /* ISO_ESC holds a value indicating part of an escape sequence
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
98 that has already been seen. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
99 enum iso_esc_flag esc;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
100
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
101 /* This records the bytes we've seen so far in an escape sequence,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
102 in case the sequence is invalid (we spit out the bytes unchanged). */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
103 unsigned char esc_bytes[8];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
104
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
105 /* Index for next byte to store in ISO escape sequence. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
106 int esc_bytes_index;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
107
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
108 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
109 /* Stuff seen so far when composing a string. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
110 unsigned_char_dynarr *composite_chars;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
111 #endif
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
112
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
113 /* If we saw an invalid designation sequence for a particular
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
114 register, we flag it here and switch to ASCII. The next time we
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
115 see a valid designation for this register, we turn off the flag
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
116 and do the designation normally, but pretend the sequence was
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
117 invalid. The effect of all this is that (most of the time) the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
118 escape sequences for both the switch to the unknown charset, and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
119 the switch back to the known charset, get inserted literally into
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
120 the buffer and saved out as such. The hope is that we can
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
121 preserve the escape sequences so that the resulting written out
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
122 file makes sense. If we don't do any of this, the designation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
123 to the invalid charset will be preserved but that switch back
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
124 to the known charset will probably get eaten because it was
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
125 the same charset that was already present in the register. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
126 unsigned char invalid_designated[4];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
127
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
128 /* We try to do similar things as above for direction-switching
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
129 sequences. If we encountered a direction switch while an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
130 invalid designation was present, or an invalid designation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
131 just after a direction switch (i.e. no valid designation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
132 encountered yet), we insert the direction-switch escape
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
133 sequence literally into the output stream, and later on
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
134 insert the corresponding direction-restoring escape sequence
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
135 literally also. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
136 unsigned int switched_dir_and_no_valid_charset_yet :1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
137 unsigned int invalid_switch_dir :1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
138
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
139 /* Tells the decoder to output the escape sequence literally
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
140 even though it was valid. Used in the games we play to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
141 avoid lossage when we encounter invalid designations. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
142 unsigned int output_literally :1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
143 /* We encountered a direction switch followed by an invalid
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
144 designation. We didn't output the direction switch
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
145 literally because we didn't know about the invalid designation;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
146 but we have to do so now. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
147 unsigned int output_direction_sequence :1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
148 };
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
149 #endif /* MULE */
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
150 EXFUN (Fcopy_coding_system, 2);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
151 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
152 struct detection_state;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
153 static int detect_coding_sjis (struct detection_state *st,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
154 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
155 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
156 static void decode_coding_sjis (Lstream *decoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
157 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
158 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
159 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
160 static void encode_coding_sjis (Lstream *encoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
161 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
162 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
163 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
164 static int detect_coding_big5 (struct detection_state *st,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
165 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
166 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
167 static void decode_coding_big5 (Lstream *decoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
168 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
169 unsigned_char_dynarr *dst, unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
170 static void encode_coding_big5 (Lstream *encoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
171 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
172 unsigned_char_dynarr *dst, unsigned int n);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
173 static int detect_coding_ucs4 (struct detection_state *st,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
174 CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
175 unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
176 static void decode_coding_ucs4 (Lstream *decoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
177 CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
178 unsigned_char_dynarr *dst, unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
179 static void encode_coding_ucs4 (Lstream *encoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
180 CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
181 unsigned_char_dynarr *dst, unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
182 static int detect_coding_utf8 (struct detection_state *st,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
183 CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
184 unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
185 static void decode_coding_utf8 (Lstream *decoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
186 CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
187 unsigned_char_dynarr *dst, unsigned int n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
188 static void encode_coding_utf8 (Lstream *encoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
189 CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
190 unsigned_char_dynarr *dst, unsigned int n);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
191 static int postprocess_iso2022_mask (int mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
192 static void reset_iso2022 (Lisp_Object coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
193 struct iso2022_decoder *iso);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
194 static int detect_coding_iso2022 (struct detection_state *st,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
195 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
196 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
197 static void decode_coding_iso2022 (Lstream *decoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
198 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
199 unsigned_char_dynarr *dst, unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
200 static void encode_coding_iso2022 (Lstream *encoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
201 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
202 unsigned_char_dynarr *dst, unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
203 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
204 static void decode_coding_no_conversion (Lstream *decoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
205 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
206 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
207 unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
208 static void encode_coding_no_conversion (Lstream *encoding,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
209 CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
210 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
211 unsigned int n);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
212 static void mule_decode (Lstream *decoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
213 unsigned_char_dynarr *dst, unsigned int n);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
214 static void mule_encode (Lstream *encoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
215 unsigned_char_dynarr *dst, unsigned int n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
216
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
217 typedef struct codesys_prop codesys_prop;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
218 struct codesys_prop
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
219 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
220 Lisp_Object sym;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
221 int prop_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
222 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
223
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
224 typedef struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
225 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
226 Dynarr_declare (codesys_prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
227 } codesys_prop_dynarr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
228
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
229 codesys_prop_dynarr *the_codesys_prop_dynarr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
230
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
231 enum codesys_prop_enum
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
232 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
233 CODESYS_PROP_ALL_OK,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
234 CODESYS_PROP_ISO2022,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
235 CODESYS_PROP_CCL
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
236 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
237
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
238
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
239 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
240 /* Coding system functions */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
241 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
242
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
243 static Lisp_Object mark_coding_system (Lisp_Object, void (*) (Lisp_Object));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
244 static void print_coding_system (Lisp_Object, Lisp_Object, int);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
245 static void finalize_coding_system (void *header, int for_disksave);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
246
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
247 DEFINE_LRECORD_IMPLEMENTATION ("coding-system", coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
248 mark_coding_system, print_coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
249 finalize_coding_system,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
250 0, 0, struct Lisp_Coding_System);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
251
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
252 static Lisp_Object
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
253 mark_coding_system (Lisp_Object obj, void (*markobj) (Lisp_Object))
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
254 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
255 Lisp_Coding_System *codesys = XCODING_SYSTEM (obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
256
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
257 markobj (CODING_SYSTEM_NAME (codesys));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
258 markobj (CODING_SYSTEM_DOC_STRING (codesys));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
259 markobj (CODING_SYSTEM_MNEMONIC (codesys));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
260 markobj (CODING_SYSTEM_EOL_LF (codesys));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
261 markobj (CODING_SYSTEM_EOL_CRLF (codesys));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
262 markobj (CODING_SYSTEM_EOL_CR (codesys));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
263
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
264 switch (CODING_SYSTEM_TYPE (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
265 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
266 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
267 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
268 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
269 for (i = 0; i < 4; i++)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
270 markobj (CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
271 if (codesys->iso2022.input_conv)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
272 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
273 for (i = 0; i < Dynarr_length (codesys->iso2022.input_conv); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
274 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
275 struct charset_conversion_spec *ccs =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
276 Dynarr_atp (codesys->iso2022.input_conv, i);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
277 markobj (ccs->from_charset);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
278 markobj (ccs->to_charset);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
279 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
280 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
281 if (codesys->iso2022.output_conv)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
282 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
283 for (i = 0; i < Dynarr_length (codesys->iso2022.output_conv); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
284 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
285 struct charset_conversion_spec *ccs =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
286 Dynarr_atp (codesys->iso2022.output_conv, i);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
287 markobj (ccs->from_charset);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
288 markobj (ccs->to_charset);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
289 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
290 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
291 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
292
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
293 case CODESYS_CCL:
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
294 markobj (CODING_SYSTEM_CCL_DECODE (codesys));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
295 markobj (CODING_SYSTEM_CCL_ENCODE (codesys));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
296 break;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
297 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
298 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
299 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
300 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
301
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
302 markobj (CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
303 return CODING_SYSTEM_POST_READ_CONVERSION (codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
304 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
305
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
306 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
307 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
308 int escapeflag)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
309 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
310 Lisp_Coding_System *c = XCODING_SYSTEM (obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
311 if (print_readably)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
312 error ("printing unreadable object #<coding_system 0x%x>",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
313 c->header.uid);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
314
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
315 write_c_string ("#<coding_system ", printcharfun);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
316 print_internal (c->name, printcharfun, 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
317 write_c_string (">", printcharfun);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
318 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
319
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
320 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
321 finalize_coding_system (void *header, int for_disksave)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
322 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
323 Lisp_Coding_System *c = (Lisp_Coding_System *) header;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
324 /* Since coding systems never go away, this function is not
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
325 necessary. But it would be necessary if we changed things
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
326 so that coding systems could go away. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
327 if (!for_disksave) /* see comment in lstream.c */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
328 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
329 switch (CODING_SYSTEM_TYPE (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
330 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
331 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
332 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
333 if (c->iso2022.input_conv)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
334 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
335 Dynarr_free (c->iso2022.input_conv);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
336 c->iso2022.input_conv = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
337 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
338 if (c->iso2022.output_conv)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
339 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
340 Dynarr_free (c->iso2022.output_conv);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
341 c->iso2022.output_conv = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
342 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
343 break;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
344 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
345 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
346 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
347 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
348 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
349 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
350
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
351 static enum eol_type
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
352 symbol_to_eol_type (Lisp_Object symbol)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
353 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
354 CHECK_SYMBOL (symbol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
355 if (NILP (symbol)) return EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
356 if (EQ (symbol, Qlf)) return EOL_LF;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
357 if (EQ (symbol, Qcrlf)) return EOL_CRLF;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
358 if (EQ (symbol, Qcr)) return EOL_CR;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
359
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
360 signal_simple_error ("Unrecognized eol type", symbol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
361 return EOL_AUTODETECT; /* not reached */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
362 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
363
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
364 static Lisp_Object
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
365 eol_type_to_symbol (enum eol_type type)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
366 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
367 switch (type)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
368 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
369 default: abort ();
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
370 case EOL_LF: return Qlf;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
371 case EOL_CRLF: return Qcrlf;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
372 case EOL_CR: return Qcr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
373 case EOL_AUTODETECT: return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
374 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
375 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
376
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
377 static void
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
378 setup_eol_coding_systems (Lisp_Coding_System *codesys)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
379 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
380 Lisp_Object codesys_obj;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
381 int len = string_length (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
382 char *codesys_name = (char *) alloca (len + 7);
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
383 int mlen = -1;
265
8efd647ea9ca Import from CVS: tag r20-5b31
cvs
parents: 263
diff changeset
384 char *codesys_mnemonic=0;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
385
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
386 Lisp_Object codesys_name_sym, sub_codesys_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
387
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
388 /* kludge */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
389
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
390 XSETCODING_SYSTEM (codesys_obj, codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
391
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
392 memcpy (codesys_name,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
393 string_data (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name), len);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
394
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
395 if (STRINGP (CODING_SYSTEM_MNEMONIC (codesys)))
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
396 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
397 mlen = XSTRING_LENGTH (CODING_SYSTEM_MNEMONIC (codesys));
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
398 codesys_mnemonic = (char *) alloca (mlen + 7);
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
399 memcpy (codesys_mnemonic,
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
400 XSTRING_DATA (CODING_SYSTEM_MNEMONIC (codesys)), mlen);
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
401 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
402
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
403 #define DEFINE_SUB_CODESYS(op_sys, op_sys_abbr, Type) do { \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
404 strcpy (codesys_name + len, "-" op_sys); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
405 if (mlen != -1) \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
406 strcpy (codesys_mnemonic + mlen, op_sys_abbr); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
407 codesys_name_sym = intern (codesys_name); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
408 sub_codesys_obj = Fcopy_coding_system (codesys_obj, codesys_name_sym); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
409 XCODING_SYSTEM_EOL_TYPE (sub_codesys_obj) = Type; \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
410 if (mlen != -1) \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
411 XCODING_SYSTEM_MNEMONIC(sub_codesys_obj) = \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
412 build_string (codesys_mnemonic); \
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
413 CODING_SYSTEM_##Type (codesys) = sub_codesys_obj; \
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
414 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
415
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
416 DEFINE_SUB_CODESYS("unix", "", EOL_LF);
263
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
417 DEFINE_SUB_CODESYS("dos", ":T", EOL_CRLF);
727739f917cb Import from CVS: tag r20-5b30
cvs
parents: 261
diff changeset
418 DEFINE_SUB_CODESYS("mac", ":t", EOL_CR);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
419 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
420
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
421 DEFUN ("coding-system-p", Fcoding_system_p, 1, 1, 0, /*
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
422 Return t if OBJECT is a coding system.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
423 A coding system is an object that defines how text containing multiple
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
424 character sets is encoded into a stream of (typically 8-bit) bytes.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
425 The coding system is used to decode the stream into a series of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
426 characters (which may be from multiple charsets) when the text is read
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
427 from a file or process, and is used to encode the text back into the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
428 same format when it is written out to a file or process.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
429
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
430 For example, many ISO2022-compliant coding systems (such as Compound
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
431 Text, which is used for inter-client data under the X Window System)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
432 use escape sequences to switch between different charsets -- Japanese
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
433 Kanji, for example, is invoked with "ESC $ ( B"; ASCII is invoked
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
434 with "ESC ( B"; and Cyrillic is invoked with "ESC - L". See
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
435 `make-coding-system' for more information.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
436
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
437 Coding systems are normally identified using a symbol, and the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
438 symbol is accepted in place of the actual coding system object whenever
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
439 a coding system is called for. (This is similar to how faces work.)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
440 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
441 (object))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
442 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
443 return CODING_SYSTEMP (object) ? Qt : Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
444 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
445
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
446 DEFUN ("find-coding-system", Ffind_coding_system, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
447 Retrieve the coding system of the given name.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
448
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
449 If CODING-SYSTEM-OR-NAME is a coding-system object, it is simply
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
450 returned. Otherwise, CODING-SYSTEM-OR-NAME should be a symbol.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
451 If there is no such coding system, nil is returned. Otherwise the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
452 associated coding system object is returned.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
453 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
454 (coding_system_or_name))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
455 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
456 if (CODING_SYSTEMP (coding_system_or_name))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
457 return coding_system_or_name;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
458
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
459 if (NILP (coding_system_or_name))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
460 coding_system_or_name = Qbinary;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
461 else
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
462 CHECK_SYMBOL (coding_system_or_name);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
463
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
464 return Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
465 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
466
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
467 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
468 Retrieve the coding system of the given name.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
469 Same as `find-coding-system' except that if there is no such
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
470 coding system, an error is signaled instead of returning nil.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
471 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
472 (name))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
473 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
474 Lisp_Object coding_system = Ffind_coding_system (name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
475
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
476 if (NILP (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
477 signal_simple_error ("No such coding system", name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
478 return coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
479 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
480
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
481 /* We store the coding systems in hash tables with the names as the key and the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
482 actual coding system object as the value. Occasionally we need to use them
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
483 in a list format. These routines provide us with that. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
484 struct coding_system_list_closure
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
485 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
486 Lisp_Object *coding_system_list;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
487 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
488
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
489 static int
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
490 add_coding_system_to_list_mapper (Lisp_Object key, Lisp_Object value,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
491 void *coding_system_list_closure)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
492 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
493 /* This function can GC */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
494 struct coding_system_list_closure *cscl =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
495 (struct coding_system_list_closure *) coding_system_list_closure;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
496 Lisp_Object *coding_system_list = cscl->coding_system_list;
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
497
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
498 *coding_system_list = Fcons (XCODING_SYSTEM (value)->name,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
499 *coding_system_list);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
500 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
501 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
502
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
503 DEFUN ("coding-system-list", Fcoding_system_list, 0, 0, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
504 Return a list of the names of all defined coding systems.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
505 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
506 ())
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
507 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
508 Lisp_Object coding_system_list = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
509 struct gcpro gcpro1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
510 struct coding_system_list_closure coding_system_list_closure;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
511
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
512 GCPRO1 (coding_system_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
513 coding_system_list_closure.coding_system_list = &coding_system_list;
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
514 elisp_maphash (add_coding_system_to_list_mapper, Vcoding_system_hash_table,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
515 &coding_system_list_closure);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
516 UNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
517
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
518 return coding_system_list;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
519 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
520
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
521 DEFUN ("coding-system-name", Fcoding_system_name, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
522 Return the name of the given coding system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
523 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
524 (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
525 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
526 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
527 return XCODING_SYSTEM_NAME (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
528 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
529
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
530 static Lisp_Coding_System *
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
531 allocate_coding_system (enum coding_system_type type, Lisp_Object name)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
532 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
533 Lisp_Coding_System *codesys =
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
534 alloc_lcrecord_type (Lisp_Coding_System, &lrecord_coding_system);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
535
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
536 zero_lcrecord (codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
537 CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
538 CODING_SYSTEM_POST_READ_CONVERSION (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
539 CODING_SYSTEM_EOL_TYPE (codesys) = EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
540 CODING_SYSTEM_EOL_CRLF (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
541 CODING_SYSTEM_EOL_CR (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
542 CODING_SYSTEM_EOL_LF (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
543 CODING_SYSTEM_TYPE (codesys) = type;
261
405dd6d1825b Import from CVS: tag r20-5b29
cvs
parents: 259
diff changeset
544 CODING_SYSTEM_MNEMONIC (codesys) = Qnil;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
545 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
546 if (type == CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
547 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
548 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
549 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
550 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
551 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
552 else if (type == CODESYS_CCL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
553 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
554 CODING_SYSTEM_CCL_DECODE (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
555 CODING_SYSTEM_CCL_ENCODE (codesys) = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
556 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
557 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
558 CODING_SYSTEM_NAME (codesys) = name;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
559
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
560 return codesys;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
561 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
562
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
563 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
564 /* Given a list of charset conversion specs as specified in a Lisp
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
565 program, parse it into STORE_HERE. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
566
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
567 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
568 parse_charset_conversion_specs (charset_conversion_spec_dynarr *store_here,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
569 Lisp_Object spec_list)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
570 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
571 Lisp_Object rest;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
572
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
573 EXTERNAL_LIST_LOOP (rest, spec_list)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
574 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
575 Lisp_Object car = XCAR (rest);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
576 Lisp_Object from, to;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
577 struct charset_conversion_spec spec;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
578
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
579 if (!CONSP (car) || !CONSP (XCDR (car)) || !NILP (XCDR (XCDR (car))))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
580 signal_simple_error ("Invalid charset conversion spec", car);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
581 from = Fget_charset (XCAR (car));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
582 to = Fget_charset (XCAR (XCDR (car)));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
583 if (XCHARSET_TYPE (from) != XCHARSET_TYPE (to))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
584 signal_simple_error_2
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
585 ("Attempted conversion between different charset types",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
586 from, to);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
587 spec.from_charset = from;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
588 spec.to_charset = to;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
589
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
590 Dynarr_add (store_here, spec);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
591 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
592 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
593
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
594 /* Given a dynarr LOAD_HERE of internally-stored charset conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
595 specs, return the equivalent as the Lisp programmer would see it.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
596
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
597 If LOAD_HERE is 0, return Qnil. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
598
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
599 static Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
600 unparse_charset_conversion_specs (charset_conversion_spec_dynarr *load_here)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
601 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
602 int i;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
603 Lisp_Object result;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
604
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
605 if (!load_here)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
606 return Qnil;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
607 for (i = 0, result = Qnil; i < Dynarr_length (load_here); i++)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
608 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
609 struct charset_conversion_spec *ccs = Dynarr_atp (load_here, i);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
610 result = Fcons (list2 (ccs->from_charset, ccs->to_charset), result);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
611 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
612
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
613 return Fnreverse (result);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
614 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
615
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
616 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
617
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
618 DEFUN ("make-coding-system", Fmake_coding_system, 2, 4, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
619 Register symbol NAME as a coding system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
620
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
621 TYPE describes the conversion method used and should be one of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
622
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
623 nil or 'undecided
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
624 Automatic conversion. XEmacs attempts to detect the coding system
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
625 used in the file.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
626 'no-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
627 No conversion. Use this for binary files and such. On output,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
628 graphic characters that are not in ASCII or Latin-1 will be
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
629 replaced by a ?. (For a no-conversion-encoded buffer, these
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
630 characters will only be present if you explicitly insert them.)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
631 'shift-jis
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
632 Shift-JIS (a Japanese encoding commonly used in PC operating systems).
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
633 'ucs-4
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
634 ISO 10646 UCS-4 encoding.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
635 'utf-8
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
636 ISO 10646 UTF-8 encoding.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
637 'iso2022
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
638 Any ISO2022-compliant encoding. Among other things, this includes
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
639 JIS (the Japanese encoding commonly used for e-mail), EUC (the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
640 standard Unix encoding for Japanese and other languages), and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
641 Compound Text (the encoding used in X11). You can specify more
371
cc15677e0335 Import from CVS: tag r21-2b1
cvs
parents: 367
diff changeset
642 specific information about the conversion with the FLAGS argument.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
643 'big5
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
644 Big5 (the encoding commonly used for Taiwanese).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
645 'ccl
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
646 The conversion is performed using a user-written pseudo-code
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
647 program. CCL (Code Conversion Language) is the name of this
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
648 pseudo-code.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
649 'internal
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
650 Write out or read in the raw contents of the memory representing
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
651 the buffer's text. This is primarily useful for debugging
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
652 purposes, and is only enabled when XEmacs has been compiled with
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
653 DEBUG_XEMACS defined (via the --debug configure option).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
654 WARNING: Reading in a file using 'internal conversion can result
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
655 in an internal inconsistency in the memory representing a
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
656 buffer's text, which will produce unpredictable results and may
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
657 cause XEmacs to crash. Under normal circumstances you should
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
658 never use 'internal conversion.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
659
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
660 DOC-STRING is a string describing the coding system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
661
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
662 PROPS is a property list, describing the specific nature of the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
663 character set. Recognized properties are:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
664
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
665 'mnemonic
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
666 String to be displayed in the modeline when this coding system is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
667 active.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
668
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
669 'eol-type
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
670 End-of-line conversion to be used. It should be one of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
671
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
672 nil
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
673 Automatically detect the end-of-line type (LF, CRLF,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
674 or CR). Also generate subsidiary coding systems named
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
675 `NAME-unix', `NAME-dos', and `NAME-mac', that are
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
676 identical to this coding system but have an EOL-TYPE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
677 value of 'lf, 'crlf, and 'cr, respectively.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
678 'lf
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
679 The end of a line is marked externally using ASCII LF.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
680 Since this is also the way that XEmacs represents an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
681 end-of-line internally, specifying this option results
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
682 in no end-of-line conversion. This is the standard
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
683 format for Unix text files.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
684 'crlf
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
685 The end of a line is marked externally using ASCII
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
686 CRLF. This is the standard format for MS-DOS text
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
687 files.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
688 'cr
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
689 The end of a line is marked externally using ASCII CR.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
690 This is the standard format for Macintosh text files.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
691 t
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
692 Automatically detect the end-of-line type but do not
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
693 generate subsidiary coding systems. (This value is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
694 converted to nil when stored internally, and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
695 `coding-system-property' will return nil.)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
696
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
697 'post-read-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
698 Function called after a file has been read in, to perform the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
699 decoding. Called with two arguments, BEG and END, denoting
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
700 a region of the current buffer to be decoded.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
701
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
702 'pre-write-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
703 Function called before a file is written out, to perform the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
704 encoding. Called with two arguments, BEG and END, denoting
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
705 a region of the current buffer to be encoded.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
706
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
707
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
708 The following additional properties are recognized if TYPE is 'iso2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
709
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
710 'charset-g0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
711 'charset-g1
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
712 'charset-g2
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
713 'charset-g3
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
714 The character set initially designated to the G0 - G3 registers.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
715 The value should be one of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
716
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
717 -- A charset object (designate that character set)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
718 -- nil (do not ever use this register)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
719 -- t (no character set is initially designated to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
720 the register, but may be later on; this automatically
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
721 sets the corresponding `force-g*-on-output' property)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
722
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
723 'force-g0-on-output
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
724 'force-g1-on-output
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
725 'force-g2-on-output
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
726 'force-g2-on-output
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
727 If non-nil, send an explicit designation sequence on output before
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
728 using the specified register.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
729
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
730 'short
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
731 If non-nil, use the short forms "ESC $ @", "ESC $ A", and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
732 "ESC $ B" on output in place of the full designation sequences
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
733 "ESC $ ( @", "ESC $ ( A", and "ESC $ ( B".
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
734
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
735 'no-ascii-eol
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
736 If non-nil, don't designate ASCII to G0 at each end of line on output.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
737 Setting this to non-nil also suppresses other state-resetting that
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
738 normally happens at the end of a line.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
739
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
740 'no-ascii-cntl
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
741 If non-nil, don't designate ASCII to G0 before control chars on output.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
742
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
743 'seven
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
744 If non-nil, use 7-bit environment on output. Otherwise, use 8-bit
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
745 environment.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
746
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
747 'lock-shift
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
748 If non-nil, use locking-shift (SO/SI) instead of single-shift
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
749 or designation by escape sequence.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
750
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
751 'no-iso6429
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
752 If non-nil, don't use ISO6429's direction specification.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
753
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
754 'escape-quoted
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
755 If non-nil, literal control characters that are the same as
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
756 the beginning of a recognized ISO2022 or ISO6429 escape sequence
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
757 (in particular, ESC (0x1B), SO (0x0E), SI (0x0F), SS2 (0x8E),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
758 SS3 (0x8F), and CSI (0x9B)) are "quoted" with an escape character
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
759 so that they can be properly distinguished from an escape sequence.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
760 (Note that doing this results in a non-portable encoding.) This
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
761 encoding flag is used for byte-compiled files. Note that ESC
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
762 is a good choice for a quoting character because there are no
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
763 escape sequences whose second byte is a character from the Control-0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
764 or Control-1 character sets; this is explicitly disallowed by the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
765 ISO2022 standard.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
766
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
767 'input-charset-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
768 A list of conversion specifications, specifying conversion of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
769 characters in one charset to another when decoding is performed.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
770 Each specification is a list of two elements: the source charset,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
771 and the destination charset.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
772
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
773 'output-charset-conversion
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
774 A list of conversion specifications, specifying conversion of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
775 characters in one charset to another when encoding is performed.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
776 The form of each specification is the same as for
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
777 'input-charset-conversion.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
778
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
779
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
780 The following additional properties are recognized (and required)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
781 if TYPE is 'ccl:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
782
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
783 'decode
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
784 CCL program used for decoding (converting to internal format).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
785
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
786 'encode
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
787 CCL program used for encoding (converting to external format).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
788 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
789 (name, type, doc_string, props))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
790 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
791 Lisp_Coding_System *codesys;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
792 Lisp_Object rest, key, value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
793 enum coding_system_type ty;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
794 int need_to_setup_eol_systems = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
795
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
796 /* Convert type to constant */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
797 if (NILP (type) || EQ (type, Qundecided))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
798 { ty = CODESYS_AUTODETECT; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
799 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
800 else if (EQ (type, Qshift_jis)) { ty = CODESYS_SHIFT_JIS; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
801 else if (EQ (type, Qiso2022)) { ty = CODESYS_ISO2022; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
802 else if (EQ (type, Qbig5)) { ty = CODESYS_BIG5; }
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
803 else if (EQ (type, Qucs4)) { ty = CODESYS_UCS4; }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
804 else if (EQ (type, Qutf8)) { ty = CODESYS_UTF8; }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
805 else if (EQ (type, Qccl)) { ty = CODESYS_CCL; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
806 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
807 else if (EQ (type, Qno_conversion)) { ty = CODESYS_NO_CONVERSION; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
808 #ifdef DEBUG_XEMACS
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
809 else if (EQ (type, Qinternal)) { ty = CODESYS_INTERNAL; }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
810 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
811 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
812 signal_simple_error ("Invalid coding system type", type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
813
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
814 CHECK_SYMBOL (name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
815
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
816 codesys = allocate_coding_system (ty, name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
817
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
818 if (NILP (doc_string))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
819 doc_string = build_string ("");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
820 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
821 CHECK_STRING (doc_string);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
822 CODING_SYSTEM_DOC_STRING (codesys) = doc_string;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
823
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
824 EXTERNAL_PROPERTY_LIST_LOOP (rest, key, value, props)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
825 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
826 if (EQ (key, Qmnemonic))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
827 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
828 if (!NILP (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
829 CHECK_STRING (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
830 CODING_SYSTEM_MNEMONIC (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
831 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
832
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
833 else if (EQ (key, Qeol_type))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
834 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
835 need_to_setup_eol_systems = NILP (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
836 if (EQ (value, Qt))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
837 value = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
838 CODING_SYSTEM_EOL_TYPE (codesys) = symbol_to_eol_type (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
839 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
840
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
841 else if (EQ (key, Qpost_read_conversion)) CODING_SYSTEM_POST_READ_CONVERSION (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
842 else if (EQ (key, Qpre_write_conversion)) CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
843 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
844 else if (ty == CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
845 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
846 #define FROB_INITIAL_CHARSET(charset_num) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
847 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, charset_num) = \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
848 ((EQ (value, Qt) || EQ (value, Qnil)) ? value : Fget_charset (value))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
849
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
850 if (EQ (key, Qcharset_g0)) FROB_INITIAL_CHARSET (0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
851 else if (EQ (key, Qcharset_g1)) FROB_INITIAL_CHARSET (1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
852 else if (EQ (key, Qcharset_g2)) FROB_INITIAL_CHARSET (2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
853 else if (EQ (key, Qcharset_g3)) FROB_INITIAL_CHARSET (3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
854
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
855 #define FROB_FORCE_CHARSET(charset_num) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
856 CODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT (codesys, charset_num) = !NILP (value)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
857
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
858 else if (EQ (key, Qforce_g0_on_output)) FROB_FORCE_CHARSET (0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
859 else if (EQ (key, Qforce_g1_on_output)) FROB_FORCE_CHARSET (1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
860 else if (EQ (key, Qforce_g2_on_output)) FROB_FORCE_CHARSET (2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
861 else if (EQ (key, Qforce_g3_on_output)) FROB_FORCE_CHARSET (3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
862
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
863 #define FROB_BOOLEAN_PROPERTY(prop) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
864 CODING_SYSTEM_ISO2022_##prop (codesys) = !NILP (value)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
865
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
866 else if (EQ (key, Qshort)) FROB_BOOLEAN_PROPERTY (SHORT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
867 else if (EQ (key, Qno_ascii_eol)) FROB_BOOLEAN_PROPERTY (NO_ASCII_EOL);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
868 else if (EQ (key, Qno_ascii_cntl)) FROB_BOOLEAN_PROPERTY (NO_ASCII_CNTL);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
869 else if (EQ (key, Qseven)) FROB_BOOLEAN_PROPERTY (SEVEN);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
870 else if (EQ (key, Qlock_shift)) FROB_BOOLEAN_PROPERTY (LOCK_SHIFT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
871 else if (EQ (key, Qno_iso6429)) FROB_BOOLEAN_PROPERTY (NO_ISO6429);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
872 else if (EQ (key, Qescape_quoted)) FROB_BOOLEAN_PROPERTY (ESCAPE_QUOTED);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
873
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
874 else if (EQ (key, Qinput_charset_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
875 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
876 codesys->iso2022.input_conv =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
877 Dynarr_new (charset_conversion_spec);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
878 parse_charset_conversion_specs (codesys->iso2022.input_conv,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
879 value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
880 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
881 else if (EQ (key, Qoutput_charset_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
882 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
883 codesys->iso2022.output_conv =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
884 Dynarr_new (charset_conversion_spec);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
885 parse_charset_conversion_specs (codesys->iso2022.output_conv,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
886 value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
887 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
888 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
889 signal_simple_error ("Unrecognized property", key);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
890 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
891 else if (EQ (type, Qccl))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
892 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
893 if (EQ (key, Qdecode))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
894 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
895 CHECK_VECTOR (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
896 CODING_SYSTEM_CCL_DECODE (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
897 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
898 else if (EQ (key, Qencode))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
899 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
900 CHECK_VECTOR (value);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
901 CODING_SYSTEM_CCL_ENCODE (codesys) = value;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
902 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
903 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
904 signal_simple_error ("Unrecognized property", key);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
905 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
906 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
907 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
908 signal_simple_error ("Unrecognized property", key);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
909 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
910
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
911 if (need_to_setup_eol_systems)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
912 setup_eol_coding_systems (codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
913
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
914 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
915 Lisp_Object codesys_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
916 XSETCODING_SYSTEM (codesys_obj, codesys);
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
917 Fputhash (name, codesys_obj, Vcoding_system_hash_table);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
918 return codesys_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
919 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
920 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
921
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
922 DEFUN ("copy-coding-system", Fcopy_coding_system, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
923 Copy OLD-CODING-SYSTEM to NEW-NAME.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
924 If NEW-NAME does not name an existing coding system, a new one will
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
925 be created.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
926 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
927 (old_coding_system, new_name))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
928 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
929 Lisp_Object new_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
930 old_coding_system = Fget_coding_system (old_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
931 new_coding_system = Ffind_coding_system (new_name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
932 if (NILP (new_coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
933 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
934 XSETCODING_SYSTEM (new_coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
935 allocate_coding_system
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
936 (XCODING_SYSTEM_TYPE (old_coding_system),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
937 new_name));
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
938 Fputhash (new_name, new_coding_system, Vcoding_system_hash_table);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
939 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
940
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
941 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
942 Lisp_Coding_System *to = XCODING_SYSTEM (new_coding_system);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
943 Lisp_Coding_System *from = XCODING_SYSTEM (old_coding_system);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
944 memcpy (((char *) to ) + sizeof (to->header),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
945 ((char *) from) + sizeof (from->header),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
946 sizeof (*from) - sizeof (from->header));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
947 to->name = new_name;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
948 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
949 return new_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
950 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
951
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
952 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, 2, 2, 0, /*
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
953 Define symbol ALIAS as an alias for coding system CODING-SYSTEM.
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
954 */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
955 (alias, coding_system))
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
956 {
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
957 CHECK_SYMBOL (alias);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
958 if (!NILP (Ffind_coding_system (alias)))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
959 signal_simple_error ("Symbol already names a coding system", alias);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
960 coding_system = Fget_coding_system (coding_system);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
961 Fputhash (alias, coding_system, Vcoding_system_hash_table);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
962
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
963 /* Set up aliases for subsidiaries. */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
964 if (XCODING_SYSTEM_EOL_TYPE (coding_system) == EOL_AUTODETECT)
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
965 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
966 Lisp_Object str;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
967 XSETSTRING (str, symbol_name (XSYMBOL (alias)));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
968 #define FROB(type, name) \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
969 do { \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
970 Lisp_Object subsidiary = XCODING_SYSTEM_EOL_##type (coding_system); \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
971 if (!NILP (subsidiary)) \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
972 Fdefine_coding_system_alias \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
973 (Fintern (concat2 (str, build_string (name)), Qnil), subsidiary); \
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
974 } while (0)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
975 FROB (LF, "-unix");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
976 FROB (CRLF, "-dos");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
977 FROB (CR, "-mac");
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
978 #undef FROB
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
979 }
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
980 /* FSF return value is a vector of [ALIAS-unix ALIAS-doc ALIAS-mac],
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
981 but it doesn't look intentional, so I'd rather return something
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
982 meaningful or nothing at all. */
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
983 return Qnil;
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
984 }
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
985
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
986 static Lisp_Object
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
987 subsidiary_coding_system (Lisp_Object coding_system, enum eol_type type)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
988 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
989 Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
990 Lisp_Object new_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
991
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
992 if (CODING_SYSTEM_EOL_TYPE (cs) != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
993 return coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
994
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
995 switch (type)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
996 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
997 case EOL_AUTODETECT: return coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
998 case EOL_LF: new_coding_system = CODING_SYSTEM_EOL_LF (cs); break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
999 case EOL_CR: new_coding_system = CODING_SYSTEM_EOL_CR (cs); break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1000 case EOL_CRLF: new_coding_system = CODING_SYSTEM_EOL_CRLF (cs); break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1001 default: abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1002 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1003
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1004 return NILP (new_coding_system) ? coding_system : new_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1005 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1006
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1007 DEFUN ("subsidiary-coding-system", Fsubsidiary_coding_system, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1008 Return the subsidiary coding system of CODING-SYSTEM with eol type EOL-TYPE.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1009 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1010 (coding_system, eol_type))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1011 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1012 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1013
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1014 return subsidiary_coding_system (coding_system,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1015 symbol_to_eol_type (eol_type));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1016 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1017
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1018
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1019 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1020 /* Coding system accessors */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1021 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1022
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1023 DEFUN ("coding-system-doc-string", Fcoding_system_doc_string, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1024 Return the doc string for CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1025 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1026 (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1027 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1028 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1029 return XCODING_SYSTEM_DOC_STRING (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1030 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1031
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1032 DEFUN ("coding-system-type", Fcoding_system_type, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1033 Return the type of CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1034 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1035 (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1036 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1037 switch (XCODING_SYSTEM_TYPE (Fget_coding_system (coding_system)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1038 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
1039 default: abort ();
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1040 case CODESYS_AUTODETECT: return Qundecided;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1041 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1042 case CODESYS_SHIFT_JIS: return Qshift_jis;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1043 case CODESYS_ISO2022: return Qiso2022;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1044 case CODESYS_BIG5: return Qbig5;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1045 case CODESYS_UCS4: return Qucs4;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1046 case CODESYS_UTF8: return Qutf8;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1047 case CODESYS_CCL: return Qccl;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1048 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1049 case CODESYS_NO_CONVERSION: return Qno_conversion;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1050 #ifdef DEBUG_XEMACS
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1051 case CODESYS_INTERNAL: return Qinternal;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1052 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1053 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1054 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1055
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1056 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1057 static
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1058 Lisp_Object coding_system_charset (Lisp_Object coding_system, int gnum)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1059 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1060 Lisp_Object cs
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1061 = XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, gnum);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1062
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1063 return CHARSETP (cs) ? XCHARSET_NAME (cs) : Qnil;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1064 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1065
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1066 DEFUN ("coding-system-charset", Fcoding_system_charset, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1067 Return initial charset of CODING-SYSTEM designated to GNUM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1068 GNUM allows 0 .. 3.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1069 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1070 (coding_system, gnum))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1071 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1072 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1073 CHECK_INT (gnum);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1074
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1075 return coding_system_charset (coding_system, XINT (gnum));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1076 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1077 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1078
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1079 DEFUN ("coding-system-property", Fcoding_system_property, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1080 Return the PROP property of CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1081 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1082 (coding_system, prop))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1083 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1084 int i, ok = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1085 enum coding_system_type type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1086
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1087 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1088 CHECK_SYMBOL (prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1089 type = XCODING_SYSTEM_TYPE (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1090
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1091 for (i = 0; !ok && i < Dynarr_length (the_codesys_prop_dynarr); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1092 if (EQ (Dynarr_at (the_codesys_prop_dynarr, i).sym, prop))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1093 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1094 ok = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1095 switch (Dynarr_at (the_codesys_prop_dynarr, i).prop_type)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1096 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1097 case CODESYS_PROP_ALL_OK:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1098 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1099 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1100 case CODESYS_PROP_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1101 if (type != CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1102 signal_simple_error
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1103 ("Property only valid in ISO2022 coding systems",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1104 prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1105 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1106
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1107 case CODESYS_PROP_CCL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1108 if (type != CODESYS_CCL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1109 signal_simple_error
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1110 ("Property only valid in CCL coding systems",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1111 prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1112 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1113 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1114 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1115 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1116 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1117 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1118
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1119 if (!ok)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1120 signal_simple_error ("Unrecognized property", prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1121
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1122 if (EQ (prop, Qname))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1123 return XCODING_SYSTEM_NAME (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1124 else if (EQ (prop, Qtype))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1125 return Fcoding_system_type (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1126 else if (EQ (prop, Qdoc_string))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1127 return XCODING_SYSTEM_DOC_STRING (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1128 else if (EQ (prop, Qmnemonic))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1129 return XCODING_SYSTEM_MNEMONIC (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1130 else if (EQ (prop, Qeol_type))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1131 return eol_type_to_symbol (XCODING_SYSTEM_EOL_TYPE (coding_system));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1132 else if (EQ (prop, Qeol_lf))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1133 return XCODING_SYSTEM_EOL_LF (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1134 else if (EQ (prop, Qeol_crlf))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1135 return XCODING_SYSTEM_EOL_CRLF (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1136 else if (EQ (prop, Qeol_cr))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1137 return XCODING_SYSTEM_EOL_CR (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1138 else if (EQ (prop, Qpost_read_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1139 return XCODING_SYSTEM_POST_READ_CONVERSION (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1140 else if (EQ (prop, Qpre_write_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1141 return XCODING_SYSTEM_PRE_WRITE_CONVERSION (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1142 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1143 else if (type == CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1144 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1145 if (EQ (prop, Qcharset_g0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1146 return coding_system_charset (coding_system, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1147 else if (EQ (prop, Qcharset_g1))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1148 return coding_system_charset (coding_system, 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1149 else if (EQ (prop, Qcharset_g2))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1150 return coding_system_charset (coding_system, 2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1151 else if (EQ (prop, Qcharset_g3))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1152 return coding_system_charset (coding_system, 3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1153
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1154 #define FORCE_CHARSET(charset_num) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1155 (XCODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1156 (coding_system, charset_num) ? Qt : Qnil)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1157
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1158 else if (EQ (prop, Qforce_g0_on_output)) return FORCE_CHARSET (0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1159 else if (EQ (prop, Qforce_g1_on_output)) return FORCE_CHARSET (1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1160 else if (EQ (prop, Qforce_g2_on_output)) return FORCE_CHARSET (2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1161 else if (EQ (prop, Qforce_g3_on_output)) return FORCE_CHARSET (3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1162
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1163 #define LISP_BOOLEAN(prop) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1164 (XCODING_SYSTEM_ISO2022_##prop (coding_system) ? Qt : Qnil)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1165
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1166 else if (EQ (prop, Qshort)) return LISP_BOOLEAN (SHORT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1167 else if (EQ (prop, Qno_ascii_eol)) return LISP_BOOLEAN (NO_ASCII_EOL);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1168 else if (EQ (prop, Qno_ascii_cntl)) return LISP_BOOLEAN (NO_ASCII_CNTL);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1169 else if (EQ (prop, Qseven)) return LISP_BOOLEAN (SEVEN);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1170 else if (EQ (prop, Qlock_shift)) return LISP_BOOLEAN (LOCK_SHIFT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1171 else if (EQ (prop, Qno_iso6429)) return LISP_BOOLEAN (NO_ISO6429);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1172 else if (EQ (prop, Qescape_quoted)) return LISP_BOOLEAN (ESCAPE_QUOTED);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1173
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1174 else if (EQ (prop, Qinput_charset_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1175 return
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1176 unparse_charset_conversion_specs
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1177 (XCODING_SYSTEM (coding_system)->iso2022.input_conv);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1178 else if (EQ (prop, Qoutput_charset_conversion))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1179 return
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1180 unparse_charset_conversion_specs
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1181 (XCODING_SYSTEM (coding_system)->iso2022.output_conv);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1182 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1183 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1184 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1185 else if (type == CODESYS_CCL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1186 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1187 if (EQ (prop, Qdecode))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1188 return XCODING_SYSTEM_CCL_DECODE (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1189 else if (EQ (prop, Qencode))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1190 return XCODING_SYSTEM_CCL_ENCODE (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1191 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1192 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1193 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1194 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1195 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1196 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1197
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1198 return Qnil; /* not reached */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1199 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1200
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1201
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1202 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1203 /* Coding category functions */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1204 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1205
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1206 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1207 decode_coding_category (Lisp_Object symbol)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1208 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1209 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1210
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1211 CHECK_SYMBOL (symbol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1212 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1213 if (EQ (coding_category_symbol[i], symbol))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1214 return i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1215
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1216 signal_simple_error ("Unrecognized coding category", symbol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1217 return 0; /* not reached */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1218 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1219
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1220 DEFUN ("coding-category-list", Fcoding_category_list, 0, 0, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1221 Return a list of all recognized coding categories.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1222 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1223 ())
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1224 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1225 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1226 Lisp_Object list = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1227
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1228 for (i = CODING_CATEGORY_LAST; i >= 0; i--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1229 list = Fcons (coding_category_symbol[i], list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1230 return list;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1231 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1232
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1233 DEFUN ("set-coding-priority-list", Fset_coding_priority_list, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1234 Change the priority order of the coding categories.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1235 LIST should be list of coding categories, in descending order of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1236 priority. Unspecified coding categories will be lower in priority
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1237 than all specified ones, in the same relative order they were in
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1238 previously.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1239 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1240 (list))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1241 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1242 int category_to_priority[CODING_CATEGORY_LAST + 1];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1243 int i, j;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1244 Lisp_Object rest;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1245
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1246 /* First generate a list that maps coding categories to priorities. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1247
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1248 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1249 category_to_priority[i] = -1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1250
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1251 /* Highest priority comes from the specified list. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1252 i = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1253 EXTERNAL_LIST_LOOP (rest, list)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1254 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1255 int cat = decode_coding_category (XCAR (rest));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1256
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1257 if (category_to_priority[cat] >= 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1258 signal_simple_error ("Duplicate coding category in list", XCAR (rest));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1259 category_to_priority[cat] = i++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1260 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1261
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1262 /* Now go through the existing categories by priority to retrieve
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1263 the categories not yet specified and preserve their priority
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1264 order. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1265 for (j = 0; j <= CODING_CATEGORY_LAST; j++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1266 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1267 int cat = coding_category_by_priority[j];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1268 if (category_to_priority[cat] < 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1269 category_to_priority[cat] = i++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1270 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1271
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1272 /* Now we need to construct the inverse of the mapping we just
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1273 constructed. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1274
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1275 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1276 coding_category_by_priority[category_to_priority[i]] = i;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1277
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1278 /* Phew! That was confusing. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1279 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1280 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1281
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1282 DEFUN ("coding-priority-list", Fcoding_priority_list, 0, 0, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1283 Return a list of coding categories in descending order of priority.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1284 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1285 ())
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1286 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1287 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1288 Lisp_Object list = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1289
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1290 for (i = CODING_CATEGORY_LAST; i >= 0; i--)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1291 list = Fcons (coding_category_symbol[coding_category_by_priority[i]],
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1292 list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1293 return list;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1294 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1295
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1296 DEFUN ("set-coding-category-system", Fset_coding_category_system, 2, 2, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1297 Change the coding system associated with a coding category.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1298 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1299 (coding_category, coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1300 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1301 int cat = decode_coding_category (coding_category);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1302
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1303 coding_system = Fget_coding_system (coding_system);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1304 coding_category_system[cat] = coding_system;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1305 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1306 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1307
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1308 DEFUN ("coding-category-system", Fcoding_category_system, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1309 Return the coding system associated with a coding category.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1310 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1311 (coding_category))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1312 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1313 int cat = decode_coding_category (coding_category);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1314 Lisp_Object sys = coding_category_system[cat];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1315
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1316 if (!NILP (sys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1317 return XCODING_SYSTEM_NAME (sys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1318 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1319 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1320
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1321
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1322 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1323 /* Detecting the encoding of data */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1324 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1325
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1326 struct detection_state
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1327 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1328 enum eol_type eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1329 int seen_non_ascii;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1330 int mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1331 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1332 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1333 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1334 int mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1335 int in_second_byte;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1336 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1337 big5;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1338
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1339 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1340 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1341 int mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1342 int in_second_byte;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1343 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1344 shift_jis;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1345
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1346 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1347 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1348 int mask;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1349 int in_byte;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1350 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1351 ucs4;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1352
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1353 struct
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1354 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1355 int mask;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1356 int in_byte;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1357 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1358 utf8;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1359
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1360 struct
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1361 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1362 int mask;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1363 int initted;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1364 struct iso2022_decoder iso;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1365 unsigned int flags;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1366 int high_byte_count;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1367 unsigned int saw_single_shift:1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1368 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1369 iso2022;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1370 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1371 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1372 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1373 int seen_anything;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1374 int just_saw_cr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1375 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1376 eol;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1377 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1378
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1379 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1380 acceptable_control_char_p (int c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1381 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1382 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1383 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1384 /* Allow and ignore control characters that you might
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1385 reasonably see in a text file */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1386 case '\r':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1387 case '\n':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1388 case '\t':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1389 case 7: /* bell */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1390 case 8: /* backspace */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1391 case 11: /* vertical tab */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1392 case 12: /* form feed */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1393 case 26: /* MS-DOS C-z junk */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1394 case 31: /* '^_' -- for info */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1395 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1396 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1397 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1398 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1399 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1400
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1401 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1402 mask_has_at_most_one_bit_p (int mask)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1403 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1404 /* Perhaps the only thing useful you learn from intensive Microsoft
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1405 technical interviews */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1406 return (mask & (mask - 1)) == 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1407 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1408
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1409 static enum eol_type
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1410 detect_eol_type (struct detection_state *st, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1411 unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1412 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1413 int c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1414
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1415 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1416 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1417 c = *src++;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1418 if (c == '\r')
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1419 st->eol.just_saw_cr = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1420 else
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1421 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1422 if (c == '\n')
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1423 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1424 if (st->eol.just_saw_cr)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1425 return EOL_CRLF;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1426 else if (st->eol.seen_anything)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1427 return EOL_LF;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1428 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1429 else if (st->eol.just_saw_cr)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1430 return EOL_CR;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1431 st->eol.just_saw_cr = 0;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1432 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1433 st->eol.seen_anything = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1434 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1435
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1436 return EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1437 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1438
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1439 /* Attempt to determine the encoding and EOL type of the given text.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1440 Before calling this function for the first type, you must initialize
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1441 st->eol_type as appropriate and initialize st->mask to ~0.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1442
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1443 st->eol_type holds the determined EOL type, or EOL_AUTODETECT if
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1444 not yet known.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1445
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1446 st->mask holds the determined coding category mask, or ~0 if only
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1447 ASCII has been seen so far.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1448
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1449 Returns:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1450
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1451 0 == st->eol_type is EOL_AUTODETECT and/or more than coding category
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1452 is present in st->mask
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1453 1 == definitive answers are here for both st->eol_type and st->mask
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1454 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1455
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1456 static int
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1457 detect_coding_type (struct detection_state *st, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1458 unsigned int n, int just_do_eol)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1459 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1460 int c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1461
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1462 if (st->eol_type == EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1463 st->eol_type = detect_eol_type (st, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1464
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1465 if (just_do_eol)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1466 return st->eol_type != EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1467
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1468 if (!st->seen_non_ascii)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1469 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1470 for (; n; n--, src++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1471 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1472 c = *src;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1473 if ((c < 0x20 && !acceptable_control_char_p (c)) || c >= 0x80)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1474 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1475 st->seen_non_ascii = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1476 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1477 st->shift_jis.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1478 st->big5.mask = ~0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1479 st->ucs4.mask = ~0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1480 st->utf8.mask = ~0;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1481 st->iso2022.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1482 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1483 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1484 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1485 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1486 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1487
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1488 if (!n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1489 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1490 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1491 if (!mask_has_at_most_one_bit_p (st->iso2022.mask))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1492 st->iso2022.mask = detect_coding_iso2022 (st, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1493 if (!mask_has_at_most_one_bit_p (st->shift_jis.mask))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1494 st->shift_jis.mask = detect_coding_sjis (st, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1495 if (!mask_has_at_most_one_bit_p (st->big5.mask))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1496 st->big5.mask = detect_coding_big5 (st, src, n);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1497 if (!mask_has_at_most_one_bit_p (st->utf8.mask))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1498 st->utf8.mask = detect_coding_utf8 (st, src, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1499 if (!mask_has_at_most_one_bit_p (st->ucs4.mask))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1500 st->ucs4.mask = detect_coding_ucs4 (st, src, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1501
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1502 st->mask
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1503 = st->iso2022.mask | st->shift_jis.mask | st->big5.mask
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1504 | st->utf8.mask | st->ucs4.mask;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1505 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1506 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1507 int retval = mask_has_at_most_one_bit_p (st->mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1508 st->mask |= CODING_CATEGORY_NO_CONVERSION_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1509 return retval && st->eol_type != EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1510 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1511 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1512
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1513 static Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1514 coding_system_from_mask (int mask)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1515 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1516 if (mask == ~0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1517 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1518 /* If the file was entirely or basically ASCII, use the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1519 default value of `buffer-file-coding-system'. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1520 Lisp_Object retval =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1521 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1522 if (!NILP (retval))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1523 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1524 retval = Ffind_coding_system (retval);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1525 if (NILP (retval))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1526 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1527 warn_when_safe
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1528 (Qbad_variable, Qwarning,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1529 "Invalid `default-buffer-file-coding-system', set to nil");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1530 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1531 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1532 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1533 if (NILP (retval))
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
1534 retval = Fget_coding_system (Qraw_text);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1535 return retval;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1536 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1537 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1538 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1539 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1540 int cat = -1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1541 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1542 mask = postprocess_iso2022_mask (mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1543 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1544 /* Look through the coding categories by priority and find
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1545 the first one that is allowed. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1546 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1547 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1548 cat = coding_category_by_priority[i];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1549 if ((mask & (1 << cat)) &&
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1550 !NILP (coding_category_system[cat]))
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1551 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1552 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1553 if (cat >= 0)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1554 return coding_category_system[cat];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1555 else
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
1556 return Fget_coding_system (Qraw_text);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1557 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1558 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1559
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1560 /* Given a seekable read stream and potential coding system and EOL type
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1561 as specified, do any autodetection that is called for. If the
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1562 coding system and/or EOL type are not autodetect, they will be left
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1563 alone; but this function will never return an autodetect coding system
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1564 or EOL type.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1565
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1566 This function does not automatically fetch subsidiary coding systems;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1567 that should be unnecessary with the explicit eol-type argument. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1568
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1569 void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1570 determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1571 enum eol_type *eol_type_in_out)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1572 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1573 struct detection_state decst;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1574
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1575 if (*eol_type_in_out == EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1576 *eol_type_in_out = XCODING_SYSTEM_EOL_TYPE (*codesys_in_out);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1577
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1578 xzero (decst);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1579 decst.eol_type = *eol_type_in_out;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1580 decst.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1581
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1582 /* If autodetection is called for, do it now. */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1583 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1584 *eol_type_in_out == EOL_AUTODETECT)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1585 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1586
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1587 while (1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1588 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1589 unsigned char random_buffer[4096];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1590 int nread;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1591
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1592 nread = Lstream_read (stream, random_buffer, sizeof (random_buffer));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1593 if (!nread)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1594 break;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1595 if (detect_coding_type (&decst, random_buffer, nread,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1596 XCODING_SYSTEM_TYPE (*codesys_in_out) !=
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1597 CODESYS_AUTODETECT))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1598 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1599 }
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1600
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1601 *eol_type_in_out = decst.eol_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1602 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1603 *codesys_in_out = coding_system_from_mask (decst.mask);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1604 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1605
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1606 /* If we absolutely can't determine the EOL type, just assume LF. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1607 if (*eol_type_in_out == EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1608 *eol_type_in_out = EOL_LF;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1609
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1610 Lstream_rewind (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1611 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1612
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1613 DEFUN ("detect-coding-region", Fdetect_coding_region, 2, 3, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1614 Detect coding system of the text in the region between START and END.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1615 Returned a list of possible coding systems ordered by priority.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1616 If only ASCII characters are found, it returns 'undecided or one of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1617 its subsidiary coding systems according to a detected end-of-line
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1618 type. Optional arg BUFFER defaults to the current buffer.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1619 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1620 (start, end, buffer))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1621 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1622 Lisp_Object val = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1623 struct buffer *buf = decode_buffer (buffer, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1624 Bufpos b, e;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1625 Lisp_Object instream, lb_instream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1626 Lstream *istr, *lb_istr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1627 struct detection_state decst;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1628 struct gcpro gcpro1, gcpro2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1629
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1630 get_buffer_range_char (buf, start, end, &b, &e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1631 lb_instream = make_lisp_buffer_input_stream (buf, b, e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1632 lb_istr = XLSTREAM (lb_instream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1633 instream = make_encoding_input_stream (lb_istr, Fget_coding_system (Qbinary));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1634 istr = XLSTREAM (instream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1635 GCPRO2 (instream, lb_instream);
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1636 xzero (decst);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1637 decst.eol_type = EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1638 decst.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1639 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1640 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1641 unsigned char random_buffer[4096];
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1642 int nread = Lstream_read (istr, random_buffer, sizeof (random_buffer));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1643
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1644 if (!nread)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1645 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1646 if (detect_coding_type (&decst, random_buffer, nread, 0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1647 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1648 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1649
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1650 if (decst.mask == ~0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1651 val = subsidiary_coding_system (Fget_coding_system (Qundecided),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1652 decst.eol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1653 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1654 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1655 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1656
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1657 val = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1658 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1659 decst.mask = postprocess_iso2022_mask (decst.mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1660 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1661 for (i = CODING_CATEGORY_LAST; i >= 0; i--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1662 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1663 int sys = coding_category_by_priority[i];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1664 if (decst.mask & (1 << sys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1665 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1666 Lisp_Object codesys = coding_category_system[sys];
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1667 if (!NILP (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1668 codesys = subsidiary_coding_system (codesys, decst.eol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1669 val = Fcons (codesys, val);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1670 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1671 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1672 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1673 Lstream_close (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1674 UNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1675 Lstream_delete (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1676 Lstream_delete (lb_istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1677 return val;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1678 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1679
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1680
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1681 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1682 /* Converting to internal Mule format ("decoding") */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1683 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1684
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1685 /* A decoding stream is a stream used for decoding text (i.e.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1686 converting from some external format to internal format).
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1687 The decoding-stream object keeps track of the actual coding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1688 stream, the stream that is at the other end, and data that
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1689 needs to be persistent across the lifetime of the stream. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1690
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1691 /* Handle the EOL stuff related to just-read-in character C.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1692 EOL_TYPE is the EOL type of the coding stream.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1693 FLAGS is the current value of FLAGS in the coding stream, and may
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1694 be modified by this macro. (The macro only looks at the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1695 CODING_STATE_CR flag.) DST is the Dynarr to which the decoded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1696 bytes are to be written. You need to also define a local goto
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1697 label "label_continue_loop" that is at the end of the main
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1698 character-reading loop.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1699
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1700 If C is a CR character, then this macro handles it entirely and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1701 jumps to label_continue_loop. Otherwise, this macro does not add
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1702 anything to DST, and continues normally. You should continue
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1703 processing C normally after this macro. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1704
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1705 #define DECODE_HANDLE_EOL_TYPE(eol_type, c, flags, dst) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1706 do { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1707 if (c == '\r') \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1708 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1709 if (eol_type == EOL_CR) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1710 Dynarr_add (dst, '\n'); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1711 else if (eol_type != EOL_CRLF || flags & CODING_STATE_CR) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1712 Dynarr_add (dst, c); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1713 else \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1714 flags |= CODING_STATE_CR; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1715 goto label_continue_loop; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1716 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1717 else if (flags & CODING_STATE_CR) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1718 { /* eol_type == CODING_SYSTEM_EOL_CRLF */ \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1719 if (c != '\n') \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1720 Dynarr_add (dst, '\r'); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1721 flags &= ~CODING_STATE_CR; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1722 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1723 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1724
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1725 /* C should be a binary character in the range 0 - 255; convert
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1726 to internal format and add to Dynarr DST. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1727
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1728 #define DECODE_ADD_BINARY_CHAR(c, dst) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1729 do { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1730 if (BYTE_ASCII_P (c)) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1731 Dynarr_add (dst, c); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1732 else if (BYTE_C1_P (c)) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1733 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1734 Dynarr_add (dst, LEADING_BYTE_CONTROL_1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1735 Dynarr_add (dst, c + 0x20); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1736 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1737 else \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1738 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1739 Dynarr_add (dst, LEADING_BYTE_LATIN_ISO8859_1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1740 Dynarr_add (dst, c); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1741 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1742 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1743
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1744 #define DECODE_OUTPUT_PARTIAL_CHAR(ch) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1745 do { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1746 if (ch) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1747 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1748 DECODE_ADD_BINARY_CHAR (ch, dst); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1749 ch = 0; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1750 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1751 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1752
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1753 #define DECODE_HANDLE_END_OF_CONVERSION(flags, ch, dst) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1754 do { \
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1755 if (flags & CODING_STATE_END) \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1756 { \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1757 DECODE_OUTPUT_PARTIAL_CHAR (ch); \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1758 if (flags & CODING_STATE_CR) \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1759 Dynarr_add (dst, '\r'); \
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
1760 } \
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1761 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1762
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1763 #define DECODING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, decoding)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1764
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1765 struct decoding_stream
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1766 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1767 /* Coding system that governs the conversion. */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1768 Lisp_Coding_System *codesys;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1769
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1770 /* Stream that we read the encoded data from or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1771 write the decoded data to. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1772 Lstream *other_end;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1773
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1774 /* If we are reading, then we can return only a fixed amount of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1775 data, so if the conversion resulted in too much data, we store it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1776 here for retrieval the next time around. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1777 unsigned_char_dynarr *runoff;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1778
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1779 /* FLAGS holds flags indicating the current state of the decoding.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1780 Some of these flags are dependent on the coding system. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1781 unsigned int flags;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1782
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1783 /* CH holds a partially built-up character. Since we only deal
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1784 with one- and two-byte characters at the moment, we only use
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1785 this to store the first byte of a two-byte character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1786 unsigned int ch;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1787
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1788 /* EOL_TYPE specifies the type of end-of-line conversion that
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1789 currently applies. We need to keep this separate from the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1790 EOL type stored in CODESYS because the latter might indicate
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1791 automatic EOL-type detection while the former will always
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1792 indicate a particular EOL type. */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1793 enum eol_type eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1794 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1795 /* Additional ISO2022 information. We define the structure above
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1796 because it's also needed by the detection routines. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1797 struct iso2022_decoder iso2022;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1798
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1799 /* Additional information (the state of the running CCL program)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1800 used by the CCL decoder. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1801 struct ccl_program ccl;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1802 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1803 struct detection_state decst;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1804 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1805
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1806 static int decoding_reader (Lstream *stream, unsigned char *data, size_t size);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1807 static int decoding_writer (Lstream *stream, CONST unsigned char *data, size_t size);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1808 static int decoding_rewinder (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1809 static int decoding_seekable_p (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1810 static int decoding_flusher (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1811 static int decoding_closer (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1812
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1813 static Lisp_Object decoding_marker (Lisp_Object stream,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1814 void (*markobj) (Lisp_Object));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1815
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1816 DEFINE_LSTREAM_IMPLEMENTATION ("decoding", lstream_decoding,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1817 sizeof (struct decoding_stream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1818
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1819 static Lisp_Object
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1820 decoding_marker (Lisp_Object stream, void (*markobj) (Lisp_Object))
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1821 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1822 Lstream *str = DECODING_STREAM_DATA (XLSTREAM (stream))->other_end;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1823 Lisp_Object str_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1824
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1825 /* We do not need to mark the coding systems or charsets stored
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1826 within the stream because they are stored in a global list
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1827 and automatically marked. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1828
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1829 XSETLSTREAM (str_obj, str);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1830 markobj (str_obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1831 if (str->imp->marker)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1832 return (str->imp->marker) (str_obj, markobj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1833 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1834 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1835 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1836
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1837 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1838 so we read data from the other end, decode it, and store it into DATA. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1839
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1840 static int
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1841 decoding_reader (Lstream *stream, unsigned char *data, size_t size)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1842 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1843 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1844 unsigned char *orig_data = data;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1845 int read_size;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1846 int error_occurred = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1847
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1848 /* We need to interface to mule_decode(), which expects to take some
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1849 amount of data and store the result into a Dynarr. We have
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1850 mule_decode() store into str->runoff, and take data from there
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1851 as necessary. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1852
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1853 /* We loop until we have enough data, reading chunks from the other
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1854 end and decoding it. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1855 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1856 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1857 /* Take data from the runoff if we can. Make sure to take at
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1858 most SIZE bytes, and delete the data from the runoff. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1859 if (Dynarr_length (str->runoff) > 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1860 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1861 size_t chunk = min (size, (size_t) Dynarr_length (str->runoff));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1862 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1863 Dynarr_delete_many (str->runoff, 0, chunk);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1864 data += chunk;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1865 size -= chunk;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1866 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1867
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1868 if (size == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1869 break; /* No more room for data */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1870
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1871 if (str->flags & CODING_STATE_END)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1872 /* This means that on the previous iteration, we hit the EOF on
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1873 the other end. We loop once more so that mule_decode() can
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1874 output any final stuff it may be holding, or any "go back
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1875 to a sane state" escape sequences. (This latter makes sense
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1876 during encoding.) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1877 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1878
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1879 /* Exhausted the runoff, so get some more. DATA has at least
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1880 SIZE bytes left of storage in it, so it's OK to read directly
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1881 into it. (We'll be overwriting above, after we've decoded it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1882 into the runoff.) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1883 read_size = Lstream_read (str->other_end, data, size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1884 if (read_size < 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1885 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1886 error_occurred = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1887 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1888 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1889 if (read_size == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1890 /* There might be some more end data produced in the translation.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1891 See the comment above. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1892 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1893 mule_decode (stream, data, str->runoff, read_size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1894 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1895
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1896 if (data - orig_data == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1897 return error_occurred ? -1 : 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1898 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1899 return data - orig_data;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1900 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1901
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1902 static int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1903 decoding_writer (Lstream *stream, CONST unsigned char *data, size_t size)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1904 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1905 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
1906 int retval;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1907
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1908 /* Decode all our data into the runoff, and then attempt to write
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1909 it all out to the other end. Remove whatever chunk we succeeded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1910 in writing. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1911 mule_decode (stream, data, str->runoff, size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1912 retval = Lstream_write (str->other_end, Dynarr_atp (str->runoff, 0),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1913 Dynarr_length (str->runoff));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1914 if (retval > 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1915 Dynarr_delete_many (str->runoff, 0, retval);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1916 /* Do NOT return retval. The return value indicates how much
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1917 of the incoming data was written, not how many bytes were
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1918 written. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1919 return size;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1920 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1921
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1922 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1923 reset_decoding_stream (struct decoding_stream *str)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1924 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1925 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1926 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_ISO2022)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1927 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1928 Lisp_Object coding_system;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1929 XSETCODING_SYSTEM (coding_system, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1930 reset_iso2022 (coding_system, &str->iso2022);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1931 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1932 else if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_CCL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1933 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1934 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_DECODE (str->codesys));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1935 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1936 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1937 str->flags = str->ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1938 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1939
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1940 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1941 decoding_rewinder (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1942 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1943 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1944 reset_decoding_stream (str);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1945 Dynarr_reset (str->runoff);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1946 return Lstream_rewind (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1947 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1948
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1949 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1950 decoding_seekable_p (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1951 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1952 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1953 return Lstream_seekable_p (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1954 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1955
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1956 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1957 decoding_flusher (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1958 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1959 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1960 return Lstream_flush (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1961 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1962
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1963 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1964 decoding_closer (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1965 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1966 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1967 if (stream->flags & LSTREAM_FL_WRITE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1968 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1969 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1970 decoding_writer (stream, 0, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1971 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1972 Dynarr_free (str->runoff);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1973 #ifdef MULE
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1974 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1975 if (str->iso2022.composite_chars)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1976 Dynarr_free (str->iso2022.composite_chars);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1977 #endif
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1978 #endif
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1979 return Lstream_close (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1980 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1981
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1982 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1983 decoding_stream_coding_system (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1984 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
1985 Lisp_Object coding_system;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1986 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1987
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1988 XSETCODING_SYSTEM (coding_system, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1989 return subsidiary_coding_system (coding_system, str->eol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1990 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1991
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1992 void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1993 set_decoding_stream_coding_system (Lstream *lstr, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1994 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
1995 Lisp_Coding_System *cs = XCODING_SYSTEM (codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1996 struct decoding_stream *str = DECODING_STREAM_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1997 str->codesys = cs;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1998 if (CODING_SYSTEM_EOL_TYPE (cs) != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
1999 str->eol_type = CODING_SYSTEM_EOL_TYPE (cs);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2000 reset_decoding_stream (str);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2001 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2002
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2003 /* WARNING WARNING WARNING WARNING!!!!! If you open up a decoding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2004 stream for writing, no automatic code detection will be performed.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2005 The reason for this is that automatic code detection requires a
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2006 seekable input. Things will also fail if you open a decoding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2007 stream for reading using a non-fully-specified coding system and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2008 a non-seekable input stream. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2009
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2010 static Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2011 make_decoding_stream_1 (Lstream *stream, Lisp_Object codesys,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2012 CONST char *mode)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2013 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2014 Lstream *lstr = Lstream_new (lstream_decoding, mode);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2015 struct decoding_stream *str = DECODING_STREAM_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2016 Lisp_Object obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2017
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2018 xzero (*str);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2019 str->other_end = stream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2020 str->runoff = (unsigned_char_dynarr *) Dynarr_new (unsigned_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2021 str->eol_type = EOL_AUTODETECT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2022 if (!strcmp (mode, "r")
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2023 && Lstream_seekable_p (stream))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2024 /* We can determine the coding system now. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2025 determine_real_coding_system (stream, &codesys, &str->eol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2026 set_decoding_stream_coding_system (lstr, codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2027 str->decst.eol_type = str->eol_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2028 str->decst.mask = ~0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2029 XSETLSTREAM (obj, lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2030 return obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2031 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2032
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2033 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2034 make_decoding_input_stream (Lstream *stream, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2035 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2036 return make_decoding_stream_1 (stream, codesys, "r");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2037 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2038
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2039 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2040 make_decoding_output_stream (Lstream *stream, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2041 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2042 return make_decoding_stream_1 (stream, codesys, "w");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2043 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2044
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2045 /* Note: the decode_coding_* functions all take the same
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2046 arguments as mule_decode(), which is to say some SRC data of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2047 size N, which is to be stored into dynamic array DST.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2048 DECODING is the stream within which the decoding is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2049 taking place, but no data is actually read from or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2050 written to that stream; that is handled in decoding_reader()
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2051 or decoding_writer(). This allows the same functions to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2052 be used for both reading and writing. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2053
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2054 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2055 mule_decode (Lstream *decoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2056 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2057 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2058 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2059
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2060 /* If necessary, do encoding-detection now. We do this when
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2061 we're a writing stream or a non-seekable reading stream,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2062 meaning that we can't just process the whole input,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2063 rewind, and start over. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2064
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2065 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2066 str->eol_type == EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2067 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2068 Lisp_Object codesys;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2069
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2070 XSETCODING_SYSTEM (codesys, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2071 detect_coding_type (&str->decst, src, n,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2072 CODING_SYSTEM_TYPE (str->codesys) !=
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2073 CODESYS_AUTODETECT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2074 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2075 str->decst.mask != ~0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2076 /* #### This is cheesy. What we really ought to do is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2077 buffer up a certain amount of data so as to get a
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2078 less random result. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2079 codesys = coding_system_from_mask (str->decst.mask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2080 str->eol_type = str->decst.eol_type;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2081 if (XCODING_SYSTEM (codesys) != str->codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2082 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2083 /* Preserve the CODING_STATE_END flag in case it was set.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2084 If we erase it, bad things might happen. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2085 int was_end = str->flags & CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2086 set_decoding_stream_coding_system (decoding, codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2087 if (was_end)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2088 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2089 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2090 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2091
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2092 switch (CODING_SYSTEM_TYPE (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2093 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2094 #ifdef DEBUG_XEMACS
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2095 case CODESYS_INTERNAL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2096 Dynarr_add_many (dst, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2097 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2098 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2099 case CODESYS_AUTODETECT:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2100 /* If we got this far and still haven't decided on the coding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2101 system, then do no conversion. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2102 case CODESYS_NO_CONVERSION:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2103 decode_coding_no_conversion (decoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2104 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2105 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2106 case CODESYS_SHIFT_JIS:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2107 decode_coding_sjis (decoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2108 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2109 case CODESYS_BIG5:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2110 decode_coding_big5 (decoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2111 break;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2112 case CODESYS_UCS4:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2113 decode_coding_ucs4 (decoding, src, dst, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2114 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2115 case CODESYS_UTF8:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2116 decode_coding_utf8 (decoding, src, dst, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2117 break;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2118 case CODESYS_CCL:
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2119 ccl_driver (&str->ccl, src, dst, n, 0);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2120 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2121 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2122 decode_coding_iso2022 (decoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2123 break;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2124 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2125 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2126 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2127 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2128 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2129
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2130 DEFUN ("decode-coding-region", Fdecode_coding_region, 3, 4, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2131 Decode the text between START and END which is encoded in CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2132 This is useful if you've read in encoded text from a file without decoding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2133 it (e.g. you read in a JIS-formatted file but used the `binary' or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2134 `no-conversion' coding system, so that it shows up as "^[$B!<!+^[(B").
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2135 Return length of decoded text.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2136 BUFFER defaults to the current buffer if unspecified.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2137 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2138 (start, end, coding_system, buffer))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2139 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2140 Bufpos b, e;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2141 struct buffer *buf = decode_buffer (buffer, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2142 Lisp_Object instream, lb_outstream, de_outstream, outstream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2143 Lstream *istr, *ostr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2144 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2145
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2146 get_buffer_range_char (buf, start, end, &b, &e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2147
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2148 barf_if_buffer_read_only (buf, b, e);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2149
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2150 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2151 instream = make_lisp_buffer_input_stream (buf, b, e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2152 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2153 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2154 coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2155 outstream = make_encoding_output_stream (XLSTREAM (de_outstream),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2156 Fget_coding_system (Qbinary));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2157 istr = XLSTREAM (instream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2158 ostr = XLSTREAM (outstream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2159 GCPRO4 (instream, lb_outstream, de_outstream, outstream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2160
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2161 /* The chain of streams looks like this:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2162
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2163 [BUFFER] <----- send through
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2164 ------> [ENCODE AS BINARY]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2165 ------> [DECODE AS SPECIFIED]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2166 ------> [BUFFER]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2167 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2168
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2169 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2170 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2171 char tempbuf[1024]; /* some random amount */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2172 Bufpos newpos, even_newer_pos;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2173 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2174 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2175
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2176 if (!size_in_bytes)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2177 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2178 newpos = lisp_buffer_stream_startpos (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2179 Lstream_write (ostr, tempbuf, size_in_bytes);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2180 even_newer_pos = lisp_buffer_stream_startpos (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2181 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2182 even_newer_pos, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2183 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2184 Lstream_close (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2185 Lstream_close (ostr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2186 UNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2187 Lstream_delete (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2188 Lstream_delete (ostr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2189 Lstream_delete (XLSTREAM (de_outstream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2190 Lstream_delete (XLSTREAM (lb_outstream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2191 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2192 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2193
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2194
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2195 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2196 /* Converting to an external encoding ("encoding") */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2197 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2198
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2199 /* An encoding stream is an output stream. When you create the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2200 stream, you specify the coding system that governs the encoding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2201 and another stream that the resulting encoded data is to be
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2202 sent to, and then start sending data to it. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2203
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2204 #define ENCODING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, encoding)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2205
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2206 struct encoding_stream
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2207 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2208 /* Coding system that governs the conversion. */
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2209 Lisp_Coding_System *codesys;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2210
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2211 /* Stream that we read the encoded data from or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2212 write the decoded data to. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2213 Lstream *other_end;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2214
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2215 /* If we are reading, then we can return only a fixed amount of
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2216 data, so if the conversion resulted in too much data, we store it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2217 here for retrieval the next time around. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2218 unsigned_char_dynarr *runoff;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2219
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2220 /* FLAGS holds flags indicating the current state of the encoding.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2221 Some of these flags are dependent on the coding system. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2222 unsigned int flags;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2223
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2224 /* CH holds a partially built-up character. Since we only deal
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2225 with one- and two-byte characters at the moment, we only use
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2226 this to store the first byte of a two-byte character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2227 unsigned int ch;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2228 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2229 /* Additional information used by the ISO2022 encoder. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2230 struct
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2231 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2232 /* CHARSET holds the character sets currently assigned to the G0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2233 through G3 registers. It is initialized from the array
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2234 INITIAL_CHARSET in CODESYS. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2235 Lisp_Object charset[4];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2236
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2237 /* Which registers are currently invoked into the left (GL) and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2238 right (GR) halves of the 8-bit encoding space? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2239 int register_left, register_right;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2240
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2241 /* Whether we need to explicitly designate the charset in the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2242 G? register before using it. It is initialized from the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2243 array FORCE_CHARSET_ON_OUTPUT in CODESYS. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2244 unsigned char force_charset_on_output[4];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2245
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2246 /* Other state variables that need to be preserved across
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2247 invocations. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2248 Lisp_Object current_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2249 int current_half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2250 int current_char_boundary;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2251 } iso2022;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2252
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2253 /* Additional information (the state of the running CCL program)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2254 used by the CCL encoder. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2255 struct ccl_program ccl;
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2256 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2257 };
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2258
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2259 static int encoding_reader (Lstream *stream, unsigned char *data, size_t size);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2260 static int encoding_writer (Lstream *stream, CONST unsigned char *data,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2261 size_t size);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2262 static int encoding_rewinder (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2263 static int encoding_seekable_p (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2264 static int encoding_flusher (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2265 static int encoding_closer (Lstream *stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2266
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2267 static Lisp_Object encoding_marker (Lisp_Object stream,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2268 void (*markobj) (Lisp_Object));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2269
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2270 DEFINE_LSTREAM_IMPLEMENTATION ("encoding", lstream_encoding,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2271 sizeof (struct encoding_stream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2272
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2273 static Lisp_Object
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2274 encoding_marker (Lisp_Object stream, void (*markobj) (Lisp_Object))
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2275 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2276 Lstream *str = ENCODING_STREAM_DATA (XLSTREAM (stream))->other_end;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2277 Lisp_Object str_obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2278
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2279 /* We do not need to mark the coding systems or charsets stored
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2280 within the stream because they are stored in a global list
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2281 and automatically marked. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2282
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2283 XSETLSTREAM (str_obj, str);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2284 markobj (str_obj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2285 if (str->imp->marker)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2286 return (str->imp->marker) (str_obj, markobj);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2287 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2288 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2289 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2290
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2291 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2292 so we read data from the other end, encode it, and store it into DATA. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2293
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2294 static int
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2295 encoding_reader (Lstream *stream, unsigned char *data, size_t size)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2296 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2297 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2298 unsigned char *orig_data = data;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2299 int read_size;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2300 int error_occurred = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2301
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2302 /* We need to interface to mule_encode(), which expects to take some
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2303 amount of data and store the result into a Dynarr. We have
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2304 mule_encode() store into str->runoff, and take data from there
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2305 as necessary. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2306
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2307 /* We loop until we have enough data, reading chunks from the other
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2308 end and encoding it. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2309 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2310 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2311 /* Take data from the runoff if we can. Make sure to take at
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2312 most SIZE bytes, and delete the data from the runoff. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2313 if (Dynarr_length (str->runoff) > 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2314 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2315 int chunk = min ((int) size, Dynarr_length (str->runoff));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2316 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2317 Dynarr_delete_many (str->runoff, 0, chunk);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2318 data += chunk;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2319 size -= chunk;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2320 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2321
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2322 if (size == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2323 break; /* No more room for data */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2324
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2325 if (str->flags & CODING_STATE_END)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2326 /* This means that on the previous iteration, we hit the EOF on
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2327 the other end. We loop once more so that mule_encode() can
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2328 output any final stuff it may be holding, or any "go back
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2329 to a sane state" escape sequences. (This latter makes sense
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2330 during encoding.) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2331 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2332
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2333 /* Exhausted the runoff, so get some more. DATA at least SIZE bytes
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2334 left of storage in it, so it's OK to read directly into it.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2335 (We'll be overwriting above, after we've encoded it into the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2336 runoff.) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2337 read_size = Lstream_read (str->other_end, data, size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2338 if (read_size < 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2339 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2340 error_occurred = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2341 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2342 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2343 if (read_size == 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2344 /* There might be some more end data produced in the translation.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2345 See the comment above. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2346 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2347 mule_encode (stream, data, str->runoff, read_size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2348 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2349
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2350 if (data == orig_data)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2351 return error_occurred ? -1 : 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2352 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2353 return data - orig_data;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2354 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2355
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2356 static int
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2357 encoding_writer (Lstream *stream, CONST unsigned char *data, size_t size)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2358 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2359 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2360 int retval;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2361
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2362 /* Encode all our data into the runoff, and then attempt to write
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2363 it all out to the other end. Remove whatever chunk we succeeded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2364 in writing. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2365 mule_encode (stream, data, str->runoff, size);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2366 retval = Lstream_write (str->other_end, Dynarr_atp (str->runoff, 0),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2367 Dynarr_length (str->runoff));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2368 if (retval > 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2369 Dynarr_delete_many (str->runoff, 0, retval);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2370 /* Do NOT return retval. The return value indicates how much
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2371 of the incoming data was written, not how many bytes were
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2372 written. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2373 return size;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2374 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2375
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2376 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2377 reset_encoding_stream (struct encoding_stream *str)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2378 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2379 #ifdef MULE
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2380 switch (CODING_SYSTEM_TYPE (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2381 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2382 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2383 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2384 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2385
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2386 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2387 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2388 str->iso2022.charset[i] =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2389 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (str->codesys, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2390 str->iso2022.force_charset_on_output[i] =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2391 CODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT (str->codesys, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2392 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2393 str->iso2022.register_left = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2394 str->iso2022.register_right = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2395 str->iso2022.current_charset = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2396 str->iso2022.current_half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2397 str->iso2022.current_char_boundary = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2398 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2399 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2400 case CODESYS_CCL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2401 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_ENCODE (str->codesys));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2402 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2403 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2404 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2405 }
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2406 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2407
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2408 str->flags = str->ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2409 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2410
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2411 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2412 encoding_rewinder (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2413 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2414 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2415 reset_encoding_stream (str);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2416 Dynarr_reset (str->runoff);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2417 return Lstream_rewind (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2418 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2419
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2420 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2421 encoding_seekable_p (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2422 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2423 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2424 return Lstream_seekable_p (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2425 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2426
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2427 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2428 encoding_flusher (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2429 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2430 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2431 return Lstream_flush (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2432 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2433
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2434 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2435 encoding_closer (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2436 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2437 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2438 if (stream->flags & LSTREAM_FL_WRITE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2439 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2440 str->flags |= CODING_STATE_END;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2441 encoding_writer (stream, 0, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2442 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2443 Dynarr_free (str->runoff);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2444 return Lstream_close (str->other_end);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2445 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2446
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2447 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2448 encoding_stream_coding_system (Lstream *stream)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2449 {
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2450 Lisp_Object coding_system;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2451 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2452
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2453 XSETCODING_SYSTEM (coding_system, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2454 return coding_system;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2455 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2456
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2457 void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2458 set_encoding_stream_coding_system (Lstream *lstr, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2459 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2460 Lisp_Coding_System *cs = XCODING_SYSTEM (codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2461 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2462 str->codesys = cs;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2463 reset_encoding_stream (str);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2464 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2465
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2466 static Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2467 make_encoding_stream_1 (Lstream *stream, Lisp_Object codesys,
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2468 CONST char *mode)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2469 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2470 Lstream *lstr = Lstream_new (lstream_encoding, mode);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2471 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2472 Lisp_Object obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2473
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
2474 xzero (*str);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2475 str->runoff = Dynarr_new (unsigned_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2476 str->other_end = stream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2477 set_encoding_stream_coding_system (lstr, codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2478 XSETLSTREAM (obj, lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2479 return obj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2480 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2481
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2482 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2483 make_encoding_input_stream (Lstream *stream, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2484 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2485 return make_encoding_stream_1 (stream, codesys, "r");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2486 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2487
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2488 Lisp_Object
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2489 make_encoding_output_stream (Lstream *stream, Lisp_Object codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2490 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2491 return make_encoding_stream_1 (stream, codesys, "w");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2492 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2493
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2494 /* Convert N bytes of internally-formatted data stored in SRC to an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2495 external format, according to the encoding stream ENCODING.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2496 Store the encoded data into DST. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2497
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2498 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2499 mule_encode (Lstream *encoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2500 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2501 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2502 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2503
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2504 switch (CODING_SYSTEM_TYPE (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2505 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2506 #ifdef DEBUG_XEMACS
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2507 case CODESYS_INTERNAL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2508 Dynarr_add_many (dst, src, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2509 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2510 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2511 case CODESYS_AUTODETECT:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2512 /* If we got this far and still haven't decided on the coding
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2513 system, then do no conversion. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2514 case CODESYS_NO_CONVERSION:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2515 encode_coding_no_conversion (encoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2516 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2517 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2518 case CODESYS_SHIFT_JIS:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2519 encode_coding_sjis (encoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2520 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2521 case CODESYS_BIG5:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2522 encode_coding_big5 (encoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2523 break;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2524 case CODESYS_UCS4:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2525 encode_coding_ucs4 (encoding, src, dst, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2526 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2527 case CODESYS_UTF8:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2528 encode_coding_utf8 (encoding, src, dst, n);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2529 break;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2530 case CODESYS_CCL:
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2531 ccl_driver (&str->ccl, src, dst, n, 0);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2532 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2533 case CODESYS_ISO2022:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2534 encode_coding_iso2022 (encoding, src, dst, n);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2535 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2536 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2537 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2538 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2539 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2540 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2541
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2542 DEFUN ("encode-coding-region", Fencode_coding_region, 3, 4, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2543 Encode the text between START and END using CODING-SYSTEM.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2544 This will, for example, convert Japanese characters into stuff such as
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2545 "^[$B!<!+^[(B" if you use the JIS encoding. Return length of encoded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2546 text. BUFFER defaults to the current buffer if unspecified.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2547 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2548 (start, end, coding_system, buffer))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2549 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2550 Bufpos b, e;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2551 struct buffer *buf = decode_buffer (buffer, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2552 Lisp_Object instream, lb_outstream, de_outstream, outstream;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2553 Lstream *istr, *ostr;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2554 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2555
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2556 get_buffer_range_char (buf, start, end, &b, &e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2557
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2558 barf_if_buffer_read_only (buf, b, e);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2559
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2560 coding_system = Fget_coding_system (coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2561 instream = make_lisp_buffer_input_stream (buf, b, e, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2562 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2563 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2564 Fget_coding_system (Qbinary));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2565 outstream = make_encoding_output_stream (XLSTREAM (de_outstream),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2566 coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2567 istr = XLSTREAM (instream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2568 ostr = XLSTREAM (outstream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2569 GCPRO4 (instream, outstream, de_outstream, lb_outstream);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2570 /* The chain of streams looks like this:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2571
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2572 [BUFFER] <----- send through
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2573 ------> [ENCODE AS SPECIFIED]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2574 ------> [DECODE AS BINARY]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2575 ------> [BUFFER]
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2576 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2577 while (1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2578 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2579 char tempbuf[1024]; /* some random amount */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2580 Bufpos newpos, even_newer_pos;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2581 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2582 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2583
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2584 if (!size_in_bytes)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2585 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2586 newpos = lisp_buffer_stream_startpos (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2587 Lstream_write (ostr, tempbuf, size_in_bytes);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2588 even_newer_pos = lisp_buffer_stream_startpos (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2589 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2590 even_newer_pos, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2591 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2592
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2593 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2594 Charcount retlen =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2595 lisp_buffer_stream_startpos (XLSTREAM (instream)) - b;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2596 Lstream_close (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2597 Lstream_close (ostr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2598 UNGCPRO;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2599 Lstream_delete (istr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2600 Lstream_delete (ostr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2601 Lstream_delete (XLSTREAM (de_outstream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2602 Lstream_delete (XLSTREAM (lb_outstream));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2603 return make_int (retlen);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2604 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2605 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2606
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2607 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2608
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2609 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2610 /* Shift-JIS methods */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2611 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2612
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2613 /* Shift-JIS is a coding system encoding three character sets: ASCII, right
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2614 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2615 as is. A character of JISX0201-Kana (DIMENSION1_CHARS94 character set) is
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2616 encoded by "position-code + 0x80". A character of JISX0208
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2617 (DIMENSION2_CHARS94 character set) is encoded in 2-byte but two
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2618 position-codes are divided and shifted so that it fit in the range
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2619 below.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2620
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2621 --- CODE RANGE of Shift-JIS ---
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2622 (character set) (range)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2623 ASCII 0x00 .. 0x7F
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2624 JISX0201-Kana 0xA0 .. 0xDF
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2625 JISX0208 (1st byte) 0x80 .. 0x9F and 0xE0 .. 0xEF
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2626 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2627 -------------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2628
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2629 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2630
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2631 /* Is this the first byte of a Shift-JIS two-byte char? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2632
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2633 #define BYTE_SJIS_TWO_BYTE_1_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2634 (((c) >= 0x81 && (c) <= 0x9F) || ((c) >= 0xE0 && (c) <= 0xEF))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2635
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2636 /* Is this the second byte of a Shift-JIS two-byte char? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2637
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2638 #define BYTE_SJIS_TWO_BYTE_2_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2639 (((c) >= 0x40 && (c) <= 0x7E) || ((c) >= 0x80 && (c) <= 0xFC))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2640
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2641 #define BYTE_SJIS_KATAKANA_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2642 ((c) >= 0xA1 && (c) <= 0xDF)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2643
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2644 static int
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2645 detect_coding_sjis (struct detection_state *st, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2646 unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2647 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2648 int c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2649
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2650 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2651 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2652 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2653 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2654 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2655 if (st->shift_jis.in_second_byte)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2656 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2657 st->shift_jis.in_second_byte = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2658 if (c < 0x40)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2659 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2660 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2661 else if ((c >= 0x80 && c < 0xA0) || c >= 0xE0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2662 st->shift_jis.in_second_byte = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2663 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2664 return CODING_CATEGORY_SHIFT_JIS_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2665 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2666
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2667 /* Convert Shift-JIS data to internal format. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2668
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2669 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2670 decode_coding_sjis (Lstream *decoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2671 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2672 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2673 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2674 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2675 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2676 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2677 eol_type_t eol_type = str->eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2678
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2679 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2680 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2681 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2682
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2683 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2684 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2685 /* Previous character was first byte of Shift-JIS Kanji char. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2686 if (BYTE_SJIS_TWO_BYTE_2_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2687 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2688 unsigned char e1, e2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2689
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2690 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2691 DECODE_SJIS (ch, c, e1, e2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2692 Dynarr_add (dst, e1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2693 Dynarr_add (dst, e2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2694 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2695 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2696 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2697 DECODE_ADD_BINARY_CHAR (ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2698 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2699 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2700 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2701 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2702 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2703 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2704 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2705 if (BYTE_SJIS_TWO_BYTE_1_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2706 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2707 else if (BYTE_SJIS_KATAKANA_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2708 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2709 Dynarr_add (dst, LEADING_BYTE_KATAKANA_JISX0201);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2710 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2711 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2712 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2713 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2714 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2715 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2716 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2717
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2718 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2719
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2720 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2721 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2722 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2723
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2724 /* Convert internally-formatted data to Shift-JIS. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2725
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2726 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2727 encode_coding_sjis (Lstream *encoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2728 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2729 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2730 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2731 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2732 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2733 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2734 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2735
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2736 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2737 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2738 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2739 if (c == '\n')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2740 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2741 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2742 Dynarr_add (dst, '\r');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2743 if (eol_type != EOL_CR)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2744 Dynarr_add (dst, '\n');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2745 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2746 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2747 else if (BYTE_ASCII_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2748 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2749 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2750 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2751 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2752 else if (BUFBYTE_LEADING_BYTE_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2753 ch = (c == LEADING_BYTE_KATAKANA_JISX0201 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2754 c == LEADING_BYTE_JAPANESE_JISX0208_1978 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2755 c == LEADING_BYTE_JAPANESE_JISX0208) ? c : 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2756 else if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2757 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2758 if (ch == LEADING_BYTE_KATAKANA_JISX0201)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2759 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2760 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2761 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2762 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2763 else if (ch == LEADING_BYTE_JAPANESE_JISX0208_1978 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2764 ch == LEADING_BYTE_JAPANESE_JISX0208)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2765 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2766 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2767 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2768 unsigned char j1, j2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2769 ENCODE_SJIS (ch, c, j1, j2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2770 Dynarr_add (dst, j1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2771 Dynarr_add (dst, j2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2772 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2773 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2774 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2775 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2776
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2777 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2778 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2779 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2780
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2781 DEFUN ("decode-shift-jis-char", Fdecode_shift_jis_char, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2782 Decode a JISX0208 character of Shift-JIS coding-system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2783 CODE is the character code in Shift-JIS as a cons of type bytes.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2784 Return the corresponding character.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2785 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2786 (code))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2787 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2788 unsigned char c1, c2, s1, s2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2789
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2790 CHECK_CONS (code);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2791 CHECK_INT (XCAR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2792 CHECK_INT (XCDR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2793 s1 = XINT (XCAR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2794 s2 = XINT (XCDR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2795 if (BYTE_SJIS_TWO_BYTE_1_P (s1) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2796 BYTE_SJIS_TWO_BYTE_2_P (s2))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2797 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2798 DECODE_SJIS (s1, s2, c1, c2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2799 return make_char (MAKE_CHAR (Vcharset_japanese_jisx0208,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2800 c1 & 0x7F, c2 & 0x7F));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2801 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2802 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2803 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2804 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2805
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2806 DEFUN ("encode-shift-jis-char", Fencode_shift_jis_char, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2807 Encode a JISX0208 character CHAR to SHIFT-JIS coding-system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2808 Return the corresponding character code in SHIFT-JIS as a cons of two bytes.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2809 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2810 (ch))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2811 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2812 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2813 int c1, c2, s1, s2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2814
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2815 CHECK_CHAR_COERCE_INT (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2816 BREAKUP_CHAR (XCHAR (ch), charset, c1, c2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2817 if (EQ (charset, Vcharset_japanese_jisx0208))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2818 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2819 ENCODE_SJIS (c1 | 0x80, c2 | 0x80, s1, s2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2820 return Fcons (make_int (s1), make_int (s2));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2821 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2822 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2823 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2824 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2825
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2826
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2827 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2828 /* Big5 methods */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2829 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2830
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2831 /* BIG5 is a coding system encoding two character sets: ASCII and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2832 Big5. An ASCII character is encoded as is. Big5 is a two-byte
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2833 character set and is encoded in two-byte.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2834
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2835 --- CODE RANGE of BIG5 ---
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2836 (character set) (range)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2837 ASCII 0x00 .. 0x7F
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2838 Big5 (1st byte) 0xA1 .. 0xFE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2839 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2840 --------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2841
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2842 Since the number of characters in Big5 is larger than maximum
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2843 characters in Emacs' charset (96x96), it can't be handled as one
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
2844 charset. So, in Emacs, Big5 is divided into two: `charset-big5-1'
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2845 and `charset-big5-2'. Both <type>s are DIMENSION2_CHARS94. The former
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2846 contains frequently used characters and the latter contains less
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2847 frequently used characters. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2848
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2849 #define BYTE_BIG5_TWO_BYTE_1_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2850 ((c) >= 0xA1 && (c) <= 0xFE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2851
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2852 /* Is this the second byte of a Shift-JIS two-byte char? */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2853
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2854 #define BYTE_BIG5_TWO_BYTE_2_P(c) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2855 (((c) >= 0x40 && (c) <= 0x7E) || ((c) >= 0xA1 && (c) <= 0xFE))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2856
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2857 /* Number of Big5 characters which have the same code in 1st byte. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2858
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2859 #define BIG5_SAME_ROW (0xFF - 0xA1 + 0x7F - 0x40)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2860
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2861 /* Code conversion macros. These are macros because they are used in
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2862 inner loops during code conversion.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2863
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2864 Note that temporary variables in macros introduce the classic
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2865 dynamic-scoping problems with variable names. We use capital-
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2866 lettered variables in the assumption that XEmacs does not use
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2867 capital letters in variables except in a very formalized way
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2868 (e.g. Qstring). */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2869
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2870 /* Convert Big5 code (b1, b2) into its internal string representation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2871 (lb, c1, c2). */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2872
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2873 /* There is a much simpler way to split the Big5 charset into two.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2874 For the moment I'm going to leave the algorithm as-is because it
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2875 claims to separate out the most-used characters into a single
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2876 charset, which perhaps will lead to optimizations in various
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2877 places.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2878
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2879 The way the algorithm works is something like this:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2880
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2881 Big5 can be viewed as a 94x157 charset, where the row is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2882 encoded into the bytes 0xA1 .. 0xFE and the column is encoded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2883 into the bytes 0x40 .. 0x7E and 0xA1 .. 0xFE. As for frequency,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2884 the split between low and high column numbers is apparently
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2885 meaningless; ascending rows produce less and less frequent chars.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2886 Therefore, we assign the lower half of rows (0xA1 .. 0xC8) to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2887 the first charset, and the upper half (0xC9 .. 0xFE) to the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2888 second. To do the conversion, we convert the character into
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2889 a single number where 0 .. 156 is the first row, 157 .. 313
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2890 is the second, etc. That way, the characters are ordered by
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2891 decreasing frequency. Then we just chop the space in two
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2892 and coerce the result into a 94x94 space.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2893 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2894
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2895 #define DECODE_BIG5(b1, b2, lb, c1, c2) do \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2896 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2897 int B1 = b1, B2 = b2; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2898 unsigned int I \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2899 = (B1 - 0xA1) * BIG5_SAME_ROW + B2 - (B2 < 0x7F ? 0x40 : 0x62); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2900 \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2901 if (B1 < 0xC9) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2902 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2903 lb = LEADING_BYTE_CHINESE_BIG5_1; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2904 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2905 else \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2906 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2907 lb = LEADING_BYTE_CHINESE_BIG5_2; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2908 I -= (BIG5_SAME_ROW) * (0xC9 - 0xA1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2909 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2910 c1 = I / (0xFF - 0xA1) + 0xA1; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2911 c2 = I % (0xFF - 0xA1) + 0xA1; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2912 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2913
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2914 /* Convert the internal string representation of a Big5 character
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2915 (lb, c1, c2) into Big5 code (b1, b2). */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2916
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2917 #define ENCODE_BIG5(lb, c1, c2, b1, b2) do \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2918 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2919 unsigned int I = ((c1) - 0xA1) * (0xFF - 0xA1) + ((c2) - 0xA1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2920 \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2921 if (lb == LEADING_BYTE_CHINESE_BIG5_2) \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2922 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2923 I += BIG5_SAME_ROW * (0xC9 - 0xA1); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2924 } \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2925 b1 = I / BIG5_SAME_ROW + 0xA1; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2926 b2 = I % BIG5_SAME_ROW; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2927 b2 += b2 < 0x3F ? 0x40 : 0x62; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2928 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2929
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2930 static int
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2931 detect_coding_big5 (struct detection_state *st, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2932 unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2933 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2934 int c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2935
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2936 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2937 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2938 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2939 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2940 (c >= 0x80 && c <= 0xA0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2941 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2942 if (st->big5.in_second_byte)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2943 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2944 st->big5.in_second_byte = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2945 if (c < 0x40 || (c >= 0x80 && c <= 0xA0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2946 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2947 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2948 else if (c >= 0xA1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2949 st->big5.in_second_byte = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2950 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2951 return CODING_CATEGORY_BIG5_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2952 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2953
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2954 /* Convert Big5 data to internal format. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2955
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2956 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
2957 decode_coding_big5 (Lstream *decoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2958 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2959 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2960 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2961 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2962 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2963 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
2964 eol_type_t eol_type = str->eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2965
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2966 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2967 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2968 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2969 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2970 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2971 /* Previous character was first byte of Big5 char. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2972 if (BYTE_BIG5_TWO_BYTE_2_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2973 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2974 unsigned char b1, b2, b3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2975 DECODE_BIG5 (ch, c, b1, b2, b3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2976 Dynarr_add (dst, b1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2977 Dynarr_add (dst, b2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2978 Dynarr_add (dst, b3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2979 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2980 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2981 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2982 DECODE_ADD_BINARY_CHAR (ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2983 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2984 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2985 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2986 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2987 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2988 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2989 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2990 if (BYTE_BIG5_TWO_BYTE_1_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2991 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2992 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2993 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2994 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2995 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2996 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2997
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2998 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
2999
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3000 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3001 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3002 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3003
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3004 /* Convert internally-formatted data to Big5. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3005
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3006 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3007 encode_coding_big5 (Lstream *encoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3008 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3009 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3010 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3011 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3012 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3013 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3014 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3015
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3016 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3017 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3018 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3019 if (c == '\n')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3020 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3021 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3022 Dynarr_add (dst, '\r');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3023 if (eol_type != EOL_CR)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3024 Dynarr_add (dst, '\n');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3025 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3026 else if (BYTE_ASCII_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3027 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3028 /* ASCII. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3029 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3030 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3031 else if (BUFBYTE_LEADING_BYTE_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3032 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3033 if (c == LEADING_BYTE_CHINESE_BIG5_1 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3034 c == LEADING_BYTE_CHINESE_BIG5_2)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3035 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3036 /* A recognized leading byte. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3037 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3038 continue; /* not done with this character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3039 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3040 /* otherwise just ignore this character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3041 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3042 else if (ch == LEADING_BYTE_CHINESE_BIG5_1 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3043 ch == LEADING_BYTE_CHINESE_BIG5_2)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3044 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3045 /* Previous char was a recognized leading byte. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3046 ch = (ch << 8) | c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3047 continue; /* not done with this character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3048 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3049 else if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3050 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3051 /* Encountering second byte of a Big5 character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3052 unsigned char b1, b2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3053
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3054 ENCODE_BIG5 (ch >> 8, ch & 0xFF, c, b1, b2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3055 Dynarr_add (dst, b1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3056 Dynarr_add (dst, b2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3057 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3058
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3059 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3060 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3061
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3062 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3063 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3064 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3065
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3066
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3067 DEFUN ("decode-big5-char", Fdecode_big5_char, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3068 Decode a Big5 character CODE of BIG5 coding-system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3069 CODE is the character code in BIG5, a cons of two integers.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3070 Return the corresponding character.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3071 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3072 (code))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3073 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3074 unsigned char c1, c2, b1, b2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3075
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3076 CHECK_CONS (code);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3077 CHECK_INT (XCAR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3078 CHECK_INT (XCDR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3079 b1 = XINT (XCAR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3080 b2 = XINT (XCDR (code));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3081 if (BYTE_BIG5_TWO_BYTE_1_P (b1) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3082 BYTE_BIG5_TWO_BYTE_2_P (b2))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3083 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3084 int leading_byte;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3085 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3086 DECODE_BIG5 (b1, b2, leading_byte, c1, c2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3087 charset = CHARSET_BY_LEADING_BYTE (leading_byte);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3088 return make_char (MAKE_CHAR (charset, c1 & 0x7F, c2 & 0x7F));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3089 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3090 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3091 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3092 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3093
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3094 DEFUN ("encode-big5-char", Fencode_big5_char, 1, 1, 0, /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3095 Encode the Big5 character CH to BIG5 coding-system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3096 Return the corresponding character code in Big5.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3097 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3098 (ch))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3099 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3100 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3101 int c1, c2, b1, b2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3102
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3103 CHECK_CHAR_COERCE_INT (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3104 BREAKUP_CHAR (XCHAR (ch), charset, c1, c2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3105 if (EQ (charset, Vcharset_chinese_big5_1) ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3106 EQ (charset, Vcharset_chinese_big5_2))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3107 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3108 ENCODE_BIG5 (XCHARSET_LEADING_BYTE (charset), c1 | 0x80, c2 | 0x80,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3109 b1, b2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3110 return Fcons (make_int (b1), make_int (b2));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3111 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3112 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3113 return Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3114 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3115
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3116
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3117 /************************************************************************/
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3118 /* UCS-4 methods */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3119 /* */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3120 /* UCS-4 character codes are implemented as nonnegative integers. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3121 /* */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3122 /************************************************************************/
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3123
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3124 Lisp_Object ucs_to_mule_table[65536];
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3125 Lisp_Object mule_to_ucs_table;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3126
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3127 DEFUN ("set-ucs-char", Fset_ucs_char, 2, 2, 0, /*
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3128 Map UCS-4 code CODE to Mule character CHARACTER.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3129
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3130 Return T on success, NIL on failure.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3131 */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3132 (code, character))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3133 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3134 unsigned int c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3135
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3136 CHECK_CHAR (character);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3137 CHECK_INT (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3138 c = XINT (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3139
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3140 if (c < sizeof (ucs_to_mule_table))
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3141 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3142 ucs_to_mule_table[c] = character;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3143 return Qt;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3144 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3145 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3146 return Qnil;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3147 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3148
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3149 static Lisp_Object
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3150 ucs_to_char (unsigned long code)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3151 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3152 if (code < sizeof (ucs_to_mule_table))
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3153 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3154 return ucs_to_mule_table[code];
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3155 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3156 else if ((0xe00000 <= code) && (code <= 0xe00000 + 94 * 94 * 14))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3157 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3158 unsigned int c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3159
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3160 code -= 0xe00000;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3161 c = code % (94 * 94);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3162 return make_char
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3163 (MAKE_CHAR (CHARSET_BY_ATTRIBUTES
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3164 (CHARSET_TYPE_94X94, code / (94 * 94) + '@',
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3165 CHARSET_LEFT_TO_RIGHT),
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3166 c / 94 + 33, c % 94 + 33));
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3167 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3168 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3169 return Qnil;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3170 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3171
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3172 DEFUN ("ucs-char", Fucs_char, 1, 1, 0, /*
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3173 Return Mule character corresponding to UCS code CODE (a positive integer).
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3174 */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3175 (code))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3176 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3177 CHECK_NATNUM (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3178 return ucs_to_char (XINT (code));
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3179 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3180
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3181 DEFUN ("set-char-ucs", Fset_char_ucs, 2, 2, 0, /*
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3182 Map Mule character CHARACTER to UCS code CODE (a positive integer).
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3183 */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3184 (character, code))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3185 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3186 /* #### Isn't this gilding the lily? Fput_char_table checks its args.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3187 Fset_char_ucs is more restrictive on index arg, but should
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3188 check code arg in a char_table method. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3189 CHECK_CHAR (character);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3190 CHECK_NATNUM (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3191 return Fput_char_table (character, code, mule_to_ucs_table);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3192 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3193
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3194 DEFUN ("char-ucs", Fchar_ucs, 1, 1, 0, /*
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3195 Return the UCS code (a positive integer) corresponding to CHARACTER.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3196 */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3197 (character))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3198 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3199 return Fget_char_table (character, mule_to_ucs_table);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3200 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3201
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3202 /* Decode a UCS-4 character into a buffer. If the lookup fails, use
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3203 <GETA MARK> (U+3013) of JIS X 0208, which means correct character
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
3204 is not found, instead.
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3205 #### do something more appropriate (use blob?)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3206 Danger, Will Robinson! Data loss. Should we signal user? */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3207 static void
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3208 decode_ucs4 (unsigned long ch, unsigned_char_dynarr *dst)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3209 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3210 Lisp_Object chr = ucs_to_char (ch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3211
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3212 if (! NILP (chr))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3213 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3214 Bufbyte work[MAX_EMCHAR_LEN];
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3215 int len;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3216
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3217 ch = XCHAR (chr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3218 len = (ch < 128) ?
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3219 simple_set_charptr_emchar (work, ch) :
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3220 non_ascii_set_charptr_emchar (work, ch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3221 Dynarr_add_many (dst, work, len);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3222 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3223 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3224 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3225 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3226 Dynarr_add (dst, 34 + 128);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3227 Dynarr_add (dst, 46 + 128);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3228 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3229 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3230
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3231 static unsigned long
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3232 mule_char_to_ucs4 (Lisp_Object charset,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3233 unsigned char h, unsigned char l)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3234 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3235 Lisp_Object code
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3236 = Fget_char_table (make_char (MAKE_CHAR (charset, h & 127, l & 127)),
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3237 mule_to_ucs_table);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3238
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3239 if (INTP (code))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3240 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3241 return XINT (code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3242 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3243 else if ( (XCHARSET_DIMENSION (charset) == 2) &&
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3244 (XCHARSET_CHARS (charset) == 94) )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3245 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3246 unsigned char final = XCHARSET_FINAL (charset);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3247
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3248 if ( ('@' <= final) && (final < 0x7f) )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3249 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3250 return 0xe00000 + (final - '@') * 94 * 94
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3251 + ((h & 127) - 33) * 94 + (l & 127) - 33;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3252 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3253 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3254 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3255 return '?';
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3256 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3257 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3258 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3259 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3260 return '?';
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3261 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3262 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3263
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3264 static void
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3265 encode_ucs4 (Lisp_Object charset,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3266 unsigned char h, unsigned char l, unsigned_char_dynarr *dst)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3267 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3268 unsigned long code = mule_char_to_ucs4 (charset, h, l);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3269 Dynarr_add (dst, code >> 24);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3270 Dynarr_add (dst, (code >> 16) & 255);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3271 Dynarr_add (dst, (code >> 8) & 255);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3272 Dynarr_add (dst, code & 255);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3273 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3274
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3275 static int
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3276 detect_coding_ucs4 (struct detection_state *st, CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3277 unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3278 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3279 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3280 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3281 int c = *src++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3282 switch (st->ucs4.in_byte)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3283 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3284 case 0:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3285 if (c >= 128)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3286 return 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3287 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3288 st->ucs4.in_byte++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3289 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3290 case 3:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3291 st->ucs4.in_byte = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3292 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3293 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3294 st->ucs4.in_byte++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3295 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3296 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3297 return CODING_CATEGORY_UCS4_MASK;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3298 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3299
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3300 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3301 decode_coding_ucs4 (Lstream *decoding, CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3302 unsigned_char_dynarr *dst, unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3303 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3304 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3305 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3306 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3307
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3308 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3309 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3310 unsigned char c = *src++;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3311 switch (flags)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3312 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3313 case 0:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3314 ch = c;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3315 flags = 3;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3316 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3317 case 1:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3318 decode_ucs4 ( ( ch << 8 ) | c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3319 ch = 0;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3320 flags = 0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3321 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3322 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3323 ch = ( ch << 8 ) | c;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3324 flags--;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3325 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3326 }
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3327 if (flags & CODING_STATE_END)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3328 DECODE_OUTPUT_PARTIAL_CHAR (ch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3329
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3330 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3331 str->ch = ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3332 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3333
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3334 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3335 encode_coding_ucs4 (Lstream *encoding, CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3336 unsigned_char_dynarr *dst, unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3337 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3338 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3339 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3340 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3341 unsigned char char_boundary = str->iso2022.current_char_boundary;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3342 Lisp_Object charset = str->iso2022.current_charset;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3343
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3344 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3345 /* flags for handling composite chars. We do a little switcharoo
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3346 on the source while we're outputting the composite char. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3347 unsigned int saved_n = 0;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3348 CONST unsigned char *saved_src = NULL;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3349 int in_composite = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3350
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3351 back_to_square_n:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3352 #endif
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3353
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3354 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3355 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3356 unsigned char c = *src++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3357
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3358 if (BYTE_ASCII_P (c))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3359 { /* Processing ASCII character */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3360 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3361 encode_ucs4 (Vcharset_ascii, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3362 char_boundary = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3363 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3364 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3365 { /* Processing Leading Byte */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3366 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3367 charset = CHARSET_BY_LEADING_BYTE (c);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3368 if (LEADING_BYTE_PREFIX_P(c))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3369 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3370 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3371 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3372 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3373 { /* Processing Non-ASCII character */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3374 char_boundary = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3375 if (EQ (charset, Vcharset_control_1))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3376 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3377 encode_ucs4 (Vcharset_control_1, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3378 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3379 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3380 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3381 switch (XCHARSET_REP_BYTES (charset))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3382 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3383 case 2:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3384 encode_ucs4 (charset, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3385 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3386 case 3:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3387 if (XCHARSET_PRIVATE_P (charset))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3388 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3389 encode_ucs4 (charset, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3390 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3391 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3392 else if (ch)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3393 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3394 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3395 if (EQ (charset, Vcharset_composite))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3396 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3397 if (in_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3398 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3399 /* #### Bother! We don't know how to
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3400 handle this yet. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3401 Dynarr_add (dst, 0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3402 Dynarr_add (dst, 0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3403 Dynarr_add (dst, 0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3404 Dynarr_add (dst, '~');
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3405 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3406 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3407 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3408 Emchar emch = MAKE_CHAR (Vcharset_composite,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3409 ch & 0x7F, c & 0x7F);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3410 Lisp_Object lstr = composite_char_string (emch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3411 saved_n = n;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3412 saved_src = src;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3413 in_composite = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3414 src = XSTRING_DATA (lstr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3415 n = XSTRING_LENGTH (lstr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3416 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3417 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3418 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3419 #endif /* ENABLE_COMPOSITE_CHARS */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3420 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3421 encode_ucs4(charset, ch, c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3422 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3423 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3424 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3425 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3426 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3427 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3428 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3429 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3430 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3431 case 4:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3432 if (ch)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3433 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3434 encode_ucs4 (charset, ch, c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3435 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3436 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3437 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3438 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3439 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3440 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3441 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3442 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3443 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3444 abort ();
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3445 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3446 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3447 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3448 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3449
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3450 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3451 if (in_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3452 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3453 n = saved_n;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3454 src = saved_src;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3455 in_composite = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3456 goto back_to_square_n; /* Wheeeeeeeee ..... */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3457 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3458 #endif /* ENABLE_COMPOSITE_CHARS */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3459
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3460 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3461 str->ch = ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3462 str->iso2022.current_char_boundary = char_boundary;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3463 str->iso2022.current_charset = charset;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3464
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3465 /* Verbum caro factum est! */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3466 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3467
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3468
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3469 /************************************************************************/
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3470 /* UTF-8 methods */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3471 /************************************************************************/
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3472
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3473 static int
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3474 detect_coding_utf8 (struct detection_state *st, CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3475 unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3476 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3477 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3478 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3479 unsigned char c = *src++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3480 switch (st->utf8.in_byte)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3481 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3482 case 0:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3483 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3484 return 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3485 else if (c >= 0xfc)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3486 st->utf8.in_byte = 5;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3487 else if (c >= 0xf8)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3488 st->utf8.in_byte = 4;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3489 else if (c >= 0xf0)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3490 st->utf8.in_byte = 3;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3491 else if (c >= 0xe0)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3492 st->utf8.in_byte = 2;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3493 else if (c >= 0xc0)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3494 st->utf8.in_byte = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3495 else if (c >= 0x80)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3496 return 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3497 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3498 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3499 if ((c & 0xc0) != 0x80)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3500 return 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3501 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3502 st->utf8.in_byte--;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3503 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3504 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3505 return CODING_CATEGORY_UTF8_MASK;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3506 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3507
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3508 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3509 decode_coding_utf8 (Lstream *decoding, CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3510 unsigned_char_dynarr *dst, unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3511 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3512 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3513 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3514 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3515 eol_type_t eol_type = str->eol_type;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3516
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3517 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3518 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3519 unsigned char c = *src++;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3520 switch (flags)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3521 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3522 case 0:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3523 if ( c >= 0xfc )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3524 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3525 ch = c & 0x01;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3526 flags = 5;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3527 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3528 else if ( c >= 0xf8 )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3529 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3530 ch = c & 0x03;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3531 flags = 4;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3532 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3533 else if ( c >= 0xf0 )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3534 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3535 ch = c & 0x07;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3536 flags = 3;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3537 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3538 else if ( c >= 0xe0 )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3539 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3540 ch = c & 0x0f;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3541 flags = 2;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3542 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3543 else if ( c >= 0xc0 )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3544 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3545 ch = c & 0x1f;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3546 flags = 1;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3547 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3548 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3549 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3550 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3551 decode_ucs4 (c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3552 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3553 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3554 case 1:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3555 ch = ( ch << 6 ) | ( c & 0x3f );
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3556 decode_ucs4 (ch, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3557 ch = 0;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3558 flags = 0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3559 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3560 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3561 ch = ( ch << 6 ) | ( c & 0x3f );
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3562 flags--;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3563 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3564 label_continue_loop:;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3565 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3566
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3567 if (flags & CODING_STATE_END)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3568 DECODE_OUTPUT_PARTIAL_CHAR (ch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3569
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3570 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3571 str->ch = ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3572 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3573
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3574 static void
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3575 encode_utf8 (Lisp_Object charset,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3576 unsigned char h, unsigned char l, unsigned_char_dynarr *dst)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3577 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3578 unsigned long code = mule_char_to_ucs4 (charset, h, l);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3579 if ( code <= 0x7f )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3580 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3581 Dynarr_add (dst, code);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3582 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3583 else if ( code <= 0x7ff )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3584 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3585 Dynarr_add (dst, (code >> 6) | 0xc0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3586 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3587 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3588 else if ( code <= 0xffff )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3589 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3590 Dynarr_add (dst, (code >> 12) | 0xe0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3591 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3592 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3593 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3594 else if ( code <= 0x1fffff )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3595 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3596 Dynarr_add (dst, (code >> 18) | 0xf0);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3597 Dynarr_add (dst, ((code >> 12) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3598 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3599 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3600 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3601 else if ( code <= 0x3ffffff )
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3602 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3603 Dynarr_add (dst, (code >> 24) | 0xf8);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3604 Dynarr_add (dst, ((code >> 18) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3605 Dynarr_add (dst, ((code >> 12) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3606 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3607 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3608 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3609 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3610 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3611 Dynarr_add (dst, (code >> 30) | 0xfc);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3612 Dynarr_add (dst, ((code >> 24) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3613 Dynarr_add (dst, ((code >> 18) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3614 Dynarr_add (dst, ((code >> 12) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3615 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3616 Dynarr_add (dst, (code & 0x3f) | 0x80);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3617 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3618 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3619
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3620 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3621 encode_coding_utf8 (Lstream *encoding, CONST unsigned char *src,
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3622 unsigned_char_dynarr *dst, unsigned int n)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3623 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3624 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3625 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3626 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3627 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3628 unsigned char char_boundary = str->iso2022.current_char_boundary;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3629 Lisp_Object charset = str->iso2022.current_charset;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3630
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3631 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3632 /* flags for handling composite chars. We do a little switcharoo
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3633 on the source while we're outputting the composite char. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3634 unsigned int saved_n = 0;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3635 CONST unsigned char *saved_src = NULL;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3636 int in_composite = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3637
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3638 back_to_square_n:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3639 #endif /* ENABLE_COMPOSITE_CHARS */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
3640
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3641 while (n--)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3642 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3643 unsigned char c = *src++;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3644
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3645 if (BYTE_ASCII_P (c))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3646 { /* Processing ASCII character */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3647 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3648 if (c == '\n')
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3649 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3650 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3651 Dynarr_add (dst, '\r');
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3652 if (eol_type != EOL_CR)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3653 Dynarr_add (dst, c);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3654 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3655 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3656 encode_utf8 (Vcharset_ascii, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3657 char_boundary = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3658 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3659 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3660 { /* Processing Leading Byte */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3661 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3662 charset = CHARSET_BY_LEADING_BYTE (c);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3663 if (LEADING_BYTE_PREFIX_P(c))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3664 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3665 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3666 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3667 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3668 { /* Processing Non-ASCII character */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3669 char_boundary = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3670 if (EQ (charset, Vcharset_control_1))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3671 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3672 encode_utf8 (Vcharset_control_1, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3673 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3674 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3675 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3676 switch (XCHARSET_REP_BYTES (charset))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3677 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3678 case 2:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3679 encode_utf8 (charset, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3680 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3681 case 3:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3682 if (XCHARSET_PRIVATE_P (charset))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3683 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3684 encode_utf8 (charset, c, 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3685 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3686 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3687 else if (ch)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3688 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3689 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3690 if (EQ (charset, Vcharset_composite))
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3691 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3692 if (in_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3693 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3694 /* #### Bother! We don't know how to
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3695 handle this yet. */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3696 encode_utf8 (Vcharset_ascii, '~', 0, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3697 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3698 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3699 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3700 Emchar emch = MAKE_CHAR (Vcharset_composite,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3701 ch & 0x7F, c & 0x7F);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3702 Lisp_Object lstr = composite_char_string (emch);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3703 saved_n = n;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3704 saved_src = src;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3705 in_composite = 1;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3706 src = XSTRING_DATA (lstr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3707 n = XSTRING_LENGTH (lstr);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3708 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3709 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3710 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3711 #endif /* ENABLE_COMPOSITE_CHARS */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3712 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3713 encode_utf8 (charset, ch, c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3714 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3715 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3716 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3717 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3718 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3719 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3720 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3721 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3722 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3723 case 4:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3724 if (ch)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3725 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3726 encode_utf8 (charset, ch, c, dst);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3727 ch = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3728 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3729 else
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3730 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3731 ch = c;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3732 char_boundary = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3733 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3734 break;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3735 default:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3736 abort ();
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3737 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3738 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3739 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3740 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3741
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3742 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3743 if (in_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3744 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3745 n = saved_n;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3746 src = saved_src;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3747 in_composite = 0;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3748 goto back_to_square_n; /* Wheeeeeeeee ..... */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3749 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3750 #endif
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3751
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3752 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3753 str->ch = ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3754 str->iso2022.current_char_boundary = char_boundary;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3755 str->iso2022.current_charset = charset;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3756
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3757 /* Verbum caro factum est! */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3758 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3759
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3760
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3761 /************************************************************************/
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3762 /* ISO2022 methods */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3763 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3764
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3765 /* The following note describes the coding system ISO2022 briefly.
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3766 Since the intention of this note is to help understand the
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3767 functions in this file, some parts are NOT ACCURATE or OVERLY
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3768 SIMPLIFIED. For thorough understanding, please refer to the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3769 original document of ISO2022.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3770
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3771 ISO2022 provides many mechanisms to encode several character sets
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3772 in 7-bit and 8-bit environments. For 7-bit environments, all text
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3773 is encoded using bytes less than 128. This may make the encoded
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3774 text a little bit longer, but the text passes more easily through
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3775 several gateways, some of which strip off MSB (Most Signigant Bit).
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3776
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3777 There are two kinds of character sets: control character set and
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3778 graphic character set. The former contains control characters such
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3779 as `newline' and `escape' to provide control functions (control
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3780 functions are also provided by escape sequences). The latter
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3781 contains graphic characters such as 'A' and '-'. Emacs recognizes
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3782 two control character sets and many graphic character sets.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3783
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3784 Graphic character sets are classified into one of the following
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3785 four classes, according to the number of bytes (DIMENSION) and
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3786 number of characters in one dimension (CHARS) of the set:
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3787 - DIMENSION1_CHARS94
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3788 - DIMENSION1_CHARS96
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3789 - DIMENSION2_CHARS94
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3790 - DIMENSION2_CHARS96
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3791
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3792 In addition, each character set is assigned an identification tag,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3793 unique for each set, called "final character" (denoted as <F>
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3794 hereafter). The <F> of each character set is decided by ECMA(*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3795 when it is registered in ISO. The code range of <F> is 0x30..0x7F
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3796 (0x30..0x3F are for private use only).
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3797
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3798 Note (*): ECMA = European Computer Manufacturers Association
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3799
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3800 Here are examples of graphic character set [NAME(<F>)]:
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3801 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ...
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3802 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ...
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3803 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ...
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3804 o DIMENSION2_CHARS96 -- none for the moment
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3805
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3806 A code area (1 byte = 8 bits) is divided into 4 areas, C0, GL, C1, and GR.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3807 C0 [0x00..0x1F] -- control character plane 0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3808 GL [0x20..0x7F] -- graphic character plane 0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3809 C1 [0x80..0x9F] -- control character plane 1
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3810 GR [0xA0..0xFF] -- graphic character plane 1
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3811
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3812 A control character set is directly designated and invoked to C0 or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3813 C1 by an escape sequence. The most common case is that:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3814 - ISO646's control character set is designated/invoked to C0, and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3815 - ISO6429's control character set is designated/invoked to C1,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3816 and usually these designations/invocations are omitted in encoded
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3817 text. In a 7-bit environment, only C0 can be used, and a control
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3818 character for C1 is encoded by an appropriate escape sequence to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3819 fit into the environment. All control characters for C1 are
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3820 defined to have corresponding escape sequences.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3821
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3822 A graphic character set is at first designated to one of four
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3823 graphic registers (G0 through G3), then these graphic registers are
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3824 invoked to GL or GR. These designations and invocations can be
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3825 done independently. The most common case is that G0 is invoked to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3826 GL, G1 is invoked to GR, and ASCII is designated to G0. Usually
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3827 these invocations and designations are omitted in encoded text.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3828 In a 7-bit environment, only GL can be used.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3829
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3830 When a graphic character set of CHARS94 is invoked to GL, codes
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3831 0x20 and 0x7F of the GL area work as control characters SPACE and
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3832 DEL respectively, and codes 0xA0 and 0xFF of the GR area should not
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3833 be used.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3834
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3835 There are two ways of invocation: locking-shift and single-shift.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3836 With locking-shift, the invocation lasts until the next different
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3837 invocation, whereas with single-shift, the invocation affects the
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3838 following character only and doesn't affect the locking-shift
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3839 state. Invocations are done by the following control characters or
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3840 escape sequences:
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3841
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3842 ----------------------------------------------------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3843 abbrev function cntrl escape seq description
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3844 ----------------------------------------------------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3845 SI/LS0 (shift-in) 0x0F none invoke G0 into GL
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3846 SO/LS1 (shift-out) 0x0E none invoke G1 into GL
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3847 LS2 (locking-shift-2) none ESC 'n' invoke G2 into GL
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3848 LS3 (locking-shift-3) none ESC 'o' invoke G3 into GL
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3849 LS1R (locking-shift-1 right) none ESC '~' invoke G1 into GR (*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3850 LS2R (locking-shift-2 right) none ESC '}' invoke G2 into GR (*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3851 LS3R (locking-shift 3 right) none ESC '|' invoke G3 into GR (*)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3852 SS2 (single-shift-2) 0x8E ESC 'N' invoke G2 for one char
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3853 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3854 ----------------------------------------------------------------------
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3855 (*) These are not used by any known coding system.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3856
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3857 Control characters for these functions are defined by macros
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3858 ISO_CODE_XXX in `coding.h'.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3859
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3860 Designations are done by the following escape sequences:
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3861 ----------------------------------------------------------------------
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3862 escape sequence description
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3863 ----------------------------------------------------------------------
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3864 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3865 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3866 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3867 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3868 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3869 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3870 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3871 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3872 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3873 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3874 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3875 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3876 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3877 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3878 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3879 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3880 ----------------------------------------------------------------------
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3881
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3882 In this list, "DIMENSION1_CHARS94<F>" means a graphic character set
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3883 of dimension 1, chars 94, and final character <F>, etc...
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3884
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3885 Note (*): Although these designations are not allowed in ISO2022,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3886 Emacs accepts them on decoding, and produces them on encoding
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3887 CHARS96 character sets in a coding system which is characterized as
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3888 7-bit environment, non-locking-shift, and non-single-shift.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3889
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3890 Note (**): If <F> is '@', 'A', or 'B', the intermediate character
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3891 '(' can be omitted. We refer to this as "short-form" hereafter.
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3892
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3893 Now you may notice that there are a lot of ways for encoding the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3894 same multilingual text in ISO2022. Actually, there exist many
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3895 coding systems such as Compound Text (used in X11's inter client
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3896 communication, ISO-2022-JP (used in Japanese internet), ISO-2022-KR
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3897 (used in Korean internet), EUC (Extended UNIX Code, used in Asian
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3898 localized platforms), and all of these are variants of ISO2022.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3899
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3900 In addition to the above, Emacs handles two more kinds of escape
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3901 sequences: ISO6429's direction specification and Emacs' private
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3902 sequence for specifying character composition.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3903
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3904 ISO6429's direction specification takes the following form:
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3905 o CSI ']' -- end of the current direction
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3906 o CSI '0' ']' -- end of the current direction
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3907 o CSI '1' ']' -- start of left-to-right text
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3908 o CSI '2' ']' -- start of right-to-left text
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3909 The control character CSI (0x9B: control sequence introducer) is
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3910 abbreviated to the escape sequence ESC '[' in a 7-bit environment.
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3911
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3912 Character composition specification takes the following form:
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3913 o ESC '0' -- start character composition
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3914 o ESC '1' -- end character composition
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3915 Since these are not standard escape sequences of any ISO standard,
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3916 their use with these meanings is restricted to Emacs only. */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3917
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3918 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3919 reset_iso2022 (Lisp_Object coding_system, struct iso2022_decoder *iso)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3920 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3921 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3922
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3923 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3924 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3925 if (!NILP (coding_system))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3926 iso->charset[i] =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3927 XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3928 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3929 iso->charset[i] = Qt;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3930 iso->invalid_designated[i] = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3931 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3932 iso->esc = ISO_ESC_NOTHING;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3933 iso->esc_bytes_index = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3934 iso->register_left = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3935 iso->register_right = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3936 iso->switched_dir_and_no_valid_charset_yet = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3937 iso->invalid_switch_dir = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3938 iso->output_direction_sequence = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3939 iso->output_literally = 0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3940 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3941 if (iso->composite_chars)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3942 Dynarr_reset (iso->composite_chars);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
3943 #endif
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3944 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3945
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3946 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3947 fit_to_be_escape_quoted (unsigned char c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3948 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3949 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3950 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3951 case ISO_CODE_ESC:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3952 case ISO_CODE_CSI:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3953 case ISO_CODE_SS2:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3954 case ISO_CODE_SS3:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3955 case ISO_CODE_SO:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3956 case ISO_CODE_SI:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3957 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3958
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3959 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3960 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3961 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3962 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3963
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3964 /* Parse one byte of an ISO2022 escape sequence.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3965 If the result is an invalid escape sequence, return 0 and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3966 do not change anything in STR. Otherwise, if the result is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3967 an incomplete escape sequence, update ISO2022.ESC and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3968 ISO2022.ESC_BYTES and return -1. Otherwise, update
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3969 all the state variables (but not ISO2022.ESC_BYTES) and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3970 return 1.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3971
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3972 If CHECK_INVALID_CHARSETS is non-zero, check for designation
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3973 or invocation of an invalid character set and treat that as
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3974 an unrecognized escape sequence. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3975
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3976 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3977 parse_iso2022_esc (Lisp_Object codesys, struct iso2022_decoder *iso,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3978 unsigned char c, unsigned int *flags,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3979 int check_invalid_charsets)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3980 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3981 /* (1) If we're at the end of a designation sequence, CS is the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3982 charset being designated and REG is the register to designate
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3983 it to.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3984
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3985 (2) If we're at the end of a locking-shift sequence, REG is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3986 the register to invoke and HALF (0 == left, 1 == right) is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3987 the half to invoke it into.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3988
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3989 (3) If we're at the end of a single-shift sequence, REG is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3990 the register to invoke. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3991 Lisp_Object cs = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3992 int reg, half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3993
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3994 /* NOTE: This code does goto's all over the fucking place.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3995 The reason for this is that we're basically implementing
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3996 a state machine here, and hierarchical languages like C
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3997 don't really provide a clean way of doing this. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3998
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
3999 if (! (*flags & CODING_STATE_ESCAPE))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4000 /* At beginning of escape sequence; we need to reset our
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4001 escape-state variables. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4002 iso->esc = ISO_ESC_NOTHING;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4003
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4004 iso->output_literally = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4005 iso->output_direction_sequence = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4006
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4007 switch (iso->esc)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4008 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4009 case ISO_ESC_NOTHING:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4010 iso->esc_bytes_index = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4011 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4012 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4013 case ISO_CODE_ESC: /* Start escape sequence */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4014 *flags |= CODING_STATE_ESCAPE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4015 iso->esc = ISO_ESC;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4016 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4017
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4018 case ISO_CODE_CSI: /* ISO6429 (specifying directionality) */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4019 *flags |= CODING_STATE_ESCAPE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4020 iso->esc = ISO_ESC_5_11;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4021 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4022
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4023 case ISO_CODE_SO: /* locking shift 1 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4024 reg = 1; half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4025 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4026 case ISO_CODE_SI: /* locking shift 0 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4027 reg = 0; half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4028 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4029
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4030 case ISO_CODE_SS2: /* single shift */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4031 reg = 2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4032 goto single_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4033 case ISO_CODE_SS3: /* single shift */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4034 reg = 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4035 goto single_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4036
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4037 default: /* Other control characters */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4038 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4039 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4040
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4041 case ISO_ESC:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4042 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4043 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4044 /**** single shift ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4045
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4046 case 'N': /* single shift 2 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4047 reg = 2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4048 goto single_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4049 case 'O': /* single shift 3 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4050 reg = 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4051 goto single_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4052
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4053 /**** locking shift ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4054
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4055 case '~': /* locking shift 1 right */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4056 reg = 1; half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4057 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4058 case 'n': /* locking shift 2 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4059 reg = 2; half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4060 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4061 case '}': /* locking shift 2 right */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4062 reg = 2; half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4063 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4064 case 'o': /* locking shift 3 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4065 reg = 3; half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4066 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4067 case '|': /* locking shift 3 right */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4068 reg = 3; half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4069 goto locking_shift;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4070
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4071 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4072 /**** composite ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4073
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4074 case '0':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4075 iso->esc = ISO_ESC_START_COMPOSITE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4076 *flags = (*flags & CODING_STATE_ISO2022_LOCK) |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4077 CODING_STATE_COMPOSITE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4078 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4079
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4080 case '1':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4081 iso->esc = ISO_ESC_END_COMPOSITE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4082 *flags = (*flags & CODING_STATE_ISO2022_LOCK) &
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4083 ~CODING_STATE_COMPOSITE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4084 return 1;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4085 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4086
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4087 /**** directionality ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4088
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4089 case '[':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4090 iso->esc = ISO_ESC_5_11;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4091 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4092
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4093 /**** designation ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4094
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4095 case '$': /* multibyte charset prefix */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4096 iso->esc = ISO_ESC_2_4;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4097 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4098
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4099 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4100 if (0x28 <= c && c <= 0x2F)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4101 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4102 iso->esc = (enum iso_esc_flag) (c - 0x28 + ISO_ESC_2_8);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4103 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4104 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4105
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4106 /* This function is called with CODESYS equal to nil when
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4107 doing coding-system detection. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4108 if (!NILP (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4109 && XCODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4110 && fit_to_be_escape_quoted (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4111 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4112 iso->esc = ISO_ESC_LITERAL;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4113 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4114 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4115 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4116
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4117 /* bzzzt! */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4118 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4119 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4120
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4121
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4122
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4123 /**** directionality ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4124
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4125 case ISO_ESC_5_11: /* ISO6429 direction control */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4126 if (c == ']')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4127 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4128 *flags &= (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4129 goto directionality;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4130 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4131 if (c == '0') iso->esc = ISO_ESC_5_11_0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4132 else if (c == '1') iso->esc = ISO_ESC_5_11_1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4133 else if (c == '2') iso->esc = ISO_ESC_5_11_2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4134 else return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4135 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4136
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4137 case ISO_ESC_5_11_0:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4138 if (c == ']')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4139 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4140 *flags &= (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4141 goto directionality;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4142 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4143 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4144
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4145 case ISO_ESC_5_11_1:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4146 if (c == ']')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4147 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4148 *flags = (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4149 goto directionality;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4150 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4151 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4152
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4153 case ISO_ESC_5_11_2:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4154 if (c == ']')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4155 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4156 *flags = (*flags & CODING_STATE_ISO2022_LOCK) | CODING_STATE_R2L;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4157 goto directionality;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4158 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4159 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4160
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4161 directionality:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4162 iso->esc = ISO_ESC_DIRECTIONALITY;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4163 /* Various junk here to attempt to preserve the direction sequences
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4164 literally in the text if they would otherwise be swallowed due
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4165 to invalid designations that don't show up as actual charset
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4166 changes in the text. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4167 if (iso->invalid_switch_dir)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4168 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4169 /* We already inserted a direction switch literally into the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4170 text. We assume (#### this may not be right) that the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4171 next direction switch is the one going the other way,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4172 and we need to output that literally as well. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4173 iso->output_literally = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4174 iso->invalid_switch_dir = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4175 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4176 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4177 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4178 int jj;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4179
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4180 /* If we are in the thrall of an invalid designation,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4181 then stick the directionality sequence literally into the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4182 output stream so it ends up in the original text again. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4183 for (jj = 0; jj < 4; jj++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4184 if (iso->invalid_designated[jj])
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4185 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4186 if (jj < 4)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4187 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4188 iso->output_literally = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4189 iso->invalid_switch_dir = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4190 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4191 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4192 /* Indicate that we haven't yet seen a valid designation,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4193 so that if a switch-dir is directly followed by an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4194 invalid designation, both get inserted literally. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4195 iso->switched_dir_and_no_valid_charset_yet = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4196 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4197 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4198
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4199
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4200 /**** designation ****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4201
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4202 case ISO_ESC_2_4:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4203 if (0x28 <= c && c <= 0x2F)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4204 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4205 iso->esc = (enum iso_esc_flag) (c - 0x28 + ISO_ESC_2_4_8);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4206 goto not_done;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4207 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4208 if (0x40 <= c && c <= 0x42)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4209 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4210 cs = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_94X94, c,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4211 *flags & CODING_STATE_R2L ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4212 CHARSET_RIGHT_TO_LEFT :
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4213 CHARSET_LEFT_TO_RIGHT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4214 reg = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4215 goto designated;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4216 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4217 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4218
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4219 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4220 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4221 int type =-1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4222
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4223 if (c < '0' || c > '~')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4224 return 0; /* bad final byte */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4225
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4226 if (iso->esc >= ISO_ESC_2_8 &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4227 iso->esc <= ISO_ESC_2_15)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4228 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4229 type = ((iso->esc >= ISO_ESC_2_12) ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4230 CHARSET_TYPE_96 : CHARSET_TYPE_94);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4231 reg = (iso->esc - ISO_ESC_2_8) & 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4232 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4233 else if (iso->esc >= ISO_ESC_2_4_8 &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4234 iso->esc <= ISO_ESC_2_4_15)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4235 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4236 type = ((iso->esc >= ISO_ESC_2_4_12) ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4237 CHARSET_TYPE_96X96 : CHARSET_TYPE_94X94);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4238 reg = (iso->esc - ISO_ESC_2_4_8) & 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4239 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4240 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4241 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4242 /* Can this ever be reached? -slb */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4243 abort();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4244 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4245
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4246 cs = CHARSET_BY_ATTRIBUTES (type, c,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4247 *flags & CODING_STATE_R2L ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4248 CHARSET_RIGHT_TO_LEFT :
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4249 CHARSET_LEFT_TO_RIGHT);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4250 goto designated;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4251 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4252 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4253
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4254 not_done:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4255 iso->esc_bytes[iso->esc_bytes_index++] = (unsigned char) c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4256 return -1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4257
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4258 single_shift:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4259 if (check_invalid_charsets && !CHARSETP (iso->charset[reg]))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4260 /* can't invoke something that ain't there. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4261 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4262 iso->esc = ISO_ESC_SINGLE_SHIFT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4263 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4264 if (reg == 2)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4265 *flags |= CODING_STATE_SS2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4266 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4267 *flags |= CODING_STATE_SS3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4268 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4269
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4270 locking_shift:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4271 if (check_invalid_charsets &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4272 !CHARSETP (iso->charset[reg]))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4273 /* can't invoke something that ain't there. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4274 return 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4275 if (half)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4276 iso->register_right = reg;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4277 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4278 iso->register_left = reg;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4279 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4280 iso->esc = ISO_ESC_LOCKING_SHIFT;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4281 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4282
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4283 designated:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4284 if (NILP (cs) && check_invalid_charsets)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4285 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4286 iso->invalid_designated[reg] = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4287 iso->charset[reg] = Vcharset_ascii;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4288 iso->esc = ISO_ESC_DESIGNATE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4289 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4290 iso->output_literally = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4291 if (iso->switched_dir_and_no_valid_charset_yet)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4292 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4293 /* We encountered a switch-direction followed by an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4294 invalid designation. Ensure that the switch-direction
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4295 gets outputted; otherwise it will probably get eaten
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4296 when the text is written out again. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4297 iso->switched_dir_and_no_valid_charset_yet = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4298 iso->output_direction_sequence = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4299 /* And make sure that the switch-dir going the other
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4300 way gets outputted, as well. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4301 iso->invalid_switch_dir = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4302 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4303 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4304 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4305 /* This function is called with CODESYS equal to nil when
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4306 doing coding-system detection. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4307 if (!NILP (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4308 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4309 charset_conversion_spec_dynarr *dyn =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4310 XCODING_SYSTEM (codesys)->iso2022.input_conv;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4311
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4312 if (dyn)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4313 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4314 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4315
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4316 for (i = 0; i < Dynarr_length (dyn); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4317 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4318 struct charset_conversion_spec *spec = Dynarr_atp (dyn, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4319 if (EQ (cs, spec->from_charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4320 cs = spec->to_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4321 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4322 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4323 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4324
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4325 iso->charset[reg] = cs;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4326 iso->esc = ISO_ESC_DESIGNATE;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4327 *flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4328 if (iso->invalid_designated[reg])
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4329 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4330 iso->invalid_designated[reg] = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4331 iso->output_literally = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4332 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4333 if (iso->switched_dir_and_no_valid_charset_yet)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4334 iso->switched_dir_and_no_valid_charset_yet = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4335 return 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4336 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4337
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4338 static int
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
4339 detect_coding_iso2022 (struct detection_state *st, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4340 unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4341 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4342 int mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4343
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4344 /* #### There are serious deficiencies in the recognition mechanism
388
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4345 here. This needs to be much smarter if it's going to cut it.
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4346 The sequence "\xff\x0f" is currently detected as LOCK_SHIFT while
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4347 it should be detected as Latin-1.
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4348 All the ISO2022 stuff in this file should be synced up with the
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4349 code from FSF Emacs-20.4, in which Mule should be more or less stable.
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4350 Perhaps we should wait till R2L works in FSF Emacs? */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4351
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4352 if (!st->iso2022.initted)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4353 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4354 reset_iso2022 (Qnil, &st->iso2022.iso);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4355 st->iso2022.mask = (CODING_CATEGORY_ISO_7_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4356 CODING_CATEGORY_ISO_8_DESIGNATE_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4357 CODING_CATEGORY_ISO_8_1_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4358 CODING_CATEGORY_ISO_8_2_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4359 CODING_CATEGORY_ISO_LOCK_SHIFT_MASK);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4360 st->iso2022.flags = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4361 st->iso2022.high_byte_count = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4362 st->iso2022.saw_single_shift = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4363 st->iso2022.initted = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4364 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4365
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4366 mask = st->iso2022.mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4367
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4368 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4369 {
388
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4370 int c = *src++;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4371 if (c >= 0xA0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4372 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4373 mask &= ~CODING_CATEGORY_ISO_7_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4374 st->iso2022.high_byte_count++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4375 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4376 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4377 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4378 if (st->iso2022.high_byte_count && !st->iso2022.saw_single_shift)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4379 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4380 if (st->iso2022.high_byte_count & 1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4381 /* odd number of high bytes; assume not iso-8-2 */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4382 mask &= ~CODING_CATEGORY_ISO_8_2_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4383 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4384 st->iso2022.high_byte_count = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4385 st->iso2022.saw_single_shift = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4386 if (c > 0x80)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4387 mask &= ~CODING_CATEGORY_ISO_7_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4388 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4389 if (!(st->iso2022.flags & CODING_STATE_ESCAPE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4390 && (BYTE_C0_P (c) || BYTE_C1_P (c)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4391 { /* control chars */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4392 switch (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4393 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4394 /* Allow and ignore control characters that you might
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4395 reasonably see in a text file */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4396 case '\r':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4397 case '\n':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4398 case '\t':
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4399 case 7: /* bell */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4400 case 8: /* backspace */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4401 case 11: /* vertical tab */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4402 case 12: /* form feed */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4403 case 26: /* MS-DOS C-z junk */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4404 case 31: /* '^_' -- for info */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4405 goto label_continue_loop;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4406
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4407 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4408 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4409 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4410 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4411
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4412 if ((st->iso2022.flags & CODING_STATE_ESCAPE) || BYTE_C0_P (c)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4413 || BYTE_C1_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4414 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4415 if (parse_iso2022_esc (Qnil, &st->iso2022.iso, c,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4416 &st->iso2022.flags, 0))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4417 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4418 switch (st->iso2022.iso.esc)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4419 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4420 case ISO_ESC_DESIGNATE:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4421 mask &= ~CODING_CATEGORY_ISO_8_1_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4422 mask &= ~CODING_CATEGORY_ISO_8_2_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4423 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4424 case ISO_ESC_LOCKING_SHIFT:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4425 mask = CODING_CATEGORY_ISO_LOCK_SHIFT_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4426 goto ran_out_of_chars;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4427 case ISO_ESC_SINGLE_SHIFT:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4428 mask &= ~CODING_CATEGORY_ISO_8_DESIGNATE_MASK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4429 st->iso2022.saw_single_shift = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4430 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4431 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4432 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4433 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4434 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4435 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4436 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4437 mask = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4438 goto ran_out_of_chars;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4439 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4440 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4441 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4442 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4443
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4444 ran_out_of_chars:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4445
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4446 return mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4447 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4448
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4449 static int
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4450 postprocess_iso2022_mask (int mask)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4451 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4452 /* #### kind of cheesy */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4453 /* If seven-bit ISO is allowed, then assume that the encoding is
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4454 entirely seven-bit and turn off the eight-bit ones. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4455 if (mask & CODING_CATEGORY_ISO_7_MASK)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4456 mask &= ~ (CODING_CATEGORY_ISO_8_DESIGNATE_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4457 CODING_CATEGORY_ISO_8_1_MASK |
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4458 CODING_CATEGORY_ISO_8_2_MASK);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4459 return mask;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4460 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4461
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4462 /* If FLAGS is a null pointer or specifies right-to-left motion,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4463 output a switch-dir-to-left-to-right sequence to DST.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4464 Also update FLAGS if it is not a null pointer.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4465 If INTERNAL_P is set, we are outputting in internal format and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4466 need to handle the CSI differently. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4467
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4468 static void
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4469 restore_left_to_right_direction (Lisp_Coding_System *codesys,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4470 unsigned_char_dynarr *dst,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4471 unsigned int *flags,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4472 int internal_p)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4473 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4474 if (!flags || (*flags & CODING_STATE_R2L))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4475 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4476 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4477 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4478 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4479 Dynarr_add (dst, '[');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4480 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4481 else if (internal_p)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4482 DECODE_ADD_BINARY_CHAR (ISO_CODE_CSI, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4483 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4484 Dynarr_add (dst, ISO_CODE_CSI);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4485 Dynarr_add (dst, '0');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4486 Dynarr_add (dst, ']');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4487 if (flags)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4488 *flags &= ~CODING_STATE_R2L;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4489 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4490 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4491
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4492 /* If FLAGS is a null pointer or specifies a direction different from
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4493 DIRECTION (which should be either CHARSET_RIGHT_TO_LEFT or
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4494 CHARSET_LEFT_TO_RIGHT), output the appropriate switch-dir escape
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4495 sequence to DST. Also update FLAGS if it is not a null pointer.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4496 If INTERNAL_P is set, we are outputting in internal format and
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4497 need to handle the CSI differently. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4498
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4499 static void
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4500 ensure_correct_direction (int direction, Lisp_Coding_System *codesys,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4501 unsigned_char_dynarr *dst, unsigned int *flags,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4502 int internal_p)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4503 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4504 if ((!flags || (*flags & CODING_STATE_R2L)) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4505 direction == CHARSET_LEFT_TO_RIGHT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4506 restore_left_to_right_direction (codesys, dst, flags, internal_p);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4507 else if (!CODING_SYSTEM_ISO2022_NO_ISO6429 (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4508 && (!flags || !(*flags & CODING_STATE_R2L)) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4509 direction == CHARSET_RIGHT_TO_LEFT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4510 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4511 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4512 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4513 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4514 Dynarr_add (dst, '[');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4515 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4516 else if (internal_p)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4517 DECODE_ADD_BINARY_CHAR (ISO_CODE_CSI, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4518 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4519 Dynarr_add (dst, ISO_CODE_CSI);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4520 Dynarr_add (dst, '2');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4521 Dynarr_add (dst, ']');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4522 if (flags)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4523 *flags |= CODING_STATE_R2L;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4524 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4525 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4526
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4527 /* Convert ISO2022-format data to internal format. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4528
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4529 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
4530 decode_coding_iso2022 (Lstream *decoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4531 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4532 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4533 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4534 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4535 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4536 eol_type_t eol_type = str->eol_type;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4537 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4538 unsigned_char_dynarr *real_dst = dst;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4539 #endif
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4540 Lisp_Object coding_system;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4541
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4542 XSETCODING_SYSTEM (coding_system, str->codesys);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4543
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4544 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4545 if (flags & CODING_STATE_COMPOSITE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4546 dst = str->iso2022.composite_chars;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4547 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4548
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4549 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4550 {
388
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4551 unsigned char c = *src++;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4552 if (flags & CODING_STATE_ESCAPE)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4553 { /* Within ESC sequence */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4554 int retval = parse_iso2022_esc (coding_system, &str->iso2022,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4555 c, &flags, 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4556
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4557 if (retval)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4558 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4559 switch (str->iso2022.esc)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4560 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4561 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4562 case ISO_ESC_START_COMPOSITE:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4563 if (str->iso2022.composite_chars)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4564 Dynarr_reset (str->iso2022.composite_chars);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4565 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4566 str->iso2022.composite_chars = Dynarr_new (unsigned_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4567 dst = str->iso2022.composite_chars;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4568 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4569 case ISO_ESC_END_COMPOSITE:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4570 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4571 Bufbyte comstr[MAX_EMCHAR_LEN];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4572 Bytecount len;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4573 Emchar emch = lookup_composite_char (Dynarr_atp (dst, 0),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4574 Dynarr_length (dst));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4575 dst = real_dst;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4576 len = set_charptr_emchar (comstr, emch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4577 Dynarr_add_many (dst, comstr, len);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4578 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4579 }
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4580 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4581
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4582 case ISO_ESC_LITERAL:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4583 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4584 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4585
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4586 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4587 /* Everything else handled already */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4588 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4589 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4590 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4591
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4592 /* Attempted error recovery. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4593 if (str->iso2022.output_direction_sequence)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4594 ensure_correct_direction (flags & CODING_STATE_R2L ?
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4595 CHARSET_RIGHT_TO_LEFT :
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4596 CHARSET_LEFT_TO_RIGHT,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4597 str->codesys, dst, 0, 1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4598 /* More error recovery. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4599 if (!retval || str->iso2022.output_literally)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4600 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4601 /* Output the (possibly invalid) sequence */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4602 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4603 for (i = 0; i < str->iso2022.esc_bytes_index; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4604 DECODE_ADD_BINARY_CHAR (str->iso2022.esc_bytes[i], dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4605 flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4606 if (!retval)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4607 n++, src--;/* Repeat the loop with the same character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4608 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4609 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4610 /* No sense in reprocessing the final byte of the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4611 escape sequence; it could mess things up anyway.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4612 Just add it now. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4613 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4614 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4615 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4616 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4617 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4618 else if (BYTE_C0_P (c) || BYTE_C1_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4619 { /* Control characters */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4620
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4621 /***** Error-handling *****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4622
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4623 /* If we were in the middle of a character, dump out the
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4624 partial character. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4625 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4626
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4627 /* If we just saw a single-shift character, dump it out.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4628 This may dump out the wrong sort of single-shift character,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4629 but least it will give an indication that something went
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4630 wrong. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4631 if (flags & CODING_STATE_SS2)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4632 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4633 DECODE_ADD_BINARY_CHAR (ISO_CODE_SS2, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4634 flags &= ~CODING_STATE_SS2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4635 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4636 if (flags & CODING_STATE_SS3)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4637 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4638 DECODE_ADD_BINARY_CHAR (ISO_CODE_SS3, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4639 flags &= ~CODING_STATE_SS3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4640 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4641
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4642 /***** Now handle the control characters. *****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4643
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4644 /* Handle CR/LF */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4645 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4646
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4647 flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4648
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4649 if (!parse_iso2022_esc (coding_system, &str->iso2022, c, &flags, 1))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4650 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4651 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4652 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4653 { /* Graphic characters */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4654 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4655 int lb;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4656 int reg;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4657
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4658 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4659
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4660 /* Now determine the charset. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4661 reg = ((flags & CODING_STATE_SS2) ? 2
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4662 : (flags & CODING_STATE_SS3) ? 3
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4663 : !BYTE_ASCII_P (c) ? str->iso2022.register_right
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4664 : str->iso2022.register_left);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4665 charset = str->iso2022.charset[reg];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4666
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4667 /* Error checking: */
388
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4668 if (! CHARSETP (charset)
aabb7f5b1c81 Import from CVS: tag r21-2-9
cvs
parents: 380
diff changeset
4669 || str->iso2022.invalid_designated[reg]
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4670 || (((c & 0x7F) == ' ' || (c & 0x7F) == ISO_CODE_DEL)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4671 && XCHARSET_CHARS (charset) == 94))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4672 /* Mrmph. We are trying to invoke a register that has no
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4673 or an invalid charset in it, or trying to add a character
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4674 outside the range of the charset. Insert that char literally
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4675 to preserve it for the output. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4676 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4677 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4678 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4679 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4680
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4681 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4682 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4683 /* Things are probably hunky-dorey. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4684
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4685 /* Fetch reverse charset, maybe. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4686 if (((flags & CODING_STATE_R2L) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4687 XCHARSET_DIRECTION (charset) == CHARSET_LEFT_TO_RIGHT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4688 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4689 (!(flags & CODING_STATE_R2L) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4690 XCHARSET_DIRECTION (charset) == CHARSET_RIGHT_TO_LEFT))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4691 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4692 Lisp_Object new_charset =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4693 XCHARSET_REVERSE_DIRECTION_CHARSET (charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4694 if (!NILP (new_charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4695 charset = new_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4696 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4697
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4698 lb = XCHARSET_LEADING_BYTE (charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4699 switch (XCHARSET_REP_BYTES (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4700 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4701 case 1: /* ASCII */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4702 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4703 Dynarr_add (dst, c & 0x7F);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4704 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4705
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4706 case 2: /* one-byte official */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4707 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4708 Dynarr_add (dst, lb);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4709 Dynarr_add (dst, c | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4710 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4711
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4712 case 3: /* one-byte private or two-byte official */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4713 if (XCHARSET_PRIVATE_P (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4714 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4715 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4716 Dynarr_add (dst, PRE_LEADING_BYTE_PRIVATE_1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4717 Dynarr_add (dst, lb);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4718 Dynarr_add (dst, c | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4719 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4720 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4721 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4722 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4723 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4724 Dynarr_add (dst, lb);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4725 Dynarr_add (dst, ch | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4726 Dynarr_add (dst, c | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4727 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4728 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4729 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4730 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4731 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4732 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4733
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4734 default: /* two-byte private */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4735 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4736 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4737 Dynarr_add (dst, PRE_LEADING_BYTE_PRIVATE_2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4738 Dynarr_add (dst, lb);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4739 Dynarr_add (dst, ch | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4740 Dynarr_add (dst, c | 0x80);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4741 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4742 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4743 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4744 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4745 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4746 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4747
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4748 if (!ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4749 flags &= CODING_STATE_ISO2022_LOCK;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4750 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4751
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4752 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4753 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4754
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4755 if (flags & CODING_STATE_END)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4756 DECODE_OUTPUT_PARTIAL_CHAR (ch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4757
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4758 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4759 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4760 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4761
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4762
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4763 /***** ISO2022 encoder *****/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4764
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4765 /* Designate CHARSET into register REG. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4766
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4767 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4768 iso2022_designate (Lisp_Object charset, unsigned char reg,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4769 struct encoding_stream *str, unsigned_char_dynarr *dst)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4770 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
4771 static CONST char inter94[] = "()*+";
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
4772 static CONST char inter96[] = ",-./";
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
4773 unsigned int type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4774 unsigned char final;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4775 Lisp_Object old_charset = str->iso2022.charset[reg];
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4776
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4777 str->iso2022.charset[reg] = charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4778 if (!CHARSETP (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4779 /* charset might be an initial nil or t. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4780 return;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4781 type = XCHARSET_TYPE (charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4782 final = XCHARSET_FINAL (charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4783 if (!str->iso2022.force_charset_on_output[reg] &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4784 CHARSETP (old_charset) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4785 XCHARSET_TYPE (old_charset) == type &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4786 XCHARSET_FINAL (old_charset) == final)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4787 return;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4788
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4789 str->iso2022.force_charset_on_output[reg] = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4790
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4791 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4792 charset_conversion_spec_dynarr *dyn =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4793 str->codesys->iso2022.output_conv;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4794
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4795 if (dyn)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4796 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4797 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4798
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4799 for (i = 0; i < Dynarr_length (dyn); i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4800 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4801 struct charset_conversion_spec *spec = Dynarr_atp (dyn, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4802 if (EQ (charset, spec->from_charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4803 charset = spec->to_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4804 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4805 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4806 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4807
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4808 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4809 switch (type)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4810 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4811 case CHARSET_TYPE_94:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4812 Dynarr_add (dst, inter94[reg]);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4813 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4814 case CHARSET_TYPE_96:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4815 Dynarr_add (dst, inter96[reg]);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4816 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4817 case CHARSET_TYPE_94X94:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4818 Dynarr_add (dst, '$');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4819 if (reg != 0
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4820 || !(CODING_SYSTEM_ISO2022_SHORT (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4821 || final < '@'
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4822 || final > 'B')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4823 Dynarr_add (dst, inter94[reg]);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4824 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4825 case CHARSET_TYPE_96X96:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4826 Dynarr_add (dst, '$');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4827 Dynarr_add (dst, inter96[reg]);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4828 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4829 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4830 Dynarr_add (dst, final);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4831 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4832
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4833 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4834 ensure_normal_shift (struct encoding_stream *str, unsigned_char_dynarr *dst)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4835 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4836 if (str->iso2022.register_left != 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4837 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4838 Dynarr_add (dst, ISO_CODE_SI);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4839 str->iso2022.register_left = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4840 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4841 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4842
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4843 static void
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4844 ensure_shift_out (struct encoding_stream *str, unsigned_char_dynarr *dst)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4845 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4846 if (str->iso2022.register_left != 1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4847 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4848 Dynarr_add (dst, ISO_CODE_SO);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4849 str->iso2022.register_left = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4850 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4851 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4852
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4853 /* Convert internally-formatted data to ISO2022 format. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4854
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4855 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
4856 encode_coding_iso2022 (Lstream *encoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4857 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4858 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4859 unsigned char charmask, c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4860 unsigned char char_boundary;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4861 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4862 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4863 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4864 Lisp_Coding_System *codesys = str->codesys;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4865 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4866 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4867 Lisp_Object charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4868 int half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4869
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4870 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4871 /* flags for handling composite chars. We do a little switcharoo
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4872 on the source while we're outputting the composite char. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4873 unsigned int saved_n = 0;
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
4874 CONST unsigned char *saved_src = NULL;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4875 int in_composite = 0;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4876 #endif /* ENABLE_COMPOSITE_CHARS */
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4877
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4878 char_boundary = str->iso2022.current_char_boundary;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4879 charset = str->iso2022.current_charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4880 half = str->iso2022.current_half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4881
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4882 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4883 back_to_square_n:
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4884 #endif
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4885 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4886 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4887 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4888
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4889 if (BYTE_ASCII_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4890 { /* Processing ASCII character */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4891 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4892
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4893 restore_left_to_right_direction (codesys, dst, &flags, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4894
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4895 /* Make sure G0 contains ASCII */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4896 if ((c > ' ' && c < ISO_CODE_DEL) ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4897 !CODING_SYSTEM_ISO2022_NO_ASCII_CNTL (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4898 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4899 ensure_normal_shift (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4900 iso2022_designate (Vcharset_ascii, 0, str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4901 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4902
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4903 /* If necessary, restore everything to the default state
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4904 at end-of-line */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4905 if (c == '\n' &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4906 !(CODING_SYSTEM_ISO2022_NO_ASCII_EOL (codesys)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4907 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4908 restore_left_to_right_direction (codesys, dst, &flags, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4909
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4910 ensure_normal_shift (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4911
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4912 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4913 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4914 Lisp_Object initial_charset =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4915 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4916 iso2022_designate (initial_charset, i, str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4917 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4918 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4919 if (c == '\n')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4920 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4921 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4922 Dynarr_add (dst, '\r');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4923 if (eol_type != EOL_CR)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4924 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4925 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4926 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4927 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4928 if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4929 && fit_to_be_escape_quoted (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4930 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4931 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4932 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4933 char_boundary = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4934 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4935
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4936 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4937 { /* Processing Leading Byte */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4938 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4939 charset = CHARSET_BY_LEADING_BYTE (c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4940 if (LEADING_BYTE_PREFIX_P(c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4941 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4942 else if (!EQ (charset, Vcharset_control_1)
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4943 #ifdef ENABLE_COMPOSITE_CHARS
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4944 && !EQ (charset, Vcharset_composite)
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4945 #endif
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
4946 )
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4947 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4948 int reg;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4949
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4950 ensure_correct_direction (XCHARSET_DIRECTION (charset),
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4951 codesys, dst, &flags, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4952
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4953 /* Now determine which register to use. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4954 reg = -1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4955 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4956 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4957 if (EQ (charset, str->iso2022.charset[i]) ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4958 EQ (charset,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4959 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4960 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4961 reg = i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4962 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4963 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4964 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4965
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4966 if (reg == -1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4967 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4968 if (XCHARSET_GRAPHIC (charset) != 0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4969 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4970 if (!NILP (str->iso2022.charset[1]) &&
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4971 (!CODING_SYSTEM_ISO2022_SEVEN (codesys) ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4972 CODING_SYSTEM_ISO2022_LOCK_SHIFT (codesys)))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4973 reg = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4974 else if (!NILP (str->iso2022.charset[2]))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4975 reg = 2;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4976 else if (!NILP (str->iso2022.charset[3]))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4977 reg = 3;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4978 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4979 reg = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4980 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4981 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4982 reg = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4983 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4984
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4985 iso2022_designate (charset, reg, str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4986
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4987 /* Now invoke that register. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4988 switch (reg)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4989 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4990 case 0:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4991 ensure_normal_shift (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4992 half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4993 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4994
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4995 case 1:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4996 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4997 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4998 ensure_shift_out (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
4999 half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5000 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5001 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5002 half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5003 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5004
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5005 case 2:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5006 if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5007 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5008 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5009 Dynarr_add (dst, 'N');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5010 half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5011 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5012 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5013 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5014 Dynarr_add (dst, ISO_CODE_SS2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5015 half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5016 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5017 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5018
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5019 case 3:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5020 if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5021 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5022 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5023 Dynarr_add (dst, 'O');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5024 half = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5025 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5026 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5027 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5028 Dynarr_add (dst, ISO_CODE_SS3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5029 half = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5030 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5031 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5032
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5033 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5034 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5035 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5036 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5037 char_boundary = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5038 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5039 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5040 { /* Processing Non-ASCII character */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5041 charmask = (half == 0 ? 0x7F : 0xFF);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5042 char_boundary = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5043 if (EQ (charset, Vcharset_control_1))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5044 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5045 if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5046 && fit_to_be_escape_quoted (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5047 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5048 /* you asked for it ... */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5049 Dynarr_add (dst, c - 0x20);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5050 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5051 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5052 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5053 switch (XCHARSET_REP_BYTES (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5054 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5055 case 2:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5056 Dynarr_add (dst, c & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5057 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5058 case 3:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5059 if (XCHARSET_PRIVATE_P (charset))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5060 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5061 Dynarr_add (dst, c & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5062 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5063 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5064 else if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5065 {
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5066 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5067 if (EQ (charset, Vcharset_composite))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5068 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5069 if (in_composite)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5070 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5071 /* #### Bother! We don't know how to
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5072 handle this yet. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5073 Dynarr_add (dst, '~');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5074 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5075 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5076 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5077 Emchar emch = MAKE_CHAR (Vcharset_composite,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5078 ch & 0x7F, c & 0x7F);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5079 Lisp_Object lstr = composite_char_string (emch);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5080 saved_n = n;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5081 saved_src = src;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5082 in_composite = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5083 src = XSTRING_DATA (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5084 n = XSTRING_LENGTH (lstr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5085 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5086 Dynarr_add (dst, '0'); /* start composing */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5087 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5088 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5089 else
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5090 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5091 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5092 Dynarr_add (dst, ch & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5093 Dynarr_add (dst, c & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5094 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5095 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5096 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5097 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5098 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5099 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5100 char_boundary = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5101 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5102 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5103 case 4:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5104 if (ch)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5105 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5106 Dynarr_add (dst, ch & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5107 Dynarr_add (dst, c & charmask);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5108 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5109 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5110 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5111 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5112 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5113 char_boundary = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5114 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5115 break;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5116 default:
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5117 abort ();
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5118 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5119 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5120 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5121 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5122
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5123 #ifdef ENABLE_COMPOSITE_CHARS
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5124 if (in_composite)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5125 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5126 n = saved_n;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5127 src = saved_src;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5128 in_composite = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5129 Dynarr_add (dst, ISO_CODE_ESC);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5130 Dynarr_add (dst, '1'); /* end composing */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5131 goto back_to_square_n; /* Wheeeeeeeee ..... */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5132 }
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5133 #endif /* ENABLE_COMPOSITE_CHARS */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5134
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5135 if (char_boundary && flags & CODING_STATE_END)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5136 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5137 restore_left_to_right_direction (codesys, dst, &flags, 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5138 ensure_normal_shift (str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5139 for (i = 0; i < 4; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5140 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5141 Lisp_Object initial_charset =
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5142 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5143 iso2022_designate (initial_charset, i, str, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5144 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5145 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5146
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5147 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5148 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5149 str->iso2022.current_char_boundary = char_boundary;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5150 str->iso2022.current_charset = charset;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5151 str->iso2022.current_half = half;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5152
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5153 /* Verbum caro factum est! */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5154 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5155 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5156
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5157 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5158 /* No-conversion methods */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5159 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5160
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5161 /* This is used when reading in "binary" files -- i.e. files that may
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5162 contain all 256 possible byte values and that are not to be
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5163 interpreted as being in any particular decoding. */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5164 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5165 decode_coding_no_conversion (Lstream *decoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5166 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5167 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5168 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5169 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5170 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5171 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5172 eol_type_t eol_type = str->eol_type;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5173
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5174 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5175 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5176 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5177
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5178 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5179 DECODE_ADD_BINARY_CHAR (c, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5180 label_continue_loop:;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5181 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5182
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5183 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5184
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5185 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5186 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5187 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5188
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5189 static void
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5190 encode_coding_no_conversion (Lstream *encoding, CONST unsigned char *src,
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5191 unsigned_char_dynarr *dst, unsigned int n)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5192 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5193 unsigned char c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5194 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5195 unsigned int flags = str->flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5196 unsigned int ch = str->ch;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5197 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5198
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5199 while (n--)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5200 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5201 c = *src++;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5202 if (c == '\n')
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5203 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5204 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5205 Dynarr_add (dst, '\r');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5206 if (eol_type != EOL_CR)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5207 Dynarr_add (dst, '\n');
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5208 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5209 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5210 else if (BYTE_ASCII_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5211 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5212 assert (ch == 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5213 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5214 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5215 else if (BUFBYTE_LEADING_BYTE_P (c))
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5216 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5217 assert (ch == 0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5218 if (c == LEADING_BYTE_LATIN_ISO8859_1 ||
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5219 c == LEADING_BYTE_CONTROL_1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5220 ch = c;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5221 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5222 Dynarr_add (dst, '~'); /* untranslatable character */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5223 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5224 else
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5225 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5226 if (ch == LEADING_BYTE_LATIN_ISO8859_1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5227 Dynarr_add (dst, c);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5228 else if (ch == LEADING_BYTE_CONTROL_1)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5229 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5230 assert (c < 0xC0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5231 Dynarr_add (dst, c - 0x20);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5232 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5233 /* else it should be the second or third byte of an
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5234 untranslatable character, so ignore it */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5235 ch = 0;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5236 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5237 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5238
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5239 str->flags = flags;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5240 str->ch = ch;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5241 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5242
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5243
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5244 /************************************************************************/
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5245 /* Simple internal/external functions */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5246 /************************************************************************/
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5247
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5248 static Extbyte_dynarr *conversion_out_dynarr;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5249 static Bufbyte_dynarr *conversion_in_dynarr;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5250
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5251 /* Determine coding system from coding format */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5252
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5253 /* #### not correct for all values of `fmt'! */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5254 static Lisp_Object
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5255 external_data_format_to_coding_system (enum external_data_format fmt)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5256 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5257 switch (fmt)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5258 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5259 case FORMAT_FILENAME:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5260 case FORMAT_TERMINAL:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5261 if (EQ (Vfile_name_coding_system, Qnil) ||
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5262 EQ (Vfile_name_coding_system, Qbinary))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5263 return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5264 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5265 return Fget_coding_system (Vfile_name_coding_system);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5266 #ifdef MULE
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5267 case FORMAT_CTEXT:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5268 return Fget_coding_system (Qctext);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5269 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5270 default:
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5271 return Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5272 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5273 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5274
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5275 Extbyte *
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5276 convert_to_external_format (CONST Bufbyte *ptr,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5277 Bytecount len,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5278 Extcount *len_out,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5279 enum external_data_format fmt)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5280 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5281 Lisp_Object coding_system = external_data_format_to_coding_system (fmt);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5282
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5283 if (!conversion_out_dynarr)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5284 conversion_out_dynarr = Dynarr_new (Extbyte);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5285 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5286 Dynarr_reset (conversion_out_dynarr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5287
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5288 if (NILP (coding_system))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5289 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5290 CONST Bufbyte *end = ptr + len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5291
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5292 for (; ptr < end;)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5293 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5294 Bufbyte c =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5295 (BYTE_ASCII_P (*ptr)) ? *ptr :
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5296 (*ptr == LEADING_BYTE_CONTROL_1) ? (*(ptr+1) - 0x20) :
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5297 (*ptr == LEADING_BYTE_LATIN_ISO8859_1) ? (*(ptr+1)) :
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5298 '~';
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5299
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5300 Dynarr_add (conversion_out_dynarr, (Extbyte) c);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5301 INC_CHARPTR (ptr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5302 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5303
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5304 #ifdef ERROR_CHECK_BUFPOS
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5305 assert (ptr == end);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5306 #endif
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5307 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5308 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5309 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5310 Lisp_Object instream, outstream, da_outstream;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5311 Lstream *istr, *ostr;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5312 struct gcpro gcpro1, gcpro2, gcpro3;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5313 char tempbuf[1024]; /* some random amount */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5314
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5315 instream = make_fixed_buffer_input_stream ((unsigned char *) ptr, len);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5316 da_outstream = make_dynarr_output_stream
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5317 ((unsigned_char_dynarr *) conversion_out_dynarr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5318 outstream =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5319 make_encoding_output_stream (XLSTREAM (da_outstream), coding_system);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5320 istr = XLSTREAM (instream);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5321 ostr = XLSTREAM (outstream);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5322 GCPRO3 (instream, outstream, da_outstream);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5323 while (1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5324 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5325 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5326 if (!size_in_bytes)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5327 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5328 Lstream_write (ostr, tempbuf, size_in_bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5329 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5330 Lstream_close (istr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5331 Lstream_close (ostr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5332 UNGCPRO;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5333 Lstream_delete (istr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5334 Lstream_delete (ostr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5335 Lstream_delete (XLSTREAM (da_outstream));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5336 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5337
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5338 *len_out = Dynarr_length (conversion_out_dynarr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5339 Dynarr_add (conversion_out_dynarr, 0); /* remember to zero-terminate! */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5340 return Dynarr_atp (conversion_out_dynarr, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5341 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5342
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5343 Bufbyte *
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5344 convert_from_external_format (CONST Extbyte *ptr,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5345 Extcount len,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5346 Bytecount *len_out,
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5347 enum external_data_format fmt)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5348 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5349 Lisp_Object coding_system = external_data_format_to_coding_system (fmt);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5350
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5351 if (!conversion_in_dynarr)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5352 conversion_in_dynarr = Dynarr_new (Bufbyte);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5353 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5354 Dynarr_reset (conversion_in_dynarr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5355
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5356 if (NILP (coding_system))
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5357 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5358 CONST Extbyte *end = ptr + len;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5359 for (; ptr < end; ptr++)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5360 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5361 Extbyte c = *ptr;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5362 DECODE_ADD_BINARY_CHAR (c, conversion_in_dynarr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5363 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5364 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5365 else
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5366 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5367 Lisp_Object instream, outstream, da_outstream;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5368 Lstream *istr, *ostr;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5369 struct gcpro gcpro1, gcpro2, gcpro3;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5370 char tempbuf[1024]; /* some random amount */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5371
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5372 instream = make_fixed_buffer_input_stream ((unsigned char *) ptr, len);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5373 da_outstream = make_dynarr_output_stream
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5374 ((unsigned_char_dynarr *) conversion_in_dynarr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5375 outstream =
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5376 make_decoding_output_stream (XLSTREAM (da_outstream), coding_system);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5377 istr = XLSTREAM (instream);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5378 ostr = XLSTREAM (outstream);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5379 GCPRO3 (instream, outstream, da_outstream);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5380 while (1)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5381 {
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5382 int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5383 if (!size_in_bytes)
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5384 break;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5385 Lstream_write (ostr, tempbuf, size_in_bytes);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5386 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5387 Lstream_close (istr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5388 Lstream_close (ostr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5389 UNGCPRO;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5390 Lstream_delete (istr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5391 Lstream_delete (ostr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5392 Lstream_delete (XLSTREAM (da_outstream));
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5393 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5394
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5395 *len_out = Dynarr_length (conversion_in_dynarr);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5396 Dynarr_add (conversion_in_dynarr, 0); /* remember to zero-terminate! */
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5397 return Dynarr_atp (conversion_in_dynarr, 0);
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5398 }
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5399
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5400
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5401 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5402 /* Initialization */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5403 /************************************************************************/
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5404
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5405 void
414
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
5406 syms_of_file_coding (void)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5407 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5408 defsymbol (&Qbuffer_file_coding_system, "buffer-file-coding-system");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5409 deferror (&Qcoding_system_error, "coding-system-error",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5410 "Coding-system error", Qio_error);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5411
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5412 DEFSUBR (Fcoding_system_p);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5413 DEFSUBR (Ffind_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5414 DEFSUBR (Fget_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5415 DEFSUBR (Fcoding_system_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5416 DEFSUBR (Fcoding_system_name);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5417 DEFSUBR (Fmake_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5418 DEFSUBR (Fcopy_coding_system);
398
74fd4e045ea6 Import from CVS: tag r21-2-29
cvs
parents: 396
diff changeset
5419 DEFSUBR (Fdefine_coding_system_alias);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5420 DEFSUBR (Fsubsidiary_coding_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5421
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5422 DEFSUBR (Fcoding_system_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5423 DEFSUBR (Fcoding_system_doc_string);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5424 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5425 DEFSUBR (Fcoding_system_charset);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5426 #endif
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5427 DEFSUBR (Fcoding_system_property);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5428
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5429 DEFSUBR (Fcoding_category_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5430 DEFSUBR (Fset_coding_priority_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5431 DEFSUBR (Fcoding_priority_list);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5432 DEFSUBR (Fset_coding_category_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5433 DEFSUBR (Fcoding_category_system);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5434
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5435 DEFSUBR (Fdetect_coding_region);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5436 DEFSUBR (Fdecode_coding_region);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5437 DEFSUBR (Fencode_coding_region);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5438 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5439 DEFSUBR (Fdecode_shift_jis_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5440 DEFSUBR (Fencode_shift_jis_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5441 DEFSUBR (Fdecode_big5_char);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5442 DEFSUBR (Fencode_big5_char);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5443 DEFSUBR (Fset_ucs_char);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5444 DEFSUBR (Fucs_char);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5445 DEFSUBR (Fset_char_ucs);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5446 DEFSUBR (Fchar_ucs);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5447 #endif /* MULE */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5448 defsymbol (&Qcoding_system_p, "coding-system-p");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5449 defsymbol (&Qno_conversion, "no-conversion");
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5450 defsymbol (&Qraw_text, "raw-text");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5451 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5452 defsymbol (&Qbig5, "big5");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5453 defsymbol (&Qshift_jis, "shift-jis");
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5454 defsymbol (&Qucs4, "ucs-4");
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5455 defsymbol (&Qutf8, "utf-8");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5456 defsymbol (&Qccl, "ccl");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5457 defsymbol (&Qiso2022, "iso2022");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5458 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5459 defsymbol (&Qmnemonic, "mnemonic");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5460 defsymbol (&Qeol_type, "eol-type");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5461 defsymbol (&Qpost_read_conversion, "post-read-conversion");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5462 defsymbol (&Qpre_write_conversion, "pre-write-conversion");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5463
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5464 defsymbol (&Qcr, "cr");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5465 defsymbol (&Qlf, "lf");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5466 defsymbol (&Qcrlf, "crlf");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5467 defsymbol (&Qeol_cr, "eol-cr");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5468 defsymbol (&Qeol_lf, "eol-lf");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5469 defsymbol (&Qeol_crlf, "eol-crlf");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5470 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5471 defsymbol (&Qcharset_g0, "charset-g0");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5472 defsymbol (&Qcharset_g1, "charset-g1");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5473 defsymbol (&Qcharset_g2, "charset-g2");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5474 defsymbol (&Qcharset_g3, "charset-g3");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5475 defsymbol (&Qforce_g0_on_output, "force-g0-on-output");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5476 defsymbol (&Qforce_g1_on_output, "force-g1-on-output");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5477 defsymbol (&Qforce_g2_on_output, "force-g2-on-output");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5478 defsymbol (&Qforce_g3_on_output, "force-g3-on-output");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5479 defsymbol (&Qno_iso6429, "no-iso6429");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5480 defsymbol (&Qinput_charset_conversion, "input-charset-conversion");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5481 defsymbol (&Qoutput_charset_conversion, "output-charset-conversion");
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
5482
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5483 defsymbol (&Qshort, "short");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5484 defsymbol (&Qno_ascii_eol, "no-ascii-eol");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5485 defsymbol (&Qno_ascii_cntl, "no-ascii-cntl");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5486 defsymbol (&Qseven, "seven");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5487 defsymbol (&Qlock_shift, "lock-shift");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5488 defsymbol (&Qescape_quoted, "escape-quoted");
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
5489 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5490 defsymbol (&Qencode, "encode");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5491 defsymbol (&Qdecode, "decode");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5492
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5493 #ifdef MULE
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5494 defsymbol (&Qctext, "ctext");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5495 defsymbol (&coding_category_symbol[CODING_CATEGORY_SHIFT_JIS],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5496 "shift-jis");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5497 defsymbol (&coding_category_symbol[CODING_CATEGORY_BIG5],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5498 "big5");
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5499 defsymbol (&coding_category_symbol[CODING_CATEGORY_UCS4],
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5500 "ucs-4");
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5501 defsymbol (&coding_category_symbol[CODING_CATEGORY_UTF8],
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5502 "utf-8");
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5503 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_7],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5504 "iso-7");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5505 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_DESIGNATE],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5506 "iso-8-designate");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5507 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_1],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5508 "iso-8-1");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5509 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_2],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5510 "iso-8-2");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5511 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_LOCK_SHIFT],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5512 "iso-lock-shift");
272
c5d627a313b1 Import from CVS: tag r21-0b34
cvs
parents: 265
diff changeset
5513 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5514 defsymbol (&coding_category_symbol[CODING_CATEGORY_NO_CONVERSION],
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5515 "no-conversion");
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5516 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5517
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5518 void
414
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
5519 lstream_type_create_file_coding (void)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5520 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5521 LSTREAM_HAS_METHOD (decoding, reader);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5522 LSTREAM_HAS_METHOD (decoding, writer);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5523 LSTREAM_HAS_METHOD (decoding, rewinder);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5524 LSTREAM_HAS_METHOD (decoding, seekable_p);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5525 LSTREAM_HAS_METHOD (decoding, flusher);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5526 LSTREAM_HAS_METHOD (decoding, closer);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5527 LSTREAM_HAS_METHOD (decoding, marker);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5528
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5529 LSTREAM_HAS_METHOD (encoding, reader);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5530 LSTREAM_HAS_METHOD (encoding, writer);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5531 LSTREAM_HAS_METHOD (encoding, rewinder);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5532 LSTREAM_HAS_METHOD (encoding, seekable_p);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5533 LSTREAM_HAS_METHOD (encoding, flusher);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5534 LSTREAM_HAS_METHOD (encoding, closer);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5535 LSTREAM_HAS_METHOD (encoding, marker);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5536 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5537
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5538 void
414
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
5539 vars_of_file_coding (void)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5540 {
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5541 int i;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5542
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5543 /* Initialize to something reasonable ... */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5544 for (i = 0; i <= CODING_CATEGORY_LAST; i++)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5545 {
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5546 coding_category_system[i] = Qnil;
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5547 coding_category_by_priority[i] = i;
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5548 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5549
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5550 Fprovide (intern ("file-coding"));
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5551
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5552 DEFVAR_LISP ("keyboard-coding-system", &Vkeyboard_coding_system /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5553 Coding system used for TTY keyboard input.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5554 Not used under a windowing system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5555 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5556 Vkeyboard_coding_system = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5557
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5558 DEFVAR_LISP ("terminal-coding-system", &Vterminal_coding_system /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5559 Coding system used for TTY display output.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5560 Not used under a windowing system.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5561 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5562 Vterminal_coding_system = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5563
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5564 DEFVAR_LISP ("coding-system-for-read", &Vcoding_system_for_read /*
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5565 Overriding coding system used when writing a file or process.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5566 You should *bind* this, not set it. If this is non-nil, it specifies
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5567 the coding system that will be used when a file or process is read
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5568 in, and overrides `buffer-file-coding-system-for-read',
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5569 `insert-file-contents-pre-hook', etc. Use those variables instead of
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5570 this one for permanent changes to the environment.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5571 */ );
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5572 Vcoding_system_for_read = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5573
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5574 DEFVAR_LISP ("coding-system-for-write",
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5575 &Vcoding_system_for_write /*
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5576 Overriding coding system used when writing a file or process.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5577 You should *bind* this, not set it. If this is non-nil, it specifies
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5578 the coding system that will be used when a file or process is wrote
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5579 in, and overrides `buffer-file-coding-system',
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5580 `write-region-pre-hook', etc. Use those variables instead of this one
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5581 for permanent changes to the environment.
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5582 */ );
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5583 Vcoding_system_for_write = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5584
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5585 DEFVAR_LISP ("file-name-coding-system", &Vfile_name_coding_system /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5586 Coding system used to convert pathnames when accessing files.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5587 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5588 Vfile_name_coding_system = Qnil;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5589
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5590 DEFVAR_BOOL ("enable-multibyte-characters", &enable_multibyte_characters /*
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5591 Non-nil means the buffer contents are regarded as multi-byte form
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5592 of characters, not a binary code. This affects the display, file I/O,
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5593 and behaviors of various editing commands.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5594
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5595 Setting this to nil does not do anything.
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5596 */ );
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5597 enable_multibyte_characters = 1;
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5598 }
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5599
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5600 void
414
da8ed4261e83 Import from CVS: tag r21-2-15
cvs
parents: 412
diff changeset
5601 complex_vars_of_file_coding (void)
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5602 {
380
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
5603 staticpro (&Vcoding_system_hash_table);
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
5604 Vcoding_system_hash_table =
8626e4521993 Import from CVS: tag r21-2-5
cvs
parents: 371
diff changeset
5605 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5606
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5607 the_codesys_prop_dynarr = Dynarr_new (codesys_prop);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5608
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5609 #define DEFINE_CODESYS_PROP(Prop_Type, Sym) do \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5610 { \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5611 struct codesys_prop csp; \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5612 csp.sym = (Sym); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5613 csp.prop_type = (Prop_Type); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5614 Dynarr_add (the_codesys_prop_dynarr, csp); \
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5615 } while (0)
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5616
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5617 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qmnemonic);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5618 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_type);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5619 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_cr);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5620 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_crlf);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5621 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_lf);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5622 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qpost_read_conversion);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5623 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qpre_write_conversion);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5624 #ifdef MULE
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5625 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g0);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5626 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g1);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5627 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g2);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5628 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g3);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5629 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g0_on_output);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5630 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g1_on_output);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5631 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g2_on_output);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5632 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g3_on_output);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5633 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qshort);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5634 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_ascii_eol);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5635 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_ascii_cntl);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5636 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qseven);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5637 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qlock_shift);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5638 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_iso6429);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5639 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qescape_quoted);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5640 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qinput_charset_conversion);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5641 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qoutput_charset_conversion);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5642
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5643 DEFINE_CODESYS_PROP (CODESYS_PROP_CCL, Qencode);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5644 DEFINE_CODESYS_PROP (CODESYS_PROP_CCL, Qdecode);
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5645 #endif /* MULE */
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5646 /* Need to create this here or we're really screwed. */
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5647 Fmake_coding_system
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5648 (Qraw_text, Qno_conversion,
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5649 build_string ("Raw text, which means it converts only line-break-codes."),
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5650 list2 (Qmnemonic, build_string ("Raw")));
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5651
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5652 Fmake_coding_system
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5653 (Qbinary, Qno_conversion,
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5654 build_string ("Binary, which means it does not convert anything."),
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5655 list4 (Qeol_type, Qlf,
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5656 Qmnemonic, build_string ("Binary")));
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5657
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5658 Fdefine_coding_system_alias (Qno_conversion, Qraw_text);
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5659
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5660 /* Need this for bootstrapping */
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5661 coding_category_system[CODING_CATEGORY_NO_CONVERSION] =
416
ebe98a74bd68 Import from CVS: tag r21-2-16
cvs
parents: 414
diff changeset
5662 Fget_coding_system (Qraw_text);
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5663
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5664 #ifdef MULE
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5665 {
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5666 unsigned int i;
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5667
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5668 for (i = 0; i < 65536; i++)
412
697ef44129c6 Import from CVS: tag r21-2-14
cvs
parents: 406
diff changeset
5669 ucs_to_mule_table[i] = Qnil;
396
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5670 }
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5671 staticpro (&mule_to_ucs_table);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5672 mule_to_ucs_table = Fmake_char_table(Qgeneric);
6719134a07c2 Import from CVS: tag r21-2-13
cvs
parents: 388
diff changeset
5673 #endif /* MULE */
259
11cf20601dec Import from CVS: tag r20-5b28
cvs
parents:
diff changeset
5674 }