-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.c
More file actions
52 lines (46 loc) · 847 Bytes
/
main.c
File metadata and controls
52 lines (46 loc) · 847 Bytes
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
#include <stdio.h>
#include <string.h>
#include "domen.h"
#include "me.h"
#define HELP_MSG \
"iputil - v0.0.1\n\
USAGE: iputil [OPTIONS] [domen]\n\
iputil [OPTIONS] me\n\
\n\
OPTIONS:\n\
-h|--help Show this message.\n\
COMMANDS:\n\
me Shows your ips."
#define HELP_DEF puts(HELP_MSG);return 1
#define ARGEQ(x) strcmp(*argv,x)==0
int
main (int argc, char ** argv)
{
Config cfg= {
.domen = 0,
.type = 0,
};
for (;;) {
if (argc==1 || !*argv) { break; }
if (ARGEQ("-h") || ARGEQ("--help")) {
HELP_DEF;
} else if(ARGEQ("me")) {
cfg.type = 2;
} else {
cfg.domen = *argv;
cfg.type = 1;
}
*argv++;
}
switch (cfg.type) {
case 1:
get_domen(cfg.domen);
break;
case 2:
get_myself();
break;
default:
fprintf(stderr,"error: invalid args.\nSee --help.\n");
return 2;
}
}