diff options
author | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-01-30 12:23:46 +0000 |
---|---|---|
committer | "Vladimir N. Oleynik" <dzo@simtreas.ru> | 2006-01-30 12:23:46 +0000 |
commit | 9b9a920eef1bcbab2c4daa239b53de7e9ca83144 (patch) | |
tree | 5249acdf982859f8a0b1b25c11a8c03db5c9a962 /coreutils/stty.c | |
parent | e75b41d9905d91b388b18d4395dae72ab17d31b7 (diff) | |
download | busybox-w32-9b9a920eef1bcbab2c4daa239b53de7e9ca83144.tar.gz busybox-w32-9b9a920eef1bcbab2c4daa239b53de7e9ca83144.tar.bz2 busybox-w32-9b9a920eef1bcbab2c4daa239b53de7e9ca83144.zip |
removed warning "comparison between signed and unsigned". Reduced size
Diffstat (limited to 'coreutils/stty.c')
-rw-r--r-- | coreutils/stty.c | 84 |
1 files changed, 41 insertions, 43 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c index cbd2c22e9..21759631e 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -399,6 +399,7 @@ static const struct control_info control_info[] = { | |||
399 | static const int NUM_control_info = | 399 | static const int NUM_control_info = |
400 | (sizeof(control_info) / sizeof(struct control_info)); | 400 | (sizeof(control_info) / sizeof(struct control_info)); |
401 | 401 | ||
402 | #define EMT(t) ((enum mode_type)(t)) | ||
402 | 403 | ||
403 | static const char * visible(unsigned int ch); | 404 | static const char * visible(unsigned int ch); |
404 | static int recover_mode(char *arg, struct termios *mode); | 405 | static int recover_mode(char *arg, struct termios *mode); |
@@ -407,17 +408,17 @@ static int set_mode(const struct mode_info *info, | |||
407 | int reversed, struct termios *mode); | 408 | int reversed, struct termios *mode); |
408 | static speed_t string_to_baud(const char *arg); | 409 | static speed_t string_to_baud(const char *arg); |
409 | static tcflag_t* mode_type_flag(enum mode_type type, struct termios *mode); | 410 | static tcflag_t* mode_type_flag(enum mode_type type, struct termios *mode); |
410 | static void display_all(struct termios *mode, int fd); | 411 | static void display_all(struct termios *mode); |
411 | static void display_changed(struct termios *mode, int fd); | 412 | static void display_changed(struct termios *mode); |
412 | static void display_recoverable(struct termios *mode, int fd); | 413 | static void display_recoverable(struct termios *mode); |
413 | static void display_speed(struct termios *mode, int fancy); | 414 | static void display_speed(struct termios *mode, int fancy); |
414 | static void display_window_size(int fancy, int fd); | 415 | static void display_window_size(int fancy); |
415 | static void sane_mode(struct termios *mode); | 416 | static void sane_mode(struct termios *mode); |
416 | static void set_control_char(const struct control_info *info, | 417 | static void set_control_char(const struct control_info *info, |
417 | const char *arg, struct termios *mode); | 418 | const char *arg, struct termios *mode); |
418 | static void set_speed(enum speed_setting type, | 419 | static void set_speed(enum speed_setting type, |
419 | const char *arg, struct termios *mode); | 420 | const char *arg, struct termios *mode); |
420 | static void set_window_size(int rows, int cols, int fd); | 421 | static void set_window_size(int rows, int cols); |
421 | 422 | ||
422 | static const char *device_name; | 423 | static const char *device_name; |
423 | 424 | ||
@@ -473,7 +474,7 @@ extern int main(int argc, char **argv) | |||
473 | #endif | 474 | #endif |
474 | { | 475 | { |
475 | struct termios mode; | 476 | struct termios mode; |
476 | void (*output_func)(struct termios *, int); | 477 | void (*output_func)(struct termios *); |
477 | int optc; | 478 | int optc; |
478 | int require_set_attr; | 479 | int require_set_attr; |
479 | int speed_was_set; | 480 | int speed_was_set; |
@@ -482,8 +483,6 @@ extern int main(int argc, char **argv) | |||
482 | int k; | 483 | int k; |
483 | int noargs = 1; | 484 | int noargs = 1; |
484 | char * file_name = NULL; | 485 | char * file_name = NULL; |
485 | int fd; | ||
486 | |||
487 | 486 | ||
488 | output_func = display_changed; | 487 | output_func = display_changed; |
489 | verbose_output = 0; | 488 | verbose_output = 0; |
@@ -539,25 +538,25 @@ extern int main(int argc, char **argv) | |||
539 | int fdflags; | 538 | int fdflags; |
540 | 539 | ||
541 | device_name = file_name; | 540 | device_name = file_name; |
542 | fd = bb_xopen(device_name, O_RDONLY | O_NONBLOCK); | 541 | fclose(stdin); |
543 | if ((fdflags = fcntl(fd, F_GETFL)) == -1 | 542 | bb_xopen(device_name, O_RDONLY | O_NONBLOCK); |
544 | || fcntl(fd, F_SETFL, fdflags & ~O_NONBLOCK) < 0) | 543 | if ((fdflags = fcntl(STDIN_FILENO, F_GETFL)) == -1 |
544 | || fcntl(STDIN_FILENO, F_SETFL, fdflags & ~O_NONBLOCK) < 0) | ||
545 | perror_on_device("%s: couldn't reset non-blocking mode"); | 545 | perror_on_device("%s: couldn't reset non-blocking mode"); |
546 | } else { | 546 | } else { |
547 | fd = 0; | ||
548 | device_name = bb_msg_standard_input; | 547 | device_name = bb_msg_standard_input; |
549 | } | 548 | } |
550 | 549 | ||
551 | /* Initialize to all zeroes so there is no risk memcmp will report a | 550 | /* Initialize to all zeroes so there is no risk memcmp will report a |
552 | spurious difference in an uninitialized portion of the structure. */ | 551 | spurious difference in an uninitialized portion of the structure. */ |
553 | memset(&mode, 0, sizeof(mode)); | 552 | memset(&mode, 0, sizeof(mode)); |
554 | if (tcgetattr(fd, &mode)) | 553 | if (tcgetattr(STDIN_FILENO, &mode)) |
555 | perror_on_device("%s"); | 554 | perror_on_device("%s"); |
556 | 555 | ||
557 | if (verbose_output | recoverable_output | noargs) { | 556 | if (verbose_output | recoverable_output | noargs) { |
558 | max_col = screen_columns(); | 557 | max_col = screen_columns(); |
559 | current_col = 0; | 558 | current_col = 0; |
560 | output_func(&mode, fd); | 559 | output_func(&mode); |
561 | return EXIT_SUCCESS; | 560 | return EXIT_SUCCESS; |
562 | } | 561 | } |
563 | 562 | ||
@@ -637,18 +636,17 @@ extern int main(int argc, char **argv) | |||
637 | bb_error_msg_and_die("missing argument to `%s'", argv[k]); | 636 | bb_error_msg_and_die("missing argument to `%s'", argv[k]); |
638 | ++k; | 637 | ++k; |
639 | set_window_size((int) bb_xparse_number(argv[k], stty_suffixes), | 638 | set_window_size((int) bb_xparse_number(argv[k], stty_suffixes), |
640 | -1, fd); | 639 | -1); |
641 | } else if (STREQ(argv[k], "cols") || STREQ(argv[k], "columns")) { | 640 | } else if (STREQ(argv[k], "cols") || STREQ(argv[k], "columns")) { |
642 | if (k == argc - 1) | 641 | if (k == argc - 1) |
643 | bb_error_msg_and_die("missing argument to `%s'", argv[k]); | 642 | bb_error_msg_and_die("missing argument to `%s'", argv[k]); |
644 | ++k; | 643 | ++k; |
645 | set_window_size(-1, | 644 | set_window_size(-1, |
646 | (int) bb_xparse_number(argv[k], stty_suffixes), | 645 | (int) bb_xparse_number(argv[k], stty_suffixes)); |
647 | fd); | ||
648 | } else if (STREQ(argv[k], "size")) { | 646 | } else if (STREQ(argv[k], "size")) { |
649 | max_col = screen_columns(); | 647 | max_col = screen_columns(); |
650 | current_col = 0; | 648 | current_col = 0; |
651 | display_window_size(0, fd); | 649 | display_window_size(0); |
652 | } | 650 | } |
653 | #endif | 651 | #endif |
654 | #ifdef HAVE_C_LINE | 652 | #ifdef HAVE_C_LINE |
@@ -677,7 +675,7 @@ extern int main(int argc, char **argv) | |||
677 | if (require_set_attr) { | 675 | if (require_set_attr) { |
678 | struct termios new_mode; | 676 | struct termios new_mode; |
679 | 677 | ||
680 | if (tcsetattr(fd, TCSADRAIN, &mode)) | 678 | if (tcsetattr(STDIN_FILENO, TCSADRAIN, &mode)) |
681 | perror_on_device("%s"); | 679 | perror_on_device("%s"); |
682 | 680 | ||
683 | /* POSIX (according to Zlotnick's book) tcsetattr returns zero if | 681 | /* POSIX (according to Zlotnick's book) tcsetattr returns zero if |
@@ -690,7 +688,7 @@ extern int main(int argc, char **argv) | |||
690 | /* Initialize to all zeroes so there is no risk memcmp will report a | 688 | /* Initialize to all zeroes so there is no risk memcmp will report a |
691 | spurious difference in an uninitialized portion of the structure. */ | 689 | spurious difference in an uninitialized portion of the structure. */ |
692 | memset(&new_mode, 0, sizeof(new_mode)); | 690 | memset(&new_mode, 0, sizeof(new_mode)); |
693 | if (tcgetattr(fd, &new_mode)) | 691 | if (tcgetattr(STDIN_FILENO, &new_mode)) |
694 | perror_on_device("%s"); | 692 | perror_on_device("%s"); |
695 | 693 | ||
696 | /* Normally, one shouldn't use memcmp to compare structures that | 694 | /* Normally, one shouldn't use memcmp to compare structures that |
@@ -731,7 +729,7 @@ set_mode(const struct mode_info *info, int reversed, struct termios *mode) | |||
731 | if (reversed && (info->flags & REV) == 0) | 729 | if (reversed && (info->flags & REV) == 0) |
732 | return 0; | 730 | return 0; |
733 | 731 | ||
734 | bitsp = mode_type_flag(info->type, mode); | 732 | bitsp = mode_type_flag(EMT(info->type), mode); |
735 | 733 | ||
736 | if (bitsp == NULL) { | 734 | if (bitsp == NULL) { |
737 | /* Combination mode. */ | 735 | /* Combination mode. */ |
@@ -922,10 +920,10 @@ set_speed(enum speed_setting type, const char *arg, struct termios *mode) | |||
922 | 920 | ||
923 | baud = string_to_baud(arg); | 921 | baud = string_to_baud(arg); |
924 | 922 | ||
925 | if (type != output_speed) { /* either input or both */ | 923 | if (type != output_speed) { /* either input or both */ |
926 | cfsetispeed(mode, baud); | 924 | cfsetispeed(mode, baud); |
927 | } | 925 | } |
928 | if (type != input_speed) { /* either output or both */ | 926 | if (type != input_speed) { /* either output or both */ |
929 | cfsetospeed(mode, baud); | 927 | cfsetospeed(mode, baud); |
930 | } | 928 | } |
931 | } | 929 | } |
@@ -940,11 +938,11 @@ static int get_win_size(int fd, struct winsize *win) | |||
940 | } | 938 | } |
941 | 939 | ||
942 | static void | 940 | static void |
943 | set_window_size(int rows, int cols, int fd) | 941 | set_window_size(int rows, int cols) |
944 | { | 942 | { |
945 | struct winsize win; | 943 | struct winsize win; |
946 | 944 | ||
947 | if (get_win_size(fd, &win)) { | 945 | if (get_win_size(STDIN_FILENO, &win)) { |
948 | if (errno != EINVAL) | 946 | if (errno != EINVAL) |
949 | perror_on_device("%s"); | 947 | perror_on_device("%s"); |
950 | memset(&win, 0, sizeof(win)); | 948 | memset(&win, 0, sizeof(win)); |
@@ -970,24 +968,24 @@ set_window_size(int rows, int cols, int fd) | |||
970 | 968 | ||
971 | win.ws_row = win.ws_col = 1; | 969 | win.ws_row = win.ws_col = 1; |
972 | 970 | ||
973 | if ((ioctl(fd, TIOCSWINSZ, (char *) &win) != 0) | 971 | if ((ioctl(STDIN_FILENO, TIOCSWINSZ, (char *) &win) != 0) |
974 | || (ioctl(fd, TIOCSSIZE, (char *) &ttysz) != 0)) { | 972 | || (ioctl(STDIN_FILENO, TIOCSSIZE, (char *) &ttysz) != 0)) { |
975 | perror_on_device("%s"); | 973 | perror_on_device("%s"); |
976 | } | 974 | } |
977 | return; | 975 | return; |
978 | } | 976 | } |
979 | # endif | 977 | # endif |
980 | 978 | ||
981 | if (ioctl(fd, TIOCSWINSZ, (char *) &win)) | 979 | if (ioctl(STDIN_FILENO, TIOCSWINSZ, (char *) &win)) |
982 | perror_on_device("%s"); | 980 | perror_on_device("%s"); |
983 | } | 981 | } |
984 | 982 | ||
985 | static void display_window_size(int fancy, int fd) | 983 | static void display_window_size(int fancy) |
986 | { | 984 | { |
987 | const char *fmt_str = "%s" "\0" "%s: no size information for this device"; | 985 | const char *fmt_str = "%s" "\0" "%s: no size information for this device"; |
988 | struct winsize win; | 986 | struct winsize win; |
989 | 987 | ||
990 | if (get_win_size(fd, &win)) { | 988 | if (get_win_size(STDIN_FILENO, &win)) { |
991 | if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) { | 989 | if ((errno != EINVAL) || ((fmt_str += 2), !fancy)) { |
992 | perror_on_device(fmt_str); | 990 | perror_on_device(fmt_str); |
993 | } | 991 | } |
@@ -1040,7 +1038,7 @@ static tcflag_t *mode_type_flag(enum mode_type type, struct termios *mode) | |||
1040 | return NULL; | 1038 | return NULL; |
1041 | } | 1039 | } |
1042 | 1040 | ||
1043 | static void display_changed(struct termios *mode, int fd) | 1041 | static void display_changed(struct termios *mode) |
1044 | { | 1042 | { |
1045 | int i; | 1043 | int i; |
1046 | int empty_line; | 1044 | int empty_line; |
@@ -1086,16 +1084,16 @@ static void display_changed(struct termios *mode, int fd) | |||
1086 | for (i = 0; i < NUM_mode_info; ++i) { | 1084 | for (i = 0; i < NUM_mode_info; ++i) { |
1087 | if (mode_info[i].flags & OMIT) | 1085 | if (mode_info[i].flags & OMIT) |
1088 | continue; | 1086 | continue; |
1089 | if (mode_info[i].type != prev_type) { | 1087 | if (EMT(mode_info[i].type) != prev_type) { |
1090 | if (empty_line == 0) { | 1088 | if (empty_line == 0) { |
1091 | putchar('\n'); | 1089 | putchar('\n'); |
1092 | current_col = 0; | 1090 | current_col = 0; |
1093 | empty_line = 1; | 1091 | empty_line = 1; |
1094 | } | 1092 | } |
1095 | prev_type = mode_info[i].type; | 1093 | prev_type = EMT(mode_info[i].type); |
1096 | } | 1094 | } |
1097 | 1095 | ||
1098 | bitsp = mode_type_flag(mode_info[i].type, mode); | 1096 | bitsp = mode_type_flag(EMT(mode_info[i].type), mode); |
1099 | mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; | 1097 | mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; |
1100 | if ((*bitsp & mask) == mode_info[i].bits) { | 1098 | if ((*bitsp & mask) == mode_info[i].bits) { |
1101 | if (mode_info[i].flags & SANE_UNSET) { | 1099 | if (mode_info[i].flags & SANE_UNSET) { |
@@ -1115,7 +1113,7 @@ static void display_changed(struct termios *mode, int fd) | |||
1115 | } | 1113 | } |
1116 | 1114 | ||
1117 | static void | 1115 | static void |
1118 | display_all(struct termios *mode, int fd) | 1116 | display_all(struct termios *mode) |
1119 | { | 1117 | { |
1120 | int i; | 1118 | int i; |
1121 | tcflag_t *bitsp; | 1119 | tcflag_t *bitsp; |
@@ -1124,7 +1122,7 @@ display_all(struct termios *mode, int fd) | |||
1124 | 1122 | ||
1125 | display_speed(mode, 1); | 1123 | display_speed(mode, 1); |
1126 | #ifdef TIOCGWINSZ | 1124 | #ifdef TIOCGWINSZ |
1127 | display_window_size(1, fd); | 1125 | display_window_size(1); |
1128 | #endif | 1126 | #endif |
1129 | #ifdef HAVE_C_LINE | 1127 | #ifdef HAVE_C_LINE |
1130 | wrapf("line = %d;", mode->c_line); | 1128 | wrapf("line = %d;", mode->c_line); |
@@ -1158,13 +1156,13 @@ display_all(struct termios *mode, int fd) | |||
1158 | for (i = 0; i < NUM_mode_info; ++i) { | 1156 | for (i = 0; i < NUM_mode_info; ++i) { |
1159 | if (mode_info[i].flags & OMIT) | 1157 | if (mode_info[i].flags & OMIT) |
1160 | continue; | 1158 | continue; |
1161 | if (mode_info[i].type != prev_type) { | 1159 | if (EMT(mode_info[i].type) != prev_type) { |
1162 | putchar('\n'); | 1160 | putchar('\n'); |
1163 | current_col = 0; | 1161 | current_col = 0; |
1164 | prev_type = mode_info[i].type; | 1162 | prev_type = EMT(mode_info[i].type); |
1165 | } | 1163 | } |
1166 | 1164 | ||
1167 | bitsp = mode_type_flag(mode_info[i].type, mode); | 1165 | bitsp = mode_type_flag(EMT(mode_info[i].type), mode); |
1168 | mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; | 1166 | mask = mode_info[i].mask ? mode_info[i].mask : mode_info[i].bits; |
1169 | if ((*bitsp & mask) == mode_info[i].bits) | 1167 | if ((*bitsp & mask) == mode_info[i].bits) |
1170 | wrapf("%s", mode_info[i].name); | 1168 | wrapf("%s", mode_info[i].name); |
@@ -1184,7 +1182,7 @@ static void display_speed(struct termios *mode, int fancy) | |||
1184 | 1182 | ||
1185 | ospeed = ispeed = cfgetispeed(mode); | 1183 | ospeed = ispeed = cfgetispeed(mode); |
1186 | if (ispeed == 0 || ispeed == (ospeed = cfgetospeed(mode))) { | 1184 | if (ispeed == 0 || ispeed == (ospeed = cfgetospeed(mode))) { |
1187 | ispeed = ospeed; /* in case ispeed was 0 */ | 1185 | ispeed = ospeed; /* in case ispeed was 0 */ |
1188 | fmt_str += 43; | 1186 | fmt_str += 43; |
1189 | } | 1187 | } |
1190 | if (fancy) { | 1188 | if (fancy) { |
@@ -1195,7 +1193,7 @@ static void display_speed(struct termios *mode, int fancy) | |||
1195 | current_col = 0; | 1193 | current_col = 0; |
1196 | } | 1194 | } |
1197 | 1195 | ||
1198 | static void display_recoverable(struct termios *mode, int fd) | 1196 | static void display_recoverable(struct termios *mode) |
1199 | { | 1197 | { |
1200 | int i; | 1198 | int i; |
1201 | 1199 | ||
@@ -1257,11 +1255,11 @@ static void sane_mode(struct termios *mode) | |||
1257 | 1255 | ||
1258 | for (i = 0; i < NUM_mode_info; ++i) { | 1256 | for (i = 0; i < NUM_mode_info; ++i) { |
1259 | if (mode_info[i].flags & SANE_SET) { | 1257 | if (mode_info[i].flags & SANE_SET) { |
1260 | bitsp = mode_type_flag(mode_info[i].type, mode); | 1258 | bitsp = mode_type_flag(EMT(mode_info[i].type), mode); |
1261 | *bitsp = (*bitsp & ~((unsigned long)mode_info[i].mask)) | 1259 | *bitsp = (*bitsp & ~((unsigned long)mode_info[i].mask)) |
1262 | | mode_info[i].bits; | 1260 | | mode_info[i].bits; |
1263 | } else if (mode_info[i].flags & SANE_UNSET) { | 1261 | } else if (mode_info[i].flags & SANE_UNSET) { |
1264 | bitsp = mode_type_flag(mode_info[i].type, mode); | 1262 | bitsp = mode_type_flag(EMT(mode_info[i].type), mode); |
1265 | *bitsp = *bitsp & ~((unsigned long)mode_info[i].mask) | 1263 | *bitsp = *bitsp & ~((unsigned long)mode_info[i].mask) |
1266 | & ~mode_info[i].bits; | 1264 | & ~mode_info[i].bits; |
1267 | } | 1265 | } |