/
dartsync.c
89 lines (73 loc) · 1.43 KB
/
dartsync.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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <getopt.h>
#include <debug.h>
#include <packet_def.h>
#include <trans_file_table.h>
#include "client/start.h"
#include "server/start.h"
int debug = 0;
enum start_mode {
CLIENT,
SERVER,
NONE
};
static const char short_options[] = "dm:h";
static const struct option long_options[] = {
{ "mode", required_argument, NULL, 'm' },
{ "debug", no_argument, NULL, 'd' },
{ "help", no_argument, NULL, 'h' },
{ 0, 0, 0, 0 }
};
static void usage(FILE *fp, char **argv)
{
fprintf(fp,
"Usage: %s [-m client|server]\n\n"
"Options:\n"
"-m | --mode client|server\n"
"-d | --open debug print debug info\n"
"-h | --help Print this message\n\n"
, argv[0]);
}
int main(int argc, char **argv)
{
enum start_mode mode = NONE;
while (1) {
int index, c;
c = getopt_long(argc, argv, short_options, long_options, &index);
if (c == -1)
break;
switch (c) {
case 0:
break;
case 'd':
debug = 1;
break;
case 'm':
if (strcmp(optarg, "server") == 0)
mode = SERVER;
else if (strcmp(optarg, "client") == 0)
mode = CLIENT;
break;
case 'h':
usage(stdout, argv);
exit(EXIT_SUCCESS);
default:
usage(stderr, argv);
exit(EXIT_FAILURE);
}
}
switch (mode) {
case CLIENT:
client_start();
break;
case SERVER:
server_start();
break;
case NONE:
usage(stderr, argv);
exit(EXIT_FAILURE);
}
return 0;
}