diff options
| author | Rob Landley <rob@landley.net> | 2006-06-21 01:49:17 +0000 |
|---|---|---|
| committer | Rob Landley <rob@landley.net> | 2006-06-21 01:49:17 +0000 |
| commit | 399d45f1c6ecfedac9801978b6ec85239142ed8d (patch) | |
| tree | 79117d78dcf9c3eddae4aefed235d3a61d23498f /miscutils | |
| parent | e5e1a10cd32e94ccd1031de98c25ed7ba2853e29 (diff) | |
| download | busybox-w32-399d45f1c6ecfedac9801978b6ec85239142ed8d.tar.gz busybox-w32-399d45f1c6ecfedac9801978b6ec85239142ed8d.tar.bz2 busybox-w32-399d45f1c6ecfedac9801978b6ec85239142ed8d.zip | |
Aurelien Jacobs pointed out inline functions that could be removed. Doing so
shrank the code a bit.
Diffstat (limited to 'miscutils')
| -rw-r--r-- | miscutils/rx.c | 42 |
1 files changed, 13 insertions, 29 deletions
diff --git a/miscutils/rx.c b/miscutils/rx.c index 7642094b7..cff5a627b 100644 --- a/miscutils/rx.c +++ b/miscutils/rx.c | |||
| @@ -39,7 +39,6 @@ | |||
| 39 | #define EOT 0x04 | 39 | #define EOT 0x04 |
| 40 | #define ACK 0x06 | 40 | #define ACK 0x06 |
| 41 | #define NAK 0x15 | 41 | #define NAK 0x15 |
| 42 | #define CAN 0x18 | ||
| 43 | #define BS 0x08 | 42 | #define BS 0x08 |
| 44 | 43 | ||
| 45 | /* | 44 | /* |
| @@ -57,18 +56,6 @@ Cf: | |||
| 57 | #define TIMEOUT_LONG 10 | 56 | #define TIMEOUT_LONG 10 |
| 58 | #define MAXERRORS 10 | 57 | #define MAXERRORS 10 |
| 59 | 58 | ||
| 60 | static inline void write_byte(int fd, char cc) { | ||
| 61 | write(fd, &cc, 1); | ||
| 62 | } | ||
| 63 | |||
| 64 | static inline void write_flush(int fd) { | ||
| 65 | tcdrain(fd); | ||
| 66 | } | ||
| 67 | |||
| 68 | static inline void read_flush(int fd) { | ||
| 69 | tcflush(fd, TCIFLUSH); | ||
| 70 | } | ||
| 71 | |||
| 72 | static int read_byte(int fd, unsigned int timeout) { | 59 | static int read_byte(int fd, unsigned int timeout) { |
| 73 | char buf[1]; | 60 | char buf[1]; |
| 74 | int n; | 61 | int n; |
| @@ -99,11 +86,11 @@ static int receive(char *error_buf, size_t error_buf_size, | |||
| 99 | #define note_error(fmt,args...) \ | 86 | #define note_error(fmt,args...) \ |
| 100 | snprintf(error_buf, error_buf_size, fmt,##args) | 87 | snprintf(error_buf, error_buf_size, fmt,##args) |
| 101 | 88 | ||
| 102 | read_flush(ttyfd); | 89 | /* Flush pending input */ |
| 90 | tcflush(ttyfd, TCIFLUSH); | ||
| 103 | 91 | ||
| 104 | /* Ask for CRC; if we get errors, we will go with checksum */ | 92 | /* Ask for CRC; if we get errors, we will go with checksum */ |
| 105 | write_byte(ttyfd, nak); | 93 | write(ttyfd, &nak, 1); |
| 106 | write_flush(ttyfd); | ||
| 107 | 94 | ||
| 108 | for (;;) { | 95 | for (;;) { |
| 109 | int blockBegin; | 96 | int blockBegin; |
| @@ -126,8 +113,8 @@ static int receive(char *error_buf, size_t error_buf_size, | |||
| 126 | break; | 113 | break; |
| 127 | 114 | ||
| 128 | case EOT: | 115 | case EOT: |
| 129 | write_byte(ttyfd, ACK); | 116 | nak = ACK; |
| 130 | write_flush(ttyfd); | 117 | write(ttyfd, &nak, 1); |
| 131 | goto done; | 118 | goto done; |
| 132 | 119 | ||
| 133 | default: | 120 | default: |
| @@ -232,8 +219,8 @@ static int receive(char *error_buf, size_t error_buf_size, | |||
| 232 | 219 | ||
| 233 | next: | 220 | next: |
| 234 | errors = 0; | 221 | errors = 0; |
| 235 | write_byte(ttyfd, ACK); | 222 | nak = ACK; |
| 236 | write_flush(ttyfd); | 223 | write(ttyfd, &nak, 1); |
| 237 | continue; | 224 | continue; |
| 238 | 225 | ||
| 239 | error: | 226 | error: |
| @@ -241,7 +228,6 @@ static int receive(char *error_buf, size_t error_buf_size, | |||
| 241 | errors++; | 228 | errors++; |
| 242 | if (errors == MAXERRORS) { | 229 | if (errors == MAXERRORS) { |
| 243 | /* Abort */ | 230 | /* Abort */ |
| 244 | int i; | ||
| 245 | 231 | ||
| 246 | // if using crc, try again w/o crc | 232 | // if using crc, try again w/o crc |
| 247 | if (nak == 'C') { | 233 | if (nak == 'C') { |
| @@ -254,17 +240,15 @@ static int receive(char *error_buf, size_t error_buf_size, | |||
| 254 | note_error("too many errors; giving up"); | 240 | note_error("too many errors; giving up"); |
| 255 | 241 | ||
| 256 | fatal: | 242 | fatal: |
| 257 | for (i = 0; i < 5; i ++) | 243 | /* 5 CAN followed by 5 BS */ |
| 258 | write_byte(ttyfd, CAN); | 244 | write(ttyfd, "\030\030\030\030\030\010\010\010\010\010", 10); |
| 259 | for (i = 0; i < 5; i ++) | ||
| 260 | write_byte(ttyfd, BS); | ||
| 261 | write_flush(ttyfd); | ||
| 262 | return -1; | 245 | return -1; |
| 263 | } | 246 | } |
| 264 | 247 | ||
| 265 | read_flush(ttyfd); | 248 | /* Flush pending input */ |
| 266 | write_byte(ttyfd, nak); | 249 | tcflush(ttyfd, TCIFLUSH); |
| 267 | write_flush(ttyfd); | 250 | |
| 251 | write(ttyfd, &nak, 1); | ||
| 268 | } | 252 | } |
| 269 | 253 | ||
| 270 | done: | 254 | done: |
