style change (bsd-like)
This commit is contained in:
parent
2a770f0987
commit
1ba417f8b0
4 changed files with 20 additions and 21 deletions
11
args.c
11
args.c
|
@ -6,14 +6,15 @@
|
|||
*/
|
||||
|
||||
#include "args.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
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;
|
||||
if (temp[1])
|
||||
return temp + 1;
|
||||
|
@ -22,13 +23,13 @@ static char* nextarg()
|
|||
return argv[argi];
|
||||
}
|
||||
|
||||
void args_parse(int argc_, char** argv_,
|
||||
void args_parse(int argc_, char **argv_,
|
||||
void flagfn(char, char*()), void plainfn(char*))
|
||||
{
|
||||
argc = argc_;
|
||||
argv = argv_;
|
||||
for (argi = 1; argi < argc; argi++) {
|
||||
char* arg = argv[argi];
|
||||
char *arg = argv[argi];
|
||||
if (!arg[0])
|
||||
continue;
|
||||
|
||||
|
|
2
args.h
2
args.h
|
@ -5,6 +5,6 @@
|
|||
* 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*));
|
||||
|
||||
|
|
14
crc32.h
14
crc32.h
|
@ -25,8 +25,8 @@ void crc_set_polynomial(ulong p);
|
|||
|
||||
static char crc_big_endian = 0;
|
||||
static const int crc_table_size = 0x100;
|
||||
static ulong* crc_be_table = NULL; /* big endian */
|
||||
static ulong* crc_le_table = NULL; /* little endian */
|
||||
static ulong *crc_be_table = NULL; /* big endian */
|
||||
static ulong *crc_le_table = NULL; /* little endian */
|
||||
static ulong crc_polynomial = 0x04C11DB7;
|
||||
|
||||
ulong crc_reflect(ulong input)
|
||||
|
@ -41,9 +41,9 @@ ulong crc_reflect(ulong input)
|
|||
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)
|
||||
exit(1);
|
||||
return p;
|
||||
|
@ -137,15 +137,13 @@ void crc_cycle(ulong *remainder, char c)
|
|||
{
|
||||
crc_fill_tables_once();
|
||||
if (crc_big_endian) {
|
||||
const ulong newByte = crc_be_table[
|
||||
((*remainder) >> 24) ^ c];
|
||||
const ulong newByte = crc_be_table[((*remainder) >> 24) ^ c];
|
||||
/* printf("%08X00 ^ %08X =\n",
|
||||
(int)(*remainder), (int)newByte); */
|
||||
*remainder = ((*remainder) << 8) ^ newByte;
|
||||
*remainder &= 0xFFFFFFFF;
|
||||
} else {
|
||||
const ulong newByte = crc_le_table[
|
||||
((*remainder) ^ c) & 0xFF];
|
||||
const ulong newByte = crc_le_table[((*remainder) ^ c) & 0xFF];
|
||||
/* printf(" %08X ^ %08X =\n",
|
||||
(int)((*remainder) >> 8), (int)newByte); */
|
||||
*remainder = ((*remainder) >> 8) ^ newByte;
|
||||
|
|
8
main.c
8
main.c
|
@ -20,8 +20,8 @@
|
|||
|
||||
static ulong remainder = 0xFFFFFFFF;
|
||||
|
||||
static FILE* input_stream = NULL;
|
||||
static char* input_filename = "-";
|
||||
static FILE *input_stream = NULL;
|
||||
static char *input_filename = "-";
|
||||
static char print_binary = 0;
|
||||
static char xor_output = 1;
|
||||
static char reflect_output = 0;
|
||||
|
@ -43,7 +43,7 @@ const char help2[] = "\
|
|||
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 */
|
||||
switch (flag) {
|
||||
case 'h':
|
||||
|
@ -119,7 +119,7 @@ static void print_crc()
|
|||
printf("%08X\n", (int) remainder);
|
||||
}
|
||||
|
||||
int main(int argc, char** argv)
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
crc_set_little_endian();
|
||||
args_parse(argc, argv, handle_flag, NULL);
|
||||
|
|
Loading…
Add table
Reference in a new issue