aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--util-linux/more.c54
-rw-r--r--util-linux/script.c20
-rw-r--r--util-linux/scriptreplay.c8
3 files changed, 35 insertions, 47 deletions
diff --git a/util-linux/more.c b/util-linux/more.c
index b0f20c441..9ac4dd8e3 100644
--- a/util-linux/more.c
+++ b/util-linux/more.c
@@ -16,7 +16,7 @@
16 16
17#include "libbb.h" 17#include "libbb.h"
18 18
19#if ENABLE_FEATURE_USE_TERMIOS 19/* Support for FEATURE_USE_TERMIOS */
20 20
21struct globals { 21struct globals {
22 int cin_fileno; 22 int cin_fileno;
@@ -29,7 +29,9 @@ struct globals {
29#define new_settings (G.new_settings ) 29#define new_settings (G.new_settings )
30#define cin_fileno (G.cin_fileno ) 30#define cin_fileno (G.cin_fileno )
31 31
32#define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp) 32#define setTermSettings(fd, argp) do { \
33 if (ENABLE_FEATURE_USE_TERMIOS) tcsetattr(fd, TCSANOW, argp); \
34 } while(0)
33#define getTermSettings(fd, argp) tcgetattr(fd, argp) 35#define getTermSettings(fd, argp) tcgetattr(fd, argp)
34 36
35static void gotsig(int sig UNUSED_PARAM) 37static void gotsig(int sig UNUSED_PARAM)
@@ -39,11 +41,6 @@ static void gotsig(int sig UNUSED_PARAM)
39 exit(EXIT_FAILURE); 41 exit(EXIT_FAILURE);
40} 42}
41 43
42#else /* !FEATURE_USE_TERMIOS */
43#define INIT_G() ((void)0)
44#define setTermSettings(fd, argp) ((void)0)
45#endif /* FEATURE_USE_TERMIOS */
46
47#define CONVERTED_TAB_SIZE 8 44#define CONVERTED_TAB_SIZE 8
48 45
49int more_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; 46int more_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
@@ -72,21 +69,21 @@ int more_main(int argc UNUSED_PARAM, char **argv)
72 if (!cin) 69 if (!cin)
73 return bb_cat(argv); 70 return bb_cat(argv);
74 71
75#if ENABLE_FEATURE_USE_TERMIOS 72 if (ENABLE_FEATURE_USE_TERMIOS) {
76 cin_fileno = fileno(cin); 73 cin_fileno = fileno(cin);
77 getTermSettings(cin_fileno, &initial_settings); 74 getTermSettings(cin_fileno, &initial_settings);
78 new_settings = initial_settings; 75 new_settings = initial_settings;
79 new_settings.c_lflag &= ~ICANON; 76 new_settings.c_lflag &= ~ICANON;
80 new_settings.c_lflag &= ~ECHO; 77 new_settings.c_lflag &= ~ECHO;
81 new_settings.c_cc[VMIN] = 1; 78 new_settings.c_cc[VMIN] = 1;
82 new_settings.c_cc[VTIME] = 0; 79 new_settings.c_cc[VTIME] = 0;
83 setTermSettings(cin_fileno, &new_settings); 80 setTermSettings(cin_fileno, &new_settings);
84 bb_signals(0 81 bb_signals(0
85 + (1 << SIGINT) 82 + (1 << SIGINT)
86 + (1 << SIGQUIT) 83 + (1 << SIGQUIT)
87 + (1 << SIGTERM) 84 + (1 << SIGTERM)
88 , gotsig); 85 , gotsig);
89#endif 86 }
90 87
91 do { 88 do {
92 file = stdin; 89 file = stdin;
@@ -126,9 +123,8 @@ int more_main(int argc UNUSED_PARAM, char **argv)
126 for (;;) { 123 for (;;) {
127 input = getc(cin); 124 input = getc(cin);
128 input = tolower(input); 125 input = tolower(input);
129#if !ENABLE_FEATURE_USE_TERMIOS 126 if (!ENABLE_FEATURE_USE_TERMIOS)
130 printf("\033[A"); /* up cursor */ 127 printf("\033[A"); /* cursor up */
131#endif
132 /* Erase the last message */ 128 /* Erase the last message */
133 printf("\r%*s\r", len, ""); 129 printf("\r%*s\r", len, "");
134 130
@@ -150,10 +146,10 @@ int more_main(int argc UNUSED_PARAM, char **argv)
150 146
151 /* The user may have resized the terminal. 147 /* The user may have resized the terminal.
152 * Re-read the dimensions. */ 148 * Re-read the dimensions. */
153#if ENABLE_FEATURE_USE_TERMIOS 149 if (ENABLE_FEATURE_USE_TERMIOS) {
154 get_terminal_width_height(cin_fileno, &terminal_width, &terminal_height); 150 get_terminal_width_height(cin_fileno, &terminal_width, &terminal_height);
155 terminal_height -= 1; 151 terminal_height -= 1;
156#endif 152 }
157 } 153 }
158 154
159 /* Crudely convert tabs into spaces, which are 155 /* Crudely convert tabs into spaces, which are
diff --git a/util-linux/script.c b/util-linux/script.c
index d16a2914a..4e0deb4ef 100644
--- a/util-linux/script.c
+++ b/util-linux/script.c
@@ -33,24 +33,20 @@ int script_main(int argc UNUSED_PARAM, char **argv)
33 OPT_c = (1 << 1), 33 OPT_c = (1 << 1),
34 OPT_f = (1 << 2), 34 OPT_f = (1 << 2),
35 OPT_q = (1 << 3), 35 OPT_q = (1 << 3),
36#if ENABLE_SCRIPTREPLAY
37 OPT_t = (1 << 4), 36 OPT_t = (1 << 4),
38#endif
39 }; 37 };
40 38
41#if ENABLE_GETOPT_LONG
42 static const char getopt_longopts[] ALIGN1 = 39 static const char getopt_longopts[] ALIGN1 =
43 "append\0" No_argument "a" 40 "append\0" No_argument "a"
44 "command\0" Required_argument "c" 41 "command\0" Required_argument "c"
45 "flush\0" No_argument "f" 42 "flush\0" No_argument "f"
46 "quiet\0" No_argument "q" 43 "quiet\0" No_argument "q"
47# if ENABLE_SCRIPTREPLAY 44 IF_SCRIPTREPLAY("timing\0" No_argument "t")
48 "timing\0" No_argument "t"
49# endif
50 ; 45 ;
51 46
52 applet_long_options = getopt_longopts; 47 if (ENABLE_GETOPT_LONG)
53#endif 48 applet_long_options = getopt_longopts;
49
54 opt_complementary = "?1"; /* max one arg */ 50 opt_complementary = "?1"; /* max one arg */
55 opt = getopt32(argv, "ac:fq" IF_SCRIPTREPLAY("t") , &shell_arg); 51 opt = getopt32(argv, "ac:fq" IF_SCRIPTREPLAY("t") , &shell_arg);
56 //argc -= optind; 52 //argc -= optind;
@@ -101,9 +97,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
101#define buf bb_common_bufsiz1 97#define buf bb_common_bufsiz1
102 struct pollfd pfd[2]; 98 struct pollfd pfd[2];
103 int outfd, count, loop; 99 int outfd, count, loop;
104#if ENABLE_SCRIPTREPLAY 100 double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0;
105 double oldtime = time(NULL);
106#endif
107 smallint fd_count = 2; 101 smallint fd_count = 2;
108 102
109 outfd = xopen(fname, mode); 103 outfd = xopen(fname, mode);
@@ -132,8 +126,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
132 goto restore; 126 goto restore;
133 } 127 }
134 if (count > 0) { 128 if (count > 0) {
135#if ENABLE_SCRIPTREPLAY 129 if (ENABLE_SCRIPTREPLAY && (opt & OPT_t)) {
136 if (opt & OPT_t) {
137 struct timeval tv; 130 struct timeval tv;
138 double newtime; 131 double newtime;
139 132
@@ -142,7 +135,6 @@ int script_main(int argc UNUSED_PARAM, char **argv)
142 fprintf(stderr, "%f %u\n", newtime - oldtime, count); 135 fprintf(stderr, "%f %u\n", newtime - oldtime, count);
143 oldtime = newtime; 136 oldtime = newtime;
144 } 137 }
145#endif
146 full_write(STDOUT_FILENO, buf, count); 138 full_write(STDOUT_FILENO, buf, count);
147 full_write(outfd, buf, count); 139 full_write(outfd, buf, count);
148 if (opt & OPT_f) { 140 if (opt & OPT_f) {
diff --git a/util-linux/scriptreplay.c b/util-linux/scriptreplay.c
index 038dbdfe1..6474d38e8 100644
--- a/util-linux/scriptreplay.c
+++ b/util-linux/scriptreplay.c
@@ -30,9 +30,9 @@ int scriptreplay_main(int argc UNUSED_PARAM, char **argv)
30 usleep(delay * factor); 30 usleep(delay * factor);
31 bb_copyfd_exact_size(fd, STDOUT_FILENO, count); 31 bb_copyfd_exact_size(fd, STDOUT_FILENO, count);
32 } 32 }
33#if ENABLE_FEATURE_CLEAN_UP 33 if (ENABLE_FEATURE_CLEAN_UP) {
34 close(fd); 34 close(fd);
35 fclose(tfp); 35 fclose(tfp);
36#endif 36 }
37 return EXIT_SUCCESS; 37 return EXIT_SUCCESS;
38} 38}