emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] Changes to emacs/src/term.c [emacs-unicode-2]


From: Kenichi Handa
Subject: [Emacs-diffs] Changes to emacs/src/term.c [emacs-unicode-2]
Date: Wed, 01 Oct 2003 00:43:53 -0400

Index: emacs/src/term.c
diff -c emacs/src/term.c:1.146.4.1 emacs/src/term.c:1.146.4.2
*** emacs/src/term.c:1.146.4.1  Mon Sep  8 08:48:12 2003
--- emacs/src/term.c    Wed Oct  1 00:43:53 2003
***************
*** 789,815 ****
      }
  }
  
  /* Encode SRC_LEN glyphs starting at SRC to terminal output codes and
!    store them at DST.  Do not write more than DST_LEN bytes.  That may
!    require stopping before all SRC_LEN input glyphs have been
!    converted.
  
     We store the number of glyphs actually converted in *CONSUMED.  The
!    return value is the number of bytes store in DST.  */
  
  int
! encode_terminal_code (src, dst, src_len, dst_len, consumed)
       struct glyph *src;
       int src_len;
!      unsigned char *dst;
!      int dst_len, *consumed;
  {
    struct glyph *src_start = src, *src_end = src + src_len;
-   unsigned char *dst_start = dst, *dst_end = dst + dst_len;
    register GLYPH g;
!   unsigned char workbuf[MAX_MULTIBYTE_LENGTH];
!   const unsigned char *buf;
!   int len;
    register int tlen = GLYPH_TABLE_LENGTH;
    register Lisp_Object *tbase = GLYPH_TABLE_BASE;
    struct coding_system *coding;
--- 789,830 ----
      }
  }
  
+ /* Buffer to store the result of terminal codes.  It is initialized in
+    term_init and, if necessary, enlarged in encode_terminal_code.  */
+ static unsigned char *terminal_encode_buffer;
+ /* Size of terminal_encode_buffer.  */
+ static int terminal_encode_buf_size;
+ 
  /* Encode SRC_LEN glyphs starting at SRC to terminal output codes and
!    store them in terminal_encode_buffer.
  
     We store the number of glyphs actually converted in *CONSUMED.  The
!    return value is the number of bytes stored in
!    terminal_encode_buffer.
! 
!    This function will stop before encoding all glyphs in these two
!    cases.
! 
!    (1) If the first glyph doesn't have a string entry in Vglyph_table,
!        it stops at encountering a glyph that has a string entry in
!        Vglyph_table.n
! 
!    (2) If the first has a string entry in Vglyph_table, it stops after
!        encoding that string.
! */
  
  int
! encode_terminal_code (src, src_len, consumed)
       struct glyph *src;
       int src_len;
!      int *consumed;
  {
    struct glyph *src_start = src, *src_end = src + src_len;
    register GLYPH g;
!   register int c;
!   Lisp_Object string;
!   unsigned char *workbuf, *buf;
!   int nchars;
    register int tlen = GLYPH_TABLE_LENGTH;
    register Lisp_Object *tbase = GLYPH_TABLE_BASE;
    struct coding_system *coding;
***************
*** 820,849 ****
    coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK
            ? &terminal_coding
            : &safe_terminal_coding);
  
!   while (src < src_end)
      {
        /* We must skip glyphs to be padded for a wide character.  */
        if (! CHAR_GLYPH_PADDING_P (*src))
        {
          g = GLYPH_FROM_CHAR_GLYPH (src[0]);
  
          if (g < 0 || g >= tlen)
!           {
!             /* This glyph doesn't have an entry in Vglyph_table.  */
!             if (! CHAR_VALID_P (src->u.ch, 0))
!               {
!                 len = 1;
!                 buf = " ";
!                 coding->src_multibyte = 0;
!               }
!             else
!               {
!                 len = CHAR_STRING (src->u.ch, workbuf);
!                 buf = workbuf;
!                 coding->src_multibyte = 1;
!               }
!           }
          else
            {
              /* This glyph has an entry in Vglyph_table,
--- 835,855 ----
    coding = (terminal_coding.common_flags & CODING_REQUIRE_ENCODING_MASK
            ? &terminal_coding
            : &safe_terminal_coding);
+   coding->destination = terminal_encode_buffer;
+   coding->dst_bytes = terminal_encode_buf_size;
+   coding->mode |= CODING_MODE_LAST_BLOCK;
  
!   workbuf = buf = alloca (MAX_MULTIBYTE_LENGTH * src_len);
!   for (nchars = 0; src < src_end; src++)
      {
        /* We must skip glyphs to be padded for a wide character.  */
        if (! CHAR_GLYPH_PADDING_P (*src))
        {
          g = GLYPH_FROM_CHAR_GLYPH (src[0]);
+         string = Qnil;
  
          if (g < 0 || g >= tlen)
!           c = src->u.ch;
          else
            {
              /* This glyph has an entry in Vglyph_table,
***************
*** 851,900 ****
              GLYPH_FOLLOW_ALIASES (tbase, tlen, g);
  
              if (GLYPH_SIMPLE_P (tbase, tlen, g))
!               {
!                 /* We set the multi-byte form of a character in G
!                    (that should be an ASCII character) at
!                    WORKBUF.  */
!                 workbuf[0] = FAST_GLYPH_CHAR (g);
!                 len = 1;
!                 buf = workbuf;
!                 coding->src_multibyte = 0;
!               }
              else
!               {
!                 /* We have a string in Vglyph_table.  */
!                 len = GLYPH_LENGTH (tbase, g);
!                 buf = GLYPH_STRING (tbase, g);
!                 coding->src_multibyte = STRING_MULTIBYTE (tbase[g]);
!               }
            }
  
!         coding->source = buf;
!         coding->destination = dst;
!         coding->dst_bytes = dst_end - dst;
!         encode_coding_object (coding, Qnil, 0, 0, 1, len, Qnil);
!         len -= coding->consumed;
!         dst += coding->produced;
!         if (coding->result == CODING_RESULT_INSUFFICIENT_DST)
!           /* The remaining output buffer is too short.  We must
!              break the loop here without increasing SRC so that the
!              next call of this function starts from the same glyph.  */
!           break;
! 
!         if (len > 0)
            {
!             /* This is the case that a code of the range 0200..0237
!                exists in buf.  We must just write out such a code.  */
!             buf += coding->consumed;
!             while (len--)
!               *dst++ = *buf++;
            }
        }
-       src++;
      }
  
    *consumed = src - src_start;
!   return (dst - dst_start);
  }
  
  
--- 857,900 ----
              GLYPH_FOLLOW_ALIASES (tbase, tlen, g);
  
              if (GLYPH_SIMPLE_P (tbase, tlen, g))
!               /* We set the multi-byte form of a character in G
!                  (that should be an ASCII character) at WORKBUF.  */
!               c = FAST_GLYPH_CHAR (g);
              else
!               /* We have a string in Vglyph_table.  */
!               string = tbase[g];
            }
  
!         if (NILP (string))
            {
!             /* Store the multibyte form of C at BUF.  */
!             buf += CHAR_STRING (c, buf);
!             nchars++;
!           }
!         else
!           {
!             if (nchars == 0)
!               {
!                 encode_coding_object (coding, string, 0, 0, SCHARS (string),
!                                       SBYTES (string), Qnil);
!                 src++;
!               }
!             break;
            }
        }
      }
  
+   if (nchars > 0)
+     {
+       coding->source = workbuf;
+       encode_coding_object (coding, Qnil, 0, 0, nchars,
+                           buf - workbuf, Qnil);
+     }
+   terminal_encode_buffer = coding->destination;
+   terminal_encode_buf_size = coding->dst_bytes;
+ 
    *consumed = src - src_start;
!   return (coding->produced);
  }
  
  
***************
*** 906,913 ****
    int produced, consumed;
    struct frame *sf = XFRAME (selected_frame);
    struct frame *f = updating_frame ? updating_frame : sf;
-   unsigned char conversion_buffer[1024];
-   int conversion_buffer_size = sizeof conversion_buffer;
  
    if (write_glyphs_hook
        && ! FRAME_TERMCAP_P (f))
--- 906,911 ----
***************
*** 951,969 ****
  
        while (n > 0)
        {
!         /* We use a fixed size (1024 bytes) of conversion buffer.
!            Usually it is sufficient, but if not, we just repeat the
!            loop.  */
!         produced = encode_terminal_code (string, conversion_buffer,
!                                          n, conversion_buffer_size,
!                                          &consumed);
          if (produced > 0)
            {
!             fwrite (conversion_buffer, 1, produced, stdout);
              if (ferror (stdout))
                clearerr (stdout);
              if (termscript)
!               fwrite (conversion_buffer, 1, produced, termscript);
            }
          len -= consumed;
          n -= consumed;
--- 949,962 ----
  
        while (n > 0)
        {
!         produced = encode_terminal_code (string, n, &consumed);
          if (produced > 0)
            {
!             fwrite (terminal_encode_buffer, 1, produced, stdout);
              if (ferror (stdout))
                clearerr (stdout);
              if (termscript)
!               fwrite (terminal_encode_buffer, 1, produced, termscript);
            }
          len -= consumed;
          n -= consumed;
***************
*** 975,999 ****
        turn_off_highlight ();
      }
  
-   /* We may have to output some codes to terminate the writing.  */
-   if (CODING_REQUIRE_FLUSHING (&terminal_coding))
-     {
-       terminal_coding.mode |= CODING_MODE_LAST_BLOCK;
-       terminal_coding.source = (unsigned char *) "";
-       terminal_coding.destination = conversion_buffer;
-       terminal_coding.dst_bytes = conversion_buffer_size;
-       encode_coding_object (&terminal_coding, Qnil, 0, 0, 0, 0, Qnil);
-       if (terminal_coding.produced > 0)
-       {
-         fwrite (conversion_buffer, 1, terminal_coding.produced, stdout);
-         if (ferror (stdout))
-           clearerr (stdout);
-         if (termscript)
-           fwrite (conversion_buffer, 1, terminal_coding.produced,
-                   termscript);
-       }
-     }
- 
    cmcheckmagic ();
  }
  
--- 968,973 ----
***************
*** 1037,1049 ****
    while (len-- > 0)
      {
        int produced, consumed;
-       unsigned char conversion_buffer[1024];
-       int conversion_buffer_size = sizeof conversion_buffer;
  
        OUTPUT1_IF (TS_ins_char);
        if (!start)
        {
!         conversion_buffer[0] = SPACEGLYPH;
          produced = 1;
        }
        else
--- 1011,1021 ----
    while (len-- > 0)
      {
        int produced, consumed;
  
        OUTPUT1_IF (TS_ins_char);
        if (!start)
        {
!         terminal_encode_buffer[0] = SPACEGLYPH;
          produced = 1;
        }
        else
***************
*** 1059,1082 ****
              OUTPUT1_IF (TS_ins_char);
              start++, len--;
            }
! 
!         if (len <= 0)
!           /* This is the last glyph.  */
!           terminal_coding.mode |= CODING_MODE_LAST_BLOCK;
! 
!         /* The size of conversion buffer (1024 bytes) is surely
!            sufficient for just one glyph.  */
!         produced = encode_terminal_code (glyph, conversion_buffer, 1,
!                                          conversion_buffer_size, &consumed);
        }
  
        if (produced > 0)
        {
!         fwrite (conversion_buffer, 1, produced, stdout);
          if (ferror (stdout))
            clearerr (stdout);
          if (termscript)
!           fwrite (conversion_buffer, 1, produced, termscript);
        }
  
        OUTPUT1_IF (TS_pad_inserted_char);
--- 1031,1046 ----
              OUTPUT1_IF (TS_ins_char);
              start++, len--;
            }
!         produced = encode_terminal_code (glyph, 1, &consumed);
        }
  
        if (produced > 0)
        {
!         fwrite (terminal_encode_buffer, 1, produced, stdout);
          if (ferror (stdout))
            clearerr (stdout);
          if (termscript)
!           fwrite (terminal_encode_buffer, 1, produced, termscript);
        }
  
        OUTPUT1_IF (TS_pad_inserted_char);
***************
*** 2557,2562 ****
--- 2521,2534 ----
  
    FRAME_CAN_HAVE_SCROLL_BARS (sf) = 0;
    FRAME_VERTICAL_SCROLL_BAR_TYPE (sf) = vertical_scroll_bar_none;
+ 
+   if (! terminal_encode_buffer)
+     {
+       terminal_encode_buffer = xmalloc (1024);
+       if (! terminal_encode_buffer)
+       abort ();
+       terminal_encode_buf_size = 1024;
+     }
  #endif /* WINDOWSNT */
  }
  




reply via email to

[Prev in Thread] Current Thread [Next in Thread]