1 /* args.c - Parse command-line arguments for grrobot using argp
3 * Copyright © 2003 Carl Worth
5 * Permission to use, copy, modify, distribute, and sell this software
6 * and its documentation for any purpose is hereby granted without
7 * fee, provided that the above copyright notice appear in all copies
8 * and that both that copyright notice and this permission notice
9 * appear in supporting documentation, and that the name of Carl Worth
10 * not be used in advertising or publicity pertaining to distribution
11 * of the software without specific, written prior permission.
12 * Carl Worth makes no representations about the suitability of this
13 * software for any purpose. It is provided "as is" without express
14 * or implied warranty.
16 * CARL WORTH DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
18 * NO EVENT SHALL CARL WORTH BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS
20 * OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
21 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
22 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
24 * Author: Carl Worth <carl@theworths.org>
32 const char *argp_program_version = "grrobot " VERSION;
34 const char *argp_program_bug_address = "<carl@theworths.org>";
36 static char doc[] = "grrobot - Ricochet Robot using GTK+ and Xr";
38 static char args_doc[] = "[file]";
40 static struct argp_option options[] = {
41 /* name, key, arg, flags, doc */
42 {"host", 'h', "HOST", 0, "Host running RR server"},
43 {"port", 'p', "PORT", 0, "Port of server"},
44 {"user", 'u', "USERNAME", 0, "Username for conection"},
45 {"game", 'g', "GAME", 0, "Game to join"},
46 {"watch", 'w', 0, 0, "Watch instad of join"},
51 parse_opt (int key, char *arg, struct argp_state *state)
53 struct args *args = state->input;
77 return ARGP_ERR_UNKNOWN;
83 static struct argp argp = { options, parse_opt, args_doc, doc };
86 args_parse(args_t *args, int argc, char *argv[])
88 args->host = getenv ("RR_HOST");
89 if (args->host == NULL)
90 args->host = ARGS_HOST_DEFAULT;
91 args->port = getenv ("RR_PORT");
92 if (args->port == NULL)
93 args->port = ARGS_PORT_DEFAULT;
94 args->user = getenv ("USER");
95 if (args->user == NULL)
96 args->user = ARGS_USER_DEFAULT;
97 args->game = getenv ("RR_GAME");
98 if (args->game == NULL)
99 args->game = ARGS_GAME_DEFAULT;
104 return argp_parse (&argp, argc, argv,