root / trunk / code / projects / colonet / ColonetServer / options.c @ 11
History | View | Annotate | Download (1.67 KB)
1 |
/**
|
---|---|
2 |
* @file options.c
|
3 |
* @brief Options for ColonetServer
|
4 |
* @author Eugene Marinelli
|
5 |
* @date 2/13/07
|
6 |
*
|
7 |
* @bug Usage not written
|
8 |
*/
|
9 |
|
10 |
#include <stdio.h> |
11 |
#include <getopt.h> |
12 |
#include <string.h> |
13 |
#include <stdlib.h> |
14 |
|
15 |
#include <colonet_defs.h> |
16 |
|
17 |
#include "includes/options.h" |
18 |
|
19 |
ColonetServerOptionsT optionsG; |
20 |
|
21 |
static void printUsage() |
22 |
{ |
23 |
printf("USAGE:\n");
|
24 |
} |
25 |
|
26 |
void parseCmdLine(int argc, char** argv) |
27 |
{ |
28 |
int c;
|
29 |
|
30 |
memset(&optionsG, 0, sizeof(ColonetServerOptionsT)); |
31 |
|
32 |
if (argc < 2) { |
33 |
printf("No port was specified for listening for client connections."
|
34 |
" Defaulting to %d\n", DEFAULTPORT);
|
35 |
} |
36 |
|
37 |
/* Defaults */
|
38 |
optionsG.listen_port = DEFAULTPORT; |
39 |
strcpy(optionsG.wireless_port, USB_PORT); |
40 |
optionsG.logging_enabled = false;
|
41 |
optionsG.listener_mode = false;
|
42 |
|
43 |
/* Parse args */
|
44 |
while (1) { |
45 |
c = getopt(argc, argv, "p:l:w:su");
|
46 |
|
47 |
if (c == -1) { |
48 |
break;
|
49 |
} |
50 |
|
51 |
switch (c) {
|
52 |
case 'p': |
53 |
/* Listen port */
|
54 |
optionsG.listen_port = atoi(optarg); |
55 |
|
56 |
if (optionsG.listen_port < SMALLEST_POSS_LISTEN_PORT) {
|
57 |
printf("You cannot listen on a port less than %d.\n",
|
58 |
SMALLEST_POSS_LISTEN_PORT); |
59 |
printf("Setting listener port to %d\n", DEFAULTPORT);
|
60 |
optionsG.listen_port = DEFAULTPORT; |
61 |
} |
62 |
break;
|
63 |
case 'w': |
64 |
/* Set wireless port */
|
65 |
strcpy(optionsG.wireless_port, optarg); |
66 |
break;
|
67 |
case 'l': |
68 |
/* Set log filename (and enable logging) */
|
69 |
strcpy(optionsG.log_filename, optarg); |
70 |
optionsG.logging_enabled = true;
|
71 |
break;
|
72 |
case 's': |
73 |
/* Enable listener mode */
|
74 |
optionsG.listener_mode = true;
|
75 |
break;
|
76 |
case 'u': |
77 |
printUsage(); |
78 |
} |
79 |
} |
80 |
} |