[gnome-games] aisleriot: Move variation_to_game_file() to util.[ch]



commit 8c4eb66230c8bc30cba59e96a0c598fc71cdfad5
Author: Christian Persch <chpe gnome org>
Date:   Thu Dec 10 14:42:20 2009 +0100

    aisleriot: Move variation_to_game_file() to util.[ch]

 aisleriot/sol.c  |   26 ++------------------------
 aisleriot/util.c |   32 ++++++++++++++++++++++++++++++++
 aisleriot/util.h |    2 ++
 3 files changed, 36 insertions(+), 24 deletions(-)
---
diff --git a/aisleriot/sol.c b/aisleriot/sol.c
index 57dfc41..cd3aa06 100644
--- a/aisleriot/sol.c
+++ b/aisleriot/sol.c
@@ -63,6 +63,7 @@
 #include "conf.h"
 #include "game.h"
 #include "window.h"
+#include "util.h"
 
 #if 0
 /* String reserve */
@@ -81,29 +82,6 @@ typedef struct {
 #endif /* HAVE_HILDON */
 } AppData;
 
-static char *
-variation_to_game_file (const char *variation)
-{
-  char *game_file, *s;
-
-  game_file = g_ascii_strdown (variation, -1);
-
-  /* Replace dangerous characters: '.' (as in "..") and '/' */
-  g_strdelimit (game_file, "." G_DIR_SEPARATOR_S, '\0');
-  g_strdelimit (game_file, NULL, '_');
-
-  if (game_file[0] == '\0') {
-    g_free (game_file);
-    return NULL;
-  }
-
-  /* Add the suffix */
-  s = g_strconcat (game_file, ".scm", NULL);
-  g_free (game_file);
-
-  return s;
-}
-
 #ifdef WITH_SMCLIENT
 
 static void
@@ -353,7 +331,7 @@ main_prog (void *closure, int argc, char *argv[])
     char *game_file = NULL;
 
     if (data.variation[0] != '\0') {
-      game_file = variation_to_game_file (data.variation);
+      game_file = aisleriot_variation_to_game_file (data.variation);
     }
 
     g_free (data.variation);
diff --git a/aisleriot/util.c b/aisleriot/util.c
index b72eeed..2784914 100644
--- a/aisleriot/util.c
+++ b/aisleriot/util.c
@@ -96,3 +96,35 @@ aisleriot_show_help (GtkWidget *window,
 
   g_free (help_section);
 }
+
+/**
+ * aisleriot_variation_to_game_file:
+ * @variation: name of a game from command line
+ *
+ * Creates a game file name from a command line --variation argument.
+ * This strips dangerous characters like .. and /.
+ *
+ * Returns: a newly allocated string containing the game file name for @variation
+ */
+char *
+aisleriot_variation_to_game_file (const char *variation)
+{
+  char *game_file, *s;
+
+  game_file = g_ascii_strdown (variation, -1);
+
+  /* Replace dangerous characters: '.' (as in ".."), '/' and '\' */
+  g_strdelimit (game_file, "./\\" , '\0');
+  g_strdelimit (game_file, NULL, '_');
+
+  if (game_file[0] == '\0') {
+    g_free (game_file);
+    return NULL;
+  }
+
+  /* Add the suffix */
+  s = g_strconcat (game_file, ".scm", NULL);
+  g_free (game_file);
+
+  return s;
+}
diff --git a/aisleriot/util.h b/aisleriot/util.h
index a4d9f00..d4726d5 100644
--- a/aisleriot/util.h
+++ b/aisleriot/util.h
@@ -26,6 +26,8 @@ G_BEGIN_DECLS
 void aisleriot_show_help (GtkWidget *window,
                           const char *game_file);
 
+char *aisleriot_variation_to_game_file (const char *variation);
+
 G_END_DECLS
 
 #endif /* !UTIL_H */



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