1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <getopt.h>
#include "args.h"
#include "array.h"
bool parse_args(client_state* state, int argc, char* argv[]) {
static struct option long_opts[] = {
{"lines", required_argument, 0, 'l'},
{"center", no_argument, 0, 'c'},
{"exact-match", no_argument, 0, 'e'},
{"verbose", no_argument, 0, 'v'},
{"password", no_argument, 0, 'P'},
{"prompt", no_argument, 0, 'p'},
{"orderless", no_argument, 0, 'o'},
{"insensitive", no_argument, 0, 'i'},
{"starting-text", required_argument, 0, 's'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
int opt;
int long_index = 0;
while ((opt = getopt_long(argc, argv, "l:p:s:coievP", long_opts, &long_index)) != -1) {
switch (opt) {
case 'l':
state->lines = MIN(atoi(optarg), array_size(state->items));
break;
case 'p':
state->prompt = optarg;
break;
case 'c':
state->center = true;
break;
case 'e':
state->exact_match = true;
break;
case 'v':
state->verbose++;
break;
case 'P':
state->password = true;
break;
case 'o':
state->orderless = true;
break;
case 'i':
state->strstr2 = strcasestr;
break;
case 's':
array_insert_many(state->input_buffer, 0, optarg, strlen(optarg));
state->cursor_index = strlen(optarg);
break;
case 'h':
fprintf(stderr, "WIP\n");
return false;
break;
default:
fprintf(stderr, "Usage: NOT WHAT YOU TYPED\n");
return false;
}
}
return true;
}
|