[gnome-video-arcade] 2009-03-02 Matthew Barnes <mbarnes redhat com>



commit 8330f348e11c91c6aac4935c0297a1ad66e4cde0
Author: Matthew Barnes <mbarnes redhat com>
Date:   Mon Mar 2 08:18:03 2009 -0500

    2009-03-02  Matthew Barnes  <mbarnes redhat com>
    
    	* README:
    	Update the build instructions.
    
    	* configure.ac:
    	Add a --with-nplayers-file option.
    
    	* src/Makefile.am:
    	Add gva-nplayers.[ch].
    
    	* src/main.c (main):
    	Call gva_nplayers_init().
    
    	* src/gva-nplayers.c:
    	* src/gva-nplayers.h:
    	New source files parse an nplayers.ini file.
---
 ChangeLog            |   18 ++++++
 README               |   14 +++++
 configure.ac         |   13 ++++
 src/Makefile.am      |    2 +
 src/gva-categories.c |    3 +-
 src/gva-nplayers.c   |  149 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/gva-nplayers.h   |   39 +++++++++++++
 src/main.c           |    4 +
 8 files changed, 241 insertions(+), 1 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 20ffac0..1f2a803 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,21 @@
+2009-03-02  Matthew Barnes  <mbarnes redhat com>
+
+	* README:
+	Update the build instructions.
+
+	* configure.ac:
+	Add a --with-nplayers-file option.
+
+	* src/Makefile.am:
+	Add gva-nplayers.[ch].
+
+	* src/main.c (main):
+	Call gva_nplayers_init().
+
+	* src/gva-nplayers.c:
+	* src/gva-nplayers.h:
+	New source files parse an nplayers.ini file.
+
 2009-02-27  Matthew Barnes  <mbarnes redhat com>
 
 	* README: Add a note about GTK+ and --with-gnome.
diff --git a/README b/README
index c2633c5..2abd42a 100644
--- a/README
+++ b/README
@@ -109,6 +109,14 @@ installed prior to compiling the source code:
        for many arcade games.  GNOME Video Arcade can utilize this
        information in its Properties window.
 
+   - nplayers.ini (optional)
+
+       This file, available from http://nplayers.arcadebelgium.be,
+       contains more detailed information about the maximum number of
+       players a game supports, including whether players alternate
+       or play simultaneously.  GNOME Video Arcade can utilize this
+       information in the Players column of the game list.
+
 
 Installation
 ------------
@@ -158,6 +166,12 @@ looks something like this:
 
    $ ./configure --with-history-file=/path/to/history.dat
 
+You can use the --with-nplayers-file configure option to specify
+the location of a nplayers.ini file as mentioned above.  Usage
+looks something like this:
+
+   $ ./configure --with-nplayers-file=/path/to/nplayers.ini
+
 The --enable-gtk-doc configure option tells "make" to generate
 developer documentation while building GNOME Video Arcade.  Once
 installed, the documentation can be viewed through Devhelp.
diff --git a/configure.ac b/configure.ac
index a37b76a..3606686 100644
--- a/configure.ac
+++ b/configure.ac
@@ -183,6 +183,18 @@ if test "$with_history" != "no"; then
 fi
 AC_MSG_RESULT($with_history)
 
+# --with-nplayers-file=PATH
+AC_MSG_CHECKING([for number of players file])
+AC_ARG_WITH([nplayers-file],
+        [AC_HELP_STRING([--with-nplayers-file=PATH],
+        [path to number of players file (usually named 'nplayers.ini')])],
+        with_nplayers="$withval", with_nplayers="no")
+if test "$with_nplayers" != "no"; then
+        AC_DEFINE_UNQUOTED(NPLAYERS_FILE, "$with_nplayers",
+                [Location of the number of players file])
+fi
+AC_MSG_RESULT($with_nplayers)
+
 AC_CONFIG_FILES([
         Makefile
         data/Makefile
@@ -203,6 +215,7 @@ echo
 echo "    MAME Program    : $MAME"
 echo "    Category File   : $with_category"
 echo "    History File    : $with_history"
+echo "    NPlayers File   : $with_nplayers"
 echo "    Use libgnomeui  : $with_gnome"
 echo "    Use libwnck     : $with_wnck"
 echo
diff --git a/m4/.gitignore b/m4/.gitignore
new file mode 100644
index 0000000..e69de29
diff --git a/src/Makefile.am b/src/Makefile.am
index 656bef3..139381a 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -58,6 +58,8 @@ gnome_video_arcade_SOURCES = \
 	gva-mame.h			\
 	gva-mute-button.c		\
 	gva-mute-button.h		\
+	gva-nplayers.c			\
+	gva-nplayers.h			\
 	gva-play-back.c			\
 	gva-play-back.h			\
 	gva-preferences.c		\
diff --git a/src/gva-categories.c b/src/gva-categories.c
index a86cf29..460c32d 100644
--- a/src/gva-categories.c
+++ b/src/gva-categories.c
@@ -52,7 +52,8 @@ gva_categories_init (GError **error)
         /* Convert Windows INI-style comments (lines beginning with ';')
          * to a form recognized by the GKeyFile parser. */
         cp = contents;
-        while (cp != NULL && *cp != '\0') {
+        while (cp != NULL && *cp != '\0')
+        {
                 if (*cp == ';')
                         *cp = '#';
                 /* Find the next line. */
diff --git a/src/gva-nplayers.c b/src/gva-nplayers.c
new file mode 100644
index 0000000..839ef11
--- /dev/null
+++ b/src/gva-nplayers.c
@@ -0,0 +1,149 @@
+/* Copyright 2007-2009 Matthew Barnes
+ *
+ * This file is part of GNOME Video Arcade.
+ *
+ * GNOME Video Arcade 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 3 of
+ * the License, or (at your option) any later version.
+ *
+ * GNOME Video Arcade 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, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gva-nplayers.h"
+
+static GKeyFile *keyfile = NULL;
+
+static void
+nplayers_parse (const gchar *string,
+                guint *max_alt,
+                guint *max_sim)
+{
+        guint max_players;
+        gboolean parsable;
+
+        /* Sanity check the string. */
+        parsable =
+                (strlen (string) > 2) &&
+                g_ascii_isdigit (string[0]) &&
+                string[1] == 'P';
+
+        if (!parsable)
+                return;
+
+        max_players = string[0] - '0';
+
+        if (max_alt != NULL && g_str_has_suffix (string, " alt"))
+                *max_alt = max_players;
+
+        if (max_sim != NULL && g_str_has_suffix (string, " sim"))
+                *max_sim = max_players;
+}
+
+/**
+ * gva_nplayers_init:
+ * @error: return location for a #GError, or %NULL
+ *
+ * Loads the number of players file.  If an error occurs, it returns
+ * %FALSE and sets @error.
+ *
+ * This function should be called once when the application starts.
+ *
+ * Returns: %TRUE on success, %FALSE if an error occurred
+ **/
+gboolean
+gva_nplayers_init (GError **error)
+{
+        gboolean success = FALSE;
+#ifdef NPLAYERS_FILE
+        gchar *contents, *cp;
+        gsize length;
+#endif
+
+        keyfile = g_key_file_new ();
+
+#ifdef NPLAYERS_FILE
+        if (!g_file_get_contents (NPLAYERS_FILE, &contents, &length, error))
+                return FALSE;
+
+        /* Convert Windows INI-style comments (lines beginning with ';')
+         * to a form recognized by the GKeyFile parser. */
+        cp = contents;
+        while (cp != NULL && *cp != '\0')
+        {
+                if (*cp == ';')
+                        *cp = '#';
+                /* Find the next line. */
+                cp = strchr (cp, '\n');
+                if (cp != NULL)
+                        cp++;
+        }
+
+        success = g_key_file_load_from_data (
+                keyfile, contents, length, G_KEY_FILE_NONE, error);
+
+        g_free (contents);
+#else
+        g_message (
+                _("This program is not configured to show"
+                  "detailed number of players information."));
+#endif
+
+        return success;
+}
+
+/**
+ * gva_nplayers_lookup:
+ * @game: the name of a game
+ * @max_alt: return location for the maximum number of alternating players
+ * @max_sim: return location for the maximum number of simultaneous players
+ * @error: return location for a #GError, or %NULL
+ *
+ * Returns the maximum number of alternating and/or simultaneous players
+ * for @game.  If @game only allows alternating players, @max_sim will be
+ * zero.  If @game only allows simultaneous players, @max_alt will be zero.
+ * If @game is listed in the file but the number of players is unknown or
+ * cannot be parsed, both @max_alt and @max_sim will be zero.  In all of
+ * these cases the function returns %TRUE.
+ *
+ * If an error occurs, the function returns %FALSE and sets @error, leaving
+ * @max_alt and @max_sim unaltered.
+ *
+ * Returns: %TRUE on success, %FALSE if an error occurred
+ **/
+gboolean
+gva_nplayers_lookup (const gchar *game,
+                     guint *max_alt,
+                     guint *max_sim,
+                     GError **error)
+{
+        gchar *nplayers;
+        gchar *cp;
+
+        nplayers = g_key_file_get_value (keyfile, "NPlayers", game, error);
+        if (nplayers == NULL)
+                return FALSE;
+
+        if (max_alt != NULL)
+                *max_alt = 0;
+
+        if (max_sim != NULL)
+                *max_sim = 0;
+
+        cp = strchr (nplayers, '/');
+        if (cp != NULL)
+        {
+                *cp++ = '\0';
+                nplayers_parse (g_strstrip (cp), max_alt, max_sim);
+        }
+
+        nplayers_parse (g_strstrip (nplayers), max_alt, max_sim);
+
+        return TRUE;
+}
diff --git a/src/gva-nplayers.h b/src/gva-nplayers.h
new file mode 100644
index 0000000..b701171
--- /dev/null
+++ b/src/gva-nplayers.h
@@ -0,0 +1,39 @@
+/* Copyright 2007-2009 Matthew Barnes
+ *
+ * This file is part of GNOME Video Arcade.
+ *
+ * GNOME Video Arcade 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 3 of
+ * the License, or (at your option) any later version.
+ *
+ * GNOME Video Arcade 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, see <http://www.gnu.org/licenses/>.
+ */
+
+/**
+ * SECTION: gva-nplayers
+ * @short_description: Number of Players Information
+ *
+ * These functions provide a the maximum number of players for a game
+ * and whether the play is alternating or simultaneous.  The information
+ * is read from a <filename>nplayers.ini</filename> file.
+ **/
+
+#ifndef GVA_NPLAYERS_H
+#define GVA_NPLAYERS_H
+
+#include "gva-common.h"
+
+G_BEGIN_DECLS
+
+gboolean        gva_nplayers_init               (GError **error);
+
+G_END_DECLS
+
+#endif /* GVA_NPLAYERS_H */
diff --git a/src/main.c b/src/main.c
index 380febd..a879406 100644
--- a/src/main.c
+++ b/src/main.c
@@ -35,6 +35,7 @@
 #include "gva-history.h"
 #include "gva-main.h"
 #include "gva-mame.h"
+#include "gva-nplayers.h"
 #include "gva-play-back.h"
 #include "gva-preferences.h"
 #include "gva-properties.h"
@@ -285,6 +286,9 @@ main (gint argc, gchar **argv)
         gva_history_init (&error);
         gva_error_handle (&error);
 
+        gva_nplayers_init (&error);
+        gva_error_handle (&error);
+
         gtk_init_add ((GtkFunction) start, NULL);
 
         gtk_main ();



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]