Skip to content

Commit

Permalink
indent cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
ninjix committed Feb 2, 2011
1 parent 60509fa commit 353fb39
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 56 deletions.
1 change: 1 addition & 0 deletions kernel.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ void add_entropy(char data[8])

close(rnd);
}

12 changes: 6 additions & 6 deletions macros.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#include <stdio.h>
#include <stdlib.h>

#define SUCCESS_E(X, E) if ((X) == (E)) {\
perror(#X);\
exit(EXIT_FAILURE);\
#define SUCCESS_E(X, E) if ((X) == (E)) { \
perror(# X); \
exit(EXIT_FAILURE); \
}
#define SUCCESS(X) SUCCESS_E((X), -1)

#define EXIT_SYNTAX 2

#define TO_INT(SRC, DST, NAME) if ((SRC) != NULL && sscanf((SRC), "%d", &(DST)) != 1) {\
fprintf(stderr, NAME " must be an integer: %s\n", (SRC));\
return EXIT_SYNTAX;\
#define TO_INT(SRC, DST, NAME) if ((SRC) != NULL && sscanf((SRC), "%d", &(DST)) != 1) { \
fprintf(stderr, NAME " must be an integer: %s\n", (SRC)); \
return EXIT_SYNTAX; \
}

/* This should be set to half the maximum pool size, in bytes */
Expand Down
103 changes: 53 additions & 50 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,73 +34,76 @@
/* Command line parsing */

typedef struct options_s {
char * args[1]; char * sleep_i; int verbose;
char * args[1]; char * sleep_i; int verbose;
} options;

const char * argp_program_version = "rng-usleep 0.2";
const char * argp_program_bug_address = "<[email protected]>";
static char argp_arg[] = "[LENGTH]";
static char argp_doc[] =
"Generate random data from the practical time variations of usleep(3). "
"If LENGTH is omitted, will generate until terminated. ";
"Generate random data from the practical time variations of usleep(3). "
"If LENGTH is omitted, will generate until terminated. ";
static struct argp_option optinfo[] = {
{ "verbose", 'v', 0, 0, "Provide extra information." },
{ "interval", 'i', "TIME", 0,
"Time in microseconds to sleep for (default 40). On top of this, there "
"is processing overhead, typically in the order of a few dozen us. " },
{ 0 }
{ "verbose", 'v', 0, 0, "Provide extra information." },
{ "interval", 'i', "TIME", 0,
"Time in microseconds to sleep for (default 40). On top of this, there "
"is processing overhead, typically in the order of a few dozen us. " },
{ 0 }
};

static error_t parse_opt(int key, char * arg, struct argp_state * state){
options * opts = state->input;

switch (key) {
case ARGP_KEY_ARG:
if (state->arg_num >= 1) {
argp_usage(state);
}
opts->args[state->arg_num] = arg;
break;
case ARGP_KEY_END:
if (state->arg_num < 0) {
argp_usage(state);
}
break;
case 'i':
opts->sleep_i = arg;
break;
case 'v':
opts->verbose = 1;
break;
default:
return ARGP_ERR_UNKNOWN;
} /* switch */

return 0;
static error_t parse_opt(int key, char * arg, struct argp_state * state)
{
options * opts = state->input;

switch (key) {
case ARGP_KEY_ARG:
if (state->arg_num >= 1) {
argp_usage(state);
}
opts->args[state->arg_num] = arg;
break;
case ARGP_KEY_END:
if (state->arg_num < 0) {
argp_usage(state);
}
break;
case 'i':
opts->sleep_i = arg;
break;
case 'v':
opts->verbose = 1;
break;
default:
return ARGP_ERR_UNKNOWN;
} /* switch */

return 0;
} /* parse_opt */

static struct argp argp = { optinfo, parse_opt, argp_arg, argp_doc };

int main(int argc, char * argv[]){
int main(int argc, char * argv[])
{

options opts = { { NULL }, NULL, 0 };
options opts = { { NULL }, NULL, 0 };

argp_parse(&argp, argc, argv, 0, 0, &opts);
argp_parse(&argp, argc, argv, 0, 0, &opts);

int length = 0, sleep_i = 40;
TO_INT(opts.args[0], length, "LENGTH");
TO_INT(opts.sleep_i, sleep_i, "TIME");
int length = 0, sleep_i = 40;
TO_INT(opts.args[0], length, "LENGTH");
TO_INT(opts.sleep_i, sleep_i, "TIME");

char * len_str, * pad_str;
len_str = (length) ? opts.args[0] : "";
pad_str = (length) ? " " : "";
char * len_str, * pad_str;
len_str = (length) ? opts.args[0] : "";
pad_str = (length) ? " " : "";

fprintf(stderr, "generating %s%srandom bytes @ %d+c us/bit\n",
len_str, pad_str, sleep_i);
fprintf(stderr, "generating %s%srandom bytes @ %d+c us/bit\n",
len_str, pad_str, sleep_i);

if (daemon(-1, -1) == -1)
printf("%s\n", "failed to become daemon process");
if (daemon(-1, -1) == -1)
printf("%s\n", "failed to become daemon process");

generate_random(length, sleep_i);
return EXIT_SUCCESS;
}

generate_random(length, sleep_i);
return EXIT_SUCCESS;
}

0 comments on commit 353fb39

Please sign in to comment.