To: vim-dev@vim.org Subject: Patch 6.1.418 (extra) Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit ------------ Patch 6.1.418 (extra) Problem: The result of strftime() is in the current locals. Need to convert it to 'encoding'. Solution: Obtain the current locale and convert the argument for strftime() to it and the result back to 'encoding'. (Daniel Elstner) Files: src/eval.c, src/ex_cmds.c, src/ex_cmds2.c, src/mbyte.c, src/proto/mbyte.pro, src/option.c, src/os_mswin.c *** ../vim61.417/src/eval.c Sat Mar 15 17:55:18 2003 --- src/eval.c Fri Mar 21 20:33:32 2003 *************** *** 4822,4830 **** str = get_var_string(&argvars[0]); from = enc_canonize(enc_skip(get_var_string_buf(&argvars[1], buf1))); to = enc_canonize(enc_skip(get_var_string_buf(&argvars[2], buf2))); ! # ifdef USE_ICONV ! vimconv.vc_fd = (iconv_t)-1; ! # endif convert_setup(&vimconv, from, to); /* If the encodings are equal, no conversion needed. */ --- 4822,4828 ---- str = get_var_string(&argvars[0]); from = enc_canonize(enc_skip(get_var_string_buf(&argvars[1], buf1))); to = enc_canonize(enc_skip(get_var_string_buf(&argvars[2], buf2))); ! vimconv.vc_type = CONV_NONE; convert_setup(&vimconv, from, to); /* If the encodings are equal, no conversion needed. */ *************** *** 4833,4839 **** else retvar->var_val.var_string = string_convert(&vimconv, str, NULL); ! convert_setup(&vimconv, (char_u *)"", (char_u *)""); vim_free(from); vim_free(to); #endif --- 4831,4837 ---- else retvar->var_val.var_string = string_convert(&vimconv, str, NULL); ! convert_setup(&vimconv, NULL, NULL); vim_free(from); vim_free(to); #endif *************** *** 6087,6097 **** VAR argvars; VAR retvar; { ! char_u result_buf[80]; struct tm *curtime; time_t seconds; char_u *p; p = get_var_string(&argvars[0]); if (argvars[1].var_type == VAR_UNKNOWN) seconds = time(NULL); --- 6085,6097 ---- VAR argvars; VAR retvar; { ! char_u result_buf[256]; struct tm *curtime; time_t seconds; char_u *p; + retvar->var_type = VAR_STRING; + p = get_var_string(&argvars[0]); if (argvars[1].var_type == VAR_UNKNOWN) seconds = time(NULL); *************** *** 6100,6111 **** curtime = localtime(&seconds); /* MSVC returns NULL for an invalid value of seconds. */ if (curtime == NULL) ! STRCPY(result_buf, _("(Invalid)")); else ! (void)strftime((char *)result_buf, (size_t)80, (char *)p, curtime); ! retvar->var_type = VAR_STRING; ! retvar->var_val.var_string = vim_strsave(result_buf); } #endif --- 6100,6141 ---- curtime = localtime(&seconds); /* MSVC returns NULL for an invalid value of seconds. */ if (curtime == NULL) ! retvar->var_val.var_string = vim_strsave((char_u *)_("(Invalid)")); else ! { ! # ifdef FEAT_MBYTE ! vimconv_T conv; ! char_u *enc; ! ! conv.vc_type = CONV_NONE; ! enc = enc_locale(); ! convert_setup(&conv, p_enc, enc); ! if (conv.vc_type != CONV_NONE) ! p = string_convert(&conv, p, NULL); ! # endif ! if (p != NULL) ! (void)strftime((char *)result_buf, sizeof(result_buf), ! (char *)p, curtime); ! else ! result_buf[0] = NUL; ! # ifdef FEAT_MBYTE ! if (conv.vc_type != CONV_NONE) ! vim_free(p); ! convert_setup(&conv, enc, p_enc); ! if (conv.vc_type != CONV_NONE) ! retvar->var_val.var_string = ! string_convert(&conv, result_buf, NULL); ! else ! # endif ! retvar->var_val.var_string = vim_strsave(result_buf); ! ! # ifdef FEAT_MBYTE ! /* Release conversion descriptors */ ! convert_setup(&conv, NULL, NULL); ! vim_free(enc); ! # endif ! } } #endif *** ../vim61.417/src/ex_cmds.c Sun Mar 16 22:28:10 2003 --- src/ex_cmds.c Fri Mar 21 20:20:33 2003 *************** *** 1600,1608 **** vir.vir_fd = fp_in; #ifdef FEAT_MBYTE vir.vir_conv.vc_type = CONV_NONE; - # ifdef USE_ICONV - vir.vir_conv.vc_fd = (iconv_t)-1; - # endif #endif if (fp_in != NULL) --- 1600,1605 ---- *************** *** 1644,1650 **** vim_free(vir.vir_line); #ifdef FEAT_MBYTE if (vir.vir_conv.vc_type != CONV_NONE) ! convert_setup(&vir.vir_conv, (char_u *)"", (char_u *)""); #endif } --- 1641,1647 ---- vim_free(vir.vir_line); #ifdef FEAT_MBYTE if (vir.vir_conv.vc_type != CONV_NONE) ! convert_setup(&vir.vir_conv, NULL, NULL); #endif } *** ../vim61.417/src/ex_cmds2.c Sat Mar 15 17:55:18 2003 --- src/ex_cmds2.c Fri Mar 21 20:21:05 2003 *************** *** 2059,2067 **** #endif #ifdef FEAT_MBYTE cookie.conv.vc_type = CONV_NONE; /* no conversion */ - # ifdef USE_ICONV - cookie.conv.vc_fd = (iconv_t)-1; - # endif #endif /* --- 2059,2064 ---- *** ../vim61.417/src/mbyte.c Wed Mar 26 21:35:24 2003 --- src/mbyte.c Wed Mar 26 19:53:37 2003 *************** *** 361,370 **** input_conv.vc_type = CONV_NONE; input_conv.vc_factor = 1; output_conv.vc_type = CONV_NONE; - #ifdef USE_ICONV - input_conv.vc_fd = (iconv_t)-1; - output_conv.vc_fd = (iconv_t)-1; - #endif return NULL; } --- 361,366 ---- *************** *** 575,584 **** set_string_option_direct((char_u *)"fencs", -1, (char_u *)"ucs-bom,utf-8,latin1", OPT_FREE); #ifdef FEAT_MBYTE_IME ! # ifdef USE_ICONV ! ime_conv.vc_fd = (iconv_t)-1; ! ime_conv_cp.vc_fd = (iconv_t)-1; ! # endif convert_setup(&ime_conv, (char_u *)"ucs-2", p_enc); ime_conv_cp.vc_type = CONV_DBCS_TO_UCS2; ime_conv_cp.vc_dbcs = GetACP(); --- 571,578 ---- set_string_option_direct((char_u *)"fencs", -1, (char_u *)"ucs-bom,utf-8,latin1", OPT_FREE); #ifdef FEAT_MBYTE_IME ! ime_conv.vc_type = CONV_NONE; ! ime_conv_cp.vc_type = CONV_NONE; convert_setup(&ime_conv, (char_u *)"ucs-2", p_enc); ime_conv_cp.vc_type = CONV_DBCS_TO_UCS2; ime_conv_cp.vc_dbcs = GetACP(); *************** *** 2426,2437 **** #endif /* ! * Set the default value for 'encoding' (p_enc). ! * This must be called only once. ! * Returns OK when successful, FAIL when not. */ ! int ! enc_default() { #ifndef WIN3264 char *s; --- 2455,2465 ---- #endif /* ! * Get the canonicalized encoding of the current locale. ! * Returns an allocated string when successful, NULL when not. */ ! char_u * ! enc_locale() { #ifndef WIN3264 char *s; *************** *** 2439,2445 **** int i; #endif char buf[50]; - char_u *save_enc; #ifdef WIN3264 long acp = GetACP(); --- 2467,2472 ---- *************** *** 2498,2515 **** buf[i] = NUL; #endif ! /* ! * Try setting 'encoding' and check if the value is valid. ! * If not, go back to the default "latin1". ! */ ! save_enc = p_enc; ! p_enc = enc_canonize((char_u *)buf); ! if (p_enc != NULL && mb_init() == NULL) ! return OK; ! vim_free(p_enc); ! p_enc = save_enc; ! ! return FAIL; } # if defined(USE_ICONV) || defined(PROTO) --- 2525,2531 ---- buf[i] = NUL; #endif ! return enc_canonize((char_u *)buf); } # if defined(USE_ICONV) || defined(PROTO) *************** *** 2709,2717 **** { /* Don't use iconv() when inputting or outputting characters. */ if (input_conv.vc_type == CONV_ICONV) ! convert_setup(&input_conv, (char_u *)"", (char_u *)""); if (output_conv.vc_type == CONV_ICONV) ! convert_setup(&output_conv, (char_u *)"", (char_u *)""); if (hIconvDLL != 0) FreeLibrary(hIconvDLL); --- 2725,2733 ---- { /* Don't use iconv() when inputting or outputting characters. */ if (input_conv.vc_type == CONV_ICONV) ! convert_setup(&input_conv, NULL, NULL); if (output_conv.vc_type == CONV_ICONV) ! convert_setup(&output_conv, NULL, NULL); if (hIconvDLL != 0) FreeLibrary(hIconvDLL); *************** *** 4062,4067 **** --- 4078,4084 ---- /* * Setup "vcp" for conversion from "from" to "to". * The names must have been made canonical with enc_canonize(). + * vcp->vc_type must have been initialized to CONV_NONE. * Note: cannot be used for conversion from/to ucs-2 and ucs-4 (will use utf-8 * instead). */ *************** *** 4075,4092 **** int to_prop; /* Reset to no conversion. */ - vcp->vc_type = CONV_NONE; - vcp->vc_factor = 1; # ifdef USE_ICONV ! if (vcp->vc_fd != (iconv_t)-1) ! { iconv_close(vcp->vc_fd); - vcp->vc_fd = (iconv_t)-1; - } # endif /* No conversion when one of the names is empty or they are equal. */ ! if (*from == NUL || *to == NUL || STRCMP(from, to) == 0) return; from_prop = enc_canon_props(from); --- 4092,4107 ---- int to_prop; /* Reset to no conversion. */ # ifdef USE_ICONV ! if (vcp->vc_type == CONV_ICONV && vcp->vc_fd != (iconv_t)-1) iconv_close(vcp->vc_fd); # endif + vcp->vc_type = CONV_NONE; + vcp->vc_factor = 1; /* No conversion when one of the names is empty or they are equal. */ ! if (from == NULL || *from == NUL || to == NULL || *to == NUL ! || STRCMP(from, to) == 0) return; from_prop = enc_canon_props(from); *** ../vim61.417/src/proto/mbyte.pro Fri Mar 22 21:41:17 2002 --- src/proto/mbyte.pro Fri Mar 21 20:29:42 2003 *************** *** 54,60 **** int mb_fix_col __ARGS((int col, int row)); char_u *enc_skip __ARGS((char_u *p)); char_u *enc_canonize __ARGS((char_u *enc)); ! int enc_default __ARGS((void)); void *my_iconv_open __ARGS((char_u *to, char_u *from)); int iconv_enabled __ARGS((int verbose)); void iconv_end __ARGS((void)); --- 54,60 ---- int mb_fix_col __ARGS((int col, int row)); char_u *enc_skip __ARGS((char_u *p)); char_u *enc_canonize __ARGS((char_u *enc)); ! char_u *enc_locale __ARGS((void)); void *my_iconv_open __ARGS((char_u *to, char_u *from)); int iconv_enabled __ARGS((int verbose)); void iconv_end __ARGS((void)); *** ../vim61.417/src/option.c Sat Mar 15 17:55:18 2003 --- src/option.c Fri Mar 21 20:36:57 2003 *************** *** 2658,2670 **** } # endif ! /* enc_default() will try setting p_enc to a value depending on the ! * current locale */ ! if (enc_default() == OK) { ! opt_idx = findoption((char_u *)"encoding"); ! options[opt_idx].def_val[VI_DEFAULT] = p_enc; ! options[opt_idx].flags |= P_DEF_ALLOCED; } #endif } --- 2658,2684 ---- } # endif ! /* enc_locale() will try to find the encoding of the current locale. */ ! p = enc_locale(); ! if (p != NULL) { ! char_u *save_enc; ! ! /* Try setting 'encoding' and check if the value is valid. ! * If not, go back to the default "latin1". */ ! save_enc = p_enc; ! p_enc = p; ! if (mb_init() == NULL) ! { ! opt_idx = findoption((char_u *)"encoding"); ! options[opt_idx].def_val[VI_DEFAULT] = p_enc; ! options[opt_idx].flags |= P_DEF_ALLOCED; ! } ! else ! { ! vim_free(p_enc); ! p_enc = save_enc; ! } } #endif } *** ../vim61.417/src/os_mswin.c Sat Mar 15 16:54:47 2003 --- src/os_mswin.c Fri Mar 21 20:24:21 2003 *************** *** 917,926 **** } else { - #ifdef USE_ICONV - conv.vc_fd = (iconv_t)-1; - #endif /* We might be called before we have p_enc set up. */ convert_setup(&conv, p_enc ? p_enc : (char_u *)"latin1", (char_u *)"utf-8"); if (conv.vc_type != CONV_NONE) --- 917,924 ---- } else { /* We might be called before we have p_enc set up. */ + conv.vc_type = CONV_NONE; convert_setup(&conv, p_enc ? p_enc : (char_u *)"latin1", (char_u *)"utf-8"); if (conv.vc_type != CONV_NONE) *************** *** 929,935 **** if (str == NULL) return NULL; } ! convert_setup(&conv, (char_u *)"", (char_u *)""); length = utf8_to_ucs2((char_u **)&str, len, NULL); ret = (WCHAR *)alloc((unsigned)(length * sizeof(WCHAR))); --- 927,933 ---- if (str == NULL) return NULL; } ! convert_setup(&conv, NULL, NULL); length = utf8_to_ucs2((char_u **)&str, len, NULL); ret = (WCHAR *)alloc((unsigned)(length * sizeof(WCHAR))); *************** *** 981,990 **** { *len = ucs2_to_utf8(&str, len, utf8_str); - #ifdef USE_ICONV - conv.vc_fd = (iconv_t)-1; - #endif /* We might be called before we have p_enc set up. */ convert_setup(&conv, (char_u *)"utf-8", p_enc? p_enc: (char_u *)"latin1"); if (conv.vc_type == CONV_NONE) --- 979,986 ---- { *len = ucs2_to_utf8(&str, len, utf8_str); /* We might be called before we have p_enc set up. */ + conv.vc_type = CONV_NONE; convert_setup(&conv, (char_u *)"utf-8", p_enc? p_enc: (char_u *)"latin1"); if (conv.vc_type == CONV_NONE) *************** *** 998,1004 **** vim_free(utf8_str); } ! convert_setup(&conv, (char_u *)"", (char_u *)""); } return enc_str; --- 994,1000 ---- vim_free(utf8_str); } ! convert_setup(&conv, NULL, NULL); } return enc_str; *** ../vim61.417/src/version.c Wed Mar 26 21:35:24 2003 --- src/version.c Wed Mar 26 21:37:35 2003 *************** *** 613,614 **** --- 613,616 ---- { /* Add new patch number below this line */ + /**/ + 418, /**/ -- hundred-and-one symptoms of being an internet addict: 228. You spend Saturday night making the counter on your home page pass that 2000 mark. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// Creator of Vim - Vi IMproved -- http://www.Vim.org \\\ \\\ Project leader for A-A-P -- http://www.A-A-P.org /// \\\ Help AIDS victims, buy at Amazon -- http://ICCF.nl/click1.html ///