aboutsummaryrefslogtreecommitdiffstats
path: root/src/process.c
diff options
context:
space:
mode:
authorKenichi Handa2003-02-10 07:58:29 +0000
committerKenichi Handa2003-02-10 07:58:29 +0000
commit03f04413590df23f1f4f8517b057db95f2dc925c (patch)
treec6ae7ded5c9d1d0d8709c7165eb365321fb14c26 /src/process.c
parent56533d51c8df97f884035220a48a1fff6f6149c6 (diff)
downloademacs-03f04413590df23f1f4f8517b057db95f2dc925c.tar.gz
emacs-03f04413590df23f1f4f8517b057db95f2dc925c.zip
(QCfilter_multibyte): New variable.
(setup_process_coding_systems): New function. (Fset_process_buffer, Fset_process_filter): Call setup_process_coding_systems. (Fstart_process): Initialize the member `filter_multibyte' of struct Lisp_Process. (create_process): Call setup_process_coding_systems. (Fmake_network_process): New keyward `:filter-multibyte'. Initialize the member `filter_multibyte' of struct Lisp_Process. Call setup_process_coding_systems. (server_accept_connection): Call setup_process_coding_systems. (read_process_output): If the process has a filter, decide the multibyteness of a string to given to the filter by `filter_multibyte' member of the process. If the process doesn't have a filter and the result of conversion is unibyte, use Fstring_to_multibyte (not Fstring_make_multibyte) to get the multibyte form. (Fset_process_coding_system): Call setup_process_coding_systems. (Fset_process_filter_multibyte): New function. (Fprocess_filter_multibyte_p): New function. (syms_of_process): Intern and staticpro QCfilter_multibyte. Defsubr Sset_process_filter_multibyte and Sprocess_filter_multibyte_p.
Diffstat (limited to 'src/process.c')
-rw-r--r--src/process.c144
1 files changed, 101 insertions, 43 deletions
diff --git a/src/process.c b/src/process.c
index 775415ac1a6..0b41431bdfb 100644
--- a/src/process.c
+++ b/src/process.c
@@ -137,6 +137,7 @@ Lisp_Object Qlast_nonmenu_event;
137/* QCfamily is declared and initialized in xfaces.c, 137/* QCfamily is declared and initialized in xfaces.c,
138 QCfilter in keyboard.c. */ 138 QCfilter in keyboard.c. */
139extern Lisp_Object QCfamily, QCfilter; 139extern Lisp_Object QCfamily, QCfilter;
140Lisp_Object QCfilter_multibyte;
140 141
141/* Qexit is declared and initialized in eval.c. */ 142/* Qexit is declared and initialized in eval.c. */
142 143
@@ -586,6 +587,39 @@ remove_process (proc)
586 587
587 deactivate_process (proc); 588 deactivate_process (proc);
588} 589}
590
591/* Setup coding systems of PROCESS. */
592
593void
594setup_process_coding_systems (process)
595 Lisp_Object process;
596{
597 struct Lisp_Process *p = XPROCESS (process);
598 int inch = XINT (p->infd);
599 int outch = XINT (p->outfd);
600
601 if (!proc_decode_coding_system[inch])
602 proc_decode_coding_system[inch]
603 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
604 setup_coding_system (p->decode_coding_system,
605 proc_decode_coding_system[inch]);
606 if (! NILP (p->filter))
607 {
608 if (NILP (p->filter_multibyte))
609 setup_raw_text_coding_system (proc_decode_coding_system[inch]);
610 }
611 else if (BUFFERP (p->buffer))
612 {
613 if (NILP (XBUFFER (p->buffer)->enable_multibyte_characters))
614 setup_raw_text_coding_system (proc_decode_coding_system[inch]);
615 }
616
617 if (!proc_encode_coding_system[outch])
618 proc_encode_coding_system[outch]
619 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
620 setup_coding_system (p->encode_coding_system,
621 proc_encode_coding_system[outch]);
622}
589 623
590DEFUN ("processp", Fprocessp, Sprocessp, 1, 1, 0, 624DEFUN ("processp", Fprocessp, Sprocessp, 1, 1, 0,
591 doc: /* Return t if OBJECT is a process. */) 625 doc: /* Return t if OBJECT is a process. */)
@@ -816,6 +850,7 @@ DEFUN ("set-process-buffer", Fset_process_buffer, Sset_process_buffer,
816 p->buffer = buffer; 850 p->buffer = buffer;
817 if (NETCONN1_P (p)) 851 if (NETCONN1_P (p))
818 p->childp = Fplist_put (p->childp, QCbuffer, buffer); 852 p->childp = Fplist_put (p->childp, QCbuffer, buffer);
853 setup_process_coding_systems (process);
819 return buffer; 854 return buffer;
820} 855}
821 856
@@ -890,6 +925,7 @@ The string argument is normally a multibyte string, except:
890 p->filter = filter; 925 p->filter = filter;
891 if (NETCONN1_P (p)) 926 if (NETCONN1_P (p))
892 p->childp = Fplist_put (p->childp, QCfilter, filter); 927 p->childp = Fplist_put (p->childp, QCfilter, filter);
928 setup_process_coding_systems (process);
893 return filter; 929 return filter;
894} 930}
895 931
@@ -1438,6 +1474,8 @@ usage: (start-process NAME BUFFER PROGRAM &rest PROGRAM-ARGS) */)
1438 XPROCESS (proc)->buffer = buffer; 1474 XPROCESS (proc)->buffer = buffer;
1439 XPROCESS (proc)->sentinel = Qnil; 1475 XPROCESS (proc)->sentinel = Qnil;
1440 XPROCESS (proc)->filter = Qnil; 1476 XPROCESS (proc)->filter = Qnil;
1477 XPROCESS (proc)->filter_multibyte
1478 = buffer_defaults.enable_multibyte_characters;
1441 XPROCESS (proc)->command = Flist (nargs - 2, args + 2); 1479 XPROCESS (proc)->command = Flist (nargs - 2, args + 2);
1442 1480
1443 /* Make the process marker point into the process buffer (if any). */ 1481 /* Make the process marker point into the process buffer (if any). */
@@ -1748,16 +1786,7 @@ create_process (process, new_argv, current_dir)
1748 XSETFASTINT (XPROCESS (process)->subtty, forkin); 1786 XSETFASTINT (XPROCESS (process)->subtty, forkin);
1749 XPROCESS (process)->pty_flag = (pty_flag ? Qt : Qnil); 1787 XPROCESS (process)->pty_flag = (pty_flag ? Qt : Qnil);
1750 XPROCESS (process)->status = Qrun; 1788 XPROCESS (process)->status = Qrun;
1751 if (!proc_decode_coding_system[inchannel]) 1789 setup_process_coding_systems (process);
1752 proc_decode_coding_system[inchannel]
1753 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
1754 setup_coding_system (XPROCESS (process)->decode_coding_system,
1755 proc_decode_coding_system[inchannel]);
1756 if (!proc_encode_coding_system[outchannel])
1757 proc_encode_coding_system[outchannel]
1758 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
1759 setup_coding_system (XPROCESS (process)->encode_coding_system,
1760 proc_encode_coding_system[outchannel]);
1761 1790
1762 /* Delay interrupts until we have a chance to store 1791 /* Delay interrupts until we have a chance to store
1763 the new fork's pid in its process structure */ 1792 the new fork's pid in its process structure */
@@ -2590,6 +2619,11 @@ The stopped state is cleared by `continue-process' and set by
2590 2619
2591:filter FILTER -- Install FILTER as the process filter. 2620:filter FILTER -- Install FILTER as the process filter.
2592 2621
2622:filter-multibyte BOOL -- If BOOL is non-nil, a string given to the
2623process filter is multibyte, otherwise it is unibyte. If this keyword
2624is not specified, the string is multibyte iff
2625`default-enable-multibyte-characters' is non-nil.
2626
2593:sentinel SENTINEL -- Install SENTINEL as the process sentinel. 2627:sentinel SENTINEL -- Install SENTINEL as the process sentinel.
2594 2628
2595:log LOG -- Install LOG as the server process log function. This 2629:log LOG -- Install LOG as the server process log function. This
@@ -3185,6 +3219,10 @@ usage: (make-network-process &rest ARGS) */)
3185 p->buffer = buffer; 3219 p->buffer = buffer;
3186 p->sentinel = sentinel; 3220 p->sentinel = sentinel;
3187 p->filter = filter; 3221 p->filter = filter;
3222 p->filter_multibyte = buffer_defaults.enable_multibyte_characters;
3223 /* Override the above only if :filter-multibyte is specified. */
3224 if (! NILP (Fplist_member (contact, QCfilter_multibyte)))
3225 p->filter_multibyte = Fplist_get (contact, QCfilter_multibyte);
3188 p->log = Fplist_get (contact, QClog); 3226 p->log = Fplist_get (contact, QClog);
3189 if (tem = Fplist_get (contact, QCnoquery), !NILP (tem)) 3227 if (tem = Fplist_get (contact, QCnoquery), !NILP (tem))
3190 p->kill_without_query = Qt; 3228 p->kill_without_query = Qt;
@@ -3296,17 +3334,7 @@ usage: (make-network-process &rest ARGS) */)
3296 } 3334 }
3297 p->encode_coding_system = val; 3335 p->encode_coding_system = val;
3298 } 3336 }
3299 3337 setup_process_coding_systems (proc);
3300 if (!proc_decode_coding_system[inch])
3301 proc_decode_coding_system[inch]
3302 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
3303 setup_coding_system (p->decode_coding_system,
3304 proc_decode_coding_system[inch]);
3305 if (!proc_encode_coding_system[outch])
3306 proc_encode_coding_system[outch]
3307 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
3308 setup_coding_system (p->encode_coding_system,
3309 proc_encode_coding_system[outch]);
3310 3338
3311 p->decoding_buf = make_uninit_string (0); 3339 p->decoding_buf = make_uninit_string (0);
3312 p->decoding_carryover = make_number (0); 3340 p->decoding_carryover = make_number (0);
@@ -3641,17 +3669,7 @@ server_accept_connection (server, channel)
3641 3669
3642 p->decode_coding_system = ps->decode_coding_system; 3670 p->decode_coding_system = ps->decode_coding_system;
3643 p->encode_coding_system = ps->encode_coding_system; 3671 p->encode_coding_system = ps->encode_coding_system;
3644 3672 setup_process_coding_systems (proc);
3645 if (!proc_decode_coding_system[s])
3646 proc_decode_coding_system[s]
3647 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
3648 setup_coding_system (p->decode_coding_system,
3649 proc_decode_coding_system[s]);
3650 if (!proc_encode_coding_system[s])
3651 proc_encode_coding_system[s]
3652 = (struct coding_system *) xmalloc (sizeof (struct coding_system));
3653 setup_coding_system (p->encode_coding_system,
3654 proc_encode_coding_system[s]);
3655 3673
3656 p->decoding_buf = make_uninit_string (0); 3674 p->decoding_buf = make_uninit_string (0);
3657 p->decoding_carryover = make_number (0); 3675 p->decoding_carryover = make_number (0);
@@ -4517,10 +4535,6 @@ read_process_output (proc, channel)
4517 4535
4518 text = decode_coding_string (make_unibyte_string (chars, nbytes), 4536 text = decode_coding_string (make_unibyte_string (chars, nbytes),
4519 coding, 0); 4537 coding, 0);
4520 if (NILP (buffer_defaults.enable_multibyte_characters))
4521 /* We had better return unibyte string. */
4522 text = string_make_unibyte (text);
4523
4524 Vlast_coding_system_used = coding->symbol; 4538 Vlast_coding_system_used = coding->symbol;
4525 /* A new coding system might be found. */ 4539 /* A new coding system might be found. */
4526 if (!EQ (p->decode_coding_system, coding->symbol)) 4540 if (!EQ (p->decode_coding_system, coding->symbol))
@@ -4551,6 +4565,11 @@ read_process_output (proc, channel)
4551 bcopy (chars + coding->consumed, SDATA (p->decoding_buf), 4565 bcopy (chars + coding->consumed, SDATA (p->decoding_buf),
4552 carryover); 4566 carryover);
4553 XSETINT (p->decoding_carryover, carryover); 4567 XSETINT (p->decoding_carryover, carryover);
4568 /* Adjust the multibyteness of TEXT to that of the filter. */
4569 if (NILP (p->filter_multibyte) != ! STRING_MULTIBYTE (text))
4570 text = (STRING_MULTIBYTE (text)
4571 ? Fstring_as_unibyte (text)
4572 : Fstring_to_multibyte (text));
4554 nbytes = SBYTES (text); 4573 nbytes = SBYTES (text);
4555 nchars = SCHARS (text); 4574 nchars = SCHARS (text);
4556 if (nbytes > 0) 4575 if (nbytes > 0)
@@ -4657,7 +4676,7 @@ read_process_output (proc, channel)
4657 != ! STRING_MULTIBYTE (text)) 4676 != ! STRING_MULTIBYTE (text))
4658 text = (STRING_MULTIBYTE (text) 4677 text = (STRING_MULTIBYTE (text)
4659 ? Fstring_as_unibyte (text) 4678 ? Fstring_as_unibyte (text)
4660 : Fstring_as_multibyte (text)); 4679 : Fstring_to_multibyte (text));
4661 nbytes = SBYTES (text); 4680 nbytes = SBYTES (text);
4662 nchars = SCHARS (text); 4681 nchars = SCHARS (text);
4663 /* Insert before markers in case we are inserting where 4682 /* Insert before markers in case we are inserting where
@@ -6118,13 +6137,12 @@ encode subprocess input. */)
6118 error ("Input file descriptor of %s closed", SDATA (p->name)); 6137 error ("Input file descriptor of %s closed", SDATA (p->name));
6119 if (XINT (p->outfd) < 0) 6138 if (XINT (p->outfd) < 0)
6120 error ("Output file descriptor of %s closed", SDATA (p->name)); 6139 error ("Output file descriptor of %s closed", SDATA (p->name));
6140 Fcheck_coding_system (decoding);
6141 Fcheck_coding_system (encoding);
6121 6142
6122 p->decode_coding_system = Fcheck_coding_system (decoding); 6143 p->decode_coding_system = decoding;
6123 p->encode_coding_system = Fcheck_coding_system (encoding); 6144 p->encode_coding_system = encoding;
6124 setup_coding_system (decoding, 6145 setup_process_coding_systems (proc);
6125 proc_decode_coding_system[XINT (p->infd)]);
6126 setup_coding_system (encoding,
6127 proc_encode_coding_system[XINT (p->outfd)]);
6128 6146
6129 return Qnil; 6147 return Qnil;
6130} 6148}
@@ -6139,6 +6157,42 @@ DEFUN ("process-coding-system",
6139 return Fcons (XPROCESS (proc)->decode_coding_system, 6157 return Fcons (XPROCESS (proc)->decode_coding_system,
6140 XPROCESS (proc)->encode_coding_system); 6158 XPROCESS (proc)->encode_coding_system);
6141} 6159}
6160
6161DEFUN ("set-process-filter-multibyte", Fset_process_filter_multibyte,
6162 Sset_process_filter_multibyte, 2, 2, 0,
6163 doc: /* Set multibyteness of a string given to PROCESS's filter.
6164If FLAG is non-nil, the filter is given a multibyte string.
6165If FLAG is nil, the filter is give a unibyte string. In this case,
6166all character code conversion except for end-of-line conversion is
6167suppressed. */)
6168 (proc, flag)
6169 Lisp_Object proc, flag;
6170{
6171 register struct Lisp_Process *p;
6172
6173 CHECK_PROCESS (proc);
6174 p = XPROCESS (proc);
6175 p->filter_multibyte = flag;
6176 setup_process_coding_systems (proc);
6177
6178 return Qnil;
6179}
6180
6181DEFUN ("process-filter-multibyte-p", Fprocess_filter_multibyte_p,
6182 Sprocess_filter_multibyte_p, 1, 1, 0,
6183 doc: /* Return t if a multibyte string is given to PROCESS's filter.*/)
6184 (proc)
6185 Lisp_Object proc;
6186{
6187 register struct Lisp_Process *p;
6188
6189 CHECK_PROCESS (proc);
6190 p = XPROCESS (proc);
6191
6192 return (NILP (p->filter_multibyte) ? Qnil : Qt);
6193}
6194
6195
6142 6196
6143/* The first time this is called, assume keyboard input comes from DESC 6197/* The first time this is called, assume keyboard input comes from DESC
6144 instead of from where we used to expect it. 6198 instead of from where we used to expect it.
@@ -6345,6 +6399,8 @@ syms_of_process ()
6345 6399
6346 Qlast_nonmenu_event = intern ("last-nonmenu-event"); 6400 Qlast_nonmenu_event = intern ("last-nonmenu-event");
6347 staticpro (&Qlast_nonmenu_event); 6401 staticpro (&Qlast_nonmenu_event);
6402 QCfilter_multibyte = intern ("filter-multibyte");
6403 staticpro (&QCfilter_multibyte);
6348 6404
6349 staticpro (&Vprocess_alist); 6405 staticpro (&Vprocess_alist);
6350 6406
@@ -6414,6 +6470,8 @@ The value takes effect when `start-process' is called. */);
6414/* defsubr (&Sprocess_connection); */ 6470/* defsubr (&Sprocess_connection); */
6415 defsubr (&Sset_process_coding_system); 6471 defsubr (&Sset_process_coding_system);
6416 defsubr (&Sprocess_coding_system); 6472 defsubr (&Sprocess_coding_system);
6473 defsubr (&Sset_process_filter_multibyte);
6474 defsubr (&Sprocess_filter_multibyte_p);
6417} 6475}
6418 6476
6419 6477