*: reduce #ifdef forest
Remove unnecessary #if statements from the "more", "script", and "scriptreplay" commands. Bloatcheck says 0 bytes changed. Signed-off-by: Rob Landley <rob@landley.net> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
d5f1b1bbe0
commit
53f1791212
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#include "libbb.h"
|
#include "libbb.h"
|
||||||
|
|
||||||
#if ENABLE_FEATURE_USE_TERMIOS
|
/* Support for FEATURE_USE_TERMIOS */
|
||||||
|
|
||||||
struct globals {
|
struct globals {
|
||||||
int cin_fileno;
|
int cin_fileno;
|
||||||
@ -29,7 +29,9 @@ struct globals {
|
|||||||
#define new_settings (G.new_settings )
|
#define new_settings (G.new_settings )
|
||||||
#define cin_fileno (G.cin_fileno )
|
#define cin_fileno (G.cin_fileno )
|
||||||
|
|
||||||
#define setTermSettings(fd, argp) tcsetattr(fd, TCSANOW, argp)
|
#define setTermSettings(fd, argp) do { \
|
||||||
|
if (ENABLE_FEATURE_USE_TERMIOS) tcsetattr(fd, TCSANOW, argp); \
|
||||||
|
} while(0)
|
||||||
#define getTermSettings(fd, argp) tcgetattr(fd, argp)
|
#define getTermSettings(fd, argp) tcgetattr(fd, argp)
|
||||||
|
|
||||||
static void gotsig(int sig UNUSED_PARAM)
|
static void gotsig(int sig UNUSED_PARAM)
|
||||||
@ -39,11 +41,6 @@ static void gotsig(int sig UNUSED_PARAM)
|
|||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
#else /* !FEATURE_USE_TERMIOS */
|
|
||||||
#define INIT_G() ((void)0)
|
|
||||||
#define setTermSettings(fd, argp) ((void)0)
|
|
||||||
#endif /* FEATURE_USE_TERMIOS */
|
|
||||||
|
|
||||||
#define CONVERTED_TAB_SIZE 8
|
#define CONVERTED_TAB_SIZE 8
|
||||||
|
|
||||||
int more_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
int more_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
|
||||||
@ -72,21 +69,21 @@ int more_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
if (!cin)
|
if (!cin)
|
||||||
return bb_cat(argv);
|
return bb_cat(argv);
|
||||||
|
|
||||||
#if ENABLE_FEATURE_USE_TERMIOS
|
if (ENABLE_FEATURE_USE_TERMIOS) {
|
||||||
cin_fileno = fileno(cin);
|
cin_fileno = fileno(cin);
|
||||||
getTermSettings(cin_fileno, &initial_settings);
|
getTermSettings(cin_fileno, &initial_settings);
|
||||||
new_settings = initial_settings;
|
new_settings = initial_settings;
|
||||||
new_settings.c_lflag &= ~ICANON;
|
new_settings.c_lflag &= ~ICANON;
|
||||||
new_settings.c_lflag &= ~ECHO;
|
new_settings.c_lflag &= ~ECHO;
|
||||||
new_settings.c_cc[VMIN] = 1;
|
new_settings.c_cc[VMIN] = 1;
|
||||||
new_settings.c_cc[VTIME] = 0;
|
new_settings.c_cc[VTIME] = 0;
|
||||||
setTermSettings(cin_fileno, &new_settings);
|
setTermSettings(cin_fileno, &new_settings);
|
||||||
bb_signals(0
|
bb_signals(0
|
||||||
+ (1 << SIGINT)
|
+ (1 << SIGINT)
|
||||||
+ (1 << SIGQUIT)
|
+ (1 << SIGQUIT)
|
||||||
+ (1 << SIGTERM)
|
+ (1 << SIGTERM)
|
||||||
, gotsig);
|
, gotsig);
|
||||||
#endif
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
file = stdin;
|
file = stdin;
|
||||||
@ -126,9 +123,8 @@ int more_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
for (;;) {
|
for (;;) {
|
||||||
input = getc(cin);
|
input = getc(cin);
|
||||||
input = tolower(input);
|
input = tolower(input);
|
||||||
#if !ENABLE_FEATURE_USE_TERMIOS
|
if (!ENABLE_FEATURE_USE_TERMIOS)
|
||||||
printf("\033[A"); /* up cursor */
|
printf("\033[A"); /* cursor up */
|
||||||
#endif
|
|
||||||
/* Erase the last message */
|
/* Erase the last message */
|
||||||
printf("\r%*s\r", len, "");
|
printf("\r%*s\r", len, "");
|
||||||
|
|
||||||
@ -150,10 +146,10 @@ int more_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
|
|
||||||
/* The user may have resized the terminal.
|
/* The user may have resized the terminal.
|
||||||
* Re-read the dimensions. */
|
* Re-read the dimensions. */
|
||||||
#if ENABLE_FEATURE_USE_TERMIOS
|
if (ENABLE_FEATURE_USE_TERMIOS) {
|
||||||
get_terminal_width_height(cin_fileno, &terminal_width, &terminal_height);
|
get_terminal_width_height(cin_fileno, &terminal_width, &terminal_height);
|
||||||
terminal_height -= 1;
|
terminal_height -= 1;
|
||||||
#endif
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Crudely convert tabs into spaces, which are
|
/* Crudely convert tabs into spaces, which are
|
||||||
|
@ -33,24 +33,20 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
OPT_c = (1 << 1),
|
OPT_c = (1 << 1),
|
||||||
OPT_f = (1 << 2),
|
OPT_f = (1 << 2),
|
||||||
OPT_q = (1 << 3),
|
OPT_q = (1 << 3),
|
||||||
#if ENABLE_SCRIPTREPLAY
|
|
||||||
OPT_t = (1 << 4),
|
OPT_t = (1 << 4),
|
||||||
#endif
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#if ENABLE_GETOPT_LONG
|
|
||||||
static const char getopt_longopts[] ALIGN1 =
|
static const char getopt_longopts[] ALIGN1 =
|
||||||
"append\0" No_argument "a"
|
"append\0" No_argument "a"
|
||||||
"command\0" Required_argument "c"
|
"command\0" Required_argument "c"
|
||||||
"flush\0" No_argument "f"
|
"flush\0" No_argument "f"
|
||||||
"quiet\0" No_argument "q"
|
"quiet\0" No_argument "q"
|
||||||
# if ENABLE_SCRIPTREPLAY
|
IF_SCRIPTREPLAY("timing\0" No_argument "t")
|
||||||
"timing\0" No_argument "t"
|
|
||||||
# endif
|
|
||||||
;
|
;
|
||||||
|
|
||||||
applet_long_options = getopt_longopts;
|
if (ENABLE_GETOPT_LONG)
|
||||||
#endif
|
applet_long_options = getopt_longopts;
|
||||||
|
|
||||||
opt_complementary = "?1"; /* max one arg */
|
opt_complementary = "?1"; /* max one arg */
|
||||||
opt = getopt32(argv, "ac:fq" IF_SCRIPTREPLAY("t") , &shell_arg);
|
opt = getopt32(argv, "ac:fq" IF_SCRIPTREPLAY("t") , &shell_arg);
|
||||||
//argc -= optind;
|
//argc -= optind;
|
||||||
@ -101,9 +97,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
#define buf bb_common_bufsiz1
|
#define buf bb_common_bufsiz1
|
||||||
struct pollfd pfd[2];
|
struct pollfd pfd[2];
|
||||||
int outfd, count, loop;
|
int outfd, count, loop;
|
||||||
#if ENABLE_SCRIPTREPLAY
|
double oldtime = ENABLE_SCRIPTREPLAY ? time(NULL) : 0;
|
||||||
double oldtime = time(NULL);
|
|
||||||
#endif
|
|
||||||
smallint fd_count = 2;
|
smallint fd_count = 2;
|
||||||
|
|
||||||
outfd = xopen(fname, mode);
|
outfd = xopen(fname, mode);
|
||||||
@ -132,8 +126,7 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
goto restore;
|
goto restore;
|
||||||
}
|
}
|
||||||
if (count > 0) {
|
if (count > 0) {
|
||||||
#if ENABLE_SCRIPTREPLAY
|
if (ENABLE_SCRIPTREPLAY && (opt & OPT_t)) {
|
||||||
if (opt & OPT_t) {
|
|
||||||
struct timeval tv;
|
struct timeval tv;
|
||||||
double newtime;
|
double newtime;
|
||||||
|
|
||||||
@ -142,7 +135,6 @@ int script_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
fprintf(stderr, "%f %u\n", newtime - oldtime, count);
|
fprintf(stderr, "%f %u\n", newtime - oldtime, count);
|
||||||
oldtime = newtime;
|
oldtime = newtime;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
full_write(STDOUT_FILENO, buf, count);
|
full_write(STDOUT_FILENO, buf, count);
|
||||||
full_write(outfd, buf, count);
|
full_write(outfd, buf, count);
|
||||||
if (opt & OPT_f) {
|
if (opt & OPT_f) {
|
||||||
|
@ -30,9 +30,9 @@ int scriptreplay_main(int argc UNUSED_PARAM, char **argv)
|
|||||||
usleep(delay * factor);
|
usleep(delay * factor);
|
||||||
bb_copyfd_exact_size(fd, STDOUT_FILENO, count);
|
bb_copyfd_exact_size(fd, STDOUT_FILENO, count);
|
||||||
}
|
}
|
||||||
#if ENABLE_FEATURE_CLEAN_UP
|
if (ENABLE_FEATURE_CLEAN_UP) {
|
||||||
close(fd);
|
close(fd);
|
||||||
fclose(tfp);
|
fclose(tfp);
|
||||||
#endif
|
}
|
||||||
return EXIT_SUCCESS;
|
return EXIT_SUCCESS;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user