/[emacs]/emacs/src/callproc.c
ViewVC logotype

Diff of /emacs/src/callproc.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.198 by fx, Mon Jun 2 18:46:55 2003 UTC revision 1.198.2.1 by handa, Mon Sep 8 12:48:09 2003 UTC
# Line 75  extern int errno; Line 75  extern int errno;
75  #include "lisp.h"  #include "lisp.h"
76  #include "commands.h"  #include "commands.h"
77  #include "buffer.h"  #include "buffer.h"
78  #include "charset.h"  #include "character.h"
79  #include "ccl.h"  #include "ccl.h"
80  #include "coding.h"  #include "coding.h"
81  #include "composite.h"  #include "composite.h"
# Line 408  usage: (call-process PROGRAM &optional I Line 408  usage: (call-process PROGRAM &optional I
408          {          {
409            argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);            argument_coding.src_multibyte = STRING_MULTIBYTE (args[i]);
410            if (CODING_REQUIRE_ENCODING (&argument_coding))            if (CODING_REQUIRE_ENCODING (&argument_coding))
411              {              /* We must encode this argument.  */
412                /* We must encode this argument.  */              args[i] = encode_coding_string (&argument_coding, args[i], 1);
               args[i] = encode_coding_string (args[i], &argument_coding, 1);  
               if (argument_coding.type == coding_type_ccl)  
                 setup_ccl_program (&(argument_coding.spec.ccl.encoder), Qnil);  
             }  
413            new_argv[i - 3] = SDATA (args[i]);            new_argv[i - 3] = SDATA (args[i]);
414          }          }
415        UNGCPRO;        UNGCPRO;
# Line 721  usage: (call-process PROGRAM &optional I Line 717  usage: (call-process PROGRAM &optional I
717            else            else
718              val = Qnil;              val = Qnil;
719          }          }
720        setup_coding_system (Fcheck_coding_system (val), &process_coding);        Fcheck_coding_system (val);
721        /* In unibyte mode, character code conversion should not take        /* In unibyte mode, character code conversion should not take
722           place but EOL conversion should.  So, setup raw-text or one           place but EOL conversion should.  So, setup raw-text or one
723           of the subsidiary according to the information just setup.  */           of the subsidiary according to the information just setup.  */
724        if (NILP (current_buffer->enable_multibyte_characters)        if (NILP (current_buffer->enable_multibyte_characters)
725            && !NILP (val))            && !NILP (val))
726          setup_raw_text_coding_system (&process_coding);          val = raw_text_coding_system (val);
727          setup_coding_system (val, &process_coding);
728      }      }
   process_coding.src_multibyte = 0;  
   process_coding.dst_multibyte  
     = (BUFFERP (buffer)  
        ? ! NILP (XBUFFER (buffer)->enable_multibyte_characters)  
        : ! NILP (current_buffer->enable_multibyte_characters));  
729    
730    immediate_quit = 1;    immediate_quit = 1;
731    QUIT;    QUIT;
# Line 745  usage: (call-process PROGRAM &optional I Line 737  usage: (call-process PROGRAM &optional I
737      int carryover = 0;      int carryover = 0;
738      int display_on_the_fly = !NILP (display) && INTERACTIVE;      int display_on_the_fly = !NILP (display) && INTERACTIVE;
739      struct coding_system saved_coding;      struct coding_system saved_coding;
     int pt_orig = PT, pt_byte_orig = PT_BYTE;  
     int inserted;  
740    
741      saved_coding = process_coding;      saved_coding = process_coding;
     if (process_coding.composing != COMPOSITION_DISABLED)  
       coding_allocate_composition_data (&process_coding, PT);  
742      while (1)      while (1)
743        {        {
744          /* Repeatedly read until we've filled as much as possible          /* Repeatedly read until we've filled as much as possible
# Line 783  usage: (call-process PROGRAM &optional I Line 771  usage: (call-process PROGRAM &optional I
771    
772          if (!NILP (buffer))          if (!NILP (buffer))
773            {            {
774              if (! CODING_MAY_REQUIRE_DECODING (&process_coding))              if (NILP (current_buffer->enable_multibyte_characters)
775                    && ! CODING_MAY_REQUIRE_DECODING (&process_coding))
776                insert_1_both (bufptr, nread, nread, 0, 1, 0);                insert_1_both (bufptr, nread, nread, 0, 1, 0);
777              else              else
778                {                 /* We have to decode the input.  */                {                 /* We have to decode the input.  */
779                  int size;                  Lisp_Object buf;
                 char *decoding_buf;  
   
               repeat_decoding:  
                 size = decoding_buffer_size (&process_coding, nread);  
                 decoding_buf = (char *) xmalloc (size);  
   
                 /* We can't use the macro CODING_REQUIRE_DETECTION  
                    because it always returns nonzero if the coding  
                    system requires EOL detection.  Here, we have to  
                    check only whether or not the coding system  
                    requires text-encoding detection.  */  
                 if (process_coding.type == coding_type_undecided)  
                   {  
                     detect_coding (&process_coding, bufptr, nread);  
                     if (process_coding.composing != COMPOSITION_DISABLED)  
                       coding_allocate_composition_data (&process_coding, PT);  
                   }  
                 if (process_coding.cmp_data)  
                   process_coding.cmp_data->char_offset = PT;  
   
                 decode_coding (&process_coding, bufptr, decoding_buf,  
                                nread, size);  
780    
781                    XSETBUFFER (buf, current_buffer);
782                    decode_coding_c_string (&process_coding, bufptr, nread,
783                                            buf);
784                  if (display_on_the_fly                  if (display_on_the_fly
785                      && saved_coding.type == coding_type_undecided                      && CODING_REQUIRE_DETECTION (&saved_coding)
786                      && process_coding.type != coding_type_undecided)                      && ! CODING_REQUIRE_DETECTION (&process_coding))
787                    {                    {
788                      /* We have detected some coding system.  But,                      /* We have detected some coding system.  But,
789                         there's a possibility that the detection was                         there's a possibility that the detection was
790                         done by insufficient data.  So, we give up                         done by insufficient data.  So, we give up
791                         displaying on the fly.  */                         displaying on the fly.  */
792                      xfree (decoding_buf);                      if (process_coding.produced > 0)
793                          del_range_2 (process_coding.dst_pos,
794                                       process_coding.dst_pos_byte,
795                                       process_coding.dst_pos
796                                       + process_coding.produced_char,
797                                       process_coding.dst_pos_byte
798                                       + process_coding.produced, 0);
799                      display_on_the_fly = 0;                      display_on_the_fly = 0;
800                      process_coding = saved_coding;                      process_coding = saved_coding;
801                      carryover = nread;                      carryover = nread;
802                      continue;                      continue;
803                    }                    }
804    
805                  if (process_coding.produced > 0)                  TEMP_SET_PT_BOTH (PT + process_coding.produced_char,
806                    insert_1_both (decoding_buf, process_coding.produced_char,                                    PT_BYTE + process_coding.produced);
807                                   process_coding.produced, 0, 1, 0);                  carryover = process_coding.carryover_bytes;
                 xfree (decoding_buf);  
   
                 if (process_coding.result == CODING_FINISH_INCONSISTENT_EOL)  
                   {  
                     Lisp_Object eol_type, coding;  
   
                     if (process_coding.eol_type == CODING_EOL_CR)  
                       {  
                         /* CRs have been replaced with LFs.  Undo  
                            that in the text inserted above.  */  
                         unsigned char *p;  
   
                         move_gap_both (PT, PT_BYTE);  
   
                         p = BYTE_POS_ADDR (pt_byte_orig);  
                         for (; p < GPT_ADDR; ++p)  
                           if (*p == '\n')  
                             *p = '\r';  
                       }  
                     else if (process_coding.eol_type == CODING_EOL_CRLF)  
                       {  
                         /* CR LFs have been replaced with LFs.  Undo  
                            that by inserting CRs in front of LFs in  
                            the text inserted above.  */  
                         EMACS_INT bytepos, old_pt, old_pt_byte, nCR;  
   
                         old_pt = PT;  
                         old_pt_byte = PT_BYTE;  
                         nCR = 0;  
   
                         for (bytepos = PT_BYTE - 1;  
                              bytepos >= pt_byte_orig;  
                              --bytepos)  
                           if (FETCH_BYTE (bytepos) == '\n')  
                             {  
                               EMACS_INT charpos = BYTE_TO_CHAR (bytepos);  
                               TEMP_SET_PT_BOTH (charpos, bytepos);  
                               insert_1_both ("\r", 1, 1, 0, 1, 0);  
                               ++nCR;  
                             }  
   
                         TEMP_SET_PT_BOTH (old_pt + nCR, old_pt_byte + nCR);  
                       }  
   
                     /* Set the coding system symbol to that for  
                        Unix-like EOL.  */  
                     eol_type = Fget (saved_coding.symbol, Qeol_type);  
                     if (VECTORP (eol_type)  
                         && ASIZE (eol_type) == 3  
                         && SYMBOLP (AREF (eol_type, CODING_EOL_LF)))  
                       coding = AREF (eol_type, CODING_EOL_LF);  
                     else  
                       coding = saved_coding.symbol;  
   
                     process_coding.symbol = coding;  
                     process_coding.eol_type = CODING_EOL_LF;  
                     process_coding.mode  
                       &= ~CODING_MODE_INHIBIT_INCONSISTENT_EOL;  
                   }  
   
                 nread -= process_coding.consumed;  
                 carryover = nread;  
808                  if (carryover > 0)                  if (carryover > 0)
809                    /* As CARRYOVER should not be that large, we had                    /* As CARRYOVER should not be that large, we had
810                       better avoid overhead of bcopy.  */                       better avoid overhead of bcopy.  */
811                    BCOPY_SHORT (bufptr + process_coding.consumed, bufptr,                    BCOPY_SHORT (process_coding.carryover, bufptr,
812                                 carryover);                                 process_coding.carryover_bytes);
                 if (process_coding.result == CODING_FINISH_INSUFFICIENT_CMP)  
                   {  
                     /* The decoding ended because of insufficient data  
                        area to record information about composition.  
                        We must try decoding with additional data area  
                        before reading more output for the process.  */  
                     coding_allocate_composition_data (&process_coding, PT);  
                     goto repeat_decoding;  
                   }  
813                }                }
814            }            }
815    
# Line 935  usage: (call-process PROGRAM &optional I Line 840  usage: (call-process PROGRAM &optional I
840        }        }
841    give_up: ;    give_up: ;
842    
843      if (!NILP (buffer)      Vlast_coding_system_used = CODING_ID_NAME (process_coding.id);
844          && process_coding.cmp_data)      /* If the caller required, let the buffer inherit the
845        {         coding-system used to decode the process output.  */
846          coding_restore_composition (&process_coding, Fcurrent_buffer ());      if (inherit_process_coding_system)
847          coding_free_composition_data (&process_coding);        call1 (intern ("after-insert-file-set-buffer-file-coding-system"),
848        }                 make_number (total_read));
   
     {  
       int post_read_count = SPECPDL_INDEX ();  
   
       record_unwind_protect (save_excursion_restore, save_excursion_save ());  
       inserted = PT - pt_orig;  
       TEMP_SET_PT_BOTH (pt_orig, pt_byte_orig);  
       if (SYMBOLP (process_coding.post_read_conversion)  
           && !NILP (Ffboundp (process_coding.post_read_conversion)))  
         call1 (process_coding.post_read_conversion, make_number (inserted));  
   
       Vlast_coding_system_used = process_coding.symbol;  
   
       /* If the caller required, let the buffer inherit the  
          coding-system used to decode the process output.  */  
       if (inherit_process_coding_system)  
         call1 (intern ("after-insert-file-set-buffer-file-coding-system"),  
                make_number (total_read));  
   
       unbind_to (post_read_count, Qnil);  
     }  
849    }    }
850    
851    /* Wait for it to terminate, unless it already has.  */    /* Wait for it to terminate, unless it already has.  */

Legend:
Removed from v.1.198  
changed lines
  Added in v.1.198.2.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26