annotate src/file-coding.c @ 563:183866b06e0b

[xemacs-hg @ 2001-05-24 07:50:48 by ben] Makefile.in.in, abbrev.c, alloc.c, buffer.c, bytecode.c, callint.c, callproc.c, casetab.c, chartab.c, cmdloop.c, cmds.c, console-msw.c, console-msw.h, console-stream.c, console-tty.c, console-x.c, console.c, data.c, database.c, debug.c, device-gtk.c, device-msw.c, device-tty.c, device-x.c, device.c, dialog-gtk.c, dialog-msw.c, dialog-x.c, dialog.c, dired-msw.c, dired.c, doc.c, doprnt.c, dragdrop.c, editfns.c, eldap.c, eldap.h, elhash.c, emacs-widget-accessors.c, emacs.c, emodules.c, esd.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, extents.c, faces.c, file-coding.c, fileio.c, filelock.c, floatfns.c, fns.c, font-lock.c, frame-gtk.c, frame-x.c, frame.c, general-slots.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-widget.c, glyphs-x.c, glyphs.c, glyphs.h, gpmevent.c, gui-gtk.c, gui-x.c, gui.c, gutter.c, hpplay.c, indent.c, input-method-xlib.c, insdel.c, intl.c, keymap.c, libsst.c, libsst.h, linuxplay.c, lisp.h, lread.c, lstream.c, lstream.h, macros.c, marker.c, md5.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, miscplay.c, miscplay.h, mule-ccl.c, mule-charset.c, mule-wnnfns.c, mule.c, nas.c, ntplay.c, ntproc.c, objects-gtk.c, objects-msw.c, objects-x.c, objects.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, ralloc.c, rangetab.c, redisplay.c, scrollbar.c, search.c, select-gtk.c, select-x.c, select.c, sgiplay.c, sheap.c, sound.c, specifier.c, sunplay.c, symbols.c, symeval.h, symsinit.h, syntax.c, sysdep.c, toolbar-msw.c, toolbar.c, tooltalk.c, ui-byhand.c, ui-gtk.c, undo.c, unexaix.c, unexapollo.c, unexconvex.c, unexec.c, widget.c, win32.c, window.c: -- defsymbol -> DEFSYMBOL. -- add an error type to all errors. -- eliminate the error functions in eval.c that let you just use Qerror as the type. -- redo the error API to be more consistent, sensibly named, and easier to use. -- redo the error hierarchy somewhat. create new errors: structure-formation-error, gui-error, invalid-constant, stack-overflow, out-of-memory, process-error, network-error, sound-error, printing-unreadable-object, base64-conversion- error; coding-system-error renamed to text-conversion error; some others. -- fix Mule problems in error strings in emodules.c, tooltalk.c. -- fix error handling in mswin open-network-stream. -- Mule-ize all sound files and clean up the headers. -- nativesound.h -> sound.h and used for all sound files. -- move some shared stuff into glyphs-shared.c: first attempt at eliminating some of the massive GTK code duplication. xemacs.mak: add glyphs-shared.c. xemacs-faq.texi: document how to debug X errors subr.el: fix doc string to reflect reality
author ben
date Thu, 24 May 2001 07:51:33 +0000
parents ef4d2466a29c
children 001628b7a5b3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1 /* Code conversion functions.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2 Copyright (C) 1991, 1995 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1995 Sun Microsystems, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
6
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
7 XEmacs is free software; you can redistribute it and/or modify it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 later version.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
11
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
15 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18 along with XEmacs; see the file COPYING. If not, write to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
20 Boston, MA 02111-1307, USA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
22 /* Synched up with: Mule 2.3. Not in FSF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
23
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
24 /* Rewritten by Ben Wing <ben@xemacs.org>. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
25
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
26 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
27 #include "lisp.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
28
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
29 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
30 #include "elhash.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
31 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
32 #include "lstream.h"
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
33 #include "opaque.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
34 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
35 #include "mule-ccl.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
36 #include "chartab.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
37 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
38 #include "file-coding.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
39
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
40 Lisp_Object Qtext_conversion_error;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
41
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
42 Lisp_Object Vkeyboard_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
43 Lisp_Object Vterminal_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
44 Lisp_Object Vcoding_system_for_read;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
45 Lisp_Object Vcoding_system_for_write;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
46 Lisp_Object Vfile_name_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
47
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
48 /* Table of symbols identifying each coding category. */
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
49 Lisp_Object coding_category_symbol[CODING_CATEGORY_LAST];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
50
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
51
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
52
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
53 struct file_coding_dump {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
54 /* Coding system currently associated with each coding category. */
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
55 Lisp_Object coding_category_system[CODING_CATEGORY_LAST];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
56
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
57 /* Table of all coding categories in decreasing order of priority.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
58 This describes a permutation of the possible coding categories. */
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
59 int coding_category_by_priority[CODING_CATEGORY_LAST];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
60
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
61 #ifdef MULE
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
62 Lisp_Object ucs_to_mule_table[65536];
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
63 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
64 } *fcd;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
65
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
66 static const struct lrecord_description fcd_description_1[] = {
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
67 { XD_LISP_OBJECT_ARRAY, offsetof (struct file_coding_dump, coding_category_system), CODING_CATEGORY_LAST },
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
68 #ifdef MULE
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
69 { XD_LISP_OBJECT_ARRAY, offsetof (struct file_coding_dump, ucs_to_mule_table), countof (fcd->ucs_to_mule_table) },
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
70 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
72 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
73
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 static const struct struct_description fcd_description = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
75 sizeof (struct file_coding_dump),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 fcd_description_1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
77 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
78
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
79 Lisp_Object mule_to_ucs_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
80
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
81 Lisp_Object Qcoding_systemp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
82
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
83 Lisp_Object Qraw_text, Qno_conversion, Qccl, Qiso2022;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
84 /* Qinternal in general.c */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
85
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 Lisp_Object Qmnemonic, Qeol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87 Lisp_Object Qcr, Qcrlf, Qlf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 Lisp_Object Qeol_cr, Qeol_crlf, Qeol_lf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 Lisp_Object Qpost_read_conversion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 Lisp_Object Qpre_write_conversion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93 Lisp_Object Qucs4, Qutf8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
94 Lisp_Object Qbig5, Qshift_jis;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
95 Lisp_Object Qcharset_g0, Qcharset_g1, Qcharset_g2, Qcharset_g3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
96 Lisp_Object Qforce_g0_on_output, Qforce_g1_on_output;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
97 Lisp_Object Qforce_g2_on_output, Qforce_g3_on_output;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
98 Lisp_Object Qno_iso6429;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
99 Lisp_Object Qinput_charset_conversion, Qoutput_charset_conversion;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
100 Lisp_Object Qescape_quoted;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
101 Lisp_Object Qshort, Qno_ascii_eol, Qno_ascii_cntl, Qseven, Qlock_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
102 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
103 Lisp_Object Qencode, Qdecode;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
104
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
105 Lisp_Object Vcoding_system_hash_table;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
106
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
107 int enable_multibyte_characters;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
108
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
109 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
110 /* Additional information used by the ISO2022 decoder and detector. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
111 struct iso2022_decoder
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
112 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
113 /* CHARSET holds the character sets currently assigned to the G0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
114 through G3 variables. It is initialized from the array
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
115 INITIAL_CHARSET in CODESYS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
116 Lisp_Object charset[4];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
117
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
118 /* Which registers are currently invoked into the left (GL) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
119 right (GR) halves of the 8-bit encoding space? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
120 int register_left, register_right;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
121
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
122 /* ISO_ESC holds a value indicating part of an escape sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
123 that has already been seen. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
124 enum iso_esc_flag esc;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
125
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
126 /* This records the bytes we've seen so far in an escape sequence,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
127 in case the sequence is invalid (we spit out the bytes unchanged). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
128 unsigned char esc_bytes[8];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 /* Index for next byte to store in ISO escape sequence. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 int esc_bytes_index;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
133 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
134 /* Stuff seen so far when composing a string. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
135 unsigned_char_dynarr *composite_chars;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
136 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
138 /* If we saw an invalid designation sequence for a particular
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
139 register, we flag it here and switch to ASCII. The next time we
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
140 see a valid designation for this register, we turn off the flag
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
141 and do the designation normally, but pretend the sequence was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
142 invalid. The effect of all this is that (most of the time) the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
143 escape sequences for both the switch to the unknown charset, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
144 the switch back to the known charset, get inserted literally into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
145 the buffer and saved out as such. The hope is that we can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
146 preserve the escape sequences so that the resulting written out
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
147 file makes sense. If we don't do any of this, the designation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
148 to the invalid charset will be preserved but that switch back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
149 to the known charset will probably get eaten because it was
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
150 the same charset that was already present in the register. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
151 unsigned char invalid_designated[4];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
152
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
153 /* We try to do similar things as above for direction-switching
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
154 sequences. If we encountered a direction switch while an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
155 invalid designation was present, or an invalid designation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
156 just after a direction switch (i.e. no valid designation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
157 encountered yet), we insert the direction-switch escape
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
158 sequence literally into the output stream, and later on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
159 insert the corresponding direction-restoring escape sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
160 literally also. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
161 unsigned int switched_dir_and_no_valid_charset_yet :1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
162 unsigned int invalid_switch_dir :1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
163
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
164 /* Tells the decoder to output the escape sequence literally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
165 even though it was valid. Used in the games we play to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 avoid lossage when we encounter invalid designations. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167 unsigned int output_literally :1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
168 /* We encountered a direction switch followed by an invalid
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
169 designation. We didn't output the direction switch
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
170 literally because we didn't know about the invalid designation;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
171 but we have to do so now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
172 unsigned int output_direction_sequence :1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
173 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
174 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
175 EXFUN (Fcopy_coding_system, 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
176 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
177 struct detection_state;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
178 static int detect_coding_sjis (struct detection_state *st,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
179 const Extbyte *src, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
180 static void decode_coding_sjis (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
181 unsigned_char_dynarr *dst, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
182 static void encode_coding_sjis (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
183 unsigned_char_dynarr *dst, Lstream_data_count n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
184 static int detect_coding_big5 (struct detection_state *st,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
185 const Extbyte *src, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
186 static void decode_coding_big5 (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
187 unsigned_char_dynarr *dst, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
188 static void encode_coding_big5 (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
189 unsigned_char_dynarr *dst, Lstream_data_count n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
190 static int detect_coding_ucs4 (struct detection_state *st,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
191 const Extbyte *src, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
192 static void decode_coding_ucs4 (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
193 unsigned_char_dynarr *dst, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
194 static void encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
195 unsigned_char_dynarr *dst, Lstream_data_count n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
196 static int detect_coding_utf8 (struct detection_state *st,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
197 const Extbyte *src, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
198 static void decode_coding_utf8 (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
199 unsigned_char_dynarr *dst, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
200 static void encode_coding_utf8 (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
201 unsigned_char_dynarr *dst, Lstream_data_count n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
202 static int postprocess_iso2022_mask (int mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
203 static void reset_iso2022 (Lisp_Object coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204 struct iso2022_decoder *iso);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 static int detect_coding_iso2022 (struct detection_state *st,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
206 const Extbyte *src, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
207 static void decode_coding_iso2022 (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
208 unsigned_char_dynarr *dst, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
209 static void encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
210 unsigned_char_dynarr *dst, Lstream_data_count n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 #endif /* MULE */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
212 static void decode_coding_no_conversion (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
213 unsigned_char_dynarr *dst, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
214 static void encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
215 unsigned_char_dynarr *dst, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
216 static void mule_decode (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
217 unsigned_char_dynarr *dst, Lstream_data_count n);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
218 static void mule_encode (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
219 unsigned_char_dynarr *dst, Lstream_data_count n);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
221 typedef struct codesys_prop codesys_prop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
222 struct codesys_prop
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
223 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
224 Lisp_Object sym;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
225 int prop_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
226 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
228 typedef struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
229 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
230 Dynarr_declare (codesys_prop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
231 } codesys_prop_dynarr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
232
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
233 static const struct lrecord_description codesys_prop_description_1[] = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
234 { XD_LISP_OBJECT, offsetof (codesys_prop, sym) },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
235 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
236 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
237
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
238 static const struct struct_description codesys_prop_description = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
239 sizeof (codesys_prop),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
240 codesys_prop_description_1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
241 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
242
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
243 static const struct lrecord_description codesys_prop_dynarr_description_1[] = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
244 XD_DYNARR_DESC (codesys_prop_dynarr, &codesys_prop_description),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
245 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
246 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
247
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
248 static const struct struct_description codesys_prop_dynarr_description = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
249 sizeof (codesys_prop_dynarr),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
250 codesys_prop_dynarr_description_1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
251 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
253 codesys_prop_dynarr *the_codesys_prop_dynarr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
255 enum codesys_prop_enum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
256 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
257 CODESYS_PROP_ALL_OK,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
258 CODESYS_PROP_ISO2022,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259 CODESYS_PROP_CCL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
263 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
264 /* Coding system functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
266
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 static Lisp_Object mark_coding_system (Lisp_Object);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268 static void print_coding_system (Lisp_Object, Lisp_Object, int);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 static void finalize_coding_system (void *header, int for_disksave);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 static const struct lrecord_description ccs_description_1[] = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
273 { XD_LISP_OBJECT, offsetof (charset_conversion_spec, from_charset) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
274 { XD_LISP_OBJECT, offsetof (charset_conversion_spec, to_charset) },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
275 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
276 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
277
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278 static const struct struct_description ccs_description = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
279 sizeof (charset_conversion_spec),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 ccs_description_1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
281 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
282
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
283 static const struct lrecord_description ccsd_description_1[] = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
284 XD_DYNARR_DESC (charset_conversion_spec_dynarr, &ccs_description),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
285 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
286 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
288 static const struct struct_description ccsd_description = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
289 sizeof (charset_conversion_spec_dynarr),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
290 ccsd_description_1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
291 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
292 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
293
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 static const struct lrecord_description coding_system_description[] = {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
295 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, name) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
296 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, doc_string) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
297 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, mnemonic) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
298 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, post_read_conversion) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
299 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, pre_write_conversion) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
300 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, eol_lf) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
301 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, eol_crlf) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
302 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, eol_cr) },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
303 #ifdef MULE
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
304 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Coding_System, iso2022.initial_charset), 4 },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
305 { XD_STRUCT_PTR, offsetof (Lisp_Coding_System, iso2022.input_conv), 1, &ccsd_description },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
306 { XD_STRUCT_PTR, offsetof (Lisp_Coding_System, iso2022.output_conv), 1, &ccsd_description },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
307 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, ccl.decode) },
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
308 { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, ccl.encode) },
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
309 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
310 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
311 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
312
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
313 DEFINE_LRECORD_IMPLEMENTATION ("coding-system", coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
314 mark_coding_system, print_coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
315 finalize_coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
316 0, 0, coding_system_description,
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
317 Lisp_Coding_System);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
318
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
320 mark_coding_system (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
321 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
322 Lisp_Coding_System *codesys = XCODING_SYSTEM (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 mark_object (CODING_SYSTEM_NAME (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
325 mark_object (CODING_SYSTEM_DOC_STRING (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
326 mark_object (CODING_SYSTEM_MNEMONIC (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
327 mark_object (CODING_SYSTEM_EOL_LF (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
328 mark_object (CODING_SYSTEM_EOL_CRLF (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
329 mark_object (CODING_SYSTEM_EOL_CR (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
330
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
331 switch (CODING_SYSTEM_TYPE (codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
332 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
333 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335 case CODESYS_ISO2022:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
336 for (i = 0; i < 4; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
337 mark_object (CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
338 if (codesys->iso2022.input_conv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
339 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
340 for (i = 0; i < Dynarr_length (codesys->iso2022.input_conv); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
341 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
342 struct charset_conversion_spec *ccs =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
343 Dynarr_atp (codesys->iso2022.input_conv, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
344 mark_object (ccs->from_charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
345 mark_object (ccs->to_charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
346 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
347 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
348 if (codesys->iso2022.output_conv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
349 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
350 for (i = 0; i < Dynarr_length (codesys->iso2022.output_conv); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
351 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
352 struct charset_conversion_spec *ccs =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
353 Dynarr_atp (codesys->iso2022.output_conv, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
354 mark_object (ccs->from_charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
355 mark_object (ccs->to_charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
356 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
357 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
360 case CODESYS_CCL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
361 mark_object (CODING_SYSTEM_CCL_DECODE (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
362 mark_object (CODING_SYSTEM_CCL_ENCODE (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
363 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
364 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
365 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
366 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
367 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
369 mark_object (CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
370 return CODING_SYSTEM_POST_READ_CONVERSION (codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
371 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
372
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
373 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
374 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
375 int escapeflag)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
376 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
377 Lisp_Coding_System *c = XCODING_SYSTEM (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
378 if (print_readably)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
379 printing_unreadable_object ("#<coding_system 0x%x>", c->header.uid);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
380
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
381 write_c_string ("#<coding_system ", printcharfun);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
382 print_internal (c->name, printcharfun, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
383 write_c_string (">", printcharfun);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
384 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
385
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
386 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
387 finalize_coding_system (void *header, int for_disksave)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
388 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
389 Lisp_Coding_System *c = (Lisp_Coding_System *) header;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
390 /* Since coding systems never go away, this function is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
391 necessary. But it would be necessary if we changed things
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
392 so that coding systems could go away. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 if (!for_disksave) /* see comment in lstream.c */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
394 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
395 switch (CODING_SYSTEM_TYPE (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
396 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
398 case CODESYS_ISO2022:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
399 if (c->iso2022.input_conv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
400 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 Dynarr_free (c->iso2022.input_conv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
402 c->iso2022.input_conv = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
403 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
404 if (c->iso2022.output_conv)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
405 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
406 Dynarr_free (c->iso2022.output_conv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 c->iso2022.output_conv = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
409 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
410 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
412 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
413 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
414 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
415 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
416
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 432
diff changeset
417 static eol_type_t
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
418 symbol_to_eol_type (Lisp_Object symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
419 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
420 CHECK_SYMBOL (symbol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
421 if (NILP (symbol)) return EOL_AUTODETECT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
422 if (EQ (symbol, Qlf)) return EOL_LF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
423 if (EQ (symbol, Qcrlf)) return EOL_CRLF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
424 if (EQ (symbol, Qcr)) return EOL_CR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
425
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
426 invalid_constant ("Unrecognized eol type", symbol);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
427 return EOL_AUTODETECT; /* not reached */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
428 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
430 static Lisp_Object
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 432
diff changeset
431 eol_type_to_symbol (eol_type_t type)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
432 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
433 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
434 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
435 default: abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
436 case EOL_LF: return Qlf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
437 case EOL_CRLF: return Qcrlf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
438 case EOL_CR: return Qcr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
439 case EOL_AUTODETECT: return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
440 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
441 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
442
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
443 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
444 setup_eol_coding_systems (Lisp_Coding_System *codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
445 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
446 Lisp_Object codesys_obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
447 int len = string_length (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
448 char *codesys_name = (char *) alloca (len + 7);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
449 int mlen = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
450 char *codesys_mnemonic=0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
452 Lisp_Object codesys_name_sym, sub_codesys_obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
454 /* kludge */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
456 XSETCODING_SYSTEM (codesys_obj, codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
457
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
458 memcpy (codesys_name,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
459 string_data (XSYMBOL (CODING_SYSTEM_NAME (codesys))->name), len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
461 if (STRINGP (CODING_SYSTEM_MNEMONIC (codesys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
462 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
463 mlen = XSTRING_LENGTH (CODING_SYSTEM_MNEMONIC (codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
464 codesys_mnemonic = (char *) alloca (mlen + 7);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
465 memcpy (codesys_mnemonic,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
466 XSTRING_DATA (CODING_SYSTEM_MNEMONIC (codesys)), mlen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
467 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
468
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
469 #define DEFINE_SUB_CODESYS(op_sys, op_sys_abbr, Type) do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
470 strcpy (codesys_name + len, "-" op_sys); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
471 if (mlen != -1) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
472 strcpy (codesys_mnemonic + mlen, op_sys_abbr); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
473 codesys_name_sym = intern (codesys_name); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
474 sub_codesys_obj = Fcopy_coding_system (codesys_obj, codesys_name_sym); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
475 XCODING_SYSTEM_EOL_TYPE (sub_codesys_obj) = Type; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
476 if (mlen != -1) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
477 XCODING_SYSTEM_MNEMONIC(sub_codesys_obj) = \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
478 build_string (codesys_mnemonic); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
479 CODING_SYSTEM_##Type (codesys) = sub_codesys_obj; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
480 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
481
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
482 DEFINE_SUB_CODESYS("unix", "", EOL_LF);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
483 DEFINE_SUB_CODESYS("dos", ":T", EOL_CRLF);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
484 DEFINE_SUB_CODESYS("mac", ":t", EOL_CR);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
485 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
486
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
487 DEFUN ("coding-system-p", Fcoding_system_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
488 Return t if OBJECT is a coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
489 A coding system is an object that defines how text containing multiple
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
490 character sets is encoded into a stream of (typically 8-bit) bytes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
491 The coding system is used to decode the stream into a series of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
492 characters (which may be from multiple charsets) when the text is read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
493 from a file or process, and is used to encode the text back into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
494 same format when it is written out to a file or process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
496 For example, many ISO2022-compliant coding systems (such as Compound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
497 Text, which is used for inter-client data under the X Window System)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
498 use escape sequences to switch between different charsets -- Japanese
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
499 Kanji, for example, is invoked with "ESC $ ( B"; ASCII is invoked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
500 with "ESC ( B"; and Cyrillic is invoked with "ESC - L". See
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
501 `make-coding-system' for more information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
503 Coding systems are normally identified using a symbol, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
504 symbol is accepted in place of the actual coding system object whenever
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
505 a coding system is called for. (This is similar to how faces work.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
506 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
507 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
508 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
509 return CODING_SYSTEMP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
510 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
512 DEFUN ("find-coding-system", Ffind_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
513 Retrieve the coding system of the given name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
515 If CODING-SYSTEM-OR-NAME is a coding-system object, it is simply
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
516 returned. Otherwise, CODING-SYSTEM-OR-NAME should be a symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
517 If there is no such coding system, nil is returned. Otherwise the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
518 associated coding system object is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
519 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
520 (coding_system_or_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
521 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
522 if (NILP (coding_system_or_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
523 coding_system_or_name = Qbinary;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
524 else if (CODING_SYSTEMP (coding_system_or_name))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
525 return coding_system_or_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
526 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
527 CHECK_SYMBOL (coding_system_or_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
528
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
529 while (1)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
530 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
531 coding_system_or_name =
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
532 Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
533
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
534 if (CODING_SYSTEMP (coding_system_or_name) || NILP (coding_system_or_name))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
535 return coding_system_or_name;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
536 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
537 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
539 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
540 Retrieve the coding system of the given name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
541 Same as `find-coding-system' except that if there is no such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
542 coding system, an error is signaled instead of returning nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
543 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
544 (name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
545 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
546 Lisp_Object coding_system = Ffind_coding_system (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
547
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
548 if (NILP (coding_system))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
549 invalid_argument ("No such coding system", name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
550 return coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
551 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
552
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
553 /* We store the coding systems in hash tables with the names as the key and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
554 actual coding system object as the value. Occasionally we need to use them
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
555 in a list format. These routines provide us with that. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
556 struct coding_system_list_closure
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
557 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
558 Lisp_Object *coding_system_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
559 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
560
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
561 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
562 add_coding_system_to_list_mapper (Lisp_Object key, Lisp_Object value,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
563 void *coding_system_list_closure)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
564 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
565 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
566 struct coding_system_list_closure *cscl =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
567 (struct coding_system_list_closure *) coding_system_list_closure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
568 Lisp_Object *coding_system_list = cscl->coding_system_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
569
432
3a7e78e1142d Import from CVS: tag r21-2-24
cvs
parents: 428
diff changeset
570 *coding_system_list = Fcons (key, *coding_system_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
571 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
572 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
573
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
574 DEFUN ("coding-system-list", Fcoding_system_list, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
575 Return a list of the names of all defined coding systems.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
576 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
577 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
578 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
579 Lisp_Object coding_system_list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
580 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
581 struct coding_system_list_closure coding_system_list_closure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
582
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
583 GCPRO1 (coding_system_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
584 coding_system_list_closure.coding_system_list = &coding_system_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 elisp_maphash (add_coding_system_to_list_mapper, Vcoding_system_hash_table,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586 &coding_system_list_closure);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 return coding_system_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
592 DEFUN ("coding-system-name", Fcoding_system_name, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 Return the name of the given coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
594 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595 (coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 coding_system = Fget_coding_system (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
598 return XCODING_SYSTEM_NAME (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 static Lisp_Coding_System *
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602 allocate_coding_system (enum coding_system_type type, Lisp_Object name)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 Lisp_Coding_System *codesys =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 alloc_lcrecord_type (Lisp_Coding_System, &lrecord_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 zero_lcrecord (codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 CODING_SYSTEM_POST_READ_CONVERSION (codesys) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 CODING_SYSTEM_EOL_TYPE (codesys) = EOL_AUTODETECT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611 CODING_SYSTEM_EOL_CRLF (codesys) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
612 CODING_SYSTEM_EOL_CR (codesys) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
613 CODING_SYSTEM_EOL_LF (codesys) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
614 CODING_SYSTEM_TYPE (codesys) = type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
615 CODING_SYSTEM_MNEMONIC (codesys) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
616 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
617 if (type == CODESYS_ISO2022)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
618 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
619 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
620 for (i = 0; i < 4; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
621 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
622 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
623 else if (type == CODESYS_CCL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
624 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
625 CODING_SYSTEM_CCL_DECODE (codesys) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
626 CODING_SYSTEM_CCL_ENCODE (codesys) = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
627 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
628 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
629 CODING_SYSTEM_NAME (codesys) = name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
631 return codesys;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
632 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
633
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
634 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
635 /* Given a list of charset conversion specs as specified in a Lisp
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
636 program, parse it into STORE_HERE. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
637
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
638 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
639 parse_charset_conversion_specs (charset_conversion_spec_dynarr *store_here,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
640 Lisp_Object spec_list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
641 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
642 Lisp_Object rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
643
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
644 EXTERNAL_LIST_LOOP (rest, spec_list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
645 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
646 Lisp_Object car = XCAR (rest);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
647 Lisp_Object from, to;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
648 struct charset_conversion_spec spec;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
649
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
650 if (!CONSP (car) || !CONSP (XCDR (car)) || !NILP (XCDR (XCDR (car))))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
651 invalid_argument ("Invalid charset conversion spec", car);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
652 from = Fget_charset (XCAR (car));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
653 to = Fget_charset (XCAR (XCDR (car)));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
654 if (XCHARSET_TYPE (from) != XCHARSET_TYPE (to))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
655 invalid_operation_2
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
656 ("Attempted conversion between different charset types",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
657 from, to);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
658 spec.from_charset = from;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
659 spec.to_charset = to;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
660
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
661 Dynarr_add (store_here, spec);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
662 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
663 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
665 /* Given a dynarr LOAD_HERE of internally-stored charset conversion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
666 specs, return the equivalent as the Lisp programmer would see it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
667
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
668 If LOAD_HERE is 0, return Qnil. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
669
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
670 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
671 unparse_charset_conversion_specs (charset_conversion_spec_dynarr *load_here)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
672 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
673 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
674 Lisp_Object result;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
675
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
676 if (!load_here)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
677 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
678 for (i = 0, result = Qnil; i < Dynarr_length (load_here); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
679 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
680 struct charset_conversion_spec *ccs = Dynarr_atp (load_here, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
681 result = Fcons (list2 (ccs->from_charset, ccs->to_charset), result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
682 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
683
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
684 return Fnreverse (result);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
685 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
686
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
687 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
689 DEFUN ("make-coding-system", Fmake_coding_system, 2, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
690 Register symbol NAME as a coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
691
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
692 TYPE describes the conversion method used and should be one of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
693
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
694 nil or 'undecided
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 Automatic conversion. XEmacs attempts to detect the coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 used in the file.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697 'no-conversion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 No conversion. Use this for binary files and such. On output,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
699 graphic characters that are not in ASCII or Latin-1 will be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 replaced by a ?. (For a no-conversion-encoded buffer, these
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 characters will only be present if you explicitly insert them.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 'shift-jis
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 Shift-JIS (a Japanese encoding commonly used in PC operating systems).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 'ucs-4
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
705 ISO 10646 UCS-4 encoding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
706 'utf-8
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
707 ISO 10646 UTF-8 encoding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
708 'iso2022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
709 Any ISO2022-compliant encoding. Among other things, this includes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
710 JIS (the Japanese encoding commonly used for e-mail), EUC (the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
711 standard Unix encoding for Japanese and other languages), and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
712 Compound Text (the encoding used in X11). You can specify more
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
713 specific information about the conversion with the PROPS argument.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
714 'big5
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
715 Big5 (the encoding commonly used for Taiwanese).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
716 'ccl
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
717 The conversion is performed using a user-written pseudo-code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
718 program. CCL (Code Conversion Language) is the name of this
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
719 pseudo-code.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
720 'internal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
721 Write out or read in the raw contents of the memory representing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
722 the buffer's text. This is primarily useful for debugging
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
723 purposes, and is only enabled when XEmacs has been compiled with
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
724 DEBUG_XEMACS defined (via the --debug configure option).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
725 WARNING: Reading in a file using 'internal conversion can result
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
726 in an internal inconsistency in the memory representing a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
727 buffer's text, which will produce unpredictable results and may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
728 cause XEmacs to crash. Under normal circumstances you should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
729 never use 'internal conversion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
730
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
731 DOC-STRING is a string describing the coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
732
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
733 PROPS is a property list, describing the specific nature of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
734 character set. Recognized properties are:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
736 'mnemonic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
737 String to be displayed in the modeline when this coding system is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
738 active.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
739
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
740 'eol-type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
741 End-of-line conversion to be used. It should be one of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
742
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
743 nil
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
744 Automatically detect the end-of-line type (LF, CRLF,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
745 or CR). Also generate subsidiary coding systems named
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
746 `NAME-unix', `NAME-dos', and `NAME-mac', that are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
747 identical to this coding system but have an EOL-TYPE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
748 value of 'lf, 'crlf, and 'cr, respectively.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
749 'lf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
750 The end of a line is marked externally using ASCII LF.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
751 Since this is also the way that XEmacs represents an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
752 end-of-line internally, specifying this option results
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
753 in no end-of-line conversion. This is the standard
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
754 format for Unix text files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
755 'crlf
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
756 The end of a line is marked externally using ASCII
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
757 CRLF. This is the standard format for MS-DOS text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
758 files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
759 'cr
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
760 The end of a line is marked externally using ASCII CR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
761 This is the standard format for Macintosh text files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
762 t
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
763 Automatically detect the end-of-line type but do not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
764 generate subsidiary coding systems. (This value is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
765 converted to nil when stored internally, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
766 `coding-system-property' will return nil.)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
767
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
768 'post-read-conversion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
769 Function called after a file has been read in, to perform the
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
770 decoding. Called with two arguments, START and END, denoting
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
771 a region of the current buffer to be decoded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
772
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
773 'pre-write-conversion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
774 Function called before a file is written out, to perform the
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
775 encoding. Called with two arguments, START and END, denoting
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 a region of the current buffer to be encoded.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
777
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 The following additional properties are recognized if TYPE is 'iso2022:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 'charset-g0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 'charset-g1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 'charset-g2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 'charset-g3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 The character set initially designated to the G0 - G3 registers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786 The value should be one of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
788 -- A charset object (designate that character set)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 -- nil (do not ever use this register)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 -- t (no character set is initially designated to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791 the register, but may be later on; this automatically
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
792 sets the corresponding `force-g*-on-output' property)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
794 'force-g0-on-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
795 'force-g1-on-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
796 'force-g2-on-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
797 'force-g2-on-output
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
798 If non-nil, send an explicit designation sequence on output before
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
799 using the specified register.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
801 'short
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
802 If non-nil, use the short forms "ESC $ @", "ESC $ A", and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
803 "ESC $ B" on output in place of the full designation sequences
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
804 "ESC $ ( @", "ESC $ ( A", and "ESC $ ( B".
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
805
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
806 'no-ascii-eol
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
807 If non-nil, don't designate ASCII to G0 at each end of line on output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
808 Setting this to non-nil also suppresses other state-resetting that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
809 normally happens at the end of a line.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
810
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
811 'no-ascii-cntl
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
812 If non-nil, don't designate ASCII to G0 before control chars on output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
813
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
814 'seven
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
815 If non-nil, use 7-bit environment on output. Otherwise, use 8-bit
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
816 environment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
817
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
818 'lock-shift
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
819 If non-nil, use locking-shift (SO/SI) instead of single-shift
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
820 or designation by escape sequence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
821
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
822 'no-iso6429
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
823 If non-nil, don't use ISO6429's direction specification.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
824
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
825 'escape-quoted
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
826 If non-nil, literal control characters that are the same as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
827 the beginning of a recognized ISO2022 or ISO6429 escape sequence
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
828 (in particular, ESC (0x1B), SO (0x0E), SI (0x0F), SS2 (0x8E),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
829 SS3 (0x8F), and CSI (0x9B)) are "quoted" with an escape character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
830 so that they can be properly distinguished from an escape sequence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
831 (Note that doing this results in a non-portable encoding.) This
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
832 encoding flag is used for byte-compiled files. Note that ESC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
833 is a good choice for a quoting character because there are no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
834 escape sequences whose second byte is a character from the Control-0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
835 or Control-1 character sets; this is explicitly disallowed by the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
836 ISO2022 standard.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
838 'input-charset-conversion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
839 A list of conversion specifications, specifying conversion of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
840 characters in one charset to another when decoding is performed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
841 Each specification is a list of two elements: the source charset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
842 and the destination charset.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
843
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
844 'output-charset-conversion
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
845 A list of conversion specifications, specifying conversion of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
846 characters in one charset to another when encoding is performed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
847 The form of each specification is the same as for
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
848 'input-charset-conversion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
849
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
850
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
851 The following additional properties are recognized (and required)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
852 if TYPE is 'ccl:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
854 'decode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
855 CCL program used for decoding (converting to internal format).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
856
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
857 'encode
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
858 CCL program used for encoding (converting to external format).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
859 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
860 (name, type, doc_string, props))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
861 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
862 Lisp_Coding_System *codesys;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
863 enum coding_system_type ty;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
864 int need_to_setup_eol_systems = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
866 /* Convert type to constant */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
867 if (NILP (type) || EQ (type, Qundecided))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
868 { ty = CODESYS_AUTODETECT; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
869 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
870 else if (EQ (type, Qshift_jis)) { ty = CODESYS_SHIFT_JIS; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
871 else if (EQ (type, Qiso2022)) { ty = CODESYS_ISO2022; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
872 else if (EQ (type, Qbig5)) { ty = CODESYS_BIG5; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
873 else if (EQ (type, Qucs4)) { ty = CODESYS_UCS4; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
874 else if (EQ (type, Qutf8)) { ty = CODESYS_UTF8; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
875 else if (EQ (type, Qccl)) { ty = CODESYS_CCL; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
876 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
877 else if (EQ (type, Qno_conversion)) { ty = CODESYS_NO_CONVERSION; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
878 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
879 else if (EQ (type, Qinternal)) { ty = CODESYS_INTERNAL; }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
880 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
881 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
882 invalid_constant ("Invalid coding system type", type);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
884 CHECK_SYMBOL (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
885
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
886 codesys = allocate_coding_system (ty, name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
888 if (NILP (doc_string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
889 doc_string = build_string ("");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
890 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
891 CHECK_STRING (doc_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
892 CODING_SYSTEM_DOC_STRING (codesys) = doc_string;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
893
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
894 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
895 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, props)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
896 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
897 if (EQ (key, Qmnemonic))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
898 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
899 if (!NILP (value))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
900 CHECK_STRING (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
901 CODING_SYSTEM_MNEMONIC (codesys) = value;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
902 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
903
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
904 else if (EQ (key, Qeol_type))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
905 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
906 need_to_setup_eol_systems = NILP (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
907 if (EQ (value, Qt))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
908 value = Qnil;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
909 CODING_SYSTEM_EOL_TYPE (codesys) = symbol_to_eol_type (value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
910 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
911
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
912 else if (EQ (key, Qpost_read_conversion)) CODING_SYSTEM_POST_READ_CONVERSION (codesys) = value;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
913 else if (EQ (key, Qpre_write_conversion)) CODING_SYSTEM_PRE_WRITE_CONVERSION (codesys) = value;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
914 #ifdef MULE
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
915 else if (ty == CODESYS_ISO2022)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
916 {
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
917 #define FROB_INITIAL_CHARSET(charset_num) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
918 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, charset_num) = \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
919 ((EQ (value, Qt) || EQ (value, Qnil)) ? value : Fget_charset (value))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
920
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
921 if (EQ (key, Qcharset_g0)) FROB_INITIAL_CHARSET (0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
922 else if (EQ (key, Qcharset_g1)) FROB_INITIAL_CHARSET (1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
923 else if (EQ (key, Qcharset_g2)) FROB_INITIAL_CHARSET (2);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
924 else if (EQ (key, Qcharset_g3)) FROB_INITIAL_CHARSET (3);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
925
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
926 #define FROB_FORCE_CHARSET(charset_num) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
927 CODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT (codesys, charset_num) = !NILP (value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
928
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
929 else if (EQ (key, Qforce_g0_on_output)) FROB_FORCE_CHARSET (0);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
930 else if (EQ (key, Qforce_g1_on_output)) FROB_FORCE_CHARSET (1);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
931 else if (EQ (key, Qforce_g2_on_output)) FROB_FORCE_CHARSET (2);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
932 else if (EQ (key, Qforce_g3_on_output)) FROB_FORCE_CHARSET (3);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 #define FROB_BOOLEAN_PROPERTY(prop) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 CODING_SYSTEM_ISO2022_##prop (codesys) = !NILP (value)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
937 else if (EQ (key, Qshort)) FROB_BOOLEAN_PROPERTY (SHORT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
938 else if (EQ (key, Qno_ascii_eol)) FROB_BOOLEAN_PROPERTY (NO_ASCII_EOL);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
939 else if (EQ (key, Qno_ascii_cntl)) FROB_BOOLEAN_PROPERTY (NO_ASCII_CNTL);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
940 else if (EQ (key, Qseven)) FROB_BOOLEAN_PROPERTY (SEVEN);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
941 else if (EQ (key, Qlock_shift)) FROB_BOOLEAN_PROPERTY (LOCK_SHIFT);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
942 else if (EQ (key, Qno_iso6429)) FROB_BOOLEAN_PROPERTY (NO_ISO6429);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
943 else if (EQ (key, Qescape_quoted)) FROB_BOOLEAN_PROPERTY (ESCAPE_QUOTED);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
944
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
945 else if (EQ (key, Qinput_charset_conversion))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
946 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
947 codesys->iso2022.input_conv =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
948 Dynarr_new (charset_conversion_spec);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
949 parse_charset_conversion_specs (codesys->iso2022.input_conv,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
950 value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
951 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
952 else if (EQ (key, Qoutput_charset_conversion))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
953 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
954 codesys->iso2022.output_conv =
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
955 Dynarr_new (charset_conversion_spec);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
956 parse_charset_conversion_specs (codesys->iso2022.output_conv,
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
957 value);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
958 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
959 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
960 invalid_constant ("Unrecognized property", key);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
961 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
962 else if (EQ (type, Qccl))
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
963 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
964 Lisp_Object sym;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
965 struct ccl_program test_ccl;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
966 Extbyte *suffix;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
967
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
968 /* Check key first. */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
969 if (EQ (key, Qdecode))
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
970 suffix = "-ccl-decode";
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
971 else if (EQ (key, Qencode))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
972 suffix = "-ccl-encode";
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
973 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
974 invalid_constant ("Unrecognized property", key);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
975
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
976 /* If value is vector, register it as a ccl program
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
977 associated with an newly created symbol for
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
978 backward compatibility. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
979 if (VECTORP (value))
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
980 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
981 sym = Fintern (concat2 (Fsymbol_name (name),
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
982 build_string (suffix)),
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
983 Qnil);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
984 Fregister_ccl_program (sym, value);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
985 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
986 else
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
987 {
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
988 CHECK_SYMBOL (value);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
989 sym = value;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
990 }
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
991 /* check if the given ccl programs are valid. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
992 if (setup_ccl_program (&test_ccl, sym) < 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
993 invalid_argument ("Invalid CCL program", value);
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
994
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
995 if (EQ (key, Qdecode))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
996 CODING_SYSTEM_CCL_DECODE (codesys) = sym;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
997 else if (EQ (key, Qencode))
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
998 CODING_SYSTEM_CCL_ENCODE (codesys) = sym;
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
999
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1000 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1001 #endif /* MULE */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1002 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1003 invalid_constant ("Unrecognized property", key);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1004 }
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1005 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 if (need_to_setup_eol_systems)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008 setup_eol_coding_systems (codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1009
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1010 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1011 Lisp_Object codesys_obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1012 XSETCODING_SYSTEM (codesys_obj, codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1013 Fputhash (name, codesys_obj, Vcoding_system_hash_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1014 return codesys_obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1015 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1016 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1017
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1018 DEFUN ("copy-coding-system", Fcopy_coding_system, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1019 Copy OLD-CODING-SYSTEM to NEW-NAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1020 If NEW-NAME does not name an existing coding system, a new one will
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1021 be created.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1022 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1023 (old_coding_system, new_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1024 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1025 Lisp_Object new_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1026 old_coding_system = Fget_coding_system (old_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1027 new_coding_system = Ffind_coding_system (new_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1028 if (NILP (new_coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1029 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1030 XSETCODING_SYSTEM (new_coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1031 allocate_coding_system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1032 (XCODING_SYSTEM_TYPE (old_coding_system),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1033 new_name));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1034 Fputhash (new_name, new_coding_system, Vcoding_system_hash_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1035 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1037 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1038 Lisp_Coding_System *to = XCODING_SYSTEM (new_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1039 Lisp_Coding_System *from = XCODING_SYSTEM (old_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1040 memcpy (((char *) to ) + sizeof (to->header),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1041 ((char *) from) + sizeof (from->header),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1042 sizeof (*from) - sizeof (from->header));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1043 to->name = new_name;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1044 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1045 return new_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1046 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1047
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1048 DEFUN ("coding-system-canonical-name-p", Fcoding_system_canonical_name_p, 1, 1, 0, /*
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1049 Return t if OBJECT names a coding system, and is not a coding system alias.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1051 (object))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1052 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1053 return CODING_SYSTEMP (Fgethash (object, Vcoding_system_hash_table, Qnil))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1054 ? Qt : Qnil;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1055 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1056
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1057 DEFUN ("coding-system-alias-p", Fcoding_system_alias_p, 1, 1, 0, /*
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1058 Return t if OBJECT is a coding system alias.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1059 All coding system aliases are created by `define-coding-system-alias'.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1060 */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1061 (object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1063 return SYMBOLP (Fgethash (object, Vcoding_system_hash_table, Qzero))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1064 ? Qt : Qnil;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1065 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1066
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1067 DEFUN ("coding-system-aliasee", Fcoding_system_aliasee, 1, 1, 0, /*
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1068 Return the coding-system symbol for which symbol ALIAS is an alias.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1069 */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1070 (alias))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1071 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1072 Lisp_Object aliasee = Fgethash (alias, Vcoding_system_hash_table, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1073 if (SYMBOLP (aliasee))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1074 return aliasee;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1075 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1076 invalid_argument ("Symbol is not a coding system alias", alias);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1077 return Qnil; /* To keep the compiler happy */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1078 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1079
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1080 static Lisp_Object
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1081 append_suffix_to_symbol (Lisp_Object symbol, const char *ascii_string)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1082 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1083 return Fintern (concat2 (Fsymbol_name (symbol), build_string (ascii_string)),
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1084 Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1085 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1086
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1087 /* A maphash function, for removing dangling coding system aliases. */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1088 static int
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1089 dangling_coding_system_alias_p (Lisp_Object alias,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1090 Lisp_Object aliasee,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1091 void *dangling_aliases)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1092 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1093 if (SYMBOLP (aliasee)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1094 && NILP (Fgethash (aliasee, Vcoding_system_hash_table, Qnil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1095 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1096 (*(int *) dangling_aliases)++;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1097 return 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1098 }
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1099 else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1100 return 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1101 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1102
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1103 DEFUN ("define-coding-system-alias", Fdefine_coding_system_alias, 2, 2, 0, /*
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1104 Define symbol ALIAS as an alias for coding system ALIASEE.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1105
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1106 You can use this function to redefine an alias that has already been defined,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1107 but you cannot redefine a name which is the canonical name for a coding system.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1108 \(a canonical name of a coding system is what is returned when you call
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1109 `coding-system-name' on a coding system).
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1110
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1111 ALIASEE itself can be an alias, which allows you to define nested aliases.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1112
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1113 You are forbidden, however, from creating alias loops or `dangling' aliases.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1114 These will be detected, and an error will be signaled if you attempt to do so.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1115
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1116 If ALIASEE is nil, then ALIAS will simply be undefined.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1117
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1118 See also `coding-system-alias-p', `coding-system-aliasee',
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1119 and `coding-system-canonical-name-p'.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1120 */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1121 (alias, aliasee))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1122 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1123 Lisp_Object real_coding_system, probe;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1124
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1125 CHECK_SYMBOL (alias);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1126
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1127 if (!NILP (Fcoding_system_canonical_name_p (alias)))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1128 invalid_change
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1129 ("Symbol is the canonical name of a coding system and cannot be redefined",
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1130 alias);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1131
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1132 if (NILP (aliasee))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1133 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1134 Lisp_Object subsidiary_unix = append_suffix_to_symbol (alias, "-unix");
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1135 Lisp_Object subsidiary_dos = append_suffix_to_symbol (alias, "-dos");
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1136 Lisp_Object subsidiary_mac = append_suffix_to_symbol (alias, "-mac");
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1137
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1138 Fremhash (alias, Vcoding_system_hash_table);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1139
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1140 /* Undefine subsidiary aliases,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1141 presumably created by a previous call to this function */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1142 if (! NILP (Fcoding_system_alias_p (subsidiary_unix)) &&
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1143 ! NILP (Fcoding_system_alias_p (subsidiary_dos)) &&
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1144 ! NILP (Fcoding_system_alias_p (subsidiary_mac)))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1145 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1146 Fdefine_coding_system_alias (subsidiary_unix, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1147 Fdefine_coding_system_alias (subsidiary_dos, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1148 Fdefine_coding_system_alias (subsidiary_mac, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1149 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1150
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1151 /* Undefine dangling coding system aliases. */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1152 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1153 int dangling_aliases;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1154
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1155 do {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1156 dangling_aliases = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1157 elisp_map_remhash (dangling_coding_system_alias_p,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1158 Vcoding_system_hash_table,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1159 &dangling_aliases);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1160 } while (dangling_aliases > 0);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1161 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1162
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1163 return Qnil;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1164 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1165
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1166 if (CODING_SYSTEMP (aliasee))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1167 aliasee = XCODING_SYSTEM_NAME (aliasee);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1168
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1169 /* Checks that aliasee names a coding-system */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1170 real_coding_system = Fget_coding_system (aliasee);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1171
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1172 /* Check for coding system alias loops */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1173 if (EQ (alias, aliasee))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1174 alias_loop: invalid_operation_2
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1175 ("Attempt to create a coding system alias loop", alias, aliasee);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1176
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1177 for (probe = aliasee;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1178 SYMBOLP (probe);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1179 probe = Fgethash (probe, Vcoding_system_hash_table, Qzero))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1180 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1181 if (EQ (probe, alias))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1182 goto alias_loop;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1183 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1184
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1185 Fputhash (alias, aliasee, Vcoding_system_hash_table);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1186
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1187 /* Set up aliases for subsidiaries.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1188 #### There must be a better way to handle subsidiary coding systems. */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1189 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1190 static const char *suffixes[] = { "-unix", "-dos", "-mac" };
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1191 int i;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1192 for (i = 0; i < countof (suffixes); i++)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1193 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1194 Lisp_Object alias_subsidiary =
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1195 append_suffix_to_symbol (alias, suffixes[i]);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1196 Lisp_Object aliasee_subsidiary =
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1197 append_suffix_to_symbol (aliasee, suffixes[i]);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1198
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1199 if (! NILP (Ffind_coding_system (aliasee_subsidiary)))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1200 Fdefine_coding_system_alias (alias_subsidiary, aliasee_subsidiary);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1201 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1202 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1203 /* FSF return value is a vector of [ALIAS-unix ALIAS-dos ALIAS-mac],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1204 but it doesn't look intentional, so I'd rather return something
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1205 meaningful or nothing at all. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1206 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1207 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1209 static Lisp_Object
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 432
diff changeset
1210 subsidiary_coding_system (Lisp_Object coding_system, eol_type_t type)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1212 Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1213 Lisp_Object new_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1214
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1215 if (CODING_SYSTEM_EOL_TYPE (cs) != EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1216 return coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1217
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1218 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1219 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1220 case EOL_AUTODETECT: return coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1221 case EOL_LF: new_coding_system = CODING_SYSTEM_EOL_LF (cs); break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1222 case EOL_CR: new_coding_system = CODING_SYSTEM_EOL_CR (cs); break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1223 case EOL_CRLF: new_coding_system = CODING_SYSTEM_EOL_CRLF (cs); break;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1224 default: abort (); return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1225 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1226
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1227 return NILP (new_coding_system) ? coding_system : new_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1228 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1229
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1230 DEFUN ("subsidiary-coding-system", Fsubsidiary_coding_system, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1231 Return the subsidiary coding system of CODING-SYSTEM with eol type EOL-TYPE.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1232 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1233 (coding_system, eol_type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1234 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1235 coding_system = Fget_coding_system (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1236
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1237 return subsidiary_coding_system (coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1238 symbol_to_eol_type (eol_type));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1239 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1240
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1242 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1243 /* Coding system accessors */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1244 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1245
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1246 DEFUN ("coding-system-doc-string", Fcoding_system_doc_string, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1247 Return the doc string for CODING-SYSTEM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1248 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1249 (coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1250 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1251 coding_system = Fget_coding_system (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1252 return XCODING_SYSTEM_DOC_STRING (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1253 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1255 DEFUN ("coding-system-type", Fcoding_system_type, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1256 Return the type of CODING-SYSTEM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1257 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1258 (coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1259 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1260 switch (XCODING_SYSTEM_TYPE (Fget_coding_system (coding_system)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1261 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1262 default: abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1263 case CODESYS_AUTODETECT: return Qundecided;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1264 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1265 case CODESYS_SHIFT_JIS: return Qshift_jis;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1266 case CODESYS_ISO2022: return Qiso2022;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1267 case CODESYS_BIG5: return Qbig5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1268 case CODESYS_UCS4: return Qucs4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1269 case CODESYS_UTF8: return Qutf8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1270 case CODESYS_CCL: return Qccl;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1271 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1272 case CODESYS_NO_CONVERSION: return Qno_conversion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1273 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1274 case CODESYS_INTERNAL: return Qinternal;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1275 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1276 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1277 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1278
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1279 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1280 static
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1281 Lisp_Object coding_system_charset (Lisp_Object coding_system, int gnum)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1282 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1283 Lisp_Object cs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1284 = XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, gnum);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1285
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1286 return CHARSETP (cs) ? XCHARSET_NAME (cs) : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1287 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1288 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1289
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1290 DEFUN ("coding-system-property", Fcoding_system_property, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1291 Return the PROP property of CODING-SYSTEM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1292 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1293 (coding_system, prop))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1294 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1295 int i, ok = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1296 enum coding_system_type type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1298 coding_system = Fget_coding_system (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1299 CHECK_SYMBOL (prop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1300 type = XCODING_SYSTEM_TYPE (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1302 for (i = 0; !ok && i < Dynarr_length (the_codesys_prop_dynarr); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1303 if (EQ (Dynarr_at (the_codesys_prop_dynarr, i).sym, prop))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1304 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1305 ok = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1306 switch (Dynarr_at (the_codesys_prop_dynarr, i).prop_type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1307 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1308 case CODESYS_PROP_ALL_OK:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1309 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1310 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1311 case CODESYS_PROP_ISO2022:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1312 if (type != CODESYS_ISO2022)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1313 invalid_argument
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1314 ("Property only valid in ISO2022 coding systems",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1315 prop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1316 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1318 case CODESYS_PROP_CCL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1319 if (type != CODESYS_CCL)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1320 invalid_argument
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1321 ("Property only valid in CCL coding systems",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1322 prop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1323 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1324 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1325 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1326 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1327 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1328 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1329
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1330 if (!ok)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1331 invalid_constant ("Unrecognized property", prop);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1333 if (EQ (prop, Qname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1334 return XCODING_SYSTEM_NAME (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1335 else if (EQ (prop, Qtype))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1336 return Fcoding_system_type (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1337 else if (EQ (prop, Qdoc_string))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1338 return XCODING_SYSTEM_DOC_STRING (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1339 else if (EQ (prop, Qmnemonic))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1340 return XCODING_SYSTEM_MNEMONIC (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1341 else if (EQ (prop, Qeol_type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1342 return eol_type_to_symbol (XCODING_SYSTEM_EOL_TYPE (coding_system));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1343 else if (EQ (prop, Qeol_lf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1344 return XCODING_SYSTEM_EOL_LF (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1345 else if (EQ (prop, Qeol_crlf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1346 return XCODING_SYSTEM_EOL_CRLF (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1347 else if (EQ (prop, Qeol_cr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1348 return XCODING_SYSTEM_EOL_CR (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1349 else if (EQ (prop, Qpost_read_conversion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1350 return XCODING_SYSTEM_POST_READ_CONVERSION (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1351 else if (EQ (prop, Qpre_write_conversion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1352 return XCODING_SYSTEM_PRE_WRITE_CONVERSION (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1353 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1354 else if (type == CODESYS_ISO2022)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1355 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1356 if (EQ (prop, Qcharset_g0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1357 return coding_system_charset (coding_system, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1358 else if (EQ (prop, Qcharset_g1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1359 return coding_system_charset (coding_system, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1360 else if (EQ (prop, Qcharset_g2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1361 return coding_system_charset (coding_system, 2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1362 else if (EQ (prop, Qcharset_g3))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1363 return coding_system_charset (coding_system, 3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1365 #define FORCE_CHARSET(charset_num) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1366 (XCODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1367 (coding_system, charset_num) ? Qt : Qnil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1369 else if (EQ (prop, Qforce_g0_on_output)) return FORCE_CHARSET (0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1370 else if (EQ (prop, Qforce_g1_on_output)) return FORCE_CHARSET (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1371 else if (EQ (prop, Qforce_g2_on_output)) return FORCE_CHARSET (2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1372 else if (EQ (prop, Qforce_g3_on_output)) return FORCE_CHARSET (3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1374 #define LISP_BOOLEAN(prop) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1375 (XCODING_SYSTEM_ISO2022_##prop (coding_system) ? Qt : Qnil)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1376
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1377 else if (EQ (prop, Qshort)) return LISP_BOOLEAN (SHORT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1378 else if (EQ (prop, Qno_ascii_eol)) return LISP_BOOLEAN (NO_ASCII_EOL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1379 else if (EQ (prop, Qno_ascii_cntl)) return LISP_BOOLEAN (NO_ASCII_CNTL);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1380 else if (EQ (prop, Qseven)) return LISP_BOOLEAN (SEVEN);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1381 else if (EQ (prop, Qlock_shift)) return LISP_BOOLEAN (LOCK_SHIFT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1382 else if (EQ (prop, Qno_iso6429)) return LISP_BOOLEAN (NO_ISO6429);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1383 else if (EQ (prop, Qescape_quoted)) return LISP_BOOLEAN (ESCAPE_QUOTED);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1385 else if (EQ (prop, Qinput_charset_conversion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1386 return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1387 unparse_charset_conversion_specs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1388 (XCODING_SYSTEM (coding_system)->iso2022.input_conv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1389 else if (EQ (prop, Qoutput_charset_conversion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1390 return
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1391 unparse_charset_conversion_specs
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1392 (XCODING_SYSTEM (coding_system)->iso2022.output_conv);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1394 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1395 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1396 else if (type == CODESYS_CCL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1397 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1398 if (EQ (prop, Qdecode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1399 return XCODING_SYSTEM_CCL_DECODE (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1400 else if (EQ (prop, Qencode))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1401 return XCODING_SYSTEM_CCL_ENCODE (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1402 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1403 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1404 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1405 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1406 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1408
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 return Qnil; /* not reached */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1410 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1411
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1413 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 /* Coding category functions */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1416
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1417 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1418 decode_coding_category (Lisp_Object symbol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1419 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1420 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1422 CHECK_SYMBOL (symbol);
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
1423 for (i = 0; i < CODING_CATEGORY_LAST; i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1424 if (EQ (coding_category_symbol[i], symbol))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1425 return i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1427 invalid_constant ("Unrecognized coding category", symbol);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1428 return 0; /* not reached */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1429 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1430
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1431 DEFUN ("coding-category-list", Fcoding_category_list, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1432 Return a list of all recognized coding categories.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1433 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1434 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1435 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1437 Lisp_Object list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1438
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
1439 for (i = CODING_CATEGORY_LAST - 1; i >= 0; i--)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1440 list = Fcons (coding_category_symbol[i], list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441 return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1442 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1443
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 DEFUN ("set-coding-priority-list", Fset_coding_priority_list, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 Change the priority order of the coding categories.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446 LIST should be list of coding categories, in descending order of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1447 priority. Unspecified coding categories will be lower in priority
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1448 than all specified ones, in the same relative order they were in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1449 previously.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1450 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1451 (list))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1452 {
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
1453 int category_to_priority[CODING_CATEGORY_LAST];
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 int i, j;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1455 Lisp_Object rest;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1456
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1457 /* First generate a list that maps coding categories to priorities. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1458
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
1459 for (i = 0; i < CODING_CATEGORY_LAST; i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1460 category_to_priority[i] = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1462 /* Highest priority comes from the specified list. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1463 i = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1464 EXTERNAL_LIST_LOOP (rest, list)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1465 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1466 int cat = decode_coding_category (XCAR (rest));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1468 if (category_to_priority[cat] >= 0)
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1469 sferror ("Duplicate coding category in list", XCAR (rest));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1470 category_to_priority[cat] = i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1471 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1473 /* Now go through the existing categories by priority to retrieve
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1474 the categories not yet specified and preserve their priority
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1475 order. */
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
1476 for (j = 0; j < CODING_CATEGORY_LAST; j++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1477 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1478 int cat = fcd->coding_category_by_priority[j];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1479 if (category_to_priority[cat] < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 category_to_priority[cat] = i++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1481 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1482
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 /* Now we need to construct the inverse of the mapping we just
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1484 constructed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1485
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
1486 for (i = 0; i < CODING_CATEGORY_LAST; i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1487 fcd->coding_category_by_priority[category_to_priority[i]] = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1488
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1489 /* Phew! That was confusing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1490 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1491 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1492
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1493 DEFUN ("coding-priority-list", Fcoding_priority_list, 0, 0, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1494 Return a list of coding categories in descending order of priority.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1495 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1496 ())
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1497 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1498 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1499 Lisp_Object list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1500
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
1501 for (i = CODING_CATEGORY_LAST - 1; i >= 0; i--)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1502 list = Fcons (coding_category_symbol[fcd->coding_category_by_priority[i]],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1503 list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1504 return list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1505 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1506
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1507 DEFUN ("set-coding-category-system", Fset_coding_category_system, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1508 Change the coding system associated with a coding category.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1509 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1510 (coding_category, coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1511 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1512 int cat = decode_coding_category (coding_category);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1513
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1514 coding_system = Fget_coding_system (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1515 fcd->coding_category_system[cat] = coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1516 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1517 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1519 DEFUN ("coding-category-system", Fcoding_category_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1520 Return the coding system associated with a coding category.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1521 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1522 (coding_category))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1523 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1524 int cat = decode_coding_category (coding_category);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1525 Lisp_Object sys = fcd->coding_category_system[cat];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1527 if (!NILP (sys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1528 return XCODING_SYSTEM_NAME (sys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1529 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1530 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1531
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1532
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1533 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1534 /* Detecting the encoding of data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1535 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1537 struct detection_state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1538 {
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 432
diff changeset
1539 eol_type_t eol_type;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1540 int seen_non_ascii;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1541 int mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1542 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1543 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1544 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1545 int mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1546 int in_second_byte;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1547 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1548 big5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1550 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1551 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1552 int mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1553 int in_second_byte;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1554 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1555 shift_jis;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1557 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1558 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1559 int mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1560 int in_byte;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1561 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1562 ucs4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1563
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1564 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1565 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1566 int mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1567 int in_byte;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1568 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1569 utf8;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1571 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1572 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1573 int mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1574 int initted;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1575 struct iso2022_decoder iso;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1576 unsigned int flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1577 int high_byte_count;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1578 unsigned int saw_single_shift:1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1579 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1580 iso2022;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1581 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1582 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1583 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1584 int seen_anything;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1585 int just_saw_cr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1586 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1587 eol;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1588 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1590 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 acceptable_control_char_p (int c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1594 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1595 /* Allow and ignore control characters that you might
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1596 reasonably see in a text file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 case '\r':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 case '\n':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 case '\t':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600 case 7: /* bell */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 case 8: /* backspace */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 case 11: /* vertical tab */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 case 12: /* form feed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 case 26: /* MS-DOS C-z junk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 case 31: /* '^_' -- for info */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1607 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1609 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1610 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1611
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1612 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 mask_has_at_most_one_bit_p (int mask)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1615 /* Perhaps the only thing useful you learn from intensive Microsoft
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 technical interviews */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 return (mask & (mask - 1)) == 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1619
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 432
diff changeset
1620 static eol_type_t
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1621 detect_eol_type (struct detection_state *st, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
1622 Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1623 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1624 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1625 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1626 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1627 if (c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1628 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1629 if (st->eol.just_saw_cr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1630 return EOL_CRLF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1631 else if (st->eol.seen_anything)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1632 return EOL_LF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1633 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1634 else if (st->eol.just_saw_cr)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1635 return EOL_CR;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1636 else if (c == '\r')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1637 st->eol.just_saw_cr = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1638 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1639 st->eol.just_saw_cr = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1640 st->eol.seen_anything = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1641 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1642
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1643 return EOL_AUTODETECT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1644 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1645
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1646 /* Attempt to determine the encoding and EOL type of the given text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1647 Before calling this function for the first type, you must initialize
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1648 st->eol_type as appropriate and initialize st->mask to ~0.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1649
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1650 st->eol_type holds the determined EOL type, or EOL_AUTODETECT if
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1651 not yet known.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1653 st->mask holds the determined coding category mask, or ~0 if only
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1654 ASCII has been seen so far.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1656 Returns:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1657
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1658 0 == st->eol_type is EOL_AUTODETECT and/or more than coding category
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1659 is present in st->mask
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1660 1 == definitive answers are here for both st->eol_type and st->mask
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1661 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1662
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663 static int
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
1664 detect_coding_type (struct detection_state *st, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
1665 Lstream_data_count n, int just_do_eol)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1666 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1667 if (st->eol_type == EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1668 st->eol_type = detect_eol_type (st, src, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1669
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1670 if (just_do_eol)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1671 return st->eol_type != EOL_AUTODETECT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1672
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1673 if (!st->seen_non_ascii)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1674 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1675 for (; n; n--, src++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1676 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1677 unsigned char c = *(unsigned char *) src;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1678 if ((c < 0x20 && !acceptable_control_char_p (c)) || c >= 0x80)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1679 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1680 st->seen_non_ascii = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1681 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 st->shift_jis.mask = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 st->big5.mask = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 st->ucs4.mask = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 st->utf8.mask = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1686 st->iso2022.mask = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1691 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1692
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 if (!n)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1694 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1695 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 if (!mask_has_at_most_one_bit_p (st->iso2022.mask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697 st->iso2022.mask = detect_coding_iso2022 (st, src, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 if (!mask_has_at_most_one_bit_p (st->shift_jis.mask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 st->shift_jis.mask = detect_coding_sjis (st, src, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 if (!mask_has_at_most_one_bit_p (st->big5.mask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 st->big5.mask = detect_coding_big5 (st, src, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 if (!mask_has_at_most_one_bit_p (st->utf8.mask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 st->utf8.mask = detect_coding_utf8 (st, src, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 if (!mask_has_at_most_one_bit_p (st->ucs4.mask))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705 st->ucs4.mask = detect_coding_ucs4 (st, src, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 st->mask
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 = st->iso2022.mask | st->shift_jis.mask | st->big5.mask
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 | st->utf8.mask | st->ucs4.mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1710 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1711 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 int retval = mask_has_at_most_one_bit_p (st->mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 st->mask |= CODING_CATEGORY_NO_CONVERSION_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1714 return retval && st->eol_type != EOL_AUTODETECT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1715 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1717
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1718 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 coding_system_from_mask (int mask)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 if (mask == ~0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 /* If the file was entirely or basically ASCII, use the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 default value of `buffer-file-coding-system'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 Lisp_Object retval =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 if (!NILP (retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1729 retval = Ffind_coding_system (retval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1730 if (NILP (retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1731 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1732 warn_when_safe
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1733 (Qbad_variable, Qwarning,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1734 "Invalid `default-buffer-file-coding-system', set to nil");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1735 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1736 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1737 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1738 if (NILP (retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1739 retval = Fget_coding_system (Qraw_text);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1740 return retval;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1741 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1742 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1743 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1744 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1745 int cat = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1746 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1747 mask = postprocess_iso2022_mask (mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1748 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1749 /* Look through the coding categories by priority and find
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1750 the first one that is allowed. */
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
1751 for (i = 0; i < CODING_CATEGORY_LAST; i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1752 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1753 cat = fcd->coding_category_by_priority[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1754 if ((mask & (1 << cat)) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1755 !NILP (fcd->coding_category_system[cat]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1756 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1757 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1758 if (cat >= 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1759 return fcd->coding_category_system[cat];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1760 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1761 return Fget_coding_system (Qraw_text);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1762 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1765 /* Given a seekable read stream and potential coding system and EOL type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1766 as specified, do any autodetection that is called for. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1767 coding system and/or EOL type are not `autodetect', they will be left
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1768 alone; but this function will never return an autodetect coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1769 or EOL type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1770
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1771 This function does not automatically fetch subsidiary coding systems;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1772 that should be unnecessary with the explicit eol-type argument. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1774 #define LENGTH(string_constant) (sizeof (string_constant) - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1775
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1776 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1777 determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out,
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 432
diff changeset
1778 eol_type_t *eol_type_in_out)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1779 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1780 struct detection_state decst;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1781
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1782 if (*eol_type_in_out == EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1783 *eol_type_in_out = XCODING_SYSTEM_EOL_TYPE (*codesys_in_out);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1785 xzero (decst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1786 decst.eol_type = *eol_type_in_out;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1787 decst.mask = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1788
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1789 /* If autodetection is called for, do it now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1790 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1791 || *eol_type_in_out == EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1792 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1793 Extbyte buf[4096];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1794 Lisp_Object coding_system = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1795 Extbyte *p;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
1796 Lstream_data_count nread = Lstream_read (stream, buf, sizeof (buf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1797 Extbyte *scan_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1798
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1799 /* Look for initial "-*-"; mode line prefix */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1800 for (p = buf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1801 scan_end = buf + nread - LENGTH ("-*-coding:?-*-");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1802 p <= scan_end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1803 && *p != '\n'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1804 && *p != '\r';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1805 p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1806 if (*p == '-' && *(p+1) == '*' && *(p+2) == '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1807 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1808 Extbyte *local_vars_beg = p + 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1809 /* Look for final "-*-"; mode line suffix */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1810 for (p = local_vars_beg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1811 scan_end = buf + nread - LENGTH ("-*-");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1812 p <= scan_end
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1813 && *p != '\n'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1814 && *p != '\r';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1815 p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1816 if (*p == '-' && *(p+1) == '*' && *(p+2) == '-')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1817 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1818 Extbyte *suffix = p;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1819 /* Look for "coding:" */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1820 for (p = local_vars_beg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1821 scan_end = suffix - LENGTH ("coding:?");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1822 p <= scan_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1823 p++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1824 if (memcmp ("coding:", p, LENGTH ("coding:")) == 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1825 && (p == local_vars_beg
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1826 || (*(p-1) == ' ' ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1827 *(p-1) == '\t' ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1828 *(p-1) == ';')))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1829 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1830 Extbyte save;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1831 int n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1832 p += LENGTH ("coding:");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1833 while (*p == ' ' || *p == '\t') p++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1834
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1835 /* Get coding system name */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1836 save = *suffix; *suffix = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1837 /* Characters valid in a MIME charset name (rfc 1521),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1838 and in a Lisp symbol name. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1839 n = strspn ( (char *) p,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1840 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1841 "abcdefghijklmnopqrstuvwxyz"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1842 "0123456789"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1843 "!$%&*+-.^_{|}~");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1844 *suffix = save;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1845 if (n > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1846 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1847 save = p[n]; p[n] = '\0';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1848 coding_system =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1849 Ffind_coding_system (intern ((char *) p));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1850 p[n] = save;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1851 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1852 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1853 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1854 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1855 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1856 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1857 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1858
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1859 if (NILP (coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1860 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1861 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1862 if (detect_coding_type (&decst, buf, nread,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1863 XCODING_SYSTEM_TYPE (*codesys_in_out)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1864 != CODESYS_AUTODETECT))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1865 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1866 nread = Lstream_read (stream, buf, sizeof (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1867 if (nread == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1868 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1869 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1870 while (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1872 else if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1873 && XCODING_SYSTEM_EOL_TYPE (coding_system) == EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1874 do
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1875 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1876 if (detect_coding_type (&decst, buf, nread, 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1877 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1878 nread = Lstream_read (stream, buf, sizeof (buf));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1879 if (!nread)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1880 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1881 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1882 while (1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1883
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1884 *eol_type_in_out = decst.eol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1885 if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1886 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1887 if (NILP (coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1888 *codesys_in_out = coding_system_from_mask (decst.mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1889 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1890 *codesys_in_out = coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1891 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1892 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1893
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1894 /* If we absolutely can't determine the EOL type, just assume LF. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1895 if (*eol_type_in_out == EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1896 *eol_type_in_out = EOL_LF;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1897
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1898 Lstream_rewind (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1899 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1900
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1901 DEFUN ("detect-coding-region", Fdetect_coding_region, 2, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1902 Detect coding system of the text in the region between START and END.
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1903 Return a list of possible coding systems ordered by priority.
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1904 If only ASCII characters are found, return 'undecided or one of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1905 its subsidiary coding systems according to a detected end-of-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1906 type. Optional arg BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1907 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1908 (start, end, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1909 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1910 Lisp_Object val = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1911 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1912 Bufpos b, e;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1913 Lisp_Object instream, lb_instream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1914 Lstream *istr, *lb_istr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1915 struct detection_state decst;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1916 struct gcpro gcpro1, gcpro2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1918 get_buffer_range_char (buf, start, end, &b, &e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1919 lb_instream = make_lisp_buffer_input_stream (buf, b, e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1920 lb_istr = XLSTREAM (lb_instream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1921 instream = make_encoding_input_stream (lb_istr, Fget_coding_system (Qbinary));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1922 istr = XLSTREAM (instream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1923 GCPRO2 (instream, lb_instream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1924 xzero (decst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1925 decst.eol_type = EOL_AUTODETECT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1926 decst.mask = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1927 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1928 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
1929 Extbyte random_buffer[4096];
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
1930 Lstream_data_count nread = Lstream_read (istr, random_buffer, sizeof (random_buffer));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1931
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1932 if (!nread)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1933 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1934 if (detect_coding_type (&decst, random_buffer, nread, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1935 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1936 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1938 if (decst.mask == ~0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1939 val = subsidiary_coding_system (Fget_coding_system (Qundecided),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1940 decst.eol_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1941 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1942 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1943 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1945 val = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1946 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1947 decst.mask = postprocess_iso2022_mask (decst.mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1948 #endif
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
1949 for (i = CODING_CATEGORY_LAST - 1; i >= 0; i--)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1950 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1951 int sys = fcd->coding_category_by_priority[i];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1952 if (decst.mask & (1 << sys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1953 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1954 Lisp_Object codesys = fcd->coding_category_system[sys];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1955 if (!NILP (codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1956 codesys = subsidiary_coding_system (codesys, decst.eol_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1957 val = Fcons (codesys, val);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1958 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1959 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1960 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1961 Lstream_close (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1962 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1963 Lstream_delete (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1964 Lstream_delete (lb_istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1965 return val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1966 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1968
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1969 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1970 /* Converting to internal Mule format ("decoding") */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1971 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1973 /* A decoding stream is a stream used for decoding text (i.e.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1974 converting from some external format to internal format).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1975 The decoding-stream object keeps track of the actual coding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1976 stream, the stream that is at the other end, and data that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1977 needs to be persistent across the lifetime of the stream. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1979 /* Handle the EOL stuff related to just-read-in character C.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1980 EOL_TYPE is the EOL type of the coding stream.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1981 FLAGS is the current value of FLAGS in the coding stream, and may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1982 be modified by this macro. (The macro only looks at the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1983 CODING_STATE_CR flag.) DST is the Dynarr to which the decoded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1984 bytes are to be written. You need to also define a local goto
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1985 label "label_continue_loop" that is at the end of the main
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1986 character-reading loop.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1988 If C is a CR character, then this macro handles it entirely and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1989 jumps to label_continue_loop. Otherwise, this macro does not add
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1990 anything to DST, and continues normally. You should continue
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1991 processing C normally after this macro. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1992
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1993 #define DECODE_HANDLE_EOL_TYPE(eol_type, c, flags, dst) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1994 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1995 if (c == '\r') \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1996 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1997 if (eol_type == EOL_CR) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1998 Dynarr_add (dst, '\n'); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1999 else if (eol_type != EOL_CRLF || flags & CODING_STATE_CR) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2000 Dynarr_add (dst, c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2001 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2002 flags |= CODING_STATE_CR; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2003 goto label_continue_loop; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2004 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2005 else if (flags & CODING_STATE_CR) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2006 { /* eol_type == CODING_SYSTEM_EOL_CRLF */ \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2007 if (c != '\n') \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2008 Dynarr_add (dst, '\r'); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2009 flags &= ~CODING_STATE_CR; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2010 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2011 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2012
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2013 /* C should be a binary character in the range 0 - 255; convert
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2014 to internal format and add to Dynarr DST. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2015
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2016 #define DECODE_ADD_BINARY_CHAR(c, dst) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2017 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2018 if (BYTE_ASCII_P (c)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2019 Dynarr_add (dst, c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2020 else if (BYTE_C1_P (c)) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2021 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2022 Dynarr_add (dst, LEADING_BYTE_CONTROL_1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2023 Dynarr_add (dst, c + 0x20); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2024 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2025 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2026 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2027 Dynarr_add (dst, LEADING_BYTE_LATIN_ISO8859_1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2028 Dynarr_add (dst, c); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2029 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2030 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2031
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2032 #define DECODE_OUTPUT_PARTIAL_CHAR(ch) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2033 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2034 if (ch) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2035 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2036 DECODE_ADD_BINARY_CHAR (ch, dst); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2037 ch = 0; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2039 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2040
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2041 #define DECODE_HANDLE_END_OF_CONVERSION(flags, ch, dst) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2042 do { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2043 if (flags & CODING_STATE_END) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2044 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2045 DECODE_OUTPUT_PARTIAL_CHAR (ch); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2046 if (flags & CODING_STATE_CR) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2047 Dynarr_add (dst, '\r'); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2048 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2049 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2051 #define DECODING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, decoding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2052
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2053 struct decoding_stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2054 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2055 /* Coding system that governs the conversion. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2056 Lisp_Coding_System *codesys;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2058 /* Stream that we read the encoded data from or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2059 write the decoded data to. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2060 Lstream *other_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2061
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2062 /* If we are reading, then we can return only a fixed amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2063 data, so if the conversion resulted in too much data, we store it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2064 here for retrieval the next time around. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2065 unsigned_char_dynarr *runoff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2066
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2067 /* FLAGS holds flags indicating the current state of the decoding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2068 Some of these flags are dependent on the coding system. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2069 unsigned int flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2070
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2071 /* CH holds a partially built-up character. Since we only deal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2072 with one- and two-byte characters at the moment, we only use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2073 this to store the first byte of a two-byte character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2074 unsigned int ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2075
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2076 /* EOL_TYPE specifies the type of end-of-line conversion that
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2077 currently applies. We need to keep this separate from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2078 EOL type stored in CODESYS because the latter might indicate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2079 automatic EOL-type detection while the former will always
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2080 indicate a particular EOL type. */
438
84b14dcb0985 Import from CVS: tag r21-2-27
cvs
parents: 432
diff changeset
2081 eol_type_t eol_type;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2082 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2083 /* Additional ISO2022 information. We define the structure above
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2084 because it's also needed by the detection routines. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2085 struct iso2022_decoder iso2022;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2087 /* Additional information (the state of the running CCL program)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2088 used by the CCL decoder. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2089 struct ccl_program ccl;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2090
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2091 /* counter for UTF-8 or UCS-4 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2092 unsigned char counter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2093 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2094 struct detection_state decst;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2095 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2096
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2097 static Lstream_data_count decoding_reader (Lstream *stream,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2098 unsigned char *data, Lstream_data_count size);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2099 static Lstream_data_count decoding_writer (Lstream *stream,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2100 const unsigned char *data, Lstream_data_count size);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2101 static int decoding_rewinder (Lstream *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2102 static int decoding_seekable_p (Lstream *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2103 static int decoding_flusher (Lstream *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2104 static int decoding_closer (Lstream *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2106 static Lisp_Object decoding_marker (Lisp_Object stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2108 DEFINE_LSTREAM_IMPLEMENTATION ("decoding", lstream_decoding,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2109 sizeof (struct decoding_stream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2110
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2111 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2112 decoding_marker (Lisp_Object stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2113 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2114 Lstream *str = DECODING_STREAM_DATA (XLSTREAM (stream))->other_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2115 Lisp_Object str_obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2116
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2117 /* We do not need to mark the coding systems or charsets stored
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2118 within the stream because they are stored in a global list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 and automatically marked. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2120
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2121 XSETLSTREAM (str_obj, str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2122 mark_object (str_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2123 if (str->imp->marker)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2124 return (str->imp->marker) (str_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2125 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2126 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2127 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2129 /* Read SIZE bytes of data and store it into DATA. We are a decoding stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2130 so we read data from the other end, decode it, and store it into DATA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2131
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2132 static Lstream_data_count
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2133 decoding_reader (Lstream *stream, unsigned char *data, Lstream_data_count size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2134 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2135 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2136 unsigned char *orig_data = data;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2137 Lstream_data_count read_size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2138 int error_occurred = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2140 /* We need to interface to mule_decode(), which expects to take some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2141 amount of data and store the result into a Dynarr. We have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2142 mule_decode() store into str->runoff, and take data from there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2143 as necessary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2144
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2145 /* We loop until we have enough data, reading chunks from the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2146 end and decoding it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2147 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2148 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2149 /* Take data from the runoff if we can. Make sure to take at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2150 most SIZE bytes, and delete the data from the runoff. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2151 if (Dynarr_length (str->runoff) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2152 {
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2153 Lstream_data_count chunk = min (size, (Lstream_data_count) Dynarr_length (str->runoff));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2154 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2155 Dynarr_delete_many (str->runoff, 0, chunk);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2156 data += chunk;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2157 size -= chunk;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2158 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2159
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2160 if (size == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2161 break; /* No more room for data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2163 if (str->flags & CODING_STATE_END)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2164 /* This means that on the previous iteration, we hit the EOF on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2165 the other end. We loop once more so that mule_decode() can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2166 output any final stuff it may be holding, or any "go back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2167 to a sane state" escape sequences. (This latter makes sense
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2168 during encoding.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2169 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2170
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2171 /* Exhausted the runoff, so get some more. DATA has at least
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2172 SIZE bytes left of storage in it, so it's OK to read directly
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2173 into it. (We'll be overwriting above, after we've decoded it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2174 into the runoff.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2175 read_size = Lstream_read (str->other_end, data, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2176 if (read_size < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2177 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2178 error_occurred = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2179 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2180 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2181 if (read_size == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2182 /* There might be some more end data produced in the translation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2183 See the comment above. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2184 str->flags |= CODING_STATE_END;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2185 mule_decode (stream, (Extbyte *) data, str->runoff, read_size);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2186 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2188 if (data - orig_data == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2189 return error_occurred ? -1 : 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2190 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2191 return data - orig_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2192 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2193
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2194 static Lstream_data_count
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2195 decoding_writer (Lstream *stream, const unsigned char *data, Lstream_data_count size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2196 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2197 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2198 Lstream_data_count retval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2199
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2200 /* Decode all our data into the runoff, and then attempt to write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2201 it all out to the other end. Remove whatever chunk we succeeded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2202 in writing. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2203 mule_decode (stream, (Extbyte *) data, str->runoff, size);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2204 retval = Lstream_write (str->other_end, Dynarr_atp (str->runoff, 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2205 Dynarr_length (str->runoff));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2206 if (retval > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2207 Dynarr_delete_many (str->runoff, 0, retval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2208 /* Do NOT return retval. The return value indicates how much
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2209 of the incoming data was written, not how many bytes were
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2210 written. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2211 return size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2212 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2213
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2214 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2215 reset_decoding_stream (struct decoding_stream *str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2216 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2217 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2218 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_ISO2022)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2219 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2220 Lisp_Object coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2221 XSETCODING_SYSTEM (coding_system, str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2222 reset_iso2022 (coding_system, &str->iso2022);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2223 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2224 else if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_CCL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2225 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2226 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_DECODE (str->codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2227 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2228 str->counter = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2229 #endif /* MULE */
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2230 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2231 || CODING_SYSTEM_EOL_TYPE (str->codesys) == EOL_AUTODETECT)
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2232 {
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2233 xzero (str->decst);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2234 str->decst.eol_type = EOL_AUTODETECT;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2235 str->decst.mask = ~0;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2236 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2237 str->flags = str->ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2238 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2239
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2240 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2241 decoding_rewinder (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2242 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2243 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2244 reset_decoding_stream (str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2245 Dynarr_reset (str->runoff);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2246 return Lstream_rewind (str->other_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2247 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2249 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2250 decoding_seekable_p (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2251 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2252 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2253 return Lstream_seekable_p (str->other_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2254 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2255
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2256 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 decoding_flusher (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2258 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2259 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2260 return Lstream_flush (str->other_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2261 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2262
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2263 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2264 decoding_closer (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2265 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2266 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2267 if (stream->flags & LSTREAM_FL_WRITE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2268 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2269 str->flags |= CODING_STATE_END;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2270 decoding_writer (stream, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2272 Dynarr_free (str->runoff);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2273 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2274 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2275 if (str->iso2022.composite_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2276 Dynarr_free (str->iso2022.composite_chars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2277 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2278 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2279 return Lstream_close (str->other_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2280 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2281
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2282 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2283 decoding_stream_coding_system (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2284 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2285 Lisp_Object coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2286 struct decoding_stream *str = DECODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2287
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2288 XSETCODING_SYSTEM (coding_system, str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2289 return subsidiary_coding_system (coding_system, str->eol_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2290 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2292 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2293 set_decoding_stream_coding_system (Lstream *lstr, Lisp_Object codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2294 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2295 Lisp_Coding_System *cs = XCODING_SYSTEM (codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2296 struct decoding_stream *str = DECODING_STREAM_DATA (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2297 str->codesys = cs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2298 if (CODING_SYSTEM_EOL_TYPE (cs) != EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2299 str->eol_type = CODING_SYSTEM_EOL_TYPE (cs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2300 reset_decoding_stream (str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2301 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2302
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2303 /* WARNING WARNING WARNING WARNING!!!!! If you open up a decoding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2304 stream for writing, no automatic code detection will be performed.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2305 The reason for this is that automatic code detection requires a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2306 seekable input. Things will also fail if you open a decoding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2307 stream for reading using a non-fully-specified coding system and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2308 a non-seekable input stream. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2309
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2310 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2311 make_decoding_stream_1 (Lstream *stream, Lisp_Object codesys,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2312 const char *mode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2313 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2314 Lstream *lstr = Lstream_new (lstream_decoding, mode);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2315 struct decoding_stream *str = DECODING_STREAM_DATA (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2316 Lisp_Object obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2317
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2318 xzero (*str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2319 str->other_end = stream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2320 str->runoff = (unsigned_char_dynarr *) Dynarr_new (unsigned_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 str->eol_type = EOL_AUTODETECT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2322 if (!strcmp (mode, "r")
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2323 && Lstream_seekable_p (stream))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2324 /* We can determine the coding system now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2325 determine_real_coding_system (stream, &codesys, &str->eol_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2326 set_decoding_stream_coding_system (lstr, codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2327 str->decst.eol_type = str->eol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2328 str->decst.mask = ~0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2329 XSETLSTREAM (obj, lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2330 return obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2331 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2333 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2334 make_decoding_input_stream (Lstream *stream, Lisp_Object codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2335 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2336 return make_decoding_stream_1 (stream, codesys, "r");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2338
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2339 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2340 make_decoding_output_stream (Lstream *stream, Lisp_Object codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2341 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2342 return make_decoding_stream_1 (stream, codesys, "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2343 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2344
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2345 /* Note: the decode_coding_* functions all take the same
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2346 arguments as mule_decode(), which is to say some SRC data of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2347 size N, which is to be stored into dynamic array DST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2348 DECODING is the stream within which the decoding is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2349 taking place, but no data is actually read from or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2350 written to that stream; that is handled in decoding_reader()
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2351 or decoding_writer(). This allows the same functions to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2352 be used for both reading and writing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2353
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2354 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2355 mule_decode (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2356 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2357 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2358 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2360 /* If necessary, do encoding-detection now. We do this when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2361 we're a writing stream or a non-seekable reading stream,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2362 meaning that we can't just process the whole input,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2363 rewind, and start over. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2365 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2366 str->eol_type == EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2367 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2368 Lisp_Object codesys;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2369
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2370 XSETCODING_SYSTEM (codesys, str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2371 detect_coding_type (&str->decst, src, n,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2372 CODING_SYSTEM_TYPE (str->codesys) !=
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2373 CODESYS_AUTODETECT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2374 if (CODING_SYSTEM_TYPE (str->codesys) == CODESYS_AUTODETECT &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2375 str->decst.mask != ~0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2376 /* #### This is cheesy. What we really ought to do is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2377 buffer up a certain amount of data so as to get a
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2378 less random result. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2379 codesys = coding_system_from_mask (str->decst.mask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2380 str->eol_type = str->decst.eol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2381 if (XCODING_SYSTEM (codesys) != str->codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2382 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2383 /* Preserve the CODING_STATE_END flag in case it was set.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2384 If we erase it, bad things might happen. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2385 int was_end = str->flags & CODING_STATE_END;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2386 set_decoding_stream_coding_system (decoding, codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2387 if (was_end)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2388 str->flags |= CODING_STATE_END;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2389 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2390 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2392 switch (CODING_SYSTEM_TYPE (str->codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2393 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2394 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2395 case CODESYS_INTERNAL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2396 Dynarr_add_many (dst, src, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2397 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2398 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2399 case CODESYS_AUTODETECT:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2400 /* If we got this far and still haven't decided on the coding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2401 system, then do no conversion. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2402 case CODESYS_NO_CONVERSION:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2403 decode_coding_no_conversion (decoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2404 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2405 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2406 case CODESYS_SHIFT_JIS:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2407 decode_coding_sjis (decoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2408 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2409 case CODESYS_BIG5:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2410 decode_coding_big5 (decoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2411 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2412 case CODESYS_UCS4:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2413 decode_coding_ucs4 (decoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2414 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2415 case CODESYS_UTF8:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2416 decode_coding_utf8 (decoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2417 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2418 case CODESYS_CCL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2419 str->ccl.last_block = str->flags & CODING_STATE_END;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2420 /* When applying ccl program to stream, MUST NOT set NULL
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2421 pointer to src. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2422 ccl_driver (&str->ccl, (src ? (unsigned char *)src : (unsigned char*)""),
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2423 dst, n, 0, CCL_MODE_DECODING);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2424 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2425 case CODESYS_ISO2022:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2426 decode_coding_iso2022 (decoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2427 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2428 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2429 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2430 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2431 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2432 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2434 DEFUN ("decode-coding-region", Fdecode_coding_region, 3, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2435 Decode the text between START and END which is encoded in CODING-SYSTEM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2436 This is useful if you've read in encoded text from a file without decoding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2437 it (e.g. you read in a JIS-formatted file but used the `binary' or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2438 `no-conversion' coding system, so that it shows up as "^[$B!<!+^[(B").
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2439 Return length of decoded text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2440 BUFFER defaults to the current buffer if unspecified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2441 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2442 (start, end, coding_system, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2443 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2444 Bufpos b, e;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2445 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2446 Lisp_Object instream, lb_outstream, de_outstream, outstream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2447 Lstream *istr, *ostr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2448 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2449
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2450 get_buffer_range_char (buf, start, end, &b, &e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2451
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2452 barf_if_buffer_read_only (buf, b, e);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2453
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2454 coding_system = Fget_coding_system (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2455 instream = make_lisp_buffer_input_stream (buf, b, e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2456 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2457 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2458 coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2459 outstream = make_encoding_output_stream (XLSTREAM (de_outstream),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2460 Fget_coding_system (Qbinary));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2461 istr = XLSTREAM (instream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2462 ostr = XLSTREAM (outstream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2463 GCPRO4 (instream, lb_outstream, de_outstream, outstream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2464
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465 /* The chain of streams looks like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2467 [BUFFER] <----- send through
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 ------> [ENCODE AS BINARY]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469 ------> [DECODE AS SPECIFIED]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2470 ------> [BUFFER]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2471 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2472
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2473 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2474 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2475 char tempbuf[1024]; /* some random amount */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2476 Bufpos newpos, even_newer_pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2477 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2478 Lstream_data_count size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2479
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2480 if (!size_in_bytes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2481 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2482 newpos = lisp_buffer_stream_startpos (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2483 Lstream_write (ostr, tempbuf, size_in_bytes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2484 even_newer_pos = lisp_buffer_stream_startpos (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2485 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2486 even_newer_pos, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2487 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2488 Lstream_close (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2489 Lstream_close (ostr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2490 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2491 Lstream_delete (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2492 Lstream_delete (ostr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2493 Lstream_delete (XLSTREAM (de_outstream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2494 Lstream_delete (XLSTREAM (lb_outstream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2495 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2496 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2498
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2499 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2500 /* Converting to an external encoding ("encoding") */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2501 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2502
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2503 /* An encoding stream is an output stream. When you create the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2504 stream, you specify the coding system that governs the encoding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2505 and another stream that the resulting encoded data is to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2506 sent to, and then start sending data to it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2508 #define ENCODING_STREAM_DATA(stream) LSTREAM_TYPE_DATA (stream, encoding)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2509
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2510 struct encoding_stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2511 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2512 /* Coding system that governs the conversion. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2513 Lisp_Coding_System *codesys;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2514
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2515 /* Stream that we read the encoded data from or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2516 write the decoded data to. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2517 Lstream *other_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2519 /* If we are reading, then we can return only a fixed amount of
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2520 data, so if the conversion resulted in too much data, we store it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2521 here for retrieval the next time around. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2522 unsigned_char_dynarr *runoff;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2523
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2524 /* FLAGS holds flags indicating the current state of the encoding.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2525 Some of these flags are dependent on the coding system. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2526 unsigned int flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2527
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2528 /* CH holds a partially built-up character. Since we only deal
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2529 with one- and two-byte characters at the moment, we only use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2530 this to store the first byte of a two-byte character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2531 unsigned int ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2532 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2533 /* Additional information used by the ISO2022 encoder. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2534 struct
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2535 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2536 /* CHARSET holds the character sets currently assigned to the G0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2537 through G3 registers. It is initialized from the array
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2538 INITIAL_CHARSET in CODESYS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2539 Lisp_Object charset[4];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2541 /* Which registers are currently invoked into the left (GL) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2542 right (GR) halves of the 8-bit encoding space? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2543 int register_left, register_right;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2544
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2545 /* Whether we need to explicitly designate the charset in the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2546 G? register before using it. It is initialized from the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2547 array FORCE_CHARSET_ON_OUTPUT in CODESYS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2548 unsigned char force_charset_on_output[4];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2549
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2550 /* Other state variables that need to be preserved across
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2551 invocations. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2552 Lisp_Object current_charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2553 int current_half;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2554 int current_char_boundary;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2555 } iso2022;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2556
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2557 /* Additional information (the state of the running CCL program)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2558 used by the CCL encoder. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2559 struct ccl_program ccl;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2560 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2561 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2562
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2563 static Lstream_data_count encoding_reader (Lstream *stream, unsigned char *data, Lstream_data_count size);
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2564 static Lstream_data_count encoding_writer (Lstream *stream, const unsigned char *data,
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2565 Lstream_data_count size);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2566 static int encoding_rewinder (Lstream *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2567 static int encoding_seekable_p (Lstream *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2568 static int encoding_flusher (Lstream *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2569 static int encoding_closer (Lstream *stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2571 static Lisp_Object encoding_marker (Lisp_Object stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2572
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2573 DEFINE_LSTREAM_IMPLEMENTATION ("encoding", lstream_encoding,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2574 sizeof (struct encoding_stream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2575
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2576 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2577 encoding_marker (Lisp_Object stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2578 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2579 Lstream *str = ENCODING_STREAM_DATA (XLSTREAM (stream))->other_end;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2580 Lisp_Object str_obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2581
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2582 /* We do not need to mark the coding systems or charsets stored
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2583 within the stream because they are stored in a global list
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2584 and automatically marked. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2586 XSETLSTREAM (str_obj, str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2587 mark_object (str_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2588 if (str->imp->marker)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2589 return (str->imp->marker) (str_obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2590 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2591 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2592 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2593
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2594 /* Read SIZE bytes of data and store it into DATA. We are a encoding stream
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2595 so we read data from the other end, encode it, and store it into DATA. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2596
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2597 static Lstream_data_count
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2598 encoding_reader (Lstream *stream, unsigned char *data, Lstream_data_count size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2599 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2600 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2601 unsigned char *orig_data = data;
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2602 Lstream_data_count read_size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2603 int error_occurred = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2604
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2605 /* We need to interface to mule_encode(), which expects to take some
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2606 amount of data and store the result into a Dynarr. We have
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2607 mule_encode() store into str->runoff, and take data from there
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2608 as necessary. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2610 /* We loop until we have enough data, reading chunks from the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2611 end and encoding it. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2612 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2613 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2614 /* Take data from the runoff if we can. Make sure to take at
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2615 most SIZE bytes, and delete the data from the runoff. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2616 if (Dynarr_length (str->runoff) > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2617 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2618 int chunk = min ((int) size, Dynarr_length (str->runoff));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2619 memcpy (data, Dynarr_atp (str->runoff, 0), chunk);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2620 Dynarr_delete_many (str->runoff, 0, chunk);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2621 data += chunk;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2622 size -= chunk;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2623 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2625 if (size == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2626 break; /* No more room for data */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2627
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2628 if (str->flags & CODING_STATE_END)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2629 /* This means that on the previous iteration, we hit the EOF on
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2630 the other end. We loop once more so that mule_encode() can
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2631 output any final stuff it may be holding, or any "go back
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2632 to a sane state" escape sequences. (This latter makes sense
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2633 during encoding.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2634 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2635
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2636 /* Exhausted the runoff, so get some more. DATA at least SIZE bytes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2637 left of storage in it, so it's OK to read directly into it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2638 (We'll be overwriting above, after we've encoded it into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2639 runoff.) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2640 read_size = Lstream_read (str->other_end, data, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2641 if (read_size < 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2642 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2643 error_occurred = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2644 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2645 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2646 if (read_size == 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2647 /* There might be some more end data produced in the translation.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2648 See the comment above. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2649 str->flags |= CODING_STATE_END;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2650 mule_encode (stream, data, str->runoff, read_size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2651 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2652
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2653 if (data == orig_data)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2654 return error_occurred ? -1 : 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2655 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2656 return data - orig_data;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2657 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2658
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2659 static Lstream_data_count
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2660 encoding_writer (Lstream *stream, const unsigned char *data, Lstream_data_count size)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2661 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2662 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2663 Lstream_data_count retval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2665 /* Encode all our data into the runoff, and then attempt to write
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2666 it all out to the other end. Remove whatever chunk we succeeded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2667 in writing. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2668 mule_encode (stream, data, str->runoff, size);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2669 retval = Lstream_write (str->other_end, Dynarr_atp (str->runoff, 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2670 Dynarr_length (str->runoff));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2671 if (retval > 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2672 Dynarr_delete_many (str->runoff, 0, retval);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2673 /* Do NOT return retval. The return value indicates how much
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2674 of the incoming data was written, not how many bytes were
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2675 written. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2676 return size;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2677 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2678
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2679 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2680 reset_encoding_stream (struct encoding_stream *str)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2681 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2682 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2683 switch (CODING_SYSTEM_TYPE (str->codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2684 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2685 case CODESYS_ISO2022:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2686 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2687 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2689 for (i = 0; i < 4; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2690 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2691 str->iso2022.charset[i] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2692 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (str->codesys, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2693 str->iso2022.force_charset_on_output[i] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2694 CODING_SYSTEM_ISO2022_FORCE_CHARSET_ON_OUTPUT (str->codesys, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2695 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2696 str->iso2022.register_left = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2697 str->iso2022.register_right = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2698 str->iso2022.current_charset = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2699 str->iso2022.current_half = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2700 str->iso2022.current_char_boundary = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2701 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2702 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2703 case CODESYS_CCL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2704 setup_ccl_program (&str->ccl, CODING_SYSTEM_CCL_ENCODE (str->codesys));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2705 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2706 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2707 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2708 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2709 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2710
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2711 str->flags = str->ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2712 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2713
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2714 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2715 encoding_rewinder (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2716 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2717 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2718 reset_encoding_stream (str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2719 Dynarr_reset (str->runoff);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2720 return Lstream_rewind (str->other_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2721 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2722
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2723 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2724 encoding_seekable_p (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2725 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2726 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2727 return Lstream_seekable_p (str->other_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2728 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2729
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2730 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2731 encoding_flusher (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2732 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2733 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2734 return Lstream_flush (str->other_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2735 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2736
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2737 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2738 encoding_closer (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2739 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2740 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2741 if (stream->flags & LSTREAM_FL_WRITE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2742 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2743 str->flags |= CODING_STATE_END;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2744 encoding_writer (stream, 0, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2745 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2746 Dynarr_free (str->runoff);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2747 return Lstream_close (str->other_end);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2748 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2749
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2750 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2751 encoding_stream_coding_system (Lstream *stream)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2752 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2753 Lisp_Object coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2754 struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2755
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2756 XSETCODING_SYSTEM (coding_system, str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2757 return coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2758 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2760 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2761 set_encoding_stream_coding_system (Lstream *lstr, Lisp_Object codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2762 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2763 Lisp_Coding_System *cs = XCODING_SYSTEM (codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2764 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2765 str->codesys = cs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2766 reset_encoding_stream (str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2767 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2769 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2770 make_encoding_stream_1 (Lstream *stream, Lisp_Object codesys,
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
2771 const char *mode)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2772 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2773 Lstream *lstr = Lstream_new (lstream_encoding, mode);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2774 struct encoding_stream *str = ENCODING_STREAM_DATA (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2775 Lisp_Object obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2776
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2777 xzero (*str);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2778 str->runoff = Dynarr_new (unsigned_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2779 str->other_end = stream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2780 set_encoding_stream_coding_system (lstr, codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2781 XSETLSTREAM (obj, lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2782 return obj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2783 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2785 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2786 make_encoding_input_stream (Lstream *stream, Lisp_Object codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2787 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2788 return make_encoding_stream_1 (stream, codesys, "r");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2789 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2791 Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2792 make_encoding_output_stream (Lstream *stream, Lisp_Object codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2793 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2794 return make_encoding_stream_1 (stream, codesys, "w");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2795 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2796
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2797 /* Convert N bytes of internally-formatted data stored in SRC to an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2798 external format, according to the encoding stream ENCODING.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2799 Store the encoded data into DST. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2801 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2802 mule_encode (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2803 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2804 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2805 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2807 switch (CODING_SYSTEM_TYPE (str->codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2808 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2809 #ifdef DEBUG_XEMACS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2810 case CODESYS_INTERNAL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2811 Dynarr_add_many (dst, src, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2812 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2813 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2814 case CODESYS_AUTODETECT:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2815 /* If we got this far and still haven't decided on the coding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2816 system, then do no conversion. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2817 case CODESYS_NO_CONVERSION:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2818 encode_coding_no_conversion (encoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2819 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2820 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2821 case CODESYS_SHIFT_JIS:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2822 encode_coding_sjis (encoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2823 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2824 case CODESYS_BIG5:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2825 encode_coding_big5 (encoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2826 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2827 case CODESYS_UCS4:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2828 encode_coding_ucs4 (encoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2829 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2830 case CODESYS_UTF8:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2831 encode_coding_utf8 (encoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2832 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2833 case CODESYS_CCL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2834 str->ccl.last_block = str->flags & CODING_STATE_END;
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2835 /* When applying ccl program to stream, MUST NOT set NULL
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2836 pointer to src. */
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2837 ccl_driver (&str->ccl, ((src) ? src : (unsigned char*)""),
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2838 dst, n, 0, CCL_MODE_ENCODING);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2839 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2840 case CODESYS_ISO2022:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2841 encode_coding_iso2022 (encoding, src, dst, n);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2842 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2843 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2844 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2845 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2846 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2847 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2848
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2849 DEFUN ("encode-coding-region", Fencode_coding_region, 3, 4, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2850 Encode the text between START and END using CODING-SYSTEM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2851 This will, for example, convert Japanese characters into stuff such as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2852 "^[$B!<!+^[(B" if you use the JIS encoding. Return length of encoded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2853 text. BUFFER defaults to the current buffer if unspecified.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2854 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2855 (start, end, coding_system, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2856 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2857 Bufpos b, e;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2858 struct buffer *buf = decode_buffer (buffer, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2859 Lisp_Object instream, lb_outstream, de_outstream, outstream;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2860 Lstream *istr, *ostr;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2861 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2862
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2863 get_buffer_range_char (buf, start, end, &b, &e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2864
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2865 barf_if_buffer_read_only (buf, b, e);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2867 coding_system = Fget_coding_system (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2868 instream = make_lisp_buffer_input_stream (buf, b, e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2869 lb_outstream = make_lisp_buffer_output_stream (buf, b, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2870 de_outstream = make_decoding_output_stream (XLSTREAM (lb_outstream),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2871 Fget_coding_system (Qbinary));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2872 outstream = make_encoding_output_stream (XLSTREAM (de_outstream),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2873 coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2874 istr = XLSTREAM (instream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2875 ostr = XLSTREAM (outstream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2876 GCPRO4 (instream, outstream, de_outstream, lb_outstream);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2877 /* The chain of streams looks like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2878
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2879 [BUFFER] <----- send through
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2880 ------> [ENCODE AS SPECIFIED]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2881 ------> [DECODE AS BINARY]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2882 ------> [BUFFER]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2883 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2884 while (1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2885 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2886 char tempbuf[1024]; /* some random amount */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2887 Bufpos newpos, even_newer_pos;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2888 Bufpos oldpos = lisp_buffer_stream_startpos (istr);
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2889 Lstream_data_count size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2890
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2891 if (!size_in_bytes)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2892 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2893 newpos = lisp_buffer_stream_startpos (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2894 Lstream_write (ostr, tempbuf, size_in_bytes);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2895 even_newer_pos = lisp_buffer_stream_startpos (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2896 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2897 even_newer_pos, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2898 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2899
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2900 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2901 Charcount retlen =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2902 lisp_buffer_stream_startpos (XLSTREAM (instream)) - b;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2903 Lstream_close (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2904 Lstream_close (ostr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2905 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2906 Lstream_delete (istr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2907 Lstream_delete (ostr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2908 Lstream_delete (XLSTREAM (de_outstream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2909 Lstream_delete (XLSTREAM (lb_outstream));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2910 return make_int (retlen);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2911 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2912 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2914 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2915
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2916 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2917 /* Shift-JIS methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2918 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2919
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2920 /* Shift-JIS is a coding system encoding three character sets: ASCII, right
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2921 half of JISX0201-Kana, and JISX0208. An ASCII character is encoded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2922 as is. A character of JISX0201-Kana (DIMENSION1_CHARS94 character set) is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2923 encoded by "position-code + 0x80". A character of JISX0208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2924 (DIMENSION2_CHARS94 character set) is encoded in 2-byte but two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2925 position-codes are divided and shifted so that it fit in the range
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2926 below.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2927
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2928 --- CODE RANGE of Shift-JIS ---
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2929 (character set) (range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2930 ASCII 0x00 .. 0x7F
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2931 JISX0201-Kana 0xA0 .. 0xDF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2932 JISX0208 (1st byte) 0x80 .. 0x9F and 0xE0 .. 0xEF
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2933 (2nd byte) 0x40 .. 0x7E and 0x80 .. 0xFC
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2934 -------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2936 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2937
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2938 /* Is this the first byte of a Shift-JIS two-byte char? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2939
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2940 #define BYTE_SJIS_TWO_BYTE_1_P(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2941 (((c) >= 0x81 && (c) <= 0x9F) || ((c) >= 0xE0 && (c) <= 0xEF))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2943 /* Is this the second byte of a Shift-JIS two-byte char? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2944
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2945 #define BYTE_SJIS_TWO_BYTE_2_P(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2946 (((c) >= 0x40 && (c) <= 0x7E) || ((c) >= 0x80 && (c) <= 0xFC))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2947
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2948 #define BYTE_SJIS_KATAKANA_P(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2949 ((c) >= 0xA1 && (c) <= 0xDF)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2950
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2951 static int
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2952 detect_coding_sjis (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2953 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2954 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2955 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2956 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2957 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2958 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2959 if (st->shift_jis.in_second_byte)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2960 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2961 st->shift_jis.in_second_byte = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2962 if (c < 0x40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2963 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2964 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2965 else if ((c >= 0x80 && c < 0xA0) || c >= 0xE0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2966 st->shift_jis.in_second_byte = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2967 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2968 return CODING_CATEGORY_SHIFT_JIS_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2969 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2970
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2971 /* Convert Shift-JIS data to internal format. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2972
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2973 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2974 decode_coding_sjis (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
2975 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2976 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2977 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2978 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2979 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2980 eol_type_t eol_type = str->eol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2981
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2982 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2983 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
2984 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2986 if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2987 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2988 /* Previous character was first byte of Shift-JIS Kanji char. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2989 if (BYTE_SJIS_TWO_BYTE_2_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2990 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2991 unsigned char e1, e2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2992
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2993 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2994 DECODE_SJIS (ch, c, e1, e2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2995 Dynarr_add (dst, e1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2996 Dynarr_add (dst, e2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2997 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2998 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2999 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3000 DECODE_ADD_BINARY_CHAR (ch, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3001 DECODE_ADD_BINARY_CHAR (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3002 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3003 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3004 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3005 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3006 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3007 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3008 if (BYTE_SJIS_TWO_BYTE_1_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3009 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3010 else if (BYTE_SJIS_KATAKANA_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3011 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3012 Dynarr_add (dst, LEADING_BYTE_KATAKANA_JISX0201);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3013 Dynarr_add (dst, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3014 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3015 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3016 DECODE_ADD_BINARY_CHAR (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3017 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3018 label_continue_loop:;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3019 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3020
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3021 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3022
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3023 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3024 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3025 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3026
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3027 /* Convert internally-formatted data to Shift-JIS. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3028
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3029 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3030 encode_coding_sjis (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3031 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3032 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3033 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3034 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3035 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3036 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3037
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3038 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3039 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3040 Bufbyte c = *src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3041 if (c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3042 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3043 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3044 Dynarr_add (dst, '\r');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3045 if (eol_type != EOL_CR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3046 Dynarr_add (dst, '\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3047 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3048 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3049 else if (BYTE_ASCII_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3050 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3051 Dynarr_add (dst, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3052 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3053 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3054 else if (BUFBYTE_LEADING_BYTE_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3055 ch = (c == LEADING_BYTE_KATAKANA_JISX0201 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3056 c == LEADING_BYTE_JAPANESE_JISX0208_1978 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3057 c == LEADING_BYTE_JAPANESE_JISX0208) ? c : 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3058 else if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3059 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3060 if (ch == LEADING_BYTE_KATAKANA_JISX0201)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3061 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3062 Dynarr_add (dst, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3063 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3064 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3065 else if (ch == LEADING_BYTE_JAPANESE_JISX0208_1978 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3066 ch == LEADING_BYTE_JAPANESE_JISX0208)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3067 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3068 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3069 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3070 unsigned char j1, j2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3071 ENCODE_SJIS (ch, c, j1, j2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3072 Dynarr_add (dst, j1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3073 Dynarr_add (dst, j2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3074 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3075 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3076 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3077 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3078
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3079 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3080 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3081 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3082
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3083 DEFUN ("decode-shift-jis-char", Fdecode_shift_jis_char, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3084 Decode a JISX0208 character of Shift-JIS coding-system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3085 CODE is the character code in Shift-JIS as a cons of type bytes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3086 Return the corresponding character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3087 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3088 (code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3089 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3090 unsigned char c1, c2, s1, s2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3091
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3092 CHECK_CONS (code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3093 CHECK_INT (XCAR (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3094 CHECK_INT (XCDR (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3095 s1 = XINT (XCAR (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3096 s2 = XINT (XCDR (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3097 if (BYTE_SJIS_TWO_BYTE_1_P (s1) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3098 BYTE_SJIS_TWO_BYTE_2_P (s2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3099 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3100 DECODE_SJIS (s1, s2, c1, c2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3101 return make_char (MAKE_CHAR (Vcharset_japanese_jisx0208,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3102 c1 & 0x7F, c2 & 0x7F));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3103 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3104 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3105 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3106 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3107
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3108 DEFUN ("encode-shift-jis-char", Fencode_shift_jis_char, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3109 Encode a JISX0208 character CHARACTER to SHIFT-JIS coding-system.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3110 Return the corresponding character code in SHIFT-JIS as a cons of two bytes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3111 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3112 (character))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3113 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3114 Lisp_Object charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3115 int c1, c2, s1, s2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3116
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3117 CHECK_CHAR_COERCE_INT (character);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3118 BREAKUP_CHAR (XCHAR (character), charset, c1, c2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3119 if (EQ (charset, Vcharset_japanese_jisx0208))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3120 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3121 ENCODE_SJIS (c1 | 0x80, c2 | 0x80, s1, s2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3122 return Fcons (make_int (s1), make_int (s2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3123 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3124 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3125 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3126 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3128
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3129 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3130 /* Big5 methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3131 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3133 /* BIG5 is a coding system encoding two character sets: ASCII and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3134 Big5. An ASCII character is encoded as is. Big5 is a two-byte
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3135 character set and is encoded in two-byte.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3136
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3137 --- CODE RANGE of BIG5 ---
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3138 (character set) (range)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3139 ASCII 0x00 .. 0x7F
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3140 Big5 (1st byte) 0xA1 .. 0xFE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3141 (2nd byte) 0x40 .. 0x7E and 0xA1 .. 0xFE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3142 --------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3143
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3144 Since the number of characters in Big5 is larger than maximum
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3145 characters in Emacs' charset (96x96), it can't be handled as one
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3146 charset. So, in Emacs, Big5 is divided into two: `charset-big5-1'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3147 and `charset-big5-2'. Both <type>s are DIMENSION2_CHARS94. The former
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3148 contains frequently used characters and the latter contains less
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3149 frequently used characters. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3150
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3151 #define BYTE_BIG5_TWO_BYTE_1_P(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3152 ((c) >= 0xA1 && (c) <= 0xFE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3153
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3154 /* Is this the second byte of a Shift-JIS two-byte char? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3155
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3156 #define BYTE_BIG5_TWO_BYTE_2_P(c) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3157 (((c) >= 0x40 && (c) <= 0x7E) || ((c) >= 0xA1 && (c) <= 0xFE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3158
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3159 /* Number of Big5 characters which have the same code in 1st byte. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3160
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3161 #define BIG5_SAME_ROW (0xFF - 0xA1 + 0x7F - 0x40)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3162
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3163 /* Code conversion macros. These are macros because they are used in
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3164 inner loops during code conversion.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3165
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3166 Note that temporary variables in macros introduce the classic
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3167 dynamic-scoping problems with variable names. We use capital-
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3168 lettered variables in the assumption that XEmacs does not use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3169 capital letters in variables except in a very formalized way
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3170 (e.g. Qstring). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3172 /* Convert Big5 code (b1, b2) into its internal string representation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3173 (lb, c1, c2). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3174
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3175 /* There is a much simpler way to split the Big5 charset into two.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3176 For the moment I'm going to leave the algorithm as-is because it
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3177 claims to separate out the most-used characters into a single
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3178 charset, which perhaps will lead to optimizations in various
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3179 places.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3180
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3181 The way the algorithm works is something like this:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3183 Big5 can be viewed as a 94x157 charset, where the row is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3184 encoded into the bytes 0xA1 .. 0xFE and the column is encoded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3185 into the bytes 0x40 .. 0x7E and 0xA1 .. 0xFE. As for frequency,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3186 the split between low and high column numbers is apparently
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3187 meaningless; ascending rows produce less and less frequent chars.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3188 Therefore, we assign the lower half of rows (0xA1 .. 0xC8) to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3189 the first charset, and the upper half (0xC9 .. 0xFE) to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3190 second. To do the conversion, we convert the character into
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3191 a single number where 0 .. 156 is the first row, 157 .. 313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3192 is the second, etc. That way, the characters are ordered by
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3193 decreasing frequency. Then we just chop the space in two
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3194 and coerce the result into a 94x94 space.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3195 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3196
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3197 #define DECODE_BIG5(b1, b2, lb, c1, c2) do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3198 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3199 int B1 = b1, B2 = b2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3200 unsigned int I \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3201 = (B1 - 0xA1) * BIG5_SAME_ROW + B2 - (B2 < 0x7F ? 0x40 : 0x62); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3202 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3203 if (B1 < 0xC9) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3204 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3205 lb = LEADING_BYTE_CHINESE_BIG5_1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3206 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3207 else \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3208 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3209 lb = LEADING_BYTE_CHINESE_BIG5_2; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3210 I -= (BIG5_SAME_ROW) * (0xC9 - 0xA1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3211 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3212 c1 = I / (0xFF - 0xA1) + 0xA1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3213 c2 = I % (0xFF - 0xA1) + 0xA1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3214 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3216 /* Convert the internal string representation of a Big5 character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3217 (lb, c1, c2) into Big5 code (b1, b2). */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3218
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3219 #define ENCODE_BIG5(lb, c1, c2, b1, b2) do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3220 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3221 unsigned int I = ((c1) - 0xA1) * (0xFF - 0xA1) + ((c2) - 0xA1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3222 \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3223 if (lb == LEADING_BYTE_CHINESE_BIG5_2) \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3224 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3225 I += BIG5_SAME_ROW * (0xC9 - 0xA1); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3226 } \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3227 b1 = I / BIG5_SAME_ROW + 0xA1; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3228 b2 = I % BIG5_SAME_ROW; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3229 b2 += b2 < 0x3F ? 0x40 : 0x62; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3230 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3232 static int
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3233 detect_coding_big5 (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3234 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3235 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3236 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3237 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3238 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3239 (c >= 0x80 && c <= 0xA0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3240 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3241 if (st->big5.in_second_byte)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3242 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3243 st->big5.in_second_byte = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3244 if (c < 0x40 || (c >= 0x80 && c <= 0xA0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3245 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3246 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3247 else if (c >= 0xA1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3248 st->big5.in_second_byte = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3249 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3250 return CODING_CATEGORY_BIG5_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3251 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3252
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3253 /* Convert Big5 data to internal format. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3254
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3255 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3256 decode_coding_big5 (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3257 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3258 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3259 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3260 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3261 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3262 eol_type_t eol_type = str->eol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3263
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3264 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3265 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3266 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3267 if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3268 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3269 /* Previous character was first byte of Big5 char. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3270 if (BYTE_BIG5_TWO_BYTE_2_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3271 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3272 unsigned char b1, b2, b3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3273 DECODE_BIG5 (ch, c, b1, b2, b3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3274 Dynarr_add (dst, b1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3275 Dynarr_add (dst, b2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3276 Dynarr_add (dst, b3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3277 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3278 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3279 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3280 DECODE_ADD_BINARY_CHAR (ch, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3281 DECODE_ADD_BINARY_CHAR (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3282 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3283 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3284 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3285 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3287 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3288 if (BYTE_BIG5_TWO_BYTE_1_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3289 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3290 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3291 DECODE_ADD_BINARY_CHAR (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3292 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3293 label_continue_loop:;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3294 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3295
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3296 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3297
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3298 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3299 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3300 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3301
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3302 /* Convert internally-formatted data to Big5. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3303
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3304 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3305 encode_coding_big5 (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3306 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3307 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3308 unsigned char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3309 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3310 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3311 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3312 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3313
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3314 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3315 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3316 c = *src++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3317 if (c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3318 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3319 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3320 Dynarr_add (dst, '\r');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3321 if (eol_type != EOL_CR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3322 Dynarr_add (dst, '\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3323 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3324 else if (BYTE_ASCII_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3325 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3326 /* ASCII. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3327 Dynarr_add (dst, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3328 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3329 else if (BUFBYTE_LEADING_BYTE_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3330 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3331 if (c == LEADING_BYTE_CHINESE_BIG5_1 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3332 c == LEADING_BYTE_CHINESE_BIG5_2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3333 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3334 /* A recognized leading byte. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3335 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3336 continue; /* not done with this character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3337 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3338 /* otherwise just ignore this character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3339 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3340 else if (ch == LEADING_BYTE_CHINESE_BIG5_1 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3341 ch == LEADING_BYTE_CHINESE_BIG5_2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3342 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3343 /* Previous char was a recognized leading byte. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3344 ch = (ch << 8) | c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3345 continue; /* not done with this character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3346 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3347 else if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3348 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3349 /* Encountering second byte of a Big5 character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3350 unsigned char b1, b2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3351
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3352 ENCODE_BIG5 (ch >> 8, ch & 0xFF, c, b1, b2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3353 Dynarr_add (dst, b1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3354 Dynarr_add (dst, b2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3355 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3357 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3358 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3359
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3360 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3361 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3362 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3363
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3364
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3365 DEFUN ("decode-big5-char", Fdecode_big5_char, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3366 Decode a Big5 character CODE of BIG5 coding-system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3367 CODE is the character code in BIG5, a cons of two integers.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3368 Return the corresponding character.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3369 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3370 (code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3371 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3372 unsigned char c1, c2, b1, b2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3373
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3374 CHECK_CONS (code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3375 CHECK_INT (XCAR (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3376 CHECK_INT (XCDR (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3377 b1 = XINT (XCAR (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3378 b2 = XINT (XCDR (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3379 if (BYTE_BIG5_TWO_BYTE_1_P (b1) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3380 BYTE_BIG5_TWO_BYTE_2_P (b2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3381 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3382 int leading_byte;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3383 Lisp_Object charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3384 DECODE_BIG5 (b1, b2, leading_byte, c1, c2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3385 charset = CHARSET_BY_LEADING_BYTE (leading_byte);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3386 return make_char (MAKE_CHAR (charset, c1 & 0x7F, c2 & 0x7F));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3387 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3388 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3389 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3390 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3392 DEFUN ("encode-big5-char", Fencode_big5_char, 1, 1, 0, /*
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3393 Encode the Big5 character CHARACTER in the BIG5 coding-system.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3394 Return the corresponding character code in Big5.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3395 */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3396 (character))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3397 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3398 Lisp_Object charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3399 int c1, c2, b1, b2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3400
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3401 CHECK_CHAR_COERCE_INT (character);
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3402 BREAKUP_CHAR (XCHAR (character), charset, c1, c2);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3403 if (EQ (charset, Vcharset_chinese_big5_1) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3404 EQ (charset, Vcharset_chinese_big5_2))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3405 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3406 ENCODE_BIG5 (XCHARSET_LEADING_BYTE (charset), c1 | 0x80, c2 | 0x80,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3407 b1, b2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3408 return Fcons (make_int (b1), make_int (b2));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3409 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3410 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3411 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3412 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3413
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3415 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3416 /* UCS-4 methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3417 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3418 /* UCS-4 character codes are implemented as nonnegative integers. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3419 /* */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3420 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3421
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3422
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3423 DEFUN ("set-ucs-char", Fset_ucs_char, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3424 Map UCS-4 code CODE to Mule character CHARACTER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3426 Return T on success, NIL on failure.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3427 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3428 (code, character))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3429 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3430 size_t c;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 CHECK_CHAR (character);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3433 CHECK_NATNUM (code);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3434 c = XINT (code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3435
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3436 if (c < countof (fcd->ucs_to_mule_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3438 fcd->ucs_to_mule_table[c] = character;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3439 return Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3440 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3441 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3442 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3443 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3445 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3446 ucs_to_char (unsigned long code)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3447 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3448 if (code < countof (fcd->ucs_to_mule_table))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3449 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3450 return fcd->ucs_to_mule_table[code];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3451 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 else if ((0xe00000 <= code) && (code <= 0xe00000 + 94 * 94 * 14))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3454 unsigned int c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 code -= 0xe00000;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3457 c = code % (94 * 94);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3458 return make_char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3459 (MAKE_CHAR (CHARSET_BY_ATTRIBUTES
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3460 (CHARSET_TYPE_94X94, code / (94 * 94) + '@',
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3461 CHARSET_LEFT_TO_RIGHT),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3462 c / 94 + 33, c % 94 + 33));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3463 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3464 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3465 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3466 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3467
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3468 DEFUN ("ucs-char", Fucs_char, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3469 Return Mule character corresponding to UCS code CODE (a positive integer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3470 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3471 (code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3472 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3473 CHECK_NATNUM (code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3474 return ucs_to_char (XINT (code));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3475 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3476
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3477 DEFUN ("set-char-ucs", Fset_char_ucs, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3478 Map Mule character CHARACTER to UCS code CODE (a positive integer).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3479 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3480 (character, code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3481 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3482 /* #### Isn't this gilding the lily? Fput_char_table checks its args.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3483 Fset_char_ucs is more restrictive on index arg, but should
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3484 check code arg in a char_table method. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3485 CHECK_CHAR (character);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3486 CHECK_NATNUM (code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3487 return Fput_char_table (character, code, mule_to_ucs_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3488 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3489
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3490 DEFUN ("char-ucs", Fchar_ucs, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3491 Return the UCS code (a positive integer) corresponding to CHARACTER.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3492 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3493 (character))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3494 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3495 return Fget_char_table (character, mule_to_ucs_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3496 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3497
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3498 /* Decode a UCS-4 character into a buffer. If the lookup fails, use
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3499 <GETA MARK> (U+3013) of JIS X 0208, which means correct character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3500 is not found, instead.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3501 #### do something more appropriate (use blob?)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3502 Danger, Will Robinson! Data loss. Should we signal user? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3503 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3504 decode_ucs4 (unsigned long ch, unsigned_char_dynarr *dst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3505 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3506 Lisp_Object chr = ucs_to_char (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3507
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3508 if (! NILP (chr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 Bufbyte work[MAX_EMCHAR_LEN];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 int len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3512
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3513 ch = XCHAR (chr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 len = (ch < 128) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 simple_set_charptr_emchar (work, ch) :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 non_ascii_set_charptr_emchar (work, ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 Dynarr_add_many (dst, work, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 Dynarr_add (dst, 34 + 128);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523 Dynarr_add (dst, 46 + 128);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 static unsigned long
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 mule_char_to_ucs4 (Lisp_Object charset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529 unsigned char h, unsigned char l)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3530 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3531 Lisp_Object code
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3532 = Fget_char_table (make_char (MAKE_CHAR (charset, h & 127, l & 127)),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3533 mule_to_ucs_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3535 if (INTP (code))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3536 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3537 return XINT (code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3538 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539 else if ( (XCHARSET_DIMENSION (charset) == 2) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540 (XCHARSET_CHARS (charset) == 94) )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3541 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3542 unsigned char final = XCHARSET_FINAL (charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3544 if ( ('@' <= final) && (final < 0x7f) )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3545 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3546 return 0xe00000 + (final - '@') * 94 * 94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3547 + ((h & 127) - 33) * 94 + (l & 127) - 33;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3548 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3549 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3550 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 return '?';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3552 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3553 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3554 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3556 return '?';
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3557 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3558 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3559
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3561 encode_ucs4 (Lisp_Object charset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3562 unsigned char h, unsigned char l, unsigned_char_dynarr *dst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3563 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3564 unsigned long code = mule_char_to_ucs4 (charset, h, l);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3565 Dynarr_add (dst, code >> 24);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3566 Dynarr_add (dst, (code >> 16) & 255);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3567 Dynarr_add (dst, (code >> 8) & 255);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 Dynarr_add (dst, code & 255);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3570
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3571 static int
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3572 detect_coding_ucs4 (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3573 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3576 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3577 switch (st->ucs4.in_byte)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3578 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580 if (c >= 128)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3582 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3583 st->ucs4.in_byte++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3585 case 3:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3586 st->ucs4.in_byte = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3587 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3588 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3589 st->ucs4.in_byte++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3590 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3591 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3592 return CODING_CATEGORY_UCS4_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3593 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3594
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3595 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3596 decode_coding_ucs4 (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3597 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3598 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3599 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3600 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3601 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3602 unsigned char counter = str->counter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3603
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3604 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3605 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3606 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 switch (counter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3608 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3610 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 counter = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 case 1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 decode_ucs4 ( ( ch << 8 ) | c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 counter = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3619 ch = ( ch << 8 ) | c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3620 counter--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3621 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3622 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3623 if (counter & CODING_STATE_END)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3624 DECODE_OUTPUT_PARTIAL_CHAR (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3625
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3626 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3627 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3628 str->counter = counter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3629 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3630
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3631 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3632 encode_coding_ucs4 (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3633 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3634 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3635 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3636 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3637 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3638 unsigned char char_boundary = str->iso2022.current_char_boundary;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3639 Lisp_Object charset = str->iso2022.current_charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3640
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3641 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3642 /* flags for handling composite chars. We do a little switcharoo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3643 on the source while we're outputting the composite char. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3644 unsigned int saved_n = 0;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3645 const unsigned char *saved_src = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3646 int in_composite = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3648 back_to_square_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3649 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3650
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3651 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3653 unsigned char c = *src++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3654
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3655 if (BYTE_ASCII_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3656 { /* Processing ASCII character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3657 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3658 encode_ucs4 (Vcharset_ascii, c, 0, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3659 char_boundary = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3660 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3661 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662 { /* Processing Leading Byte */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3664 charset = CHARSET_BY_LEADING_BYTE (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 if (LEADING_BYTE_PREFIX_P(c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3666 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3667 char_boundary = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3668 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3669 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3670 { /* Processing Non-ASCII character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3671 char_boundary = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3672 if (EQ (charset, Vcharset_control_1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3673 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3674 encode_ucs4 (Vcharset_control_1, c, 0, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3675 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3676 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3677 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3678 switch (XCHARSET_REP_BYTES (charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3679 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3680 case 2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3681 encode_ucs4 (charset, c, 0, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3682 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3683 case 3:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3684 if (XCHARSET_PRIVATE_P (charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3685 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3686 encode_ucs4 (charset, c, 0, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 else if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3692 if (EQ (charset, Vcharset_composite))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694 if (in_composite)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3695 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3696 /* #### Bother! We don't know how to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697 handle this yet. */
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3698 Dynarr_add (dst, '\0');
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3699 Dynarr_add (dst, '\0');
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3700 Dynarr_add (dst, '\0');
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3701 Dynarr_add (dst, '~');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3702 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3703 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3704 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3705 Emchar emch = MAKE_CHAR (Vcharset_composite,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 ch & 0x7F, c & 0x7F);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3707 Lisp_Object lstr = composite_char_string (emch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3708 saved_n = n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3709 saved_src = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3710 in_composite = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3711 src = XSTRING_DATA (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3712 n = XSTRING_LENGTH (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3713 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3715 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3716 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3717 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3718 encode_ucs4(charset, ch, c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3719 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3720 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3721 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3722 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3723 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3724 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3725 char_boundary = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3726 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3727 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3728 case 4:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3729 if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3730 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3731 encode_ucs4 (charset, ch, c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3732 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3733 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3734 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3735 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3737 char_boundary = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3738 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3741 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3742 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3743 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3744 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3745 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3746
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3747 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3748 if (in_composite)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3749 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3750 n = saved_n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3751 src = saved_src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3752 in_composite = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3753 goto back_to_square_n; /* Wheeeeeeeee ..... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3754 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3755 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3756
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3757 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3758 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3759 str->iso2022.current_char_boundary = char_boundary;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3760 str->iso2022.current_charset = charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3761
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3762 /* Verbum caro factum est! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3763 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3764
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3765
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3766 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3767 /* UTF-8 methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3768 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3769
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3770 static int
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3771 detect_coding_utf8 (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3772 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3773 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3774 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3775 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3776 switch (st->utf8.in_byte)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3777 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3778 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3779 if (c == ISO_CODE_ESC || c == ISO_CODE_SI || c == ISO_CODE_SO)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3780 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3781 else if (c >= 0xfc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3782 st->utf8.in_byte = 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3783 else if (c >= 0xf8)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3784 st->utf8.in_byte = 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3785 else if (c >= 0xf0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3786 st->utf8.in_byte = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787 else if (c >= 0xe0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3788 st->utf8.in_byte = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3789 else if (c >= 0xc0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 st->utf8.in_byte = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791 else if (c >= 0x80)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3794 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 if ((c & 0xc0) != 0x80)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3797 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3798 st->utf8.in_byte--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3799 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3800 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3801 return CODING_CATEGORY_UTF8_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3802 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3803
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3804 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3805 decode_coding_utf8 (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3806 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3807 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3808 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3809 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3810 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3811 eol_type_t eol_type = str->eol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3812 unsigned char counter = str->counter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3813
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3814 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3815 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3816 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3817 switch (counter)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3818 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3819 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3820 if ( c >= 0xfc )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3821 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3822 ch = c & 0x01;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3823 counter = 5;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3824 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3825 else if ( c >= 0xf8 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3826 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3827 ch = c & 0x03;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3828 counter = 4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3829 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3830 else if ( c >= 0xf0 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3831 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3832 ch = c & 0x07;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3833 counter = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3834 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3835 else if ( c >= 0xe0 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3836 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3837 ch = c & 0x0f;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3838 counter = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3839 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3840 else if ( c >= 0xc0 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3841 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3842 ch = c & 0x1f;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3843 counter = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3844 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3845 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3846 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3847 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3848 decode_ucs4 (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3849 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3850 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3851 case 1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3852 ch = ( ch << 6 ) | ( c & 0x3f );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3853 decode_ucs4 (ch, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3854 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3855 counter = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3856 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3857 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3858 ch = ( ch << 6 ) | ( c & 0x3f );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3859 counter--;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3860 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3861 label_continue_loop:;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3862 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3863
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3864 if (flags & CODING_STATE_END)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3865 DECODE_OUTPUT_PARTIAL_CHAR (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3866
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3867 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3868 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3869 str->counter = counter;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3870 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3871
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3872 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3873 encode_utf8 (Lisp_Object charset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3874 unsigned char h, unsigned char l, unsigned_char_dynarr *dst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3875 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3876 unsigned long code = mule_char_to_ucs4 (charset, h, l);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3877 if ( code <= 0x7f )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3878 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3879 Dynarr_add (dst, code);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3880 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3881 else if ( code <= 0x7ff )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3882 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3883 Dynarr_add (dst, (code >> 6) | 0xc0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3884 Dynarr_add (dst, (code & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3885 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3886 else if ( code <= 0xffff )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3887 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3888 Dynarr_add (dst, (code >> 12) | 0xe0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3889 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3890 Dynarr_add (dst, (code & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3891 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3892 else if ( code <= 0x1fffff )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3893 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3894 Dynarr_add (dst, (code >> 18) | 0xf0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3895 Dynarr_add (dst, ((code >> 12) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3896 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3897 Dynarr_add (dst, (code & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3898 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3899 else if ( code <= 0x3ffffff )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3900 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3901 Dynarr_add (dst, (code >> 24) | 0xf8);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3902 Dynarr_add (dst, ((code >> 18) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3903 Dynarr_add (dst, ((code >> 12) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3904 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3905 Dynarr_add (dst, (code & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3906 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3907 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3908 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3909 Dynarr_add (dst, (code >> 30) | 0xfc);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3910 Dynarr_add (dst, ((code >> 24) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3911 Dynarr_add (dst, ((code >> 18) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3912 Dynarr_add (dst, ((code >> 12) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3913 Dynarr_add (dst, ((code >> 6) & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3914 Dynarr_add (dst, (code & 0x3f) | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3915 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3916 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3917
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3918 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
3919 encode_coding_utf8 (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
3920 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3921 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3922 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3923 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3924 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3925 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3926 unsigned char char_boundary = str->iso2022.current_char_boundary;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3927 Lisp_Object charset = str->iso2022.current_charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3928
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3929 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3930 /* flags for handling composite chars. We do a little switcharoo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3931 on the source while we're outputting the composite char. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3932 unsigned int saved_n = 0;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
3933 const unsigned char *saved_src = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3934 int in_composite = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3935
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3936 back_to_square_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3937 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3938
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3939 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3940 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3941 unsigned char c = *src++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3942
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3943 if (BYTE_ASCII_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3944 { /* Processing ASCII character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3945 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3946 if (c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3947 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3948 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3949 Dynarr_add (dst, '\r');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3950 if (eol_type != EOL_CR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3951 Dynarr_add (dst, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3952 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3953 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3954 encode_utf8 (Vcharset_ascii, c, 0, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3955 char_boundary = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3956 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3957 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3958 { /* Processing Leading Byte */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3959 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3960 charset = CHARSET_BY_LEADING_BYTE (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3961 if (LEADING_BYTE_PREFIX_P(c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3962 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3963 char_boundary = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3964 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3965 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3966 { /* Processing Non-ASCII character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3967 char_boundary = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3968 if (EQ (charset, Vcharset_control_1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3969 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3970 encode_utf8 (Vcharset_control_1, c, 0, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3971 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3972 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3973 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3974 switch (XCHARSET_REP_BYTES (charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3975 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3976 case 2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3977 encode_utf8 (charset, c, 0, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3978 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3979 case 3:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3980 if (XCHARSET_PRIVATE_P (charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3981 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3982 encode_utf8 (charset, c, 0, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3983 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3984 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3985 else if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3986 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3987 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3988 if (EQ (charset, Vcharset_composite))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3989 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3990 if (in_composite)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3991 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3992 /* #### Bother! We don't know how to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3993 handle this yet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3994 encode_utf8 (Vcharset_ascii, '~', 0, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3995 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3996 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3997 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3998 Emchar emch = MAKE_CHAR (Vcharset_composite,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3999 ch & 0x7F, c & 0x7F);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4000 Lisp_Object lstr = composite_char_string (emch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4001 saved_n = n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4002 saved_src = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4003 in_composite = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4004 src = XSTRING_DATA (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4005 n = XSTRING_LENGTH (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4006 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4007 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4008 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4009 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4010 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4011 encode_utf8 (charset, ch, c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4012 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4013 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4014 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4015 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4016 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4017 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4018 char_boundary = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4019 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4020 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4021 case 4:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4022 if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4023 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4024 encode_utf8 (charset, ch, c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4025 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4026 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4027 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4028 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4029 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4030 char_boundary = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4031 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4032 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4033 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4034 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4035 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4036 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4037 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4038 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4039
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4040 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4041 if (in_composite)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4042 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4043 n = saved_n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4044 src = saved_src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4045 in_composite = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4046 goto back_to_square_n; /* Wheeeeeeeee ..... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4047 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4048 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4049
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4050 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4051 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4052 str->iso2022.current_char_boundary = char_boundary;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4053 str->iso2022.current_charset = charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4054
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4055 /* Verbum caro factum est! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4056 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4057
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4058
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4059 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4060 /* ISO2022 methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4061 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4062
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4063 /* The following note describes the coding system ISO2022 briefly.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4064 Since the intention of this note is to help understand the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4065 functions in this file, some parts are NOT ACCURATE or OVERLY
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4066 SIMPLIFIED. For thorough understanding, please refer to the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4067 original document of ISO2022.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4068
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4069 ISO2022 provides many mechanisms to encode several character sets
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4070 in 7-bit and 8-bit environments. For 7-bit environments, all text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4071 is encoded using bytes less than 128. This may make the encoded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4072 text a little bit longer, but the text passes more easily through
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4073 several gateways, some of which strip off MSB (Most Signigant Bit).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4074
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4075 There are two kinds of character sets: control character set and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4076 graphic character set. The former contains control characters such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4077 as `newline' and `escape' to provide control functions (control
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4078 functions are also provided by escape sequences). The latter
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4079 contains graphic characters such as 'A' and '-'. Emacs recognizes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4080 two control character sets and many graphic character sets.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4081
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4082 Graphic character sets are classified into one of the following
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4083 four classes, according to the number of bytes (DIMENSION) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4084 number of characters in one dimension (CHARS) of the set:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4085 - DIMENSION1_CHARS94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4086 - DIMENSION1_CHARS96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4087 - DIMENSION2_CHARS94
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4088 - DIMENSION2_CHARS96
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4089
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4090 In addition, each character set is assigned an identification tag,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4091 unique for each set, called "final character" (denoted as <F>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4092 hereafter). The <F> of each character set is decided by ECMA(*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4093 when it is registered in ISO. The code range of <F> is 0x30..0x7F
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4094 (0x30..0x3F are for private use only).
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4095
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4096 Note (*): ECMA = European Computer Manufacturers Association
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4097
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4098 Here are examples of graphic character set [NAME(<F>)]:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4099 o DIMENSION1_CHARS94 -- ASCII('B'), right-half-of-JISX0201('I'), ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4100 o DIMENSION1_CHARS96 -- right-half-of-ISO8859-1('A'), ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4101 o DIMENSION2_CHARS94 -- GB2312('A'), JISX0208('B'), ...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4102 o DIMENSION2_CHARS96 -- none for the moment
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4104 A code area (1 byte = 8 bits) is divided into 4 areas, C0, GL, C1, and GR.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4105 C0 [0x00..0x1F] -- control character plane 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4106 GL [0x20..0x7F] -- graphic character plane 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4107 C1 [0x80..0x9F] -- control character plane 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4108 GR [0xA0..0xFF] -- graphic character plane 1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4109
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4110 A control character set is directly designated and invoked to C0 or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4111 C1 by an escape sequence. The most common case is that:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4112 - ISO646's control character set is designated/invoked to C0, and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4113 - ISO6429's control character set is designated/invoked to C1,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4114 and usually these designations/invocations are omitted in encoded
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4115 text. In a 7-bit environment, only C0 can be used, and a control
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4116 character for C1 is encoded by an appropriate escape sequence to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4117 fit into the environment. All control characters for C1 are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4118 defined to have corresponding escape sequences.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4119
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4120 A graphic character set is at first designated to one of four
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4121 graphic registers (G0 through G3), then these graphic registers are
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4122 invoked to GL or GR. These designations and invocations can be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4123 done independently. The most common case is that G0 is invoked to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4124 GL, G1 is invoked to GR, and ASCII is designated to G0. Usually
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4125 these invocations and designations are omitted in encoded text.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4126 In a 7-bit environment, only GL can be used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4128 When a graphic character set of CHARS94 is invoked to GL, codes
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4129 0x20 and 0x7F of the GL area work as control characters SPACE and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4130 DEL respectively, and codes 0xA0 and 0xFF of the GR area should not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4131 be used.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4132
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4133 There are two ways of invocation: locking-shift and single-shift.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4134 With locking-shift, the invocation lasts until the next different
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4135 invocation, whereas with single-shift, the invocation affects the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4136 following character only and doesn't affect the locking-shift
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4137 state. Invocations are done by the following control characters or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4138 escape sequences:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4139
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4140 ----------------------------------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4141 abbrev function cntrl escape seq description
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4142 ----------------------------------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4143 SI/LS0 (shift-in) 0x0F none invoke G0 into GL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4144 SO/LS1 (shift-out) 0x0E none invoke G1 into GL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4145 LS2 (locking-shift-2) none ESC 'n' invoke G2 into GL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4146 LS3 (locking-shift-3) none ESC 'o' invoke G3 into GL
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4147 LS1R (locking-shift-1 right) none ESC '~' invoke G1 into GR (*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4148 LS2R (locking-shift-2 right) none ESC '}' invoke G2 into GR (*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4149 LS3R (locking-shift 3 right) none ESC '|' invoke G3 into GR (*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4150 SS2 (single-shift-2) 0x8E ESC 'N' invoke G2 for one char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4151 SS3 (single-shift-3) 0x8F ESC 'O' invoke G3 for one char
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4152 ----------------------------------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4153 (*) These are not used by any known coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4154
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4155 Control characters for these functions are defined by macros
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4156 ISO_CODE_XXX in `coding.h'.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4157
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4158 Designations are done by the following escape sequences:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4159 ----------------------------------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4160 escape sequence description
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4161 ----------------------------------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4162 ESC '(' <F> designate DIMENSION1_CHARS94<F> to G0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4163 ESC ')' <F> designate DIMENSION1_CHARS94<F> to G1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4164 ESC '*' <F> designate DIMENSION1_CHARS94<F> to G2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4165 ESC '+' <F> designate DIMENSION1_CHARS94<F> to G3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4166 ESC ',' <F> designate DIMENSION1_CHARS96<F> to G0 (*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4167 ESC '-' <F> designate DIMENSION1_CHARS96<F> to G1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4168 ESC '.' <F> designate DIMENSION1_CHARS96<F> to G2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4169 ESC '/' <F> designate DIMENSION1_CHARS96<F> to G3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4170 ESC '$' '(' <F> designate DIMENSION2_CHARS94<F> to G0 (**)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4171 ESC '$' ')' <F> designate DIMENSION2_CHARS94<F> to G1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4172 ESC '$' '*' <F> designate DIMENSION2_CHARS94<F> to G2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4173 ESC '$' '+' <F> designate DIMENSION2_CHARS94<F> to G3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4174 ESC '$' ',' <F> designate DIMENSION2_CHARS96<F> to G0 (*)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4175 ESC '$' '-' <F> designate DIMENSION2_CHARS96<F> to G1
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4176 ESC '$' '.' <F> designate DIMENSION2_CHARS96<F> to G2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4177 ESC '$' '/' <F> designate DIMENSION2_CHARS96<F> to G3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4178 ----------------------------------------------------------------------
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4179
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4180 In this list, "DIMENSION1_CHARS94<F>" means a graphic character set
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4181 of dimension 1, chars 94, and final character <F>, etc...
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4182
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4183 Note (*): Although these designations are not allowed in ISO2022,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4184 Emacs accepts them on decoding, and produces them on encoding
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4185 CHARS96 character sets in a coding system which is characterized as
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4186 7-bit environment, non-locking-shift, and non-single-shift.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4187
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4188 Note (**): If <F> is '@', 'A', or 'B', the intermediate character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4189 '(' can be omitted. We refer to this as "short-form" hereafter.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4190
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4191 Now you may notice that there are a lot of ways for encoding the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4192 same multilingual text in ISO2022. Actually, there exist many
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4193 coding systems such as Compound Text (used in X11's inter client
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4194 communication, ISO-2022-JP (used in Japanese internet), ISO-2022-KR
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4195 (used in Korean internet), EUC (Extended UNIX Code, used in Asian
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4196 localized platforms), and all of these are variants of ISO2022.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4197
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4198 In addition to the above, Emacs handles two more kinds of escape
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4199 sequences: ISO6429's direction specification and Emacs' private
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4200 sequence for specifying character composition.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4201
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4202 ISO6429's direction specification takes the following form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4203 o CSI ']' -- end of the current direction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4204 o CSI '0' ']' -- end of the current direction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4205 o CSI '1' ']' -- start of left-to-right text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4206 o CSI '2' ']' -- start of right-to-left text
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4207 The control character CSI (0x9B: control sequence introducer) is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4208 abbreviated to the escape sequence ESC '[' in a 7-bit environment.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4209
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4210 Character composition specification takes the following form:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4211 o ESC '0' -- start character composition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4212 o ESC '1' -- end character composition
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4213 Since these are not standard escape sequences of any ISO standard,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4214 their use with these meanings is restricted to Emacs only. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4215
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4216 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4217 reset_iso2022 (Lisp_Object coding_system, struct iso2022_decoder *iso)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4218 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4219 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4221 for (i = 0; i < 4; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4222 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4223 if (!NILP (coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4224 iso->charset[i] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4225 XCODING_SYSTEM_ISO2022_INITIAL_CHARSET (coding_system, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4226 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4227 iso->charset[i] = Qt;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4228 iso->invalid_designated[i] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4229 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4230 iso->esc = ISO_ESC_NOTHING;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4231 iso->esc_bytes_index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4232 iso->register_left = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4233 iso->register_right = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4234 iso->switched_dir_and_no_valid_charset_yet = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4235 iso->invalid_switch_dir = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4236 iso->output_direction_sequence = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4237 iso->output_literally = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4238 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4239 if (iso->composite_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4240 Dynarr_reset (iso->composite_chars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4241 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4242 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4243
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4244 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4245 fit_to_be_escape_quoted (unsigned char c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4246 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4247 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4248 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4249 case ISO_CODE_ESC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4250 case ISO_CODE_CSI:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4251 case ISO_CODE_SS2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4252 case ISO_CODE_SS3:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4253 case ISO_CODE_SO:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4254 case ISO_CODE_SI:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4255 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4256
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4257 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4258 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4259 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4260 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4261
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4262 /* Parse one byte of an ISO2022 escape sequence.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4263 If the result is an invalid escape sequence, return 0 and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4264 do not change anything in STR. Otherwise, if the result is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4265 an incomplete escape sequence, update ISO2022.ESC and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4266 ISO2022.ESC_BYTES and return -1. Otherwise, update
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4267 all the state variables (but not ISO2022.ESC_BYTES) and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4268 return 1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4269
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4270 If CHECK_INVALID_CHARSETS is non-zero, check for designation
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4271 or invocation of an invalid character set and treat that as
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4272 an unrecognized escape sequence.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4273
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4274 ********************************************************************
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4275
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4276 #### Strategies for error annotation and coding orthogonalization
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4277
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4278 We really want to separate out a number of things. Conceptually,
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4279 there is a nested syntax.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4280
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4281 At the top level is the ISO 2022 extension syntax, including charset
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4282 designation and invocation, and certain auxiliary controls such as the
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4283 ISO 6429 direction specification. These are octet-oriented, with the
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4284 single exception (AFAIK) of the "exit Unicode" sequence which uses the
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4285 UTF's natural width (1 byte for UTF-7 and UTF-8, 2 bytes for UCS-2 and
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4286 UTF-16, and 4 bytes for UCS-4 and UTF-32). This will be treated as a
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4287 (deprecated) special case in Unicode processing.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4288
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4289 The middle layer is ISO 2022 character interpretation. This will depend
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4290 on the current state of the ISO 2022 registers, and assembles octets
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4291 into the character's internal representation.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4292
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4293 The lowest level is translating system control conventions. At present
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4294 this is restricted to newline translation, but one could imagine doing
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4295 tab conversion or line wrapping here. "Escape from Unicode" processing
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4296 would be done at this level.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4297
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4298 At each level the parser will verify the syntax. In the case of a
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4299 syntax error or warning (such as a redundant escape sequence that affects
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4300 no characters), the parser will take some action, typically inserting the
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4301 erroneous octets directly into the output and creating an annotation
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4302 which can be used by higher level I/O to mark the affected region.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4303
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4304 This should make it possible to do something sensible about separating
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4305 newline convention processing from character construction, and about
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4306 preventing ISO 2022 escape sequences from being recognized
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4307 inappropriately.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4308
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4309 The basic strategy will be to have octet classification tables, and
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4310 switch processing according to the table entry.
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4311
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4312 It's possible that, by doing the processing with tables of functions or
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
4313 the like, the parser can be used for both detection and translation. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4314
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4315 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4316 parse_iso2022_esc (Lisp_Object codesys, struct iso2022_decoder *iso,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4317 unsigned char c, unsigned int *flags,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4318 int check_invalid_charsets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4319 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4320 /* (1) If we're at the end of a designation sequence, CS is the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4321 charset being designated and REG is the register to designate
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4322 it to.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4324 (2) If we're at the end of a locking-shift sequence, REG is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4325 the register to invoke and HALF (0 == left, 1 == right) is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4326 the half to invoke it into.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4327
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4328 (3) If we're at the end of a single-shift sequence, REG is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4329 the register to invoke. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4330 Lisp_Object cs = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4331 int reg, half;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4332
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4333 /* NOTE: This code does goto's all over the fucking place.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4334 The reason for this is that we're basically implementing
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4335 a state machine here, and hierarchical languages like C
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4336 don't really provide a clean way of doing this. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4337
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4338 if (! (*flags & CODING_STATE_ESCAPE))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4339 /* At beginning of escape sequence; we need to reset our
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4340 escape-state variables. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4341 iso->esc = ISO_ESC_NOTHING;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4342
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4343 iso->output_literally = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4344 iso->output_direction_sequence = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4345
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4346 switch (iso->esc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4347 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4348 case ISO_ESC_NOTHING:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4349 iso->esc_bytes_index = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4350 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4351 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4352 case ISO_CODE_ESC: /* Start escape sequence */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4353 *flags |= CODING_STATE_ESCAPE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4354 iso->esc = ISO_ESC;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4355 goto not_done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4356
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4357 case ISO_CODE_CSI: /* ISO6429 (specifying directionality) */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4358 *flags |= CODING_STATE_ESCAPE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4359 iso->esc = ISO_ESC_5_11;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4360 goto not_done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4361
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4362 case ISO_CODE_SO: /* locking shift 1 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4363 reg = 1; half = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4364 goto locking_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4365 case ISO_CODE_SI: /* locking shift 0 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4366 reg = 0; half = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4367 goto locking_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4368
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4369 case ISO_CODE_SS2: /* single shift */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4370 reg = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4371 goto single_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4372 case ISO_CODE_SS3: /* single shift */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4373 reg = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4374 goto single_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4375
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4376 default: /* Other control characters */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4377 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4378 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4379
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4380 case ISO_ESC:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4381 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4382 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4383 /**** single shift ****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4384
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4385 case 'N': /* single shift 2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4386 reg = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4387 goto single_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4388 case 'O': /* single shift 3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4389 reg = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4390 goto single_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4391
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4392 /**** locking shift ****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4393
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4394 case '~': /* locking shift 1 right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4395 reg = 1; half = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4396 goto locking_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4397 case 'n': /* locking shift 2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4398 reg = 2; half = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4399 goto locking_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4400 case '}': /* locking shift 2 right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4401 reg = 2; half = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4402 goto locking_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4403 case 'o': /* locking shift 3 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4404 reg = 3; half = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4405 goto locking_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4406 case '|': /* locking shift 3 right */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4407 reg = 3; half = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4408 goto locking_shift;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4409
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4410 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4411 /**** composite ****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4412
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4413 case '0':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4414 iso->esc = ISO_ESC_START_COMPOSITE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4415 *flags = (*flags & CODING_STATE_ISO2022_LOCK) |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4416 CODING_STATE_COMPOSITE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4417 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4418
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4419 case '1':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4420 iso->esc = ISO_ESC_END_COMPOSITE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4421 *flags = (*flags & CODING_STATE_ISO2022_LOCK) &
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4422 ~CODING_STATE_COMPOSITE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4423 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4424 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4425
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4426 /**** directionality ****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4427
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4428 case '[':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4429 iso->esc = ISO_ESC_5_11;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4430 goto not_done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4431
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4432 /**** designation ****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4433
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4434 case '$': /* multibyte charset prefix */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4435 iso->esc = ISO_ESC_2_4;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4436 goto not_done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4437
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4438 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4439 if (0x28 <= c && c <= 0x2F)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4440 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4441 iso->esc = (enum iso_esc_flag) (c - 0x28 + ISO_ESC_2_8);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4442 goto not_done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4443 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4444
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4445 /* This function is called with CODESYS equal to nil when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4446 doing coding-system detection. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4447 if (!NILP (codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4448 && XCODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4449 && fit_to_be_escape_quoted (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4450 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4451 iso->esc = ISO_ESC_LITERAL;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4452 *flags &= CODING_STATE_ISO2022_LOCK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4453 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4454 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4455
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4456 /* bzzzt! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4457 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4458 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4459
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4460
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4462 /**** directionality ****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4463
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4464 case ISO_ESC_5_11: /* ISO6429 direction control */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4465 if (c == ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4466 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4467 *flags &= (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4468 goto directionality;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4469 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4470 if (c == '0') iso->esc = ISO_ESC_5_11_0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4471 else if (c == '1') iso->esc = ISO_ESC_5_11_1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4472 else if (c == '2') iso->esc = ISO_ESC_5_11_2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4473 else return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4474 goto not_done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4475
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4476 case ISO_ESC_5_11_0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4477 if (c == ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4478 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4479 *flags &= (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4480 goto directionality;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4481 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4482 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4483
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4484 case ISO_ESC_5_11_1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4485 if (c == ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4486 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4487 *flags = (CODING_STATE_ISO2022_LOCK & ~CODING_STATE_R2L);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4488 goto directionality;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4489 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4490 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4492 case ISO_ESC_5_11_2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4493 if (c == ']')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4494 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4495 *flags = (*flags & CODING_STATE_ISO2022_LOCK) | CODING_STATE_R2L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4496 goto directionality;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4497 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4498 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4500 directionality:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4501 iso->esc = ISO_ESC_DIRECTIONALITY;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4502 /* Various junk here to attempt to preserve the direction sequences
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4503 literally in the text if they would otherwise be swallowed due
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4504 to invalid designations that don't show up as actual charset
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4505 changes in the text. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4506 if (iso->invalid_switch_dir)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4507 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4508 /* We already inserted a direction switch literally into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4509 text. We assume (#### this may not be right) that the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4510 next direction switch is the one going the other way,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4511 and we need to output that literally as well. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4512 iso->output_literally = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4513 iso->invalid_switch_dir = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4514 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4515 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4516 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4517 int jj;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4518
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4519 /* If we are in the thrall of an invalid designation,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4520 then stick the directionality sequence literally into the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4521 output stream so it ends up in the original text again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4522 for (jj = 0; jj < 4; jj++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4523 if (iso->invalid_designated[jj])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4524 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4525 if (jj < 4)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4526 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4527 iso->output_literally = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4528 iso->invalid_switch_dir = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4529 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4530 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4531 /* Indicate that we haven't yet seen a valid designation,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4532 so that if a switch-dir is directly followed by an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4533 invalid designation, both get inserted literally. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4534 iso->switched_dir_and_no_valid_charset_yet = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4535 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4536 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4537
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4538
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4539 /**** designation ****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4540
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4541 case ISO_ESC_2_4:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4542 if (0x28 <= c && c <= 0x2F)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4543 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4544 iso->esc = (enum iso_esc_flag) (c - 0x28 + ISO_ESC_2_4_8);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4545 goto not_done;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4546 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4547 if (0x40 <= c && c <= 0x42)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4548 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4549 cs = CHARSET_BY_ATTRIBUTES (CHARSET_TYPE_94X94, c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4550 *flags & CODING_STATE_R2L ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4551 CHARSET_RIGHT_TO_LEFT :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4552 CHARSET_LEFT_TO_RIGHT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4553 reg = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4554 goto designated;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4555 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4556 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4557
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4558 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4559 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4560 int type =-1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4561
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4562 if (c < '0' || c > '~')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4563 return 0; /* bad final byte */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4564
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4565 if (iso->esc >= ISO_ESC_2_8 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4566 iso->esc <= ISO_ESC_2_15)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4567 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4568 type = ((iso->esc >= ISO_ESC_2_12) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4569 CHARSET_TYPE_96 : CHARSET_TYPE_94);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4570 reg = (iso->esc - ISO_ESC_2_8) & 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4571 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4572 else if (iso->esc >= ISO_ESC_2_4_8 &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4573 iso->esc <= ISO_ESC_2_4_15)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4574 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4575 type = ((iso->esc >= ISO_ESC_2_4_12) ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4576 CHARSET_TYPE_96X96 : CHARSET_TYPE_94X94);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4577 reg = (iso->esc - ISO_ESC_2_4_8) & 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4578 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4579 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4580 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4581 /* Can this ever be reached? -slb */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4582 abort();
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4583 return 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4584 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4585
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4586 cs = CHARSET_BY_ATTRIBUTES (type, c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4587 *flags & CODING_STATE_R2L ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4588 CHARSET_RIGHT_TO_LEFT :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4589 CHARSET_LEFT_TO_RIGHT);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4590 goto designated;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4591 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4592 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4593
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4594 not_done:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4595 iso->esc_bytes[iso->esc_bytes_index++] = (unsigned char) c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4596 return -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4597
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4598 single_shift:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4599 if (check_invalid_charsets && !CHARSETP (iso->charset[reg]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4600 /* can't invoke something that ain't there. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4601 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4602 iso->esc = ISO_ESC_SINGLE_SHIFT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4603 *flags &= CODING_STATE_ISO2022_LOCK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4604 if (reg == 2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4605 *flags |= CODING_STATE_SS2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4606 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4607 *flags |= CODING_STATE_SS3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4608 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4609
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4610 locking_shift:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4611 if (check_invalid_charsets &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4612 !CHARSETP (iso->charset[reg]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4613 /* can't invoke something that ain't there. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4614 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4615 if (half)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4616 iso->register_right = reg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4617 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4618 iso->register_left = reg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4619 *flags &= CODING_STATE_ISO2022_LOCK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4620 iso->esc = ISO_ESC_LOCKING_SHIFT;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4621 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4622
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4623 designated:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4624 if (NILP (cs) && check_invalid_charsets)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4625 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4626 iso->invalid_designated[reg] = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4627 iso->charset[reg] = Vcharset_ascii;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4628 iso->esc = ISO_ESC_DESIGNATE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4629 *flags &= CODING_STATE_ISO2022_LOCK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4630 iso->output_literally = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4631 if (iso->switched_dir_and_no_valid_charset_yet)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4632 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4633 /* We encountered a switch-direction followed by an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4634 invalid designation. Ensure that the switch-direction
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4635 gets outputted; otherwise it will probably get eaten
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4636 when the text is written out again. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4637 iso->switched_dir_and_no_valid_charset_yet = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4638 iso->output_direction_sequence = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4639 /* And make sure that the switch-dir going the other
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4640 way gets outputted, as well. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4641 iso->invalid_switch_dir = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4642 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4643 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4644 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4645 /* This function is called with CODESYS equal to nil when
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4646 doing coding-system detection. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4647 if (!NILP (codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4648 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4649 charset_conversion_spec_dynarr *dyn =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4650 XCODING_SYSTEM (codesys)->iso2022.input_conv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4651
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4652 if (dyn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4653 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4654 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4655
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4656 for (i = 0; i < Dynarr_length (dyn); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4657 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4658 struct charset_conversion_spec *spec = Dynarr_atp (dyn, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4659 if (EQ (cs, spec->from_charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4660 cs = spec->to_charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4661 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4662 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4663 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4665 iso->charset[reg] = cs;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4666 iso->esc = ISO_ESC_DESIGNATE;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4667 *flags &= CODING_STATE_ISO2022_LOCK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4668 if (iso->invalid_designated[reg])
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4669 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4670 iso->invalid_designated[reg] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4671 iso->output_literally = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4672 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4673 if (iso->switched_dir_and_no_valid_charset_yet)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4674 iso->switched_dir_and_no_valid_charset_yet = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4675 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4676 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4677
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4678 static int
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
4679 detect_coding_iso2022 (struct detection_state *st, const Extbyte *src, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4680 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4681 int mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4682
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4683 /* #### There are serious deficiencies in the recognition mechanism
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4684 here. This needs to be much smarter if it's going to cut it.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4685 The sequence "\xff\x0f" is currently detected as LOCK_SHIFT while
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4686 it should be detected as Latin-1.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4687 All the ISO2022 stuff in this file should be synced up with the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4688 code from FSF Emacs-20.4, in which Mule should be more or less stable.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4689 Perhaps we should wait till R2L works in FSF Emacs? */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4690
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4691 if (!st->iso2022.initted)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4692 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4693 reset_iso2022 (Qnil, &st->iso2022.iso);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4694 st->iso2022.mask = (CODING_CATEGORY_ISO_7_MASK |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4695 CODING_CATEGORY_ISO_8_DESIGNATE_MASK |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4696 CODING_CATEGORY_ISO_8_1_MASK |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4697 CODING_CATEGORY_ISO_8_2_MASK |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4698 CODING_CATEGORY_ISO_LOCK_SHIFT_MASK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4699 st->iso2022.flags = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4700 st->iso2022.high_byte_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4701 st->iso2022.saw_single_shift = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4702 st->iso2022.initted = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4703 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4704
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4705 mask = st->iso2022.mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4706
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4707 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4708 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4709 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4710 if (c >= 0xA0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4711 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4712 mask &= ~CODING_CATEGORY_ISO_7_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4713 st->iso2022.high_byte_count++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4714 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4715 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4716 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4717 if (st->iso2022.high_byte_count && !st->iso2022.saw_single_shift)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4718 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4719 if (st->iso2022.high_byte_count & 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4720 /* odd number of high bytes; assume not iso-8-2 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4721 mask &= ~CODING_CATEGORY_ISO_8_2_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4722 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4723 st->iso2022.high_byte_count = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4724 st->iso2022.saw_single_shift = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4725 if (c > 0x80)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4726 mask &= ~CODING_CATEGORY_ISO_7_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4727 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4728 if (!(st->iso2022.flags & CODING_STATE_ESCAPE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4729 && (BYTE_C0_P (c) || BYTE_C1_P (c)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4730 { /* control chars */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4731 switch (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4732 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4733 /* Allow and ignore control characters that you might
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4734 reasonably see in a text file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4735 case '\r':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4736 case '\n':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4737 case '\t':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4738 case 7: /* bell */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4739 case 8: /* backspace */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4740 case 11: /* vertical tab */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4741 case 12: /* form feed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4742 case 26: /* MS-DOS C-z junk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4743 case 31: /* '^_' -- for info */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4744 goto label_continue_loop;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4745
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4746 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4747 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4748 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4749 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4750
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4751 if ((st->iso2022.flags & CODING_STATE_ESCAPE) || BYTE_C0_P (c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4752 || BYTE_C1_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4753 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4754 if (parse_iso2022_esc (Qnil, &st->iso2022.iso, c,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4755 &st->iso2022.flags, 0))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4756 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4757 switch (st->iso2022.iso.esc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4758 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4759 case ISO_ESC_DESIGNATE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4760 mask &= ~CODING_CATEGORY_ISO_8_1_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4761 mask &= ~CODING_CATEGORY_ISO_8_2_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4762 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4763 case ISO_ESC_LOCKING_SHIFT:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4764 mask = CODING_CATEGORY_ISO_LOCK_SHIFT_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4765 goto ran_out_of_chars;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4766 case ISO_ESC_SINGLE_SHIFT:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4767 mask &= ~CODING_CATEGORY_ISO_8_DESIGNATE_MASK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4768 st->iso2022.saw_single_shift = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4769 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4770 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4771 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4772 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4773 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4774 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4775 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4776 mask = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4777 goto ran_out_of_chars;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4778 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4779 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4780 label_continue_loop:;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4781 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4782
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4783 ran_out_of_chars:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4784
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4785 return mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4786 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4787
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4788 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4789 postprocess_iso2022_mask (int mask)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4790 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4791 /* #### kind of cheesy */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4792 /* If seven-bit ISO is allowed, then assume that the encoding is
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4793 entirely seven-bit and turn off the eight-bit ones. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4794 if (mask & CODING_CATEGORY_ISO_7_MASK)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4795 mask &= ~ (CODING_CATEGORY_ISO_8_DESIGNATE_MASK |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4796 CODING_CATEGORY_ISO_8_1_MASK |
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4797 CODING_CATEGORY_ISO_8_2_MASK);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4798 return mask;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4799 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4800
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4801 /* If FLAGS is a null pointer or specifies right-to-left motion,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4802 output a switch-dir-to-left-to-right sequence to DST.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4803 Also update FLAGS if it is not a null pointer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4804 If INTERNAL_P is set, we are outputting in internal format and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4805 need to handle the CSI differently. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4806
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4807 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4808 restore_left_to_right_direction (Lisp_Coding_System *codesys,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4809 unsigned_char_dynarr *dst,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4810 unsigned int *flags,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4811 int internal_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4812 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4813 if (!flags || (*flags & CODING_STATE_R2L))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4814 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4815 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4816 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4817 Dynarr_add (dst, ISO_CODE_ESC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4818 Dynarr_add (dst, '[');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4819 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4820 else if (internal_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4821 DECODE_ADD_BINARY_CHAR (ISO_CODE_CSI, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4822 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4823 Dynarr_add (dst, ISO_CODE_CSI);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4824 Dynarr_add (dst, '0');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4825 Dynarr_add (dst, ']');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4826 if (flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4827 *flags &= ~CODING_STATE_R2L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4828 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4829 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4830
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4831 /* If FLAGS is a null pointer or specifies a direction different from
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4832 DIRECTION (which should be either CHARSET_RIGHT_TO_LEFT or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4833 CHARSET_LEFT_TO_RIGHT), output the appropriate switch-dir escape
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4834 sequence to DST. Also update FLAGS if it is not a null pointer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4835 If INTERNAL_P is set, we are outputting in internal format and
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4836 need to handle the CSI differently. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4837
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4838 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4839 ensure_correct_direction (int direction, Lisp_Coding_System *codesys,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4840 unsigned_char_dynarr *dst, unsigned int *flags,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4841 int internal_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4842 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4843 if ((!flags || (*flags & CODING_STATE_R2L)) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4844 direction == CHARSET_LEFT_TO_RIGHT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4845 restore_left_to_right_direction (codesys, dst, flags, internal_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4846 else if (!CODING_SYSTEM_ISO2022_NO_ISO6429 (codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4847 && (!flags || !(*flags & CODING_STATE_R2L)) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4848 direction == CHARSET_RIGHT_TO_LEFT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4849 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4850 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4851 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4852 Dynarr_add (dst, ISO_CODE_ESC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4853 Dynarr_add (dst, '[');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4854 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4855 else if (internal_p)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4856 DECODE_ADD_BINARY_CHAR (ISO_CODE_CSI, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4857 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4858 Dynarr_add (dst, ISO_CODE_CSI);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4859 Dynarr_add (dst, '2');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4860 Dynarr_add (dst, ']');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4861 if (flags)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4862 *flags |= CODING_STATE_R2L;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4863 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4864 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4865
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4866 /* Convert ISO2022-format data to internal format. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4867
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4868 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4869 decode_coding_iso2022 (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
4870 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4871 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4872 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4873 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4874 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4875 eol_type_t eol_type = str->eol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4876 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4877 unsigned_char_dynarr *real_dst = dst;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4878 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4879 Lisp_Object coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4880
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4881 XSETCODING_SYSTEM (coding_system, str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4882
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4883 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4884 if (flags & CODING_STATE_COMPOSITE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4885 dst = str->iso2022.composite_chars;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4886 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4887
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4888 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4889 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
4890 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4891 if (flags & CODING_STATE_ESCAPE)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4892 { /* Within ESC sequence */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4893 int retval = parse_iso2022_esc (coding_system, &str->iso2022,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4894 c, &flags, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4895
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4896 if (retval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4897 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4898 switch (str->iso2022.esc)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4899 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4900 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4901 case ISO_ESC_START_COMPOSITE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4902 if (str->iso2022.composite_chars)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4903 Dynarr_reset (str->iso2022.composite_chars);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4904 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4905 str->iso2022.composite_chars = Dynarr_new (unsigned_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4906 dst = str->iso2022.composite_chars;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4907 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4908 case ISO_ESC_END_COMPOSITE:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4909 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4910 Bufbyte comstr[MAX_EMCHAR_LEN];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4911 Bytecount len;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4912 Emchar emch = lookup_composite_char (Dynarr_atp (dst, 0),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4913 Dynarr_length (dst));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4914 dst = real_dst;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4915 len = set_charptr_emchar (comstr, emch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4916 Dynarr_add_many (dst, comstr, len);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4917 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4918 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4919 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4920
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4921 case ISO_ESC_LITERAL:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4922 DECODE_ADD_BINARY_CHAR (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4923 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4924
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4925 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4926 /* Everything else handled already */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4927 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4928 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4929 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4931 /* Attempted error recovery. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4932 if (str->iso2022.output_direction_sequence)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4933 ensure_correct_direction (flags & CODING_STATE_R2L ?
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4934 CHARSET_RIGHT_TO_LEFT :
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4935 CHARSET_LEFT_TO_RIGHT,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4936 str->codesys, dst, 0, 1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4937 /* More error recovery. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4938 if (!retval || str->iso2022.output_literally)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4939 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4940 /* Output the (possibly invalid) sequence */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4941 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4942 for (i = 0; i < str->iso2022.esc_bytes_index; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4943 DECODE_ADD_BINARY_CHAR (str->iso2022.esc_bytes[i], dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4944 flags &= CODING_STATE_ISO2022_LOCK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4945 if (!retval)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4946 n++, src--;/* Repeat the loop with the same character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4947 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4948 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4949 /* No sense in reprocessing the final byte of the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4950 escape sequence; it could mess things up anyway.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4951 Just add it now. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4952 DECODE_ADD_BINARY_CHAR (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4953 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4954 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4955 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4956 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4957 else if (BYTE_C0_P (c) || BYTE_C1_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4958 { /* Control characters */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4959
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4960 /***** Error-handling *****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4961
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4962 /* If we were in the middle of a character, dump out the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4963 partial character. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4964 DECODE_OUTPUT_PARTIAL_CHAR (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4965
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4966 /* If we just saw a single-shift character, dump it out.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4967 This may dump out the wrong sort of single-shift character,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4968 but least it will give an indication that something went
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4969 wrong. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4970 if (flags & CODING_STATE_SS2)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4971 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4972 DECODE_ADD_BINARY_CHAR (ISO_CODE_SS2, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4973 flags &= ~CODING_STATE_SS2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4974 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4975 if (flags & CODING_STATE_SS3)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4976 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4977 DECODE_ADD_BINARY_CHAR (ISO_CODE_SS3, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4978 flags &= ~CODING_STATE_SS3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4979 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4980
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4981 /***** Now handle the control characters. *****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4982
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4983 /* Handle CR/LF */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4984 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4985
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4986 flags &= CODING_STATE_ISO2022_LOCK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4988 if (!parse_iso2022_esc (coding_system, &str->iso2022, c, &flags, 1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4989 DECODE_ADD_BINARY_CHAR (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4990 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4991 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4992 { /* Graphic characters */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4993 Lisp_Object charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4994 int lb;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4995 int reg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4996
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4997 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4998
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4999 /* Now determine the charset. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5000 reg = ((flags & CODING_STATE_SS2) ? 2
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5001 : (flags & CODING_STATE_SS3) ? 3
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5002 : !BYTE_ASCII_P (c) ? str->iso2022.register_right
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5003 : str->iso2022.register_left);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5004 charset = str->iso2022.charset[reg];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5006 /* Error checking: */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5007 if (! CHARSETP (charset)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5008 || str->iso2022.invalid_designated[reg]
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5009 || (((c & 0x7F) == ' ' || (c & 0x7F) == ISO_CODE_DEL)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5010 && XCHARSET_CHARS (charset) == 94))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5011 /* Mrmph. We are trying to invoke a register that has no
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5012 or an invalid charset in it, or trying to add a character
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5013 outside the range of the charset. Insert that char literally
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5014 to preserve it for the output. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5015 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5016 DECODE_OUTPUT_PARTIAL_CHAR (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5017 DECODE_ADD_BINARY_CHAR (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5018 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5019
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5020 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5021 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5022 /* Things are probably hunky-dorey. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5023
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5024 /* Fetch reverse charset, maybe. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5025 if (((flags & CODING_STATE_R2L) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5026 XCHARSET_DIRECTION (charset) == CHARSET_LEFT_TO_RIGHT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5027 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5028 (!(flags & CODING_STATE_R2L) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5029 XCHARSET_DIRECTION (charset) == CHARSET_RIGHT_TO_LEFT))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5030 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5031 Lisp_Object new_charset =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5032 XCHARSET_REVERSE_DIRECTION_CHARSET (charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5033 if (!NILP (new_charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5034 charset = new_charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5035 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5036
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5037 lb = XCHARSET_LEADING_BYTE (charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5038 switch (XCHARSET_REP_BYTES (charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5039 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5040 case 1: /* ASCII */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5041 DECODE_OUTPUT_PARTIAL_CHAR (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5042 Dynarr_add (dst, c & 0x7F);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5043 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5044
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5045 case 2: /* one-byte official */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5046 DECODE_OUTPUT_PARTIAL_CHAR (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5047 Dynarr_add (dst, lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5048 Dynarr_add (dst, c | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5049 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5050
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5051 case 3: /* one-byte private or two-byte official */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5052 if (XCHARSET_PRIVATE_P (charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5053 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5054 DECODE_OUTPUT_PARTIAL_CHAR (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5055 Dynarr_add (dst, PRE_LEADING_BYTE_PRIVATE_1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5056 Dynarr_add (dst, lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5057 Dynarr_add (dst, c | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5058 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5059 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5060 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5061 if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5062 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5063 Dynarr_add (dst, lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5064 Dynarr_add (dst, ch | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5065 Dynarr_add (dst, c | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5066 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5067 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5068 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5069 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5070 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5071 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5072
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5073 default: /* two-byte private */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5074 if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5075 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5076 Dynarr_add (dst, PRE_LEADING_BYTE_PRIVATE_2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5077 Dynarr_add (dst, lb);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5078 Dynarr_add (dst, ch | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5079 Dynarr_add (dst, c | 0x80);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5080 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5081 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5082 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5083 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5084 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5085 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5086
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5087 if (!ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5088 flags &= CODING_STATE_ISO2022_LOCK;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5089 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5090
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5091 label_continue_loop:;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5092 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5093
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5094 if (flags & CODING_STATE_END)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5095 DECODE_OUTPUT_PARTIAL_CHAR (ch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5096
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5097 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5098 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5099 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5100
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5101
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5102 /***** ISO2022 encoder *****/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5103
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5104 /* Designate CHARSET into register REG. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5105
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5106 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5107 iso2022_designate (Lisp_Object charset, unsigned char reg,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5108 struct encoding_stream *str, unsigned_char_dynarr *dst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5109 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5110 static const char inter94[] = "()*+";
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5111 static const char inter96[] = ",-./";
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5112 unsigned int type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5113 unsigned char final;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5114 Lisp_Object old_charset = str->iso2022.charset[reg];
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5115
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5116 str->iso2022.charset[reg] = charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5117 if (!CHARSETP (charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5118 /* charset might be an initial nil or t. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5119 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5120 type = XCHARSET_TYPE (charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5121 final = XCHARSET_FINAL (charset);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5122 if (!str->iso2022.force_charset_on_output[reg] &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5123 CHARSETP (old_charset) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5124 XCHARSET_TYPE (old_charset) == type &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5125 XCHARSET_FINAL (old_charset) == final)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5126 return;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5127
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5128 str->iso2022.force_charset_on_output[reg] = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5129
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5130 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5131 charset_conversion_spec_dynarr *dyn =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5132 str->codesys->iso2022.output_conv;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5133
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5134 if (dyn)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5135 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5136 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5137
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5138 for (i = 0; i < Dynarr_length (dyn); i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5139 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5140 struct charset_conversion_spec *spec = Dynarr_atp (dyn, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5141 if (EQ (charset, spec->from_charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5142 charset = spec->to_charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5143 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5144 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5145 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5146
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5147 Dynarr_add (dst, ISO_CODE_ESC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5148 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5149 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5150 case CHARSET_TYPE_94:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5151 Dynarr_add (dst, inter94[reg]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5152 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5153 case CHARSET_TYPE_96:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5154 Dynarr_add (dst, inter96[reg]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5155 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5156 case CHARSET_TYPE_94X94:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5157 Dynarr_add (dst, '$');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5158 if (reg != 0
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5159 || !(CODING_SYSTEM_ISO2022_SHORT (str->codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5160 || final < '@'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5161 || final > 'B')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5162 Dynarr_add (dst, inter94[reg]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5163 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5164 case CHARSET_TYPE_96X96:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5165 Dynarr_add (dst, '$');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5166 Dynarr_add (dst, inter96[reg]);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5167 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5168 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5169 Dynarr_add (dst, final);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5170 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5171
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5172 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5173 ensure_normal_shift (struct encoding_stream *str, unsigned_char_dynarr *dst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5174 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5175 if (str->iso2022.register_left != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5176 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5177 Dynarr_add (dst, ISO_CODE_SI);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5178 str->iso2022.register_left = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5179 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5180 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5181
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5182 static void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5183 ensure_shift_out (struct encoding_stream *str, unsigned_char_dynarr *dst)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5184 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5185 if (str->iso2022.register_left != 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5186 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5187 Dynarr_add (dst, ISO_CODE_SO);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5188 str->iso2022.register_left = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5189 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5190 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5191
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5192 /* Convert internally-formatted data to ISO2022 format. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5193
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5194 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
5195 encode_coding_iso2022 (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
5196 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5197 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5198 unsigned char charmask, c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5199 unsigned char char_boundary;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5200 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5201 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5202 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5203 Lisp_Coding_System *codesys = str->codesys;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5204 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5205 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5206 Lisp_Object charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5207 int half;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5209 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5210 /* flags for handling composite chars. We do a little switcharoo
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5211 on the source while we're outputting the composite char. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5212 unsigned int saved_n = 0;
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5213 const unsigned char *saved_src = NULL;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5214 int in_composite = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5215 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5216
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5217 char_boundary = str->iso2022.current_char_boundary;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5218 charset = str->iso2022.current_charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5219 half = str->iso2022.current_half;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5220
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5221 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5222 back_to_square_n:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5223 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5224 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5225 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5226 c = *src++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5227
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5228 if (BYTE_ASCII_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5229 { /* Processing ASCII character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5230 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5231
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5232 restore_left_to_right_direction (codesys, dst, &flags, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5233
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5234 /* Make sure G0 contains ASCII */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5235 if ((c > ' ' && c < ISO_CODE_DEL) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5236 !CODING_SYSTEM_ISO2022_NO_ASCII_CNTL (codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5237 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5238 ensure_normal_shift (str, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5239 iso2022_designate (Vcharset_ascii, 0, str, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5240 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5241
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5242 /* If necessary, restore everything to the default state
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5243 at end-of-line */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5244 if (c == '\n' &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5245 !(CODING_SYSTEM_ISO2022_NO_ASCII_EOL (codesys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5246 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5247 restore_left_to_right_direction (codesys, dst, &flags, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5248
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5249 ensure_normal_shift (str, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5250
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5251 for (i = 0; i < 4; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5252 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5253 Lisp_Object initial_charset =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5254 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5255 iso2022_designate (initial_charset, i, str, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5256 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5257 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5258 if (c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5259 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5260 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5261 Dynarr_add (dst, '\r');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5262 if (eol_type != EOL_CR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5263 Dynarr_add (dst, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5264 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5265 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5266 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5267 if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5268 && fit_to_be_escape_quoted (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5269 Dynarr_add (dst, ISO_CODE_ESC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5270 Dynarr_add (dst, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5271 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5272 char_boundary = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5273 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5274
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5275 else if (BUFBYTE_LEADING_BYTE_P (c) || BUFBYTE_LEADING_BYTE_P (ch))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5276 { /* Processing Leading Byte */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5277 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5278 charset = CHARSET_BY_LEADING_BYTE (c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5279 if (LEADING_BYTE_PREFIX_P(c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5280 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5281 else if (!EQ (charset, Vcharset_control_1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5282 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5283 && !EQ (charset, Vcharset_composite)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5284 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5285 )
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5286 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5287 int reg;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5288
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5289 ensure_correct_direction (XCHARSET_DIRECTION (charset),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5290 codesys, dst, &flags, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5291
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5292 /* Now determine which register to use. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5293 reg = -1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5294 for (i = 0; i < 4; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5295 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5296 if (EQ (charset, str->iso2022.charset[i]) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5297 EQ (charset,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5298 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5299 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5300 reg = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5301 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5302 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5303 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5304
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5305 if (reg == -1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5306 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5307 if (XCHARSET_GRAPHIC (charset) != 0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5308 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5309 if (!NILP (str->iso2022.charset[1]) &&
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5310 (!CODING_SYSTEM_ISO2022_SEVEN (codesys) ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5311 CODING_SYSTEM_ISO2022_LOCK_SHIFT (codesys)))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5312 reg = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5313 else if (!NILP (str->iso2022.charset[2]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5314 reg = 2;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5315 else if (!NILP (str->iso2022.charset[3]))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5316 reg = 3;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5317 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5318 reg = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5319 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5320 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5321 reg = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5322 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5323
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5324 iso2022_designate (charset, reg, str, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5325
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5326 /* Now invoke that register. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5327 switch (reg)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5328 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5329 case 0:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5330 ensure_normal_shift (str, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5331 half = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5332 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5333
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5334 case 1:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5335 if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5336 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5337 ensure_shift_out (str, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5338 half = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5339 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5340 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5341 half = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5342 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5343
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5344 case 2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5345 if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5346 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5347 Dynarr_add (dst, ISO_CODE_ESC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5348 Dynarr_add (dst, 'N');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5349 half = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5350 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5351 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5352 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5353 Dynarr_add (dst, ISO_CODE_SS2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5354 half = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5355 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5356 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5357
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5358 case 3:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5359 if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5360 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5361 Dynarr_add (dst, ISO_CODE_ESC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5362 Dynarr_add (dst, 'O');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5363 half = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5364 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5365 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5366 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5367 Dynarr_add (dst, ISO_CODE_SS3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5368 half = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5369 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5370 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5371
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5372 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5373 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5374 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5375 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5376 char_boundary = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5377 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5378 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5379 { /* Processing Non-ASCII character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5380 charmask = (half == 0 ? 0x7F : 0xFF);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5381 char_boundary = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5382 if (EQ (charset, Vcharset_control_1))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5383 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5384 if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5385 && fit_to_be_escape_quoted (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5386 Dynarr_add (dst, ISO_CODE_ESC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5387 /* you asked for it ... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5388 Dynarr_add (dst, c - 0x20);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5389 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5390 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5391 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5392 switch (XCHARSET_REP_BYTES (charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5393 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5394 case 2:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5395 Dynarr_add (dst, c & charmask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5396 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5397 case 3:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5398 if (XCHARSET_PRIVATE_P (charset))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5399 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5400 Dynarr_add (dst, c & charmask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5401 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5402 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5403 else if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5404 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5405 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5406 if (EQ (charset, Vcharset_composite))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5407 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5408 if (in_composite)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5409 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5410 /* #### Bother! We don't know how to
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5411 handle this yet. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5412 Dynarr_add (dst, '~');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5413 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5414 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5415 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5416 Emchar emch = MAKE_CHAR (Vcharset_composite,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5417 ch & 0x7F, c & 0x7F);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5418 Lisp_Object lstr = composite_char_string (emch);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5419 saved_n = n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5420 saved_src = src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5421 in_composite = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5422 src = XSTRING_DATA (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5423 n = XSTRING_LENGTH (lstr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5424 Dynarr_add (dst, ISO_CODE_ESC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5425 Dynarr_add (dst, '0'); /* start composing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5426 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5427 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5428 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5429 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5430 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5431 Dynarr_add (dst, ch & charmask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5432 Dynarr_add (dst, c & charmask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5433 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5434 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5435 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5436 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5437 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5438 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5439 char_boundary = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5440 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5441 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5442 case 4:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5443 if (ch)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5444 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5445 Dynarr_add (dst, ch & charmask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5446 Dynarr_add (dst, c & charmask);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5447 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5448 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5449 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5450 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5451 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5452 char_boundary = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5453 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5454 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5455 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5456 abort ();
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5457 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5458 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5459 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5460 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5461
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5462 #ifdef ENABLE_COMPOSITE_CHARS
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5463 if (in_composite)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5464 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5465 n = saved_n;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5466 src = saved_src;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5467 in_composite = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5468 Dynarr_add (dst, ISO_CODE_ESC);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5469 Dynarr_add (dst, '1'); /* end composing */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5470 goto back_to_square_n; /* Wheeeeeeeee ..... */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5471 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5472 #endif /* ENABLE_COMPOSITE_CHARS */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5473
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5474 if (char_boundary && flags & CODING_STATE_END)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5475 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5476 restore_left_to_right_direction (codesys, dst, &flags, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5477 ensure_normal_shift (str, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5478 for (i = 0; i < 4; i++)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5479 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5480 Lisp_Object initial_charset =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5481 CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5482 iso2022_designate (initial_charset, i, str, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5483 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5486 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5487 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5488 str->iso2022.current_char_boundary = char_boundary;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5489 str->iso2022.current_charset = charset;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5490 str->iso2022.current_half = half;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5491
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5492 /* Verbum caro factum est! */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5493 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5494 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5495
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5496 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5497 /* No-conversion methods */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5498 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5499
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5500 /* This is used when reading in "binary" files -- i.e. files that may
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5501 contain all 256 possible byte values and that are not to be
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5502 interpreted as being in any particular decoding. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5503 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
5504 decode_coding_no_conversion (Lstream *decoding, const Extbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
5505 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5506 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5507 struct decoding_stream *str = DECODING_STREAM_DATA (decoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5508 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5509 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5510 eol_type_t eol_type = str->eol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5511
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5512 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5513 {
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
5514 unsigned char c = *(unsigned char *)src++;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5515
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5516 DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5517 DECODE_ADD_BINARY_CHAR (c, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5518 label_continue_loop:;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5519 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5520
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5521 DECODE_HANDLE_END_OF_CONVERSION (flags, ch, dst);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5522
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5523 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5524 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5525 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5526
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5527 static void
444
576fb035e263 Import from CVS: tag r21-2-37
cvs
parents: 442
diff changeset
5528 encode_coding_no_conversion (Lstream *encoding, const Bufbyte *src,
462
0784d089fdc9 Import from CVS: tag r21-2-46
cvs
parents: 452
diff changeset
5529 unsigned_char_dynarr *dst, Lstream_data_count n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5530 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5531 unsigned char c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5532 struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5533 unsigned int flags = str->flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5534 unsigned int ch = str->ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5535 eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5536
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5537 while (n--)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5538 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5539 c = *src++;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5540 if (c == '\n')
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5541 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5542 if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5543 Dynarr_add (dst, '\r');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5544 if (eol_type != EOL_CR)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5545 Dynarr_add (dst, '\n');
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5546 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5547 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5548 else if (BYTE_ASCII_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5549 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5550 assert (ch == 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5551 Dynarr_add (dst, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5552 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5553 else if (BUFBYTE_LEADING_BYTE_P (c))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5554 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5555 assert (ch == 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5556 if (c == LEADING_BYTE_LATIN_ISO8859_1 ||
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5557 c == LEADING_BYTE_CONTROL_1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5558 ch = c;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5559 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5560 Dynarr_add (dst, '~'); /* untranslatable character */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5561 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5562 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5563 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5564 if (ch == LEADING_BYTE_LATIN_ISO8859_1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5565 Dynarr_add (dst, c);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5566 else if (ch == LEADING_BYTE_CONTROL_1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5567 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5568 assert (c < 0xC0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5569 Dynarr_add (dst, c - 0x20);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5570 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5571 /* else it should be the second or third byte of an
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5572 untranslatable character, so ignore it */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5573 ch = 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5574 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5575 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5576
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5577 str->flags = flags;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5578 str->ch = ch;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5579 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5581
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5582
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5583 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5584 /* Initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5585 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5587 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5588 syms_of_file_coding (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5589 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5590 INIT_LRECORD_IMPLEMENTATION (coding_system);
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5591
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5592 DEFERROR_STANDARD (Qtext_conversion_error, Qconversion_error);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5593
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5594 DEFSUBR (Fcoding_system_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5595 DEFSUBR (Ffind_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5596 DEFSUBR (Fget_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5597 DEFSUBR (Fcoding_system_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5598 DEFSUBR (Fcoding_system_name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5599 DEFSUBR (Fmake_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5600 DEFSUBR (Fcopy_coding_system);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5601 DEFSUBR (Fcoding_system_canonical_name_p);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5602 DEFSUBR (Fcoding_system_alias_p);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5603 DEFSUBR (Fcoding_system_aliasee);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5604 DEFSUBR (Fdefine_coding_system_alias);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5605 DEFSUBR (Fsubsidiary_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5606
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5607 DEFSUBR (Fcoding_system_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5608 DEFSUBR (Fcoding_system_doc_string);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5609 DEFSUBR (Fcoding_system_property);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5610
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5611 DEFSUBR (Fcoding_category_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5612 DEFSUBR (Fset_coding_priority_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5613 DEFSUBR (Fcoding_priority_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5614 DEFSUBR (Fset_coding_category_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5615 DEFSUBR (Fcoding_category_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5616
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5617 DEFSUBR (Fdetect_coding_region);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5618 DEFSUBR (Fdecode_coding_region);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5619 DEFSUBR (Fencode_coding_region);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5620 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5621 DEFSUBR (Fdecode_shift_jis_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5622 DEFSUBR (Fencode_shift_jis_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5623 DEFSUBR (Fdecode_big5_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5624 DEFSUBR (Fencode_big5_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5625 DEFSUBR (Fset_ucs_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5626 DEFSUBR (Fucs_char);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5627 DEFSUBR (Fset_char_ucs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5628 DEFSUBR (Fchar_ucs);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5629 #endif /* MULE */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5630 DEFSYMBOL_MULTIWORD_PREDICATE (Qcoding_systemp);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5631 DEFSYMBOL (Qno_conversion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5632 DEFSYMBOL (Qraw_text);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5633 #ifdef MULE
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5634 DEFSYMBOL (Qbig5);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5635 DEFSYMBOL (Qshift_jis);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5636 defsymbol (&Qucs4, "ucs-4");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5637 defsymbol (&Qutf8, "utf-8");
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5638 DEFSYMBOL (Qccl);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5639 DEFSYMBOL (Qiso2022);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5640 #endif /* MULE */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5641 DEFSYMBOL (Qmnemonic);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5642 DEFSYMBOL (Qeol_type);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5643 DEFSYMBOL (Qpost_read_conversion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5644 DEFSYMBOL (Qpre_write_conversion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5645
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5646 DEFSYMBOL (Qcr);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5647 DEFSYMBOL (Qlf);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5648 DEFSYMBOL (Qcrlf);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5649 DEFSYMBOL (Qeol_cr);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5650 DEFSYMBOL (Qeol_lf);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5651 DEFSYMBOL (Qeol_crlf);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5652 #ifdef MULE
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5653 DEFSYMBOL (Qcharset_g0);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5654 DEFSYMBOL (Qcharset_g1);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5655 DEFSYMBOL (Qcharset_g2);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5656 DEFSYMBOL (Qcharset_g3);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5657 DEFSYMBOL (Qforce_g0_on_output);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5658 DEFSYMBOL (Qforce_g1_on_output);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5659 DEFSYMBOL (Qforce_g2_on_output);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5660 DEFSYMBOL (Qforce_g3_on_output);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5661 DEFSYMBOL (Qno_iso6429);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5662 DEFSYMBOL (Qinput_charset_conversion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5663 DEFSYMBOL (Qoutput_charset_conversion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5664
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5665 DEFSYMBOL (Qshort);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5666 DEFSYMBOL (Qno_ascii_eol);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5667 DEFSYMBOL (Qno_ascii_cntl);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5668 DEFSYMBOL (Qseven);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5669 DEFSYMBOL (Qlock_shift);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5670 DEFSYMBOL (Qescape_quoted);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5671 #endif /* MULE */
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5672 DEFSYMBOL (Qencode);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
5673 DEFSYMBOL (Qdecode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5674
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5675 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5676 defsymbol (&coding_category_symbol[CODING_CATEGORY_SHIFT_JIS],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5677 "shift-jis");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5678 defsymbol (&coding_category_symbol[CODING_CATEGORY_BIG5],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5679 "big5");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5680 defsymbol (&coding_category_symbol[CODING_CATEGORY_UCS4],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5681 "ucs-4");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5682 defsymbol (&coding_category_symbol[CODING_CATEGORY_UTF8],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5683 "utf-8");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5684 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_7],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5685 "iso-7");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5686 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_DESIGNATE],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5687 "iso-8-designate");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5688 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_1],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5689 "iso-8-1");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5690 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_8_2],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5691 "iso-8-2");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5692 defsymbol (&coding_category_symbol[CODING_CATEGORY_ISO_LOCK_SHIFT],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5693 "iso-lock-shift");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5694 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5695 defsymbol (&coding_category_symbol[CODING_CATEGORY_NO_CONVERSION],
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5696 "no-conversion");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5697 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5698
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5699 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5700 lstream_type_create_file_coding (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5701 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5702 LSTREAM_HAS_METHOD (decoding, reader);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5703 LSTREAM_HAS_METHOD (decoding, writer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5704 LSTREAM_HAS_METHOD (decoding, rewinder);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5705 LSTREAM_HAS_METHOD (decoding, seekable_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5706 LSTREAM_HAS_METHOD (decoding, flusher);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5707 LSTREAM_HAS_METHOD (decoding, closer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5708 LSTREAM_HAS_METHOD (decoding, marker);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5709
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5710 LSTREAM_HAS_METHOD (encoding, reader);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5711 LSTREAM_HAS_METHOD (encoding, writer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5712 LSTREAM_HAS_METHOD (encoding, rewinder);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5713 LSTREAM_HAS_METHOD (encoding, seekable_p);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5714 LSTREAM_HAS_METHOD (encoding, flusher);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5715 LSTREAM_HAS_METHOD (encoding, closer);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5716 LSTREAM_HAS_METHOD (encoding, marker);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5717 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5718
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5719 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5720 vars_of_file_coding (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5721 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5722 int i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5723
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5724 fcd = xnew (struct file_coding_dump);
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 448
diff changeset
5725 dump_add_root_struct_ptr (&fcd, &fcd_description);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5726
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5727 /* Initialize to something reasonable ... */
448
3078fd1074e8 Import from CVS: tag r21-2-39
cvs
parents: 444
diff changeset
5728 for (i = 0; i < CODING_CATEGORY_LAST; i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5729 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5730 fcd->coding_category_system[i] = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5731 fcd->coding_category_by_priority[i] = i;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5732 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5733
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5734 Fprovide (intern ("file-coding"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5735
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5736 DEFVAR_LISP ("keyboard-coding-system", &Vkeyboard_coding_system /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5737 Coding system used for TTY keyboard input.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5738 Not used under a windowing system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5739 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5740 Vkeyboard_coding_system = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5741
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5742 DEFVAR_LISP ("terminal-coding-system", &Vterminal_coding_system /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5743 Coding system used for TTY display output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5744 Not used under a windowing system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5745 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5746 Vterminal_coding_system = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5747
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5748 DEFVAR_LISP ("coding-system-for-read", &Vcoding_system_for_read /*
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5749 Overriding coding system used when reading from a file or process.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5750 You should bind this variable with `let', but do not set it globally.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5751 If this is non-nil, it specifies the coding system that will be used
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5752 to decode input on read operations, such as from a file or process.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5753 It overrides `buffer-file-coding-system-for-read',
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5754 `insert-file-contents-pre-hook', etc. Use those variables instead of
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5755 this one for permanent changes to the environment. */ );
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5756 Vcoding_system_for_read = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5757
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5758 DEFVAR_LISP ("coding-system-for-write",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5759 &Vcoding_system_for_write /*
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5760 Overriding coding system used when writing to a file or process.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5761 You should bind this variable with `let', but do not set it globally.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5762 If this is non-nil, it specifies the coding system that will be used
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5763 to encode output for write operations, such as to a file or process.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5764 It overrides `buffer-file-coding-system', `write-region-pre-hook', etc.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5765 Use those variables instead of this one for permanent changes to the
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5766 environment. */ );
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5767 Vcoding_system_for_write = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5768
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5769 DEFVAR_LISP ("file-name-coding-system", &Vfile_name_coding_system /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5770 Coding system used to convert pathnames when accessing files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5771 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5772 Vfile_name_coding_system = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5773
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5774 DEFVAR_BOOL ("enable-multibyte-characters", &enable_multibyte_characters /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5775 Non-nil means the buffer contents are regarded as multi-byte form
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5776 of characters, not a binary code. This affects the display, file I/O,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5777 and behaviors of various editing commands.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5778
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5779 Setting this to nil does not do anything.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5780 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5781 enable_multibyte_characters = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5782 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5783
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5784 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5785 complex_vars_of_file_coding (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5786 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5787 staticpro (&Vcoding_system_hash_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5788 Vcoding_system_hash_table =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5789 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, HASH_TABLE_EQ);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5790
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5791 the_codesys_prop_dynarr = Dynarr_new (codesys_prop);
452
3d3049ae1304 Import from CVS: tag r21-2-41
cvs
parents: 448
diff changeset
5792 dump_add_root_struct_ptr (&the_codesys_prop_dynarr, &codesys_prop_dynarr_description);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5793
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5794 #define DEFINE_CODESYS_PROP(Prop_Type, Sym) do \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5795 { \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5796 struct codesys_prop csp; \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5797 csp.sym = (Sym); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5798 csp.prop_type = (Prop_Type); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5799 Dynarr_add (the_codesys_prop_dynarr, csp); \
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5800 } while (0)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5801
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5802 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qmnemonic);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5803 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_type);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5804 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_cr);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5805 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_crlf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5806 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qeol_lf);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5807 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qpost_read_conversion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5808 DEFINE_CODESYS_PROP (CODESYS_PROP_ALL_OK, Qpre_write_conversion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5809 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5810 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5811 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g1);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5812 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g2);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5813 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qcharset_g3);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5814 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g0_on_output);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5815 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g1_on_output);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5816 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g2_on_output);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5817 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qforce_g3_on_output);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5818 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qshort);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5819 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_ascii_eol);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5820 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_ascii_cntl);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5821 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qseven);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5822 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qlock_shift);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5823 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qno_iso6429);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5824 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qescape_quoted);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5825 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qinput_charset_conversion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5826 DEFINE_CODESYS_PROP (CODESYS_PROP_ISO2022, Qoutput_charset_conversion);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5827
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5828 DEFINE_CODESYS_PROP (CODESYS_PROP_CCL, Qencode);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5829 DEFINE_CODESYS_PROP (CODESYS_PROP_CCL, Qdecode);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5830 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5831 /* Need to create this here or we're really screwed. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5832 Fmake_coding_system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5833 (Qraw_text, Qno_conversion,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5834 build_string ("Raw text, which means it converts only line-break-codes."),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5835 list2 (Qmnemonic, build_string ("Raw")));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5836
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5837 Fmake_coding_system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5838 (Qbinary, Qno_conversion,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5839 build_string ("Binary, which means it does not convert anything."),
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5840 list4 (Qeol_type, Qlf,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5841 Qmnemonic, build_string ("Binary")));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5842
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5843 Fdefine_coding_system_alias (Qno_conversion, Qraw_text);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5844
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5845 Fdefine_coding_system_alias (Qfile_name, Qbinary);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5846
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5847 Fdefine_coding_system_alias (Qterminal, Qbinary);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5848 Fdefine_coding_system_alias (Qkeyboard, Qbinary);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5849
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5850 /* Need this for bootstrapping */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5851 fcd->coding_category_system[CODING_CATEGORY_NO_CONVERSION] =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5852 Fget_coding_system (Qraw_text);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5853
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5854 #ifdef MULE
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5855 {
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5856 size_t i;
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5857
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
5858 for (i = 0; i < countof (fcd->ucs_to_mule_table); i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5859 fcd->ucs_to_mule_table[i] = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5860 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5861 staticpro (&mule_to_ucs_table);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5862 mule_to_ucs_table = Fmake_char_table(Qgeneric);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5863 #endif /* MULE */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5864 }