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