-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
69 lines (56 loc) · 1.75 KB
/
main.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
#include <ctype.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "myfuncs.h"
#include "mylayers.h"
#include "mynet.h"
#include "types.h"
int vlevel = 0;
void printhelp(void);
void printhelp(void) {
printf("\t-h - prints help menu.\n\t-v - sets level of verbose output.\n"
"\t-o some option.\n");
}
int main(int argc, char **argv) {
char c, *optstr = "e:hv:o:", *endptr;
while ((c = getopt(argc, argv, optstr)) != -1) {
switch (c) {
case 'e': //echo
printf("%s\n", optarg);
break;
case 'h': //help
printhelp();
break;
case 'v': //verbose
errno = 0;
vlevel = strtol(optarg, &endptr, 10);
if (errno != 0) {
printf("invalid argument to numeric option\n");
return 1;
} else if (endptr == optarg) {
printf("no digits were found\n");
return 1;
}
printf("verbose output level set to %i\n", vlevel);
break;
case 'o': //output
printf("output: %s\n", optarg);
break;
case '?': //unknown
if (optopt == 'o')
printf("Option -o requires an argument.\n");
else if (isprint(optopt))
printf("Unknown option -%c.\n", optopt);
else
printf("Unknown option character -%c [#%i].\n",
optopt, optopt);
return 1;
default: //other
return 1;
}
}
return 0;
}