[BACK]Return to line.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / less

Diff for /src/usr.bin/less/line.c between version 1.24 and 1.25

version 1.24, 2019/02/26 11:01:54 version 1.25, 2019/03/01 14:31:34
Line 112 
Line 112 
 /*  /*
  * Is a character ASCII?   * Is a character ASCII?
  */   */
 int  static int
 is_ascii_char(LWCHAR ch)  is_ascii_char(LWCHAR ch)
 {  {
         return (ch <= 0x7F);          return (ch <= 0x7F);
Line 458 
Line 458 
 }  }
   
 /*  /*
  * Are we currently within a recognized ANSI escape sequence?  
  */  
 static int  
 in_ansi_esc_seq(void)  
 {  
         int i;  
   
         /*  
          * Search backwards for either an ESC (which means we ARE in a seq);  
          * or an end char (which means we're NOT in a seq).  
          */  
         for (i = curr - 1; i >= 0; i--) {  
                 if (linebuf[i] == ESC)  
                         return (1);  
                 if (!is_ansi_middle(linebuf[i]))  
                         return (0);  
         }  
         return (0);  
 }  
   
 /*  
  * Is a character the end of an ANSI escape sequence?   * Is a character the end of an ANSI escape sequence?
  */   */
 int  static int
 is_ansi_end(LWCHAR ch)  is_ansi_end(LWCHAR ch)
 {  {
         if (!is_ascii_char(ch))          if (!is_ascii_char(ch))
Line 512 
Line 491 
 static int  static int
 store_char(LWCHAR ch, char a, char *rep, off_t pos)  store_char(LWCHAR ch, char a, char *rep, off_t pos)
 {  {
           int i;
         int w;          int w;
         int replen;          int replen;
         char cs;          char cs;
Line 529 
Line 509 
                 }                  }
         }          }
   
         if (ctldisp == OPT_ONPLUS && in_ansi_esc_seq()) {          w = -1;
                 if (!is_ansi_end(ch) && !is_ansi_middle(ch)) {          if (ctldisp == OPT_ONPLUS) {
                   /*
                    * Set i to the beginning of an ANSI escape sequence
                    * that was begun and not yet ended, or to -1 otherwise.
                    */
                   for (i = curr - 1; i >= 0; i--) {
                           if (linebuf[i] == ESC)
                                   break;
                           if (!is_ansi_middle(linebuf[i]))
                                   i = 0;
                   }
                   if (i >= 0 && !is_ansi_end(ch) && !is_ansi_middle(ch)) {
                         /* Remove whole unrecognized sequence.  */                          /* Remove whole unrecognized sequence.  */
                         do {                          curr = i;
                                 curr--;  
                         } while (curr > 0 && linebuf[curr] != ESC);  
                         return (0);                          return (0);
                 }                  }
                 a = AT_ANSI;    /* Will force re-AT_'ing around it.  */                  if (i >= 0 || ch == ESC) {
                 w = 0;                          a = AT_ANSI;  /* Will force re-AT_'ing around it. */
         } else if (ctldisp == OPT_ONPLUS && ch == ESC) {                          w = 0;
                 a = AT_ANSI;    /* Will force re-AT_'ing around it.  */                  }
                 w = 0;          }
         } else {          if (w == -1) {
                 char *p = &linebuf[curr];                  wchar_t prev_ch;
                 LWCHAR prev_ch = step_char(&p, -1, linebuf);  
                   if (utf_mode) {
                           for (i = curr - 1; i >= 0; i--)
                                   if (!IS_UTF8_TRAIL(linebuf[i]))
                                           break;
                           if (i >= 0) {
                                   w = mbtowc(&prev_ch, linebuf + i, curr - i);
                                   if (w == -1 || i + w < curr)
                                           prev_ch = L' ';
                           } else
                                   prev_ch = L' ';
                   } else
                           prev_ch = curr > 0 ? linebuf[curr - 1] : L' ';
                 w = pwidth(ch, a, prev_ch);                  w = pwidth(ch, a, prev_ch);
         }          }
   

Legend:
Removed from v.1.24  
changed lines
  Added in v.1.25