/* Coding system handler (conversion, detection, etc).
- Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN.
- Licensed to the Free Software Foundation.
- Copyright (C) 2001, 2002 Free Software Foundation, Inc.
+ Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
+ Copyright (C) 1995, 1997, 1998, 2002, 2003, 2004, 2005
+ National Institute of Advanced Industrial Science and Technology (AIST)
+ Registration Number H14PRO021
Copyright (C) 2003
National Institute of Advanced Industrial Science and Technology (AIST)
Registration Number H13PRO009
You should have received a copy of the GNU General Public License
along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+Boston, MA 02110-1301, USA. */
/*** TABLE OF CONTENTS ***
struct coding_system *coding;
struct coding_detection_info *detect_info;
{
- unsigned char *src = coding->source;
- unsigned char *src_end = coding->source + coding->src_bytes;
+ const unsigned char *src = coding->source;
+ const unsigned char *src_end = coding->source + coding->src_bytes;
int multibytep = coding->src_multibyte;
int consumed_chars = 0;
int found = 0;
decode_coding_XXXX (coding)
struct coding_system *coding;
{
- unsigned char *src = coding->source + coding->consumed;
- unsigned char *src_end = coding->source + coding->src_bytes;
+ const unsigned char *src = coding->source + coding->consumed;
+ const unsigned char *src_end = coding->source + coding->src_bytes;
/* SRC_BASE remembers the start position in source in each loop.
The loop will be exited when there's not enough source code, or
when there's no room in CHARBUF for a decoded character. */
- unsigned char *src_base;
+ const unsigned char *src_base;
/* A buffer to produce decoded characters. */
int *charbuf = coding->charbuf + coding->charbuf_used;
int *charbuf_end = coding->charbuf + coding->charbuf_size;
Lisp_Object QCcategory, QCmnemonic, QCdefalut_char;
Lisp_Object QCdecode_translation_table, QCencode_translation_table;
Lisp_Object QCpost_read_conversion, QCpre_write_conversion;
+Lisp_Object QCascii_compatible_p;
extern Lisp_Object Qinsert_file_contents, Qwrite_region;
-Lisp_Object Qcall_process, Qcall_process_region, Qprocess_argument;
+Lisp_Object Qcall_process, Qcall_process_region;
Lisp_Object Qstart_process, Qopen_network_stream;
Lisp_Object Qtarget_idx;
c = ((c & 1) << 6) | *src++; \
else \
{ \
- c = - string_char (--src, &src, NULL); \
+ src--; \
+ c = - string_char (src, &src, NULL); \
record_conversion_result \
(coding, CODING_RESULT_INVALID_SRC); \
} \
c = ((c & 1) << 6) | *src++; \
else \
{ \
- c = - string_char (--src, &src, NULL); \
+ src--; \
+ c = - string_char (src, &src, NULL); \
record_conversion_result \
(coding, CODING_RESULT_INVALID_SRC); \
} \
case CODING_RESULT_INSUFFICIENT_MEM:
Vlast_code_conversion_error = Qinsufficient_memory;
break;
+ default:
+ Vlast_code_conversion_error = intern ("Unknown error");
}
}
/* Not yet implemented. */
break;
case CODING_ANNOTATE_CHARSET_MASK:
- preferred_charset_id = charbuf[3];
+ preferred_charset_id = charbuf[2];
if (preferred_charset_id >= 0
&& NILP (Fmemq (make_number (preferred_charset_id),
charset_list)))
return;
}
+/* Return a list of charsets supported by CODING. */
+
+Lisp_Object
+coding_charset_list (coding)
+ struct coding_system *coding;
+{
+ Lisp_Object attrs, charset_list;
+
+ CODING_GET_INFO (coding, attrs, charset_list);
+ if (EQ (CODING_ATTR_TYPE (attrs), Qiso_2022))
+ {
+ int flags = XINT (AREF (attrs, coding_attr_iso_flags));
+
+ if (flags & CODING_ISO_FLAG_FULL_SUPPORT)
+ charset_list = Viso_2022_charset_list;
+ }
+ else if (EQ (CODING_ATTR_TYPE (attrs), Qemacs_mule))
+ {
+ charset_list = Vemacs_mule_charset_list;
+ }
+ return charset_list;
+}
+
+
/* Return raw-text or one of its subsidiaries that has the same
eol_type as CODING-SYSTEM. */
{
int c = *src++;
- coding->charbuf[coding->charbuf_used++] = (c & 0x80 ? - c : c);
+ if (c & 0x80)
+ c = BYTE8_TO_CHAR (c);
+ coding->charbuf[coding->charbuf_used++] = c;
}
produce_chars (coding, Qnil, 1);
}
Lisp_Object arg;
{
Lisp_Object current, workbuf;
+ struct gcpro gcpro1;
+ GCPRO1 (arg);
current = XCAR (arg);
workbuf = XCDR (arg);
if (! NILP (workbuf))
Fkill_buffer (workbuf);
}
set_buffer_internal (XBUFFER (current));
+ UNGCPRO;
return Qnil;
}
TEMP_SET_PT_BOTH (coding->dst_pos, coding->dst_pos_byte);
GCPRO2 (coding->src_object, coding->dst_object);
- val = call1 (CODING_ATTR_POST_READ (attrs),
- make_number (coding->produced_char));
+ val = safe_call1 (CODING_ATTR_POST_READ (attrs),
+ make_number (coding->produced_char));
UNGCPRO;
CHECK_NATNUM (val);
coding->produced_char += Z - prev_Z;
Lisp_Object attrs;
Lisp_Object buffer;
int saved_pt = -1, saved_pt_byte;
+ int kill_src_buffer = 0;
buffer = Fcurrent_buffer ();
set_buffer_internal (XBUFFER (coding->src_object));
}
- call2 (CODING_ATTR_PRE_WRITE (attrs),
- make_number (BEG), make_number (Z));
+ {
+ Lisp_Object args[3];
+
+ args[0] = CODING_ATTR_PRE_WRITE (attrs);
+ args[1] = make_number (BEG);
+ args[2] = make_number (Z);
+ safe_call (3, args);
+ }
+ if (XBUFFER (coding->src_object) != current_buffer)
+ kill_src_buffer = 1;
coding->src_object = Fcurrent_buffer ();
if (BEG != GPT)
move_gap_both (BEG, BEG_BYTE);
saved_pt_byte + (coding->produced - bytes));
}
+ if (kill_src_buffer)
+ Fkill_buffer (coding->src_object);
unbind_to (count, Qnil);
}
CODING_ATTR_PLIST (attrs)
= Fcons (QCcategory, Fcons (AREF (Vcoding_category_table, category),
CODING_ATTR_PLIST (attrs)));
+ CODING_ATTR_PLIST (attrs)
+ = Fcons (QCascii_compatible_p,
+ Fcons (CODING_ATTR_ASCII_COMPAT (attrs),
+ CODING_ATTR_PLIST (attrs)));
eol_type = args[coding_arg_eol_type];
if (! NILP (eol_type)
CHECK_SYMBOL (val);
CODING_ATTR_PRE_WRITE (attrs) = val;
}
+ else if (EQ (prop, QCascii_compatible_p))
+ {
+ CODING_ATTR_ASCII_COMPAT (attrs) = val;
+ }
CODING_ATTR_PLIST (attrs)
= Fplist_put (CODING_ATTR_PLIST (attrs), prop, val);
DEFSYM (QCencode_translation_table, ":encode-translation-table");
DEFSYM (QCpost_read_conversion, ":post-read-conversion");
DEFSYM (QCpre_write_conversion, ":pre-write-conversion");
+ DEFSYM (QCascii_compatible_p, ":ascii-compatible-p");
Vcoding_category_table
= Fmake_vector (make_number (coding_category_max), Qnil);
On detecting a coding system, Emacs tries code detection algorithms
associated with each coding-category one by one in this order. When
one algorithm agrees with a byte sequence of source text, the coding
-system bound to the corresponding coding-category is selected. */);
+system bound to the corresponding coding-category is selected.
+
+Don't modify this variable directly, but use `set-coding-priority'. */);
{
int i;
plist[3] = args[coding_arg_mnemonic] = make_number ('-');
plist[5] = args[coding_arg_coding_type] = Qundecided;
/* This is already set.
- /*plist[7] = args[coding_arg_ascii_compatible_p] = Qt;*/
+ plist[7] = args[coding_arg_ascii_compatible_p] = Qt; */
plist[8] = intern (":charset-list");
plist[9] = args[coding_arg_charset_list] = Fcons (Qascii, Qnil);
plist[11] = args[coding_arg_for_unibyte] = Qnil;