aboutsummaryrefslogtreecommitdiff
path: root/coreutils/stty.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-10-08 12:49:22 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-10-08 12:49:22 +0000
commit1385899416a4396385ad421ae1f532be7103738a (patch)
treefc4d14a910593d1235318bb36abe5e9f72d2039e /coreutils/stty.c
parent5625415085e68ac5e150f54e685417c866620d76 (diff)
downloadbusybox-w32-1385899416a4396385ad421ae1f532be7103738a.tar.gz
busybox-w32-1385899416a4396385ad421ae1f532be7103738a.tar.bz2
busybox-w32-1385899416a4396385ad421ae1f532be7103738a.zip
attempt to regularize atoi mess.
Diffstat (limited to 'coreutils/stty.c')
-rw-r--r--coreutils/stty.c36
1 files changed, 16 insertions, 20 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c
index a41faaf1e..8c16c27a9 100644
--- a/coreutils/stty.c
+++ b/coreutils/stty.c
@@ -370,9 +370,9 @@ enum {
370}; 370};
371 371
372/* The width of the screen, for output wrapping */ 372/* The width of the screen, for output wrapping */
373static int max_col; 373static unsigned max_col = 80; /* default */
374/* Current position, to know when to wrap */ 374/* Current position, to know when to wrap */
375static int current_col; 375static unsigned current_col;
376static const char *device_name = bb_msg_standard_input; 376static const char *device_name = bb_msg_standard_input;
377 377
378/* Return a string that is the printable representation of character CH */ 378/* Return a string that is the printable representation of character CH */
@@ -422,7 +422,7 @@ static tcflag_t *mode_type_flag(unsigned type, const struct termios *mode)
422 422
423static speed_t string_to_baud_or_die(const char *arg) 423static speed_t string_to_baud_or_die(const char *arg)
424{ 424{
425 return tty_value_to_baud(bb_xparse_number(arg, 0)); 425 return tty_value_to_baud(xatou(arg));
426} 426}
427 427
428static void set_speed_or_die(enum speed_setting type, const char *arg, 428static void set_speed_or_die(enum speed_setting type, const char *arg,
@@ -556,9 +556,8 @@ static inline void display_window_size(int fancy) {}
556 556
557#endif /* !TIOCGWINSZ */ 557#endif /* !TIOCGWINSZ */
558 558
559static int screen_columns(void) 559static int screen_columns_or_die(void)
560{ 560{
561 int columns;
562 const char *s; 561 const char *s;
563 562
564#ifdef TIOCGWINSZ 563#ifdef TIOCGWINSZ
@@ -574,11 +573,10 @@ static int screen_columns(void)
574 return win.ws_col; 573 return win.ws_col;
575#endif 574#endif
576 575
577 columns = 80; 576 s = getenv("COLUMNS");
578 if ((s = getenv("COLUMNS"))) { 577 if (s)
579 columns = atoi(s); 578 return xatoi_u(s);
580 } 579 return 80;
581 return columns;
582} 580}
583 581
584static const struct suffix_mult stty_suffixes[] = { 582static const struct suffix_mult stty_suffixes[] = {
@@ -745,14 +743,14 @@ end_option:
745#ifdef HAVE_C_LINE 743#ifdef HAVE_C_LINE
746 case param_line: 744 case param_line:
747# ifndef TIOCGWINSZ 745# ifndef TIOCGWINSZ
748 bb_xparse_number(argnext, stty_suffixes); 746 xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
749 break; 747 break;
750# endif /* else fall-through */ 748# endif /* else fall-through */
751#endif 749#endif
752#ifdef TIOCGWINSZ 750#ifdef TIOCGWINSZ
753 case param_rows: 751 case param_rows:
754 case param_cols: 752 case param_cols:
755 bb_xparse_number(argnext, stty_suffixes); 753 xatoul_range_sfx(argnext, 1, INT_MAX, stty_suffixes);
756 break; 754 break;
757 case param_size: 755 case param_size:
758#endif 756#endif
@@ -802,7 +800,7 @@ end_option:
802 perror_on_device_and_die("%s"); 800 perror_on_device_and_die("%s");
803 801
804 if (verbose_output || recoverable_output || noargs) { 802 if (verbose_output || recoverable_output || noargs) {
805 max_col = screen_columns(); 803 max_col = screen_columns_or_die();
806 output_func(&mode); 804 output_func(&mode);
807 return EXIT_SUCCESS; 805 return EXIT_SUCCESS;
808 } 806 }
@@ -846,24 +844,22 @@ end_option:
846 switch (param) { 844 switch (param) {
847#ifdef HAVE_C_LINE 845#ifdef HAVE_C_LINE
848 case param_line: 846 case param_line:
849 mode.c_line = bb_xparse_number(argnext, stty_suffixes); 847 mode.c_line = xatoul_sfx(argnext, stty_suffixes);
850 require_set_attr = 1; 848 require_set_attr = 1;
851 break; 849 break;
852#endif 850#endif
853#ifdef TIOCGWINSZ 851#ifdef TIOCGWINSZ
854 case param_cols: 852 case param_cols:
855 set_window_size(-1, (int) bb_xparse_number(argnext, stty_suffixes)); 853 set_window_size(-1, xatoul_sfx(argnext, stty_suffixes));
856 break; 854 break;
857 case param_size: 855 case param_size:
858 max_col = screen_columns();
859 display_window_size(0); 856 display_window_size(0);
860 break; 857 break;
861 case param_rows: 858 case param_rows:
862 set_window_size((int) bb_xparse_number(argnext, stty_suffixes), -1); 859 set_window_size(xatoul_sfx(argnext, stty_suffixes), -1);
863 break; 860 break;
864#endif 861#endif
865 case param_speed: 862 case param_speed:
866 max_col = screen_columns();
867 display_speed(&mode, 0); 863 display_speed(&mode, 0);
868 break; 864 break;
869 case param_ispeed: 865 case param_ispeed:
@@ -1096,7 +1092,7 @@ static void set_control_char_or_die(const struct control_info *info,
1096 unsigned char value; 1092 unsigned char value;
1097 1093
1098 if (info->name == stty_min || info->name == stty_time) 1094 if (info->name == stty_min || info->name == stty_time)
1099 value = bb_xparse_number(arg, stty_suffixes); 1095 value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
1100 else if (arg[0] == '\0' || arg[1] == '\0') 1096 else if (arg[0] == '\0' || arg[1] == '\0')
1101 value = arg[0]; 1097 value = arg[0];
1102 else if (streq(arg, "^-") || streq(arg, "undef")) 1098 else if (streq(arg, "^-") || streq(arg, "undef"))
@@ -1106,7 +1102,7 @@ static void set_control_char_or_die(const struct control_info *info,
1106 if (arg[1] == '?') 1102 if (arg[1] == '?')
1107 value = 127; 1103 value = 127;
1108 } else 1104 } else
1109 value = bb_xparse_number(arg, stty_suffixes); 1105 value = xatoul_range_sfx(arg, 0, 0xff, stty_suffixes);
1110 mode->c_cc[info->offset] = value; 1106 mode->c_cc[info->offset] = value;
1111} 1107}
1112 1108