annotate src/file-coding.c @ 5819:ba0ff364bd94

Repair invalid GNU-style key-bindings.
author Stephen J. Turnbull <stephen@xemacs.org>
date Sat, 18 Oct 2014 23:21:30 +0900
parents a216b3c2b09e
children 96fb76dd98df
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1 /* Text encoding conversion functions; coding-system object.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2 #### rename me to coding-system.c or coding.c
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3 Copyright (C) 1991, 1995 Free Software Foundation, Inc.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4 Copyright (C) 1995 Sun Microsystems, Inc.
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5126
diff changeset
5 Copyright (C) 2000, 2001, 2002, 2003, 2005, 2010 Ben Wing.
428
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 This file is part of XEmacs.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
8
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5191
diff changeset
9 XEmacs is free software: you can redistribute it and/or modify it
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
10 under the terms of the GNU General Public License as published by the
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5191
diff changeset
11 Free Software Foundation, either version 3 of the License, or (at your
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5191
diff changeset
12 option) any later version.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
13
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
14 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
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
17 for more details.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
18
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
19 You should have received a copy of the GNU General Public License
5402
308d34e9f07d Changed bulk of GPLv2 or later files identified by script
Mats Lidell <matsl@xemacs.org>
parents: 5191
diff changeset
20 along with XEmacs. If not, see <http://www.gnu.org/licenses/>. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
21
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
22 /* Synched up with: Not in FSF. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
23
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
24 /* Authorship:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
25
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
26 Current primary author: Ben Wing <ben@xemacs.org>
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
27
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
28 Rewritten by Ben Wing <ben@xemacs.org>, based originally on coding.c
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
29 from Mule 2.? but probably does not share one line of code with that
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
30 original source. Rewriting work started around Dec. 1994. or Jan. 1995.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
31 Proceeded in earnest till Nov. 1995.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
32
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
33 Around Feb. 17, 1998, Andy Piper renamed what was then mule-coding.c to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
34 file-coding.c, with the intention of using it to do end-of-line conversion
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
35 on non-MULE machines (specifically, on Windows machines). He separated
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
36 out the MULE stuff from non-MULE using ifdef's, and searched throughout
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
37 the rest of the source tree looking for coding-system-related code that
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
38 was ifdef MULE but should be ifdef HAVE_CODING_SYSTEMS.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
39
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
40 Sept. 4 - 8, 1998, Tomohiko Morioka added the UCS_4 and UTF_8 coding system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
41 types, providing a primitive means of decoding and encoding externally-
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
42 formatted Unicode/UCS_4 and Unicode/UTF_8 data.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
43
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
44 January 25, 2000, Martin Buchholz redid and fleshed out the coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
45 system alias handling that was first added in prototype form by
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
46 Hrjove Niksic, April 15, 1999.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
47
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
48 April to May 2000, Ben Wing: More major reorganization. Adding features
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
49 needed for MS Windows (multibyte, unicode, unicode-to-multibyte), the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
50 "chain" coding system for chaining two together, and doing a lot of
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
51 reorganization in preparation for properly abstracting out the different
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
52 coding system types.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
53
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
54 June 2001, Ben Wing: Added Unicode support. Eliminated previous
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
55 junky Unicode translation support.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
56
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
57 August 2001, Ben Wing: Moved Unicode support to unicode.c. Finished
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
58 abstracting everything except detection, which is hard to abstract (see
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
59 just below).
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
60
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
61 September 2001, Ben Wing: Moved Mule code to mule-coding.c, Windows code
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
62 to intl-win32.c. Lots more rewriting; very little code is untouched
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
63 from before April 2000. Abstracted the detection code, added multiple
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
64 levels of likelihood to increase the reliability of the algorithm.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
65
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
66 October 2001, Ben Wing: HAVE_CODING_SYSTEMS is always now defined.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
67 Removed the conditionals.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
68 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
69
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
70 #include <config.h>
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
71 #include "lisp.h"
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 #include "buffer.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
74 #include "elhash.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
75 #include "insdel.h"
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
76 #include "lstream.h"
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
77 #include "opaque.h"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
78 #include "file-coding.h"
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
79 #include "extents.h"
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
80 #include "rangetab.h"
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
81 #include "chartab.h"
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
82 #include "sysfile.h"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
83
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
84 #ifdef HAVE_ZLIB
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
85 #include "zlib.h"
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
86 #endif
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
87
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
88 Lisp_Object Vkeyboard_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
89 Lisp_Object Vterminal_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
90 Lisp_Object Vcoding_system_for_read;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
91 Lisp_Object Vcoding_system_for_write;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
92 Lisp_Object Vfile_name_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
93
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
94 Lisp_Object Qaliases, Qcharset_skip_chars_string;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
95
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
96 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
97 Lisp_Object Vdebug_coding_detection;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
98 #endif
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
99
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
100 #ifdef MULE
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
101 extern Lisp_Object Vcharset_ascii, Vcharset_control_1,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
102 Vcharset_latin_iso8859_1;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
103 #endif
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
104
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
105 typedef struct coding_system_type_entry
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
106 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
107 struct coding_system_methods *meths;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
108 } coding_system_type_entry;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
109
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
110 typedef struct
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
111 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
112 Dynarr_declare (coding_system_type_entry);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
113 } coding_system_type_entry_dynarr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
114
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
115 static coding_system_type_entry_dynarr *the_coding_system_type_entry_dynarr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
116
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
117 static const struct memory_description cste_description_1[] = {
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
118 { XD_BLOCK_PTR, offsetof (coding_system_type_entry, meths), 1,
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
119 { &coding_system_methods_description } },
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
120 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
121 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
122
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
123 static const struct sized_memory_description cste_description = {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
124 sizeof (coding_system_type_entry),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
125 cste_description_1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
126 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
127
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
128 static const struct memory_description csted_description_1[] = {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
129 XD_DYNARR_DESC (coding_system_type_entry_dynarr, &cste_description),
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
130 { XD_END }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
131 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
132
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
133 static const struct sized_memory_description csted_description = {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
134 sizeof (coding_system_type_entry_dynarr),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
135 csted_description_1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
136 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
137
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
138 static Lisp_Object Vcoding_system_type_list;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
139
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
140 /* Coding system currently associated with each coding category. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
141 Lisp_Object coding_category_system[MAX_DETECTOR_CATEGORIES];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
142
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
143 /* Table of all coding categories in decreasing order of priority.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
144 This describes a permutation of the possible coding categories. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
145 int coding_category_by_priority[MAX_DETECTOR_CATEGORIES];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
146
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
147 /* Value used with to give a unique name to nameless coding systems */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
148 int coding_system_tick;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
149
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
150 int coding_detector_count;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
151 int coding_detector_category_count;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
152
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
153 detector_dynarr *all_coding_detectors;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
154
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
155 static const struct memory_description struct_detector_category_description_1[]
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
156 =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
157 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
158 { XD_LISP_OBJECT, offsetof (struct detector_category, sym) },
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
159 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
160 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
161
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
162 static const struct sized_memory_description struct_detector_category_description =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
163 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
164 sizeof (struct detector_category),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
165 struct_detector_category_description_1
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
166 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
167
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
168 static const struct memory_description detector_category_dynarr_description_1[] =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
169 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
170 XD_DYNARR_DESC (detector_category_dynarr,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
171 &struct_detector_category_description),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
172 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
173 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
174
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
175 static const struct sized_memory_description detector_category_dynarr_description = {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
176 sizeof (detector_category_dynarr),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
177 detector_category_dynarr_description_1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
178 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
179
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
180 static const struct memory_description struct_detector_description_1[]
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
181 =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
182 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
183 { XD_BLOCK_PTR, offsetof (struct detector, cats), 1,
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
184 { &detector_category_dynarr_description } },
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
185 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
186 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
187
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
188 static const struct sized_memory_description struct_detector_description =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
189 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
190 sizeof (struct detector),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
191 struct_detector_description_1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
192 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
193
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
194 static const struct memory_description detector_dynarr_description_1[] =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
195 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
196 XD_DYNARR_DESC (detector_dynarr, &struct_detector_description),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
197 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
198 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
199
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
200 static const struct sized_memory_description detector_dynarr_description = {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
201 sizeof (detector_dynarr),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
202 detector_dynarr_description_1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
203 };
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
204
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
205 Lisp_Object Qcoding_systemp;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
206
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
207 Lisp_Object Qraw_text;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
208
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
209 Lisp_Object Qmnemonic, Qeol_type;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
210 Lisp_Object Qcr, Qcrlf, Qlf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
211 Lisp_Object Qeol_cr, Qeol_crlf, Qeol_lf;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
212 Lisp_Object Qpost_read_conversion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
213 Lisp_Object Qpre_write_conversion;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
214
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
215 Lisp_Object Qtranslation_table_for_decode;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
216 Lisp_Object Qtranslation_table_for_encode;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
217 Lisp_Object Qsafe_chars;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
218 Lisp_Object Qsafe_charsets;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
219 Lisp_Object Qmime_charset;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
220 Lisp_Object Qvalid_codes;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
221
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
222 Lisp_Object Qno_conversion;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
223 Lisp_Object Qconvert_eol;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
224 Lisp_Object Qescape_quoted;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
225 Lisp_Object Qencode, Qdecode;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
226
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
227 Lisp_Object Qconvert_eol_lf, Qconvert_eol_cr, Qconvert_eol_crlf;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
228 Lisp_Object Qconvert_eol_autodetect;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
229
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
230 Lisp_Object Qnear_certainty, Qquite_probable, Qsomewhat_likely;
1494
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
231 Lisp_Object Qslightly_likely;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
232 Lisp_Object Qas_likely_as_unlikely, Qsomewhat_unlikely, Qquite_improbable;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
233 Lisp_Object Qnearly_impossible;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
234
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
235 Lisp_Object Qdo_eol, Qdo_coding;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
236
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
237 Lisp_Object Qcanonicalize_after_coding;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
238
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
239 Lisp_Object QScoding_system_cookie;
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
240
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
241 Lisp_Object Qposix_charset_to_coding_system_hash;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
242
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
243 /* This is used to convert autodetected coding systems into existing
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
244 systems. For example, the chain undecided->convert-eol-autodetect may
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
245 have its separate parts detected as mswindows-multibyte and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
246 convert-eol-crlf, and the result needs to be mapped to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
247 mswindows-multibyte-dos. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
248 /* #### It's not clear we need this whole chain-canonicalize mechanism
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
249 any more. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
250 static Lisp_Object Vchain_canonicalize_hash_table;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
251
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
252 #ifdef HAVE_ZLIB
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
253 Lisp_Object Qgzip;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
254 #endif
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
255
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
256 /* Maps symbols (coding system names) to either coding system objects or
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
257 (for aliases) other names. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
258 static Lisp_Object Vcoding_system_hash_table;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
259
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
260 int enable_multibyte_characters;
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 EXFUN (Fcopy_coding_system, 2);
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
265 /************************************************************************/
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
266 /* Coding system object methods */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
267 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
268
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
269 static Lisp_Object
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
270 mark_coding_system (Lisp_Object obj)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
271 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
272 Lisp_Coding_System *codesys = XCODING_SYSTEM (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
273
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
274 #define MARKED_SLOT(x) mark_object (codesys->x);
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
275 #include "coding-system-slots.h"
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
276
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
277 MAYBE_CODESYSMETH (codesys, mark, (obj));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
278
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
279 return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
280 }
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 static void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
283 print_coding_system_properties (Lisp_Object obj, Lisp_Object printcharfun)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
284 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
285 Lisp_Coding_System *c = XCODING_SYSTEM (obj);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
286 print_internal (c->methods->type, printcharfun, 1);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
287 MAYBE_CODESYSMETH (c, print, (obj, printcharfun, 1));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
288 if (CODING_SYSTEM_EOL_TYPE (c) != EOL_AUTODETECT)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
289 write_fmt_string_lisp (printcharfun, " eol-type=%s",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
290 1, Fcoding_system_property (obj, Qeol_type));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
291 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
292
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
293 static void
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
294 print_coding_system (Lisp_Object obj, Lisp_Object printcharfun,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
295 int UNUSED (escapeflag))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
296 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
297 Lisp_Coding_System *c = XCODING_SYSTEM (obj);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
298 if (print_readably)
5142
f965e31a35f0 reduce lcrecord headers to 2 words, rename printing_unreadable_object
Ben Wing <ben@xemacs.org>
parents: 5128
diff changeset
299 printing_unreadable_lisp_object (obj, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
300
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
301 write_fmt_string_lisp (printcharfun, "#<coding-system %s ", 1, c->name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
302 print_coding_system_properties (obj, printcharfun);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
303 write_ascstring (printcharfun, ">");
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
304 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
305
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
306 /* Print an abbreviated version of a coding system (but still containing
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
307 all the information), for use within a coding system print method. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
308
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
309 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
310 print_coding_system_in_print_method (Lisp_Object cs, Lisp_Object printcharfun,
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
311 int UNUSED (escapeflag))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
312 {
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
313 write_fmt_string_lisp (printcharfun, "%s[", 1, XCODING_SYSTEM_NAME (cs));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
314 print_coding_system_properties (cs, printcharfun);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
315 write_ascstring (printcharfun, "]");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
316 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
317
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3142
diff changeset
318 #ifndef NEW_GC
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
319 static void
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5126
diff changeset
320 finalize_coding_system (Lisp_Object obj)
428
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 /* Since coding systems never go away, this function is not
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
323 necessary. But it would be necessary if we changed things
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
324 so that coding systems could go away. */
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5126
diff changeset
325 MAYBE_XCODESYSMETH (obj, finalize, (obj));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
326 }
3263
d674024a8674 [xemacs-hg @ 2006-02-27 16:29:00 by crestani]
crestani
parents: 3142
diff changeset
327 #endif /* not NEW_GC */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
328
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
329 static Bytecount
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5126
diff changeset
330 sizeof_coding_system (Lisp_Object obj)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
331 {
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5126
diff changeset
332 const Lisp_Coding_System *p = XCODING_SYSTEM (obj);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
333 return offsetof (Lisp_Coding_System, data) + p->methods->extra_data_size;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
334 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
335
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
336 static const struct memory_description coding_system_methods_description_1[]
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
337 = {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
338 { XD_LISP_OBJECT,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
339 offsetof (struct coding_system_methods, type) },
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
340 { XD_LISP_OBJECT,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
341 offsetof (struct coding_system_methods, predicate_symbol) },
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
342 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
343 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
344
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
345 const struct sized_memory_description coding_system_methods_description = {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
346 sizeof (struct coding_system_methods),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
347 coding_system_methods_description_1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
348 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
349
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
350 static const struct sized_memory_description coding_system_extra_description_map[] =
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
351 {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
352 { offsetof (Lisp_Coding_System, methods) },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
353 { offsetof (struct coding_system_methods, extra_description) },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
354 { -1 },
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
355 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
356
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
357 static const struct memory_description coding_system_description[] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
358 {
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
359 { XD_BLOCK_PTR, offsetof (Lisp_Coding_System, methods), 1,
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
360 { &coding_system_methods_description } },
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
361 #define MARKED_SLOT(x) { XD_LISP_OBJECT, offsetof (Lisp_Coding_System, x) },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
362 #define MARKED_SLOT_ARRAY(slot, size) \
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
363 { XD_LISP_OBJECT_ARRAY, offsetof (Lisp_Coding_System, slot), size },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
364 #include "coding-system-slots.h"
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
365 { XD_BLOCK_ARRAY, offsetof (Lisp_Coding_System, data), 1,
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
366 { coding_system_extra_description_map } },
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
367 { XD_END }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
368 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
369
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
370 static const struct memory_description coding_system_empty_extra_description_1[] =
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
371 {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
372 { XD_END }
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
373 };
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
374
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
375 const struct sized_memory_description coding_system_empty_extra_description = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
376 0, coding_system_empty_extra_description_1
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
377 };
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
378
5118
e0db3c197671 merge up to latest default branch, doesn't compile yet
Ben Wing <ben@xemacs.org>
parents: 5117 4690
diff changeset
379 DEFINE_DUMPABLE_SIZABLE_LISP_OBJECT ("coding-system", coding_system,
5124
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5120
diff changeset
380 mark_coding_system,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5120
diff changeset
381 print_coding_system,
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
382 IF_OLD_GC (finalize_coding_system),
5124
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5120
diff changeset
383 0, 0, coding_system_description,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5120
diff changeset
384 sizeof_coding_system,
623d57b7fbe8 separate regular and disksave finalization, print method fixes.
Ben Wing <ben@xemacs.org>
parents: 5120
diff changeset
385 Lisp_Coding_System);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
386
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
387 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
388 /* Creating coding systems */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
389 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
390
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
391 static struct coding_system_methods *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
392 decode_coding_system_type (Lisp_Object type, Error_Behavior errb)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
393 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
394 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
395
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
396 for (i = 0; i < Dynarr_length (the_coding_system_type_entry_dynarr); i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
397 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
398 if (EQ (type,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
399 Dynarr_at (the_coding_system_type_entry_dynarr, i).meths->type))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
400 return Dynarr_at (the_coding_system_type_entry_dynarr, i).meths;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
401 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
402
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
403 maybe_invalid_constant ("Invalid coding system type", type,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
404 Qcoding_system, errb);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
405
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
406 return 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
407 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
408
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
409 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
410 valid_coding_system_type_p (Lisp_Object type)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
411 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
412 return decode_coding_system_type (type, ERROR_ME_NOT) != 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
413 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
414
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
415 #ifdef MULE
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
416 static Lisp_Object Vdefault_query_coding_region_chartab_cache;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
417
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
418 /* Non-static because it's used in INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA. */
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
419 Lisp_Object
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
420 default_query_method (Lisp_Object codesys, struct buffer *buf,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
421 Charbpos end, int flags)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
422 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
423 Charbpos pos = BUF_PT (buf), fail_range_start, fail_range_end;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
424 Charbpos pos_byte = BYTE_BUF_PT (buf);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
425 Lisp_Object safe_charsets = XCODING_SYSTEM_SAFE_CHARSETS (codesys);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
426 Lisp_Object safe_chars = XCODING_SYSTEM_SAFE_CHARS (codesys),
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
427 result = Qnil;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
428 enum query_coding_failure_reasons failed_reason,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
429 previous_failed_reason = query_coding_succeeded;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
430
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
431 /* safe-charsets of t means the coding system can encode everything. */
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
432 if (EQ (Qnil, safe_chars))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
433 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
434 if (EQ (Qt, safe_charsets))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
435 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
436 return Qnil;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
437 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
438
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
439 /* If we've no information on what characters the coding system can
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
440 encode, give up. */
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
441 if (EQ (Qnil, safe_charsets) && EQ (Qnil, safe_chars))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
442 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
443 return Qunbound;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
444 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
445
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
446 safe_chars = Fgethash (safe_charsets,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
447 Vdefault_query_coding_region_chartab_cache,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
448 Qnil);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
449 if (NILP (safe_chars))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
450 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
451 safe_chars = Fmake_char_table (Qgeneric);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
452 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
453 EXTERNAL_LIST_LOOP_2 (safe_charset, safe_charsets)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
454 Fput_char_table (safe_charset, Qt, safe_chars);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
455 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
456
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
457 Fputhash (safe_charsets, safe_chars,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
458 Vdefault_query_coding_region_chartab_cache);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
459 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
460 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
461
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
462 if (flags & QUERY_METHOD_HIGHLIGHT &&
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
463 /* If we're being called really early, live without highlights getting
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
464 cleared properly: */
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
465 !(UNBOUNDP (XSYMBOL (Qquery_coding_clear_highlights)->function)))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
466 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
467 /* It's okay to call Lisp here, the only non-stack object we may have
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
468 allocated up to this point is safe_chars, and that's
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
469 reachable from its entry in
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
470 Vdefault_query_coding_region_chartab_cache */
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
471 call3 (Qquery_coding_clear_highlights, make_fixnum (pos), make_fixnum (end),
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
472 wrap_buffer (buf));
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
473 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
474
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
475 while (pos < end)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
476 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
477 Ichar ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
478 if (!EQ (Qnil, get_char_table (ch, safe_chars)))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
479 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
480 pos++;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
481 INC_BYTEBPOS (buf, pos_byte);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
482 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
483 else
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
484 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
485 fail_range_start = pos;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
486 while ((pos < end) &&
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
487 (EQ (Qnil, get_char_table (ch, safe_chars))
4839
5f1c6ca4d05e fix bad change to default_query_method, rewrite conditional for more correctness
Ben Wing <ben@xemacs.org>
parents: 4830
diff changeset
488 && (failed_reason = query_coding_unencodable,
5f1c6ca4d05e fix bad change to default_query_method, rewrite conditional for more correctness
Ben Wing <ben@xemacs.org>
parents: 4830
diff changeset
489 (previous_failed_reason == query_coding_succeeded
5f1c6ca4d05e fix bad change to default_query_method, rewrite conditional for more correctness
Ben Wing <ben@xemacs.org>
parents: 4830
diff changeset
490 || previous_failed_reason == failed_reason))))
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
491 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
492 pos++;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
493 INC_BYTEBPOS (buf, pos_byte);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
494 ch = BYTE_BUF_FETCH_CHAR (buf, pos_byte);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
495 previous_failed_reason = failed_reason;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
496 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
497
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
498 if (fail_range_start == pos)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
499 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
500 /* The character can actually be encoded; move on. */
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
501 pos++;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
502 INC_BYTEBPOS (buf, pos_byte);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
503 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
504 else
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
505 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
506 assert (previous_failed_reason == query_coding_unencodable);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
507
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
508 if (flags & QUERY_METHOD_ERRORP)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
509 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
510 signal_error_2
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
511 (Qtext_conversion_error,
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
512 "Cannot encode using coding system",
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
513 make_string_from_buffer (buf, fail_range_start,
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
514 pos - fail_range_start),
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
515 XCODING_SYSTEM_NAME (codesys));
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
516 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
517
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
518 if (NILP (result))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
519 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
520 result = Fmake_range_table (Qstart_closed_end_open);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
521 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
522
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
523 fail_range_end = pos;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
524
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
525 Fput_range_table (make_fixnum (fail_range_start),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
526 make_fixnum (fail_range_end),
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
527 Qunencodable,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
528 result);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
529 previous_failed_reason = query_coding_succeeded;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
530
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
531 if (flags & QUERY_METHOD_HIGHLIGHT)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
532 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
533 Lisp_Object extent
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
534 = Fmake_extent (make_fixnum (fail_range_start),
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
535 make_fixnum (fail_range_end),
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
536 wrap_buffer (buf));
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
537
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
538 Fset_extent_priority
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
539 (extent, make_fixnum (2 + mouse_highlight_priority));
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
540 Fset_extent_face (extent, Qquery_coding_warning_face);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
541 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
542 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
543 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
544 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
545
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
546 return result;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
547 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
548 #else
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
549 Lisp_Object
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
550 default_query_method (Lisp_Object UNUSED (codesys),
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
551 struct buffer * UNUSED (buf),
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
552 Charbpos UNUSED (end), int UNUSED (flags))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
553 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
554 return Qnil;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
555 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
556 #endif /* defined MULE */
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
557
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
558 DEFUN ("valid-coding-system-type-p", Fvalid_coding_system_type_p, 1, 1, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
559 Given a CODING-SYSTEM-TYPE, return non-nil if it is valid.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
560 Valid types depend on how XEmacs was compiled but may include
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 3024
diff changeset
561 `undecided', `chain', `integer', `ccl', `iso2022', `big5', `shift-jis',
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 3024
diff changeset
562 `utf-16', `ucs-4', `utf-8', etc.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
563 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
564 (coding_system_type))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
565 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
566 return valid_coding_system_type_p (coding_system_type) ? Qt : Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
567 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
568
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
569 DEFUN ("coding-system-type-list", Fcoding_system_type_list, 0, 0, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
570 Return a list of valid coding system types.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
571 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
572 ())
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
573 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
574 return Fcopy_sequence (Vcoding_system_type_list);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
575 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
576
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
577 void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
578 add_entry_to_coding_system_type_list (struct coding_system_methods *meths)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
579 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
580 struct coding_system_type_entry entry;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
581
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
582 entry.meths = meths;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
583 Dynarr_add (the_coding_system_type_entry_dynarr, entry);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
584 Vcoding_system_type_list = Fcons (meths->type, Vcoding_system_type_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
585 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
586
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
587 DEFUN ("coding-system-p", Fcoding_system_p, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
588 Return t if OBJECT is a coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
589 A coding system is an object that defines how text containing multiple
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
590 character sets is encoded into a stream of (typically 8-bit) bytes.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
591 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
592 characters (which may be from multiple charsets) when the text is read
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
593 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
594 same format when it is written out to a file or process.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
595
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
596 For example, many ISO2022-compliant coding systems (such as Compound
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
597 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
598 use escape sequences to switch between different charsets -- Japanese
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
599 Kanji, for example, is invoked with "ESC $ ( B"; ASCII is invoked
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
600 with "ESC ( B"; and Cyrillic is invoked with "ESC - L". See
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
601 `make-coding-system' for more information.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
602
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
603 Coding systems are normally identified using a symbol, and the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
604 symbol is accepted in place of the actual coding system object whenever
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
605 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
606 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
607 (object))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
608 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
609 return CODING_SYSTEMP (object) ? Qt : Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
610 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
611
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
612 static Lisp_Object
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
613 find_coding_system (Lisp_Object coding_system_or_name,
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
614 int do_autoloads)
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
615 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
616 Lisp_Object lookup;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
617
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
618 if (NILP (coding_system_or_name))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
619 coding_system_or_name = Qbinary;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
620 else if (CODING_SYSTEMP (coding_system_or_name))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
621 return coding_system_or_name;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
622 else
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
623 CHECK_SYMBOL (coding_system_or_name);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
624
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
625 while (1)
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
626 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
627 lookup =
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
628 Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
629
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
630 if (CONSP (lookup) && do_autoloads)
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
631 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
632 struct gcpro gcpro1;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
633 int length;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
634 DECLARE_EISTRING (desired_base);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
635 DECLARE_EISTRING (warning_info);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
636
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
637 eicpy_lstr (desired_base, XSYMBOL_NAME (coding_system_or_name));
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
638
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
639 /* Work out the name of the base coding system. */
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
640 length = eilen (desired_base);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
641 if (length > (int)(sizeof ("-unix") - 1))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
642 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
643 if (0 == qxestrcmp ((UAscbyte *)"-unix", (eidata (desired_base))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
644 + (length - (sizeof ("-unix") - 1))))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
645 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
646 eidel (desired_base, length - (sizeof ("-unix") - 1),
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
647 -1, 5, 5);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
648 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
649 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
650 else if (length > (int)(sizeof ("-dos") - 1))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
651 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
652 if ((0 == qxestrcmp ((UAscbyte *)"-dos", (eidata (desired_base))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
653 + (length - (sizeof ("-dos") - 1)))) ||
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
654 (0 == qxestrcmp ((UAscbyte *)"-mac", (eidata (desired_base))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
655 + (length - (sizeof ("-mac") - 1)))))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
656 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
657 eidel (desired_base, length - (sizeof ("-dos") - 1), -1,
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
658 4, 4);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
659 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
660 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
661
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
662 coding_system_or_name = intern_istring (eidata (desired_base));
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
663
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
664 /* Remove this coding system and its subsidiary coding
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
665 systems from the hash, to avoid calling this code recursively. */
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
666 Fremhash (coding_system_or_name, Vcoding_system_hash_table);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
667 Fremhash (add_suffix_to_symbol(coding_system_or_name, "-unix"),
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
668 Vcoding_system_hash_table);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
669 Fremhash (add_suffix_to_symbol(coding_system_or_name, "-dos"),
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
670 Vcoding_system_hash_table);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
671 Fremhash (add_suffix_to_symbol(coding_system_or_name, "-mac"),
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
672 Vcoding_system_hash_table);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
673
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
674 eicpy_ascii (warning_info, "Error autoloading coding system ");
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
675 eicat_lstr (warning_info, XSYMBOL_NAME (coding_system_or_name));
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
676
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
677 /* Keep around the form so it doesn't disappear from under
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
678 #'eval's feet. */
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
679 GCPRO1 (lookup);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
680 call1_trapping_problems ((const CIbyte *) eidata (warning_info),
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
681 Qeval, lookup, 0);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
682 UNGCPRO;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
683
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
684 lookup =
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
685 Fgethash (coding_system_or_name, Vcoding_system_hash_table, Qnil);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
686 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
687
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
688 if (CODING_SYSTEMP (lookup) || NILP (lookup))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
689 return lookup;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
690
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
691 coding_system_or_name = lookup;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
692 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
693 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
694
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
695 DEFUN ("find-coding-system", Ffind_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
696 Retrieve the coding system of the given name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
698 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
699 returned. Otherwise, CODING-SYSTEM-OR-NAME should be a symbol.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
700 If there is no such coding system, nil is returned. Otherwise the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
701 associated coding system object is returned.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
702 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
703 (coding_system_or_name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
704 {
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
705 return find_coding_system(coding_system_or_name, 1);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
706 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
707
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
708 DEFUN ("autoload-coding-system", Fautoload_coding_system, 2, 2, 0, /*
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
709 Define SYMBOL as a coding-system that is loaded on demand.
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
710
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
711 FORM is a form to evaluate to define the coding-system.
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
712 */
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
713 (symbol, form))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
714 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
715 Lisp_Object lookup;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
716
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
717 CHECK_SYMBOL (symbol);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
718 CHECK_CONS (form);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
719
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
720 lookup = find_coding_system (symbol, 0);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
721
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
722 if (!NILP (lookup) &&
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
723 /* Allow autoloads to be redefined. */
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
724 !CONSP (lookup))
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
725 {
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
726 invalid_operation ("Cannot redefine existing coding system",
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
727 symbol);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
728 }
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
729
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
730 Fputhash (symbol, form, Vcoding_system_hash_table);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
731 Fputhash (add_suffix_to_symbol(symbol, "-unix"), form,
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
732 Vcoding_system_hash_table);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
733 Fputhash (add_suffix_to_symbol(symbol, "-dos"), form,
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
734 Vcoding_system_hash_table);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
735 Fputhash (add_suffix_to_symbol(symbol, "-mac"), form,
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
736 Vcoding_system_hash_table);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
737
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
738 /* Tell the POSIX locale infrastructure about this coding system (though
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
739 unfortunately it'll be too late for the startup locale sniffing. */
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
740 if (!UNBOUNDP (Qposix_charset_to_coding_system_hash))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
741 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
742 Lisp_Object val = Fsymbol_value (Qposix_charset_to_coding_system_hash);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
743 DECLARE_EISTRING (minimal_name);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
744 Ibyte *full_name;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
745 int len = XSTRING_LENGTH (XSYMBOL_NAME (symbol)), i;
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
746
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
747 if (!NILP (val))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
748 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
749 full_name = XSTRING_DATA (XSYMBOL_NAME (symbol));
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
750 for (i = 0; i < len; ++i)
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
751 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
752 if (full_name[i] >= '0' && full_name[i] <= '9')
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
753 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
754 eicat_ch (minimal_name, full_name[i]);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
755 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
756 else if (full_name[i] >= 'a' && full_name[i] <= 'z')
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
757 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
758 eicat_ch (minimal_name, full_name[i]);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
759 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
760 else if (full_name[i] >= 'A' && full_name[i] <= 'Z')
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
761 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
762 eicat_ch (minimal_name, full_name[i] +
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
763 ('a' - 'A'));
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
764 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
765 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
766
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
767 if (eilen (minimal_name))
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
768 {
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
769 CHECK_HASH_TABLE (val);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
770 Fputhash (eimake_string(minimal_name), symbol, val);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
771 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
772 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
773 }
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
774
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
775 return Qt;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
776 }
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 DEFUN ("get-coding-system", Fget_coding_system, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
779 Retrieve the coding system of the given name.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
780 Same as `find-coding-system' except that if there is no such
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
781 coding system, an error is signaled instead of returning nil.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
782 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
783 (name))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
784 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
785 Lisp_Object coding_system = Ffind_coding_system (name);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
786
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
787 if (NILP (coding_system))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
788 invalid_argument ("No such coding system", name);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
789 return coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
790 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
791
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
792 int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
793 coding_system_is_binary (Lisp_Object coding_system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
794 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
795 Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
796 return
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
797 (EQ (CODING_SYSTEM_TYPE (cs), Qno_conversion) &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
798 CODING_SYSTEM_EOL_TYPE (cs) == EOL_LF &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
799 EQ (CODING_SYSTEM_POST_READ_CONVERSION (cs), Qnil) &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
800 EQ (CODING_SYSTEM_PRE_WRITE_CONVERSION (cs), Qnil));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
801 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
802
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
803 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
804 coding_system_real_canonical (Lisp_Object cs)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
805 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
806 if (!NILP (XCODING_SYSTEM_CANONICAL (cs)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
807 return XCODING_SYSTEM_CANONICAL (cs);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
808 return cs;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
809 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
810
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
811 /* Return true if coding system is of the "standard" type that decodes
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
812 bytes into characters (suitable for decoding a text file). */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
813 int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
814 coding_system_is_for_text_file (Lisp_Object coding_system)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
815 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
816 return (XCODESYSMETH_OR_GIVEN
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
817 (coding_system, conversion_end_type,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
818 (coding_system_real_canonical (coding_system)),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
819 DECODES_BYTE_TO_CHARACTER) ==
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
820 DECODES_BYTE_TO_CHARACTER);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
821 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
822
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
823 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
824 decoding_source_sink_type_is_char (Lisp_Object cs, enum source_or_sink sex)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
825 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
826 enum source_sink_type type =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
827 XCODESYSMETH_OR_GIVEN (cs, conversion_end_type,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
828 (coding_system_real_canonical (cs)),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
829 DECODES_BYTE_TO_CHARACTER);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
830 if (sex == CODING_SOURCE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
831 return (type == DECODES_CHARACTER_TO_CHARACTER ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
832 type == DECODES_CHARACTER_TO_BYTE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
833 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
834 return (type == DECODES_CHARACTER_TO_CHARACTER ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
835 type == DECODES_BYTE_TO_CHARACTER);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
836 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
837
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
838 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
839 encoding_source_sink_type_is_char (Lisp_Object cs, enum source_or_sink sex)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
840 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
841 return decoding_source_sink_type_is_char (cs,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
842 /* Sex change */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
843 sex == CODING_SOURCE ?
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
844 CODING_SINK : CODING_SOURCE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
845 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
846
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
847 /* Like Ffind_coding_system() but check that the coding system is of the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
848 "standard" type that decodes bytes into characters (suitable for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
849 decoding a text file), and if not, returns an appropriate wrapper that
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
850 does. Also, if EOL_WRAP is non-zero, check whether this coding system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
851 wants EOL auto-detection, and if so, wrap with a convert-eol coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
852 system to do this. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
853
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
854 Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
855 find_coding_system_for_text_file (Lisp_Object name, int eol_wrap)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
856 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
857 Lisp_Object coding_system = Ffind_coding_system (name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
858 Lisp_Object wrapper = coding_system;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
859
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
860 if (NILP (coding_system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
861 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
862 if (!coding_system_is_for_text_file (coding_system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
863 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
864 wrapper = XCODING_SYSTEM_TEXT_FILE_WRAPPER (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
865 if (NILP (wrapper))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
866 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
867 Lisp_Object chain;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
868 if (!decoding_source_sink_type_is_char (coding_system, CODING_SINK))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
869 chain = list2 (coding_system, Qbinary);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
870 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
871 chain = list1 (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
872 if (decoding_source_sink_type_is_char (coding_system, CODING_SOURCE))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
873 chain = Fcons (Qbinary, chain);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
874 wrapper =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
875 make_internal_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
876 (coding_system,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
877 "internal-text-file-wrapper",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
878 Qchain,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
879 Qunbound, list4 (Qchain, chain,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
880 Qcanonicalize_after_coding, coding_system));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
881 XCODING_SYSTEM_TEXT_FILE_WRAPPER (coding_system) = wrapper;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
882 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
883 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
884
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
885 if (!eol_wrap || XCODING_SYSTEM_EOL_TYPE (coding_system) != EOL_AUTODETECT)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
886 return wrapper;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
887
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
888 coding_system = wrapper;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
889 wrapper = XCODING_SYSTEM_AUTO_EOL_WRAPPER (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
890 if (!NILP (wrapper))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
891 return wrapper;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
892 wrapper =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
893 make_internal_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
894 (coding_system,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
895 "internal-auto-eol-wrapper",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
896 Qundecided, Qunbound,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
897 list4 (Qcoding_system, coding_system,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
898 Qdo_eol, Qt));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
899 XCODING_SYSTEM_AUTO_EOL_WRAPPER (coding_system) = wrapper;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
900 return wrapper;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
901 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
902
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
903 /* Like Fget_coding_system() but verify that the coding system is of the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
904 "standard" type that decodes bytes into characters (suitable for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
905 decoding a text file), and if not, returns an appropriate wrapper that
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
906 does. Also, if EOL_WRAP is non-zero, check whether this coding system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
907 wants EOL auto-detection, and if so, wrap with a convert-eol coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
908 system to do this. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
909
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
910 Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
911 get_coding_system_for_text_file (Lisp_Object name, int eol_wrap)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
912 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
913 Lisp_Object coding_system = find_coding_system_for_text_file (name,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
914 eol_wrap);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
915 if (NILP (coding_system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
916 invalid_argument ("No such coding system", name);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
917 return coding_system;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
918 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
919
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
920 /* We store the coding systems in hash tables with the names as the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
921 key and the actual coding system object as the value. Occasionally
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
922 we need to use them in a list format. These routines provide us
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
923 with that. */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
924 struct coding_system_list_closure
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 Lisp_Object *coding_system_list;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
927 int normal;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
928 int internal;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
929 };
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
930
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
931 static int
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
932 add_coding_system_to_list_mapper (Lisp_Object key, Lisp_Object value,
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
933 void *coding_system_list_closure)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
934 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
935 /* This function can GC */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
936 struct coding_system_list_closure *cscl =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
937 (struct coding_system_list_closure *) coding_system_list_closure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
938 Lisp_Object *coding_system_list = cscl->coding_system_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
939
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
940 /* We can't just use VALUE because KEY might be an alias, and we need
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
941 the real coding system object.
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
942
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
943 Autoloaded coding systems have conses for their values, and can't be
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
944 internal coding systems, or coding system aliases. */
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
945 if (CONSP (value) ||
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
946 (XCODING_SYSTEM (Ffind_coding_system (key))->internal_p ?
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
947 cscl->internal : cscl->normal))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
948 *coding_system_list = Fcons (key, *coding_system_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
949 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
950 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
951
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
952 /* #### should we specify a conventional for "all coding systems"? */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
953 DEFUN ("coding-system-list", Fcoding_system_list, 0, 1, 0, /*
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
954 Return a list of the names of all defined coding systems.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
955 If INTERNAL is nil, only the normal (non-internal) coding systems are
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
956 included. (Internal coding systems are created for various internal
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
957 purposes, such as implementing EOL types of CRLF and CR; generally, you do
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
958 not want to see these.) If it is t, only the internal coding systems are
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
959 included. If it is any other non-nil value both normal and internal are
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
960 included.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
961 */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
962 (internal))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
963 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
964 Lisp_Object coding_system_list = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
965 struct gcpro gcpro1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
966 struct coding_system_list_closure coding_system_list_closure;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
967
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
968 GCPRO1 (coding_system_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
969 coding_system_list_closure.coding_system_list = &coding_system_list;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
970 coding_system_list_closure.normal = !EQ (internal, Qt);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
971 coding_system_list_closure.internal = !NILP (internal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
972 elisp_maphash (add_coding_system_to_list_mapper, Vcoding_system_hash_table,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
973 &coding_system_list_closure);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
974 UNGCPRO;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
975
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
976 return coding_system_list;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
977 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
978
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
979 DEFUN ("coding-system-name", Fcoding_system_name, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
980 Return the name of the given coding system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
981 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
982 (coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
983 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
984 coding_system = Fget_coding_system (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
985 return XCODING_SYSTEM_NAME (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
986 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
987
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
988 static Lisp_Coding_System *
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
989 allocate_coding_system (struct coding_system_methods *codesys_meths,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
990 Bytecount data_size,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
991 Lisp_Object name)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
992 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
993 Bytecount total_size = offsetof (Lisp_Coding_System, data) + data_size;
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
994 Lisp_Object obj = ALLOC_SIZED_LISP_OBJECT (total_size, coding_system);
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
995 Lisp_Coding_System *codesys = XCODING_SYSTEM (obj);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
996
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
997 codesys->methods = codesys_meths;
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
998 #define MARKED_SLOT(x) codesys->x = Qnil;
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
999 #include "coding-system-slots.h"
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1000
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1001 CODING_SYSTEM_EOL_TYPE (codesys) = EOL_LF;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1002 CODING_SYSTEM_NAME (codesys) = name;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1003
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1004 MAYBE_CODESYSMETH (codesys, init, (wrap_coding_system (codesys)));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1005
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1006 return codesys;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1007 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1008
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1009 static enum eol_type
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1010 symbol_to_eol_type (Lisp_Object symbol)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1011 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1012 CHECK_SYMBOL (symbol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1013 if (NILP (symbol)) return EOL_AUTODETECT;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1014 if (EQ (symbol, Qlf)) return EOL_LF;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1015 if (EQ (symbol, Qcrlf)) return EOL_CRLF;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1016 if (EQ (symbol, Qcr)) return EOL_CR;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1017
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1018 invalid_constant ("Unrecognized eol type", symbol);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1019 RETURN_NOT_REACHED (EOL_AUTODETECT);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1020 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1021
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1022 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1023 eol_type_to_symbol (enum eol_type type)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1024 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1025 switch (type)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1026 {
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
1027 default: ABORT ();
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1028 case EOL_LF: return Qlf;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1029 case EOL_CRLF: return Qcrlf;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1030 case EOL_CR: return Qcr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1031 case EOL_AUTODETECT: return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1032 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1033 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1034
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1035 struct subsidiary_type
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1036 {
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
1037 const Ascbyte *extension;
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
1038 const Ascbyte *mnemonic_ext;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1039 enum eol_type eol;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1040 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1041
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1042 static struct subsidiary_type coding_subsidiary_list[] =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1043 { { "-unix", "", EOL_LF },
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1044 { "-dos", ":T", EOL_CRLF },
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1045 { "-mac", ":t", EOL_CR } };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1046
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1047 /* kludge */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1048 static void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1049 setup_eol_coding_systems (Lisp_Object codesys)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1050 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
1051 int len = XSTRING_LENGTH (XSYMBOL (XCODING_SYSTEM_NAME (codesys))->name);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
1052 Ibyte *codesys_name = alloca_ibytes (len + 7);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1053 int mlen = -1;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
1054 Ibyte *codesys_mnemonic = 0;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1055 Lisp_Object codesys_name_sym, sub_codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1056 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1057
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1058 memcpy (codesys_name,
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
1059 XSTRING_DATA (XSYMBOL (XCODING_SYSTEM_NAME (codesys))->name), len);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1060
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1061 if (STRINGP (XCODING_SYSTEM_MNEMONIC (codesys)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1062 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1063 mlen = XSTRING_LENGTH (XCODING_SYSTEM_MNEMONIC (codesys));
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
1064 codesys_mnemonic = alloca_ibytes (mlen + 7);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1065 memcpy (codesys_mnemonic,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1066 XSTRING_DATA (XCODING_SYSTEM_MNEMONIC (codesys)), mlen);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1067 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1068
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1069 /* Create three "subsidiary" coding systems, decoding data encoded using
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1070 each of the three EOL types. We do this for each subsidiary by
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1071 copying the original coding system, setting the EOL type
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1072 appropriately, and setting the CANONICAL member of the new coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1073 system to be a chain consisting of the original coding system followed
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1074 by a convert-eol coding system to do the EOL decoding. For EOL type
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1075 LF, however, we don't need any decoding, so we skip creating a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1076 CANONICAL.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1077
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1078 If the original coding system is not a text-type coding system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1079 (decodes byte->char), we need to coerce it to one by the appropriate
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1080 wrapping in CANONICAL. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1081
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1082 for (i = 0; i < countof (coding_subsidiary_list); i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1083 {
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
1084 const Ascbyte *extension = coding_subsidiary_list[i].extension;
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
1085 const Ascbyte *mnemonic_ext = coding_subsidiary_list[i].mnemonic_ext;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1086 enum eol_type eol = coding_subsidiary_list[i].eol;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1087
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
1088 qxestrcpy_ascii (codesys_name + len, extension);
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1089 codesys_name_sym = intern_istring (codesys_name);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1090 if (mlen != -1)
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
1091 qxestrcpy_ascii (codesys_mnemonic + mlen, mnemonic_ext);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1092
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1093 sub_codesys = Fcopy_coding_system (codesys, codesys_name_sym);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1094 if (mlen != -1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1095 XCODING_SYSTEM_MNEMONIC (sub_codesys) =
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1096 build_istring (codesys_mnemonic);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1097
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1098 if (eol != EOL_LF)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1099 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1100 Lisp_Object chain = list2 (get_coding_system_for_text_file
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1101 (codesys, 0),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1102 eol == EOL_CR ? Qconvert_eol_cr :
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1103 Qconvert_eol_crlf);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1104 Lisp_Object canon =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1105 make_internal_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1106 (sub_codesys, "internal-subsidiary-eol-wrapper",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1107 Qchain, Qunbound,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1108 mlen != -1 ?
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1109 list6 (Qmnemonic, build_istring (codesys_mnemonic),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1110 Qchain, chain,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1111 Qcanonicalize_after_coding, sub_codesys) :
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1112 list4 (Qchain, chain,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1113 Qcanonicalize_after_coding, sub_codesys));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1114 XCODING_SYSTEM_CANONICAL (sub_codesys) = canon;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1115 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1116 XCODING_SYSTEM_EOL_TYPE (sub_codesys) = eol;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1117 XCODING_SYSTEM_SUBSIDIARY_PARENT (sub_codesys) = codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1118 XCODING_SYSTEM (codesys)->eol[eol] = sub_codesys;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1119 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1120 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1121
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1122 DEFUN ("coding-system-canonical-name-p", Fcoding_system_canonical_name_p,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1123 1, 1, 0, /*
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1124 Return t if OBJECT names a coding system, and is not a coding system alias.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1125 */
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1126 (object))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1127 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1128 return CODING_SYSTEMP (Fgethash (object, Vcoding_system_hash_table, Qnil))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1129 ? Qt : Qnil;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1130 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1131
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1132 /* Basic function to create new coding systems. For `make-coding-system',
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1133 NAME-OR-EXISTING is the NAME argument, PREFIX is null, and TYPE,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1134 DESCRIPTION, and PROPS are the same. All created coding systems are put
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1135 in a hash table indexed by NAME.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1136
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1137 If PREFIX is a string, NAME-OR-EXISTING should specify an existing
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1138 coding system (or nil), and an internal coding system will be created.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1139 The name of the coding system will be constructed by combining PREFIX
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1140 with the name of the existing coding system (if given), and a number
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1141 will be appended to insure uniqueness. In such a case, if Qunbound is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1142 given for DESCRIPTION, the description gets created based on the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1143 generated name. Also, if no mnemonic is given in the properties list, a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1144 mnemonic is created based on the generated name.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1145
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1146 For internal coding systems, the coding system is marked as internal
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1147 (see `coding-system-list'), and no subsidiaries will be created or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1148 eol-wrapping will happen. Otherwise:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1149
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1150 -- if the eol-type property is `lf' or t, the coding system is merely
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1151 created and returned. (For t, the coding system will be wrapped with
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1152 an EOL autodetector when it's used to read a file.)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1153
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1154 -- if eol-type is `crlf' or `cr', after the coding system object is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1155 created, it will be wrapped in a chain with the appropriate
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1156 convert-eol coding system (either `convert-eol-crlf' or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1157 `convert-eol-cr'), so that CRLF->LF or CR->LF conversion is done at
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1158 decoding time, and the opposite at encoding time. The resulting
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1159 chain becomes the CANONICAL field of the coding system object.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1160
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1161 -- if eol-type is nil or omitted, "subsidiaries" are generated: Three
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1162 coding systems where the original coding system (before wrapping with
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1163 convert-eol-autodetect) is either unwrapped or wrapped with
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1164 convert-eol-crlf or convert-eol-cr, respectively, so that coding systems
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1165 to handle LF, CRLF, and CR end-of-line indicators are created. (This
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1166 crazy crap is based on existing behavior in other Mule versions,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1167 including FSF Emacs.)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1168 */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1169
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1170 static Lisp_Object
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
1171 make_coding_system_1 (Lisp_Object name_or_existing, const Ascbyte *prefix,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1172 Lisp_Object type, Lisp_Object description,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1173 Lisp_Object props)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1174 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1175 Lisp_Coding_System *cs;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1176 int need_to_setup_eol_systems = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1177 enum eol_type eol_wrapper = EOL_AUTODETECT;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1178 struct coding_system_methods *meths;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1179 Lisp_Object csobj;
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1180 Lisp_Object defmnem = Qnil, aliases = Qnil;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1181
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1182 if (NILP (type))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1183 type = Qundecided;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1184 meths = decode_coding_system_type (type, ERROR_ME);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1185
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1186 if (prefix)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1187 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
1188 Ibyte *newname =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1189 emacs_sprintf_malloc (NULL, "%s-%s-%d",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1190 prefix,
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
1191 NILP (name_or_existing) ? (Ibyte *) "nil" :
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1192 XSTRING_DATA (Fsymbol_name (XCODING_SYSTEM_NAME
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1193 (name_or_existing))),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1194 ++coding_system_tick);
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1195 name_or_existing = intern_istring (newname);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
1196 xfree (newname);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1197
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1198 if (UNBOUNDP (description))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1199 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1200 newname =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1201 emacs_sprintf_malloc
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1202 (NULL, "For Internal Use (%s)",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1203 XSTRING_DATA (Fsymbol_name (name_or_existing)));
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1204 description = build_istring (newname);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
1205 xfree (newname);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1206 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1207
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1208 newname = emacs_sprintf_malloc (NULL, "Int%d", coding_system_tick);
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1209 defmnem = build_istring (newname);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
1210 xfree (newname);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1211 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1212 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1213 CHECK_SYMBOL (name_or_existing);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1214
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
1215 /* See is there an entry for name_or_existing in the defined coding system
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
1216 hash table. */
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
1217 csobj = find_coding_system (name_or_existing, 0);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
1218 /* Error if it's there and not an autoload form. */
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
1219 if (!NILP (csobj) && !CONSP (csobj))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1220 invalid_operation ("Cannot redefine existing coding system",
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
1221 name_or_existing);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1222
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1223 cs = allocate_coding_system (meths, meths->extra_data_size,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1224 name_or_existing);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
1225 csobj = wrap_coding_system (cs);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1226
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1227 cs->internal_p = !!prefix;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1228
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1229 if (NILP (description))
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
1230 description = build_ascstring ("");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1231 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1232 CHECK_STRING (description);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1233 CODING_SYSTEM_DESCRIPTION (cs) = description;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1234
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1235 if (!NILP (defmnem))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1236 CODING_SYSTEM_MNEMONIC (cs) = defmnem;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1237
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1238 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1239 EXTERNAL_PROPERTY_LIST_LOOP_3 (key, value, props)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1240 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1241 int recognized = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1242
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1243 if (EQ (key, Qmnemonic))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1244 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1245 if (!NILP (value))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1246 CHECK_STRING (value);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1247 CODING_SYSTEM_MNEMONIC (cs) = value;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1248 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1249
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1250 else if (EQ (key, Qdocumentation))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1251 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1252 if (!NILP (value))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1253 CHECK_STRING (value);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1254 CODING_SYSTEM_DOCUMENTATION (cs) = value;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1255 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1256
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1257 else if (EQ (key, Qeol_type))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1258 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1259 need_to_setup_eol_systems = NILP (value);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1260 if (EQ (value, Qt))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1261 value = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1262 eol_wrapper = symbol_to_eol_type (value);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1263 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1264
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1265 else if (EQ (key, Qpost_read_conversion))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1266 CODING_SYSTEM_POST_READ_CONVERSION (cs) = value;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1267 else if (EQ (key, Qpre_write_conversion))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1268 CODING_SYSTEM_PRE_WRITE_CONVERSION (cs) = value;
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1269 else if (EQ (key, Qaliases))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1270 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1271 EXTERNAL_LIST_LOOP_2 (alias, value)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1272 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1273 CHECK_SYMBOL (alias);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1274
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1275 if (!NILP (Fcoding_system_canonical_name_p (alias)))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1276 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1277 invalid_change ("Symbol is the canonical name of a "
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1278 "coding system and cannot be redefined",
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1279 alias);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1280 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1281 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1282 aliases = value;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1283 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1284 /* FSF compatibility */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1285 else if (EQ (key, Qtranslation_table_for_decode))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1286 ;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1287 else if (EQ (key, Qtranslation_table_for_encode))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1288 ;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1289 else if (EQ (key, Qsafe_chars))
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1290 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1291 CHECK_CHAR_TABLE (value);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1292 CODING_SYSTEM_SAFE_CHARS (cs) = value;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1293 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1294 else if (EQ (key, Qsafe_charsets))
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1295 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1296 if (!EQ (Qt, value)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1297 /* Would be nice to actually do this check, but there are
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1298 some order conflicts with japanese.el and
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1299 mule-coding.el */
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1300 && 0)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1301 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1302 #ifdef MULE
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1303 EXTERNAL_LIST_LOOP_2 (safe_charset, value)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1304 CHECK_CHARSET (Ffind_charset (safe_charset));
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1305 #endif
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1306 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1307
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1308 CODING_SYSTEM_SAFE_CHARSETS (cs) = value;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1309 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1310 else if (EQ (key, Qcategory))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1311 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1312 Fput (name_or_existing, intern ("coding-system-property"),
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1313 Fplist_put (Fget (name_or_existing,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1314 intern ("coding-system-property"),
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1315 Qnil),
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1316 Qcategory, value));
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1317 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1318 else if (EQ (key, Qmime_charset))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1319 ;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1320 else if (EQ (key, Qvalid_codes))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1321 ;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1322 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1323 recognized = CODESYSMETH_OR_GIVEN (cs, putprop,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1324 (csobj, key, value), 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1325
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1326 if (!recognized)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1327 invalid_constant ("Unrecognized property", key);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1328 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1329 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1330
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1331 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1332 XCODING_SYSTEM_CANONICAL (csobj) =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1333 CODESYSMETH_OR_GIVEN (cs, canonicalize, (csobj), Qnil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1334 XCODING_SYSTEM_EOL_TYPE (csobj) = EOL_AUTODETECT; /* for copy-coding-system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1335 below */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1336
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
1337 Fputhash (name_or_existing, csobj, Vcoding_system_hash_table);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
1338
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1339 if (need_to_setup_eol_systems && !cs->internal_p)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1340 setup_eol_coding_systems (csobj);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1341 else if (eol_wrapper == EOL_CR || eol_wrapper == EOL_CRLF)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1342 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1343 /* If a specific eol-type (other than LF) was specified, we handle
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1344 this by converting the coding system into a chain that wraps the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1345 coding system along with a convert-eol system after it, in
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1346 exactly that same switcheroo fashion that the normal
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1347 canonicalize method works -- BUT we will run into a problem if
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1348 we do it the obvious way, because when `chain' creates its
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1349 substreams, the substream containing the coding system we're
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1350 creating will have canonicalization expansion done on it,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1351 leading to infinite recursion. So we have to generate a new,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1352 internal coding system with the previous value of CANONICAL. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
1353 Ibyte *newname =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1354 emacs_sprintf_malloc
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1355 (NULL, "internal-eol-copy-%s-%d",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1356 XSTRING_DATA (Fsymbol_name (name_or_existing)),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1357 ++coding_system_tick);
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
1358 Lisp_Object newnamesym = intern_istring (newname);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1359 Lisp_Object copied = Fcopy_coding_system (csobj, newnamesym);
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
1360 xfree (newname);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1361
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1362 XCODING_SYSTEM_CANONICAL (csobj) =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1363 make_internal_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1364 (csobj,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1365 "internal-eol-wrapper",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1366 Qchain, Qunbound,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1367 list4 (Qchain,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1368 list2 (copied,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1369 eol_wrapper == EOL_CR ?
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1370 Qconvert_eol_cr :
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1371 Qconvert_eol_crlf),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1372 Qcanonicalize_after_coding,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1373 csobj));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1374 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1375 XCODING_SYSTEM_EOL_TYPE (csobj) = eol_wrapper;
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1376
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1377 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1378 EXTERNAL_LIST_LOOP_2 (alias, aliases)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1379 Fdefine_coding_system_alias (alias, csobj);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1380 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1381 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1382
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1383 return csobj;
428
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
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1386 Lisp_Object
4528
726060ee587c First draft of g++ 4.3 warning removal patch. Builds. *Needs ChangeLogs.*
Stephen J. Turnbull <stephen@xemacs.org>
parents: 4522
diff changeset
1387 make_internal_coding_system (Lisp_Object existing, const Ascbyte *prefix,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1388 Lisp_Object type, Lisp_Object description,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1389 Lisp_Object props)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1390 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1391 return make_coding_system_1 (existing, prefix, type, description, props);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1392 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1393
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1394 DEFUN ("make-coding-system-internal", Fmake_coding_system_internal, 2, 4, 0, /*
5083
88f955fa5a7f Back out revision c673987f5f3d, undump mule/make-coding-system.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5038
diff changeset
1395 Create a new coding system object, and register NAME as its name.
88f955fa5a7f Back out revision c673987f5f3d, undump mule/make-coding-system.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5038
diff changeset
1396
88f955fa5a7f Back out revision c673987f5f3d, undump mule/make-coding-system.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5038
diff changeset
1397 With Mule support, this does much of the work of `make-coding-system'.
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1398 Without Mule support, it does all the work of that function, and an alias
5083
88f955fa5a7f Back out revision c673987f5f3d, undump mule/make-coding-system.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5038
diff changeset
1399 exists, mapping `make-coding-system' to `make-coding-system-internal'.
88f955fa5a7f Back out revision c673987f5f3d, undump mule/make-coding-system.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5038
diff changeset
1400
88f955fa5a7f Back out revision c673987f5f3d, undump mule/make-coding-system.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5038
diff changeset
1401 You'll need a Mule XEmacs to read the complete docstring. Or you can
88f955fa5a7f Back out revision c673987f5f3d, undump mule/make-coding-system.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5038
diff changeset
1402 just read it in make-coding-system.el; something like the following
88f955fa5a7f Back out revision c673987f5f3d, undump mule/make-coding-system.el.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5038
diff changeset
1403 should work:
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1404
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
1405 \\[find-function-other-window] find-file RET \\[find-file] mule/make-coding-system.el RET
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1406
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1407 */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1408 (name, type, description, props))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1409 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1410 return make_coding_system_1 (name, 0, type, description, props);
428
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 DEFUN ("copy-coding-system", Fcopy_coding_system, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1414 Copy OLD-CODING-SYSTEM to NEW-NAME.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1415 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
1416 be created.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1417 If you are using this function to create an alias, think again:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1418 Use `define-coding-system-alias' instead.
428
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 (old_coding_system, new_name))
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 Lisp_Object new_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1423 old_coding_system = Fget_coding_system (old_coding_system);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1424 new_coding_system =
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
1425 UNBOUNDP (new_name) ? Qnil : find_coding_system (new_name, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1426 if (NILP (new_coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1427 {
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
1428 new_coding_system =
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
1429 wrap_coding_system
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
1430 (allocate_coding_system
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
1431 (XCODING_SYSTEM (old_coding_system)->methods,
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
1432 XCODING_SYSTEM (old_coding_system)->methods->extra_data_size,
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
1433 new_name));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1434 if (!UNBOUNDP (new_name))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1435 Fputhash (new_name, new_coding_system, Vcoding_system_hash_table);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1436 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1437 else if (XCODING_SYSTEM (old_coding_system)->methods !=
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1438 XCODING_SYSTEM (new_coding_system)->methods)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1439 invalid_operation_2 ("Coding systems not same type",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1440 old_coding_system, new_coding_system);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1441
5127
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5126
diff changeset
1442 copy_lisp_object (new_coding_system, old_coding_system);
a9c41067dd88 more cleanups, terminology clarification, lots of doc work
Ben Wing <ben@xemacs.org>
parents: 5126
diff changeset
1443 XCODING_SYSTEM (new_coding_system)->name = new_name;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1444 return new_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1445 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1446
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
1447 /* #### Shouldn't this really be a find/get pair? */
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
1448
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1449 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
1450 Return t if OBJECT is a coding system alias.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1451 All coding system aliases are created by `define-coding-system-alias'.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1452 */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1453 (object))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1454 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1455 return SYMBOLP (Fgethash (object, Vcoding_system_hash_table, Qzero))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1456 ? Qt : Qnil;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1457 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1458
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1459 DEFUN ("coding-system-aliasee", Fcoding_system_aliasee, 1, 1, 0, /*
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1460 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
1461 */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1462 (alias))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1463 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1464 Lisp_Object aliasee = Fgethash (alias, Vcoding_system_hash_table, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1465 if (SYMBOLP (aliasee))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1466 return aliasee;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1467 else
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1468 invalid_argument ("Symbol is not a coding system alias", alias);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1469 RETURN_NOT_REACHED (Qnil);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1470 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1471
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1472 /* A maphash function, for removing dangling coding system aliases. */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1473 static int
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
1474 dangling_coding_system_alias_p (Lisp_Object UNUSED (alias),
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1475 Lisp_Object aliasee,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1476 void *dangling_aliases)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1477 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1478 if (SYMBOLP (aliasee)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1479 && NILP (Fgethash (aliasee, Vcoding_system_hash_table, Qnil)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1480 {
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1481 (*(int *) dangling_aliases)++;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1482 return 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1483 }
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1484 else
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1485 return 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1486 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1487
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1488 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
1489 Define symbol ALIAS as an alias for coding system ALIASEE.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1490
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1491 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
1492 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
1493 \(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
1494 `coding-system-name' on a coding system).
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1495
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1496 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
1497
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1498 You are forbidden, however, from creating alias loops or `dangling' aliases.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1499 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
1500
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1501 If ALIASEE is nil, then ALIAS will simply be undefined.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1502
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1503 See also `coding-system-alias-p', `coding-system-aliasee',
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1504 and `coding-system-canonical-name-p'.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1505 */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1506 (alias, aliasee))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1507 {
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
1508 Lisp_Object probe;
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1509
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1510 CHECK_SYMBOL (alias);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1511
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1512 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
1513 invalid_change
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1514 ("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
1515 alias);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1516
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1517 if (NILP (aliasee))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1518 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1519 Lisp_Object subsidiary_unix = add_suffix_to_symbol (alias, "-unix");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1520 Lisp_Object subsidiary_dos = add_suffix_to_symbol (alias, "-dos");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1521 Lisp_Object subsidiary_mac = add_suffix_to_symbol (alias, "-mac");
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1522
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1523 Fremhash (alias, Vcoding_system_hash_table);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1524
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1525 /* Undefine subsidiary aliases,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1526 presumably created by a previous call to this function */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1527 if (! NILP (Fcoding_system_alias_p (subsidiary_unix)) &&
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1528 ! NILP (Fcoding_system_alias_p (subsidiary_dos)) &&
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1529 ! NILP (Fcoding_system_alias_p (subsidiary_mac)))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1530 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1531 Fdefine_coding_system_alias (subsidiary_unix, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1532 Fdefine_coding_system_alias (subsidiary_dos, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1533 Fdefine_coding_system_alias (subsidiary_mac, Qnil);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1534 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1535
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1536 /* Undefine dangling coding system aliases. */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1537 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1538 int dangling_aliases;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1539
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1540 do {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1541 dangling_aliases = 0;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1542 elisp_map_remhash (dangling_coding_system_alias_p,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1543 Vcoding_system_hash_table,
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1544 &dangling_aliases);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1545 } while (dangling_aliases > 0);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1546 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1547
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1548 return Qnil;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1549 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1550
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1551 if (CODING_SYSTEMP (aliasee))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1552 aliasee = XCODING_SYSTEM_NAME (aliasee);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1553
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1554 /* Checks that aliasee names a coding-system */
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
1555 (void) Fget_coding_system (aliasee);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1556
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1557 /* Check for coding system alias loops */
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1558 if (EQ (alias, aliasee))
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
1559 alias_loop: invalid_operation_2
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1560 ("Attempt to create a coding system alias loop", alias, aliasee);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1561
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1562 for (probe = aliasee;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1563 SYMBOLP (probe);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1564 probe = Fgethash (probe, Vcoding_system_hash_table, Qzero))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1565 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1566 if (EQ (probe, alias))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1567 goto alias_loop;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1568 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1569
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1570 Fputhash (alias, aliasee, Vcoding_system_hash_table);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1571
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1572 /* Set up aliases for subsidiaries.
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
1573 #### There must be a better way to handle subsidiary coding systems.
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
1574 Inquiring Minds Want To Know: shouldn't they always be chains? */
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1575 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1576 static const char *suffixes[] = { "-unix", "-dos", "-mac" };
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1577 int i;
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1578 for (i = 0; i < countof (suffixes); i++)
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1579 {
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1580 Lisp_Object alias_subsidiary =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1581 add_suffix_to_symbol (alias, suffixes[i]);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1582 Lisp_Object aliasee_subsidiary =
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1583 add_suffix_to_symbol (aliasee, suffixes[i]);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1584
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1585 if (! NILP (Ffind_coding_system (aliasee_subsidiary)))
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1586 Fdefine_coding_system_alias (alias_subsidiary, aliasee_subsidiary);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1587 }
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
1588 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1589 /* 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
1590 but it doesn't look intentional, so I'd rather return something
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1591 meaningful or nothing at all. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1592 return Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1593 }
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 static Lisp_Object
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1596 subsidiary_coding_system (Lisp_Object coding_system, enum eol_type type)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1597 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1598 Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1599 Lisp_Object new_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1600
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1601 switch (type)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1602 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1603 case EOL_AUTODETECT: return coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1604 case EOL_LF: new_coding_system = CODING_SYSTEM_EOL_LF (cs); break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1605 case EOL_CR: new_coding_system = CODING_SYSTEM_EOL_CR (cs); break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1606 case EOL_CRLF: new_coding_system = CODING_SYSTEM_EOL_CRLF (cs); break;
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
1607 default: ABORT (); return Qnil;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1608 }
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 return NILP (new_coding_system) ? coding_system : new_coding_system;
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1613 DEFUN ("subsidiary-coding-system", Fsubsidiary_coding_system, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1614 Return the subsidiary coding system of CODING-SYSTEM with eol type EOL-TYPE.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1615 The logically opposite operation is `coding-system-base'.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1616 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1617 (coding_system, eol_type))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1618 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1619 coding_system = get_coding_system_for_text_file (coding_system, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1621 return subsidiary_coding_system (coding_system,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1622 symbol_to_eol_type (eol_type));
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
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1625 DEFUN ("coding-system-base", Fcoding_system_base,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1626 1, 1, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1627 Return the base coding system of CODING-SYSTEM.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1628 If CODING-SYSTEM is a subsidiary, this returns its parent; otherwise, it
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1629 returns CODING-SYSTEM.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1630 The logically opposite operation is `subsidiary-coding-system'.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1631 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1632 (coding_system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1633 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1634 Lisp_Object base;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1635
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1636 coding_system = Fget_coding_system (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1637 if (EQ (XCODING_SYSTEM_NAME (coding_system), Qbinary))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1638 return Fget_coding_system (Qraw_text); /* hack! */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1639 base = XCODING_SYSTEM_SUBSIDIARY_PARENT (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1640 if (!NILP (base))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1641 return base;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1642 return coding_system;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1643 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1644
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1645 DEFUN ("coding-system-used-for-io", Fcoding_system_used_for_io,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1646 1, 1, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1647 Return the coding system actually used for I/O.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1648 In some cases (e.g. when a particular EOL type is specified) this won't be
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
1649 the coding system itself. This can be useful when trying to determine
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
1650 precisely how data was decoded.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1651 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1652 (coding_system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1653 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1654 Lisp_Object canon;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1655
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1656 coding_system = Fget_coding_system (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1657 canon = XCODING_SYSTEM_CANONICAL (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1658 if (!NILP (canon))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1659 return canon;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1660 return coding_system;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1661 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1662
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1663
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1664 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1665 /* Coding system accessors */
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
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1668 DEFUN ("coding-system-description", Fcoding_system_description, 1, 1, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1669 Return the description for CODING-SYSTEM.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1670 The `description' of a coding system is a short English phrase giving the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1671 name rendered according to English punctuation rules, plus possibly some
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1672 explanatory text (typically in the form of a parenthetical phrase). The
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1673 description is intended to be short enough that it can appear as a menu item,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1674 and clear enough to be recognizable even to someone who is assumed to have
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1675 some basic familiarity with different encodings but may not know all the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1676 technical names; thus, for `cn-gb-2312' is described as "Chinese EUC" and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1677 `hz-gb-2312' is described as "Hz/ZW (Chinese)", where the actual name of
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1678 the encoding is given, followed by a note that this is a Chinese encoding,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1679 because the great majority of people encountering this would have no idea
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1680 what it is, and giving the language indicates whether the encoding should
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1681 just be ignored or (conceivably) investigated more thoroughly.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1682 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1683 (coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1684 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1685 coding_system = Fget_coding_system (coding_system);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1686 return XCODING_SYSTEM_DESCRIPTION (coding_system);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1687 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1688
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1689 DEFUN ("coding-system-type", Fcoding_system_type, 1, 1, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1690 Return the type of CODING-SYSTEM.
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 (coding_system))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1693 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1694 coding_system = Fget_coding_system (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1695 return XCODING_SYSTEM_TYPE (coding_system);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1696 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1697
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1698 DEFUN ("coding-system-property", Fcoding_system_property, 2, 2, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1699 Return the PROP property of CODING-SYSTEM.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1700 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1701 (coding_system, prop))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1702 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1703 coding_system = Fget_coding_system (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1704 CHECK_SYMBOL (prop);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1705
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1706 if (EQ (prop, Qname))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1707 return XCODING_SYSTEM_NAME (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1708 else if (EQ (prop, Qtype))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1709 return Fcoding_system_type (coding_system);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1710 else if (EQ (prop, Qdescription))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1711 return XCODING_SYSTEM_DESCRIPTION (coding_system);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1712 else if (EQ (prop, Qmnemonic))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1713 return XCODING_SYSTEM_MNEMONIC (coding_system);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1714 else if (EQ (prop, Qdocumentation))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1715 return XCODING_SYSTEM_DOCUMENTATION (coding_system);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1716 else if (EQ (prop, Qeol_type))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1717 return eol_type_to_symbol (XCODING_SYSTEM_EOL_TYPE
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1718 (coding_system));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1719 else if (EQ (prop, Qeol_lf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1720 return XCODING_SYSTEM_EOL_LF (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1721 else if (EQ (prop, Qeol_crlf))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1722 return XCODING_SYSTEM_EOL_CRLF (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1723 else if (EQ (prop, Qeol_cr))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1724 return XCODING_SYSTEM_EOL_CR (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1725 else if (EQ (prop, Qpost_read_conversion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1726 return XCODING_SYSTEM_POST_READ_CONVERSION (coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1727 else if (EQ (prop, Qpre_write_conversion))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
1728 return XCODING_SYSTEM_PRE_WRITE_CONVERSION (coding_system);
4568
1d74a1d115ee Add #'query-coding-region tests; do the work necessary to get them running.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4303
diff changeset
1729 else if (EQ (prop, Qsafe_charsets))
1d74a1d115ee Add #'query-coding-region tests; do the work necessary to get them running.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4303
diff changeset
1730 return XCODING_SYSTEM_SAFE_CHARSETS (coding_system);
1d74a1d115ee Add #'query-coding-region tests; do the work necessary to get them running.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4303
diff changeset
1731 else if (EQ (prop, Qsafe_chars))
1d74a1d115ee Add #'query-coding-region tests; do the work necessary to get them running.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4303
diff changeset
1732 return XCODING_SYSTEM_SAFE_CHARS (coding_system);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1733 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1734 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1735 Lisp_Object value = CODESYSMETH_OR_GIVEN (XCODING_SYSTEM (coding_system),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1736 getprop,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1737 (coding_system, prop),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1738 Qunbound);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1739 if (UNBOUNDP (value))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1740 invalid_constant ("Unrecognized property", prop);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1741 return value;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1742 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1743 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1744
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1745
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1746 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1747 /* Coding stream functions */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1748 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1749
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1750 /* A coding stream is a stream used for encoding or decoding text. The
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1751 coding-stream object keeps track of the actual coding system, the stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1752 that is at the other end, and data that needs to be persistent across
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1753 the lifetime of the stream. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1754
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1755 extern const struct sized_memory_description chain_coding_stream_description;
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1756 extern const struct sized_memory_description undecided_coding_stream_description;
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1757
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1758 static const struct memory_description coding_stream_data_description_1 []= {
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
1759 { XD_BLOCK_PTR, chain_coding_system, 1,
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
1760 { &chain_coding_stream_description } },
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
1761 { XD_BLOCK_PTR, undecided_coding_system, 1,
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
1762 { &undecided_coding_stream_description } },
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1763 { XD_END }
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1764 };
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1765
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1766 static const struct sized_memory_description coding_stream_data_description = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1767 sizeof (void *), coding_stream_data_description_1
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1768 };
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1769
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1770 static const struct memory_description coding_lstream_description[] = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1771 { XD_INT, offsetof (struct coding_stream, type) },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1772 { XD_LISP_OBJECT, offsetof (struct coding_stream, orig_codesys) },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1773 { XD_LISP_OBJECT, offsetof (struct coding_stream, codesys) },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1774 { XD_LISP_OBJECT, offsetof (struct coding_stream, other_end) },
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1775 { XD_UNION, offsetof (struct coding_stream, data),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
1776 XD_INDIRECT (0, 0), { &coding_stream_data_description } },
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1777 { XD_END }
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1778 };
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1779
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
1780 DEFINE_LSTREAM_IMPLEMENTATION_WITH_DATA ("coding", coding);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1781
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1782 /* Encoding and decoding are parallel operations, so we create just one
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1783 stream for both. "Decoding" may involve the extra step of autodetection
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1784 of the data format, but that's only because of the conventional
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1785 definition of decoding as converting from external- to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1786 internal-formatted data.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1787
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
1788 [[ REWRITE ME! ]]
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
1789
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1790 #### We really need to abstract out the concept of "data formats" and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1791 define "converters" that convert from and to specified formats,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1792 eliminating the idea of decoding and encoding. When specifying a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1793 conversion process, we need to give the data formats themselves, not the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1794 conversion processes -- e.g. a coding system called "Unicode->multibyte"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1795 converts in both directions, and we could auto-detect the format of data
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1796 at either end. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1797
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1798 static Bytecount
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1799 coding_reader (Lstream *stream, unsigned char *data, Bytecount size)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1800 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1801 unsigned char *orig_data = data;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1802 Bytecount read_size;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1803 int error_occurred = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1804 struct coding_stream *str = CODING_STREAM_DATA (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1805
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1806 /* We need to interface to coding_{de,en}code_1(), which expects to take
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1807 some amount of data and store the result into a Dynarr. We have
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1808 coding_{de,en}code_1() store into c->runoff, and take data from there
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1809 as necessary. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1810
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1811 /* We loop until we have enough data, reading chunks from the other
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1812 end and converting it. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1813 while (1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1814 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1815 /* Take data from convert_to if we can. Make sure to take at
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1816 most SIZE bytes, and delete the data from convert_to. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1817 if (Dynarr_length (str->convert_to) > 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1818 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1819 Bytecount chunk =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1820 min (size, (Bytecount) Dynarr_length (str->convert_to));
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
1821 memcpy (data, Dynarr_begin (str->convert_to), chunk);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1822 Dynarr_delete_many (str->convert_to, 0, chunk);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1823 data += chunk;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1824 size -= chunk;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1825 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1826
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1827 if (size == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1828 break; /* No more room for data */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1829
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1830 if (str->eof)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1831 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1832
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1833 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1834 /* Exhausted convert_to, so get some more. Read into convert_from,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1835 after existing "rejected" data from the last conversion. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1836 Bytecount rejected = Dynarr_length (str->convert_from);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1837 /* #### 1024 is arbitrary; we really need to separate 0 from EOF,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1838 and when we get 0, keep taking more data until we don't get 0 --
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1839 we don't know how much data the conversion routine might need
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
1840 before it can generate any data of its own (eg, bzip2). */
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1841 Bytecount readmore =
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1842 str->one_byte_at_a_time ? (Bytecount) 1 :
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1843 max (size, (Bytecount) 1024);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1844
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1845 Dynarr_add_many (str->convert_from, 0, readmore);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1846 read_size = Lstream_read (str->other_end,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1847 Dynarr_atp (str->convert_from, rejected),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1848 readmore);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1849 /* Trim size down to how much we actually got */
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1850 Dynarr_set_lengthr (str->convert_from, rejected + max (0, read_size));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1851 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1852
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1853 if (read_size < 0) /* LSTREAM_ERROR */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1854 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1855 error_occurred = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1856 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1857 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1858 if (read_size == 0) /* LSTREAM_EOF */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1859 /* There might be some more end data produced in the translation,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1860 so we set a flag and call the conversion method once more to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1861 output any final stuff it may be holding, any "go back to a sane
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1862 state" escape sequences, etc. The conversion method is free to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1863 look at this flag, and we use it above to stop looping. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1864 str->eof = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1865 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1866 Bytecount processed;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1867 Bytecount to_process = Dynarr_length (str->convert_from);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1868
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1869 /* Convert the data, and save any rejected data in convert_from */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1870 processed =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1871 XCODESYSMETH (str->codesys, convert,
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
1872 (str, Dynarr_begin (str->convert_from),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1873 str->convert_to, to_process));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1874 if (processed < 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1875 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1876 error_occurred = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1877 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1878 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1879 assert (processed <= to_process);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1880 if (processed < to_process)
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
1881 memmove (Dynarr_begin (str->convert_from),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1882 Dynarr_atp (str->convert_from, processed),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1883 to_process - processed);
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
1884 Dynarr_set_lengthr (str->convert_from, to_process - processed);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1885 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1886 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1887
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1888 if (data - orig_data == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1889 return error_occurred ? -1 : 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1890 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1891 return data - orig_data;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1892 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1893
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1894 static Bytecount
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1895 coding_writer (Lstream *stream, const unsigned char *data, Bytecount size)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1896 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1897 struct coding_stream *str = CODING_STREAM_DATA (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1898
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1899 /* Convert all our data into convert_to, and then attempt to write
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1900 it all out to the other end. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1901 Dynarr_reset (str->convert_to);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1902 size = XCODESYSMETH (str->codesys, convert,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1903 (str, data, str->convert_to, size));
4967
0d4c9d0f6a8d rewrite dynarr code
Ben Wing <ben@xemacs.org>
parents: 4953
diff changeset
1904 if (Lstream_write (str->other_end, Dynarr_begin (str->convert_to),
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1905 Dynarr_length (str->convert_to)) < 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1906 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1907 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1908 /* The return value indicates how much of the incoming data was
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1909 processed, not how many bytes were written. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1910 return size;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1911 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1912
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1913 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1914 encode_decode_source_sink_type_is_char (Lisp_Object cs,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1915 enum source_or_sink sex,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1916 enum encode_decode direction)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1917 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1918 return (direction == CODING_DECODE ?
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1919 decoding_source_sink_type_is_char (cs, sex) :
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1920 encoding_source_sink_type_is_char (cs, sex));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1921 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1922
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1923 /* Ensure that the convert methods only get full characters sent to them to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1924 convert if the source of that conversion is characters; and that no such
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1925 full-character checking happens when the source is bytes. Keep in mind
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1926 that (1) the conversion_end_type return values take the perspective of
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1927 encoding; (2) the source for decoding is the same as the sink for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1928 encoding; (3) when writing, the data is given to us, and we set our own
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1929 stream to be character mode or not; (4) when reading, the data comes
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1930 from the other_end stream, and we set that one to be character mode or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1931 not. This is consistent with the comment above the prototype for
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1932 Lstream_set_character_mode(), which lays out rules for who is allowed to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1933 modify the character type mode on a stream.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1934
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1935 If we're a read stream, we're always setting character mode on the
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1936 source, but we also set it on ourselves consistent with the flag that
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1937 can disable this (see again the comment above
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1938 Lstream_set_character_mode()).
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1939 */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1940
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1941 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1942 set_coding_character_mode (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1943 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1944 struct coding_stream *str = CODING_STREAM_DATA (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1945 Lstream *stream_to_set =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1946 stream->flags & LSTREAM_FL_WRITE ? stream : str->other_end;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1947 if (encode_decode_source_sink_type_is_char
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1948 (str->codesys, CODING_SOURCE, str->direction))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1949 Lstream_set_character_mode (stream_to_set);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1950 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1951 Lstream_unset_character_mode (stream_to_set);
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1952 if (str->set_char_mode_on_us_when_reading &&
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1953 (stream->flags & LSTREAM_FL_READ))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1954 {
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1955 if (encode_decode_source_sink_type_is_char
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1956 (str->codesys, CODING_SINK, str->direction))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1957 Lstream_set_character_mode (stream);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1958 else
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1959 Lstream_unset_character_mode (stream);
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
1960 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1961 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1962
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1963 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1964 coding_marker (Lisp_Object stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1965 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1966 struct coding_stream *str = CODING_STREAM_DATA (XLSTREAM (stream));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1967
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1968 mark_object (str->orig_codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1969 mark_object (str->codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1970 MAYBE_XCODESYSMETH (str->codesys, mark_coding_stream, (str));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1971 return wrap_lstream (str->other_end);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1972 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1973
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1974 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1975 coding_rewinder (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1976 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1977 struct coding_stream *str = CODING_STREAM_DATA (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1978 MAYBE_XCODESYSMETH (str->codesys, rewind_coding_stream, (str));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1979
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1980 str->ch = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1981 Dynarr_reset (str->convert_to);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1982 Dynarr_reset (str->convert_from);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1983 return Lstream_rewind (str->other_end);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1984 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1985
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1986 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1987 coding_seekable_p (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1988 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1989 struct coding_stream *str = CODING_STREAM_DATA (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1990 return Lstream_seekable_p (str->other_end);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1991 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
1992
5776
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
1993 static Charcount
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
1994 coding_character_tell (Lstream *stream)
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
1995 {
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
1996 struct coding_stream *str = CODING_STREAM_DATA (stream);
5784
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
1997 Charcount ctell
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
1998 = XCODESYSMETH_OR_GIVEN (str->codesys, character_tell, (str), -1);
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
1999
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2000 if (ctell > 0 && Dynarr_length (str->convert_to) > 0)
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2001 {
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2002 ctell
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2003 -= buffered_bytecount_to_charcount ((const Ibyte *)
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2004 (Dynarr_begin (str->convert_to)),
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2005 Dynarr_length (str->convert_to));
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2006 text_checking_assert (ctell >= 0);
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2007 }
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2008
0cb4f494a548 Have the result of coding_character_tell() reflect str->convert_to, too.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5777
diff changeset
2009 return ctell;
5776
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2010 }
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2011
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2012 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2013 coding_flusher (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2014 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2015 struct coding_stream *str = CODING_STREAM_DATA (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2016 return Lstream_flush (str->other_end);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2017 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2018
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2019 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2020 coding_closer (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2021 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2022 struct coding_stream *str = CODING_STREAM_DATA (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2023 if (stream->flags & LSTREAM_FL_WRITE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2024 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2025 str->eof = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2026 coding_writer (stream, 0, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2027 str->eof = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2028 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2029 /* It's safe to free the runoff dynarrs now because they are used only
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2030 during conversion. We need to keep the type-specific data around,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2031 though, because of canonicalize_after_coding. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2032 if (str->convert_to)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2033 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2034 Dynarr_free (str->convert_to);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2035 str->convert_to = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2036 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2037 if (str->convert_from)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2038 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2039 Dynarr_free (str->convert_from);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2040 str->convert_from = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2041 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2042
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2043 if (str->no_close_other)
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2044 return Lstream_flush (str->other_end);
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2045 else
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2046 return Lstream_close (str->other_end);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2047 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2048
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2049 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2050 coding_finalizer (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2051 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2052 struct coding_stream *str = CODING_STREAM_DATA (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2053
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2054 assert (!str->finalized);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2055 MAYBE_XCODESYSMETH (str->codesys, finalize_coding_stream, (str));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2056 if (str->data)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2057 {
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
2058 xfree (str->data);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2059 str->data = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2060 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2061 str->finalized = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2062 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2063
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2064 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2065 coding_stream_canonicalize_after_coding (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2066 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2067 struct coding_stream *str = CODING_STREAM_DATA (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2068
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2069 return XCODESYSMETH_OR_GIVEN (str->codesys, canonicalize_after_coding,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2070 (str), str->codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2071 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2072
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2073 Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2074 coding_stream_detected_coding_system (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2075 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2076 Lisp_Object codesys =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2077 coding_stream_canonicalize_after_coding (stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2078 if (NILP (codesys))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2079 return Fget_coding_system (Qidentity);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2080 return codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2081 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2082
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2083 Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2084 coding_stream_coding_system (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2085 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2086 return CODING_STREAM_DATA (stream)->codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2087 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2088
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2089 /* Change the coding system associated with a stream. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2090
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2091 void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2092 set_coding_stream_coding_system (Lstream *lstr, Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2093 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2094 struct coding_stream *str = CODING_STREAM_DATA (lstr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2095 if (EQ (str->orig_codesys, codesys))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2096 return;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2097 /* We do the equivalent of closing the stream, destroying it, and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2098 reinitializing it. This includes flushing out the data and signalling
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2099 EOF, if we're a writing stream; we also replace the type-specific data
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2100 with the data appropriate for the new coding system. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2101 if (!NILP (str->codesys))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2102 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2103 if (lstr->flags & LSTREAM_FL_WRITE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2104 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2105 Lstream_flush (lstr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2106 str->eof = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2107 coding_writer (lstr, 0, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2108 str->eof = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2109 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2110 MAYBE_XCODESYSMETH (str->codesys, finalize_coding_stream, (str));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2111 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2112 str->orig_codesys = codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2113 str->codesys = coding_system_real_canonical (codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2114
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2115 if (str->data)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2116 {
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
2117 xfree (str->data);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2118 str->data = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2119 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2120 if (XCODING_SYSTEM_METHODS (str->codesys)->coding_data_size)
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2121 {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2122 str->data =
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2123 xmalloc_and_zero (XCODING_SYSTEM_METHODS (str->codesys)->
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2124 coding_data_size);
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2125 str->type = XCODING_SYSTEM_METHODS (str->codesys)->enumtype;
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2126 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2127 MAYBE_XCODESYSMETH (str->codesys, init_coding_stream, (str));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2128 /* The new coding system may have different ideas regarding whether its
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2129 ends are characters or bytes. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2130 set_coding_character_mode (lstr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2131 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2132
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2133 /* WARNING WARNING WARNING WARNING!!!!! If you open up a coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2134 stream for writing, no automatic code detection will be performed.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2135 The reason for this is that automatic code detection requires a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2136 seekable input. Things will also fail if you open a coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2137 stream for reading using a non-fully-specified coding system and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2138 a non-seekable input stream. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2139
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2140 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2141 make_coding_stream_1 (Lstream *stream, Lisp_Object codesys,
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2142 const char *mode, enum encode_decode direction,
802
19dfb459d51a [xemacs-hg @ 2002-04-03 10:47:37 by ben]
ben
parents: 801
diff changeset
2143 int flags)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2144 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2145 Lstream *lstr = Lstream_new (lstream_coding, mode);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2146 struct coding_stream *str = CODING_STREAM_DATA (lstr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2147
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2148 codesys = Fget_coding_system (codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2149 xzero (*str);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2150 str->codesys = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2151 str->orig_codesys = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2152 str->us = lstr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2153 str->other_end = stream;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2154 str->convert_to = Dynarr_new (unsigned_char);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2155 str->convert_from = Dynarr_new (unsigned_char);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2156 str->direction = direction;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2157 if (flags & LSTREAM_FL_NO_CLOSE_OTHER)
802
19dfb459d51a [xemacs-hg @ 2002-04-03 10:47:37 by ben]
ben
parents: 801
diff changeset
2158 str->no_close_other = 1;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2159 if (flags & LSTREAM_FL_READ_ONE_BYTE_AT_A_TIME)
802
19dfb459d51a [xemacs-hg @ 2002-04-03 10:47:37 by ben]
ben
parents: 801
diff changeset
2160 str->one_byte_at_a_time = 1;
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2161 if (!(flags & LSTREAM_FL_NO_INIT_CHAR_MODE_WHEN_READING))
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2162 str->set_char_mode_on_us_when_reading = 1;
802
19dfb459d51a [xemacs-hg @ 2002-04-03 10:47:37 by ben]
ben
parents: 801
diff changeset
2163
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2164 set_coding_stream_coding_system (lstr, codesys);
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
2165 return wrap_lstream (lstr);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2166 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2167
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2168 /* FLAGS:
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2169
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2170 LSTREAM_FL_NO_CLOSE_OTHER
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2171 Don't close STREAM (the stream at the other end) when this stream is
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2172 closed.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2173
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2174 LSTREAM_FL_READ_ONE_BYTE_AT_A_TIME
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2175 When reading from STREAM, read and process one byte at a time rather
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2176 than in large chunks. This is for reading from TTY's, so we don't
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2177 block. #### We should instead create a non-blocking filedesc stream
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2178 that emulates the behavior as necessary using select(), when the
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2179 fcntls don't work. (As seems to be the case on Cygwin.)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2180
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2181 LSTREAM_FL_NO_INIT_CHAR_MODE_WHEN_READING
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2182 When reading from STREAM, read and process one byte at a time rather
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2183 than in large chunks. This is for reading from TTY's, so we don't
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2184 block. #### We should instead create a non-blocking filedesc stream
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2185 that emulates the behavior as necessary using select(), when the
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2186 fcntls don't work. (As seems to be the case on Cygwin.)
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2187 */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2188 Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2189 make_coding_input_stream (Lstream *stream, Lisp_Object codesys,
802
19dfb459d51a [xemacs-hg @ 2002-04-03 10:47:37 by ben]
ben
parents: 801
diff changeset
2190 enum encode_decode direction, int flags)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2191 {
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2192 return make_coding_stream_1 (stream, codesys, "r", direction,
802
19dfb459d51a [xemacs-hg @ 2002-04-03 10:47:37 by ben]
ben
parents: 801
diff changeset
2193 flags);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2194 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2195
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2196 /* FLAGS:
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2197
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2198 LSTREAM_FL_NO_CLOSE_OTHER
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2199 Don't close STREAM (the stream at the other end) when this stream is
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2200 closed.
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
2201 */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2202 Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2203 make_coding_output_stream (Lstream *stream, Lisp_Object codesys,
802
19dfb459d51a [xemacs-hg @ 2002-04-03 10:47:37 by ben]
ben
parents: 801
diff changeset
2204 enum encode_decode direction, int flags)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2205 {
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2206 return make_coding_stream_1 (stream, codesys, "w", direction,
802
19dfb459d51a [xemacs-hg @ 2002-04-03 10:47:37 by ben]
ben
parents: 801
diff changeset
2207 flags);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2208 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2209
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2210 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2211 encode_decode_coding_region (Lisp_Object start, Lisp_Object end,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2212 Lisp_Object coding_system, Lisp_Object buffer,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2213 enum encode_decode direction)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2214 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2215 Charbpos b, e;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2216 struct buffer *buf = decode_buffer (buffer, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2217 Lisp_Object instream = Qnil, to_outstream = Qnil, outstream = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2218 Lisp_Object from_outstream = Qnil, auto_outstream = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2219 Lisp_Object lb_outstream = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2220 Lisp_Object next;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2221 Lstream *istr, *ostr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2222 struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2223 struct gcpro ngcpro1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2224 int source_char, sink_char;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2225
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2226 get_buffer_range_char (buf, start, end, &b, &e, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2227 barf_if_buffer_read_only (buf, b, e);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2228
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2229 GCPRO5 (instream, to_outstream, outstream, from_outstream, lb_outstream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2230 NGCPRO1 (auto_outstream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2231
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2232 coding_system = Fget_coding_system (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2233 source_char = encode_decode_source_sink_type_is_char (coding_system,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2234 CODING_SOURCE,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2235 direction);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2236 sink_char = encode_decode_source_sink_type_is_char (coding_system,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2237 CODING_SINK,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2238 direction);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2239
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2240 /* Order is IN <---> [TO] -> OUT -> [FROM] -> [AUTODETECT-EOL] -> LB */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2241 instream = make_lisp_buffer_input_stream (buf, b, e, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2242 next = lb_outstream = make_lisp_buffer_output_stream (buf, b, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2243
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2244 if (direction == CODING_DECODE &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2245 XCODING_SYSTEM_EOL_TYPE (coding_system) == EOL_AUTODETECT)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2246 next = auto_outstream =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2247 make_coding_output_stream
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2248 (XLSTREAM (next), Fget_coding_system (Qconvert_eol_autodetect),
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2249 CODING_DECODE, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2250
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2251 if (!sink_char)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2252 next = from_outstream =
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2253 make_coding_output_stream (XLSTREAM (next), Qbinary, CODING_DECODE, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2254 outstream = make_coding_output_stream (XLSTREAM (next), coding_system,
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2255 direction, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2256 if (!source_char)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2257 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2258 to_outstream =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2259 make_coding_output_stream (XLSTREAM (outstream),
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2260 Qbinary, CODING_ENCODE, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2261 ostr = XLSTREAM (to_outstream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2262 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2263 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2264 ostr = XLSTREAM (outstream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2265 istr = XLSTREAM (instream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2266
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2267 /* The chain of streams looks like this:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2268
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2269 [BUFFER] <----- (( read from/send to loop ))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2270 ------> [CHAR->BYTE i.e. ENCODE AS BINARY if source is
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2271 in bytes]
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2272 ------> [ENCODE/DECODE AS SPECIFIED]
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2273 ------> [BYTE->CHAR i.e. DECODE AS BINARY
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2274 if sink is in bytes]
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2275 ------> [AUTODETECT EOL if
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2276 we're decoding and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2277 coding system calls
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2278 for this]
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2279 ------> [BUFFER]
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2280 */
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2281
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2282 /* #### See comment
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2283
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2284 EFFICIENCY OF CODING CONVERSION WITH MULTIPLE COPIES/CHAINS
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2285
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2286 in text.c.
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2287 */
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2288
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2289 while (1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2290 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2291 char tempbuf[1024]; /* some random amount */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2292 Charbpos newpos, even_newer_pos;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2293 Charbpos oldpos = lisp_buffer_stream_startpos (istr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2294 Bytecount size_in_bytes =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2295 Lstream_read (istr, tempbuf, sizeof (tempbuf));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2296
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2297 if (size_in_bytes < 0)
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2298 {
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2299 int err = Lstream_errno (istr);
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2300 if (err)
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2301 signal_error_2 (Qtext_conversion_error,
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2302 direction == CODING_DECODE
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2303 ? "Internal error while decoding"
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2304 : "Internal error while encoding",
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2305 XCODING_SYSTEM_NAME (coding_system),
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2306 lisp_strerror (err));
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2307 else
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2308 signal_error (Qtext_conversion_error,
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2309 direction == CODING_DECODE
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2310 ? "Internal error while decoding"
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2311 : "Internal error while encoding",
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2312 XCODING_SYSTEM_NAME (coding_system));
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
2313 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2314 if (!size_in_bytes)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2315 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2316 newpos = lisp_buffer_stream_startpos (istr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2317 Lstream_write (ostr, tempbuf, size_in_bytes);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2318 even_newer_pos = lisp_buffer_stream_startpos (istr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2319 buffer_delete_range (buf, even_newer_pos - (newpos - oldpos),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2320 even_newer_pos, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2321 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2322
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2323 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2324 Charcount retlen =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2325 lisp_buffer_stream_startpos (XLSTREAM (instream)) - b;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2326 Lstream_close (istr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2327 Lstream_close (ostr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2328 NUNGCPRO;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2329 UNGCPRO;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2330 Lstream_delete (istr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2331 if (!NILP (from_outstream))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2332 Lstream_delete (XLSTREAM (from_outstream));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2333 Lstream_delete (XLSTREAM (outstream));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2334 if (!NILP (to_outstream))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2335 Lstream_delete (XLSTREAM (to_outstream));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2336 if (!NILP (auto_outstream))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2337 Lstream_delete (XLSTREAM (auto_outstream));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2338 Lstream_delete (XLSTREAM (lb_outstream));
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
2339 return make_fixnum (retlen);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2340 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2341 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2342
3302
3d54e5f2dfb0 [xemacs-hg @ 2006-03-26 13:05:14 by stephent]
stephent
parents: 3263
diff changeset
2343 DEFUN ("decode-coding-region", Fdecode_coding_region, 3, 4,
3d54e5f2dfb0 [xemacs-hg @ 2006-03-26 13:05:14 by stephent]
stephent
parents: 3263
diff changeset
2344 "*r\nzDecode from coding system: \ni", /*
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2345 Decode the text between START and END which is encoded in CODING-SYSTEM.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2346 This is useful if you've read in encoded text from a file without decoding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2347 it (e.g. you read in a JIS-formatted file but used the `binary' or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2348 `no-conversion' coding system, so that it shows up as "^[$B!<!+^[(B").
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2349 Return length of decoded text.
3302
3d54e5f2dfb0 [xemacs-hg @ 2006-03-26 13:05:14 by stephent]
stephent
parents: 3263
diff changeset
2350 BUFFER defaults to the current buffer if unspecified, and when interactive.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2351 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2352 (start, end, coding_system, buffer))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2353 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2354 return encode_decode_coding_region (start, end, coding_system, buffer,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2355 CODING_DECODE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2356 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2357
3302
3d54e5f2dfb0 [xemacs-hg @ 2006-03-26 13:05:14 by stephent]
stephent
parents: 3263
diff changeset
2358 DEFUN ("encode-coding-region", Fencode_coding_region, 3, 4,
3d54e5f2dfb0 [xemacs-hg @ 2006-03-26 13:05:14 by stephent]
stephent
parents: 3263
diff changeset
2359 "*r\nzEncode to coding system: \ni", /*
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2360 Encode the text between START and END using CODING-SYSTEM.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2361 This will, for example, convert Japanese characters into stuff such as
3302
3d54e5f2dfb0 [xemacs-hg @ 2006-03-26 13:05:14 by stephent]
stephent
parents: 3263
diff changeset
2362 "^[$B!<!+^[(B" if you use the JIS encoding. Return length of encoded text.
3d54e5f2dfb0 [xemacs-hg @ 2006-03-26 13:05:14 by stephent]
stephent
parents: 3263
diff changeset
2363 BUFFER defaults to the current buffer if unspecified, and when interactive.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2364 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2365 (start, end, coding_system, buffer))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2366 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2367 return encode_decode_coding_region (start, end, coding_system, buffer,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2368 CODING_ENCODE);
428
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
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2371 DEFUN ("query-coding-region", Fquery_coding_region, 3, 7, 0, /*
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2372 Work out whether CODING-SYSTEM can losslessly encode a region.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2373
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2374 START and END are the beginning and end of the region to check.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2375 CODING-SYSTEM is the coding system to try.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2376
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2377 Optional argument BUFFER is the buffer to check, and defaults to the current
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2378 buffer.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2379
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2380 IGNORE-INVALID-SEQUENCESP, also an optional argument, says to treat XEmacs
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2381 characters which have an unambiguous encoded representation, despite being
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2382 undefined in what they represent, as encodable. These chiefly arise with
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2383 variable-length encodings like UTF-8 and UTF-16, where an invalid sequence
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2384 is passed through to XEmacs as a sequence of characters with a defined
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2385 correspondence to the octets on disk, but no non-error semantics; see the
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2386 `invalid-sequence-coding-system' argument to `set-language-info'.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2387
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2388 They can also arise with fixed-length encodings like ISO 8859-7, where
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2389 certain octets on disk have undefined values, and treating them as
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2390 corresponding to the ISO 8859-1 characters with the same numerical values
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2391 may lead to data that is not understood by other applications.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2392
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2393 Optional argument ERRORP says to signal a `text-conversion-error' if some
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2394 character in the region cannot be encoded, and defaults to nil.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2395
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2396 Optional argument HIGHLIGHT says to display unencodable characters in the
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2397 region using `query-coding-warning-face'. It defaults to nil.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2398
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2399 This function can return multiple values; the intention is that callers use
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2400 `multiple-value-bind' or the related CL multiple value functions to deal
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2401 with it. The first result is `t' if the region can be encoded using
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2402 CODING-SYSTEM, or `nil' if not. If the region cannot be encoded using
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2403 CODING-SYSTEM, the second result is a range table describing the positions
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2404 of the unencodable characters.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2405
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2406 Ranges that describe characters that would be ignored were
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2407 IGNORE-INVALID-SEQUENCESP non-nil map to the symbol `invalid-sequence';
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2408 other ranges map to the symbol `unencodable'. If IGNORE-INVALID-SEQUENCESP
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2409 is non-nil, all ranges will map to the symbol `unencodable'. See
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2410 `make-range-table' for more details of range tables.
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2411 */
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2412 (start, end, coding_system, buffer, ignore_invalid_sequencesp,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2413 errorp, highlight))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2414 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2415 Charbpos b, e;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2416 struct buffer *buf = decode_buffer (buffer, 1);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2417 Lisp_Object result;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2418 int flags = 0, speccount = specpdl_depth ();
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2419
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2420 coding_system = Fget_coding_system (coding_system);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2421
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2422 get_buffer_range_char (buf, start, end, &b, &e, 0);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2423
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2424 if (buf != current_buffer)
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2425 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2426 record_unwind_protect (save_current_buffer_restore, Fcurrent_buffer ());
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2427 set_buffer_internal (buf);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2428 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2429
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2430 record_unwind_protect (save_excursion_restore, save_excursion_save ());
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2431
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2432 BUF_SET_PT (buf, b);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2433
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2434 if (!NILP (ignore_invalid_sequencesp))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2435 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2436 flags |= QUERY_METHOD_IGNORE_INVALID_SEQUENCES;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2437 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2438
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2439 if (!NILP (errorp))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2440 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2441 flags |= QUERY_METHOD_ERRORP;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2442 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2443
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2444 if (!NILP (highlight))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2445 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2446 flags |= QUERY_METHOD_HIGHLIGHT;
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2447 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2448
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2449 result = XCODESYSMETH_OR_GIVEN (coding_system, query,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2450 (coding_system, buf, e, flags), Qunbound);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2451
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2452 if (UNBOUNDP (result))
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2453 {
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2454 signal_error (Qtext_conversion_error,
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2455 "Coding system doesn't say what it can encode",
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2456 XCODING_SYSTEM_NAME (coding_system));
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2457 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2458
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2459 result = (NILP (result)) ? Qt : values2 (Qnil, result);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2460
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2461 return unbind_to_1 (speccount, result);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2462 }
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2463
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
2464
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2465
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2466 /************************************************************************/
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2467 /* Chain methods */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2468 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2469
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2470 /* #### Need a way to create "opposite-direction" coding systems. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2471
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2472 /* Chain two or more coding systems together to make a combination coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2473 system. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2474
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2475 struct chain_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2476 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2477 /* List of coding systems, in decode order */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2478 Lisp_Object *chain;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2479 /* Number of coding systems in list */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2480 int count;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2481 /* Coding system to return as a result of canonicalize-after-coding */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2482 Lisp_Object canonicalize_after_coding;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2483 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2484
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2485 struct chain_coding_stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2486 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2487 int initted;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2488 /* Lstreams for chain coding system */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2489 Lisp_Object *lstreams;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2490 int lstream_count;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2491 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2492
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2493 static const struct memory_description chain_coding_system_description[] = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2494 { XD_INT, offsetof (struct chain_coding_system, count) },
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2495 { XD_BLOCK_PTR, offsetof (struct chain_coding_system, chain),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
2496 XD_INDIRECT (0, 0), { &lisp_object_description } },
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2497 { XD_LISP_OBJECT, offsetof (struct chain_coding_system,
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2498 canonicalize_after_coding) },
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2499 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2500 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2501
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2502 static const struct memory_description chain_coding_stream_description_1 [] = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2503 { XD_INT, offsetof (struct chain_coding_stream, lstream_count) },
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2504 { XD_BLOCK_PTR, offsetof (struct chain_coding_stream, lstreams),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
2505 XD_INDIRECT (0, 0), { &lisp_object_description } },
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2506 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2507 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2508
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2509 const struct sized_memory_description chain_coding_stream_description = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2510 sizeof (struct chain_coding_stream), chain_coding_stream_description_1
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2511 };
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2512
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2513 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (chain);
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
2514
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2515 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2516 chain_canonicalize (Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2517 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2518 /* We make use of the fact that this method is called at init time, after
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2519 properties have been parsed. init_method is called too early. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2520 /* #### It's not clear we need this whole chain-canonicalize mechanism
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2521 any more. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2522 Lisp_Object chain = Flist (XCODING_SYSTEM_CHAIN_COUNT (codesys),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2523 XCODING_SYSTEM_CHAIN_CHAIN (codesys));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2524 chain = Fcons (XCODING_SYSTEM_PRE_WRITE_CONVERSION (codesys),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2525 Fcons (XCODING_SYSTEM_POST_READ_CONVERSION (codesys),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2526 chain));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2527 Fputhash (chain, codesys, Vchain_canonicalize_hash_table);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2528 return codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2529 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2530
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2531 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2532 chain_canonicalize_after_coding (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2533 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2534 Lisp_Object cac =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2535 XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (str->codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2536 if (!NILP (cac))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2537 return cac;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2538 return str->codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2539 #if 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2540 struct chain_coding_stream *data = CODING_STREAM_TYPE_DATA (str, chain);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2541 Lisp_Object us = str->codesys, codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2542 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2543 Lisp_Object chain;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2544 Lisp_Object tail;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2545 int changed = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2546
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2547 /* #### It's not clear we need this whole chain-canonicalize mechanism
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2548 any more. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2549 if (str->direction == CODING_ENCODE || !data->initted)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2550 return us;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2551
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2552 chain = Flist (XCODING_SYSTEM_CHAIN_COUNT (us),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2553 XCODING_SYSTEM_CHAIN_CHAIN (us));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2554
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2555 tail = chain;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2556 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (us); i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2557 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2558 codesys = (coding_stream_canonicalize_after_coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2559 (XLSTREAM (data->lstreams[i])));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2560 if (!EQ (codesys, XCAR (tail)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2561 changed = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2562 XCAR (tail) = codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2563 tail = XCDR (tail);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2564 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2565
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2566 if (!changed)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2567 return us;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2568
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2569 chain = delq_no_quit (Qnil, chain);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2570
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2571 if (NILP (XCODING_SYSTEM_PRE_WRITE_CONVERSION (us)) &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2572 NILP (XCODING_SYSTEM_POST_READ_CONVERSION (us)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2573 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2574 if (NILP (chain))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2575 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2576 if (NILP (XCDR (chain)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2577 return XCAR (chain);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2578 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2579
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2580 codesys = Fgethash (Fcons (XCODING_SYSTEM_PRE_WRITE_CONVERSION (us),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2581 Fcons (XCODING_SYSTEM_POST_READ_CONVERSION (us),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2582 chain)), Vchain_canonicalize_hash_table,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2583 Qnil);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2584 if (!NILP (codesys))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2585 return codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2586 return make_internal_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2587 (us, "internal-chain-canonicalizer-wrapper",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2588 Qchain, Qunbound, list2 (Qchain, chain));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2589 #endif /* 0 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2590 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2591
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2592 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2593 chain_init (Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2594 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2595 XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (codesys) = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2596 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2597
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2598 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2599 chain_mark (Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2600 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2601 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2602
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2603 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (codesys); i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2604 mark_object (XCODING_SYSTEM_CHAIN_CHAIN (codesys)[i]);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2605 mark_object (XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (codesys));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2606 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2607
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2608 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2609 chain_mark_coding_stream_1 (struct chain_coding_stream *data)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2610 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2611 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2612
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2613 for (i = 0; i < data->lstream_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2614 mark_object (data->lstreams[i]);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2615 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2616
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2617 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2618 chain_mark_coding_stream (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2619 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2620 chain_mark_coding_stream_1 (CODING_STREAM_TYPE_DATA (str, chain));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2621 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2622
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2623 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2624 chain_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2625 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2626 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2627
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
2628 write_ascstring (printcharfun, "(");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2629 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (cs); i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2630 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
2631 write_ascstring (printcharfun, i == 0 ? "" : "->");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2632 print_coding_system_in_print_method (XCODING_SYSTEM_CHAIN_CHAIN (cs)[i],
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2633 printcharfun, escapeflag);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2634 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2635 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2636 Lisp_Object cac = XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (cs);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2637 if (!NILP (cac))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2638 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2639 if (i > 0)
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
2640 write_ascstring (printcharfun, " ");
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
2641 write_ascstring (printcharfun, "canonicalize-after-coding=");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2642 print_coding_system_in_print_method (cac, printcharfun, escapeflag);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2643 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2644 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2645
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
2646 write_ascstring (printcharfun, ")");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2647 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2648
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2649 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2650 chain_rewind_coding_stream_1 (struct chain_coding_stream *data)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2651 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2652 /* Each will rewind the next; there is always at least one stream (the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2653 dynarr stream at the end) if we're initted */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2654 if (data->initted)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2655 Lstream_rewind (XLSTREAM (data->lstreams[0]));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2656 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2657
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2658 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2659 chain_rewind_coding_stream (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2660 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2661 chain_rewind_coding_stream_1 (CODING_STREAM_TYPE_DATA (str, chain));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2662 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2663
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2664 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2665 chain_init_coding_streams_1 (struct chain_coding_stream *data,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2666 unsigned_char_dynarr *dst,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2667 int ncodesys, Lisp_Object *codesys,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2668 enum encode_decode direction)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2669 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2670 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2671 Lisp_Object lstream_out;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2672
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2673 data->lstream_count = ncodesys + 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2674 data->lstreams = xnew_array (Lisp_Object, data->lstream_count);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2675
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2676 lstream_out = make_dynarr_output_stream (dst);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2677 Lstream_set_buffering (XLSTREAM (lstream_out), LSTREAM_UNBUFFERED, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2678 data->lstreams[data->lstream_count - 1] = lstream_out;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2679
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2680 for (i = ncodesys - 1; i >= 0; i--)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2681 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2682 data->lstreams[i] =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2683 make_coding_output_stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2684 (XLSTREAM (lstream_out),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2685 codesys[direction == CODING_ENCODE ? ncodesys - (i + 1) : i],
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
2686 direction, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2687 lstream_out = data->lstreams[i];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2688 Lstream_set_buffering (XLSTREAM (lstream_out), LSTREAM_UNBUFFERED,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2689 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2690 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2691 data->initted = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2692 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2693
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2694 static Bytecount
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2695 chain_convert (struct coding_stream *str, const UExtbyte *src,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2696 unsigned_char_dynarr *dst, Bytecount n)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2697 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2698 struct chain_coding_stream *data = CODING_STREAM_TYPE_DATA (str, chain);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2699
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2700 if (str->eof)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2701 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2702 /* Each will close the next; there is always at least one stream (the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2703 dynarr stream at the end) if we're initted. We need to close now
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2704 because more data may be generated. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2705 if (data->initted)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2706 Lstream_close (XLSTREAM (data->lstreams[0]));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2707 return n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2708 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2709
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2710 if (!data->initted)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2711 chain_init_coding_streams_1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2712 (data, dst, XCODING_SYSTEM_CHAIN_COUNT (str->codesys),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2713 XCODING_SYSTEM_CHAIN_CHAIN (str->codesys), str->direction);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2714
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2715 if (Lstream_write (XLSTREAM (data->lstreams[0]), src, n) < 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2716 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2717 return n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2718 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2719
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2720 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2721 chain_finalize_coding_stream_1 (struct chain_coding_stream *data)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2722 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2723 if (data->lstreams)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2724 {
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2725 /* During GC, these objects are unmarked, and are about to be freed.
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2726 We do NOT want them on the free list, and that will cause lots of
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2727 nastiness including crashes. Just let them be freed normally. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2728 if (!gc_in_progress)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2729 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2730 int i;
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2731 /* Order of deletion is important here! Delete from the head of
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2732 the chain and work your way towards the tail. In general,
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2733 when you delete an object, there should be *NO* pointers to it
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2734 anywhere. Deleting back-to-front would be a problem because
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2735 there are pointers going forward. If there were pointers in
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2736 both directions, you'd have to disconnect the pointers to a
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2737 particular object before deleting it. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2738 for (i = 0; i < data->lstream_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2739 Lstream_delete (XLSTREAM ((data->lstreams)[i]));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2740 }
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
2741 xfree (data->lstreams);
5169
6c6d78781d59 cleanup of code related to xfree(), better KKCC backtrace capabilities, document XD_INLINE_LISP_OBJECT_BLOCK_PTR, fix some memory leaks, other code cleanup
Ben Wing <ben@xemacs.org>
parents: 5142
diff changeset
2742 data->lstreams = 0;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2743 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2744 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2745
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2746 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2747 chain_finalize_coding_stream (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2748 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2749 chain_finalize_coding_stream_1 (CODING_STREAM_TYPE_DATA (str, chain));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2750 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2751
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2752 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2753 chain_finalize (Lisp_Object c)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2754 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2755 if (XCODING_SYSTEM_CHAIN_CHAIN (c))
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
2756 xfree (XCODING_SYSTEM_CHAIN_CHAIN (c));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2757 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2758
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
2759 static int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2760 chain_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2761 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2762 if (EQ (key, Qchain))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2763 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2764 Lisp_Object *cslist;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2765 int count = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2766 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2767
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2768 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2769 EXTERNAL_LIST_LOOP_2 (elt, value)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2770 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2771 Fget_coding_system (elt);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2772 count++;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2773 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2774 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2775
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2776 cslist = xnew_array (Lisp_Object, count);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2777 XCODING_SYSTEM_CHAIN_CHAIN (codesys) = cslist;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2778
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2779 count = 0;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2780 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2781 EXTERNAL_LIST_LOOP_2 (elt, value)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2782 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2783 cslist[count] = Fget_coding_system (elt);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2784 count++;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2785 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
2786 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2787
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2788 XCODING_SYSTEM_CHAIN_COUNT (codesys) = count;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2789
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2790 for (i = 0; i < count - 1; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2791 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2792 if (decoding_source_sink_type_is_char (cslist[i], CODING_SINK) !=
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2793 decoding_source_sink_type_is_char (cslist[i + 1], CODING_SOURCE))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2794 invalid_argument_2 ("Sink of first must match source of second",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2795 cslist[i], cslist[i + 1]);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2796 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2797 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2798 else if (EQ (key, Qcanonicalize_after_coding))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2799 XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (codesys) =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2800 Fget_coding_system (value);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2801 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2802 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2803 return 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2804 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2805
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2806 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2807 chain_getprop (Lisp_Object coding_system, Lisp_Object prop)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2808 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2809 if (EQ (prop, Qchain))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2810 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2811 Lisp_Object result = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2812 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2813
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2814 for (i = 0; i < XCODING_SYSTEM_CHAIN_COUNT (coding_system); i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2815 result = Fcons (XCODING_SYSTEM_CHAIN_CHAIN (coding_system)[i],
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2816 result);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2817
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2818 return Fnreverse (result);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2819 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2820 else if (EQ (prop, Qcanonicalize_after_coding))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2821 return XCODING_SYSTEM_CHAIN_CANONICALIZE_AFTER_CODING (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2822 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2823 return Qunbound;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2824 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2825
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2826 static enum source_sink_type
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2827 chain_conversion_end_type (Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2828 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2829 Lisp_Object *cslist = XCODING_SYSTEM_CHAIN_CHAIN (codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2830 int n = XCODING_SYSTEM_CHAIN_COUNT (codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2831 int charp_source, charp_sink;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2832
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2833 if (n == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2834 return DECODES_BYTE_TO_BYTE; /* arbitrary */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2835 charp_source = decoding_source_sink_type_is_char (cslist[0], CODING_SOURCE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2836 charp_sink = decoding_source_sink_type_is_char (cslist[n - 1], CODING_SINK);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2837
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2838 switch (charp_source * 2 + charp_sink)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2839 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2840 case 0: return DECODES_BYTE_TO_BYTE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2841 case 1: return DECODES_BYTE_TO_CHARACTER;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2842 case 2: return DECODES_CHARACTER_TO_BYTE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2843 case 3: return DECODES_CHARACTER_TO_CHARACTER;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2844 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2845
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
2846 ABORT ();
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2847 return DECODES_BYTE_TO_BYTE;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2848 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2849
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2850
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2851 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2852 /* No-conversion methods */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2853 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2854
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2855 /* "No conversion"; used for binary files. We use quotes because there
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2856 really is some conversion being applied (it does byte<->char
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2857 conversion), but it appears to the user as if the text is read in
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2858 without conversion.
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2859
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2860 #### Shouldn't we _call_ it that, then? And while we're at it,
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2861 separate it into "to_internal" and "to_external"? */
5776
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2862
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2863 struct no_conversion_coding_stream
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2864 {
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2865 /* Number of characters seen when decoding. */
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2866 Charcount characters_seen;
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2867 };
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2868
5777
ccaa851ae712 Rework description of no_conversion coding system, avoiding pdump confusion.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5776
diff changeset
2869 DEFINE_CODING_SYSTEM_TYPE (no_conversion);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2870
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2871 /* This is used when reading in "binary" files -- i.e. files that may
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2872 contain all 256 possible byte values and that are not to be
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2873 interpreted as being in any particular encoding. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2874 static Bytecount
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2875 no_conversion_convert (struct coding_stream *str,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2876 const UExtbyte *src,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2877 unsigned_char_dynarr *dst, Bytecount n)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2878 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2879 UExtbyte c;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2880 unsigned int ch = str->ch;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2881 Bytecount orign = n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2882
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2883 if (str->direction == CODING_DECODE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2884 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2885 while (n--)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2886 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2887 c = *src++;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2888
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2889 DECODE_ADD_BINARY_CHAR (c, dst);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2890 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2891
5776
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2892 CODING_STREAM_TYPE_DATA (str, no_conversion)->characters_seen
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2893 += orign;
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2894
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2895 if (str->eof)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2896 DECODE_OUTPUT_PARTIAL_CHAR (ch, dst);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2897 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2898 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2899 {
5774
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2900 const Ibyte *bend = (const Ibyte *)src + n;
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2901
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2902 while (n > 0)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2903 {
5774
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2904 if (byte_ascii_p (*src))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2905 {
5774
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2906 const Ibyte *nonascii = skip_ascii ((Ibyte *)src, bend);
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2907
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2908 Dynarr_add_many (dst, src, nonascii - src);
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2909 n -= nonascii - src;
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2910
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2911 src = nonascii;
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2912 if (n < 1)
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2913 {
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2914 break;
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2915 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2916 }
5774
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2917
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2918 n--, c = *src++;
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2919
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2920 #ifdef MULE
5774
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2921 if (ibyte_leading_byte_p (c))
7a538e1a4676 Use skip_ascii() in no_conversion_convert() when encoding.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5682
diff changeset
2922 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2923 assert (ch == 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2924 if (c == LEADING_BYTE_LATIN_ISO8859_1 ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2925 c == LEADING_BYTE_CONTROL_1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2926 ch = c;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2927 else
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
2928 /* #### This is just plain unacceptable. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2929 Dynarr_add (dst, '~'); /* untranslatable character */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2930 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2931 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2932 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2933 if (ch == LEADING_BYTE_LATIN_ISO8859_1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2934 Dynarr_add (dst, c);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2935 else if (ch == LEADING_BYTE_CONTROL_1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2936 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2937 assert (c < 0xC0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2938 Dynarr_add (dst, c - 0x20);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2939 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2940 /* else it should be the second or third byte of an
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2941 untranslatable character, so ignore it */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2942 ch = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2943 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2944 #endif /* MULE */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2945
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2946 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2947 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2948
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2949 str->ch = ch;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2950 return orign;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2951 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2952
5776
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2953 static Charcount
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2954 no_conversion_character_tell (struct coding_stream *str)
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2955 {
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2956 return CODING_STREAM_TYPE_DATA (str, no_conversion)->characters_seen;
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2957 }
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
2958
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2959 DEFINE_DETECTOR (no_conversion);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2960 DEFINE_DETECTOR_CATEGORY (no_conversion, no_conversion);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2961
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2962 struct no_conversion_detector
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2963 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2964 int dummy;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2965 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2966
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2967 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
2968 no_conversion_detect (struct detection_state *st, const UExtbyte *UNUSED (src),
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
2969 Bytecount UNUSED (n))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2970 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2971 /* Hack until we get better handling of this stuff! */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2972 DET_RESULT (st, no_conversion) = DET_SLIGHTLY_LIKELY;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2973 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2974
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2975
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2976 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2977 /* Convert-eol methods */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2978 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2979
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2980 /* This is used to handle end-of-line (EOL) differences. It is
2819
18bd0414af22 [xemacs-hg @ 2005-06-19 21:08:29 by aidan]
aidan
parents: 2720
diff changeset
2981 character-to-character, and works (when encoding) *BEFORE* sending data to
18bd0414af22 [xemacs-hg @ 2005-06-19 21:08:29 by aidan]
aidan
parents: 2720
diff changeset
2982 the main encoding routine -- thus, that routine must handle different EOL
18bd0414af22 [xemacs-hg @ 2005-06-19 21:08:29 by aidan]
aidan
parents: 2720
diff changeset
2983 types itself if it does line-oriented type processing. This is unavoidable
18bd0414af22 [xemacs-hg @ 2005-06-19 21:08:29 by aidan]
aidan
parents: 2720
diff changeset
2984 because we don't know whether the output of the main encoding routine is
18bd0414af22 [xemacs-hg @ 2005-06-19 21:08:29 by aidan]
aidan
parents: 2720
diff changeset
2985 ASCII compatible (UTF-16 is definitely not, for example). [[ sjt sez this
18bd0414af22 [xemacs-hg @ 2005-06-19 21:08:29 by aidan]
aidan
parents: 2720
diff changeset
2986 is bogus. There should be _no_ EOL processing (or processing of any kind)
18bd0414af22 [xemacs-hg @ 2005-06-19 21:08:29 by aidan]
aidan
parents: 2720
diff changeset
2987 after conversion to external. ]]
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2988
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
2989 There is one parameter: `subtype', either `cr', `lf', `crlf', or nil.
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2990 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2991
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2992 struct convert_eol_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2993 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2994 enum eol_type subtype;
2132
34ca43a57692 [xemacs-hg @ 2004-06-16 12:01:17 by malcolmp]
malcolmp
parents: 1726
diff changeset
2995 int dummy; /* On some architectures (eg ia64) the portable dumper can
34ca43a57692 [xemacs-hg @ 2004-06-16 12:01:17 by malcolmp]
malcolmp
parents: 1726
diff changeset
2996 produce unaligned access errors without this field. Probably
34ca43a57692 [xemacs-hg @ 2004-06-16 12:01:17 by malcolmp]
malcolmp
parents: 1726
diff changeset
2997 because the combined structure of this structure and
34ca43a57692 [xemacs-hg @ 2004-06-16 12:01:17 by malcolmp]
malcolmp
parents: 1726
diff changeset
2998 Lisp_Coding_System is not properly aligned. */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
2999 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3000
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3001 #define CODING_SYSTEM_CONVERT_EOL_SUBTYPE(codesys) \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3002 (CODING_SYSTEM_TYPE_DATA (codesys, convert_eol)->subtype)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3003 #define XCODING_SYSTEM_CONVERT_EOL_SUBTYPE(codesys) \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3004 (XCODING_SYSTEM_TYPE_DATA (codesys, convert_eol)->subtype)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3005
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3006 struct convert_eol_coding_stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3007 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3008 enum eol_type actual;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3009 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3010
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3011 static const struct memory_description
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3012 convert_eol_coding_system_description[] = {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3013 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3014 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3015
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3016 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (convert_eol);
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3017
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3018 static void
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
3019 convert_eol_print (Lisp_Object cs, Lisp_Object printcharfun,
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
3020 int UNUSED (escapeflag))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3021 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3022 struct convert_eol_coding_system *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3023 XCODING_SYSTEM_TYPE_DATA (cs, convert_eol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3024
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3025 write_fmt_string (printcharfun, "(%s)",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3026 data->subtype == EOL_LF ? "lf" :
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3027 data->subtype == EOL_CRLF ? "crlf" :
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3028 data->subtype == EOL_CR ? "cr" :
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
3029 data->subtype == EOL_AUTODETECT ? "nil" :
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
3030 (ABORT(), ""));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3031 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3032
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3033 static enum source_sink_type
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
3034 convert_eol_conversion_end_type (Lisp_Object UNUSED (codesys))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3035 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3036 return DECODES_CHARACTER_TO_CHARACTER;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3037 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3038
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3039 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3040 convert_eol_putprop (Lisp_Object codesys,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3041 Lisp_Object key,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3042 Lisp_Object value)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3043 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3044 struct convert_eol_coding_system *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3045 XCODING_SYSTEM_TYPE_DATA (codesys, convert_eol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3046
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3047 if (EQ (key, Qsubtype))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3048 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3049 if (EQ (value, Qlf) /* || EQ (value, Qunix) */)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3050 data->subtype = EOL_LF;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3051 else if (EQ (value, Qcrlf) /* || EQ (value, Qdos) */)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3052 data->subtype = EOL_CRLF;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3053 else if (EQ (value, Qcr) /* || EQ (value, Qmac) */)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3054 data->subtype = EOL_CR;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
3055 else if (EQ (value, Qnil))
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3056 data->subtype = EOL_AUTODETECT;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3057 else invalid_constant ("Unrecognized eol type", value);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3058 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3059 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3060 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3061 return 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3062 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3063
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3064 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3065 convert_eol_getprop (Lisp_Object coding_system, Lisp_Object prop)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3066 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3067 struct convert_eol_coding_system *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3068 XCODING_SYSTEM_TYPE_DATA (coding_system, convert_eol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3069
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3070 if (EQ (prop, Qsubtype))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3071 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3072 switch (data->subtype)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3073 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3074 case EOL_LF: return Qlf;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3075 case EOL_CRLF: return Qcrlf;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3076 case EOL_CR: return Qcr;
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
3077 case EOL_AUTODETECT: return Qnil;
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
3078 default: ABORT ();
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3079 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3080 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3081
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3082 return Qunbound;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3083 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3084
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3085 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3086 convert_eol_init_coding_stream (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3087 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3088 struct convert_eol_coding_stream *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3089 CODING_STREAM_TYPE_DATA (str, convert_eol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3090 data->actual = XCODING_SYSTEM_CONVERT_EOL_SUBTYPE (str->codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3091 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3092
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3093 static Bytecount
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
3094 convert_eol_convert (struct coding_stream *str, const Ibyte *src,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3095 unsigned_char_dynarr *dst, Bytecount n)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3096 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3097 if (str->direction == CODING_DECODE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3098 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3099 struct convert_eol_coding_stream *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3100 CODING_STREAM_TYPE_DATA (str, convert_eol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3101
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3102 if (data->actual == EOL_AUTODETECT)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3103 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3104 Bytecount n2 = n;
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
3105 const Ibyte *src2 = src;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3106
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3107 for (; n2; n2--)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3108 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
3109 Ibyte c = *src2++;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3110 if (c == '\n')
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3111 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3112 data->actual = EOL_LF;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3113 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3114 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3115 else if (c == '\r')
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3116 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3117 if (n2 == 1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3118 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3119 /* If we're seeing a '\r' at the end of the data, then
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3120 reject the '\r' right now so it doesn't become an
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3121 issue in the code below -- unless we're at the end of
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3122 the stream, in which case we can't do that (because
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3123 then the '\r' will never get written out), and in any
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3124 case we should be recognizing it at EOL_CR format. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3125 if (str->eof)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3126 data->actual = EOL_CR;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3127 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3128 n--;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3129 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3130 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3131 else if (*src2 == '\n')
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3132 data->actual = EOL_CRLF;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3133 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3134 data->actual = EOL_CR;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3135 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3136 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3137 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3138 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3139
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3140 /* str->eof is set, the caller reached EOF on the other end and has
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3141 no new data to give us. The only data we get is the data we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3142 rejected from last time. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3143 if (data->actual == EOL_LF || data->actual == EOL_AUTODETECT ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3144 (str->eof))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3145 Dynarr_add_many (dst, src, n);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3146 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3147 {
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
3148 const Ibyte *end = src + n;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3149 while (1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3150 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3151 /* Find the next section with no \r and add it. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
3152 const Ibyte *runstart = src;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
3153 src = (Ibyte *) memchr (src, '\r', end - src);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3154 if (!src)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3155 src = end;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3156 Dynarr_add_many (dst, runstart, src - runstart);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3157 /* Stop if at end ... */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3158 if (src == end)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3159 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3160 /* ... else, translate as necessary. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3161 src++;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3162 if (data->actual == EOL_CR)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3163 Dynarr_add (dst, '\n');
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3164 /* We need to be careful here with CRLF. If we see a CR at the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3165 end of the data, we don't know if it's part of a CRLF, so we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3166 reject it. Otherwise: If it's part of a CRLF, eat it and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3167 loop; the following LF gets added next time around. If it's
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3168 not part of a CRLF, add the CR and loop. The following
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3169 character will be processed in the next loop iteration. This
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3170 correctly handles a sequence like CR+CR+LF. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3171 else if (src == end)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3172 return n - 1; /* reject the CR at the end; we'll get it again
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3173 next time the convert method is called */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3174 else if (*src != '\n')
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3175 Dynarr_add (dst, '\r');
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3176 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3177 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3178
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3179 return n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3180 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3181 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3182 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3183 enum eol_type subtype =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3184 XCODING_SYSTEM_CONVERT_EOL_SUBTYPE (str->codesys);
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
3185 const Ibyte *end = src + n;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3186
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3187 /* We try to be relatively efficient here. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3188 if (subtype == EOL_LF)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3189 Dynarr_add_many (dst, src, n);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3190 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3191 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3192 while (1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3193 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3194 /* Find the next section with no \n and add it. */
867
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
3195 const Ibyte *runstart = src;
804517e16990 [xemacs-hg @ 2002-06-05 09:54:39 by ben]
ben
parents: 851
diff changeset
3196 src = (Ibyte *) memchr (src, '\n', end - src);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3197 if (!src)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3198 src = end;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3199 Dynarr_add_many (dst, runstart, src - runstart);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3200 /* Stop if at end ... */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3201 if (src == end)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3202 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3203 /* ... else, skip over \n and add its translation. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3204 src++;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3205 Dynarr_add (dst, '\r');
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3206 if (subtype == EOL_CRLF)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3207 Dynarr_add (dst, '\n');
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3208 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3209 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3210
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3211 return n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3212 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3213 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3214
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3215 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3216 convert_eol_canonicalize_after_coding (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3217 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3218 struct convert_eol_coding_stream *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3219 CODING_STREAM_TYPE_DATA (str, convert_eol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3220
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3221 if (str->direction == CODING_ENCODE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3222 return str->codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3223
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3224 switch (data->actual)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3225 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3226 case EOL_LF: return Fget_coding_system (Qconvert_eol_lf);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3227 case EOL_CRLF: return Fget_coding_system (Qconvert_eol_crlf);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3228 case EOL_CR: return Fget_coding_system (Qconvert_eol_cr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3229 case EOL_AUTODETECT: return str->codesys;
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
3230 default: ABORT (); return Qnil;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3231 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3232 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3233
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3234
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3235 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3236 /* Undecided methods */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3237 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3238
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3239 /* Do autodetection. We can autodetect the EOL type only, the coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3240 system only, or both. We only do autodetection when decoding; when
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3241 encoding, we just pass the data through.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3242
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3243 When doing just EOL detection, a coding system can be specified; if so,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3244 we will decode this data through the coding system before doing EOL
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3245 detection. The reason for specifying this is so that
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3246 canonicalize-after-coding works: We will canonicalize the specified
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3247 coding system into the appropriate EOL type. When doing both coding and
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3248 EOL detection, we do similar canonicalization, and also catch situations
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3249 where the EOL type is overspecified, i.e. the detected coding system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3250 specifies an EOL type, and either switch to the equivalent
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3251 non-EOL-processing coding system (if possible), or terminate EOL
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3252 detection and use the specified EOL type. This prevents data from being
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3253 EOL-processed twice.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3254 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3255
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3256 struct undecided_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3257 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3258 int do_eol, do_coding;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3259 Lisp_Object cs;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3260 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3261
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3262 struct undecided_coding_stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3263 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3264 Lisp_Object actual;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3265 /* Either 2 or 3 lstreams here; see undecided_convert */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3266 struct chain_coding_stream c;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3267
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3268 struct detection_state *st;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3269 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3270
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3271 static const struct memory_description undecided_coding_system_description[] = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3272 { XD_LISP_OBJECT, offsetof (struct undecided_coding_system, cs) },
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3273 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3274 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3275
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3276 static const struct memory_description undecided_coding_stream_description_1 [] = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3277 { XD_LISP_OBJECT, offsetof (struct undecided_coding_stream, actual) },
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
3278 { XD_BLOCK_ARRAY, offsetof (struct undecided_coding_stream, c),
2551
9f70af3ac939 [xemacs-hg @ 2005-02-03 16:14:02 by james]
james
parents: 2531
diff changeset
3279 1, { &chain_coding_stream_description } },
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3280 { XD_END }
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3281 };
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3282
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3283 const struct sized_memory_description undecided_coding_stream_description = {
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3284 sizeof (struct undecided_coding_stream), undecided_coding_stream_description_1
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3285 };
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3286
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3287 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (undecided);
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3288
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3289 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3290 undecided_init (Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3291 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3292 struct undecided_coding_system *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3293 XCODING_SYSTEM_TYPE_DATA (codesys, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3294
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3295 data->cs = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3296 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3297
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3298 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3299 undecided_mark (Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3300 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3301 struct undecided_coding_system *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3302 XCODING_SYSTEM_TYPE_DATA (codesys, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3303
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3304 mark_object (data->cs);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3305 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3306
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3307 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3308 undecided_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3309 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3310 struct undecided_coding_system *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3311 XCODING_SYSTEM_TYPE_DATA (cs, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3312 int need_space = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3313
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
3314 write_ascstring (printcharfun, "(");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3315 if (data->do_eol)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3316 {
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
3317 write_ascstring (printcharfun, "do-eol");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3318 need_space = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3319 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3320 if (data->do_coding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3321 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3322 if (need_space)
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
3323 write_ascstring (printcharfun, " ");
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
3324 write_ascstring (printcharfun, "do-coding");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3325 need_space = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3326 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3327 if (!NILP (data->cs))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3328 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3329 if (need_space)
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
3330 write_ascstring (printcharfun, " ");
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
3331 write_ascstring (printcharfun, "coding-system=");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3332 print_coding_system_in_print_method (data->cs, printcharfun, escapeflag);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3333 }
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
3334 write_ascstring (printcharfun, ")");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3335 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3336
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3337 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3338 undecided_mark_coding_stream (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3339 {
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3340 mark_object (CODING_STREAM_TYPE_DATA (str, undecided)->actual);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3341 chain_mark_coding_stream_1 (&CODING_STREAM_TYPE_DATA (str, undecided)->c);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3342 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3343
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3344 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3345 undecided_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3346 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3347 struct undecided_coding_system *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3348 XCODING_SYSTEM_TYPE_DATA (codesys, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3349
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3350 if (EQ (key, Qdo_eol))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3351 data->do_eol = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3352 else if (EQ (key, Qdo_coding))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3353 data->do_coding = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3354 else if (EQ (key, Qcoding_system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3355 data->cs = get_coding_system_for_text_file (value, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3356 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3357 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3358 return 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3359 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3360
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3361 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3362 undecided_getprop (Lisp_Object codesys, Lisp_Object prop)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3363 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3364 struct undecided_coding_system *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3365 XCODING_SYSTEM_TYPE_DATA (codesys, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3366
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3367 if (EQ (prop, Qdo_eol))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3368 return data->do_eol ? Qt : Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3369 if (EQ (prop, Qdo_coding))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3370 return data->do_coding ? Qt : Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3371 if (EQ (prop, Qcoding_system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3372 return data->cs;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3373 return Qunbound;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3374 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3375
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3376 static struct detection_state *
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3377 allocate_detection_state (void)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3378 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3379 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3380 Bytecount size = MAX_ALIGN_SIZE (sizeof (struct detection_state));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3381 struct detection_state *block;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3382
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3383 for (i = 0; i < coding_detector_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3384 size += MAX_ALIGN_SIZE (Dynarr_at (all_coding_detectors, i).data_size);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3385
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3386 block = (struct detection_state *) xmalloc_and_zero (size);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3387
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3388 size = MAX_ALIGN_SIZE (sizeof (struct detection_state));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3389 for (i = 0; i < coding_detector_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3390 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3391 block->data_offset[i] = size;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3392 size += MAX_ALIGN_SIZE (Dynarr_at (all_coding_detectors, i).data_size);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3393 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3394
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3395 return block;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3396 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3397
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3398 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3399 free_detection_state (struct detection_state *st)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3400 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3401 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3402
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3403 for (i = 0; i < coding_detector_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3404 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3405 if (Dynarr_at (all_coding_detectors, i).finalize_detection_state_method)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3406 Dynarr_at (all_coding_detectors, i).finalize_detection_state_method
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3407 (st);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3408 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3409
4976
16112448d484 Rename xfree(FOO, TYPE) -> xfree(FOO)
Ben Wing <ben@xemacs.org>
parents: 4967
diff changeset
3410 xfree (st);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3411 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3412
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3413 static int
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3414 coding_category_symbol_to_id (Lisp_Object symbol)
428
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 int i;
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 CHECK_SYMBOL (symbol);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3419 for (i = 0; i < coding_detector_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3420 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3421 detector_category_dynarr *cats =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3422 Dynarr_at (all_coding_detectors, i).cats;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3423 int j;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3424
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3425 for (j = 0; j < Dynarr_length (cats); j++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3426 if (EQ (Dynarr_at (cats, j).sym, symbol))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3427 return Dynarr_at (cats, j).id;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3428 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3429
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
3430 invalid_constant ("Unrecognized coding category", symbol);
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
3431 RETURN_NOT_REACHED (0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3432 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3433
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3434 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3435 coding_category_id_to_symbol (int id)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3436 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3437 int i;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3438
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3439 for (i = 0; i < coding_detector_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3440 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3441 detector_category_dynarr *cats =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3442 Dynarr_at (all_coding_detectors, i).cats;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3443 int j;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3444
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3445 for (j = 0; j < Dynarr_length (cats); j++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3446 if (id == Dynarr_at (cats, j).id)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3447 return Dynarr_at (cats, j).sym;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3448 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3449
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
3450 ABORT ();
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3451 return Qnil; /* (usually) not reached */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3452 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3453
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3454 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3455 detection_result_number_to_symbol (enum detection_result result)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3456 {
1494
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3457 /* let compiler warn if not all enumerators are handled */
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3458 switch (result) {
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3459 #define FROB(sym, num) case num: return (sym)
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3460 FROB (Qnear_certainty, DET_NEAR_CERTAINTY);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3461 FROB (Qquite_probable, DET_QUITE_PROBABLE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3462 FROB (Qsomewhat_likely, DET_SOMEWHAT_LIKELY);
1494
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3463 FROB (Qslightly_likely, DET_SLIGHTLY_LIKELY);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3464 FROB (Qas_likely_as_unlikely, DET_AS_LIKELY_AS_UNLIKELY);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3465 FROB (Qsomewhat_unlikely, DET_SOMEWHAT_UNLIKELY);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3466 FROB (Qquite_improbable, DET_QUITE_IMPROBABLE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3467 FROB (Qnearly_impossible, DET_NEARLY_IMPOSSIBLE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3468 #undef FROB
1494
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3469 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3470
2500
3d8143fc88e1 [xemacs-hg @ 2005-01-24 23:33:30 by ben]
ben
parents: 2367
diff changeset
3471 ABORT ();
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3472 return Qnil; /* (usually) not reached */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3473 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3474
778
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 771
diff changeset
3475 #if 0 /* not used */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3476 static enum detection_result
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3477 detection_result_symbol_to_number (Lisp_Object symbol)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3478 {
1494
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3479 /* using switch here would be bad style, and doesn't help */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3480 #define FROB(sym, num) if (EQ (symbol, sym)) return (num)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3481 FROB (Qnear_certainty, DET_NEAR_CERTAINTY);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3482 FROB (Qquite_probable, DET_QUITE_PROBABLE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3483 FROB (Qsomewhat_likely, DET_SOMEWHAT_LIKELY);
1494
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3484 FROB (Qslightly_likely, DET_SLIGHTLY_LIKELY);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3485 FROB (Qas_likely_as_unlikely, DET_AS_LIKELY_AS_UNLIKELY);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3486 FROB (Qsomewhat_unlikely, DET_SOMEWHAT_UNLIKELY);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3487 FROB (Qquite_improbable, DET_QUITE_IMPROBABLE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3488 FROB (Qnearly_impossible, DET_NEARLY_IMPOSSIBLE);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3489 #undef FROB
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3490
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3491 invalid_constant ("Unrecognized detection result", symbol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3492 return ((enum detection_result) 0); /* not reached */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3493 }
778
2923009caf47 [xemacs-hg @ 2002-03-16 10:38:59 by ben]
ben
parents: 771
diff changeset
3494 #endif /* 0 */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3495
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3496 /* Set all detection results for a given detector to a specified value. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3497 void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3498 set_detection_results (struct detection_state *st, int detector, int given)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3499 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3500 detector_category_dynarr *cats =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3501 Dynarr_at (all_coding_detectors, detector).cats;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3502 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3503
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3504 for (i = 0; i < Dynarr_length (cats); i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3505 st->categories[Dynarr_at (cats, i).id] = given;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3506 }
428
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 static int
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3509 acceptable_control_char_p (int c)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3510 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3511 switch (c)
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 /* Allow and ignore control characters that you might
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3514 reasonably see in a text file */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3515 case '\r':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3516 case '\n':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3517 case '\t':
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3518 case 7: /* bell */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3519 case 8: /* backspace */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3520 case 11: /* vertical tab */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3521 case 12: /* form feed */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3522 case 26: /* MS-DOS C-z junk */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3523 case 31: /* '^_' -- for info */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3524 return 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3525 default:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3526 return 0;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3527 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3528 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3529
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3530 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3531
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3532 static UExtbyte
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3533 hex_digit_to_char (int digit)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3534 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3535 if (digit < 10)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3536 return digit + '0';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3537 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3538 return digit - 10 + 'A';
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3539 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3540
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3541 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3542 output_bytes_in_ascii_and_hex (const UExtbyte *src, Bytecount n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3543 {
3425
ca9976dc328e [xemacs-hg @ 2006-05-25 08:04:56 by aidan]
aidan
parents: 3420
diff changeset
3544 Extbyte *ascii = alloca_array (Extbyte, n + 1);
ca9976dc328e [xemacs-hg @ 2006-05-25 08:04:56 by aidan]
aidan
parents: 3420
diff changeset
3545 Extbyte *hex = alloca_array (Extbyte, 3 * n + 1);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3546 int i;
3413
e13aec8357bb [xemacs-hg @ 2006-05-22 20:27:57 by aidan]
aidan
parents: 3302
diff changeset
3547 DECLARE_EISTRING (eistr_ascii);
e13aec8357bb [xemacs-hg @ 2006-05-22 20:27:57 by aidan]
aidan
parents: 3302
diff changeset
3548 DECLARE_EISTRING (eistr_hex);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3549
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3550 for (i = 0; i < n; i++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3551 {
3425
ca9976dc328e [xemacs-hg @ 2006-05-25 08:04:56 by aidan]
aidan
parents: 3420
diff changeset
3552 Extbyte c = src[i];
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3553 if (c < 0x20)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3554 ascii[i] = '.';
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3555 else
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3556 ascii[i] = c;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3557 hex[3 * i] = hex_digit_to_char (c >> 4);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3558 hex[3 * i + 1] = hex_digit_to_char (c & 0xF);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3559 hex[3 * i + 2] = ' ';
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3560 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3561 ascii[i] = '\0';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3562 hex[3 * i - 1] = '\0';
3413
e13aec8357bb [xemacs-hg @ 2006-05-22 20:27:57 by aidan]
aidan
parents: 3302
diff changeset
3563
e13aec8357bb [xemacs-hg @ 2006-05-22 20:27:57 by aidan]
aidan
parents: 3302
diff changeset
3564 eicpy_ext(eistr_hex, hex, Qbinary);
e13aec8357bb [xemacs-hg @ 2006-05-22 20:27:57 by aidan]
aidan
parents: 3302
diff changeset
3565 eicpy_ext(eistr_ascii, ascii, Qbinary);
e13aec8357bb [xemacs-hg @ 2006-05-22 20:27:57 by aidan]
aidan
parents: 3302
diff changeset
3566
3425
ca9976dc328e [xemacs-hg @ 2006-05-25 08:04:56 by aidan]
aidan
parents: 3420
diff changeset
3567 stderr_out ("%s %s", eidata(eistr_ascii), eidata(eistr_hex));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3568 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3569
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3570 #endif /* DEBUG_XEMACS */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3571
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3572 /* Attempt to determine the encoding of the given text. Before calling
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3573 this function for the first time, you must zero out the detection state.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3574
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3575 Returns:
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3576
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3577 0 == keep going
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3578 1 == stop
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3579 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3580
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3581 static int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3582 detect_coding_type (struct detection_state *st, const UExtbyte *src,
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3583 Bytecount n, int err)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3584 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3585 Bytecount n2 = n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3586 const UExtbyte *src2 = src;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3587 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3588
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3589 if (n < 0)
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3590 signal_error (Qtext_conversion_error,
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3591 "Error reading file to determine coding system",
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3592 err ? lisp_strerror (err) : Qnil);
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3593
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3594 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3595 if (!NILP (Vdebug_coding_detection))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3596 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3597 int bytes = min (16, n);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3598 stderr_out ("detect_coding_type: processing %ld bytes\n", n);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3599 stderr_out ("First %d: ", bytes);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3600 output_bytes_in_ascii_and_hex (src, bytes);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3601 stderr_out ("\nLast %d: ", bytes);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3602 output_bytes_in_ascii_and_hex (src + n - bytes, bytes);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3603 stderr_out ("\n");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3604 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3605 #endif /* DEBUG_XEMACS */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3606 if (!st->seen_non_ascii)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3607 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3608 for (; n2; n2--, src2++)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3609 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3610 UExtbyte c = *src2;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3611 if ((c < 0x20 && !acceptable_control_char_p (c)) || c >= 0x80)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3612 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3613 st->seen_non_ascii = 1;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3614 break;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3615 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3616 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3617 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3618
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3619 for (i = 0; i < coding_detector_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3620 Dynarr_at (all_coding_detectors, i).detect_method (st, src, n);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3621
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3622 st->bytes_seen += n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3623
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3624 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3625 if (!NILP (Vdebug_coding_detection))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3626 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3627 stderr_out ("seen_non_ascii: %d\n", st->seen_non_ascii);
1494
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3628 if (coding_detector_category_count <= 0)
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3629 stderr_out ("found %d detector categories\n",
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3630 coding_detector_category_count);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3631 for (i = 0; i < coding_detector_category_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3632 stderr_out_lisp
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3633 ("%s: %s\n",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3634 2,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3635 coding_category_id_to_symbol (i),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3636 detection_result_number_to_symbol ((enum detection_result)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3637 st->categories[i]));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3638 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3639 #endif /* DEBUG_XEMACS */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3640
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3641 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3642 int not_unlikely = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3643 int retval;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3644
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3645 for (i = 0; i < coding_detector_category_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3646 if (st->categories[i] >= 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3647 not_unlikely++;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3648
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3649 retval = (not_unlikely <= 1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3650 #if 0 /* this is bogus */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3651 || st->bytes_seen >= MAX_BYTES_PROCESSED_FOR_DETECTION
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3652 #endif
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3653 );
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3654
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3655 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3656 if (!NILP (Vdebug_coding_detection))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3657 stderr_out ("detect_coding_type: returning %d (%s)\n",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3658 retval, retval ? "stop" : "keep going");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3659 #endif /* DEBUG_XEMACS */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3660
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3661 return retval;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3662 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3663 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3664
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3665 static Lisp_Object
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3666 detected_coding_system (struct detection_state *st)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3667 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3668 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3669 int even = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3670
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3671 if (st->seen_non_ascii)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3672 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3673 for (i = 0; i < coding_detector_category_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3674 if (st->categories[i] != DET_AS_LIKELY_AS_UNLIKELY)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3675 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3676 even = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3677 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3678 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3679 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3680
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3681 /* #### Here we are ignoring the results of detection when it's all
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3682 ASCII. This is obviously a bad thing. But we need to fix up the
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3683 existing detection methods somewhat before we can switch. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3684 if (even)
428
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 /* If the file was entirely or basically ASCII, use the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3687 default value of `buffer-file-coding-system'. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3688 Lisp_Object retval =
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3689 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3690 if (!NILP (retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3691 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3692 retval = find_coding_system_for_text_file (retval, 0);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3693 if (NILP (retval))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3694 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3695 warn_when_safe
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3696 (Qbad_variable, Qwarning,
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3697 "Invalid `default-buffer-file-coding-system', set to nil");
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3698 XBUFFER (Vbuffer_defaults)->buffer_file_coding_system = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3699 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3700 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3701 if (NILP (retval))
4100
d1cf2b9c4dfd [xemacs-hg @ 2007-08-06 14:50:39 by michaels]
michaels
parents: 4072
diff changeset
3702 retval = Fget_coding_system (Qbinary);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3703 return retval;
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 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3706 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3707 int likelihood;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3708 Lisp_Object retval = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3709
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3710 /* Look through the coding categories first by likelihood and then by
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3711 priority and find the first one that is allowed. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3712
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3713 for (likelihood = DET_HIGHEST; likelihood >= DET_LOWEST; likelihood--)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3714 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3715 for (i = 0; i < coding_detector_category_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3716 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3717 int cat = coding_category_by_priority[i];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3718 if (st->categories[cat] == likelihood &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3719 !NILP (coding_category_system[cat]))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3720 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3721 retval = (get_coding_system_for_text_file
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3722 (coding_category_system[cat], 0));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3723 if (likelihood < DET_AS_LIKELY_AS_UNLIKELY)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3724 warn_when_safe_lispobj
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3725 (intern ("detection"),
793
e38acbeb1cae [xemacs-hg @ 2002-03-29 04:46:17 by ben]
ben
parents: 778
diff changeset
3726 Qwarning,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3727 emacs_sprintf_string_lisp
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3728 (
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3729 "Detected coding %s is unlikely to be correct (likelihood == `%s')",
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3730 Qnil, 2, XCODING_SYSTEM_NAME (retval),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3731 detection_result_number_to_symbol
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3732 ((enum detection_result) likelihood)));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3733 return retval;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3734 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3735 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3736 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3737
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3738 return Fget_coding_system (Qraw_text);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3739 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3740 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3741
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3742 /* Look for a coding system in the string (skipping over leading
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3743 blanks). If found, return it, otherwise nil. */
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3744
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3745 static Lisp_Object
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3746 snarf_coding_system (const UExtbyte *p, Bytecount len,
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3747 Boolint find_coding_system_p)
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3748 {
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3749 Bytecount n;
2531
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3750 UExtbyte *name;
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3751
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3752 while (*p == ' ' || *p == '\t') p++, len--;
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3753 len = min (len, 1000);
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3754 name = alloca_ibytes (len + 1);
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3755 memcpy (name, p, len);
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3756 name[len] = '\0';
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3757
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3758 /* Get coding system name */
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3759 /* Characters valid in a MIME charset name (rfc 1521),
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3760 and in a Lisp symbol name. */
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3761 n = qxestrspn (name,
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3762 "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3763 "abcdefghijklmnopqrstuvwxyz"
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3764 "0123456789"
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3765 "!$%&*+-.^_{|}~");
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3766 if (n > 0)
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3767 {
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3768 name[n] = '\0';
4953
304aebb79cd3 function renamings to track names of char typedefs
Ben Wing <ben@xemacs.org>
parents: 4952
diff changeset
3769 /* This call to intern_istring() is OK because we already verified that
2531
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3770 there are only ASCII characters in the string */
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3771 if (find_coding_system_p)
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3772 {
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3773 return
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3774 find_coding_system_for_text_file (intern_istring ((Ibyte *) name),
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3775 0);
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3776 }
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3777 else
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3778 {
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3779 return build_ascstring ((const Ascbyte *) name);
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3780 }
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3781 }
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3782
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3783 return Qnil;
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3784 }
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3785
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3786 /* Given a seekable read stream and potential coding system and EOL type
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3787 as specified, do any autodetection that is called for. If the
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3788 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
3789 alone; but this function will never return an autodetect coding system
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3790 or EOL type.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3791
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3792 This function does not automatically fetch subsidiary coding systems;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3793 that should be unnecessary with the explicit eol-type argument. */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3794
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3795 #define LENGTH(string_constant) (sizeof (string_constant) - 1)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3796
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3797 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3798 unwind_free_detection_state (Lisp_Object opaque)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3799 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3800 struct detection_state *st =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3801 (struct detection_state *) get_opaque_ptr (opaque);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3802 free_detection_state (st);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3803 free_opaque_ptr (opaque);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3804 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3805 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3806
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3807 static Lisp_Object
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3808 look_for_coding_system_magic_cookie (const UExtbyte *data, Bytecount len,
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3809 Boolint find_coding_system_p, int err)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3810 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3811 const UExtbyte *p;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3812 const UExtbyte *scan_end;
2531
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3813 Bytecount cookie_len;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3814
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3815 if (len < 0)
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3816 {
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3817 signal_error (Qtext_conversion_error,
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3818 "Internal error while looking for coding cookie",
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3819 err ? lisp_strerror (err) : Qnil);
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3820 }
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3821
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3822 /* Look for initial "-*-"; mode line prefix */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3823 for (p = data,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3824 scan_end = data + len - LENGTH ("-*-coding:?-*-");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3825 p <= scan_end
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3826 && *p != '\n'
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3827 && *p != '\r';
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3828 p++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3829 if (*p == '-' && *(p+1) == '*' && *(p+2) == '-')
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3830 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3831 const UExtbyte *local_vars_beg = p + 3;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3832 /* Look for final "-*-"; mode line suffix */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3833 for (p = local_vars_beg,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3834 scan_end = data + len - LENGTH ("-*-");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3835 p <= scan_end
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3836 && *p != '\n'
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3837 && *p != '\r';
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3838 p++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3839 if (*p == '-' && *(p+1) == '*' && *(p+2) == '-')
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3840 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3841 const UExtbyte *suffix = p;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3842 /* Look for "coding:" */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3843 for (p = local_vars_beg,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3844 scan_end = suffix - LENGTH ("coding:?");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3845 p <= scan_end;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3846 p++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3847 if (memcmp ("coding:", p, LENGTH ("coding:")) == 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3848 && (p == local_vars_beg
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3849 || (*(p-1) == ' ' ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3850 *(p-1) == '\t' ||
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3851 *(p-1) == ';')))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3852 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3853 p += LENGTH ("coding:");
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3854 return snarf_coding_system (p, suffix - p,
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3855 find_coding_system_p);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3856 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3857 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3858 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3859 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3860 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3861 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3862
2531
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3863 /* Look for ;;;###coding system */
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3864
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3865 cookie_len = LENGTH (";;;###coding system: ");
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3866
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3867 for (p = data,
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3868 scan_end = data + len - cookie_len;
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3869 p <= scan_end;
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3870 p++)
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3871 {
2531
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3872 if (*p == ';' && !memcmp (p, ";;;###coding system: ", cookie_len))
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3873 {
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3874 const UExtbyte *suffix;
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3875
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3876 p += cookie_len;
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3877 suffix = p;
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3878 while (suffix < scan_end && !isspace (*suffix))
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3879 suffix++;
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3880 return snarf_coding_system (p, suffix - p, find_coding_system_p);
2531
7de8d9ab7bbd [xemacs-hg @ 2005-01-29 09:06:37 by ben]
ben
parents: 2500
diff changeset
3881 }
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3882 }
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3883
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
3884 return Qnil;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3885 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3886
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3887 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3888 determine_real_coding_system (Lstream *stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3889 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3890 struct detection_state *st = allocate_detection_state ();
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3891 int depth = record_unwind_protect (unwind_free_detection_state,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3892 make_opaque_ptr (st));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3893 UExtbyte buf[4096];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3894 Bytecount nread = Lstream_read (stream, buf, sizeof (buf));
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
3895 Lisp_Object coding_system
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3896 = look_for_coding_system_magic_cookie (buf, nread, 1,
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3897 Lstream_errno (stream));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3898
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3899 if (NILP (coding_system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3900 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3901 while (1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3902 {
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
3903 if (detect_coding_type (st, buf, nread, Lstream_errno (stream)))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3904 break;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3905 nread = Lstream_read (stream, buf, sizeof (buf));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3906 if (nread == 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3907 break;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3908 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3909
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3910 coding_system = detected_coding_system (st);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3911 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3912
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
3913 Lstream_rewind (stream);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3914
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3915 unbind_to (depth);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3916 return coding_system;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3917 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3918
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3919 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3920 undecided_init_coding_stream (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3921 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3922 struct undecided_coding_stream *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3923 CODING_STREAM_TYPE_DATA (str, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3924 struct undecided_coding_system *csdata =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3925 XCODING_SYSTEM_TYPE_DATA (str->codesys, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3926
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3927 data->actual = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3928
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3929 if (str->direction == CODING_DECODE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3930 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3931 Lstream *lst = str->other_end;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3932
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3933 if ((lst->flags & LSTREAM_FL_READ) &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3934 Lstream_seekable_p (lst) &&
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3935 csdata->do_coding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3936 /* We can determine the coding system now. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3937 data->actual = determine_real_coding_system (lst);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3938 }
1494
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3939
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3940 #ifdef DEBUG_XEMACS
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3941 if (!NILP (Vdebug_coding_detection))
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3942 stderr_out_lisp ("detected coding system: %s\n", 1, data->actual);
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
3943 #endif /* DEBUG_XEMACS */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3944 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3945
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3946 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3947 undecided_rewind_coding_stream (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3948 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3949 chain_rewind_coding_stream_1 (&CODING_STREAM_TYPE_DATA (str, undecided)->c);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3950 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3951
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3952 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3953 undecided_finalize_coding_stream (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3954 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3955 struct undecided_coding_stream *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3956 CODING_STREAM_TYPE_DATA (str, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3957
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3958 chain_finalize_coding_stream_1
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3959 (&CODING_STREAM_TYPE_DATA (str, undecided)->c);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3960 if (data->st)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3961 free_detection_state (data->st);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3962 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3963
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3964 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3965 undecided_canonicalize (Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3966 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3967 struct undecided_coding_system *csdata =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3968 XCODING_SYSTEM_TYPE_DATA (codesys, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3969 if (!csdata->do_eol && !csdata->do_coding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3970 return NILP (csdata->cs) ? Fget_coding_system (Qbinary) : csdata->cs;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3971 if (csdata->do_eol && !csdata->do_coding && NILP (csdata->cs))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3972 return Fget_coding_system (Qconvert_eol_autodetect);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3973 return codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3974 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3975
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3976 static Bytecount
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3977 undecided_convert (struct coding_stream *str, const UExtbyte *src,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3978 unsigned_char_dynarr *dst, Bytecount n)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3979 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3980 int first_time = 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3981
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3982 if (str->direction == CODING_DECODE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3983 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3984 /* At this point, we have only the following possibilities:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3985
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3986 do_eol && do_coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3987 do_coding only
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3988 do_eol only and a coding system was specified
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3989
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3990 Other possibilities are removed during undecided_canonicalize.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3991
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3992 Therefore, our substreams are either
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3993
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3994 lstream_coding -> lstream_dynarr, or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3995 lstream_coding -> lstream_eol -> lstream_dynarr.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3996 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3997 struct undecided_coding_system *csdata =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3998 XCODING_SYSTEM_TYPE_DATA (str->codesys, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
3999 struct undecided_coding_stream *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4000 CODING_STREAM_TYPE_DATA (str, undecided);
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
4001 int err = 0;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4002
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4003 if (str->eof)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4004 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4005 /* Each will close the next. We need to close now because more
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4006 data may be generated. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4007 if (data->c.initted)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4008 Lstream_close (XLSTREAM (data->c.lstreams[0]));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4009 return n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4010 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4011
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4012 if (!data->c.initted)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4013 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4014 data->c.lstream_count = csdata->do_eol ? 3 : 2;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4015 data->c.lstreams = xnew_array (Lisp_Object, data->c.lstream_count);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4016
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4017 data->c.lstreams[data->c.lstream_count - 1] =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4018 make_dynarr_output_stream (dst);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4019 Lstream_set_buffering
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4020 (XLSTREAM (data->c.lstreams[data->c.lstream_count - 1]),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4021 LSTREAM_UNBUFFERED, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4022 if (csdata->do_eol)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4023 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4024 data->c.lstreams[1] =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4025 make_coding_output_stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4026 (XLSTREAM (data->c.lstreams[data->c.lstream_count - 1]),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4027 Fget_coding_system (Qconvert_eol_autodetect),
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
4028 CODING_DECODE, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4029 Lstream_set_buffering
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4030 (XLSTREAM (data->c.lstreams[1]),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4031 LSTREAM_UNBUFFERED, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4032 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4033
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4034 data->c.lstreams[0] =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4035 make_coding_output_stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4036 (XLSTREAM (data->c.lstreams[1]),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4037 /* Substitute binary if we need to detect the encoding */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4038 csdata->do_coding ? Qbinary : csdata->cs,
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
4039 CODING_DECODE, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4040 Lstream_set_buffering (XLSTREAM (data->c.lstreams[0]),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4041 LSTREAM_UNBUFFERED, 0);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4042
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4043 first_time = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4044 data->c.initted = 1;
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
4045 err = Lstream_errno (str->other_end);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4046 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4047
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4048 /* If necessary, do encoding-detection now. We do this when we're a
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4049 writing stream or a non-seekable reading stream, meaning that we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4050 can't just process the whole input, rewind, and start over. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4051
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4052 if (csdata->do_coding)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4053 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4054 int actual_was_nil = NILP (data->actual);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4055 if (NILP (data->actual))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4056 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4057 if (!data->st)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4058 data->st = allocate_detection_state ();
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4059 if (first_time)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4060 /* #### This is cheesy. What we really ought to do is buffer
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4061 up a certain minimum amount of data to get a better result.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4062 */
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
4063 data->actual =
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
4064 look_for_coding_system_magic_cookie (src, n, 1, err);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4065 if (NILP (data->actual))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4066 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4067 /* #### This is cheesy. What we really ought to do is buffer
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4068 up a certain minimum amount of data so as to get a less
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4069 random result when doing subprocess detection. */
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
4070 detect_coding_type (data->st, src, n, err);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4071 data->actual = detected_coding_system (data->st);
4100
d1cf2b9c4dfd [xemacs-hg @ 2007-08-06 14:50:39 by michaels]
michaels
parents: 4072
diff changeset
4072 /* kludge to prevent infinite recursion */
d1cf2b9c4dfd [xemacs-hg @ 2007-08-06 14:50:39 by michaels]
michaels
parents: 4072
diff changeset
4073 if (XCODING_SYSTEM(data->actual)->methods->enumtype == undecided_coding_system)
d1cf2b9c4dfd [xemacs-hg @ 2007-08-06 14:50:39 by michaels]
michaels
parents: 4072
diff changeset
4074 data->actual = Fget_coding_system (Qbinary);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4075 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4076 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4077 /* We need to set the detected coding system if we actually have
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4078 such a coding system but didn't before. That is the case
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4079 either when we just detected it in the previous code or when
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4080 it was detected during undecided_init_coding_stream(). We
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4081 can check for that using first_time. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4082 if (!NILP (data->actual) && (actual_was_nil || first_time))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4083 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4084 /* If the detected coding system doesn't allow for EOL
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4085 autodetection, try to get the equivalent that does;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4086 otherwise, disable EOL detection (overriding whatever
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4087 may already have been detected). */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4088 if (XCODING_SYSTEM_EOL_TYPE (data->actual) != EOL_AUTODETECT)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4089 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4090 if (!NILP (XCODING_SYSTEM_SUBSIDIARY_PARENT (data->actual)))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4091 data->actual =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4092 XCODING_SYSTEM_SUBSIDIARY_PARENT (data->actual);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4093 else if (data->c.lstream_count == 3)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4094 set_coding_stream_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4095 (XLSTREAM (data->c.lstreams[1]),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4096 Fget_coding_system (Qidentity));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4097 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4098 set_coding_stream_coding_system
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4099 (XLSTREAM (data->c.lstreams[0]), data->actual);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4100 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4101 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4102
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4103 if (Lstream_write (XLSTREAM (data->c.lstreams[0]), src, n) < 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4104 return -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4105 return n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4106 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4107 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4108 return no_conversion_convert (str, src, dst, n);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4109 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4110
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4111 static Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4112 undecided_canonicalize_after_coding (struct coding_stream *str)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4113 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4114 struct undecided_coding_stream *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4115 CODING_STREAM_TYPE_DATA (str, undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4116 Lisp_Object ret, eolret;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4117
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4118 if (str->direction == CODING_ENCODE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4119 return str->codesys;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4120
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4121 if (!data->c.initted)
4647
e4ed58cb0e5b Fix bugs with #'find-file, 0-length files, & coding-system-for-read specified.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4569
diff changeset
4122 return str->codesys;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4123
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4124 ret = coding_stream_canonicalize_after_coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4125 (XLSTREAM (data->c.lstreams[0]));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4126 if (NILP (ret))
4647
e4ed58cb0e5b Fix bugs with #'find-file, 0-length files, & coding-system-for-read specified.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4569
diff changeset
4127 ret = str->codesys;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4128 if (XCODING_SYSTEM_EOL_TYPE (ret) != EOL_AUTODETECT)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4129 return ret;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4130 eolret = coding_stream_canonicalize_after_coding
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4131 (XLSTREAM (data->c.lstreams[1]));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4132 if (!EQ (XCODING_SYSTEM_TYPE (eolret), Qconvert_eol))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4133 return ret;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4134 return
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4135 Fsubsidiary_coding_system (ret, Fcoding_system_property (eolret,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4136 Qsubtype));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4137 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4138
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4139
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4140 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4141 /* Lisp interface: Coding category functions and detection */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4142 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4143
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4144 DEFUN ("coding-category-list", Fcoding_category_list, 0, 0, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4145 Return a list of all recognized coding categories.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4146 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4147 ())
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4148 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4149 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4150 Lisp_Object list = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4151
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4152 for (i = 0; i < coding_detector_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4153 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4154 detector_category_dynarr *cats =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4155 Dynarr_at (all_coding_detectors, i).cats;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4156 int j;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4157
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4158 for (j = 0; j < Dynarr_length (cats); j++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4159 list = Fcons (Dynarr_at (cats, j).sym, list);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4160 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4161
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4162 return Fnreverse (list);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4163 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4164
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4165 DEFUN ("set-coding-priority-list", Fset_coding_priority_list, 1, 1, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4166 Change the priority order of the coding categories.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4167 LIST should be list of coding categories, in descending order of
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4168 priority. Unspecified coding categories will be lower in priority
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4169 than all specified ones, in the same relative order they were in
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4170 previously.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4171 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4172 (list))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4173 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4174 int *category_to_priority =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4175 alloca_array (int, coding_detector_category_count);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4176 int i, j;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4177
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4178 /* First generate a list that maps coding categories to priorities. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4179
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4180 for (i = 0; i < coding_detector_category_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4181 category_to_priority[i] = -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4182
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4183 /* Highest priority comes from the specified list. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4184 i = 0;
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4185 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4186 EXTERNAL_LIST_LOOP_2 (elt, list)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4187 {
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4188 int cat = coding_category_symbol_to_id (elt);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4189
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4190 if (category_to_priority[cat] >= 0)
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4191 sferror ("Duplicate coding category in list", elt);
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4192 category_to_priority[cat] = i++;
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4193 }
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4194 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4195
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4196 /* Now go through the existing categories by priority to retrieve
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4197 the categories not yet specified and preserve their priority
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4198 order. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4199 for (j = 0; j < coding_detector_category_count; j++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4200 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4201 int cat = coding_category_by_priority[j];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4202 if (category_to_priority[cat] < 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4203 category_to_priority[cat] = i++;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4204 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4205
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4206 /* Now we need to construct the inverse of the mapping we just
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4207 constructed. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4208
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4209 for (i = 0; i < coding_detector_category_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4210 coding_category_by_priority[category_to_priority[i]] = i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4211
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4212 /* Phew! That was confusing. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4213 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4214 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4215
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4216 DEFUN ("coding-priority-list", Fcoding_priority_list, 0, 0, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4217 Return a list of coding categories in descending order of priority.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4218 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4219 ())
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4220 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4221 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4222 Lisp_Object list = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4223
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4224 for (i = 0; i < coding_detector_category_count; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4225 list =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4226 Fcons (coding_category_id_to_symbol (coding_category_by_priority[i]),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4227 list);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4228 return Fnreverse (list);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4229 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4230
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4231 DEFUN ("set-coding-category-system", Fset_coding_category_system, 2, 2, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4232 Change the coding system associated with a coding category.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4233 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4234 (coding_category, coding_system))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4235 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4236 coding_category_system[coding_category_symbol_to_id (coding_category)] =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4237 Fget_coding_system (coding_system);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4238 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4239 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4240
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4241 DEFUN ("coding-category-system", Fcoding_category_system, 1, 1, 0, /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4242 Return the coding system associated with a coding category.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4243 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4244 (coding_category))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4245 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4246 Lisp_Object sys =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4247 coding_category_system[coding_category_symbol_to_id (coding_category)];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4248
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4249 if (!NILP (sys))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4250 return XCODING_SYSTEM_NAME (sys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4251 return Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4252 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4253
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
4254 /* Detect the encoding of STREAM. Assumes stream is at the begnning and will
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
4255 read through to the end of STREAM, leaving it there but open. */
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
4256
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4257 Lisp_Object
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4258 detect_coding_stream (Lisp_Object stream)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4259 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4260 Lisp_Object val = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4261 struct gcpro gcpro1, gcpro2, gcpro3;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4262 UExtbyte random_buffer[65536];
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4263 Lisp_Object binary_instream =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4264 make_coding_input_stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4265 (XLSTREAM (stream), Qbinary,
814
a634e3b7acc8 [xemacs-hg @ 2002-04-14 12:41:59 by ben]
ben
parents: 802
diff changeset
4266 CODING_ENCODE, LSTREAM_FL_NO_CLOSE_OTHER);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4267 Lisp_Object decstream =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4268 make_coding_input_stream
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4269 (XLSTREAM (binary_instream),
800
a5954632b187 [xemacs-hg @ 2002-03-31 08:27:14 by ben]
ben
parents: 793
diff changeset
4270 Qundecided, CODING_DECODE, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4271 Lstream *decstr = XLSTREAM (decstream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4272
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4273 GCPRO3 (decstream, stream, binary_instream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4274 /* Read and discard all data; detection happens as a side effect of this,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4275 and we examine what was detected afterwards. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4276 while (Lstream_read (decstr, random_buffer, sizeof (random_buffer)) > 0)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4277 ;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4278
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4279 val = coding_stream_detected_coding_system (decstr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4280 Lstream_close (decstr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4281 Lstream_delete (decstr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4282 Lstream_delete (XLSTREAM (binary_instream));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4283 UNGCPRO;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4284 return val;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4285 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4286
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4287 DEFUN ("detect-coding-region", Fdetect_coding_region, 2, 3, 0, /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4288 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
4289 Return a list of possible coding systems ordered by priority.
3025
facf3239ba30 [xemacs-hg @ 2005-10-25 11:16:19 by ben]
ben
parents: 3024
diff changeset
4290 If only ASCII characters are found, return `undecided' or one of
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4291 its subsidiary coding systems according to a detected end-of-line
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4292 type. Optional arg BUFFER defaults to the current buffer.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4293 */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4294 (start, end, buffer))
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4295 {
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4296 Lisp_Object val = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4297 struct buffer *buf = decode_buffer (buffer, 0);
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
4298 Charbpos b, e;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4299 Lisp_Object lb_instream;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4300
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4301 get_buffer_range_char (buf, start, end, &b, &e, 0);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4302 lb_instream = make_lisp_buffer_input_stream (buf, b, e, 0);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4303
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4304 val = detect_coding_stream (lb_instream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4305 Lstream_delete (XLSTREAM (lb_instream));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4306 return val;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4307 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4308
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4309 DEFUN ("find-coding-system-magic-cookie-in-file",
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4310 Ffind_coding_system_magic_cookie_in_file, 1, 1, 0, /*
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4311 Look for the coding-system magic cookie in FILENAME.
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4312 The coding-system magic cookie is either the local variable specification
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4313 -*- ... coding: ... -*- on the first line, or the exact string
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4314 \";;;###coding system: \" somewhere within the first 3000 characters
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4315 of the file. If found, the coding system name (as a string) is returned;
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4316 otherwise nil is returned. Note that it is extremely unlikely that
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4317 either such string would occur coincidentally as the result of encoding
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4318 some characters in a non-ASCII charset, and that the spaces make it
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4319 even less likely since the space character is not a valid octet in any
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4320 ISO 2022 encoding of most non-ASCII charsets.
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4321 */
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4322 (filename))
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4323 {
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4324 Lisp_Object lstream;
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4325 UExtbyte buf[4096];
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4326 Bytecount nread;
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
4327 int fd = -1, err;
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4328 struct stat st;
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4329
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4330 filename = Fexpand_file_name (filename, Qnil);
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4331
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4332 if (qxe_stat (XSTRING_DATA (filename), &st) < 0)
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4333 {
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4334 badopen:
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4335 report_file_error ("Opening input file", filename);
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4336 }
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4337
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4338 if (fd < 0)
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4339 {
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4340 if ((fd = qxe_interruptible_open (XSTRING_DATA (filename),
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4341 O_RDONLY | OPEN_BINARY, 0)) < 0)
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4342 goto badopen;
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4343 }
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4344
5814
a216b3c2b09e Add TLS support. See xemacs-patches message with ID
Jerry James <james@xemacs.org>
parents: 5795
diff changeset
4345 lstream = make_filedesc_input_stream (fd, 0, -1, 0, NULL);
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4346 Lstream_set_buffering (XLSTREAM (lstream), LSTREAM_UNBUFFERED, 0);
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4347 nread = Lstream_read (XLSTREAM (lstream), buf, sizeof (buf));
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
4348 err = Lstream_errno (XLSTREAM (lstream));
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4349 Lstream_delete (XLSTREAM (lstream));
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4350 retry_close (fd);
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4351
5795
d2c0ff38ad5c Report lstream errors when encoding/decoding.
Jerry James <james@xemacs.org>
parents: 5784
diff changeset
4352 return look_for_coding_system_magic_cookie (buf, nread, 0, err);
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4353 }
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4354
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4355
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4356 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4357
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4358 /************************************************************************/
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4359 /* Internal methods */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4360 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4361
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4362 /* Raw (internally-formatted) data. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4363 DEFINE_CODING_SYSTEM_TYPE (internal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4364
665
fdefd0186b75 [xemacs-hg @ 2001-09-20 06:28:42 by ben]
ben
parents: 647
diff changeset
4365 static Bytecount
2286
04bc9d2f42c7 [xemacs-hg @ 2004-09-20 19:18:55 by james]
james
parents: 2132
diff changeset
4366 internal_convert (struct coding_stream *UNUSED (str), const UExtbyte *src,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4367 unsigned_char_dynarr *dst, Bytecount n)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4368 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4369 Bytecount orign = n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4370 Dynarr_add_many (dst, src, n);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4371 return orign;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4372 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4373
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4374 #endif /* DEBUG_XEMACS */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4375
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4376
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4377
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4378 #ifdef HAVE_ZLIB
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4379
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4380 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4381 /* Gzip methods */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4382 /************************************************************************/
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4383
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4384 struct gzip_coding_system
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4385 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4386 int level; /* 0 through 9, or -1 for default */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4387 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4388
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4389 #define CODING_SYSTEM_GZIP_LEVEL(codesys) \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4390 (CODING_SYSTEM_TYPE_DATA (codesys, gzip)->level)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4391 #define XCODING_SYSTEM_GZIP_LEVEL(codesys) \
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4392 (XCODING_SYSTEM_TYPE_DATA (codesys, gzip)->level)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4393
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4394 struct gzip_coding_stream
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4395 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4396 z_stream stream;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4397 int stream_initted;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4398 int reached_eof; /* #### this should be handled by the caller, once we
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4399 return LSTREAM_EOF */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4400 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4401
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
4402 static const struct memory_description
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4403 gzip_coding_system_description[] = {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4404 { XD_END }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4405 };
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4406
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
4407 DEFINE_CODING_SYSTEM_TYPE_WITH_DATA (gzip);
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
4408
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4409 enum source_sink_type
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4410 gzip_conversion_end_type (Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4411 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4412 return DECODES_BYTE_TO_BYTE;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4413 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4414
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4415 static void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4416 gzip_init (Lisp_Object codesys)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4417 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4418 struct gzip_coding_system *data = XCODING_SYSTEM_TYPE_DATA (codesys, gzip);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4419 data->level = -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4420 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4421
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4422 static void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4423 gzip_print (Lisp_Object cs, Lisp_Object printcharfun, int escapeflag)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4424 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4425 struct gzip_coding_system *data = XCODING_SYSTEM_TYPE_DATA (cs, gzip);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4426
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
4427 write_ascstring (printcharfun, "(");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4428 if (data->level == -1)
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
4429 write_ascstring (printcharfun, "default");
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4430 else
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
4431 print_internal (make_fixnum (data->level), printcharfun, 0);
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
4432 write_ascstring (printcharfun, ")");
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4435 static int
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4436 gzip_putprop (Lisp_Object codesys, Lisp_Object key, Lisp_Object value)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4437 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4438 struct gzip_coding_system *data = XCODING_SYSTEM_TYPE_DATA (codesys, gzip);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4439
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4440 if (EQ (key, Qlevel))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4441 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4442 if (EQ (value, Qdefault))
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4443 data->level = -1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4444 else
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4445 {
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
4446 check_integer_range (value, Qzero, make_fixnum (9));
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
4447 data->level = XFIXNUM (value);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4448 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4449 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4450 else
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4451 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4452 return 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4453 }
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 static Lisp_Object
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4456 gzip_getprop (Lisp_Object coding_system, Lisp_Object prop)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4457 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4458 struct gzip_coding_system *data =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4459 XCODING_SYSTEM_TYPE_DATA (coding_system, gzip);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4460
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4461 if (EQ (prop, Qlevel))
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4462 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4463 if (data->level == -1)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4464 return Qdefault;
5581
56144c8593a8 Mechanically change INT to FIXNUM in our sources.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5474
diff changeset
4465 return make_fixnum (data->level);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4466 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4467
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4468 return Qunbound;
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4471 static void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4472 gzip_init_coding_stream (struct coding_stream *str)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4473 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4474 struct gzip_coding_stream *data = CODING_STREAM_TYPE_DATA (str, gzip);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4475 if (data->stream_initted)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4476 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4477 if (str->direction == CODING_DECODE)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4478 inflateEnd (&data->stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4479 else
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4480 deflateEnd (&data->stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4481 data->stream_initted = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4482 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4483 data->reached_eof = 0;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4484 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4485
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4486 static void
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4487 gzip_rewind_coding_stream (struct coding_stream *str)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4488 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4489 gzip_init_coding_stream (str);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4490 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4491
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4492 static Bytecount
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4493 gzip_convert (struct coding_stream *str,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4494 const UExtbyte *src,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4495 unsigned_char_dynarr *dst, Bytecount n)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4496 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4497 struct gzip_coding_stream *data = CODING_STREAM_TYPE_DATA (str, gzip);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4498 int zerr;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4499 if (str->direction == CODING_DECODE)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4500 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4501 if (data->reached_eof)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4502 return n; /* eat the data */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4503
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4504 if (!data->stream_initted)
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4505 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4506 xzero (data->stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4507 if (inflateInit (&data->stream) != Z_OK)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4508 return LSTREAM_ERROR;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4509 data->stream_initted = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4510 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4511
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4512 data->stream.next_in = (Bytef *) src;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4513 data->stream.avail_in = n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4514
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4515 /* Normally we stop when we've fed all data to the decompressor; but
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4516 if we're at the end of the input, and the decompressor hasn't
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4517 reported EOF, we need to keep going, as there might be more output
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4518 to generate. Z_OK from the decompressor means input was processed
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4519 or output was generated; if neither, we break out of the loop.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4520 Other return values are:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4521
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4522 Z_STREAM_END EOF from decompressor
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4523 Z_DATA_ERROR Corrupted data
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4524 Z_BUF_ERROR No progress possible (this should happen if
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4525 we try to feed it an incomplete file)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4526 Z_MEM_ERROR Out of memory
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4527 Z_STREAM_ERROR (should never happen)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4528 Z_NEED_DICT (#### when will this happen?)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4529 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4530 while (data->stream.avail_in > 0 || str->eof)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4531 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4532 /* Reserve an output buffer of the same size as the input buffer;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4533 if that's not enough, we keep reserving the same size. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4534 Bytecount reserved = n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4535 Dynarr_add_many (dst, 0, reserved);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4536 /* Careful here! Don't retrieve the pointer until after
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4537 reserving the space, or it might be bogus */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4538 data->stream.next_out =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4539 Dynarr_atp (dst, Dynarr_length (dst) - reserved);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4540 data->stream.avail_out = reserved;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4541 zerr = inflate (&data->stream, Z_NO_FLUSH);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4542 /* Lop off the unused portion */
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
4543 Dynarr_set_lengthr (dst, Dynarr_length (dst) - data->stream.avail_out);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4544 if (zerr != Z_OK)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4545 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4546 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4547
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4548 if (zerr == Z_STREAM_END)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4549 data->reached_eof = 1;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4550
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4551 if ((Bytecount) data->stream.avail_in < n)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4552 return n - data->stream.avail_in;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4553
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4554 if (zerr == Z_OK || zerr == Z_STREAM_END)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4555 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4556
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4557 return LSTREAM_ERROR;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4558 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4559 else
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4560 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4561 if (!data->stream_initted)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4562 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4563 int level = XCODING_SYSTEM_GZIP_LEVEL (str->codesys);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4564 xzero (data->stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4565 if (deflateInit (&data->stream,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4566 level == -1 ? Z_DEFAULT_COMPRESSION : level) !=
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4567 Z_OK)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4568 return LSTREAM_ERROR;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4569 data->stream_initted = 1;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4570 }
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4571
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4572 data->stream.next_in = (Bytef *) src;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4573 data->stream.avail_in = n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4574
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4575 /* Normally we stop when we've fed all data to the compressor; but if
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4576 we're at the end of the input, and the compressor hasn't reported
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4577 EOF, we need to keep going, as there might be more output to
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4578 generate. (To signal EOF on our end, we set the FLUSH parameter
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4579 to Z_FINISH; when all data is output, Z_STREAM_END will be
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4580 returned.) Z_OK from the compressor means input was processed or
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4581 output was generated; if neither, we break out of the loop. Other
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4582 return values are:
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4583
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4584 Z_STREAM_END EOF from compressor
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4585 Z_BUF_ERROR No progress possible (should never happen)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4586 Z_STREAM_ERROR (should never happen)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4587 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4588 while (data->stream.avail_in > 0 || str->eof)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4589 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4590 /* Reserve an output buffer of the same size as the input buffer;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4591 if that's not enough, we keep reserving the same size. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4592 Bytecount reserved = n;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4593 Dynarr_add_many (dst, 0, reserved);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4594 /* Careful here! Don't retrieve the pointer until after
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4595 reserving the space, or it might be bogus */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4596 data->stream.next_out =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4597 Dynarr_atp (dst, Dynarr_length (dst) - reserved);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4598 data->stream.avail_out = reserved;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4599 zerr =
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4600 deflate (&data->stream,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4601 str->eof ? Z_FINISH : Z_NO_FLUSH);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4602 /* Lop off the unused portion */
5038
9410323e4b0d major dynarr fixes
Ben Wing <ben@xemacs.org>
parents: 4976
diff changeset
4603 Dynarr_set_lengthr (dst, Dynarr_length (dst) - data->stream.avail_out);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4604 if (zerr != Z_OK)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4605 break;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4606 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4607
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4608 if ((Bytecount) data->stream.avail_in < n)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4609 return n - data->stream.avail_in;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4610
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4611 if (zerr == Z_OK || zerr == Z_STREAM_END)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4612 return 0;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4613
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4614 return LSTREAM_ERROR;
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4615 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4616 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4617
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4618 #endif /* HAVE_ZLIB */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4619
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4620
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4621 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4622 /* Initialization */
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4623 /************************************************************************/
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4624
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4625 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4626 syms_of_file_coding (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4627 {
5117
3742ea8250b5 Checking in final CVS version of workspace 'ben-lisp-object'
Ben Wing <ben@xemacs.org>
parents: 3025
diff changeset
4628 INIT_LISP_OBJECT (coding_system);
442
abe6d1db359e Import from CVS: tag r21-2-36
cvs
parents: 440
diff changeset
4629
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4630 DEFSUBR (Fvalid_coding_system_type_p);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4631 DEFSUBR (Fcoding_system_type_list);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4632 DEFSUBR (Fcoding_system_p);
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
4633 DEFSUBR (Fautoload_coding_system);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4634 DEFSUBR (Ffind_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4635 DEFSUBR (Fget_coding_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4636 DEFSUBR (Fcoding_system_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4637 DEFSUBR (Fcoding_system_name);
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4638 DEFSUBR (Fmake_coding_system_internal);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4639 DEFSUBR (Fcopy_coding_system);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
4640 DEFSUBR (Fcoding_system_canonical_name_p);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
4641 DEFSUBR (Fcoding_system_alias_p);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
4642 DEFSUBR (Fcoding_system_aliasee);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4643 DEFSUBR (Fdefine_coding_system_alias);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4644 DEFSUBR (Fsubsidiary_coding_system);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4645 DEFSUBR (Fcoding_system_base);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4646 DEFSUBR (Fcoding_system_used_for_io);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4647
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4648 DEFSUBR (Fcoding_system_type);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4649 DEFSUBR (Fcoding_system_description);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4650 DEFSUBR (Fcoding_system_property);
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 DEFSUBR (Fcoding_category_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4653 DEFSUBR (Fset_coding_priority_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4654 DEFSUBR (Fcoding_priority_list);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4655 DEFSUBR (Fset_coding_category_system);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4656 DEFSUBR (Fcoding_category_system);
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 DEFSUBR (Fdetect_coding_region);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4659 DEFSUBR (Fdecode_coding_region);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4660 DEFSUBR (Fencode_coding_region);
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4661 DEFSUBR (Fquery_coding_region);
5682
dae33b5feffe Unify #'find-coding-system-magic-cookie-in-file, look_for_coding_system_magic_cookie()
Aidan Kehoe <kehoea@parhasard.net>
parents: 5581
diff changeset
4662 DEFSUBR (Ffind_coding_system_magic_cookie_in_file);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4663 DEFSYMBOL_MULTIWORD_PREDICATE (Qcoding_systemp);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4664 DEFSYMBOL (Qno_conversion);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4665 DEFSYMBOL (Qconvert_eol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4666 DEFSYMBOL (Qconvert_eol_autodetect);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4667 DEFSYMBOL (Qconvert_eol_lf);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4668 DEFSYMBOL (Qconvert_eol_cr);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4669 DEFSYMBOL (Qconvert_eol_crlf);
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4670 DEFSYMBOL (Qraw_text);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4671
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4672 DEFSYMBOL (Qmnemonic);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4673 DEFSYMBOL (Qeol_type);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4674 DEFSYMBOL (Qpost_read_conversion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4675 DEFSYMBOL (Qpre_write_conversion);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4676
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4677 DEFSYMBOL (Qtranslation_table_for_decode);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4678 DEFSYMBOL (Qtranslation_table_for_encode);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4679 DEFSYMBOL (Qsafe_chars);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4680 DEFSYMBOL (Qsafe_charsets);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4681 DEFSYMBOL (Qmime_charset);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4682 DEFSYMBOL (Qvalid_codes);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4683
563
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4684 DEFSYMBOL (Qcr);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4685 DEFSYMBOL (Qlf);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4686 DEFSYMBOL (Qcrlf);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4687 DEFSYMBOL (Qeol_cr);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4688 DEFSYMBOL (Qeol_lf);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4689 DEFSYMBOL (Qeol_crlf);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4690 DEFSYMBOL (Qencode);
183866b06e0b [xemacs-hg @ 2001-05-24 07:50:48 by ben]
ben
parents: 528
diff changeset
4691 DEFSYMBOL (Qdecode);
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4692
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4693 DEFSYMBOL (Qnear_certainty);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4694 DEFSYMBOL (Qquite_probable);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4695 DEFSYMBOL (Qsomewhat_likely);
1494
210683f31426 [xemacs-hg @ 2003-05-22 06:09:03 by stephent]
stephent
parents: 1348
diff changeset
4696 DEFSYMBOL (Qslightly_likely);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4697 DEFSYMBOL (Qas_likely_as_unlikely);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4698 DEFSYMBOL (Qsomewhat_unlikely);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4699 DEFSYMBOL (Qquite_improbable);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4700 DEFSYMBOL (Qnearly_impossible);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4701
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4702 DEFSYMBOL (Qdo_eol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4703 DEFSYMBOL (Qdo_coding);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4704
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4705 DEFSYMBOL (Qcanonicalize_after_coding);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4706
4303
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
4707 DEFSYMBOL (Qposix_charset_to_coding_system_hash);
cee827542370 [xemacs-hg @ 2007-12-04 20:18:33 by aidan]
aidan
parents: 4100
diff changeset
4708
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4709 DEFSYMBOL (Qescape_quoted);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4710
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4711 DEFSYMBOL (Qquery_coding_warning_face);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4712 DEFSYMBOL (Qaliases);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4713 DEFSYMBOL (Qcharset_skip_chars_string);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4714
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4715 #ifdef HAVE_ZLIB
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4716 DEFSYMBOL (Qgzip);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4717 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4718
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4719 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4720
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4721 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4722 lstream_type_create_file_coding (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4723 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4724 LSTREAM_HAS_METHOD (coding, reader);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4725 LSTREAM_HAS_METHOD (coding, writer);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4726 LSTREAM_HAS_METHOD (coding, rewinder);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4727 LSTREAM_HAS_METHOD (coding, seekable_p);
5776
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
4728 LSTREAM_HAS_METHOD (coding, character_tell);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4729 LSTREAM_HAS_METHOD (coding, marker);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4730 LSTREAM_HAS_METHOD (coding, flusher);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4731 LSTREAM_HAS_METHOD (coding, closer);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4732 LSTREAM_HAS_METHOD (coding, finalizer);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4733 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4734
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4735 void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4736 coding_system_type_create (void)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4737 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4738 int i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4739
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4740 staticpro (&Vcoding_system_hash_table);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4741 Vcoding_system_hash_table =
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
4742 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, Qeq);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4743
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4744 the_coding_system_type_entry_dynarr = Dynarr_new (coding_system_type_entry);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4745 dump_add_root_block_ptr (&the_coding_system_type_entry_dynarr,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4746 &csted_description);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4747
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4748 Vcoding_system_type_list = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4749 staticpro (&Vcoding_system_type_list);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4750
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4751 /* Initialize to something reasonable ... */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4752 for (i = 0; i < MAX_DETECTOR_CATEGORIES; i++)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4753 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4754 coding_category_system[i] = Qnil;
1204
e22b0213b713 [xemacs-hg @ 2003-01-12 11:07:58 by michaels]
michaels
parents: 945
diff changeset
4755 dump_add_root_lisp_object (&coding_category_system[i]);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4756 coding_category_by_priority[i] = i;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4757 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4758
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4759 dump_add_opaque (coding_category_by_priority,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4760 sizeof (coding_category_by_priority));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4761
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4762 all_coding_detectors = Dynarr_new2 (detector_dynarr, struct detector);
2367
ecf1ebac70d8 [xemacs-hg @ 2004-11-04 23:05:23 by ben]
ben
parents: 2297
diff changeset
4763 dump_add_root_block_ptr (&all_coding_detectors,
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4764 &detector_dynarr_description);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4765
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4766 dump_add_opaque_int (&coding_system_tick);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4767 dump_add_opaque_int (&coding_detector_count);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4768 dump_add_opaque_int (&coding_detector_category_count);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4769
5777
ccaa851ae712 Rework description of no_conversion coding system, avoiding pdump confusion.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5776
diff changeset
4770 INITIALIZE_CODING_SYSTEM_TYPE (no_conversion,
ccaa851ae712 Rework description of no_conversion coding system, avoiding pdump confusion.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5776
diff changeset
4771 "no-conversion-coding-system-p");
ccaa851ae712 Rework description of no_conversion coding system, avoiding pdump confusion.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5776
diff changeset
4772 /* This is the only coding system type that has coding_stream info but no
ccaa851ae712 Rework description of no_conversion coding system, avoiding pdump confusion.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5776
diff changeset
4773 coding_system info, which is why we're not using
ccaa851ae712 Rework description of no_conversion coding system, avoiding pdump confusion.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5776
diff changeset
4774 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA. */
ccaa851ae712 Rework description of no_conversion coding system, avoiding pdump confusion.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5776
diff changeset
4775 no_conversion_coding_system_methods->coding_data_size =
ccaa851ae712 Rework description of no_conversion coding system, avoiding pdump confusion.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5776
diff changeset
4776 sizeof (struct no_conversion_coding_stream);
ccaa851ae712 Rework description of no_conversion coding system, avoiding pdump confusion.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5776
diff changeset
4777
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4778 CODING_SYSTEM_HAS_METHOD (no_conversion, convert);
5776
65d65b52d608 Pass character count from coding systems to buffer insertion code.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5774
diff changeset
4779 CODING_SYSTEM_HAS_METHOD (no_conversion, character_tell);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4780
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4781 INITIALIZE_DETECTOR (no_conversion);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4782 DETECTOR_HAS_METHOD (no_conversion, detect);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4783 INITIALIZE_DETECTOR_CATEGORY (no_conversion, no_conversion);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4784
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4785 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (convert_eol,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4786 "convert-eol-coding-system-p");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4787 CODING_SYSTEM_HAS_METHOD (convert_eol, print);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4788 CODING_SYSTEM_HAS_METHOD (convert_eol, convert);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4789 CODING_SYSTEM_HAS_METHOD (convert_eol, getprop);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4790 CODING_SYSTEM_HAS_METHOD (convert_eol, putprop);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4791 CODING_SYSTEM_HAS_METHOD (convert_eol, conversion_end_type);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4792 CODING_SYSTEM_HAS_METHOD (convert_eol, canonicalize_after_coding);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4793 CODING_SYSTEM_HAS_METHOD (convert_eol, init_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4794
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4795 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (undecided,
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4796 "undecided-coding-system-p");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4797 CODING_SYSTEM_HAS_METHOD (undecided, init);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4798 CODING_SYSTEM_HAS_METHOD (undecided, mark);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4799 CODING_SYSTEM_HAS_METHOD (undecided, print);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4800 CODING_SYSTEM_HAS_METHOD (undecided, convert);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4801 CODING_SYSTEM_HAS_METHOD (undecided, putprop);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4802 CODING_SYSTEM_HAS_METHOD (undecided, getprop);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4803 CODING_SYSTEM_HAS_METHOD (undecided, init_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4804 CODING_SYSTEM_HAS_METHOD (undecided, rewind_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4805 CODING_SYSTEM_HAS_METHOD (undecided, finalize_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4806 CODING_SYSTEM_HAS_METHOD (undecided, mark_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4807 CODING_SYSTEM_HAS_METHOD (undecided, canonicalize);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4808 CODING_SYSTEM_HAS_METHOD (undecided, canonicalize_after_coding);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4809
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4810 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (chain, "chain-coding-system-p");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4811
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4812 CODING_SYSTEM_HAS_METHOD (chain, print);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4813 CODING_SYSTEM_HAS_METHOD (chain, canonicalize);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4814 CODING_SYSTEM_HAS_METHOD (chain, init);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4815 CODING_SYSTEM_HAS_METHOD (chain, mark);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4816 CODING_SYSTEM_HAS_METHOD (chain, mark_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4817 CODING_SYSTEM_HAS_METHOD (chain, convert);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4818 CODING_SYSTEM_HAS_METHOD (chain, rewind_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4819 CODING_SYSTEM_HAS_METHOD (chain, finalize_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4820 CODING_SYSTEM_HAS_METHOD (chain, finalize);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4821 CODING_SYSTEM_HAS_METHOD (chain, putprop);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4822 CODING_SYSTEM_HAS_METHOD (chain, getprop);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4823 CODING_SYSTEM_HAS_METHOD (chain, conversion_end_type);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4824 CODING_SYSTEM_HAS_METHOD (chain, canonicalize_after_coding);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4825
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4826 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4827 INITIALIZE_CODING_SYSTEM_TYPE (internal, "internal-coding-system-p");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4828 CODING_SYSTEM_HAS_METHOD (internal, convert);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4829 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4830
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4831 #ifdef HAVE_ZLIB
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4832 INITIALIZE_CODING_SYSTEM_TYPE_WITH_DATA (gzip, "gzip-coding-system-p");
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4833 CODING_SYSTEM_HAS_METHOD (gzip, conversion_end_type);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4834 CODING_SYSTEM_HAS_METHOD (gzip, convert);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4835 CODING_SYSTEM_HAS_METHOD (gzip, init);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4836 CODING_SYSTEM_HAS_METHOD (gzip, print);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4837 CODING_SYSTEM_HAS_METHOD (gzip, init_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4838 CODING_SYSTEM_HAS_METHOD (gzip, rewind_coding_stream);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4839 CODING_SYSTEM_HAS_METHOD (gzip, putprop);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4840 CODING_SYSTEM_HAS_METHOD (gzip, getprop);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4841 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4842 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4843
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4844 void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4845 reinit_coding_system_type_create (void)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4846 {
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4847 REINITIALIZE_CODING_SYSTEM_TYPE (no_conversion);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4848 REINITIALIZE_CODING_SYSTEM_TYPE (convert_eol);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4849 REINITIALIZE_CODING_SYSTEM_TYPE (undecided);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4850 REINITIALIZE_CODING_SYSTEM_TYPE (chain);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4851 #if 0
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4852 REINITIALIZE_CODING_SYSTEM_TYPE (text_file_wrapper);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4853 #endif /* 0 */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4854 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4855 REINITIALIZE_CODING_SYSTEM_TYPE (internal);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4856 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4857 #ifdef HAVE_ZLIB
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4858 REINITIALIZE_CODING_SYSTEM_TYPE (gzip);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4859 #endif
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4860 }
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4861
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4862 void
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4863 reinit_vars_of_file_coding (void)
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4864 {
428
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
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4867 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4868 vars_of_file_coding (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4869 {
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4870 /* We always have file-coding support */
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4871 Fprovide (intern ("file-coding"));
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4872
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
4873 QScoding_system_cookie = build_ascstring (";;;###coding system: ");
1347
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
4874 staticpro (&QScoding_system_cookie);
8d350b095c21 [xemacs-hg @ 2003-03-09 12:59:36 by ben]
ben
parents: 1318
diff changeset
4875
1242
f0af455e89d9 [xemacs-hg @ 2003-01-31 12:02:30 by stephent]
stephent
parents: 1204
diff changeset
4876 #ifdef HAVE_DEFAULT_EOL_DETECTION
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
4877 /* #### Find a more appropriate place for this comment.
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
4878 WARNING: The existing categories are intimately tied to the function
1242
f0af455e89d9 [xemacs-hg @ 2003-01-31 12:02:30 by stephent]
stephent
parents: 1204
diff changeset
4879 `coding-system-category' in coding.el. If you change a category, or
f0af455e89d9 [xemacs-hg @ 2003-01-31 12:02:30 by stephent]
stephent
parents: 1204
diff changeset
4880 change the layout of any coding system associated with a category, you
f0af455e89d9 [xemacs-hg @ 2003-01-31 12:02:30 by stephent]
stephent
parents: 1204
diff changeset
4881 need to check that function and make sure it's written properly. */
f0af455e89d9 [xemacs-hg @ 2003-01-31 12:02:30 by stephent]
stephent
parents: 1204
diff changeset
4882
f0af455e89d9 [xemacs-hg @ 2003-01-31 12:02:30 by stephent]
stephent
parents: 1204
diff changeset
4883 Fprovide (intern ("unix-default-eol-detection"));
f0af455e89d9 [xemacs-hg @ 2003-01-31 12:02:30 by stephent]
stephent
parents: 1204
diff changeset
4884 #endif
f0af455e89d9 [xemacs-hg @ 2003-01-31 12:02:30 by stephent]
stephent
parents: 1204
diff changeset
4885
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4886 DEFVAR_LISP ("keyboard-coding-system", &Vkeyboard_coding_system /*
3142
77f5a5135b3a [xemacs-hg @ 2005-12-17 19:46:57 by aidan]
aidan
parents: 3025
diff changeset
4887 Default coding system used for TTY and X11 keyboard input.
5384
3889ef128488 Fix misspelled words, and some grammar, across the entire source tree.
Jerry James <james@xemacs.org>
parents: 5345
diff changeset
4888 Under X11, used only to interpret the character for a key event when that
3142
77f5a5135b3a [xemacs-hg @ 2005-12-17 19:46:57 by aidan]
aidan
parents: 3025
diff changeset
4889 event has a KeySym of NoSymbol but does have an associated string keysym,
77f5a5135b3a [xemacs-hg @ 2005-12-17 19:46:57 by aidan]
aidan
parents: 3025
diff changeset
4890 something that's seen with input methods.
77f5a5135b3a [xemacs-hg @ 2005-12-17 19:46:57 by aidan]
aidan
parents: 3025
diff changeset
4891
77f5a5135b3a [xemacs-hg @ 2005-12-17 19:46:57 by aidan]
aidan
parents: 3025
diff changeset
4892 If you need to set these things to different coding systems, call the
77f5a5135b3a [xemacs-hg @ 2005-12-17 19:46:57 by aidan]
aidan
parents: 3025
diff changeset
4893 function `set-console-tty-coding-system' for the TTY and use this variable
77f5a5135b3a [xemacs-hg @ 2005-12-17 19:46:57 by aidan]
aidan
parents: 3025
diff changeset
4894 for X11.
428
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 Vkeyboard_coding_system = Qnil;
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 DEFVAR_LISP ("terminal-coding-system", &Vterminal_coding_system /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4899 Coding system used for TTY display output.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4900 Not used under a windowing system.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4901 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4902 Vterminal_coding_system = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4903
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4904 DEFVAR_LISP ("coding-system-for-read", &Vcoding_system_for_read /*
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
4905 Overriding coding system used when reading from a file or process.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
4906 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
4907 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
4908 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
4909 It overrides `buffer-file-coding-system-for-read',
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4910 `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
4911 this one for permanent changes to the environment. */ );
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4912 Vcoding_system_for_read = Qnil;
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4913
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4914 DEFVAR_LISP ("coding-system-for-write",
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4915 &Vcoding_system_for_write /*
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
4916 Overriding coding system used when writing to a file or process.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
4917 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
4918 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
4919 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
4920 It overrides `buffer-file-coding-system', `write-region-pre-hook', etc.
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
4921 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
4922 environment. */ );
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4923 Vcoding_system_for_write = Qnil;
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 DEFVAR_LISP ("file-name-coding-system", &Vfile_name_coding_system /*
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4926 Coding system used to convert pathnames when accessing files.
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4927 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4928 Vfile_name_coding_system = Qnil;
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 DEFVAR_BOOL ("enable-multibyte-characters", &enable_multibyte_characters /*
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4931 Setting this has no effect. It is purely for FSF compatibility.
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4932 */ );
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4933 enable_multibyte_characters = 1;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4934
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4935 Vchain_canonicalize_hash_table =
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
4936 make_lisp_hash_table (50, HASH_TABLE_NON_WEAK, Qequal);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4937 staticpro (&Vchain_canonicalize_hash_table);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4938
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4939 #ifdef DEBUG_XEMACS
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4940 DEFVAR_LISP ("debug-coding-detection", &Vdebug_coding_detection /*
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4941 If non-nil, display debug information about detection operations in progress.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4942 Information is displayed on stderr.
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4943 */ );
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4944 Vdebug_coding_detection = Qnil;
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4945 #endif
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4946
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4947 #ifdef MULE
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4948 Vdefault_query_coding_region_chartab_cache
5191
71ee43b8a74d Add #'equalp as a hash test by default; add #'define-hash-table-test, GNU API
Aidan Kehoe <kehoea@parhasard.net>
parents: 5169
diff changeset
4949 = make_lisp_hash_table (25, HASH_TABLE_NON_WEAK, Qequal);
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4950 staticpro (&Vdefault_query_coding_region_chartab_cache);
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4951 #endif
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4952 }
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4953
2297
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
4954 /* #### reformat this for consistent appearance? */
13a418960a88 [xemacs-hg @ 2004-09-22 02:05:42 by stephent]
stephent
parents: 2286
diff changeset
4955
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4956 void
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4957 complex_vars_of_file_coding (void)
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
4958 {
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4959 Fmake_coding_system_internal
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4960 (Qconvert_eol_cr, Qconvert_eol,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
4961 build_defer_string ("Convert CR to LF"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4962 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4963 build_defer_string (
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4964 "Converts CR (used to mark the end of a line on Macintosh systems) to LF\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4965 "(used internally and under Unix to mark the end of a line)."),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4966 Qmnemonic, build_ascstring ("CR->LF"),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4967 Qsubtype, Qcr,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4968 /* VERY IMPORTANT! Tell make-coding-system not to generate
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4969 subsidiaries -- it needs the coding systems we're creating
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4970 to do so! */
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4971 Qeol_type, Qlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4972 Qsafe_charsets, Qt,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4973 Qunbound));
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4974 Fmake_coding_system_internal
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4975 (Qconvert_eol_lf, Qconvert_eol,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
4976 build_defer_string ("Convert LF to LF (do nothing)"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4977 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4978 build_defer_string ("Do nothing."),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4979 Qmnemonic, build_ascstring ("LF->LF"),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4980 Qsubtype, Qlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4981 /* VERY IMPORTANT! Tell make-coding-system not to generate
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4982 subsidiaries -- it needs the coding systems we're creating
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4983 to do so! */
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4984 Qeol_type, Qlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4985 Qsafe_charsets, Qt,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4986 Qunbound));
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4987
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
4988 Fmake_coding_system_internal
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4989 (Qconvert_eol_crlf, Qconvert_eol,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
4990 build_defer_string ("Convert CRLF to LF"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4991 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4992 build_defer_string (
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4993 "Converts CR+LF (used to mark the end of a line on Macintosh systems) to LF\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
4994 "(used internally and under Unix to mark the end of a line)."),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4995 Qmnemonic, build_ascstring ("CRLF->LF"),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4996 Qsubtype, Qcrlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4997 /* VERY IMPORTANT! Tell make-coding-system not to generate
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4998 subsidiaries -- it needs the coding systems we're creating
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
4999 to do so! */
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5000 Qeol_type, Qlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5001 Qsafe_charsets, Qt,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5002 Qunbound));
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5003
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5004 Fmake_coding_system_internal
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5005 (Qconvert_eol_autodetect, Qconvert_eol,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
5006 build_defer_string ("Autodetect EOL type"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5007 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5008 build_defer_string ("Autodetect the end-of-line type."),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5009 Qmnemonic, build_ascstring ("Auto-EOL"),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5010 Qsubtype, Qnil,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5011 /* VERY IMPORTANT! Tell make-coding-system not to generate
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5012 subsidiaries -- it needs the coding systems we're creating
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5013 to do so! */
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5014 Qeol_type, Qlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5015 Qsafe_charsets, Qt,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5016 Qunbound));
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5017
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5018 Fmake_coding_system_internal
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5019 (Qundecided, Qundecided,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
5020 build_defer_string ("Undecided (auto-detect)"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5021 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5022 build_defer_string ("Automatically detects the correct encoding."),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5023 Qmnemonic, build_ascstring ("Auto"),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5024 Qdo_eol, Qt, Qdo_coding, Qt,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5025 /* We do EOL detection ourselves so we don't need to be
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5026 wrapped in an EOL detector. (It doesn't actually hurt,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5027 though, I don't think.) */
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5028 Qeol_type, Qlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5029 Qunbound));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5030
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5031 Fmake_coding_system_internal
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5032 (intern ("undecided-dos"), Qundecided,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
5033 build_defer_string ("Undecided (auto-detect) (CRLF)"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5034 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5035 build_defer_string
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5036 ("Automatically detects the correct encoding; EOL type of CRLF forced."),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5037 Qmnemonic, build_ascstring ("Auto"),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5038 Qdo_coding, Qt,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5039 Qeol_type, Qcrlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5040 Qunbound));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5041
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5042 Fmake_coding_system_internal
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5043 (intern ("undecided-unix"), Qundecided,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
5044 build_defer_string ("Undecided (auto-detect) (LF)"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5045 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5046 build_defer_string
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5047 ("Automatically detects the correct encoding; EOL type of LF forced."),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5048 Qmnemonic, build_ascstring ("Auto"),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5049 Qdo_coding, Qt,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5050 Qeol_type, Qlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5051 Qunbound));;
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5052
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5053 Fmake_coding_system_internal
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5054 (intern ("undecided-mac"), Qundecided,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
5055 build_defer_string ("Undecided (auto-detect) (CR)"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5056 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5057 build_defer_string
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5058 ("Automatically detects the correct encoding; EOL type of CR forced."),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5059 Qmnemonic, build_ascstring ("Auto"),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5060 Qdo_coding, Qt,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5061 Qeol_type, Qcr,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5062 Qunbound));
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5063
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5064 /* Need to create this here or we're really screwed. */
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5065 Fmake_coding_system_internal
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5066 (Qraw_text, Qno_conversion,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
5067 build_defer_string ("Raw Text"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5068 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5069 build_defer_string ("Raw text converts only line-break "
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5070 "codes, and acts otherwise like "
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5071 "`binary'."),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5072 Qmnemonic, build_ascstring ("Raw"),
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5073 #ifdef MULE
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5074 Qsafe_charsets, list3 (Vcharset_ascii, Vcharset_control_1,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5075 Vcharset_latin_iso8859_1),
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5076
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5077 #endif
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5078 Qunbound));
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5079
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5080
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5081 Fmake_coding_system_internal
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5082 (Qbinary, Qno_conversion,
4952
19a72041c5ed Mule-izing, various fixes related to char * arguments
Ben Wing <ben@xemacs.org>
parents: 4846
diff changeset
5083 build_defer_string ("Binary"),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5084 listu (Qdocumentation,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5085 build_defer_string (
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5086 "This coding system is as close as it comes to doing no conversion.\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5087 "On input, each byte is converted directly into the character\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5088 "with the corresponding code -- i.e. from the `ascii', `control-1',\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5089 "or `latin-1' character sets. On output, these characters are\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5090 "converted back to the corresponding bytes, and other characters\n"
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5091 "are converted to the default character, i.e. `~'."),
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5092 Qeol_type, Qlf,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5093 Qmnemonic, build_ascstring ("Binary"),
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5094 #ifdef MULE
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5095 Qsafe_charsets, list3 (Vcharset_ascii, Vcharset_control_1,
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5096 Vcharset_latin_iso8859_1),
4690
257b468bf2ca Move the #'query-coding-region implementation to C.
Aidan Kehoe <kehoea@parhasard.net>
parents: 4647
diff changeset
5097 #endif
5345
db326b8fe982 Use Ben's recently-introduced listu (), where appropriate.
Aidan Kehoe <kehoea@parhasard.net>
parents: 5307
diff changeset
5098 Qunbound));
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5099
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5100 /* Formerly aliased to raw-text! Completely bogus and not even the same
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5101 as FSF Emacs. */
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5102 Fdefine_coding_system_alias (Qno_conversion, Qbinary);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5103 Fdefine_coding_system_alias (intern ("no-conversion-unix"),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5104 intern ("raw-text-unix"));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5105 Fdefine_coding_system_alias (intern ("no-conversion-dos"),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5106 intern ("raw-text-dos"));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5107 Fdefine_coding_system_alias (intern ("no-conversion-mac"),
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5108 intern ("raw-text-mac"));
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5109
1318
b531bf8658e9 [xemacs-hg @ 2003-02-21 06:56:46 by ben]
ben
parents: 1242
diff changeset
5110 /* These three below will get their defaults set correctly
b531bf8658e9 [xemacs-hg @ 2003-02-21 06:56:46 by ben]
ben
parents: 1242
diff changeset
5111 in code-init.el. We init them now so we can handle stuff at dump
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5112 time before we get to code-init.el. */
1318
b531bf8658e9 [xemacs-hg @ 2003-02-21 06:56:46 by ben]
ben
parents: 1242
diff changeset
5113 Fdefine_coding_system_alias (Qnative, Qbinary);
440
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5114 Fdefine_coding_system_alias (Qterminal, Qbinary);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5115 Fdefine_coding_system_alias (Qkeyboard, Qbinary);
8de8e3f6228a Import from CVS: tag r21-2-28
cvs
parents: 438
diff changeset
5116
1318
b531bf8658e9 [xemacs-hg @ 2003-02-21 06:56:46 by ben]
ben
parents: 1242
diff changeset
5117 Fdefine_coding_system_alias (Qfile_name, Qnative);
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5118 Fdefine_coding_system_alias (Qidentity, Qconvert_eol_lf);
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5119
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5120 /* Need this for bootstrapping */
771
943eaba38521 [xemacs-hg @ 2002-03-13 08:51:24 by ben]
ben
parents: 665
diff changeset
5121 coding_category_system[detector_category_no_conversion] =
428
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5122 Fget_coding_system (Qraw_text);
3ecd8885ac67 Import from CVS: tag r21-2-22
cvs
parents:
diff changeset
5123 }