Aurelien Jacobs pointed out inline functions that could be removed. Doing so

shrank the code a bit.
This commit is contained in:
Rob Landley 2006-06-21 01:49:17 +00:00
parent e5e1a10cd3
commit 399d45f1c6

View File

@ -39,7 +39,6 @@
#define EOT 0x04 #define EOT 0x04
#define ACK 0x06 #define ACK 0x06
#define NAK 0x15 #define NAK 0x15
#define CAN 0x18
#define BS 0x08 #define BS 0x08
/* /*
@ -57,18 +56,6 @@ Cf:
#define TIMEOUT_LONG 10 #define TIMEOUT_LONG 10
#define MAXERRORS 10 #define MAXERRORS 10
static inline void write_byte(int fd, char cc) {
write(fd, &cc, 1);
}
static inline void write_flush(int fd) {
tcdrain(fd);
}
static inline void read_flush(int fd) {
tcflush(fd, TCIFLUSH);
}
static int read_byte(int fd, unsigned int timeout) { static int read_byte(int fd, unsigned int timeout) {
char buf[1]; char buf[1];
int n; int n;
@ -99,11 +86,11 @@ static int receive(char *error_buf, size_t error_buf_size,
#define note_error(fmt,args...) \ #define note_error(fmt,args...) \
snprintf(error_buf, error_buf_size, fmt,##args) snprintf(error_buf, error_buf_size, fmt,##args)
read_flush(ttyfd); /* Flush pending input */
tcflush(ttyfd, TCIFLUSH);
/* Ask for CRC; if we get errors, we will go with checksum */ /* Ask for CRC; if we get errors, we will go with checksum */
write_byte(ttyfd, nak); write(ttyfd, &nak, 1);
write_flush(ttyfd);
for (;;) { for (;;) {
int blockBegin; int blockBegin;
@ -126,8 +113,8 @@ static int receive(char *error_buf, size_t error_buf_size,
break; break;
case EOT: case EOT:
write_byte(ttyfd, ACK); nak = ACK;
write_flush(ttyfd); write(ttyfd, &nak, 1);
goto done; goto done;
default: default:
@ -232,8 +219,8 @@ static int receive(char *error_buf, size_t error_buf_size,
next: next:
errors = 0; errors = 0;
write_byte(ttyfd, ACK); nak = ACK;
write_flush(ttyfd); write(ttyfd, &nak, 1);
continue; continue;
error: error:
@ -241,7 +228,6 @@ static int receive(char *error_buf, size_t error_buf_size,
errors++; errors++;
if (errors == MAXERRORS) { if (errors == MAXERRORS) {
/* Abort */ /* Abort */
int i;
// if using crc, try again w/o crc // if using crc, try again w/o crc
if (nak == 'C') { if (nak == 'C') {
@ -254,17 +240,15 @@ static int receive(char *error_buf, size_t error_buf_size,
note_error("too many errors; giving up"); note_error("too many errors; giving up");
fatal: fatal:
for (i = 0; i < 5; i ++) /* 5 CAN followed by 5 BS */
write_byte(ttyfd, CAN); write(ttyfd, "\030\030\030\030\030\010\010\010\010\010", 10);
for (i = 0; i < 5; i ++)
write_byte(ttyfd, BS);
write_flush(ttyfd);
return -1; return -1;
} }
read_flush(ttyfd); /* Flush pending input */
write_byte(ttyfd, nak); tcflush(ttyfd, TCIFLUSH);
write_flush(ttyfd);
write(ttyfd, &nak, 1);
} }
done: done: