summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/ChangeLog16
-rw-r--r--src/callproc.c21
-rw-r--r--src/coding.c57
-rw-r--r--src/coding.h1
-rw-r--r--src/process.c36
5 files changed, 108 insertions, 23 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index b756aebe8a5..773715ed1f2 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,19 @@
+2010-09-30 Kenichi Handa <handa@m17n.org>
+
+ * coding.c (complement_process_encoding_system): New function.
+
+ * coding.h (complement_process_encoding_system): Extern it.
+
+ * callproc.c (Fcall_process): Complement the coding system for
+ encoding arguments.
+ (Fcall_process_region): Complement the coding system for encoding
+ the input to the process.
+
+ * process.c (Fstart_process): Complement the coding system for
+ encoding arguments.
+ (send_process): Complement the coding system for encoding what
+ sent to the process.
+
2010-09-29 Kenichi Handa <handa@m17n.org>
* xfont.c (xfont_open): Fix setting of font->average_width from
diff --git a/src/callproc.c b/src/callproc.c
index bed3302e508..863d4e41dbd 100644
--- a/src/callproc.c
+++ b/src/callproc.c
@@ -287,21 +287,16 @@ usage: (call-process PROGRAM &optional INFILE BUFFER DISPLAY &rest ARGS) */)
if (!NILP (Vcoding_system_for_write))
val = Vcoding_system_for_write;
else if (! must_encode)
- val = Qnil;
+ val = Qraw_text;
else
{
args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
args2[0] = Qcall_process;
for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
- if (CONSP (coding_systems))
- val = XCDR (coding_systems);
- else if (CONSP (Vdefault_process_coding_system))
- val = XCDR (Vdefault_process_coding_system);
- else
- val = Qnil;
+ val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil;
}
- val = coding_inherit_eol_type (val, Qnil);
+ val = complement_process_encoding_system (val);
setup_coding_system (Fcheck_coding_system (val), &argument_coding);
coding_attrs = CODING_ID_ATTRS (argument_coding.id);
if (NILP (CODING_ATTR_ASCII_COMPAT (coding_attrs)))
@@ -954,20 +949,16 @@ usage: (call-process-region START END PROGRAM &optional DELETE BUFFER DISPLAY &r
if (!NILP (Vcoding_system_for_write))
val = Vcoding_system_for_write;
else if (NILP (current_buffer->enable_multibyte_characters))
- val = Qnil;
+ val = Qraw_text;
else
{
args2 = (Lisp_Object *) alloca ((nargs + 1) * sizeof *args2);
args2[0] = Qcall_process_region;
for (i = 0; i < nargs; i++) args2[i + 1] = args[i];
coding_systems = Ffind_operation_coding_system (nargs + 1, args2);
- if (CONSP (coding_systems))
- val = XCDR (coding_systems);
- else if (CONSP (Vdefault_process_coding_system))
- val = XCDR (Vdefault_process_coding_system);
- else
- val = Qnil;
+ val = CONSP (coding_systems) ? XCDR (coding_systems) : Qnil;
}
+ val = complement_process_encoding_system (val);
{
int count1 = SPECPDL_INDEX ();
diff --git a/src/coding.c b/src/coding.c
index 92b328091ff..cbebeff6310 100644
--- a/src/coding.c
+++ b/src/coding.c
@@ -6112,6 +6112,63 @@ coding_inherit_eol_type (coding_system, parent)
return coding_system;
}
+
+/* Check if text-conversion and eol-conversion of CODING_SYSTEM are
+ decided for writing to a process. If not, complement them, and
+ return a new coding system. */
+
+Lisp_Object
+complement_process_encoding_system (coding_system)
+ Lisp_Object coding_system;
+{
+ Lisp_Object spec, attrs, coding_type, eol_type;
+
+ if (NILP (coding_system))
+ coding_system = Qundecided;
+ spec = CODING_SYSTEM_SPEC (coding_system);
+ attrs = AREF (spec, 0);
+ coding_type = CODING_ATTR_TYPE (attrs);
+ eol_type = AREF (spec, 2);
+
+ if (EQ (coding_type, Qundecided))
+ {
+ /* We must decide the text-conversion part. */
+ if (CONSP (Vdefault_process_coding_system))
+ {
+ coding_system = XCDR (Vdefault_process_coding_system);
+ if (! NILP (coding_system))
+ {
+ spec = CODING_SYSTEM_SPEC (coding_system);
+ attrs = AREF (spec, 0);
+ coding_type = CODING_ATTR_TYPE (attrs);
+ eol_type = AREF (spec, 2);
+ }
+ }
+ if (EQ (coding_type, Qundecided))
+ {
+ coding_system = preferred_coding_system ();
+ spec = CODING_SYSTEM_SPEC (coding_system);
+ attrs = AREF (spec, 0);
+ coding_type = CODING_ATTR_TYPE (attrs);
+ eol_type = AREF (spec, 2);
+ }
+ if (EQ (coding_type, Qundecided))
+ {
+ coding_system = Qraw_text;
+ coding_type = Qraw_text;
+ eol_type = Qnil;
+ }
+ }
+ if (NILP (eol_type) || VECTORP (eol_type))
+ {
+ /* We must decide the eol-conversion part. */
+ coding_system = coding_inherit_eol_type (coding_system, Qnil);
+ }
+
+ return coding_system;
+}
+
+
/* Emacs has a mechanism to automatically detect a coding system if it
is one of Emacs' internal format, ISO2022, SJIS, and BIG5. But,
it's impossible to distinguish some coding systems accurately
diff --git a/src/coding.h b/src/coding.h
index f47c33847f9..58d70644124 100644
--- a/src/coding.h
+++ b/src/coding.h
@@ -707,6 +707,7 @@ extern Lisp_Object code_convert_string_norecord P_ ((Lisp_Object, Lisp_Object,
int));
extern Lisp_Object raw_text_coding_system P_ ((Lisp_Object));
extern Lisp_Object coding_inherit_eol_type P_ ((Lisp_Object, Lisp_Object));
+extern Lisp_Object complement_process_encoding_system P_ ((Lisp_Object));
extern int decode_coding_gap P_ ((struct coding_system *,
EMACS_INT, EMACS_INT));
diff --git a/src/process.c b/src/process.c
index 7adc114075e..3e2aa61ffe6 100644
--- a/src/process.c
+++ b/src/process.c
@@ -1727,6 +1727,11 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
val = XCDR (Vdefault_process_coding_system);
}
XPROCESS (proc)->encode_coding_system = val;
+ /* Note: At this momemnt, the above coding system may leave
+ text-conversion or eol-conversion unspecified. They will be
+ decided after we read output from the process and decode it by
+ some coding system, or just before we actually send a text to
+ the process. */
}
@@ -1769,6 +1774,7 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
tem = Fsubstring (tem, make_number (2), Qnil);
{
+ Lisp_Object arg_encoding = Qnil;
struct gcpro gcpro1;
GCPRO1 (tem);
@@ -1786,9 +1792,14 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
tem = Fcons (args[i], tem);
CHECK_STRING (XCAR (tem));
if (STRING_MULTIBYTE (XCAR (tem)))
- XSETCAR (tem,
- code_convert_string_norecord
- (XCAR (tem), XPROCESS (proc)->encode_coding_system, 1));
+ {
+ if (NILP (arg_encoding))
+ arg_encoding = (complement_process_encoding_system
+ (XPROCESS (proc)->encode_coding_system));
+ XSETCAR (tem,
+ code_convert_string_norecord
+ (XCAR (tem), arg_encoding, 1));
+ }
}
UNGCPRO;
@@ -5690,12 +5701,21 @@ send_process (proc, buf, len, object)
&& !NILP (XBUFFER (object)->enable_multibyte_characters))
|| EQ (object, Qt))
{
+ p->encode_coding_system
+ = complement_process_encoding_system (p->encode_coding_system);
if (!EQ (Vlast_coding_system_used, p->encode_coding_system))
- /* The coding system for encoding was changed to raw-text
- because we sent a unibyte text previously. Now we are
- sending a multibyte text, thus we must encode it by the
- original coding system specified for the current process. */
- setup_coding_system (p->encode_coding_system, coding);
+ {
+ /* The coding system for encoding was changed to raw-text
+ because we sent a unibyte text previously. Now we are
+ sending a multibyte text, thus we must encode it by the
+ original coding system specified for the current process.
+
+ Another reason we comming here is that the coding system
+ was just complemented and new one was returned by
+ complement_process_encoding_system. */
+ setup_coding_system (p->encode_coding_system, coding);
+ Vlast_coding_system_used = p->encode_coding_system;
+ }
coding->src_multibyte = 1;
}
else