diff options
author | Rob Landley <rob@landley.net> | 2006-06-18 23:59:03 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2006-06-18 23:59:03 +0000 |
commit | 290fcb4213ae5ab9ec6cb228dd64ef2c9f02d26d (patch) | |
tree | 083c3dad70b970ba65848de929fbb8d4b738676a | |
parent | ea224be6aa8fed5486376d3021a4cb911e935106 (diff) | |
download | busybox-w32-290fcb4213ae5ab9ec6cb228dd64ef2c9f02d26d.tar.gz busybox-w32-290fcb4213ae5ab9ec6cb228dd64ef2c9f02d26d.tar.bz2 busybox-w32-290fcb4213ae5ab9ec6cb228dd64ef2c9f02d26d.zip |
Undo all of the ugliness and some of the bloat from 15412.
-rw-r--r-- | coreutils/stty.c | 4 | ||||
-rw-r--r-- | include/libbb.h | 4 | ||||
-rw-r--r-- | libbb/speed_table.c | 158 | ||||
-rw-r--r-- | loginutils/getty.c | 2 |
4 files changed, 22 insertions, 146 deletions
diff --git a/coreutils/stty.c b/coreutils/stty.c index cfb7f7f39..b78368e7b 100644 --- a/coreutils/stty.c +++ b/coreutils/stty.c | |||
@@ -1190,7 +1190,7 @@ static void display_speed(struct termios *mode, int fancy) | |||
1190 | if (fancy) { | 1190 | if (fancy) { |
1191 | fmt_str += 9; | 1191 | fmt_str += 9; |
1192 | } | 1192 | } |
1193 | wrapf(fmt_str, bb_baud_to_value(ispeed), bb_baud_to_value(ospeed)); | 1193 | wrapf(fmt_str, tty_baud_to_value(ispeed), tty_baud_to_value(ospeed)); |
1194 | if (!fancy) | 1194 | if (!fancy) |
1195 | current_col = 0; | 1195 | current_col = 0; |
1196 | } | 1196 | } |
@@ -1239,7 +1239,7 @@ static int recover_mode(char *arg, struct termios *mode) | |||
1239 | 1239 | ||
1240 | static speed_t string_to_baud(const char *arg) | 1240 | static speed_t string_to_baud(const char *arg) |
1241 | { | 1241 | { |
1242 | return bb_value_to_baud(bb_xparse_number(arg, 0)); | 1242 | return tty_value_to_baud(bb_xparse_number(arg, 0)); |
1243 | } | 1243 | } |
1244 | 1244 | ||
1245 | static void sane_mode(struct termios *mode) | 1245 | static void sane_mode(struct termios *mode) |
diff --git a/include/libbb.h b/include/libbb.h index e9d7e7596..bc886dab9 100644 --- a/include/libbb.h +++ b/include/libbb.h | |||
@@ -140,8 +140,8 @@ extern int recursive_action(const char *fileName, int recurse, | |||
140 | extern int bb_parse_mode( const char* s, mode_t* theMode); | 140 | extern int bb_parse_mode( const char* s, mode_t* theMode); |
141 | extern long bb_xgetlarg(const char *arg, int base, long lower, long upper); | 141 | extern long bb_xgetlarg(const char *arg, int base, long lower, long upper); |
142 | 142 | ||
143 | extern unsigned long bb_baud_to_value(speed_t speed); | 143 | extern unsigned int tty_baud_to_value(speed_t speed); |
144 | extern speed_t bb_value_to_baud(unsigned long value); | 144 | extern speed_t tty_value_to_baud(unsigned int value); |
145 | 145 | ||
146 | extern int get_linux_version_code(void); | 146 | extern int get_linux_version_code(void); |
147 | 147 | ||
diff --git a/libbb/speed_table.c b/libbb/speed_table.c index b4d576b4c..d6073f12f 100644 --- a/libbb/speed_table.c +++ b/libbb/speed_table.c | |||
@@ -4,160 +4,36 @@ | |||
4 | * | 4 | * |
5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> | 5 | * Copyright (C) 2003 Manuel Novoa III <mjn3@codepoet.org> |
6 | * | 6 | * |
7 | * This program is free software; you can redistribute it and/or modify | 7 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
8 | * it under the terms of the GNU General Public License as published by | ||
9 | * the Free Software Foundation; either version 2 of the License, or | ||
10 | * (at your option) any later version. | ||
11 | * | ||
12 | * This program is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU General Public License | ||
18 | * along with this program; if not, write to the Free Software | ||
19 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
20 | * | ||
21 | */ | 8 | */ |
22 | 9 | ||
23 | #include <termios.h> | ||
24 | #include "libbb.h" | 10 | #include "libbb.h" |
25 | 11 | ||
26 | struct speed_map { | 12 | static const unsigned short speeds[] = { |
27 | unsigned short speed; | 13 | 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800, 9600, |
28 | unsigned short value; | 14 | 19200, 38400, 57600>>8, 115200>>8, 230400>>8, 460800>>8, 500000>>8, |
29 | }; | 15 | 576000>>8, 921600>>8, 1000000>>8, 1152000>>8, 1500000>>8, 2000000>>8, |
30 | 16 | 3000000>>8, 3500000>>8, 4000000>>8 | |
31 | static const struct speed_map speeds[] = { | ||
32 | {B0, 0}, | ||
33 | {B50, 50}, | ||
34 | {B75, 75}, | ||
35 | {B110, 110}, | ||
36 | {B134, 134}, | ||
37 | {B150, 150}, | ||
38 | {B200, 200}, | ||
39 | {B300, 300}, | ||
40 | {B600, 600}, | ||
41 | {B1200, 1200}, | ||
42 | {B1800, 1800}, | ||
43 | {B2400, 2400}, | ||
44 | {B4800, 4800}, | ||
45 | {B9600, 9600}, | ||
46 | #ifdef B19200 | ||
47 | {B19200, 19200}, | ||
48 | #elif defined(EXTA) | ||
49 | {EXTA, 19200}, | ||
50 | #endif | ||
51 | #ifdef B38400 | ||
52 | {B38400, 38400/256 + 0x8000U}, | ||
53 | #elif defined(EXTB) | ||
54 | {EXTB, 38400/256 + 0x8000U}, | ||
55 | #endif | ||
56 | #ifdef B57600 | ||
57 | {B57600, 57600/256 + 0x8000U}, | ||
58 | #endif | ||
59 | #ifdef B115200 | ||
60 | {B115200, 115200/256 + 0x8000U}, | ||
61 | #endif | ||
62 | #ifdef B230400 | ||
63 | {B230400, 230400/256 + 0x8000U}, | ||
64 | #endif | ||
65 | #ifdef B460800 | ||
66 | {B460800, 460800/256 + 0x8000U}, | ||
67 | #endif | ||
68 | #ifdef B500000 | ||
69 | {B500000, 500000/256 + 0x8000U}, | ||
70 | #endif | ||
71 | #ifdef B576000 | ||
72 | {B576000, 576000/256 + 0x8000U}, | ||
73 | #endif | ||
74 | #ifdef B921600 | ||
75 | {B921600, 921600/256 + 0x8000U}, | ||
76 | #endif | ||
77 | #ifdef B1000000 | ||
78 | {B1000000, 1000000/256 + 0x8000U}, | ||
79 | #endif | ||
80 | #ifdef B1152000 | ||
81 | {B1152000, 1152000/256 + 0x8000U}, | ||
82 | #endif | ||
83 | #ifdef B1500000 | ||
84 | {B1500000, 1500000/256 + 0x8000U}, | ||
85 | #endif | ||
86 | #ifdef B2000000 | ||
87 | {B2000000, 2000000/256 + 0x8000U}, | ||
88 | #endif | ||
89 | #ifdef B2500000 | ||
90 | {B2500000, 2500000/256 + 0x8000U}, | ||
91 | #endif | ||
92 | #ifdef B3000000 | ||
93 | {B3000000, 3000000/256 + 0x8000U}, | ||
94 | #endif | ||
95 | #ifdef B3500000 | ||
96 | {B3500000, 3500000/256 + 0x8000U}, | ||
97 | #endif | ||
98 | #ifdef B4000000 | ||
99 | {B4000000, 4000000/256 + 0x8000U}, | ||
100 | #endif | ||
101 | }; | 17 | }; |
102 | 18 | ||
103 | enum { NUM_SPEEDS = (sizeof(speeds) / sizeof(struct speed_map)) }; | 19 | unsigned int tty_baud_to_value(speed_t speed) |
104 | |||
105 | unsigned long bb_baud_to_value(speed_t speed) | ||
106 | { | 20 | { |
107 | int i = 0; | 21 | int i; |
108 | 22 | ||
109 | do { | 23 | for (i=0; i<sizeof(speeds) / sizeof(*speeds); i++) |
110 | if (speed == speeds[i].speed) { | 24 | if (speed == speeds[i] * (i>15 ? 256 : 1)) |
111 | if (speeds[i].value & 0x8000U) { | 25 | return i>15 ? (i+4096-14) : i; |
112 | return ((unsigned long) (speeds[i].value) & 0x7fffU) * 256; | ||
113 | } | ||
114 | return speeds[i].value; | ||
115 | } | ||
116 | } while (++i < NUM_SPEEDS); | ||
117 | 26 | ||
118 | return 0; | 27 | return 0; |
119 | } | 28 | } |
120 | 29 | ||
121 | speed_t bb_value_to_baud(unsigned long value) | 30 | speed_t tty_value_to_baud(unsigned int value) |
122 | { | 31 | { |
123 | int i = 0; | 32 | int i; |
124 | 33 | ||
125 | do { | 34 | for (i=0; i<sizeof(speeds) / sizeof(*speeds); i++) |
126 | if (value == bb_baud_to_value(speeds[i].speed)) { | 35 | if (value == (i>15 ? (i+4096-14) : i)) |
127 | return speeds[i].speed; | 36 | return speeds[i] * (i>15 ? 256 : 1); |
128 | } | ||
129 | } while (++i < NUM_SPEEDS); | ||
130 | |||
131 | return (speed_t) - 1; | ||
132 | } | ||
133 | 37 | ||
134 | #if 0 | 38 | return -1; |
135 | /* testing code */ | ||
136 | #include <stdio.h> | ||
137 | |||
138 | int main(void) | ||
139 | { | ||
140 | unsigned long v; | ||
141 | speed_t s; | ||
142 | |||
143 | for (v = 0 ; v < 500000 ; v++) { | ||
144 | s = bb_value_to_baud(v); | ||
145 | if (s == (speed_t) -1) { | ||
146 | continue; | ||
147 | } | ||
148 | printf("v = %lu -- s = %0lo\n", v, (unsigned long) s); | ||
149 | } | ||
150 | |||
151 | printf("-------------------------------\n"); | ||
152 | |||
153 | for (s = 0 ; s < 010017+1 ; s++) { | ||
154 | v = bb_baud_to_value(s); | ||
155 | if (!v) { | ||
156 | continue; | ||
157 | } | ||
158 | printf("v = %lu -- s = %0lo\n", v, (unsigned long) s); | ||
159 | } | ||
160 | |||
161 | return 0; | ||
162 | } | 39 | } |
163 | #endif | ||
diff --git a/loginutils/getty.c b/loginutils/getty.c index 11eb5a050..e68f2cde1 100644 --- a/loginutils/getty.c +++ b/loginutils/getty.c | |||
@@ -287,7 +287,7 @@ static int bcode(const char *s) | |||
287 | if (safe_strtoul((char *)s, &value)) { | 287 | if (safe_strtoul((char *)s, &value)) { |
288 | return -1; | 288 | return -1; |
289 | } | 289 | } |
290 | if ((r = bb_value_to_baud(value)) > 0) { | 290 | if ((r = tty_value_to_baud(value)) > 0) { |
291 | return r; | 291 | return r; |
292 | } | 292 | } |
293 | return 0; | 293 | return 0; |