home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 6.0.244 < prev    next >
Encoding:
Internet Message Format  |  2002-02-20  |  13.6 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.0.244
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. MIME-Version: 1.0
  6. Content-Type: text/plain; charset=ISO-8859-1
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 6.0.244
  11. Problem:    Multi-byte: Problems with (illegal) UTF-8 characters in menu and
  12.         file name (e.g., icon text, status line).
  13. Solution:   Correctly handle unprintable characters.  Catch illegal UTF-8
  14.         characters and replace them with <xx>.  Truncating the status line
  15.         wasn't done correctly at a multi-byte character. (Yasuhiro
  16.         Matsumoto)
  17.         Added correct_cmdspos() and transchar_byte().
  18. Files:        src/buffer.c, src/charset.c, src/ex_getln.c, src/gui.c,
  19.         src/message.c, src/proto/charset.pro, src/screen.c, src/vim.h
  20.  
  21.  
  22. *** ../vim60.243/src/buffer.c    Tue Feb 12 10:13:15 2002
  23. --- src/buffer.c    Thu Feb 21 10:50:09 2002
  24. ***************
  25. *** 2504,2512 ****
  26.           name = curbuf->b_ffname;
  27.       home_replace(shorthelp ? curbuf : NULL, name, p,
  28.                         (int)(IOSIZE - (p - buffer)), TRUE);
  29. -     /* the file name may contain unprintable characters, esp. when using
  30. -      * multi-byte chars */
  31. -     trans_characters(buffer, IOSIZE);
  32.       }
  33.   
  34.       sprintf((char *)buffer + STRLEN(buffer),
  35. --- 2504,2509 ----
  36. ***************
  37. *** 2735,2745 ****
  38.           else            /* use file name only in icon */
  39.           i_name = gettail(curbuf->b_ffname);
  40.           *i_str = NUL;
  41. !         /* Truncate name at 100 chars. */
  42. !         if (STRLEN(i_name) > 100)
  43. !         i_name += STRLEN(i_name) - 100;
  44. !         while (*i_name)
  45. !         STRCAT(i_str, transchar(*i_name++));
  46.       }
  47.       }
  48.   
  49. --- 2732,2750 ----
  50.           else            /* use file name only in icon */
  51.           i_name = gettail(curbuf->b_ffname);
  52.           *i_str = NUL;
  53. !         /* Truncate name at 100 bytes. */
  54. !         len = STRLEN(i_name);
  55. !         if (len > 100)
  56. !         {
  57. !         len -= 100;
  58. ! #ifdef FEAT_MBYTE
  59. !         if (has_mbyte)
  60. !             len += (*mb_tail_off)(i_name, i_name + len) + 1;
  61. ! #endif
  62. !         i_name += len;
  63. !         }
  64. !         STRCPY(i_str, i_name);
  65. !         trans_characters(i_str, IOSIZE);
  66.       }
  67.       }
  68.   
  69. *** ../vim60.243/src/charset.c    Mon Feb 11 14:09:33 2002
  70. --- src/charset.c    Thu Feb 21 12:15:54 2002
  71. ***************
  72. *** 276,282 ****
  73.   
  74.   /*
  75.    * Translate any special characters in buf[bufsize] in-place.
  76. !  * If there is not enough room, not all characters will be translated.
  77.    */
  78.       void
  79.   trans_characters(buf, bufsize)
  80. --- 276,283 ----
  81.   
  82.   /*
  83.    * Translate any special characters in buf[bufsize] in-place.
  84. !  * The result is a string with only printable characters, but if there is not
  85. !  * enough room, not all characters will be translated.
  86.    */
  87.       void
  88.   trans_characters(buf, bufsize)
  89. ***************
  90. *** 293,316 ****
  91.       while (*buf != 0)
  92.       {
  93.   #ifdef FEAT_MBYTE
  94. -     char    bstr[7];
  95.       /* Assume a multi-byte character doesn't need translation. */
  96.       if (has_mbyte && (trs_len = (*mb_ptr2len_check)(buf)) > 1)
  97.           len -= trs_len;
  98.       else
  99.   #endif
  100.       {
  101. ! #ifdef FEAT_MBYTE
  102. !         /* catch illegal UTF-8 byte */
  103. !         if (enc_utf8 && *buf >= 0x80)
  104. !         {
  105. !         transchar_nonprint(bstr, *buf);
  106. !         trs = bstr;
  107. !         }
  108. !         else
  109. ! #endif
  110. !         trs = transchar(*buf);
  111.           trs_len = (int)STRLEN(trs);
  112.           if (trs_len > 1)
  113.           {
  114. --- 294,306 ----
  115.       while (*buf != 0)
  116.       {
  117.   #ifdef FEAT_MBYTE
  118.       /* Assume a multi-byte character doesn't need translation. */
  119.       if (has_mbyte && (trs_len = (*mb_ptr2len_check)(buf)) > 1)
  120.           len -= trs_len;
  121.       else
  122.   #endif
  123.       {
  124. !         trs = transchar_byte(*buf);
  125.           trs_len = (int)STRLEN(trs);
  126.           if (trs_len > 1)
  127.           {
  128. ***************
  129. *** 361,367 ****
  130.           if (l > 0)
  131.               len += l;
  132.           else
  133. !             ++len;    /* illegal byte sequence */
  134.           }
  135.       }
  136.       res = alloc((unsigned)(len + 1));
  137. --- 351,357 ----
  138.           if (l > 0)
  139.               len += l;
  140.           else
  141. !             len += 4;    /* illegal byte sequence */
  142.           }
  143.       }
  144.       res = alloc((unsigned)(len + 1));
  145. ***************
  146. *** 378,389 ****
  147.   #ifdef FEAT_MBYTE
  148.           if (has_mbyte && (l = (*mb_ptr2len_check)(p)) > 1)
  149.           {
  150. !         STRNCAT(res, p, l);
  151.           p += l;
  152.           }
  153.           else
  154.   #endif
  155. !         STRCAT(res, transchar(*p++));
  156.       }
  157.       }
  158.       return res;
  159. --- 368,379 ----
  160.   #ifdef FEAT_MBYTE
  161.           if (has_mbyte && (l = (*mb_ptr2len_check)(p)) > 1)
  162.           {
  163. !         STRNCAT(res, p, l);    /* append printable multi-byte char */
  164.           p += l;
  165.           }
  166.           else
  167.   #endif
  168. !         STRCAT(res, transchar_byte(*p++));
  169.       }
  170.       }
  171.       return res;
  172. ***************
  173. *** 430,448 ****
  174.    * initialized, and initializing options may cause transchar() to be called!
  175.    * When chartab_initialized == FALSE don't use chartab[].
  176.    * Does NOT work for multi-byte characters, c must be <= 255.
  177.    */
  178.       char_u *
  179.   transchar(c)
  180.       int        c;
  181.   {
  182. -     static char_u    buf[7];
  183.       int            i;
  184.   
  185.       i = 0;
  186.       if (IS_SPECIAL(c))        /* special key code, display as ~@ char */
  187.       {
  188. !     buf[0] = '~';
  189. !     buf[1] = '@';
  190.       i = 2;
  191.       c = K_SECOND(c);
  192.       }
  193. --- 420,441 ----
  194.    * initialized, and initializing options may cause transchar() to be called!
  195.    * When chartab_initialized == FALSE don't use chartab[].
  196.    * Does NOT work for multi-byte characters, c must be <= 255.
  197. +  * Also doesn't work for the first byte of a multi-byte, "c" must be a
  198. +  * character!
  199.    */
  200. + static char_u    transchar_buf[7];
  201.       char_u *
  202.   transchar(c)
  203.       int        c;
  204.   {
  205.       int            i;
  206.   
  207.       i = 0;
  208.       if (IS_SPECIAL(c))        /* special key code, display as ~@ char */
  209.       {
  210. !     transchar_buf[0] = '~';
  211. !     transchar_buf[1] = '@';
  212.       i = 2;
  213.       c = K_SECOND(c);
  214.       }
  215. ***************
  216. *** 459,471 ****
  217.           )) || (c < 256 && vim_isprintc_strict(c)))
  218.       {
  219.       /* printable character */
  220. !     buf[i] = c;
  221. !     buf[i + 1] = NUL;
  222.       }
  223.       else
  224. !     transchar_nonprint(buf + i, c);
  225. !     return buf;
  226.   }
  227.   
  228.   /*
  229.    * Convert non-printable character to two or more printable characters in
  230. --- 452,482 ----
  231.           )) || (c < 256 && vim_isprintc_strict(c)))
  232.       {
  233.       /* printable character */
  234. !     transchar_buf[i] = c;
  235. !     transchar_buf[i + 1] = NUL;
  236.       }
  237.       else
  238. !     transchar_nonprint(transchar_buf + i, c);
  239. !     return transchar_buf;
  240.   }
  241. + #if defined(FEAT_MBYTE) || defined(PROTO)
  242. + /*
  243. +  * Like transchar(), but called with a byte instead of a character.  Checks
  244. +  * for an illegal UTF-8 byte.
  245. +  */
  246. +     char_u *
  247. + transchar_byte(c)
  248. +     int        c;
  249. + {
  250. +     if (enc_utf8 && c >= 0x80)
  251. +     {
  252. +     transchar_nonprint(transchar_buf, c);
  253. +     return transchar_buf;
  254. +     }
  255. +     return transchar(c);
  256. + }
  257. + #endif
  258.   
  259.   /*
  260.    * Convert non-printable character to two or more printable characters in
  261. *** ../vim60.243/src/ex_getln.c    Mon Feb  4 22:30:34 2002
  262. --- src/ex_getln.c    Thu Feb 21 11:30:52 2002
  263. ***************
  264. *** 72,77 ****
  265. --- 72,80 ----
  266.   static int    cmdline_charsize __ARGS((int idx));
  267.   static void    set_cmdspos __ARGS((void));
  268.   static void    set_cmdspos_cursor __ARGS((void));
  269. + #ifdef FEAT_MBYTE
  270. + static void    correct_cmdspos __ARGS((int idx, int cells));
  271. + #endif
  272.   static void    alloc_cmdbuff __ARGS((int len));
  273.   static int    realloc_cmdbuff __ARGS((int len));
  274.   #ifdef FEAT_WILDMENU
  275. ***************
  276. *** 1078,1086 ****
  277.               if (has_mbyte)
  278.               {
  279.               /* Count ">" for double-wide char that doesn't fit. */
  280. !             if ((*mb_ptr2cells)(ccline.cmdbuff + ccline.cmdpos) > 1
  281. !                     && ccline.cmdspos % Columns + i > Columns)
  282. !                 ccline.cmdspos++;
  283.               ccline.cmdpos += (*mb_ptr2len_check)(ccline.cmdbuff
  284.                                + ccline.cmdpos) - 1;
  285.               }
  286. --- 1081,1087 ----
  287.               if (has_mbyte)
  288.               {
  289.               /* Count ">" for double-wide char that doesn't fit. */
  290. !             correct_cmdspos(ccline.cmdpos, i);
  291.               ccline.cmdpos += (*mb_ptr2len_check)(ccline.cmdbuff
  292.                                + ccline.cmdpos) - 1;
  293.               }
  294. ***************
  295. *** 1580,1590 ****
  296.       {
  297.       c = cmdline_charsize(i);
  298.   #ifdef FEAT_MBYTE
  299. !     /* Count ">" for double-wide char that doesn't fit. */
  300. !     if (has_mbyte
  301. !         && (*mb_ptr2cells)(ccline.cmdbuff + i) > 1
  302. !         && ccline.cmdspos % Columns + c > Columns)
  303. !         ccline.cmdspos++;
  304.   #endif
  305.       /* If the cmdline doesn't fit, put cursor on last visible char. */
  306.       if ((ccline.cmdspos += c) >= m)
  307. --- 1581,1589 ----
  308.       {
  309.       c = cmdline_charsize(i);
  310.   #ifdef FEAT_MBYTE
  311. !     /* Count ">" for double-wide multi-byte char that doesn't fit. */
  312. !     if (has_mbyte)
  313. !         correct_cmdspos(i, c);
  314.   #endif
  315.       /* If the cmdline doesn't fit, put cursor on last visible char. */
  316.       if ((ccline.cmdspos += c) >= m)
  317. ***************
  318. *** 1600,1605 ****
  319. --- 1599,1621 ----
  320.       }
  321.   }
  322.   
  323. + #ifdef FEAT_MBYTE
  324. + /*
  325. +  * Check if the character at "idx", which is "cells" wide, is a multi-byte
  326. +  * character that doesn't fit, so that a ">" must be displayed.
  327. +  */
  328. +     static void
  329. + correct_cmdspos(idx, cells)
  330. +     int        idx;
  331. +     int        cells;
  332. + {
  333. +     if ((*mb_ptr2len_check)(ccline.cmdbuff + idx) > 1
  334. +         && (*mb_ptr2cells)(ccline.cmdbuff + idx) > 1
  335. +         && ccline.cmdspos % Columns + cells > Columns)
  336. +     ccline.cmdspos++;
  337. + }
  338. + #endif
  339.   /*
  340.    * Get an Ex command line for the ":" command.
  341.    */
  342. ***************
  343. *** 2058,2067 ****
  344.           c = cmdline_charsize(ccline.cmdpos);
  345.   #ifdef FEAT_MBYTE
  346.           /* count ">" for a double-wide char that doesn't fit. */
  347. !         if (has_mbyte
  348. !             && (*mb_ptr2cells)(ccline.cmdbuff + ccline.cmdpos) > 1
  349. !             && ccline.cmdspos % Columns + c > Columns)
  350. !             ccline.cmdspos++;
  351.   #endif
  352.           /* Stop cursor at the end of the screen */
  353.           if (ccline.cmdspos + c >= m)
  354. --- 2074,2081 ----
  355.           c = cmdline_charsize(ccline.cmdpos);
  356.   #ifdef FEAT_MBYTE
  357.           /* count ">" for a double-wide char that doesn't fit. */
  358. !         if (has_mbyte)
  359. !             correct_cmdspos(ccline.cmdpos, c);
  360.   #endif
  361.           /* Stop cursor at the end of the screen */
  362.           if (ccline.cmdspos + c >= m)
  363. *** ../vim60.243/src/gui.c    Thu Feb 21 12:32:53 2002
  364. --- src/gui.c    Thu Feb 21 12:11:52 2002
  365. ***************
  366. *** 1398,1404 ****
  367.           }
  368.           else
  369.           {
  370. !         str = transchar(s[i]);
  371.           if (str[0] && str[1])
  372.               printf("<%s>", (char *)str);
  373.           else
  374. --- 1398,1404 ----
  375.           }
  376.           else
  377.           {
  378. !         str = transchar_byte(s[i]);
  379.           if (str[0] && str[1])
  380.               printf("<%s>", (char *)str);
  381.           else
  382. *** ../vim60.243/src/message.c    Thu Feb 21 12:58:20 2002
  383. --- src/message.c    Thu Feb 21 12:52:20 2002
  384. ***************
  385. *** 1060,1066 ****
  386.       return p + l;
  387.       }
  388.   #endif
  389. !     msg_puts_attr(transchar(*p), attr);
  390.       return p + 1;
  391.   }
  392.   
  393. --- 1060,1066 ----
  394.       return p + l;
  395.       }
  396.   #endif
  397. !     msg_puts_attr(transchar_byte(*p), attr);
  398.       return p + 1;
  399.   }
  400.   
  401. ***************
  402. *** 1110,1116 ****
  403.       else
  404.   #endif
  405.       {
  406. !         s = transchar(*str);
  407.           if (attr == 0 && s[1] != NUL)
  408.           msg_puts_attr(s, hl_attr(HLF_8));    /* unprintable char */
  409.           else
  410. --- 1110,1116 ----
  411.       else
  412.   #endif
  413.       {
  414. !         s = transchar_byte(*str);
  415.           if (attr == 0 && s[1] != NUL)
  416.           msg_puts_attr(s, hl_attr(HLF_8));    /* unprintable char */
  417.           else
  418. ***************
  419. *** 1357,1363 ****
  420.           else if (c != NUL && (n = byte2cells(c)) > 1)
  421.           {
  422.           n_extra = n - 1;
  423. !         p_extra = transchar(c);
  424.           c_extra = NUL;
  425.           c = *p_extra++;
  426.           }
  427. --- 1357,1363 ----
  428.           else if (c != NUL && (n = byte2cells(c)) > 1)
  429.           {
  430.           n_extra = n - 1;
  431. !         p_extra = transchar_byte(c);
  432.           c_extra = NUL;
  433.           c = *p_extra++;
  434.           }
  435. *** ../vim60.243/src/proto/charset.pro    Tue Sep 25 21:49:10 2001
  436. --- src/proto/charset.pro    Thu Feb 21 12:15:35 2002
  437. ***************
  438. *** 5,10 ****
  439. --- 5,11 ----
  440.   char_u *transstr __ARGS((char_u *s));
  441.   void str_foldcase __ARGS((char_u *p));
  442.   char_u *transchar __ARGS((int c));
  443. + char_u *transchar_byte __ARGS((int c));
  444.   void transchar_nonprint __ARGS((char_u *buf, int c));
  445.   void transchar_hex __ARGS((char_u *buf, int c));
  446.   int byte2cells __ARGS((int b));
  447. *** ../vim60.243/src/screen.c    Tue Feb  5 22:26:51 2002
  448. --- src/screen.c    Thu Feb 21 12:10:20 2002
  449. ***************
  450. *** 4559,4565 ****
  451.           else
  452.   #endif
  453.           {
  454. !         STRCPY(buf + len, transchar(*s));
  455.           len += (int)STRLEN(buf + len);
  456.           }
  457.       }
  458. --- 4564,4570 ----
  459.           else
  460.   #endif
  461.           {
  462. !         STRCPY(buf + len, transchar_byte(*s));
  463.           len += (int)STRLEN(buf + len);
  464.           }
  465.       }
  466. ***************
  467. *** 4739,4753 ****
  468.               clen += (*mb_ptr2cells)(p + i);
  469.           /* Find first character that will fit.
  470.            * Going from start to end is much faster for DBCS. */
  471. !         for (i = 0; p[i] != NUL && clen > this_ru_col - 1;
  472.                             i += (*mb_ptr2len_check)(p + i))
  473.               clen -= (*mb_ptr2cells)(p + i);
  474.           if (i > 0)
  475.           {
  476.               p = p + i - 1;
  477.               *p = '<';
  478.           }
  479. -         len = clen;
  480.   
  481.           }
  482.           else
  483. --- 4744,4759 ----
  484.               clen += (*mb_ptr2cells)(p + i);
  485.           /* Find first character that will fit.
  486.            * Going from start to end is much faster for DBCS. */
  487. !         for (i = 0; p[i] != NUL && clen >= this_ru_col - 1;
  488.                             i += (*mb_ptr2len_check)(p + i))
  489.               clen -= (*mb_ptr2cells)(p + i);
  490. +         len = clen;
  491.           if (i > 0)
  492.           {
  493.               p = p + i - 1;
  494.               *p = '<';
  495. +             ++len;
  496.           }
  497.   
  498.           }
  499.           else
  500. *** ../vim60.243/src/vim.h    Sun Feb 17 23:22:34 2002
  501. --- src/vim.h    Thu Feb 21 12:15:37 2002
  502. ***************
  503. *** 1198,1203 ****
  504. --- 1198,1204 ----
  505.   #else
  506.   # define MB_STRICMP(d, s)    STRICMP((d), (s))
  507.   # define MB_STRNICMP(d, s, n)    STRNICMP((d), (s), (n))
  508. + # define transchar_byte(c)    transchar(c)
  509.   #endif
  510.   
  511.   #define STRCAT(d, s)        strcat((char *)(d), (char *)(s))
  512. *** ../vim60.243/src/version.c    Thu Feb 21 12:58:20 2002
  513. --- src/version.c    Thu Feb 21 13:51:56 2002
  514. ***************
  515. *** 608,609 ****
  516. --- 608,611 ----
  517.   {   /* Add new patch number below this line */
  518. + /**/
  519. +     244,
  520.   /**/
  521.  
  522. -- 
  523. "You're fired." (1980)
  524. "You're laid off." (1985)
  525. "You're downsized." (1990)
  526. "You're rightsized." (1992)
  527.                 (Scott Adams - The Dilbert principle)
  528.  
  529.  ///  Bram Moolenaar -- Bram@moolenaar.net -- http://www.moolenaar.net  \\\
  530. ///   Creator of Vim -- http://vim.sf.net -- ftp://ftp.vim.org/pub/vim   \\\
  531. \\\           Project leader for A-A-P -- http://www.a-a-p.org           ///
  532.  \\\  Help me helping AIDS orphans in Uganda - http://iccf-holland.org  ///
  533.