Permalink
Browse files

update code to use consistent bracing conventions

This is purely a coding style update.  Most of it is moving braces to be
consistent with the other code.  Some braces were also added for
clarity.
  • Loading branch information...
ossguy committed Mar 2, 2009
1 parent f207962 commit 82fbd62156ac5afdb700109e1609098d935b690f
Showing with 39 additions and 49 deletions.
  1. +11 −23 bitconvert.c
  2. +15 −12 combine.c
  3. +13 −14 driver.c
View
@@ -48,17 +48,14 @@ void (*send_error)(const char*);
char to_ascii(char bits, unsigned char value)
{
- if (5 == bits)
- {
+ if (5 == bits) {
/* the BCD encoding is the subset of ASCII beginning at
* character 48 ('0'), ending at character 63; see
* http://www.cyberd.co.uk/support/technotes/isocards.htm
* http://en.wikipedia.org/wiki/ASCII#ASCII_printable_characters
*/
return '0' + value;
- }
- else if (7 == bits)
- {
+ } else if (7 == bits) {
/* the ALPHA encoding is the subset of ASCII beginning at
* character 32 (' '), ending at character 95; see
* http://www.cyberd.co.uk/support/technotes/isocards.htm
@@ -96,45 +93,37 @@ int bc_decode_format(char* bits, char** result, unsigned char format_bits)
*result = malloc( ((bits_len - start_idx) / format_bits) + 1 );
result_idx = 0;
- for (i = start_idx; (i + format_bits) <= bits_len; i += format_bits)
- {
+ for (i = start_idx; (i + format_bits) <= bits_len; i += format_bits) {
current_value = 0;
parity = 1;
- for (j = 0; j < (format_bits - 1); j++)
- {
- if ('1' == bits[i + j])
- {
+ for (j = 0; j < (format_bits - 1); j++) {
+ if ('1' == bits[i + j]) {
/* push a 1 onto the front of our accumulator */
current_value |= (1 << j);
parity ^= 1; /* flip parity bit */
- }
- /* assimilating a 0 is a no-op */
- else if ('0' != bits[i + j])
- {
+ } else if ('0' != bits[i + j]) {
retval = BCERR_INVALID_INPUT;
break;
}
+ /* assimilating a 0 is a no-op */
}
/* since C doesn't have multi-level breaks */
- if (0 != retval)
- {
+ if (0 != retval) {
break;
}
- if ("01"[parity] != bits[i + j])
- {
+ if ("01"[parity] != bits[i + j]) {
retval = BCERR_PARITY_MISMATCH;
break;
}
(*result)[result_idx] = to_ascii(format_bits, current_value);
result_idx++;
- if ('?' == (*result)[result_idx - 1])
- {
+ if ('?' == (*result)[result_idx - 1]) {
/* found end sentinel; we're done */
break;
}
@@ -666,8 +655,7 @@ int bc_combine(struct bc_input* forward, struct bc_input* backward,
const char* bc_strerror(int err)
{
- switch (err)
- {
+ switch (err) {
case 0: return "Success";
case BCERR_INVALID_INPUT: return "Invalid input";
case BCERR_PARITY_MISMATCH: return "Parity mismatch";
View
@@ -28,15 +28,13 @@ char* get_track(FILE* input, char* bits, int bits_len)
{
int bits_end;
- if (NULL == fgets(bits, bits_len, input))
- {
+ if (NULL == fgets(bits, bits_len, input)) {
return NULL;
}
bits_end = strlen(bits);
/* strip trailing newline */
- if ('\n' == bits[bits_end - 1])
- {
+ if ('\n' == bits[bits_end - 1]) {
bits[bits_end - 1] = '\0';
}
@@ -65,21 +63,26 @@ int main(void)
input = stdin;
bc_init(print_error);
- while (1)
- {
- if (NULL == get_track(input, ft1, sizeof(ft1)))
+ while (1) {
+ if (NULL == get_track(input, ft1, sizeof(ft1))) {
break;
- if (NULL == get_track(input, ft2, sizeof(ft2)))
+ }
+ if (NULL == get_track(input, ft2, sizeof(ft2))) {
break;
- if (NULL == get_track(input, ft3, sizeof(ft3)))
+ }
+ if (NULL == get_track(input, ft3, sizeof(ft3))) {
break;
+ }
- if (NULL == get_track(input, bt1, sizeof(bt1)))
+ if (NULL == get_track(input, bt1, sizeof(bt1))) {
break;
- if (NULL == get_track(input, bt2, sizeof(bt2)))
+ }
+ if (NULL == get_track(input, bt2, sizeof(bt2))) {
break;
- if (NULL == get_track(input, bt3, sizeof(bt3)))
+ }
+ if (NULL == get_track(input, bt3, sizeof(bt3))) {
break;
+ }
forward.t1 = ft1;
forward.t2 = ft2;
View
@@ -28,15 +28,13 @@ char* get_track(FILE* input, char* bits, int bits_len)
{
int bits_end;
- if (NULL == fgets(bits, bits_len, input))
- {
+ if (NULL == fgets(bits, bits_len, input)) {
return NULL;
}
bits_end = strlen(bits);
/* strip trailing newline */
- if ('\n' == bits[bits_end - 1])
- {
+ if ('\n' == bits[bits_end - 1]) {
bits[bits_end - 1] = '\0';
}
@@ -74,14 +72,16 @@ int main(void)
input = stdin;
bc_init(print_error);
- while (1)
- {
- if (NULL == get_track(input, t1, sizeof(t1)))
+ while (1) {
+ if (NULL == get_track(input, t1, sizeof(t1))) {
break;
- if (NULL == get_track(input, t2, sizeof(t2)))
+ }
+ if (NULL == get_track(input, t2, sizeof(t2))) {
break;
- if (NULL == get_track(input, t3, sizeof(t3)))
+ }
+ if (NULL == get_track(input, t3, sizeof(t3))) {
break;
+ }
in.t1 = t1;
in.t2 = t2;
@@ -111,22 +111,21 @@ int main(void)
encoding_to_str(result.t3_encoding), result.t3);
}
- if (0 != rv)
+ if (0 != rv) {
/* if there was an error, bc_find_fields isn't useful */
continue;
+ }
rv = bc_find_fields(&result);
- if (0 != rv)
- {
+ if (0 != rv) {
printf("Error %d (%s); no fields found for this card\n",
rv, bc_strerror(rv));
continue;
}
printf("\n=== Fields ===\n");
printf("Card name: %s\n", result.name);
- for (i = 0; result.field_names[i] != NULL; i++)
- {
+ for (i = 0; result.field_names[i] != NULL; i++) {
/* NOTE: you should verify that the BC_TRACK_* constants
* in the version of libbitconvert that you are using
* map cleanly onto integers if you wish to print the

0 comments on commit 82fbd62

Please sign in to comment.