root / trunk / code / projects / colonet / server / options.c @ 764
History | View | Annotate | Download (2.15 KB)
1 | 11 | emarinel | /**
|
---|---|---|---|
2 | * @file options.c
|
||
3 | 55 | jknichel | *
|
4 | 11 | emarinel | * @brief Options for ColonetServer
|
5 | 55 | jknichel | *
|
6 | 11 | emarinel | * @author Eugene Marinelli
|
7 | 55 | jknichel | *
|
8 | 11 | emarinel | * @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 | 397 | emarinel | #include <options.h> |
21 | 11 | emarinel | |
22 | ColonetServerOptionsT optionsG; |
||
23 | |||
24 | 55 | jknichel | /**
|
25 | * @brief Prints the usage of the program
|
||
26 | */
|
||
27 | static void printUsage() { |
||
28 | 391 | emarinel | 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 | 11 | emarinel | } |
33 | |||
34 | 55 | jknichel | /**
|
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 | 426 | emarinel | void options_parseCmdLine(int argc, char** argv) { |
43 | 11 | emarinel | int c;
|
44 | |||
45 | memset(&optionsG, 0, sizeof(ColonetServerOptionsT)); |
||
46 | 347 | emarinel | |
47 | 11 | emarinel | if (argc < 2) { |
48 | 399 | emarinel | printf("No port was specified for listening for client connections. Defaulting to %d\n", DEFAULTPORT);
|
49 | 11 | emarinel | } |
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 | 391 | emarinel | c = getopt(argc, argv, "p:l:w:sh");
|
60 | 11 | emarinel | |
61 | if (c == -1) { |
||
62 | break;
|
||
63 | } |
||
64 | 347 | emarinel | |
65 | 11 | emarinel | switch (c) {
|
66 | case 'p': |
||
67 | /* Listen port */
|
||
68 | optionsG.listen_port = atoi(optarg); |
||
69 | 347 | emarinel | |
70 | 11 | emarinel | if (optionsG.listen_port < SMALLEST_POSS_LISTEN_PORT) {
|
71 | 399 | emarinel | printf("You cannot listen on a port less than %d.\n", SMALLEST_POSS_LISTEN_PORT);
|
72 | 11 | emarinel | 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 | 399 | emarinel | printf("Wireless port set to %s.\n", optionsG.wireless_port);
|
80 | 11 | emarinel | 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 | 391 | emarinel | case 'h': |
91 | 11 | emarinel | printUsage(); |
92 | 391 | emarinel | exit(1);
|
93 | 11 | emarinel | } |
94 | } |
||
95 | } |