aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c4
-rw-r--r--editors/diff.c21
-rw-r--r--editors/sed.c5
-rw-r--r--editors/vi.c59
4 files changed, 83 insertions, 6 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 685e8bed8..84ba125cd 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -728,7 +728,11 @@ static char *skip_spaces(char *p)
728 if (*p == '\\' && p[1] == '\n') { 728 if (*p == '\\' && p[1] == '\n') {
729 p++; 729 p++;
730 t_lineno++; 730 t_lineno++;
731#if !ENABLE_PLATFORM_MINGW32
731 } else if (*p != ' ' && *p != '\t') { 732 } else if (*p != ' ' && *p != '\t') {
733#else
734 } else if (*p != ' ' && *p != '\t' && *p != '\r') {
735#endif
732 break; 736 break;
733 } 737 }
734 p++; 738 p++;
diff --git a/editors/diff.c b/editors/diff.c
index 75229ad8c..0ae7e20b3 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -724,6 +724,10 @@ static int diffreg(char *file[2])
724 FILE *fp[2]; 724 FILE *fp[2];
725 bool binary = false, differ = false; 725 bool binary = false, differ = false;
726 int status = STATUS_SAME, i; 726 int status = STATUS_SAME, i;
727#if ENABLE_PLATFORM_MINGW32
728 char *tmpfile[2] = { NULL, NULL };
729 char *tmpdir;
730#endif
727 731
728 fp[0] = stdin; 732 fp[0] = stdin;
729 fp[1] = stdin; 733 fp[1] = stdin;
@@ -735,10 +739,19 @@ static int diffreg(char *file[2])
735 * When we meet non-seekable file, we must make a temp copy. 739 * When we meet non-seekable file, we must make a temp copy.
736 */ 740 */
737 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) { 741 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
742#if !ENABLE_PLATFORM_MINGW32
738 char name[] = "/tmp/difXXXXXX"; 743 char name[] = "/tmp/difXXXXXX";
739 int fd_tmp = xmkstemp(name); 744 int fd_tmp = xmkstemp(name);
740 745
741 unlink(name); 746 unlink(name);
747#else
748 int fd_tmp;
749
750 if (!(tmpdir=getenv("TMPDIR")))
751 goto out;
752 tmpfile[i] = xasprintf("%s/difXXXXXX", tmpdir);
753 fd_tmp = xmkstemp(tmpfile[i]);
754#endif
742 if (bb_copyfd_eof(fd, fd_tmp) < 0) 755 if (bb_copyfd_eof(fd, fd_tmp) < 0)
743 xfunc_die(); 756 xfunc_die();
744 if (fd != STDIN_FILENO) 757 if (fd != STDIN_FILENO)
@@ -781,6 +794,14 @@ static int diffreg(char *file[2])
781out: 794out:
782 fclose_if_not_stdin(fp[0]); 795 fclose_if_not_stdin(fp[0]);
783 fclose_if_not_stdin(fp[1]); 796 fclose_if_not_stdin(fp[1]);
797#if ENABLE_PLATFORM_MINGW32
798 for (i = 0; i < 2; i++) {
799 if (tmpfile[i]) {
800 unlink(tmpfile[i]);
801 free(tmpfile[i]);
802 }
803 }
804#endif
784 805
785 return status; 806 return status;
786} 807}
diff --git a/editors/sed.c b/editors/sed.c
index 637a6851b..86230ea42 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -1016,6 +1016,11 @@ static char *get_next_line(char *gets_char, char *last_puts_char)
1016 char c = temp[len-1]; 1016 char c = temp[len-1];
1017 if (c == '\n' || c == '\0') { 1017 if (c == '\n' || c == '\0') {
1018 temp[len-1] = '\0'; 1018 temp[len-1] = '\0';
1019#if ENABLE_PLATFORM_MINGW32
1020 if (c == '\n' && len > 1 && temp[len-2] == '\r') {
1021 temp[len-2] = '\0';
1022 }
1023#endif
1019 gc = c; 1024 gc = c;
1020 if (c == '\0') { 1025 if (c == '\0') {
1021 int ch = fgetc(fp); 1026 int ch = fgetc(fp);
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