aboutsummaryrefslogtreecommitdiff
path: root/util-linux
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--util-linux/more.c19
-rw-r--r--util-linux/rev.c10
2 files changed, 26 insertions, 3 deletions
diff --git a/util-linux/more.c b/util-linux/more.c
index 934b30f8a..d04c17f90 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -35,6 +35,9 @@
35//usage:#define more_example_usage 35//usage:#define more_example_usage
36//usage: "$ dmesg | more\n" 36//usage: "$ dmesg | more\n"
37 37
38#if ENABLE_PLATFORM_MINGW32
39#include <conio.h>
40#endif
38#include "libbb.h" 41#include "libbb.h"
39#include "common_bufsiz.h" 42#include "common_bufsiz.h"
40 43
@@ -100,9 +103,13 @@ int more_main(int argc UNUSED_PARAM, char **argv)
100 * is not a tty and turns into cat. This makes sense. */ 103 * is not a tty and turns into cat. This makes sense. */
101 if (!isatty(STDOUT_FILENO)) 104 if (!isatty(STDOUT_FILENO))
102 return bb_cat(argv); 105 return bb_cat(argv);
106#if !ENABLE_PLATFORM_MINGW32
103 cin = fopen_for_read(CURRENT_TTY); 107 cin = fopen_for_read(CURRENT_TTY);
104 if (!cin) 108 if (!cin)
105 return bb_cat(argv); 109 return bb_cat(argv);
110#else
111 cin = stdin;
112#endif
106 113
107 if (ENABLE_FEATURE_USE_TERMIOS) { 114 if (ENABLE_FEATURE_USE_TERMIOS) {
108 cin_fileno = fileno(cin); 115 cin_fileno = fileno(cin);
@@ -158,7 +165,11 @@ int more_main(int argc UNUSED_PARAM, char **argv)
158 * to get input from the user. 165 * to get input from the user.
159 */ 166 */
160 for (;;) { 167 for (;;) {
168#if !ENABLE_PLATFORM_MINGW32
161 input = getc(cin); 169 input = getc(cin);
170#else
171 input = _getch();
172#endif
162 input = tolower(input); 173 input = tolower(input);
163 if (!ENABLE_FEATURE_USE_TERMIOS) 174 if (!ENABLE_FEATURE_USE_TERMIOS)
164 printf("\033[A"); /* cursor up */ 175 printf("\033[A"); /* cursor up */
@@ -172,6 +183,10 @@ int more_main(int argc UNUSED_PARAM, char **argv)
172 * commands, else we show help msg. */ 183 * commands, else we show help msg. */
173 if (input == ' ' || input == '\n' || input == 'q' || input == 'r') 184 if (input == ' ' || input == '\n' || input == 'q' || input == 'r')
174 break; 185 break;
186#if ENABLE_PLATFORM_MINGW32
187 if (input == '\r')
188 break;
189#endif
175 len = printf("(Enter:next line Space:next page Q:quit R:show the rest)"); 190 len = printf("(Enter:next line Space:next page Q:quit R:show the rest)");
176 } 191 }
177 len = 0; 192 len = 0;
@@ -212,6 +227,10 @@ int more_main(int argc UNUSED_PARAM, char **argv)
212 * will move us to a new line. */ 227 * will move us to a new line. */
213 if (++lines >= terminal_height || input == '\n') 228 if (++lines >= terminal_height || input == '\n')
214 please_display_more_prompt = 1; 229 please_display_more_prompt = 1;
230#if ENABLE_PLATFORM_MINGW32
231 if (input == '\r')
232 please_display_more_prompt = 1;
233#endif
215 len = 0; 234 len = 0;
216 } 235 }
217 if (c != '\n' && wrap) { 236 if (c != '\n' && wrap) {
diff --git a/util-linux/rev.c b/util-linux/rev.c
index c22505314..d34838a35 100644
--- a/util-linux/rev.c
+++ b/util-linux/rev.c
@@ -31,7 +31,7 @@
31#endif 31#endif
32 32
33/* In-place invert */ 33/* In-place invert */
34static void strrev(CHAR_T *s, int len) 34static void bb_strrev(CHAR_T *s, int len)
35{ 35{
36 int i; 36 int i;
37 37
@@ -39,6 +39,10 @@ static void strrev(CHAR_T *s, int len)
39 len--; 39 len--;
40 if (len != 0 && s[len] == '\n') 40 if (len != 0 && s[len] == '\n')
41 len--; 41 len--;
42#if ENABLE_PLATFORM_MINGW32
43 if (len != 0 && s[len] == '\r')
44 len--;
45#endif
42 } 46 }
43 47
44 for (i = 0; i < len; i++, len--) { 48 for (i = 0; i < len; i++, len--) {
@@ -99,14 +103,14 @@ int rev_main(int argc UNUSED_PARAM, char **argv)
99 /* Convert to wchar_t (might error out!) */ 103 /* Convert to wchar_t (might error out!) */
100 int len = mbstowcs(tmp, buf, bufsize); 104 int len = mbstowcs(tmp, buf, bufsize);
101 if (len >= 0) { 105 if (len >= 0) {
102 strrev(tmp, len); 106 bb_strrev(tmp, len);
103 /* Convert back to char */ 107 /* Convert back to char */
104 wcstombs(buf, tmp, bufsize); 108 wcstombs(buf, tmp, bufsize);
105 } 109 }
106 free(tmp); 110 free(tmp);
107 } 111 }
108#else 112#else
109 strrev(buf, strlen(buf)); 113 bb_strrev(buf, strlen(buf));
110#endif 114#endif
111 fputs(buf, stdout); 115 fputs(buf, stdout);
112 } 116 }