root / trunk / code / projects / colonet / ColonetServer / options.c @ 391
History | View | Annotate | Download (2.11 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("Colonet Server\n");
|
29 |
printf(" ./ColonetServer [-h (help)] [-p server_listen_port]\n");
|
30 |
printf(" [-w wireless_port_file_desc (e.g. /dev/ttyUSB0)]\n");
|
31 |
printf(" [-l log_filename] [-s (enable listener mode)]\n");
|
32 |
} |
33 |
|
34 |
/**
|
35 |
* @brief Parses the command line arguments
|
36 |
*
|
37 |
* @param argc The number of arguments passed to the program
|
38 |
* @param argv The arguments passed to the program
|
39 |
*
|
40 |
* @return Void
|
41 |
*/
|
42 |
void parseCmdLine(int argc, char** argv) { |
43 |
int c;
|
44 |
|
45 |
memset(&optionsG, 0, sizeof(ColonetServerOptionsT)); |
46 |
|
47 |
if (argc < 2) { |
48 |
printf("No port was specified for listening for client connections."
|
49 |
" Defaulting to %d\n", DEFAULTPORT);
|
50 |
} |
51 |
|
52 |
/* Defaults */
|
53 |
optionsG.listen_port = DEFAULTPORT; |
54 |
strcpy(optionsG.wireless_port, USB_PORT); |
55 |
optionsG.logging_enabled = false;
|
56 |
optionsG.listener_mode = false;
|
57 |
|
58 |
/* Parse args */
|
59 |
while (1) { |
60 |
c = getopt(argc, argv, "p:l:w:sh");
|
61 |
|
62 |
if (c == -1) { |
63 |
break;
|
64 |
} |
65 |
|
66 |
switch (c) {
|
67 |
case 'p': |
68 |
/* Listen port */
|
69 |
optionsG.listen_port = atoi(optarg); |
70 |
|
71 |
if (optionsG.listen_port < SMALLEST_POSS_LISTEN_PORT) {
|
72 |
printf("You cannot listen on a port less than %d.\n",
|
73 |
SMALLEST_POSS_LISTEN_PORT); |
74 |
printf("Setting listener port to %d\n", DEFAULTPORT);
|
75 |
optionsG.listen_port = DEFAULTPORT; |
76 |
} |
77 |
break;
|
78 |
case 'w': |
79 |
/* Set wireless port */
|
80 |
strcpy(optionsG.wireless_port, optarg); |
81 |
break;
|
82 |
case 'l': |
83 |
/* Set log filename (and enable logging) */
|
84 |
strcpy(optionsG.log_filename, optarg); |
85 |
optionsG.logging_enabled = true;
|
86 |
break;
|
87 |
case 's': |
88 |
/* Enable listener mode */
|
89 |
optionsG.listener_mode = true;
|
90 |
break;
|
91 |
case 'h': |
92 |
printUsage(); |
93 |
exit(1);
|
94 |
} |
95 |
} |
96 |
} |