From: Richard Worth Date: Sat, 5 Nov 2005 20:25:11 +0000 (+0000) Subject: * src/args.c: Renamed ttt-args.c X-Git-Url: https://git.cworth.org/git?p=ttt;a=commitdiff_plain;h=c425d769ad013c2f76bd15e433fbda4e66436e05;hp=75d32f38216f0d23936f62f85d3a1e45b07d543c * src/args.c: Renamed ttt-args.c * src/args.h: Renamed ttt-args.h * src/ttt-args.c: (ttt_args_help), (ttt_args_usage), (ttt_args_parse): Added ttt_ prefix. * src/ttt-args.h: Added ttt_, TTT_ prefix. --- diff --git a/ChangeLog b/ChangeLog index eedf81b..2bf3f37 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,16 @@ +2005-11-05 Richard D. Worth + + * src/args.c: Renamed ttt-args.c + * src/args.h: Renamed ttt-args.h + * src/ttt-args.c: (ttt_args_help), (ttt_args_usage), + (ttt_args_parse): Added ttt_ prefix. + * src/ttt-args.h: Added ttt_, TTT_ prefix. + +2005-11-05 Kevin Worth + + * src/ttt-board.c: (ttt_board_init): Implemented board_init. + * src/ttt-board.h: (ttt_board_t): Added cells array. + 2005-11-05 Carl Worth * src/Makefile.am: Add ttt-board.[ch] and x.[ch] 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; -} diff --git a/src/args.h b/src/args.h deleted file mode 100644 index 6172a9e..0000000 --- a/src/args.h +++ /dev/null @@ -1,41 +0,0 @@ -/* args.h - 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 - */ - -#ifndef ARGS_H -#define ARGS_H - -#ifdef HAVE_CONFIG_H -#include "config.h" -#endif - -typedef struct args -{ - /* XXX: SAMPLE: - char *display; - */ - char *file; - -} args_t; - -int -args_parse(args_t *args, int argc, char *argv[], int *args_first); - -#endif diff --git a/src/ttt-args.c b/src/ttt-args.c new file mode 100644 index 0000000..302e301 --- /dev/null +++ b/src/ttt-args.c @@ -0,0 +1,138 @@ +/* ttt-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 "ttt-args.h" + +static const char TTT_ARGS_PROGRAM_VERSION[] = VERSION; +static const char TTT_ARGS_PROGRAM_DESCRIPTION[] = "client-server tic-tac-toe game"; +static const char TTT_ARGS_PROGRAM_BUG_ADDRESS[] = ""; + +/* XXX: SAMPLE: */ +static char TTT_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 ttt_args_optstring[] = "hV"; +static struct option ttt_args_options[] = { + /* name, has_arg, flag, val */ + /* XXX: SAMPLE: + {"display", 1, 0, 'd'}, + */ + {"help", 0, 0, 'h'}, + {"version", 0, 0, 'V'}, + { 0 } +}; + +static void +ttt_args_help (const char *argv0) +{ + printf ("Usage: %s [OPTION] %s\n", argv0, TTT_ARGS_PROGRAM_ARGDOC); + printf ("%s - %s\n", argv0, TTT_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 +ttt_args_usage (const char *argv0) +{ + printf ("Usage: %s [OPTION] %s\n", argv0, TTT_ARGS_PROGRAM_ARGDOC); + printf ("Try `%s --help' for more information.\n", argv0); +} + +int +ttt_args_parse(ttt_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, ttt_args_optstring, ttt_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; +} diff --git a/src/ttt-args.h b/src/ttt-args.h new file mode 100644 index 0000000..f5e117a --- /dev/null +++ b/src/ttt-args.h @@ -0,0 +1,41 @@ +/* ttt-args.h - 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 + */ + +#ifndef TTT_ARGS_H +#define TTT_ARGS_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +typedef struct ttt_args +{ + /* XXX: SAMPLE: + char *display; + */ + char *file; + +} ttt_args_t; + +int +ttt_args_parse(ttt_args_t *args, int argc, char *argv[], int *args_first); + +#endif