-
Notifications
You must be signed in to change notification settings - Fork 0
/
settings.cpp
40 lines (35 loc) · 905 Bytes
/
settings.cpp
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
#include "settings.h"
Settings::Settings(){
addr = NULL;
port = -1;
dir = NULL;
}
int Settings::readSettingsFromArguments(int argc, char ** argv){
int index;
int c;
opterr = 0;
while ((c = getopt (argc, argv, "h:p:d:")) != -1)
switch (c)
{
case 'h':
addr = optarg;
break;
case 'p':
port = atoi(optarg);
break;
case 'd':
dir = optarg;
break;
case '?':
if (optopt == 'h' || optopt == 'p' || optopt == 'd')
fprintf (stderr, "Option -%c requires an argument.\n", optopt);
else if (isprint (optopt))
fprintf (stderr, "Unknown option `-%c'.\n", optopt);
else
fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt);
return -1;
default:
abort ();
}
return 0;
}