This describes a permutation of the possible coding categories. */
int coding_category_by_priority[CODING_CATEGORY_LAST + 1];
+#ifndef UTF2000
Lisp_Object ucs_to_mule_table[65536];
+#endif
} *fcd;
static const struct lrecord_description fcd_description_1[] = {
{ XD_LISP_OBJECT, offsetof(struct file_coding_dump, coding_category_system), CODING_CATEGORY_LAST + 1 },
+#ifndef UTF2000
{ XD_LISP_OBJECT, offsetof(struct file_coding_dump, ucs_to_mule_table), 65536 },
+#endif
{ XD_END }
};
sizeof(charset_conversion_spec),
ccs_description_1
};
-
+
static const struct lrecord_description ccsd_description_1[] = {
XD_DYNARR_DESC(charset_conversion_spec_dynarr, &ccs_description),
{ XD_END }
}
}
-static enum eol_type
+static eol_type_t
symbol_to_eol_type (Lisp_Object symbol)
{
CHECK_SYMBOL (symbol);
}
static Lisp_Object
-eol_type_to_symbol (enum eol_type type)
+eol_type_to_symbol (eol_type_t type)
{
switch (type)
{
(struct coding_system_list_closure *) coding_system_list_closure;
Lisp_Object *coding_system_list = cscl->coding_system_list;
- *coding_system_list = Fcons (XCODING_SYSTEM (value)->name,
- *coding_system_list);
+ *coding_system_list = Fcons (key, *coding_system_list);
return 0;
}
FROB (CR, "-mac");
#undef FROB
}
- /* FSF return value is a vector of [ALIAS-unix ALIAS-doc ALIAS-mac],
+ /* FSF return value is a vector of [ALIAS-unix ALIAS-dos ALIAS-mac],
but it doesn't look intentional, so I'd rather return something
meaningful or nothing at all. */
return Qnil;
}
static Lisp_Object
-subsidiary_coding_system (Lisp_Object coding_system, enum eol_type type)
+subsidiary_coding_system (Lisp_Object coding_system, eol_type_t type)
{
Lisp_Coding_System *cs = XCODING_SYSTEM (coding_system);
Lisp_Object new_coding_system;
struct detection_state
{
- enum eol_type eol_type;
+ eol_type_t eol_type;
int seen_non_ascii;
int mask;
#ifdef MULE
return (mask & (mask - 1)) == 0;
}
-static enum eol_type
+static eol_type_t
detect_eol_type (struct detection_state *st, CONST unsigned char *src,
unsigned int n)
{
while (n--)
{
c = *src++;
- if (c == '\r')
- st->eol.just_saw_cr = 1;
- else
+ if (c == '\n')
{
- if (c == '\n')
- {
- if (st->eol.just_saw_cr)
- return EOL_CRLF;
- else if (st->eol.seen_anything)
- return EOL_LF;
- }
- else if (st->eol.just_saw_cr)
- return EOL_CR;
- st->eol.just_saw_cr = 0;
+ if (st->eol.just_saw_cr)
+ return EOL_CRLF;
+ else if (st->eol.seen_anything)
+ return EOL_LF;
}
+ else if (st->eol.just_saw_cr)
+ return EOL_CR;
+ else if (c == '\r')
+ st->eol.just_saw_cr = 1;
+ else
+ st->eol.just_saw_cr = 0;
st->eol.seen_anything = 1;
}
*/
static int
-detect_coding_type (struct detection_state *st, CONST unsigned char *src,
+detect_coding_type (struct detection_state *st, CONST Extbyte *src,
unsigned int n, int just_do_eol)
{
int c;
/* Given a seekable read stream and potential coding system and EOL type
as specified, do any autodetection that is called for. If the
- coding system and/or EOL type are not autodetect, they will be left
+ coding system and/or EOL type are not `autodetect', they will be left
alone; but this function will never return an autodetect coding system
or EOL type.
This function does not automatically fetch subsidiary coding systems;
that should be unnecessary with the explicit eol-type argument. */
+#define LENGTH(string_constant) (sizeof (string_constant) - 1)
+
void
determine_real_coding_system (Lstream *stream, Lisp_Object *codesys_in_out,
- enum eol_type *eol_type_in_out)
+ eol_type_t *eol_type_in_out)
{
struct detection_state decst;
decst.mask = ~0;
/* If autodetection is called for, do it now. */
- if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT ||
- *eol_type_in_out == EOL_AUTODETECT)
+ if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT
+ || *eol_type_in_out == EOL_AUTODETECT)
{
- unsigned char random_buffer[4096];
- int nread;
+ Extbyte buf[4096];
Lisp_Object coding_system = Qnil;
-
- nread = Lstream_read (stream, random_buffer, sizeof (random_buffer));
- if (nread)
- {
- unsigned char *cp = random_buffer;
-
- while (cp < random_buffer + nread)
- {
- if ((*cp++ == 'c') && (cp < random_buffer + nread) &&
- (*cp++ == 'o') && (cp < random_buffer + nread) &&
- (*cp++ == 'd') && (cp < random_buffer + nread) &&
- (*cp++ == 'i') && (cp < random_buffer + nread) &&
- (*cp++ == 'n') && (cp < random_buffer + nread) &&
- (*cp++ == 'g') && (cp < random_buffer + nread) &&
- (*cp++ == ':') && (cp < random_buffer + nread))
+ Extbyte *p;
+ ssize_t nread = Lstream_read (stream, buf, sizeof (buf));
+ Extbyte *scan_end;
+
+ /* Look for initial "-*-"; mode line prefix */
+ for (p = buf,
+ scan_end = buf + nread - LENGTH ("-*-coding:?-*-");
+ p <= scan_end
+ && *p != '\n'
+ && *p != '\r';
+ p++)
+ if (*p == '-' && *(p+1) == '*' && *(p+2) == '-')
+ {
+ Extbyte *local_vars_beg = p + 3;
+ /* Look for final "-*-"; mode line suffix */
+ for (p = local_vars_beg,
+ scan_end = buf + nread - LENGTH ("-*-");
+ p <= scan_end
+ && *p != '\n'
+ && *p != '\r';
+ p++)
+ if (*p == '-' && *(p+1) == '*' && *(p+2) == '-')
{
- unsigned char coding_system_name[4096 - 6];
- unsigned char *np = coding_system_name;
-
- while ( (cp < random_buffer + nread)
- && ((*cp == ' ') || (*cp == '\t')) )
- {
- cp++;
- }
- while ( (cp < random_buffer + nread) &&
- (*cp != ' ') && (*cp != '\t') && (*cp != ';') )
- {
- *np++ = *cp++;
- }
- *np = 0;
- coding_system
- = Ffind_coding_system (intern ((char *) coding_system_name));
+ Extbyte *suffix = p;
+ /* Look for "coding:" */
+ for (p = local_vars_beg,
+ scan_end = suffix - LENGTH ("coding:?");
+ p <= scan_end;
+ p++)
+ if (memcmp ("coding:", p, LENGTH ("coding:")) == 0
+ && (p == local_vars_beg
+ || (*(p-1) == ' ' ||
+ *(p-1) == '\t' ||
+ *(p-1) == ';')))
+ {
+ Extbyte save;
+ int n;
+ p += LENGTH ("coding:");
+ while (*p == ' ' || *p == '\t') p++;
+
+ /* Get coding system name */
+ save = *suffix; *suffix = '\0';
+ /* Characters valid in a MIME charset name (rfc 1521),
+ and in a Lisp symbol name. */
+ n = strspn ( (char *) p,
+ "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789"
+ "!$%&*+-.^_{|}~");
+ *suffix = save;
+ if (n > 0)
+ {
+ save = p[n]; p[n] = '\0';
+ coding_system =
+ Ffind_coding_system (intern ((char *) p));
+ p[n] = save;
+ }
+ break;
+ }
break;
}
- }
- if (EQ(coding_system, Qnil))
- do{
- if (detect_coding_type (&decst, random_buffer, nread,
- XCODING_SYSTEM_TYPE (*codesys_in_out)
- != CODESYS_AUTODETECT))
- break;
- nread = Lstream_read (stream,
- random_buffer, sizeof (random_buffer));
- if (!nread)
- break;
- } while(1);
- }
+ break;
+ }
+
+ if (NILP (coding_system))
+ do
+ {
+ if (detect_coding_type (&decst, buf, nread,
+ XCODING_SYSTEM_TYPE (*codesys_in_out)
+ != CODESYS_AUTODETECT))
+ break;
+ nread = Lstream_read (stream, buf, sizeof (buf));
+ if (nread == 0)
+ break;
+ }
+ while (1);
+
+ else if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT
+ && XCODING_SYSTEM_EOL_TYPE (coding_system) == EOL_AUTODETECT)
+ do
+ {
+ if (detect_coding_type (&decst, buf, nread, 1))
+ break;
+ nread = Lstream_read (stream, buf, sizeof (buf));
+ if (!nread)
+ break;
+ }
+ while (1);
+
*eol_type_in_out = decst.eol_type;
if (XCODING_SYSTEM_TYPE (*codesys_in_out) == CODESYS_AUTODETECT)
{
- if (EQ(coding_system, Qnil))
+ if (NILP (coding_system))
*codesys_in_out = coding_system_from_mask (decst.mask);
else
*codesys_in_out = coding_system;
}
}
+
/* If we absolutely can't determine the EOL type, just assume LF. */
if (*eol_type_in_out == EOL_AUTODETECT)
*eol_type_in_out = EOL_LF;
while (1)
{
unsigned char random_buffer[4096];
- int nread = Lstream_read (istr, random_buffer, sizeof (random_buffer));
+ ssize_t nread = Lstream_read (istr, random_buffer, sizeof (random_buffer));
if (!nread)
break;
/* C should be a binary character in the range 0 - 255; convert
to internal format and add to Dynarr DST. */
+#ifdef UTF2000
+#define DECODE_ADD_BINARY_CHAR(c, dst) \
+do { \
+ if (BYTE_ASCII_P (c)) \
+ Dynarr_add (dst, c); \
+ else \
+ { \
+ Dynarr_add (dst, (c >> 6) | 0xc0); \
+ Dynarr_add (dst, (c & 0x3f) | 0x80); \
+ } \
+} while (0)
+
+INLINE void
+DECODE_ADD_UCS_CHAR(Emchar c, unsigned_char_dynarr* dst)
+{
+ if ( c <= 0x7f )
+ {
+ Dynarr_add (dst, c);
+ }
+ else if ( c <= 0x7ff )
+ {
+ Dynarr_add (dst, (c >> 6) | 0xc0);
+ Dynarr_add (dst, (c & 0x3f) | 0x80);
+ }
+ else if ( c <= 0xffff )
+ {
+ Dynarr_add (dst, (c >> 12) | 0xe0);
+ Dynarr_add (dst, ((c >> 6) & 0x3f) | 0x80);
+ Dynarr_add (dst, (c & 0x3f) | 0x80);
+ }
+ else if ( c <= 0x1fffff )
+ {
+ Dynarr_add (dst, (c >> 18) | 0xf0);
+ Dynarr_add (dst, ((c >> 12) & 0x3f) | 0x80);
+ Dynarr_add (dst, ((c >> 6) & 0x3f) | 0x80);
+ Dynarr_add (dst, (c & 0x3f) | 0x80);
+ }
+ else if ( c <= 0x3ffffff )
+ {
+ Dynarr_add (dst, (c >> 24) | 0xf8);
+ Dynarr_add (dst, ((c >> 18) & 0x3f) | 0x80);
+ Dynarr_add (dst, ((c >> 12) & 0x3f) | 0x80);
+ Dynarr_add (dst, ((c >> 6) & 0x3f) | 0x80);
+ Dynarr_add (dst, (c & 0x3f) | 0x80);
+ }
+ else
+ {
+ Dynarr_add (dst, (c >> 30) | 0xfc);
+ Dynarr_add (dst, ((c >> 24) & 0x3f) | 0x80);
+ Dynarr_add (dst, ((c >> 18) & 0x3f) | 0x80);
+ Dynarr_add (dst, ((c >> 12) & 0x3f) | 0x80);
+ Dynarr_add (dst, ((c >> 6) & 0x3f) | 0x80);
+ Dynarr_add (dst, (c & 0x3f) | 0x80);
+ }
+}
+#else
#define DECODE_ADD_BINARY_CHAR(c, dst) \
do { \
if (BYTE_ASCII_P (c)) \
Dynarr_add (dst, c); \
} \
} while (0)
+#endif
#define DECODE_OUTPUT_PARTIAL_CHAR(ch) \
do { \
EOL type stored in CODESYS because the latter might indicate
automatic EOL-type detection while the former will always
indicate a particular EOL type. */
- enum eol_type eol_type;
+ eol_type_t eol_type;
#ifdef MULE
/* Additional ISO2022 information. We define the structure above
because it's also needed by the detection routines. */
struct detection_state decst;
};
-static int decoding_reader (Lstream *stream, unsigned char *data, size_t size);
-static int decoding_writer (Lstream *stream, CONST unsigned char *data, size_t size);
+static ssize_t decoding_reader (Lstream *stream,
+ unsigned char *data, size_t size);
+static ssize_t decoding_writer (Lstream *stream,
+ CONST unsigned char *data, size_t size);
static int decoding_rewinder (Lstream *stream);
static int decoding_seekable_p (Lstream *stream);
static int decoding_flusher (Lstream *stream);
/* Read SIZE bytes of data and store it into DATA. We are a decoding stream
so we read data from the other end, decode it, and store it into DATA. */
-static int
+static ssize_t
decoding_reader (Lstream *stream, unsigned char *data, size_t size)
{
struct decoding_stream *str = DECODING_STREAM_DATA (stream);
unsigned char *orig_data = data;
- int read_size;
+ ssize_t read_size;
int error_occurred = 0;
/* We need to interface to mule_decode(), which expects to take some
return data - orig_data;
}
-static int
+static ssize_t
decoding_writer (Lstream *stream, CONST unsigned char *data, size_t size)
{
struct decoding_stream *str = DECODING_STREAM_DATA (stream);
- int retval;
+ ssize_t retval;
/* Decode all our data into the runoff, and then attempt to write
it all out to the other end. Remove whatever chunk we succeeded
char tempbuf[1024]; /* some random amount */
Bufpos newpos, even_newer_pos;
Bufpos oldpos = lisp_buffer_stream_startpos (istr);
- int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
+ ssize_t size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
if (!size_in_bytes)
break;
#endif /* MULE */
};
-static int encoding_reader (Lstream *stream, unsigned char *data, size_t size);
-static int encoding_writer (Lstream *stream, CONST unsigned char *data,
- size_t size);
+static ssize_t encoding_reader (Lstream *stream, unsigned char *data, size_t size);
+static ssize_t encoding_writer (Lstream *stream, CONST unsigned char *data,
+ size_t size);
static int encoding_rewinder (Lstream *stream);
static int encoding_seekable_p (Lstream *stream);
static int encoding_flusher (Lstream *stream);
/* Read SIZE bytes of data and store it into DATA. We are a encoding stream
so we read data from the other end, encode it, and store it into DATA. */
-static int
+static ssize_t
encoding_reader (Lstream *stream, unsigned char *data, size_t size)
{
struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
unsigned char *orig_data = data;
- int read_size;
+ ssize_t read_size;
int error_occurred = 0;
/* We need to interface to mule_encode(), which expects to take some
return data - orig_data;
}
-static int
+static ssize_t
encoding_writer (Lstream *stream, CONST unsigned char *data, size_t size)
{
struct encoding_stream *str = ENCODING_STREAM_DATA (stream);
- int retval;
+ ssize_t retval;
/* Encode all our data into the runoff, and then attempt to write
it all out to the other end. Remove whatever chunk we succeeded
str->iso2022.register_right = 1;
str->iso2022.current_charset = Qnil;
str->iso2022.current_half = 0;
+#ifdef UTF2000
+ str->iso2022.current_char_boundary = 0;
+#else
str->iso2022.current_char_boundary = 1;
+#endif
break;
}
case CODESYS_CCL:
char tempbuf[1024]; /* some random amount */
Bufpos newpos, even_newer_pos;
Bufpos oldpos = lisp_buffer_stream_startpos (istr);
- int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
+ ssize_t size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
if (!size_in_bytes)
break;
{
unsigned char e1, e2;
- Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
DECODE_SJIS (ch, c, e1, e2);
+#ifdef UTF2000
+ DECODE_ADD_UCS_CHAR(MAKE_CHAR(Vcharset_japanese_jisx0208,
+ e1 & 0x7F,
+ e2 & 0x7F), dst);
+#else
+ Dynarr_add (dst, LEADING_BYTE_JAPANESE_JISX0208);
Dynarr_add (dst, e1);
Dynarr_add (dst, e2);
+#endif
}
else
{
ch = c;
else if (BYTE_SJIS_KATAKANA_P (c))
{
+#ifdef UTF2000
+ DECODE_ADD_UCS_CHAR(MAKE_CHAR(Vcharset_katakana_jisx0201,
+ c & 0x7F, 0), dst);
+#else
Dynarr_add (dst, LEADING_BYTE_KATAKANA_JISX0201);
Dynarr_add (dst, c);
+#endif
}
else
DECODE_ADD_BINARY_CHAR (c, dst);
unsigned int flags = str->flags;
unsigned int ch = str->ch;
eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
+#ifdef UTF2000
+ unsigned char char_boundary = str->iso2022.current_char_boundary;
+#endif
while (n--)
{
c = *src++;
+#ifdef UTF2000
+ switch (char_boundary)
+ {
+ case 0:
+ if ( c >= 0xfc )
+ {
+ ch = c & 0x01;
+ char_boundary = 5;
+ }
+ else if ( c >= 0xf8 )
+ {
+ ch = c & 0x03;
+ char_boundary = 4;
+ }
+ else if ( c >= 0xf0 )
+ {
+ ch = c & 0x07;
+ char_boundary = 3;
+ }
+ else if ( c >= 0xe0 )
+ {
+ ch = c & 0x0f;
+ char_boundary = 2;
+ }
+ else if ( c >= 0xc0 )
+ {
+ ch = c & 0x1f;
+ char_boundary = 1;
+ }
+ else
+ {
+ ch = 0;
+ if (c == '\n')
+ {
+ if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
+ Dynarr_add (dst, '\r');
+ if (eol_type != EOL_CR)
+ Dynarr_add (dst, c);
+ }
+ else
+ Dynarr_add (dst, c);
+ char_boundary = 0;
+ }
+ break;
+ case 1:
+ ch = ( ch << 6 ) | ( c & 0x3f );
+ {
+ Lisp_Object charset;
+ unsigned int c1, c2, s1, s2;
+
+ BREAKUP_CHAR (ch, charset, c1, c2);
+ if (EQ(charset, Vcharset_katakana_jisx0201))
+ {
+ Dynarr_add (dst, c1 | 0x80);
+ }
+ else if (EQ(charset, Vcharset_japanese_jisx0208))
+ {
+ ENCODE_SJIS (c1 | 0x80, c2 | 0x80, s1, s2);
+ Dynarr_add (dst, s1);
+ Dynarr_add (dst, s2);
+ }
+ }
+ char_boundary = 0;
+ break;
+ default:
+ ch = ( ch << 6 ) | ( c & 0x3f );
+ char_boundary--;
+ }
+#else
if (c == '\n')
{
if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
ch = 0;
}
}
+#endif
}
str->flags = flags;
str->ch = ch;
+#ifdef UTF2000
+ str->iso2022.current_char_boundary = char_boundary;
+#endif
}
DEFUN ("decode-shift-jis-char", Fdecode_shift_jis_char, 1, 1, 0, /*
encode_coding_big5 (Lstream *encoding, CONST unsigned char *src,
unsigned_char_dynarr *dst, unsigned int n)
{
+#ifndef UTF2000
unsigned char c;
struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
unsigned int flags = str->flags;
str->flags = flags;
str->ch = ch;
+#endif
}
if (BYTE_BIG5_TWO_BYTE_1_P (b1) &&
BYTE_BIG5_TWO_BYTE_2_P (b2))
{
- int leading_byte;
+ Charset_ID leading_byte;
Lisp_Object charset;
DECODE_BIG5 (b1, b2, leading_byte, c1, c2);
charset = CHARSET_BY_LEADING_BYTE (leading_byte);
/* */
/************************************************************************/
-
+#ifndef UTF2000
DEFUN ("set-ucs-char", Fset_ucs_char, 2, 2, 0, /*
Map UCS-4 code CODE to Mule character CHARACTER.
{
return Fget_char_table (character, mule_to_ucs_table);
}
+#endif
+#ifdef UTF2000
+#define decode_ucs4 DECODE_ADD_UCS_CHAR
+#else
/* Decode a UCS-4 character into a buffer. If the lookup fails, use
<GETA MARK> (U+3013) of JIS X 0208, which means correct character
is not found, instead.
Dynarr_add (dst, 46 + 128);
}
}
+#endif
+#ifndef UTF2000
static unsigned long
mule_char_to_ucs4 (Lisp_Object charset,
unsigned char h, unsigned char l)
Dynarr_add (dst, (code >> 8) & 255);
Dynarr_add (dst, code & 255);
}
+#endif
static int
detect_coding_ucs4 (struct detection_state *st, CONST unsigned char *src,
encode_coding_ucs4 (Lstream *encoding, CONST unsigned char *src,
unsigned_char_dynarr *dst, unsigned int n)
{
+#ifndef UTF2000
struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
unsigned int flags = str->flags;
unsigned int ch = str->ch;
str->iso2022.current_charset = charset;
/* Verbum caro factum est! */
+#endif
}
\f
str->counter = counter;
}
+#ifndef UTF2000
static void
encode_utf8 (Lisp_Object charset,
unsigned char h, unsigned char l, unsigned_char_dynarr *dst)
Dynarr_add (dst, (code & 0x3f) | 0x80);
}
}
+#endif
static void
encode_coding_utf8 (Lstream *encoding, CONST unsigned char *src,
unsigned int ch = str->ch;
eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
unsigned char char_boundary = str->iso2022.current_char_boundary;
+#ifdef UTF2000
+
+ while (n--)
+ {
+ unsigned char c = *src++;
+ switch (char_boundary)
+ {
+ case 0:
+ if ( c >= 0xfc )
+ {
+ Dynarr_add (dst, c);
+ char_boundary = 5;
+ }
+ else if ( c >= 0xf8 )
+ {
+ Dynarr_add (dst, c);
+ char_boundary = 4;
+ }
+ else if ( c >= 0xf0 )
+ {
+ Dynarr_add (dst, c);
+ char_boundary = 3;
+ }
+ else if ( c >= 0xe0 )
+ {
+ Dynarr_add (dst, c);
+ char_boundary = 2;
+ }
+ else if ( c >= 0xc0 )
+ {
+ Dynarr_add (dst, c);
+ char_boundary = 1;
+ }
+ else
+ {
+ if (c == '\n')
+ {
+ if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
+ Dynarr_add (dst, '\r');
+ if (eol_type != EOL_CR)
+ Dynarr_add (dst, c);
+ }
+ else
+ Dynarr_add (dst, c);
+ char_boundary = 0;
+ }
+ break;
+ case 1:
+ Dynarr_add (dst, c);
+ char_boundary = 0;
+ break;
+ default:
+ Dynarr_add (dst, c);
+ char_boundary--;
+ }
+ }
+#else /* not UTF2000 */
Lisp_Object charset = str->iso2022.current_charset;
#ifdef ENABLE_COMPOSITE_CHARS
back_to_square_n:
#endif /* ENABLE_COMPOSITE_CHARS */
-
+
while (n--)
{
unsigned char c = *src++;
}
#endif
+#endif /* not UTF2000 */
str->flags = flags;
str->ch = ch;
str->iso2022.current_char_boundary = char_boundary;
+#ifndef UTF2000
str->iso2022.current_charset = charset;
+#endif
/* Verbum caro factum est! */
}
else
{ /* Graphic characters */
Lisp_Object charset;
- int lb;
+#ifndef UTF2000
+ Charset_ID lb;
+#endif
int reg;
DECODE_HANDLE_EOL_TYPE (eol_type, c, flags, dst);
charset = new_charset;
}
+#ifdef UTF2000
+ if (XCHARSET_DIMENSION (charset) == 1)
+ {
+ DECODE_OUTPUT_PARTIAL_CHAR (ch);
+ DECODE_ADD_UCS_CHAR
+ (MAKE_CHAR (charset, c & 0x7F, 0), dst);
+ }
+ else if (ch)
+ {
+ DECODE_ADD_UCS_CHAR
+ (MAKE_CHAR (charset, ch & 0x7F, c & 0x7F), dst);
+ ch = 0;
+ }
+ else
+ ch = c;
+#else
lb = XCHARSET_LEADING_BYTE (charset);
switch (XCHARSET_REP_BYTES (charset))
{
else
ch = c;
}
+#endif
}
if (!ch)
unsigned char char_boundary;
struct encoding_stream *str = ENCODING_STREAM_DATA (encoding);
unsigned int flags = str->flags;
- unsigned int ch = str->ch;
+ Emchar ch = str->ch;
Lisp_Coding_System *codesys = str->codesys;
eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
int i;
Lisp_Object charset;
int half;
+#ifdef UTF2000
+ unsigned int byte1, byte2;
+#endif
#ifdef ENABLE_COMPOSITE_CHARS
/* flags for handling composite chars. We do a little switcharoo
#ifdef ENABLE_COMPOSITE_CHARS
back_to_square_n:
#endif
+#ifdef UTF2000
+ while (n--)
+ {
+ c = *src++;
+
+ switch (char_boundary)
+ {
+ case 0:
+ if ( c >= 0xfc )
+ {
+ ch = c & 0x01;
+ char_boundary = 5;
+ }
+ else if ( c >= 0xf8 )
+ {
+ ch = c & 0x03;
+ char_boundary = 4;
+ }
+ else if ( c >= 0xf0 )
+ {
+ ch = c & 0x07;
+ char_boundary = 3;
+ }
+ else if ( c >= 0xe0 )
+ {
+ ch = c & 0x0f;
+ char_boundary = 2;
+ }
+ else if ( c >= 0xc0 )
+ {
+ ch = c & 0x1f;
+ char_boundary = 1;
+ }
+ else
+ {
+ ch = 0;
+
+ restore_left_to_right_direction (codesys, dst, &flags, 0);
+
+ /* Make sure G0 contains ASCII */
+ if ((c > ' ' && c < ISO_CODE_DEL) ||
+ !CODING_SYSTEM_ISO2022_NO_ASCII_CNTL (codesys))
+ {
+ ensure_normal_shift (str, dst);
+ iso2022_designate (Vcharset_ascii, 0, str, dst);
+ }
+
+ /* If necessary, restore everything to the default state
+ at end-of-line */
+ if (c == '\n' &&
+ !(CODING_SYSTEM_ISO2022_NO_ASCII_EOL (codesys)))
+ {
+ restore_left_to_right_direction (codesys, dst, &flags, 0);
+
+ ensure_normal_shift (str, dst);
+
+ for (i = 0; i < 4; i++)
+ {
+ Lisp_Object initial_charset =
+ CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i);
+ iso2022_designate (initial_charset, i, str, dst);
+ }
+ }
+ if (c == '\n')
+ {
+ if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
+ Dynarr_add (dst, '\r');
+ if (eol_type != EOL_CR)
+ Dynarr_add (dst, c);
+ }
+ else
+ {
+ if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
+ && fit_to_be_escape_quoted (c))
+ Dynarr_add (dst, ISO_CODE_ESC);
+ Dynarr_add (dst, c);
+ }
+ char_boundary = 0;
+ }
+ break;
+ case 1:
+ ch = ( ch << 6 ) | ( c & 0x3f );
+
+ char_boundary = 0;
+ if ( (0x80 <= ch) && (ch <= 0x9f) )
+ {
+ charmask = (half == 0 ? 0x00 : 0x80);
+
+ if (CODING_SYSTEM_ISO2022_ESCAPE_QUOTED (codesys)
+ && fit_to_be_escape_quoted (ch))
+ Dynarr_add (dst, ISO_CODE_ESC);
+ /* you asked for it ... */
+ Dynarr_add (dst, ch);
+ }
+ else
+ {
+ int reg;
+
+ BREAKUP_CHAR (ch, charset, byte1, byte2);
+ ensure_correct_direction (XCHARSET_DIRECTION (charset),
+ codesys, dst, &flags, 0);
+
+ /* Now determine which register to use. */
+ reg = -1;
+ for (i = 0; i < 4; i++)
+ {
+ if (EQ (charset, str->iso2022.charset[i]) ||
+ EQ (charset,
+ CODING_SYSTEM_ISO2022_INITIAL_CHARSET (codesys, i)))
+ {
+ reg = i;
+ break;
+ }
+ }
+
+ if (reg == -1)
+ {
+ if (XCHARSET_GRAPHIC (charset) != 0)
+ {
+ if (!NILP (str->iso2022.charset[1]) &&
+ (!CODING_SYSTEM_ISO2022_SEVEN (codesys) ||
+ CODING_SYSTEM_ISO2022_LOCK_SHIFT (codesys)))
+ reg = 1;
+ else if (!NILP (str->iso2022.charset[2]))
+ reg = 2;
+ else if (!NILP (str->iso2022.charset[3]))
+ reg = 3;
+ else
+ reg = 0;
+ }
+ else
+ reg = 0;
+ }
+
+ iso2022_designate (charset, reg, str, dst);
+
+ /* Now invoke that register. */
+ switch (reg)
+ {
+ case 0:
+ ensure_normal_shift (str, dst);
+ half = 0;
+ break;
+
+ case 1:
+ if (CODING_SYSTEM_ISO2022_SEVEN (codesys))
+ {
+ ensure_shift_out (str, dst);
+ half = 0;
+ }
+ else
+ half = 1;
+ break;
+
+ case 2:
+ if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
+ {
+ Dynarr_add (dst, ISO_CODE_ESC);
+ Dynarr_add (dst, 'N');
+ half = 0;
+ }
+ else
+ {
+ Dynarr_add (dst, ISO_CODE_SS2);
+ half = 1;
+ }
+ break;
+
+ case 3:
+ if (CODING_SYSTEM_ISO2022_SEVEN (str->codesys))
+ {
+ Dynarr_add (dst, ISO_CODE_ESC);
+ Dynarr_add (dst, 'O');
+ half = 0;
+ }
+ else
+ {
+ Dynarr_add (dst, ISO_CODE_SS3);
+ half = 1;
+ }
+ break;
+
+ default:
+ abort ();
+ }
+
+ charmask = (half == 0 ? 0x00 : 0x80);
+
+ switch (XCHARSET_DIMENSION (charset))
+ {
+ case 1:
+ Dynarr_add (dst, byte1 | charmask);
+ break;
+ case 2:
+ Dynarr_add (dst, byte1 | charmask);
+ Dynarr_add (dst, byte2 | charmask);
+ break;
+ default:
+ abort ();
+ }
+ }
+ ch =0;
+ break;
+ default:
+ ch = ( ch << 6 ) | ( c & 0x3f );
+ char_boundary--;
+ }
+ }
+#else /* not UTF2000 */
+
while (n--)
{
c = *src++;
}
}
}
+#endif /* not UTF2000 */
#ifdef ENABLE_COMPOSITE_CHARS
if (in_composite)
}
#endif /* ENABLE_COMPOSITE_CHARS */
+#ifdef UTF2000
+ if ( (char_boundary == 0) && flags & CODING_STATE_END)
+#else
if (char_boundary && flags & CODING_STATE_END)
+#endif
{
restore_left_to_right_direction (codesys, dst, &flags, 0);
ensure_normal_shift (str, dst);
unsigned int flags = str->flags;
unsigned int ch = str->ch;
eol_type_t eol_type = CODING_SYSTEM_EOL_TYPE (str->codesys);
+#ifdef UTF2000
+ unsigned char char_boundary = str->iso2022.current_char_boundary;
+#endif
while (n--)
{
- c = *src++;
+ c = *src++;
+#ifdef UTF2000
+ switch (char_boundary)
+ {
+ case 0:
+ if ( c >= 0xfc )
+ {
+ ch = c & 0x01;
+ char_boundary = 5;
+ }
+ else if ( c >= 0xf8 )
+ {
+ ch = c & 0x03;
+ char_boundary = 4;
+ }
+ else if ( c >= 0xf0 )
+ {
+ ch = c & 0x07;
+ char_boundary = 3;
+ }
+ else if ( c >= 0xe0 )
+ {
+ ch = c & 0x0f;
+ char_boundary = 2;
+ }
+ else if ( c >= 0xc0 )
+ {
+ ch = c & 0x1f;
+ char_boundary = 1;
+ }
+ else
+ {
+ ch = 0;
+
+ if (c == '\n')
+ {
+ if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
+ Dynarr_add (dst, '\r');
+ if (eol_type != EOL_CR)
+ Dynarr_add (dst, c);
+ }
+ else
+ Dynarr_add (dst, c);
+ char_boundary = 0;
+ }
+ break;
+ case 1:
+ ch = ( ch << 6 ) | ( c & 0x3f );
+ Dynarr_add (dst, ch & 0xff);
+ char_boundary = 0;
+ break;
+ default:
+ ch = ( ch << 6 ) | ( c & 0x3f );
+ char_boundary--;
+ }
+#else /* not UTF2000 */
if (c == '\n')
{
if (eol_type != EOL_LF && eol_type != EOL_AUTODETECT)
untranslatable character, so ignore it */
ch = 0;
}
+#endif /* not UTF2000 */
}
str->flags = flags;
str->ch = ch;
+#ifdef UTF2000
+ str->iso2022.current_char_boundary = char_boundary;
+#endif
}
\f
for (; ptr < end;)
{
+#ifdef UTF2000
+ Bufbyte c =
+ (*ptr < 0xc0) ? *ptr :
+ ((*ptr & 0x1f) << 6) | (*(ptr+1) & 0x3f);
+#else
Bufbyte c =
(BYTE_ASCII_P (*ptr)) ? *ptr :
(*ptr == LEADING_BYTE_CONTROL_1) ? (*(ptr+1) - 0x20) :
(*ptr == LEADING_BYTE_LATIN_ISO8859_1) ? (*(ptr+1)) :
'~';
-
+#endif
Dynarr_add (conversion_out_dynarr, (Extbyte) c);
INC_CHARPTR (ptr);
}
GCPRO3 (instream, outstream, da_outstream);
while (1)
{
- int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
+ ssize_t size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
if (!size_in_bytes)
break;
Lstream_write (ostr, tempbuf, size_in_bytes);
GCPRO3 (instream, outstream, da_outstream);
while (1)
{
- int size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
+ ssize_t size_in_bytes = Lstream_read (istr, tempbuf, sizeof (tempbuf));
if (!size_in_bytes)
break;
Lstream_write (ostr, tempbuf, size_in_bytes);
DEFSUBR (Fencode_shift_jis_char);
DEFSUBR (Fdecode_big5_char);
DEFSUBR (Fencode_big5_char);
+#ifndef UTF2000
DEFSUBR (Fset_ucs_char);
DEFSUBR (Fucs_char);
DEFSUBR (Fset_char_ucs);
DEFSUBR (Fchar_ucs);
+#endif /* not UTF2000 */
#endif /* MULE */
defsymbol (&Qcoding_systemp, "coding-system-p");
defsymbol (&Qno_conversion, "no-conversion");
list4 (Qeol_type, Qlf,
Qmnemonic, build_string ("Binary")));
+#ifdef UTF2000
+ Fmake_coding_system
+ (Qutf8, Qutf8,
+ build_string ("Coding-system of ISO/IEC 10646 UTF-8."),
+ list2 (Qmnemonic, build_string ("UTF8")));
+#endif
+
Fdefine_coding_system_alias (Qno_conversion, Qraw_text);
/* Need this for bootstrapping */
fcd->coding_category_system[CODING_CATEGORY_NO_CONVERSION] =
Fget_coding_system (Qraw_text);
-#ifdef MULE
+#ifdef UTF2000
+ fcd->coding_category_system[CODING_CATEGORY_UTF8]
+ = Fget_coding_system (Qutf8);
+#endif
+
+#if defined(MULE) && !defined(UTF2000)
{
unsigned int i;