aboutsummaryrefslogtreecommitdiff
path: root/editors/vi.c
diff options
context:
space:
mode:
Diffstat (limited to 'editors/vi.c')
-rw-r--r--editors/vi.c59
1 files changed, 53 insertions, 6 deletions
diff --git a/editors/vi.c b/editors/vi.c
index 116022c93..91e954a87 100644
--- a/editors/vi.c
+++ b/editors/vi.c
@@ -2800,6 +2800,14 @@ static void catch_sig(int sig)
2800 2800
2801static int mysleep(int hund) // sleep for 'hund' 1/100 seconds or stdin ready 2801static int mysleep(int hund) // sleep for 'hund' 1/100 seconds or stdin ready
2802{ 2802{
2803#if ENABLE_PLATFORM_MINGW32
2804 HANDLE h = GetStdHandle(STD_INPUT_HANDLE);
2805 DWORD ret;
2806
2807 fflush(stdout);
2808 ret = WaitForSingleObject(h, hund*10);
2809 return ret != WAIT_TIMEOUT;
2810#else
2803 struct pollfd pfd[1]; 2811 struct pollfd pfd[1];
2804 2812
2805 if (hund != 0) 2813 if (hund != 0)
@@ -2808,6 +2816,7 @@ static int mysleep(int hund) // sleep for 'hund' 1/100 seconds or stdin ready
2808 pfd[0].fd = STDIN_FILENO; 2816 pfd[0].fd = STDIN_FILENO;
2809 pfd[0].events = POLLIN; 2817 pfd[0].events = POLLIN;
2810 return safe_poll(pfd, 1, hund*10) > 0; 2818 return safe_poll(pfd, 1, hund*10) > 0;
2819#endif
2811} 2820}
2812 2821
2813//----- IO Routines -------------------------------------------- 2822//----- IO Routines --------------------------------------------
@@ -2936,6 +2945,9 @@ static int file_insert(const char *fn, char *p, int initial)
2936 status_line_bold("'%s' is not a regular file", fn); 2945 status_line_bold("'%s' is not a regular file", fn);
2937 goto fi; 2946 goto fi;
2938 } 2947 }
2948#if ENABLE_PLATFORM_MINGW32
2949 _setmode(fd, _O_TEXT);
2950#endif
2939 size = (statbuf.st_size < INT_MAX ? (int)statbuf.st_size : INT_MAX); 2951 size = (statbuf.st_size < INT_MAX ? (int)statbuf.st_size : INT_MAX);
2940 p += text_hole_make(p, size); 2952 p += text_hole_make(p, size);
2941 cnt = full_read(fd, p, size); 2953 cnt = full_read(fd, p, size);
@@ -2944,8 +2956,25 @@ static int file_insert(const char *fn, char *p, int initial)
2944 p = text_hole_delete(p, p + size - 1, NO_UNDO); // un-do buffer insert 2956 p = text_hole_delete(p, p + size - 1, NO_UNDO); // un-do buffer insert
2945 } else if (cnt < size) { 2957 } else if (cnt < size) {
2946 // There was a partial read, shrink unused space 2958 // There was a partial read, shrink unused space
2959#if ENABLE_PLATFORM_MINGW32
2960 int i, newline;
2961
2962 newline = 0;
2963 for ( i=0; i<cnt; ++i ) {
2964 if ( p[i] == '\n' ) {
2965 ++newline;
2966 }
2967 }
2968#endif
2947 p = text_hole_delete(p + cnt, p + size - 1, NO_UNDO); 2969 p = text_hole_delete(p + cnt, p + size - 1, NO_UNDO);
2970#if ENABLE_PLATFORM_MINGW32
2971 // on WIN32 a partial read might just mean CRs have been removed
2972 if ( cnt+newline != size ) {
2973 status_line_bold("can't read '%s'", fn);
2974 }
2975#else
2948 status_line_bold("can't read '%s'", fn); 2976 status_line_bold("can't read '%s'", fn);
2977#endif
2949 } 2978 }
2950 fi: 2979 fi:
2951 close(fd); 2980 close(fd);
@@ -2967,6 +2996,9 @@ static int file_insert(const char *fn, char *p, int initial)
2967static int file_write(char *fn, char *first, char *last) 2996static int file_write(char *fn, char *first, char *last)
2968{ 2997{
2969 int fd, cnt, charcnt; 2998 int fd, cnt, charcnt;
2999#if ENABLE_PLATFORM_MINGW32
3000 int i, newline;
3001#endif
2970 3002
2971 if (fn == 0) { 3003 if (fn == 0) {
2972 status_line_bold("No current filename"); 3004 status_line_bold("No current filename");
@@ -2980,8 +3012,23 @@ static int file_write(char *fn, char *first, char *last)
2980 if (fd < 0) 3012 if (fd < 0)
2981 return -1; 3013 return -1;
2982 cnt = last - first + 1; 3014 cnt = last - first + 1;
3015#if ENABLE_PLATFORM_MINGW32
3016 /* write file in text mode; this makes it bigger so adjust
3017 * the truncation to match
3018 */
3019 _setmode(fd, _O_TEXT);
3020 newline = 0;
3021 for ( i=0; i<cnt; ++i ) {
3022 if ( first[i] == '\n' ) {
3023 ++newline;
3024 }
3025 }
3026 charcnt = full_write(fd, first, cnt);
3027 ftruncate(fd, charcnt+newline);
3028#else
2983 charcnt = full_write(fd, first, cnt); 3029 charcnt = full_write(fd, first, cnt);
2984 ftruncate(fd, charcnt); 3030 ftruncate(fd, charcnt);
3031#endif
2985 if (charcnt == cnt) { 3032 if (charcnt == cnt) {
2986 // good write 3033 // good write
2987 //modified_count = FALSE; 3034 //modified_count = FALSE;
@@ -3032,7 +3079,12 @@ static void go_bottom_and_clear_to_eol(void)
3032//----- Erase from cursor to end of screen ----------------------- 3079//----- Erase from cursor to end of screen -----------------------
3033static void clear_to_eos(void) 3080static void clear_to_eos(void)
3034{ 3081{
3082#if !ENABLE_PLATFORM_MINGW32
3035 write1(ESC_CLEAR2EOS); 3083 write1(ESC_CLEAR2EOS);
3084#else
3085 /* in practice clear_to_eos() always clears the entire screen */
3086 reset_screen();
3087#endif
3036} 3088}
3037 3089
3038//----- Start standout mode ------------------------------------ 3090//----- Start standout mode ------------------------------------
@@ -3578,12 +3630,7 @@ static void do_cmd(int c)
3578 break; 3630 break;
3579 case 12: // ctrl-L force redraw whole screen 3631 case 12: // ctrl-L force redraw whole screen
3580 case 18: // ctrl-R force redraw 3632 case 18: // ctrl-R force redraw
3581 place_cursor(0, 0); 3633 redraw(TRUE); // this will redraw the entire display
3582 clear_to_eos();
3583 //mysleep(10); // why???
3584 screen_erase(); // erase the internal screen buffer
3585 last_status_cksum = 0; // force status update
3586 refresh(TRUE); // this will redraw the entire display
3587 break; 3634 break;
3588 case 13: // Carriage Return ^M 3635 case 13: // Carriage Return ^M
3589 case '+': // +- goto next line 3636 case '+': // +- goto next line