replace printf() used for debugging by fprintf()

This commit is contained in:
marschap
2005-07-03 18:03:10 +00:00
parent a73fab8867
commit 448c39f63c
+14 -14
View File
@@ -62,7 +62,7 @@ void EmptyKeyRing(KeyRing *kr)
int AddKeyToKeyRing(KeyRing *kr, unsigned char key) int AddKeyToKeyRing(KeyRing *kr, unsigned char key)
{ {
if (((kr->head + 1) % KEYRINGSIZE) != (kr->tail % KEYRINGSIZE)) { if (((kr->head + 1) % KEYRINGSIZE) != (kr->tail % KEYRINGSIZE)) {
/* printf("We add key: %d\n", key); */ /* fprintf(stderr, "We add key: %d\n", key); */
kr->contents[kr->head % KEYRINGSIZE] = key; kr->contents[kr->head % KEYRINGSIZE] = key;
kr->head = (kr->head + 1) % KEYRINGSIZE; kr->head = (kr->head + 1) % KEYRINGSIZE;
@@ -86,7 +86,7 @@ unsigned char GetKeyFromKeyRing(KeyRing *kr)
kr->tail = (kr->tail + 1) % KEYRINGSIZE; kr->tail = (kr->tail + 1) % KEYRINGSIZE;
} }
/* if (retval) printf("We remove key: %d\n", retval); */ /* if (retval) fprintf(stderr, "We remove key: %d\n", retval); */
return retval; return retval;
} }
@@ -254,25 +254,25 @@ void SyncReceiveBuffer(ReceiveBuffer *rb, int fd, unsigned int number)
BytesRead = read(fd, buffer, number); BytesRead = read(fd, buffer, number);
if (BytesRead == -1) { if (BytesRead == -1) {
/* printf("~~~Problem reading: %s .\n", strerror(errno)); */ /* fprintf(stderr, "~~~Problem reading: %s .\n", strerror(errno)); */
} }
else { else {
int i; int i;
/* printf("Read %d Bytes:", BytesRead); */ /* fprintf(stderr, "Read %d Bytes:", BytesRead); */
/* wrap write pointer to the receive buffer */ /* wrap write pointer to the receive buffer */
rb->head %= RECEIVEBUFFERSIZE; rb->head %= RECEIVEBUFFERSIZE;
/* store the bytes read */ /* store the bytes read */
for (i = 0; i < BytesRead; i++) { for (i = 0; i < BytesRead; i++) {
/* printf(" %02x", buffer[i]); */ /* fprintf(stderr, " %02x", buffer[i]); */
rb->contents[rb->head] = buffer[i]; rb->contents[rb->head] = buffer[i];
/* increment write pointer (wrap if needed) */ /* increment write pointer (wrap if needed) */
rb->head = (rb->head + 1) % RECEIVEBUFFERSIZE; rb->head = (rb->head + 1) % RECEIVEBUFFERSIZE;
} }
/* printf("\n"); */ /* fprintf(stderr, "\n"); */
} }
} }
@@ -416,7 +416,7 @@ check_for_packet(int fd, unsigned char expected_length)
//First off, there must be at least 4 bytes available in the input stream //First off, there must be at least 4 bytes available in the input stream
//for there to be a valid command in it (command, length, no data, CRC). //for there to be a valid command in it (command, length, no data, CRC).
if (BytesAvail(&receivebuffer) < 4) { if (BytesAvail(&receivebuffer) < 4) {
/* printf("Not enough byte available for even the smallest message.\n"); */ /* fprintf(stderr, "Not enough bytes available for even the smallest message.\n"); */
return(GIVE_UP); /* We don't need to retry before more byte are received */ return(GIVE_UP); /* We don't need to retry before more byte are received */
} }
@@ -430,7 +430,7 @@ check_for_packet(int fd, unsigned char expected_length)
if (MAX_COMMAND < (0x3F & incoming_command.command)) { if (MAX_COMMAND < (0x3F & incoming_command.command)) {
/* Throw out one byte of garbage. Next pass through should re-sync. */ /* Throw out one byte of garbage. Next pass through should re-sync. */
GetByte(&receivebuffer); GetByte(&receivebuffer);
/* printf("###: Unknown command.\n"); */ /* fprintf(stderr, "###: Unknown command.\n"); */
return(TRY_AGAIN); return(TRY_AGAIN);
} }
@@ -441,7 +441,7 @@ check_for_packet(int fd, unsigned char expected_length)
if (MAX_DATA_LENGTH < incoming_command.data_length) { if (MAX_DATA_LENGTH < incoming_command.data_length) {
//Throw out one byte of garbage. Next pass through should re-sync. //Throw out one byte of garbage. Next pass through should re-sync.
GetByte(&receivebuffer); GetByte(&receivebuffer);
/* printf("###: Too long packet: %d.\n", incoming_command.data_length); */ /* fprintf(stderr, "###: Too long packet: %d.\n", incoming_command.data_length); */
return(TRY_AGAIN); return(TRY_AGAIN);
} }
@@ -450,7 +450,7 @@ check_for_packet(int fd, unsigned char expected_length)
if ((int) PeekBytesAvail(&receivebuffer) < (incoming_command.data_length + 2)) { if ((int) PeekBytesAvail(&receivebuffer) < (incoming_command.data_length + 2)) {
//It looked like a valid start of a packet, but it does not look //It looked like a valid start of a packet, but it does not look
//like the complete packet has been received yet. //like the complete packet has been received yet.
/* printf("Not enough read to check the complete message.\n"); */ /* fprintf(stderr, "Not enough read to check the complete message.\n"); */
return(GIVE_UP); /* Let's not return until more byte are available */ return(GIVE_UP); /* Let's not return until more byte are available */
} }
@@ -482,7 +482,7 @@ check_for_packet(int fd, unsigned char expected_length)
* Next pass through should re-sync. * Next pass through should re-sync.
*/ */
GetByte(&receivebuffer); GetByte(&receivebuffer);
/* printf("###: Wrong CheckSum. computed/real %04x:%04x \n", /* fprintf(stderr, "###: Wrong CheckSum. computed/real %04x:%04x \n",
testcrc, incoming_command.crc.as_word); */ testcrc, incoming_command.crc.as_word); */
return(TRY_AGAIN); return(TRY_AGAIN);
} }
@@ -502,12 +502,12 @@ print_packet(COMMAND_PACKET *packet)
cmd = (0x3F & (packet->command)); cmd = (0x3F & (packet->command));
len = packet->data_length; len = packet->data_length;
printf("Message (%d,%d) %d [", top, cmd, len); fprintf(stderr, "Message (%d,%d) %d [", top, cmd, len);
//There is enough data to make a packet. Transfer over the data. //There is enough data to make a packet. Transfer over the data.
for (i = 0; i < packet->data_length; i++) for (i = 0; i < packet->data_length; i++)
printf(" %02x", packet->data[i]); fprintf(stderr, " %02x", packet->data[i]);
printf(" ] %02x %02x .\n", packet->crc.as_bytes[0], packet->crc.as_bytes[1]); fprintf(stderr, " ] %02x %02x .\n", packet->crc.as_bytes[0], packet->crc.as_bytes[1]);
} }