aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c6
-rw-r--r--editors/diff.c21
-rw-r--r--editors/sed.c5
-rw-r--r--editors/vi.c59
4 files changed, 84 insertions, 7 deletions
diff --git a/editors/awk.c b/editors/awk.c
index cc17ad438..56688d72c 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -727,7 +727,11 @@ static char *skip_spaces(char *p)
727 if (*p == '\\' && p[1] == '\n') { 727 if (*p == '\\' && p[1] == '\n') {
728 p++; 728 p++;
729 t_lineno++; 729 t_lineno++;
730#if !ENABLE_PLATFORM_MINGW32
730 } else if (*p != ' ' && *p != '\t') { 731 } else if (*p != ' ' && *p != '\t') {
732#else
733 } else if (*p != ' ' && *p != '\t' && *p != '\r') {
734#endif
731 break; 735 break;
732 } 736 }
733 p++; 737 p++;
@@ -2073,7 +2077,7 @@ static int fmt_num(char *b, int size, const char *format, double n, int int_as_i
2073 const char *s = format; 2077 const char *s = format;
2074 2078
2075 if (int_as_int && n == (long long)n) { 2079 if (int_as_int && n == (long long)n) {
2076 r = snprintf(b, size, "%lld", (long long)n); 2080 r = snprintf(b, size, "%"LL_FMT"d", (long long)n);
2077 } else { 2081 } else {
2078 do { c = *s; } while (c && *++s); 2082 do { c = *s; } while (c && *++s);
2079 if (strchr("diouxX", c)) { 2083 if (strchr("diouxX", c)) {
diff --git a/editors/diff.c b/editors/diff.c
index 03c13908e..62f558944 100644
--- a/editors/diff.c
+++ b/editors/diff.c
@@ -711,6 +711,10 @@ static int diffreg(char *file[2])
711 FILE *fp[2]; 711 FILE *fp[2];
712 bool binary = false, differ = false; 712 bool binary = false, differ = false;
713 int status = STATUS_SAME, i; 713 int status = STATUS_SAME, i;
714#if ENABLE_PLATFORM_MINGW32
715 char *tmpfile[2] = { NULL, NULL };
716 char *tmpdir;
717#endif
714 718
715 fp[0] = stdin; 719 fp[0] = stdin;
716 fp[1] = stdin; 720 fp[1] = stdin;
@@ -732,10 +736,19 @@ static int diffreg(char *file[2])
732 * When we meet non-seekable file, we must make a temp copy. 736 * When we meet non-seekable file, we must make a temp copy.
733 */ 737 */
734 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) { 738 if (lseek(fd, 0, SEEK_SET) == -1 && errno == ESPIPE) {
739#if !ENABLE_PLATFORM_MINGW32
735 char name[] = "/tmp/difXXXXXX"; 740 char name[] = "/tmp/difXXXXXX";
736 int fd_tmp = xmkstemp(name); 741 int fd_tmp = xmkstemp(name);
737 742
738 unlink(name); 743 unlink(name);
744#else
745 int fd_tmp;
746
747 if (!(tmpdir=getenv("TMPDIR")))
748 goto out;
749 tmpfile[i] = xasprintf("%s/difXXXXXX", tmpdir);
750 fd_tmp = xmkstemp(tmpfile[i]);
751#endif
739 if (bb_copyfd_eof(fd, fd_tmp) < 0) 752 if (bb_copyfd_eof(fd, fd_tmp) < 0)
740 xfunc_die(); 753 xfunc_die();
741 if (fd != STDIN_FILENO) 754 if (fd != STDIN_FILENO)
@@ -778,6 +791,14 @@ static int diffreg(char *file[2])
778out: 791out:
779 fclose_if_not_stdin(fp[0]); 792 fclose_if_not_stdin(fp[0]);
780 fclose_if_not_stdin(fp[1]); 793 fclose_if_not_stdin(fp[1]);
794#if ENABLE_PLATFORM_MINGW32
795 for (i = 0; i < 2; i++) {
796 if (tmpfile[i]) {
797 unlink(tmpfile[i]);
798 free(tmpfile[i]);
799 }
800 }
801#endif
781 802
782 return status; 803 return status;
783} 804}
diff --git a/editors/sed.c b/editors/sed.c
index bec20040a..e10078b7c 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 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