Mercurial > vim
comparison src/message.c @ 15822:9745c25da3bc v8.1.0918
patch 8.1.0918: MS-Windows: startup messages are not converted
commit https://github.com/vim/vim/commit/9b5c1fcdeae75f82a2083fafbbf75ab220f6ac1e
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Feb 14 14:08:04 2019 +0100
patch 8.1.0918: MS-Windows: startup messages are not converted
Problem: MS-Windows: startup messages are not converted.
Solution: Convert messages when the current codepage differs from
'encoding'. (Yasuhiro Matsumoto, closes #3914)
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 14 Feb 2019 14:15:15 +0100 |
parents | 2dcaa860e3fc |
children | 6733b8b1caf3 |
comparison
equal
deleted
inserted
replaced
15821:1c1897fe1cc2 | 15822:9745c25da3bc |
---|---|
2568 */ | 2568 */ |
2569 static void | 2569 static void |
2570 msg_puts_printf(char_u *str, int maxlen) | 2570 msg_puts_printf(char_u *str, int maxlen) |
2571 { | 2571 { |
2572 char_u *s = str; | 2572 char_u *s = str; |
2573 char_u buf[4]; | 2573 char_u *buf = NULL; |
2574 char_u *p; | 2574 char_u *p = s; |
2575 | |
2575 #ifdef WIN3264 | 2576 #ifdef WIN3264 |
2576 # if !defined(FEAT_GUI_MSWIN) | |
2577 char_u *ccp = NULL; | |
2578 | |
2579 # endif | |
2580 if (!(silent_mode && p_verbose == 0)) | 2577 if (!(silent_mode && p_verbose == 0)) |
2581 mch_settmode(TMODE_COOK); /* handle '\r' and '\n' correctly */ | 2578 mch_settmode(TMODE_COOK); /* handle CR and NL correctly */ |
2582 | |
2583 # if !defined(FEAT_GUI_MSWIN) | |
2584 if (enc_codepage >= 0 && (int)GetConsoleCP() != enc_codepage) | |
2585 { | |
2586 int inlen = (int)STRLEN(str); | |
2587 int outlen; | |
2588 WCHAR *widestr = (WCHAR *)enc_to_utf16(str, &inlen); | |
2589 | |
2590 if (widestr != NULL) | |
2591 { | |
2592 WideCharToMultiByte_alloc(GetConsoleCP(), 0, widestr, inlen, | |
2593 (LPSTR *)&ccp, &outlen, 0, 0); | |
2594 vim_free(widestr); | |
2595 s = str = ccp; | |
2596 } | |
2597 } | |
2598 # endif | |
2599 #endif | 2579 #endif |
2600 while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) | 2580 while ((maxlen < 0 || (int)(s - str) < maxlen) && *s != NUL) |
2601 { | 2581 { |
2602 if (!(silent_mode && p_verbose == 0)) | 2582 if (!(silent_mode && p_verbose == 0)) |
2603 { | 2583 { |
2604 /* NL --> CR NL translation (for Unix, not for "--version") */ | 2584 // NL --> CR NL translation (for Unix, not for "--version") |
2605 p = &buf[0]; | 2585 if (*s == NL) |
2606 if (*s == '\n' && !info_message) | 2586 { |
2607 *p++ = '\r'; | 2587 int n = (int)(s - p); |
2608 #if defined(USE_CR) | 2588 |
2609 else | 2589 buf = alloc(n + 3); |
2610 #endif | 2590 memcpy(buf, p, n); |
2611 *p++ = *s; | 2591 if (!info_message) |
2612 *p = '\0'; | 2592 buf[n++] = CAR; |
2613 if (info_message) /* informative message, not an error */ | 2593 #ifdef USE_CR |
2614 mch_msg((char *)buf); | 2594 else |
2615 else | 2595 #endif |
2616 mch_errmsg((char *)buf); | 2596 buf[n++] = NL; |
2617 } | 2597 buf[n++] = NUL; |
2618 | 2598 if (info_message) // informative message, not an error |
2619 /* primitive way to compute the current column */ | 2599 mch_msg((char *)buf); |
2600 else | |
2601 mch_errmsg((char *)buf); | |
2602 vim_free(buf); | |
2603 p = s + 1; | |
2604 } | |
2605 } | |
2606 | |
2607 // primitive way to compute the current column | |
2620 #ifdef FEAT_RIGHTLEFT | 2608 #ifdef FEAT_RIGHTLEFT |
2621 if (cmdmsg_rl) | 2609 if (cmdmsg_rl) |
2622 { | 2610 { |
2623 if (*s == '\r' || *s == '\n') | 2611 if (*s == CAR || *s == NL) |
2624 msg_col = Columns - 1; | 2612 msg_col = Columns - 1; |
2625 else | 2613 else |
2626 --msg_col; | 2614 --msg_col; |
2627 } | 2615 } |
2628 else | 2616 else |
2629 #endif | 2617 #endif |
2630 { | 2618 { |
2631 if (*s == '\r' || *s == '\n') | 2619 if (*s == CAR || *s == NL) |
2632 msg_col = 0; | 2620 msg_col = 0; |
2633 else | 2621 else |
2634 ++msg_col; | 2622 ++msg_col; |
2635 } | 2623 } |
2636 ++s; | 2624 ++s; |
2637 } | 2625 } |
2638 msg_didout = TRUE; /* assume that line is not empty */ | 2626 |
2627 if (*p != NUL && !(silent_mode && p_verbose == 0)) | |
2628 { | |
2629 if (maxlen > 0 && STRLEN(p) > (size_t)maxlen) | |
2630 p[maxlen] = 0; | |
2631 if (info_message) | |
2632 mch_msg((char *)p); | |
2633 else | |
2634 mch_errmsg((char *)p); | |
2635 } | |
2636 | |
2637 msg_didout = TRUE; // assume that line is not empty | |
2639 | 2638 |
2640 #ifdef WIN3264 | 2639 #ifdef WIN3264 |
2641 # if !defined(FEAT_GUI_MSWIN) | |
2642 vim_free(ccp); | |
2643 # endif | |
2644 if (!(silent_mode && p_verbose == 0)) | 2640 if (!(silent_mode && p_verbose == 0)) |
2645 mch_settmode(TMODE_RAW); | 2641 mch_settmode(TMODE_RAW); |
2646 #endif | 2642 #endif |
2647 } | 2643 } |
2648 | 2644 |
2939 * started and they can be displayed in a message box. | 2935 * started and they can be displayed in a message box. |
2940 */ | 2936 */ |
2941 void | 2937 void |
2942 mch_errmsg(char *str) | 2938 mch_errmsg(char *str) |
2943 { | 2939 { |
2940 #if defined(WIN3264) && !defined(FEAT_GUI_MSWIN) | |
2941 int len = STRLEN(str); | |
2942 DWORD nwrite = 0; | |
2943 DWORD mode = 0; | |
2944 HANDLE h = GetStdHandle(STD_ERROR_HANDLE); | |
2945 | |
2946 if (GetConsoleMode(h, &mode) && enc_codepage >= 0 | |
2947 && (int)GetConsoleCP() != enc_codepage) | |
2948 { | |
2949 WCHAR *w = enc_to_utf16((char_u *)str, &len); | |
2950 | |
2951 WriteConsoleW(h, w, len, &nwrite, NULL); | |
2952 vim_free(w); | |
2953 } | |
2954 else | |
2955 { | |
2956 fprintf(stderr, "%s", str); | |
2957 } | |
2958 #else | |
2944 int len; | 2959 int len; |
2945 | 2960 |
2946 #if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) | 2961 # if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) |
2947 /* On Unix use stderr if it's a tty. | 2962 /* On Unix use stderr if it's a tty. |
2948 * When not going to start the GUI also use stderr. | 2963 * When not going to start the GUI also use stderr. |
2949 * On Mac, when started from Finder, stderr is the console. */ | 2964 * On Mac, when started from Finder, stderr is the console. */ |
2950 if ( | 2965 if ( |
2951 # ifdef UNIX | 2966 # ifdef UNIX |
2952 # ifdef MACOS_X | 2967 # ifdef MACOS_X |
2953 (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0) | 2968 (isatty(2) && strcmp("/dev/console", ttyname(2)) != 0) |
2954 # else | 2969 # else |
2955 isatty(2) | 2970 isatty(2) |
2971 # endif | |
2972 # ifdef FEAT_GUI | |
2973 || | |
2974 # endif | |
2956 # endif | 2975 # endif |
2957 # ifdef FEAT_GUI | 2976 # ifdef FEAT_GUI |
2958 || | 2977 !(gui.in_use || gui.starting) |
2959 # endif | 2978 # endif |
2960 # endif | |
2961 # ifdef FEAT_GUI | |
2962 !(gui.in_use || gui.starting) | |
2963 # endif | |
2964 ) | 2979 ) |
2965 { | 2980 { |
2966 fprintf(stderr, "%s", str); | 2981 fprintf(stderr, "%s", str); |
2967 return; | 2982 return; |
2968 } | 2983 } |
2969 #endif | 2984 # endif |
2970 | 2985 |
2971 /* avoid a delay for a message that isn't there */ | 2986 /* avoid a delay for a message that isn't there */ |
2972 emsg_on_display = FALSE; | 2987 emsg_on_display = FALSE; |
2973 | 2988 |
2974 len = (int)STRLEN(str) + 1; | 2989 len = (int)STRLEN(str) + 1; |
2979 } | 2994 } |
2980 if (ga_grow(&error_ga, len) == OK) | 2995 if (ga_grow(&error_ga, len) == OK) |
2981 { | 2996 { |
2982 mch_memmove((char_u *)error_ga.ga_data + error_ga.ga_len, | 2997 mch_memmove((char_u *)error_ga.ga_data + error_ga.ga_len, |
2983 (char_u *)str, len); | 2998 (char_u *)str, len); |
2984 #ifdef UNIX | 2999 # ifdef UNIX |
2985 /* remove CR characters, they are displayed */ | 3000 /* remove CR characters, they are displayed */ |
2986 { | 3001 { |
2987 char_u *p; | 3002 char_u *p; |
2988 | 3003 |
2989 p = (char_u *)error_ga.ga_data + error_ga.ga_len; | 3004 p = (char_u *)error_ga.ga_data + error_ga.ga_len; |
2993 if (p == NULL) | 3008 if (p == NULL) |
2994 break; | 3009 break; |
2995 *p = ' '; | 3010 *p = ' '; |
2996 } | 3011 } |
2997 } | 3012 } |
2998 #endif | 3013 # endif |
2999 --len; /* don't count the NUL at the end */ | 3014 --len; /* don't count the NUL at the end */ |
3000 error_ga.ga_len += len; | 3015 error_ga.ga_len += len; |
3001 } | 3016 } |
3017 #endif | |
3002 } | 3018 } |
3003 | 3019 |
3004 /* | 3020 /* |
3005 * Give a message. To be used when the screen hasn't been initialized yet. | 3021 * Give a message. To be used when the screen hasn't been initialized yet. |
3006 * When there is no tty, collect messages until the GUI has started and they | 3022 * When there is no tty, collect messages until the GUI has started and they |
3007 * can be displayed in a message box. | 3023 * can be displayed in a message box. |
3008 */ | 3024 */ |
3009 void | 3025 void |
3010 mch_msg(char *str) | 3026 mch_msg(char *str) |
3011 { | 3027 { |
3012 #if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) | 3028 #if defined(WIN3264) && !defined(FEAT_GUI_MSWIN) |
3029 int len = STRLEN(str); | |
3030 DWORD nwrite = 0; | |
3031 DWORD mode; | |
3032 HANDLE h = GetStdHandle(STD_OUTPUT_HANDLE); | |
3033 | |
3034 | |
3035 if (GetConsoleMode(h, &mode) && enc_codepage >= 0 | |
3036 && (int)GetConsoleCP() != enc_codepage) | |
3037 { | |
3038 WCHAR *w = enc_to_utf16((char_u *)str, &len); | |
3039 | |
3040 WriteConsoleW(h, w, len, &nwrite, NULL); | |
3041 vim_free(w); | |
3042 } | |
3043 else | |
3044 { | |
3045 printf("%s", str); | |
3046 } | |
3047 #else | |
3048 # if (defined(UNIX) || defined(FEAT_GUI)) && !defined(ALWAYS_USE_GUI) | |
3013 /* On Unix use stdout if we have a tty. This allows "vim -h | more" and | 3049 /* On Unix use stdout if we have a tty. This allows "vim -h | more" and |
3014 * uses mch_errmsg() when started from the desktop. | 3050 * uses mch_errmsg() when started from the desktop. |
3015 * When not going to start the GUI also use stdout. | 3051 * When not going to start the GUI also use stdout. |
3016 * On Mac, when started from Finder, stderr is the console. */ | 3052 * On Mac, when started from Finder, stderr is the console. */ |
3017 if ( | 3053 if ( |
3033 printf("%s", str); | 3069 printf("%s", str); |
3034 return; | 3070 return; |
3035 } | 3071 } |
3036 # endif | 3072 # endif |
3037 mch_errmsg(str); | 3073 mch_errmsg(str); |
3074 #endif | |
3038 } | 3075 } |
3039 #endif /* USE_MCH_ERRMSG */ | 3076 #endif /* USE_MCH_ERRMSG */ |
3040 | 3077 |
3041 /* | 3078 /* |
3042 * Put a character on the screen at the current message position and advance | 3079 * Put a character on the screen at the current message position and advance |