root / trunk / code / projects / colonet / server / options.c @ 520
History | View | Annotate | Download (2.15 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 <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 options_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. Defaulting to %d\n", DEFAULTPORT);
|
49 |
} |
50 |
|
51 |
/* Defaults */
|
52 |
optionsG.listen_port = DEFAULTPORT; |
53 |
strcpy(optionsG.wireless_port, USB_PORT); |
54 |
optionsG.logging_enabled = false;
|
55 |
optionsG.listener_mode = false;
|
56 |
|
57 |
/* Parse args */
|
58 |
while (1) { |
59 |
c = getopt(argc, argv, "p:l:w:sh");
|
60 |
|
61 |
if (c == -1) { |
62 |
break;
|
63 |
} |
64 |
|
65 |
switch (c) {
|
66 |
case 'p': |
67 |
/* Listen port */
|
68 |
optionsG.listen_port = atoi(optarg); |
69 |
|
70 |
if (optionsG.listen_port < SMALLEST_POSS_LISTEN_PORT) {
|
71 |
printf("You cannot listen on a port less than %d.\n", SMALLEST_POSS_LISTEN_PORT);
|
72 |
printf("Setting listener port to %d\n", DEFAULTPORT);
|
73 |
optionsG.listen_port = DEFAULTPORT; |
74 |
} |
75 |
break;
|
76 |
case 'w': |
77 |
/* Set wireless port */
|
78 |
strcpy(optionsG.wireless_port, optarg); |
79 |
printf("Wireless port set to %s.\n", optionsG.wireless_port);
|
80 |
break;
|
81 |
case 'l': |
82 |
/* Set log filename (and enable logging) */
|
83 |
strcpy(optionsG.log_filename, optarg); |
84 |
optionsG.logging_enabled = true;
|
85 |
break;
|
86 |
case 's': |
87 |
/* Enable listener mode */
|
88 |
optionsG.listener_mode = true;
|
89 |
break;
|
90 |
case 'h': |
91 |
printUsage(); |
92 |
exit(1);
|
93 |
} |
94 |
} |
95 |
} |