} while (0)
-static void encode_eol P_ ((struct coding_system *, unsigned char *,
+static void encode_eol P_ ((struct coding_system *, const unsigned char *,
unsigned char *, int, int));
static void
while (mask && src < src_end)
{
ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
+ retry:
switch (c)
{
case ISO_CODE_ESC:
&& mask & CODING_CATEGORY_MASK_ISO_8_2)
{
int i = 1;
+
+ c = -1;
while (src < src_end)
{
ONE_MORE_BYTE_CHECK_MULTIBYTE (c, multibytep);
mask &= ~CODING_CATEGORY_MASK_ISO_8_2;
else
mask_found |= CODING_CATEGORY_MASK_ISO_8_2;
+ if (c >= 0)
+ /* This means that we have read one extra byte. */
+ goto retry;
}
}
break;
static void
encode_eol (coding, source, destination, src_bytes, dst_bytes)
struct coding_system *coding;
- unsigned char *source, *destination;
+ const unsigned char *source;
+ unsigned char *destination;
int src_bytes, dst_bytes;
{
- unsigned char *src = source;
+ const unsigned char *src = source;
unsigned char *dst = destination;
- unsigned char *src_end = src + src_bytes;
+ const unsigned char *src_end = src + src_bytes;
unsigned char *dst_end = dst + dst_bytes;
Lisp_Object translation_table;
/* SRC_BASE remembers the start position in source in each loop.
analyze multi-byte codes (within macro ONE_MORE_CHAR), or when
there's not enough destination area to produce encoded codes
(within macro EMIT_BYTES). */
- unsigned char *src_base;
+ const unsigned char *src_base;
+ unsigned char *tmp;
int c;
int selective_display = coding->mode & CODING_MODE_SELECTIVE_DISPLAY;
}
if (coding->eol_type == CODING_EOL_CR)
{
- for (src = destination; src < dst; src++)
- if (*src == '\n') *src = '\r';
+ for (tmp = destination; tmp < dst; tmp++)
+ if (*tmp == '\n') *tmp = '\r';
}
else if (selective_display)
{
- for (src = destination; src < dst; src++)
- if (*src == '\r') *src = '\n';
+ for (tmp = destination; tmp < dst; tmp++)
+ if (*tmp == '\r') *tmp = '\n';
}
}
if (coding->src_multibyte)
void
detect_coding (coding, src, src_bytes)
struct coding_system *coding;
- unsigned char *src;
+ const unsigned char *src;
int src_bytes;
{
unsigned int idx;
void
detect_eol (coding, src, src_bytes)
struct coding_system *coding;
- unsigned char *src;
+ const unsigned char *src;
int src_bytes;
{
Lisp_Object val;
int
decode_coding (coding, source, destination, src_bytes, dst_bytes)
struct coding_system *coding;
- unsigned char *source, *destination;
+ const unsigned char *source;
+ unsigned char *destination;
int src_bytes, dst_bytes;
{
int extra = 0;
if (coding->mode & CODING_MODE_LAST_BLOCK
&& coding->result == CODING_FINISH_INSUFFICIENT_SRC)
{
- unsigned char *src = source + coding->consumed;
+ const unsigned char *src = source + coding->consumed;
unsigned char *dst = destination + coding->produced;
src_bytes -= coding->consumed;
int
encode_coding (coding, source, destination, src_bytes, dst_bytes)
struct coding_system *coding;
- unsigned char *source, *destination;
+ const unsigned char *source;
+ unsigned char *destination;
int src_bytes, dst_bytes;
{
coding->produced = coding->produced_char = 0;
if (coding->mode & CODING_MODE_LAST_BLOCK
&& coding->result == CODING_FINISH_INSUFFICIENT_SRC)
{
- unsigned char *src = source + coding->consumed;
+ const unsigned char *src = source + coding->consumed;
unsigned char *dst = destination + coding->produced;
if (coding->type == coding_type_iso2022)
else
newstr = make_uninit_string (produced + shrinked_bytes);
if (from > 0)
- bcopy (SDATA (str), SDATA (newstr), from);
- bcopy (buf.data, SDATA (newstr) + from, produced);
+ STRING_COPYIN (newstr, 0, SDATA (str), from);
+ STRING_COPYIN (newstr, from, buf.data, produced);
if (shrinked_bytes > from)
- bcopy (SDATA (str) + to_byte,
- SDATA (newstr) + from + produced,
- shrinked_bytes - from);
+ STRING_COPYIN (newstr, from + produced,
+ SDATA (str) + to_byte,
+ shrinked_bytes - from);
free_conversion_buffer (&buf);
if (coding->cmp_data && coding->cmp_data->used)
newstr = make_uninit_string (produced + shrinked_bytes);
if (from > 0)
- bcopy (SDATA (str), SDATA (newstr), from);
- bcopy (buf.data, SDATA (newstr) + from, produced);
+ STRING_COPYIN (newstr, 0, SDATA (str), from);
+ STRING_COPYIN (newstr, from, buf.data, produced);
if (shrinked_bytes > from)
- bcopy (SDATA (str) + to_byte,
- SDATA (newstr) + from + produced,
- shrinked_bytes - from);
+ STRING_COPYIN (newstr, from + produced,
+ SDATA (str) + to_byte,
+ shrinked_bytes - from);
free_conversion_buffer (&buf);
coding_free_composition_data (coding);
\f
Lisp_Object
detect_coding_system (src, src_bytes, highest, multibytep)
- unsigned char *src;
+ const unsigned char *src;
int src_bytes, highest;
int multibytep;
{
if (nargs < 1 + XINT (target_idx))
error ("Too few arguments for operation: %s",
SDATA (SYMBOL_NAME (operation)));
+ /* For write-region, if the 6th argument (i.e. VISIT, the 5th
+ argument to write-region) is string, it must be treated as a
+ target file name. */
+ if (EQ (operation, Qwrite_region)
+ && nargs > 5
+ && STRINGP (args[5]))
+ target_idx = make_number (4);
target = args[XINT (target_idx) + 1];
if (!(STRINGP (target)
|| (EQ (operation, Qopen_network_stream) && INTEGERP (target))))