-
Notifications
You must be signed in to change notification settings - Fork 0
/
gastask.c
77 lines (63 loc) · 996 Bytes
/
gastask.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
#include "gastask.h"
BOOL verbose;
static int seed = 0;
static void
usage(void)
{
fprintf(stdout,
"Usage: gastask <options> <config path>\n"
" <options>\n"
" -h: this message\n"
" -v: verbose mode\n"
" -s <seed>: (default: 0)\n"
);
}
void
errmsg(const char *fmt, ...)
{
va_list ap;
char *errmsg;
va_start(ap, fmt);
vasprintf(&errmsg, fmt, ap);
va_end(ap);
fprintf(stderr, "ERROR: %s\n", errmsg);
free(errmsg);
}
static void
parse_args(int argc, char *argv[])
{
int c;
while ((c = getopt(argc, argv, "s:h")) != -1) {
switch (c) {
case 's':
if (sscanf(optarg, "%d", &seed) != 1) {
usage();
exit(1);
}
break;
case 'h':
usage();
exit(0);
default:
errmsg("invalid option");
usage();
exit(1);
}
}
if (argc - optind < 1) {
usage();
exit(1);
}
load_conf(argv[optind]);
}
int
main(int argc, char *argv[])
{
parse_args(argc, argv);
#if 0
srand(seed);
#endif
srand(getpid() + time(NULL));
run_GA();
return 0;
}