style change (bsd-like)

This commit is contained in:
Connor Olding 2012-08-04 07:24:04 -07:00
parent 2a770f0987
commit 1ba417f8b0
4 changed files with 20 additions and 21 deletions

13
args.c
View File

@ -6,14 +6,15 @@
*/ */
#include "args.h" #include "args.h"
#include <stddef.h> #include <stddef.h>
static int argc, argi; static int argc, argi;
static char** argv, * flag; static char **argv, *flag;
static char* nextarg() static char *nextarg()
{ {
char* temp = flag; char *temp = flag;
flag = NULL; flag = NULL;
if (temp[1]) if (temp[1])
return temp + 1; return temp + 1;
@ -22,13 +23,13 @@ static char* nextarg()
return argv[argi]; return argv[argi];
} }
void args_parse(int argc_, char** argv_, void args_parse(int argc_, char **argv_,
void flagfn(char, char*()), void plainfn(char*)) void flagfn(char, char*()), void plainfn(char*))
{ {
argc = argc_; argc = argc_;
argv = argv_; argv = argv_;
for (argi = 1; argi < argc; argi++) { for (argi = 1; argi < argc; argi++) {
char* arg = argv[argi]; char *arg = argv[argi];
if (!arg[0]) if (!arg[0])
continue; continue;

4
args.h
View File

@ -5,6 +5,6 @@
* copy of the license along with this program; see the file LICENSE. * copy of the license along with this program; see the file LICENSE.
*/ */
void args_parse(int argc, char** argv, void args_parse(int argc, char **argv,
void flagfn(char, char*()), void plainfn(char*)); void flagfn(char, char*()), void plainfn(char*));

14
crc32.h
View File

@ -25,8 +25,8 @@ void crc_set_polynomial(ulong p);
static char crc_big_endian = 0; static char crc_big_endian = 0;
static const int crc_table_size = 0x100; static const int crc_table_size = 0x100;
static ulong* crc_be_table = NULL; /* big endian */ static ulong *crc_be_table = NULL; /* big endian */
static ulong* crc_le_table = NULL; /* little endian */ static ulong *crc_le_table = NULL; /* little endian */
static ulong crc_polynomial = 0x04C11DB7; static ulong crc_polynomial = 0x04C11DB7;
ulong crc_reflect(ulong input) ulong crc_reflect(ulong input)
@ -41,9 +41,9 @@ ulong crc_reflect(ulong input)
return reflected; return reflected;
} }
static ulong* crc_alloc(size_t size) static ulong *crc_alloc(size_t size)
{ {
ulong* p = (ulong*) malloc(size * sizeof(ulong)); ulong *p = (ulong*) malloc(size * sizeof(ulong));
if (p == NULL) if (p == NULL)
exit(1); exit(1);
return p; return p;
@ -137,15 +137,13 @@ void crc_cycle(ulong *remainder, char c)
{ {
crc_fill_tables_once(); crc_fill_tables_once();
if (crc_big_endian) { if (crc_big_endian) {
const ulong newByte = crc_be_table[ const ulong newByte = crc_be_table[((*remainder) >> 24) ^ c];
((*remainder) >> 24) ^ c];
/* printf("%08X00 ^ %08X =\n", /* printf("%08X00 ^ %08X =\n",
(int)(*remainder), (int)newByte); */ (int)(*remainder), (int)newByte); */
*remainder = ((*remainder) << 8) ^ newByte; *remainder = ((*remainder) << 8) ^ newByte;
*remainder &= 0xFFFFFFFF; *remainder &= 0xFFFFFFFF;
} else { } else {
const ulong newByte = crc_le_table[ const ulong newByte = crc_le_table[((*remainder) ^ c) & 0xFF];
((*remainder) ^ c) & 0xFF];
/* printf(" %08X ^ %08X =\n", /* printf(" %08X ^ %08X =\n",
(int)((*remainder) >> 8), (int)newByte); */ (int)((*remainder) >> 8), (int)newByte); */
*remainder = ((*remainder) >> 8) ^ newByte; *remainder = ((*remainder) >> 8) ^ newByte;

10
main.c
View File

@ -20,8 +20,8 @@
static ulong remainder = 0xFFFFFFFF; static ulong remainder = 0xFFFFFFFF;
static FILE* input_stream = NULL; static FILE *input_stream = NULL;
static char* input_filename = "-"; static char *input_filename = "-";
static char print_binary = 0; static char print_binary = 0;
static char xor_output = 1; static char xor_output = 1;
static char reflect_output = 0; static char reflect_output = 0;
@ -43,7 +43,7 @@ const char help2[] = "\
numbers <n> may be entered as hexadecimal or octal with prefixes\n\ numbers <n> may be entered as hexadecimal or octal with prefixes\n\
"; ";
void handle_flag(char flag, char* (*nextarg)()) { void handle_flag(char flag, char *(*nextarg)()) {
/* TODO: check for NULL on nextarg */ /* TODO: check for NULL on nextarg */
switch (flag) { switch (flag) {
case 'h': case 'h':
@ -87,7 +87,7 @@ static void open_stream()
} }
if (input_stream == NULL) { if (input_stream == NULL) {
fprintf(stderr, "Could not open file for reading: %s\n", fprintf(stderr, "Could not open file for reading: %s\n",
input_filename); input_filename);
exit(1); exit(1);
} }
} }
@ -119,7 +119,7 @@ static void print_crc()
printf("%08X\n", (int) remainder); printf("%08X\n", (int) remainder);
} }
int main(int argc, char** argv) int main(int argc, char **argv)
{ {
crc_set_little_endian(); crc_set_little_endian();
args_parse(argc, argv, handle_flag, NULL); args_parse(argc, argv, handle_flag, NULL);