-
Notifications
You must be signed in to change notification settings - Fork 2
/
command_line.c
113 lines (103 loc) · 4.21 KB
/
command_line.c
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#include "command_line.h"
#include "settings.h"
int ParseCommandLine(int argc, char *argv[], TNet *Conf)
{
CMDLINE *CL;
int Act=ACT_INTERACTIVE;
const char *ptr;
CL=CommandLineParserCreate(argc, argv);
ptr=CommandLineFirst(CL);
if (StrValid(ptr))
{
if (strcmp(ptr, "list")==0) Act=ACT_LIST;
else if (strcmp(ptr, "interfaces")==0) Act=ACT_IFACE_LIST;
else if (strcmp(ptr, "scan")==0)
{
ptr=CommandLineNext(CL);
if (ListFindNamedItem(Interfaces, ptr))
{
Conf->Interface=CopyStr(Conf->Interface, ptr);
}
Act=ACT_SCAN;
}
else if (strcmp(ptr, "add")==0)
{
Act=ACT_ADD;
Conf->Flags |= NET_STORE;
Conf->ESSID=CopyStr(Conf->ESSID, CommandLineNext(CL));
Conf->Address=CopyStr(Conf->Address, CommandLineNext(CL));
if (strcasecmp(Conf->Address, "dhcp") !=0)
{
Conf->Netmask=CopyStr(Conf->Netmask, CommandLineNext(CL));
Conf->Gateway=CopyStr(Conf->Gateway, CommandLineNext(CL));
Conf->DNSServer=CopyStr(Conf->DNSServer, CommandLineNext(CL));
}
}
else if (strcmp(ptr, "join")==0)
{
Act=ACT_JOIN;
Conf->Interface=CopyStr(Conf->Interface, CommandLineNext(CL));
if (! ListFindNamedItem(Interfaces, Conf->Interface))
{
printf("ERROR: '%s' is not an interface\n", Conf->Interface);
printf("usage: %s join <interface> <essid>\n", argv[0]);
exit(1);
}
Conf->ESSID=CopyStr(Conf->ESSID, CommandLineNext(CL));
}
else if (strcmp(ptr, "connect")==0)
{
Act=ACT_JOIN;
Conf->ESSID=CopyStr(Conf->ESSID, CommandLineNext(CL));
Conf->Interface=CopyStr(Conf->Interface, CommandLineNext(CL));
}
else if (strcmp(ptr, "leave")==0)
{
Act=ACT_LEAVE;
Conf->Interface=CopyStr(Conf->Interface, CommandLineNext(CL));
if (! ListFindNamedItem(Interfaces, Conf->Interface))
{
printf("ERROR: '%s' is not an interface\n", Conf->Interface);
printf("usage: %s join <interface> <essid>\n", argv[0]);
exit(1);
}
}
else if (strcmp(ptr, "forget")==0)
{
Act=ACT_FORGET;
Conf->ESSID=CopyStr(Conf->ESSID, CommandLineNext(CL));
}
else if (strcmp(ptr, "qrcode")==0)
{
Act=ACT_QRCODE;
Conf->ESSID=CopyStr(Conf->ESSID, CommandLineNext(CL));
}
else if (strcmp(ptr, "status")==0) Act=ACT_STATUS;
else if (strcmp(ptr, "help")==0) Act=ACT_HELP;
else if (strcmp(ptr, "version")==0) Act=ACT_VERSION;
}
ptr=CommandLineCurr(CL);
while (ptr)
{
if (strcmp(ptr, "-?")==0) Act=ACT_HELP;
else if (strcmp(ptr, "-h")==0) Act=ACT_HELP;
else if (strcmp(ptr, "-help")==0) Act=ACT_HELP;
else if (strcmp(ptr, "--help")==0) Act=ACT_HELP;
else if (strcmp(ptr, "-version")==0) Act=ACT_VERSION;
else if (strcmp(ptr, "--version")==0) Act=ACT_VERSION;
else if (strcmp(ptr, "-i")==0) Conf->Interface=CopyStr(Conf->Interface, CommandLineNext(CL));
else if (strcmp(ptr, "-ap")==0) Conf->AccessPoint=CopyStr(Conf->AccessPoint, CommandLineNext(CL));
else if (strcmp(ptr, "-k")==0) Conf->Key=CopyStr(Conf->Key, CommandLineNext(CL));
else if (strcmp(ptr, "-w")==0) Settings.WPASupplicantSock=CopyStr(Settings.WPASupplicantSock, CommandLineNext(CL));
else if (strcmp(ptr, "-o")==0) Settings.OutputPath=CopyStr(Settings.OutputPath, CommandLineNext(CL));
else if (strcmp(ptr, "-viewer")==0) Settings.ImageViewer=CopyStr(Settings.ImageViewer, CommandLineNext(CL));
else if (strcmp(ptr, "-view")==0)
{
ptr=CommandLineNext(CL);
if (strcasecmp(ptr, "sixel")==0) Settings.ImageViewer=CopyStr(Settings.ImageViewer, "img2sixel -e,convert");
else Settings.ImageViewer=CopyStr(Settings.ImageViewer, CommandLineNext(CL));
}
ptr=CommandLineNext(CL);
}
return(Act);
}