Skip to content

Commit fdc6eb1

Browse files
committed
Working on option parsing.
1 parent 8feb588 commit fdc6eb1

File tree

1 file changed

+61
-3
lines changed

1 file changed

+61
-3
lines changed

src/params.c

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "utils.h"
1515
#include "input.h"
1616
#include "output.h"
17+
#include "random.h"
1718

1819
params* new_params() {
1920
params* p = calloc(sizeof(params), 1);
@@ -56,10 +57,67 @@ void dispose_params(params* p) {
5657
free(p);
5758
}
5859

59-
char doc[] = "A program with a help and default options";
60-
struct argp argp = { NULL, NULL, NULL, doc };
60+
static int parse_opt(int key, char* arg, struct argp_state* state) {
61+
int* arg_count = state->input;
62+
switch (key) {
63+
case 'i': {
64+
printf("in: %s\n", arg);
65+
}
66+
break;
67+
case 'o': {
68+
printf("out: %s\n", arg);
69+
}
70+
break;
71+
case 'c': {
72+
printf("count: %s\n", arg);
73+
}
74+
break;
75+
case 1000: {
76+
printf("low: %s\n", arg);
77+
}
78+
break;
79+
case 1001: {
80+
printf("high: %s\n", arg);
81+
}
82+
break;
83+
case ARGP_KEY_INIT: {
84+
printf("INIT\n");
85+
}
86+
break;
87+
case ARGP_KEY_ARG: {
88+
printf("arg: %s\n", arg);
89+
}
90+
break;
91+
case ARGP_KEY_END: {
92+
printf("END\n");
93+
}
94+
break;
95+
}
96+
return 0;
97+
}
98+
99+
struct argp_option options[] = {
100+
{"in", 'i', "[random|hex|bits|cards|dice|base6|base10|ints|bip39|slip39]", 0, "Specify the input format (default: random)"},
101+
{"out", 'o', "[hex|bits|cards|dice|base6|base10|ints|bip39|slip39]", 0, "Specify the output format (default: hex)."},
102+
{"count", 'c', "N", 0, "Specify the count of output units (default: 32)"},
103+
{"deterministic", 'd', "SEED", 0, "Use a deterministic random number generator with SEED"},
104+
{0, 0, 0, 0, "ints Input and Output Options:", 7},
105+
{"low", 1000, "LOW", 0, "The lowest int returned (default: 1)"},
106+
{"high", 1001, "HIGH", 0, "The highest int returned (default: 9)"},
107+
{0, 0, 0, 0, "SLIP39 Output Options:", 6},
108+
{"group-threshold", 1002, "N", 0, "The number of groups that must contribute (default: 1)"},
109+
{"group", 1003, "N-of-M", 0, "The group specification (default: 1-of-1)"},
110+
{ 0 }
111+
};
112+
113+
const char* argp_program_version = "version 1.0";
114+
const char* argp_program_bug_address = "[email protected]";
115+
116+
char doc[] = "Converts cryptographic seeds between various forms.";
117+
struct argp argp = { options, parse_opt, "WORD [WORD [WORD [WORD]]]", doc };
118+
61119
params* parse_params( int argc, char *argv[] ) {
62-
argp_parse( &argp, argc, argv, 0, 0, NULL );
63120
params* p = new_params();
121+
argp_parse( &argp, argc, argv, 0, 0, p );
64122
return p;
65123
}

0 commit comments

Comments
 (0)