-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cpp
80 lines (72 loc) · 1.29 KB
/
Main.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
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
#include <stdlib.h>
#include <stdio.h>
#include <getopt.h>
int main (int argc, char *argv[]){
opterr=0;
const char* short_options = "hcrsf:";
int flag_h = 0;
int flag_s = 0;
int flag_r = 0;
int flag_c = 0;
int flag_f = 0;
const struct option long_options[] = {
{"help",no_argument,NULL,'h'},
{"size",optional_argument,NULL,'s'},
{"reverse",no_argument,NULL,'r'},
{"check",no_argument,NULL,'c'},
{"file",required_argument,NULL,'f'},
{NULL,0,NULL,0}
};
int rez;
int option_index;
while ((rez=getopt_long(argc,argv,short_options,
long_options,&option_index))!=-1){
switch(rez){
case 'h': {
if (flag_h > 0) {
continue;
}
flag_h = 1;
printf("Arg: Help\n");
break;
};
case 's': {
if (flag_s > 0) {
continue;
}
flag_s = 1;
printf("Arg: Size\n");
break;
};
case 'c': {
if (flag_c > 0) {
continue;
}
flag_c = 1;
printf("Arg: Check\n");
break;
};
case 'r': {
if (flag_r > 0) {
continue;
}
flag_r = 1;
printf("Arg: Reverse\n");
break;
};
case 'f': {
if (flag_f > 0) {
continue;
}
flag_f = 1;
printf("file = %s\n",optarg);
break;
};
case '?': default: {
printf("unknown option\n");
break;
};
};
};
return 0;
};