aboutsummaryrefslogtreecommitdiff
path: root/coreutils/stty.c
diff options
context:
space:
mode:
authorandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-06-20 09:01:58 +0000
committerandersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-06-20 09:01:58 +0000
commit3b4406c151cabd47b24d309dbbd9c5b19e9d6b33 (patch)
treef67de9320202043aca8ded20fb80d668c3b0c2d8 /coreutils/stty.c
parent90e9e2c71f1e3ed8031334106594ef7fa9e0173b (diff)
downloadbusybox-w32-3b4406c151cabd47b24d309dbbd9c5b19e9d6b33.tar.gz
busybox-w32-3b4406c151cabd47b24d309dbbd9c5b19e9d6b33.tar.bz2
busybox-w32-3b4406c151cabd47b24d309dbbd9c5b19e9d6b33.zip
last_patch89 from vodz:
Manuel, I rewrite bb_getopt_ulflags() function for more universal usage. My version support now: - options with arguments (optional arg as GNU extension also) - complementaly and/or incomplementaly and/or incongruously and/or list options - long_opt (all applets may have long option, add supporting is trivial) This realisation full compatibile from your version. Code size grow 480 bytes, but only coreutils/* over compensate this size after using new function. Last patch reduced over 800 bytes and not full applied to all. "mkdir" and "mv" applets have long_opt now for demonstrate trivial addition support long_opt with usage new bb_getopt_ulflags(). Complementaly and/or incomplementaly and/or incongruously and/or list options logic is not trivial, but new "cut" and "grep" applets using this logic for examples with full demostrating. New "grep" applet reduced over 300 bytes. Mark, Also. I removed bug from "grep" applet. $ echo a b | busybox grep -e a b a b a b But right is printing one only. --w vodz git-svn-id: svn://busybox.net/trunk/busybox@6939 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to 'coreutils/stty.c')
-rw-r--r--coreutils/stty.c71
1 files changed, 35 insertions, 36 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c
index a3a98d9ef..bd3a36911 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -414,22 +414,25 @@ static int set_mode(const struct mode_info *info,
414 int reversed, struct termios *mode); 414 int reversed, struct termios *mode);
415static speed_t string_to_baud(const char *arg); 415static speed_t string_to_baud(const char *arg);
416static tcflag_t* mode_type_flag(enum mode_type type, struct termios *mode); 416static tcflag_t* mode_type_flag(enum mode_type type, struct termios *mode);
417static void display_all(struct termios *mode, int fd, 417static void display_all(struct termios *mode, int fd);
418 const char *device_name); 418static void display_changed(struct termios *mode, int fd);
419static void display_changed(struct termios *mode, int fd, 419static void display_recoverable(struct termios *mode, int fd);
420 const char *device_name);
421static void display_recoverable(struct termios *mode, int fd,
422 const char *device_name);
423static void display_speed(struct termios *mode, int fancy); 420static void display_speed(struct termios *mode, int fancy);
424static void display_window_size(int fancy, int fd, 421static void display_window_size(int fancy, int fd);
425 const char *device_name);
426static void sane_mode(struct termios *mode); 422static void sane_mode(struct termios *mode);
427static void set_control_char(const struct control_info *info, 423static void set_control_char(const struct control_info *info,
428 const char *arg, struct termios *mode); 424 const char *arg, struct termios *mode);
429static void set_speed(enum speed_setting type, 425static void set_speed(enum speed_setting type,
430 const char *arg, struct termios *mode); 426 const char *arg, struct termios *mode);
431static void set_window_size(int rows, int cols, int fd, 427static void set_window_size(int rows, int cols, int fd);
432 const char *device_name); 428
429static const char *device_name;
430
431static __attribute__ ((noreturn)) void perror_on_device(const char *fmt)
432{
433 bb_perror_msg_and_die(fmt, device_name);
434}
435
433 436
434/* The width of the screen, for output wrapping. */ 437/* The width of the screen, for output wrapping. */
435static int max_col; 438static int max_col;
@@ -477,7 +480,7 @@ extern int main(int argc, char **argv)
477#endif 480#endif
478{ 481{
479 struct termios mode; 482 struct termios mode;
480 void (*output_func)(struct termios *, int, const char *); 483 void (*output_func)(struct termios *, int);
481 int optc; 484 int optc;
482 int require_set_attr; 485 int require_set_attr;
483 int speed_was_set; 486 int speed_was_set;
@@ -487,7 +490,7 @@ extern int main(int argc, char **argv)
487 int noargs = 1; 490 int noargs = 1;
488 char * file_name = NULL; 491 char * file_name = NULL;
489 int fd; 492 int fd;
490 const char *device_name; 493
491 494
492 output_func = display_changed; 495 output_func = display_changed;
493 verbose_output = 0; 496 verbose_output = 0;
@@ -543,13 +546,10 @@ extern int main(int argc, char **argv)
543 int fdflags; 546 int fdflags;
544 547
545 device_name = file_name; 548 device_name = file_name;
546 fd = open(device_name, O_RDONLY | O_NONBLOCK); 549 fd = bb_xopen(device_name, O_RDONLY | O_NONBLOCK);
547 if (fd < 0)
548 bb_perror_msg_and_die("%s", device_name);
549 if ((fdflags = fcntl(fd, F_GETFL)) == -1 550 if ((fdflags = fcntl(fd, F_GETFL)) == -1
550 || fcntl(fd, F_SETFL, fdflags & ~O_NONBLOCK) < 0) 551 || fcntl(fd, F_SETFL, fdflags & ~O_NONBLOCK) < 0)
551 bb_perror_msg_and_die("%s: couldn't reset non-blocking mode", 552 perror_on_device("%s: couldn't reset non-blocking mode");
552 device_name);
553 } else { 553 } else {
554 fd = 0; 554 fd = 0;
555 device_name = bb_msg_standard_input; 555 device_name = bb_msg_standard_input;
@@ -559,12 +559,12 @@ extern int main(int argc, char **argv)
559 spurious difference in an uninitialized portion of the structure. */ 559 spurious difference in an uninitialized portion of the structure. */
560 memset(&mode, 0, sizeof(mode)); 560 memset(&mode, 0, sizeof(mode));
561 if (tcgetattr(fd, &mode)) 561 if (tcgetattr(fd, &mode))
562 bb_perror_msg_and_die("%s", device_name); 562 perror_on_device("%s");
563 563
564 if (verbose_output | recoverable_output | noargs) { 564 if (verbose_output | recoverable_output | noargs) {
565 max_col = screen_columns(); 565 max_col = screen_columns();
566 current_col = 0; 566 current_col = 0;
567 output_func(&mode, fd, device_name); 567 output_func(&mode, fd);
568 return EXIT_SUCCESS; 568 return EXIT_SUCCESS;
569 } 569 }
570 570
@@ -644,18 +644,18 @@ extern int main(int argc, char **argv)
644 bb_error_msg_and_die("missing argument to `%s'", argv[k]); 644 bb_error_msg_and_die("missing argument to `%s'", argv[k]);
645 ++k; 645 ++k;
646 set_window_size((int) bb_xparse_number(argv[k], stty_suffixes), 646 set_window_size((int) bb_xparse_number(argv[k], stty_suffixes),
647 -1, fd, device_name); 647 -1, fd);
648 } else if (STREQ(argv[k], "cols") || STREQ(argv[k], "columns")) { 648 } else if (STREQ(argv[k], "cols") || STREQ(argv[k], "columns")) {
649 if (k == argc - 1) 649 if (k == argc - 1)
650 bb_error_msg_and_die("missing argument to `%s'", argv[k]); 650 bb_error_msg_and_die("missing argument to `%s'", argv[k]);
651 ++k; 651 ++k;
652 set_window_size(-1, 652 set_window_size(-1,
653 (int) bb_xparse_number(argv[k], stty_suffixes), 653 (int) bb_xparse_number(argv[k], stty_suffixes),
654 fd, device_name); 654 fd);
655 } else if (STREQ(argv[k], "size")) { 655 } else if (STREQ(argv[k], "size")) {
656 max_col = screen_columns(); 656 max_col = screen_columns();
657 current_col = 0; 657 current_col = 0;
658 display_window_size(0, fd, device_name); 658 display_window_size(0, fd);
659 } 659 }
660#endif 660#endif
661#ifdef HAVE_C_LINE 661#ifdef HAVE_C_LINE
@@ -685,7 +685,7 @@ extern int main(int argc, char **argv)
685 struct termios new_mode; 685 struct termios new_mode;
686 686
687 if (tcsetattr(fd, TCSADRAIN, &mode)) 687 if (tcsetattr(fd, TCSADRAIN, &mode))
688 bb_perror_msg_and_die("%s", device_name); 688 perror_on_device("%s");
689 689
690 /* POSIX (according to Zlotnick's book) tcsetattr returns zero if 690 /* POSIX (according to Zlotnick's book) tcsetattr returns zero if
691 it performs *any* of the requested operations. This means it 691 it performs *any* of the requested operations. This means it
@@ -698,7 +698,7 @@ extern int main(int argc, char **argv)
698 spurious difference in an uninitialized portion of the structure. */ 698 spurious difference in an uninitialized portion of the structure. */
699 memset(&new_mode, 0, sizeof(new_mode)); 699 memset(&new_mode, 0, sizeof(new_mode));
700 if (tcgetattr(fd, &new_mode)) 700 if (tcgetattr(fd, &new_mode))
701 bb_perror_msg_and_die("%s", device_name); 701 perror_on_device("%s");
702 702
703 /* Normally, one shouldn't use memcmp to compare structures that 703 /* Normally, one shouldn't use memcmp to compare structures that
704 may have `holes' containing uninitialized data, but we have been 704 may have `holes' containing uninitialized data, but we have been
@@ -721,8 +721,7 @@ extern int main(int argc, char **argv)
721 new_mode.c_cflag &= (~CIBAUD); 721 new_mode.c_cflag &= (~CIBAUD);
722 if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0) 722 if (speed_was_set || memcmp(&mode, &new_mode, sizeof(mode)) != 0)
723#endif 723#endif
724 bb_error_msg_and_die ("%s: unable to perform all requested operations", 724 perror_on_device ("%s: unable to perform all requested operations");
725 device_name);
726 } 725 }
727 } 726 }
728 727
@@ -948,13 +947,13 @@ static int get_win_size(int fd, struct winsize *win)
948} 947}
949 948
950static void 949static void
951set_window_size(int rows, int cols, int fd, const char *device_name) 950set_window_size(int rows, int cols, int fd)
952{ 951{
953 struct winsize win; 952 struct winsize win;
954 953
955 if (get_win_size(fd, &win)) { 954 if (get_win_size(fd, &win)) {
956 if (errno != EINVAL) 955 if (errno != EINVAL)
957 bb_perror_msg_and_die("%s", device_name); 956 perror_on_device("%s");
958 memset(&win, 0, sizeof(win)); 957 memset(&win, 0, sizeof(win));
959 } 958 }
960 959
@@ -980,23 +979,23 @@ set_window_size(int rows, int cols, int fd, const char *device_name)
980 979
981 if ((ioctl(fd, TIOCSWINSZ, (char *) &win) != 0) 980 if ((ioctl(fd, TIOCSWINSZ, (char *) &win) != 0)
982 || (ioctl(fd, TIOCSSIZE, (char *) &ttysz) != 0)) { 981 || (ioctl(fd, TIOCSSIZE, (char *) &ttysz) != 0)) {
983 bb_perror_msg_and_die("%s", device_name); 982 perror_on_device("%s");
984 return; 983 return;
985 } 984 }
986# endif 985# endif
987 986
988 if (ioctl(fd, TIOCSWINSZ, (char *) &win)) 987 if (ioctl(fd, TIOCSWINSZ, (char *) &win))
989 bb_perror_msg_and_die("%s", device_name); 988 perror_on_device("%s");
990} 989}
991 990
992static void display_window_size(int fancy, int fd, const char *device_name) 991static void display_window_size(int fancy, int fd)
993{ 992{
994 const char *fmt_str = "%s" "\0" "%s: no size information for this device"; 993 const char *fmt_str = "%s" "\0" "%s: no size information for this device";
995 struct winsize win; 994 struct winsize win;
996 995
997 if (get_win_size(fd, &win)) { 996 if (get_win_size(fd, &win)) {
998 if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) { 997 if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) {
999 bb_perror_msg_and_die(fmt_str, device_name); 998 perror_on_device(fmt_str);
1000 } 999 }
1001 } else { 1000 } else {
1002 wrapf(fancy ? "rows %d; columns %d;" : "%d %d\n", 1001 wrapf(fancy ? "rows %d; columns %d;" : "%d %d\n",
@@ -1047,7 +1046,7 @@ static tcflag_t *mode_type_flag(enum mode_type type, struct termios *mode)
1047 return NULL; 1046 return NULL;
1048} 1047}
1049 1048
1050static void display_changed(struct termios *mode, int fd, const char *device_name) 1049static void display_changed(struct termios *mode, int fd)
1051{ 1050{
1052 int i; 1051 int i;
1053 int empty_line; 1052 int empty_line;
@@ -1122,7 +1121,7 @@ static void display_changed(struct termios *mode, int fd, const char *device_nam
1122} 1121}
1123 1122
1124static void 1123static void
1125display_all(struct termios *mode, int fd, const char *device_name) 1124display_all(struct termios *mode, int fd)
1126{ 1125{
1127 int i; 1126 int i;
1128 tcflag_t *bitsp; 1127 tcflag_t *bitsp;
@@ -1131,7 +1130,7 @@ display_all(struct termios *mode, int fd, const char *device_name)
1131 1130
1132 display_speed(mode, 1); 1131 display_speed(mode, 1);
1133#ifdef TIOCGWINSZ 1132#ifdef TIOCGWINSZ
1134 display_window_size(1, fd, device_name); 1133 display_window_size(1, fd);
1135#endif 1134#endif
1136#ifdef HAVE_C_LINE 1135#ifdef HAVE_C_LINE
1137 wrapf("line = %d;", mode->c_line); 1136 wrapf("line = %d;", mode->c_line);
@@ -1202,7 +1201,7 @@ static void display_speed(struct termios *mode, int fancy)
1202 current_col = 0; 1201 current_col = 0;
1203} 1202}
1204 1203
1205static void display_recoverable(struct termios *mode, int fd, const char *device_name) 1204static void display_recoverable(struct termios *mode, int fd)
1206{ 1205{
1207 int i; 1206 int i;
1208 1207