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.1.418 < prev    next >
Encoding:
Internet Message Format  |  2003-03-25  |  13.6 KB

  1. To: vim-dev@vim.org
  2. Subject: Patch 6.1.418 (extra)
  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.1.418 (extra)
  11. Problem:    The result of strftime() is in the current locals.  Need to
  12.         convert it to 'encoding'.
  13. Solution:   Obtain the current locale and convert the argument for strftime()
  14.         to it and the result back to 'encoding'.  (Daniel Elstner)
  15. Files:        src/eval.c, src/ex_cmds.c, src/ex_cmds2.c, src/mbyte.c,
  16.         src/proto/mbyte.pro, src/option.c, src/os_mswin.c
  17.  
  18.  
  19. *** ../vim61.417/src/eval.c    Sat Mar 15 17:55:18 2003
  20. --- src/eval.c    Fri Mar 21 20:33:32 2003
  21. ***************
  22. *** 4822,4830 ****
  23.       str = get_var_string(&argvars[0]);
  24.       from = enc_canonize(enc_skip(get_var_string_buf(&argvars[1], buf1)));
  25.       to = enc_canonize(enc_skip(get_var_string_buf(&argvars[2], buf2)));
  26. ! # ifdef USE_ICONV
  27. !     vimconv.vc_fd = (iconv_t)-1;
  28. ! # endif
  29.       convert_setup(&vimconv, from, to);
  30.   
  31.       /* If the encodings are equal, no conversion needed. */
  32. --- 4822,4828 ----
  33.       str = get_var_string(&argvars[0]);
  34.       from = enc_canonize(enc_skip(get_var_string_buf(&argvars[1], buf1)));
  35.       to = enc_canonize(enc_skip(get_var_string_buf(&argvars[2], buf2)));
  36. !     vimconv.vc_type = CONV_NONE;
  37.       convert_setup(&vimconv, from, to);
  38.   
  39.       /* If the encodings are equal, no conversion needed. */
  40. ***************
  41. *** 4833,4839 ****
  42.       else
  43.       retvar->var_val.var_string = string_convert(&vimconv, str, NULL);
  44.   
  45. !     convert_setup(&vimconv, (char_u *)"", (char_u *)"");
  46.       vim_free(from);
  47.       vim_free(to);
  48.   #endif
  49. --- 4831,4837 ----
  50.       else
  51.       retvar->var_val.var_string = string_convert(&vimconv, str, NULL);
  52.   
  53. !     convert_setup(&vimconv, NULL, NULL);
  54.       vim_free(from);
  55.       vim_free(to);
  56.   #endif
  57. ***************
  58. *** 6087,6097 ****
  59.       VAR        argvars;
  60.       VAR        retvar;
  61.   {
  62. !     char_u    result_buf[80];
  63.       struct tm    *curtime;
  64.       time_t    seconds;
  65.       char_u    *p;
  66.   
  67.       p = get_var_string(&argvars[0]);
  68.       if (argvars[1].var_type == VAR_UNKNOWN)
  69.       seconds = time(NULL);
  70. --- 6085,6097 ----
  71.       VAR        argvars;
  72.       VAR        retvar;
  73.   {
  74. !     char_u    result_buf[256];
  75.       struct tm    *curtime;
  76.       time_t    seconds;
  77.       char_u    *p;
  78.   
  79. +     retvar->var_type = VAR_STRING;
  80.       p = get_var_string(&argvars[0]);
  81.       if (argvars[1].var_type == VAR_UNKNOWN)
  82.       seconds = time(NULL);
  83. ***************
  84. *** 6100,6111 ****
  85.       curtime = localtime(&seconds);
  86.       /* MSVC returns NULL for an invalid value of seconds. */
  87.       if (curtime == NULL)
  88. !     STRCPY(result_buf, _("(Invalid)"));
  89.       else
  90. !     (void)strftime((char *)result_buf, (size_t)80, (char *)p, curtime);
  91.   
  92. !     retvar->var_type = VAR_STRING;
  93. !     retvar->var_val.var_string = vim_strsave(result_buf);
  94.   }
  95.   #endif
  96.   
  97. --- 6100,6141 ----
  98.       curtime = localtime(&seconds);
  99.       /* MSVC returns NULL for an invalid value of seconds. */
  100.       if (curtime == NULL)
  101. !     retvar->var_val.var_string = vim_strsave((char_u *)_("(Invalid)"));
  102.       else
  103. !     {
  104. ! # ifdef FEAT_MBYTE
  105. !     vimconv_T   conv;
  106. !     char_u        *enc;
  107. !     conv.vc_type = CONV_NONE;
  108. !     enc = enc_locale();
  109. !     convert_setup(&conv, p_enc, enc);
  110. !     if (conv.vc_type != CONV_NONE)
  111. !         p = string_convert(&conv, p, NULL);
  112. ! # endif
  113. !     if (p != NULL)
  114. !         (void)strftime((char *)result_buf, sizeof(result_buf),
  115. !                               (char *)p, curtime);
  116. !     else
  117. !         result_buf[0] = NUL;
  118.   
  119. ! # ifdef FEAT_MBYTE
  120. !     if (conv.vc_type != CONV_NONE)
  121. !         vim_free(p);
  122. !     convert_setup(&conv, enc, p_enc);
  123. !     if (conv.vc_type != CONV_NONE)
  124. !         retvar->var_val.var_string =
  125. !                       string_convert(&conv, result_buf, NULL);
  126. !     else
  127. ! # endif
  128. !         retvar->var_val.var_string = vim_strsave(result_buf);
  129. ! # ifdef FEAT_MBYTE
  130. !     /* Release conversion descriptors */
  131. !     convert_setup(&conv, NULL, NULL);
  132. !     vim_free(enc);
  133. ! # endif
  134. !     }
  135.   }
  136.   #endif
  137.   
  138. *** ../vim61.417/src/ex_cmds.c    Sun Mar 16 22:28:10 2003
  139. --- src/ex_cmds.c    Fri Mar 21 20:20:33 2003
  140. ***************
  141. *** 1600,1608 ****
  142.       vir.vir_fd = fp_in;
  143.   #ifdef FEAT_MBYTE
  144.       vir.vir_conv.vc_type = CONV_NONE;
  145. - # ifdef USE_ICONV
  146. -     vir.vir_conv.vc_fd = (iconv_t)-1;
  147. - # endif
  148.   #endif
  149.   
  150.       if (fp_in != NULL)
  151. --- 1600,1605 ----
  152. ***************
  153. *** 1644,1650 ****
  154.       vim_free(vir.vir_line);
  155.   #ifdef FEAT_MBYTE
  156.       if (vir.vir_conv.vc_type != CONV_NONE)
  157. !     convert_setup(&vir.vir_conv, (char_u *)"", (char_u *)"");
  158.   #endif
  159.   }
  160.   
  161. --- 1641,1647 ----
  162.       vim_free(vir.vir_line);
  163.   #ifdef FEAT_MBYTE
  164.       if (vir.vir_conv.vc_type != CONV_NONE)
  165. !     convert_setup(&vir.vir_conv, NULL, NULL);
  166.   #endif
  167.   }
  168.   
  169. *** ../vim61.417/src/ex_cmds2.c    Sat Mar 15 17:55:18 2003
  170. --- src/ex_cmds2.c    Fri Mar 21 20:21:05 2003
  171. ***************
  172. *** 2059,2067 ****
  173.   #endif
  174.   #ifdef FEAT_MBYTE
  175.       cookie.conv.vc_type = CONV_NONE;        /* no conversion */
  176. - # ifdef USE_ICONV
  177. -     cookie.conv.vc_fd = (iconv_t)-1;
  178. - # endif
  179.   #endif
  180.   
  181.       /*
  182. --- 2059,2064 ----
  183. *** ../vim61.417/src/mbyte.c    Wed Mar 26 21:35:24 2003
  184. --- src/mbyte.c    Wed Mar 26 19:53:37 2003
  185. ***************
  186. *** 361,370 ****
  187.       input_conv.vc_type = CONV_NONE;
  188.       input_conv.vc_factor = 1;
  189.       output_conv.vc_type = CONV_NONE;
  190. - #ifdef USE_ICONV
  191. -     input_conv.vc_fd = (iconv_t)-1;
  192. -     output_conv.vc_fd = (iconv_t)-1;
  193. - #endif
  194.       return NULL;
  195.       }
  196.   
  197. --- 361,366 ----
  198. ***************
  199. *** 575,584 ****
  200.       set_string_option_direct((char_u *)"fencs", -1,
  201.                    (char_u *)"ucs-bom,utf-8,latin1", OPT_FREE);
  202.   #ifdef FEAT_MBYTE_IME
  203. ! # ifdef USE_ICONV
  204. !     ime_conv.vc_fd = (iconv_t)-1;
  205. !     ime_conv_cp.vc_fd = (iconv_t)-1;
  206. ! # endif
  207.       convert_setup(&ime_conv, (char_u *)"ucs-2", p_enc);
  208.       ime_conv_cp.vc_type = CONV_DBCS_TO_UCS2;
  209.       ime_conv_cp.vc_dbcs = GetACP();
  210. --- 571,578 ----
  211.       set_string_option_direct((char_u *)"fencs", -1,
  212.                    (char_u *)"ucs-bom,utf-8,latin1", OPT_FREE);
  213.   #ifdef FEAT_MBYTE_IME
  214. !     ime_conv.vc_type = CONV_NONE;
  215. !     ime_conv_cp.vc_type = CONV_NONE;
  216.       convert_setup(&ime_conv, (char_u *)"ucs-2", p_enc);
  217.       ime_conv_cp.vc_type = CONV_DBCS_TO_UCS2;
  218.       ime_conv_cp.vc_dbcs = GetACP();
  219. ***************
  220. *** 2426,2437 ****
  221.   #endif
  222.   
  223.   /*
  224. !  * Set the default value for 'encoding' (p_enc).
  225. !  * This must be called only once.
  226. !  * Returns OK when successful, FAIL when not.
  227.    */
  228. !     int
  229. ! enc_default()
  230.   {
  231.   #ifndef WIN3264
  232.       char    *s;
  233. --- 2455,2465 ----
  234.   #endif
  235.   
  236.   /*
  237. !  * Get the canonicalized encoding of the current locale.
  238. !  * Returns an allocated string when successful, NULL when not.
  239.    */
  240. !     char_u *
  241. ! enc_locale()
  242.   {
  243.   #ifndef WIN3264
  244.       char    *s;
  245. ***************
  246. *** 2439,2445 ****
  247.       int        i;
  248.   #endif
  249.       char    buf[50];
  250. -     char_u    *save_enc;
  251.   #ifdef WIN3264
  252.       long    acp = GetACP();
  253.   
  254. --- 2467,2472 ----
  255. ***************
  256. *** 2498,2515 ****
  257.       buf[i] = NUL;
  258.   #endif
  259.   
  260. !     /*
  261. !      * Try setting 'encoding' and check if the value is valid.
  262. !      * If not, go back to the default "latin1".
  263. !      */
  264. !     save_enc = p_enc;
  265. !     p_enc = enc_canonize((char_u *)buf);
  266. !     if (p_enc != NULL && mb_init() == NULL)
  267. !     return OK;
  268. !     vim_free(p_enc);
  269. !     p_enc = save_enc;
  270. !     return FAIL;
  271.   }
  272.   
  273.   # if defined(USE_ICONV) || defined(PROTO)
  274. --- 2525,2531 ----
  275.       buf[i] = NUL;
  276.   #endif
  277.   
  278. !     return enc_canonize((char_u *)buf);
  279.   }
  280.   
  281.   # if defined(USE_ICONV) || defined(PROTO)
  282. ***************
  283. *** 2709,2717 ****
  284.   {
  285.       /* Don't use iconv() when inputting or outputting characters. */
  286.       if (input_conv.vc_type == CONV_ICONV)
  287. !     convert_setup(&input_conv, (char_u *)"", (char_u *)"");
  288.       if (output_conv.vc_type == CONV_ICONV)
  289. !     convert_setup(&output_conv, (char_u *)"", (char_u *)"");
  290.   
  291.       if (hIconvDLL != 0)
  292.       FreeLibrary(hIconvDLL);
  293. --- 2725,2733 ----
  294.   {
  295.       /* Don't use iconv() when inputting or outputting characters. */
  296.       if (input_conv.vc_type == CONV_ICONV)
  297. !     convert_setup(&input_conv, NULL, NULL);
  298.       if (output_conv.vc_type == CONV_ICONV)
  299. !     convert_setup(&output_conv, NULL, NULL);
  300.   
  301.       if (hIconvDLL != 0)
  302.       FreeLibrary(hIconvDLL);
  303. ***************
  304. *** 4062,4067 ****
  305. --- 4078,4084 ----
  306.   /*
  307.    * Setup "vcp" for conversion from "from" to "to".
  308.    * The names must have been made canonical with enc_canonize().
  309. +  * vcp->vc_type must have been initialized to CONV_NONE.
  310.    * Note: cannot be used for conversion from/to ucs-2 and ucs-4 (will use utf-8
  311.    * instead).
  312.    */
  313. ***************
  314. *** 4075,4092 ****
  315.       int        to_prop;
  316.   
  317.       /* Reset to no conversion. */
  318. -     vcp->vc_type = CONV_NONE;
  319. -     vcp->vc_factor = 1;
  320.   # ifdef USE_ICONV
  321. !     if (vcp->vc_fd != (iconv_t)-1)
  322. !     {
  323.       iconv_close(vcp->vc_fd);
  324. -     vcp->vc_fd = (iconv_t)-1;
  325. -     }
  326.   # endif
  327.   
  328.       /* No conversion when one of the names is empty or they are equal. */
  329. !     if (*from == NUL || *to == NUL || STRCMP(from, to) == 0)
  330.       return;
  331.   
  332.       from_prop = enc_canon_props(from);
  333. --- 4092,4107 ----
  334.       int        to_prop;
  335.   
  336.       /* Reset to no conversion. */
  337.   # ifdef USE_ICONV
  338. !     if (vcp->vc_type == CONV_ICONV && vcp->vc_fd != (iconv_t)-1)
  339.       iconv_close(vcp->vc_fd);
  340.   # endif
  341. +     vcp->vc_type = CONV_NONE;
  342. +     vcp->vc_factor = 1;
  343.   
  344.       /* No conversion when one of the names is empty or they are equal. */
  345. !     if (from == NULL || *from == NUL || to == NULL || *to == NUL
  346. !                              || STRCMP(from, to) == 0)
  347.       return;
  348.   
  349.       from_prop = enc_canon_props(from);
  350. *** ../vim61.417/src/proto/mbyte.pro    Fri Mar 22 21:41:17 2002
  351. --- src/proto/mbyte.pro    Fri Mar 21 20:29:42 2003
  352. ***************
  353. *** 54,60 ****
  354.   int mb_fix_col __ARGS((int col, int row));
  355.   char_u *enc_skip __ARGS((char_u *p));
  356.   char_u *enc_canonize __ARGS((char_u *enc));
  357. ! int enc_default __ARGS((void));
  358.   void *my_iconv_open __ARGS((char_u *to, char_u *from));
  359.   int iconv_enabled __ARGS((int verbose));
  360.   void iconv_end __ARGS((void));
  361. --- 54,60 ----
  362.   int mb_fix_col __ARGS((int col, int row));
  363.   char_u *enc_skip __ARGS((char_u *p));
  364.   char_u *enc_canonize __ARGS((char_u *enc));
  365. ! char_u *enc_locale __ARGS((void));
  366.   void *my_iconv_open __ARGS((char_u *to, char_u *from));
  367.   int iconv_enabled __ARGS((int verbose));
  368.   void iconv_end __ARGS((void));
  369. *** ../vim61.417/src/option.c    Sat Mar 15 17:55:18 2003
  370. --- src/option.c    Fri Mar 21 20:36:57 2003
  371. ***************
  372. *** 2658,2670 ****
  373.       }
  374.   # endif
  375.   
  376. !     /* enc_default() will try setting p_enc to a value depending on the
  377. !      * current locale */
  378. !     if (enc_default() == OK)
  379.       {
  380. !     opt_idx = findoption((char_u *)"encoding");
  381. !     options[opt_idx].def_val[VI_DEFAULT] = p_enc;
  382. !     options[opt_idx].flags |= P_DEF_ALLOCED;
  383.       }
  384.   #endif
  385.   }
  386. --- 2658,2684 ----
  387.       }
  388.   # endif
  389.   
  390. !     /* enc_locale() will try to find the encoding of the current locale. */
  391. !     p = enc_locale();
  392. !     if (p != NULL)
  393.       {
  394. !     char_u *save_enc;
  395. !     /* Try setting 'encoding' and check if the value is valid.
  396. !      * If not, go back to the default "latin1". */
  397. !     save_enc = p_enc;
  398. !     p_enc = p;
  399. !     if (mb_init() == NULL)
  400. !     {
  401. !         opt_idx = findoption((char_u *)"encoding");
  402. !         options[opt_idx].def_val[VI_DEFAULT] = p_enc;
  403. !         options[opt_idx].flags |= P_DEF_ALLOCED;
  404. !     }
  405. !     else
  406. !     {
  407. !         vim_free(p_enc);
  408. !         p_enc = save_enc;
  409. !     }
  410.       }
  411.   #endif
  412.   }
  413. *** ../vim61.417/src/os_mswin.c    Sat Mar 15 16:54:47 2003
  414. --- src/os_mswin.c    Fri Mar 21 20:24:21 2003
  415. ***************
  416. *** 917,926 ****
  417.       }
  418.       else
  419.       {
  420. - #ifdef USE_ICONV
  421. -     conv.vc_fd = (iconv_t)-1;
  422. - #endif
  423.       /* We might be called before we have p_enc set up. */
  424.       convert_setup(&conv, p_enc ? p_enc : (char_u *)"latin1",
  425.                                  (char_u *)"utf-8");
  426.       if (conv.vc_type != CONV_NONE)
  427. --- 917,924 ----
  428.       }
  429.       else
  430.       {
  431.       /* We might be called before we have p_enc set up. */
  432. +     conv.vc_type = CONV_NONE;
  433.       convert_setup(&conv, p_enc ? p_enc : (char_u *)"latin1",
  434.                                  (char_u *)"utf-8");
  435.       if (conv.vc_type != CONV_NONE)
  436. ***************
  437. *** 929,935 ****
  438.           if (str == NULL)
  439.           return NULL;
  440.       }
  441. !     convert_setup(&conv, (char_u *)"", (char_u *)"");
  442.   
  443.       length = utf8_to_ucs2((char_u **)&str, len, NULL);
  444.       ret = (WCHAR *)alloc((unsigned)(length * sizeof(WCHAR)));
  445. --- 927,933 ----
  446.           if (str == NULL)
  447.           return NULL;
  448.       }
  449. !     convert_setup(&conv, NULL, NULL);
  450.   
  451.       length = utf8_to_ucs2((char_u **)&str, len, NULL);
  452.       ret = (WCHAR *)alloc((unsigned)(length * sizeof(WCHAR)));
  453. ***************
  454. *** 981,990 ****
  455.       {
  456.       *len = ucs2_to_utf8(&str, len, utf8_str);
  457.   
  458. - #ifdef USE_ICONV
  459. -     conv.vc_fd = (iconv_t)-1;
  460. - #endif
  461.       /* We might be called before we have p_enc set up. */
  462.       convert_setup(&conv, (char_u *)"utf-8",
  463.                           p_enc? p_enc: (char_u *)"latin1");
  464.       if (conv.vc_type == CONV_NONE)
  465. --- 979,986 ----
  466.       {
  467.       *len = ucs2_to_utf8(&str, len, utf8_str);
  468.   
  469.       /* We might be called before we have p_enc set up. */
  470. +     conv.vc_type = CONV_NONE;
  471.       convert_setup(&conv, (char_u *)"utf-8",
  472.                           p_enc? p_enc: (char_u *)"latin1");
  473.       if (conv.vc_type == CONV_NONE)
  474. ***************
  475. *** 998,1004 ****
  476.           vim_free(utf8_str);
  477.       }
  478.   
  479. !     convert_setup(&conv, (char_u *)"", (char_u *)"");
  480.       }
  481.   
  482.       return enc_str;
  483. --- 994,1000 ----
  484.           vim_free(utf8_str);
  485.       }
  486.   
  487. !     convert_setup(&conv, NULL, NULL);
  488.       }
  489.   
  490.       return enc_str;
  491. *** ../vim61.417/src/version.c    Wed Mar 26 21:35:24 2003
  492. --- src/version.c    Wed Mar 26 21:37:35 2003
  493. ***************
  494. *** 613,614 ****
  495. --- 613,616 ----
  496.   {   /* Add new patch number below this line */
  497. + /**/
  498. +     418,
  499.   /**/
  500.  
  501. -- 
  502. hundred-and-one symptoms of being an internet addict:
  503. 228. You spend Saturday night making the counter on your home page
  504.      pass that 2000 mark.
  505.  
  506.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  507. ///          Creator of Vim - Vi IMproved -- http://www.Vim.org          \\\
  508. \\\              Project leader for A-A-P -- http://www.A-A-P.org        ///
  509.  \\\     Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///
  510.