aboutsummaryrefslogtreecommitdiff
path: root/editors/vi.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--editors/vi.c59
1 files changed, 53 insertions, 6 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 38a4692fd..b81f2b92d 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2801,6 +2801,14 @@ static void catch_sig(int sig)
2801 2801
2802static int mysleep(int hund) // sleep for 'hund' 1/100 seconds or stdin ready 2802static int mysleep(int hund) // sleep for 'hund' 1/100 seconds or stdin ready
2803{ 2803{
2804#if ENABLE_PLATFORM_MINGW32
2805 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
2806 DWORD ret;
2807
2808 fflush(stdout);
2809 ret = WaitForSingleObject(h, hund*10);
2810 return ret != WAIT_TIMEOUT;
2811#else
2804 struct pollfd pfd[1]; 2812 struct pollfd pfd[1];
2805 2813
2806 if (hund != 0) 2814 if (hund != 0)
@@ -2809,6 +2817,7 @@ static int mysleep(int hund) // sleep for 'hund' 1/100 seconds or stdin ready
2809 pfd[0].fd = STDIN_FILENO; 2817 pfd[0].fd = STDIN_FILENO;
2810 pfd[0].events = POLLIN; 2818 pfd[0].events = POLLIN;
2811 return safe_poll(pfd, 1, hund*10) > 0; 2819 return safe_poll(pfd, 1, hund*10) > 0;
2820#endif
2812} 2821}
2813 2822
2814//----- IO Routines -------------------------------------------- 2823//----- IO Routines --------------------------------------------
@@ -2930,6 +2939,9 @@ static int file_insert(const char *fn, char *p, int initial)
2930 status_line_bold("'%s' is not a regular file", fn); 2939 status_line_bold("'%s' is not a regular file", fn);
2931 goto fi; 2940 goto fi;
2932 } 2941 }
2942#if ENABLE_PLATFORM_MINGW32
2943 _setmode(fd, _O_TEXT);
2944#endif
2933 size = (statbuf.st_size < INT_MAX ? (int)statbuf.st_size : INT_MAX); 2945 size = (statbuf.st_size < INT_MAX ? (int)statbuf.st_size : INT_MAX);
2934 p += text_hole_make(p, size); 2946 p += text_hole_make(p, size);
2935 cnt = full_read(fd, p, size); 2947 cnt = full_read(fd, p, size);
@@ -2938,8 +2950,25 @@ static int file_insert(const char *fn, char *p, int initial)
2938 p = text_hole_delete(p, p + size - 1, NO_UNDO); // un-do buffer insert 2950 p = text_hole_delete(p, p + size - 1, NO_UNDO); // un-do buffer insert
2939 } else if (cnt < size) { 2951 } else if (cnt < size) {
2940 // There was a partial read, shrink unused space 2952 // There was a partial read, shrink unused space
2953#if ENABLE_PLATFORM_MINGW32
2954 int i, newline;
2955
2956 newline = 0;
2957 for ( i=0; i<cnt; ++i ) {
2958 if ( p[i] == '\n' ) {
2959 ++newline;
2960 }
2961 }
2962#endif
2941 p = text_hole_delete(p + cnt, p + size - 1, NO_UNDO); 2963 p = text_hole_delete(p + cnt, p + size - 1, NO_UNDO);
2964#if ENABLE_PLATFORM_MINGW32
2965 // on WIN32 a partial read might just mean CRs have been removed
2966 if ( cnt+newline != size ) {
2967 status_line_bold("can't read '%s'", fn);
2968 }
2969#else
2942 status_line_bold("can't read '%s'", fn); 2970 status_line_bold("can't read '%s'", fn);
2971#endif
2943 } 2972 }
2944 fi: 2973 fi:
2945 close(fd); 2974 close(fd);
@@ -2961,6 +2990,9 @@ static int file_insert(const char *fn, char *p, int initial)
2961static int file_write(char *fn, char *first, char *last) 2990static int file_write(char *fn, char *first, char *last)
2962{ 2991{
2963 int fd, cnt, charcnt; 2992 int fd, cnt, charcnt;
2993#if ENABLE_PLATFORM_MINGW32
2994 int i, newline;
2995#endif
2964 2996
2965 if (fn == 0) { 2997 if (fn == 0) {
2966 status_line_bold("No current filename"); 2998 status_line_bold("No current filename");
@@ -2974,8 +3006,23 @@ static int file_write(char *fn, char *first, char *last)
2974 if (fd < 0) 3006 if (fd < 0)
2975 return -1; 3007 return -1;
2976 cnt = last - first + 1; 3008 cnt = last - first + 1;
3009#if ENABLE_PLATFORM_MINGW32
3010 /* write file in text mode; this makes it bigger so adjust
3011 * the truncation to match
3012 */
3013 _setmode(fd, _O_TEXT);
3014 newline = 0;
3015 for ( i=0; i<cnt; ++i ) {
3016 if ( first[i] == '\n' ) {
3017 ++newline;
3018 }
3019 }
3020 charcnt = full_write(fd, first, cnt);
3021 ftruncate(fd, charcnt+newline);
3022#else
2977 charcnt = full_write(fd, first, cnt); 3023 charcnt = full_write(fd, first, cnt);
2978 ftruncate(fd, charcnt); 3024 ftruncate(fd, charcnt);
3025#endif
2979 if (charcnt == cnt) { 3026 if (charcnt == cnt) {
2980 // good write 3027 // good write
2981 //modified_count = FALSE; 3028 //modified_count = FALSE;
@@ -3026,7 +3073,12 @@ static void go_bottom_and_clear_to_eol(void)
3026//----- Erase from cursor to end of screen ----------------------- 3073//----- Erase from cursor to end of screen -----------------------
3027static void clear_to_eos(void) 3074static void clear_to_eos(void)
3028{ 3075{
3076#if !ENABLE_PLATFORM_MINGW32
3029 write1(ESC_CLEAR2EOS); 3077 write1(ESC_CLEAR2EOS);
3078#else
3079 /* in practice clear_to_eos() always clears the entire screen */
3080 reset_screen();
3081#endif
3030} 3082}
3031 3083
3032//----- Start standout mode ------------------------------------ 3084//----- Start standout mode ------------------------------------
@@ -3572,12 +3624,7 @@ static void do_cmd(int c)
3572 break; 3624 break;
3573 case 12: // ctrl-L force redraw whole screen 3625 case 12: // ctrl-L force redraw whole screen
3574 case 18: // ctrl-R force redraw 3626 case 18: // ctrl-R force redraw
3575 place_cursor(0, 0); 3627 redraw(TRUE); // this will redraw the entire display
3576 clear_to_eos();
3577 //mysleep(10); // why???
3578 screen_erase(); // erase the internal screen buffer
3579 last_status_cksum = 0; // force status update
3580 refresh(TRUE); // this will redraw the entire display
3581 break; 3628 break;
3582 case 13: // Carriage Return ^M 3629 case 13: // Carriage Return ^M
3583 case '+': // +- goto next line 3630 case '+': // +- goto next line