X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;ds=sidebyside;f=src%2Fargs.c;fp=src%2Fargs.c;h=0000000000000000000000000000000000000000;hb=c425d769ad013c2f76bd15e433fbda4e66436e05;hp=5f776c933928e880bd902314395ad0306e87884b;hpb=75d32f38216f0d23936f62f85d3a1e45b07d543c;p=ttt diff --git a/src/args.c b/src/args.c deleted file mode 100644 index 5f776c9..0000000 --- a/src/args.c +++ /dev/null @@ -1,138 +0,0 @@ -/* args.c - Parse command-line arguments for ttt using getopt - * - * Copyright © 2005 Carl Worth - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2, or (at your option) - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * Author: Carl Worth - */ - -#include -#include -#include -#include -#include - -#include "args.h" - -static const char ARGS_PROGRAM_VERSION[] = VERSION; -static const char ARGS_PROGRAM_DESCRIPTION[] = "client-server tic-tac-toe game"; -static const char ARGS_PROGRAM_BUG_ADDRESS[] = ""; - -/* XXX: SAMPLE: */ -static char ARGS_PROGRAM_ARGDOC[] = ""; - -/* XXX: getopt is rather annoying in that you must maintain a - * string-encoding of the options in addition to the table. For - * example, to enable the sample display option below, one would have - * to add "d:" to the optstring. - * - * A useful exercise would be to write a function to generate the - * optstring from the table. - * - * The other annoying thing is that the table does not include help - * strings, so the args_help function below must also be maintained - * manually. - */ -static char args_optstring[] = "hV"; -static struct option args_options[] = { - /* name, has_arg, flag, val */ - /* XXX: SAMPLE: - {"display", 1, 0, 'd'}, - */ - {"help", 0, 0, 'h'}, - {"version", 0, 0, 'V'}, - { 0 } -}; - -static void -args_help (const char *argv0) -{ - printf ("Usage: %s [OPTION] %s\n", argv0, ARGS_PROGRAM_ARGDOC); - printf ("%s - %s\n", argv0, ARGS_PROGRAM_DESCRIPTION); - puts (""); - printf (" -h, --help\t\tGive this help list\n"); - printf (" -V, --version\t\tPrint program version\n"); - /* XXX: SAMPLE: - printf (" -d, --display=DISPLAY\tX server to connect to"); - */ -} - -static void -args_usage (const char *argv0) -{ - printf ("Usage: %s [OPTION] %s\n", argv0, ARGS_PROGRAM_ARGDOC); - printf ("Try `%s --help' for more information.\n", argv0); -} - -int -args_parse(args_t *args, int argc, char *argv[], int *args_first) -{ - char *argv0_copy = strdup (argv[0]); - char *argv0 = basename (argv0_copy); - - int c; - - /* XXX: SAMPLE: - args->display = NULL; - */ - - while (1) { - c = getopt_long (argc, argv, args_optstring, args_options, NULL); - if (c == -1) - break; - - switch (c) { - /* XXX: SAMPLE: - case 'd': - args->display = optarg; - break; - */ - case 'V': - printf ("%s\n", VERSION); - exit (0); - break; - - case 'h': - args_help (argv0); - exit (0); - break; - - case '?': - args_help (argv0); - exit (1); - break; - - default: - fprintf (stderr, "Unhandled option `%c'\n", c); - break; - } - } - - /* XXX: SAMPLE: - if (argc - optind == 1) { - args->file = argv[optind]; - } else { - args_usage (argv0); - } - */ - - if (args_first) - *args_first = optind; - - free (argv0_copy); - - return 0; -}