gnome-games r8326 - trunk/aisleriot
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8326 - trunk/aisleriot
- Date: Sun, 23 Nov 2008 19:34:44 +0000 (UTC)
Author: chpe
Date: Sun Nov 23 19:34:44 2008
New Revision: 8326
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8326&view=rev
Log:
Move hint code to AisleriotGame.
Modified:
trunk/aisleriot/game.c
trunk/aisleriot/game.h
trunk/aisleriot/window.c
Modified: trunk/aisleriot/game.c
==============================================================================
--- trunk/aisleriot/game.c (original)
+++ trunk/aisleriot/game.c Sun Nov 23 19:34:44 2008
@@ -293,7 +293,7 @@
#define CALL_DATA_INIT { 0, 0, 0, 0, 0, 0 };
-void
+static void
checked_write (int fildes, const void *buf, size_t nbyte)
{
int n_written;
@@ -1872,17 +1872,20 @@
}
/**
- * aisleriot_game_hint_lambda:
+ * aisleriot_game_get_hint:
* @game:
*
* Gets a hint.
*
- * Returns: a #SCM containing the hint
+ * Returns: a newly allocated string containing the hint message
*/
-SCM
-aisleriot_game_hint_lambda (AisleriotGame *game)
+char *
+aisleriot_game_get_hint (AisleriotGame *game)
{
CallData data = CALL_DATA_INIT;
+ SCM hint, string1, string2;
+ char *message = NULL;
+ char *str1, *str2;
data.lambda = game->hint_lambda;
data.n_args = 0;
@@ -1890,7 +1893,105 @@
cscmi_call_lambda, &data,
cscmi_catch_handler, NULL);
- return data.retval;
+ hint = data.retval;
+ /* FIXMEchpe: check for exceptions before this, so we don't crash here! */
+
+ if (!SCM_NFALSEP (hint)) {
+ message = g_strdup (_("This game does not have hint support yet."));
+ } else {
+ switch (scm_num2int (SCM_CAR (hint), SCM_ARG1, NULL)) {
+
+ case 0:
+ string1 = SCM_CADR (hint);
+ if (!scm_is_string (string1))
+ break;
+
+ str1 = scm_to_locale_string (string1);
+ if (!str1)
+ break;
+
+ message = g_strdup (str1);
+ free (str1);
+ break;
+
+ case 1:
+ string1 = SCM_CADR (hint);
+ string2 = SCM_CADDR (hint);
+
+ if (!scm_is_string (string1) || !scm_is_string (string2))
+ break;
+
+ str1 = scm_to_locale_string (string1);
+ if (!str1)
+ break;
+ str2 = scm_to_locale_string (string2);
+ if (!str2) {
+ free (str1);
+ break;
+ }
+
+ /* Both %s are card names */
+ message = g_strdup_printf (_("Move %s onto %s."), str1, str2);
+ free (str1);
+ free (str2);
+ break;
+
+ case 2:
+ /* NOTE! This case is exactly the same as case 1, but the strings
+ * are different: the first is a card name, the 2nd a sentence fragment.
+ * NOTE! FIXMEchpe! This is bad for i18n.
+ */
+ string1 = SCM_CADR (hint);
+ string2 = SCM_CADDR (hint);
+
+ if (!scm_is_string (string1) || !scm_is_string (string2))
+ break;
+
+ str1 = scm_to_locale_string (string1);
+ if (!str1)
+ break;
+ str2 = scm_to_locale_string (string2);
+ if (!str2) {
+ free (str1);
+ break;
+ }
+
+ /* The first %s is a card name, the 2nd %s a sentence fragment.
+ * Yes, we know this is bad for i18n.
+ */
+ message = g_strdup_printf (_("Move %s onto %s."), str1, str2);
+ free (str1);
+ free (str2);
+ break;
+
+ case 3: /* This is deprecated (due to i18n issues) do not use. */
+ g_warning ("This game uses a deprecated hint method (case 3).\n"
+ "Please file a bug at http://bugzilla.gnome.org "
+ "including this message and the name of the game "
+ "you were playing, which is %s.\n",
+ aisleriot_game_get_game_file (game));
+ break;
+
+ case 4:
+ string1 = SCM_CADR (hint);
+ if (!scm_is_string (string1))
+ break;
+
+ str1 = scm_to_locale_string (string1);
+ if (!str1)
+ break;
+
+ message = g_strdup_printf (_("You are searching for a %s."), str1);
+ free (str1);
+ break;
+
+ default:
+ message = g_strdup (_("This game is unable to provide a hint."));
+ break;
+ }
+ }
+
+ return message;
}
/**
Modified: trunk/aisleriot/game.h
==============================================================================
--- trunk/aisleriot/game.h (original)
+++ trunk/aisleriot/game.h Sun Nov 23 19:34:44 2008
@@ -179,7 +179,7 @@
gboolean aisleriot_game_button_double_clicked_lambda (AisleriotGame * game,
int slot_id);
-SCM aisleriot_game_hint_lambda (AisleriotGame * game);
+char *aisleriot_game_get_hint (AisleriotGame *game);
SCM aisleriot_game_get_options_lambda (AisleriotGame * game);
Modified: trunk/aisleriot/window.c
==============================================================================
--- trunk/aisleriot/window.c (original)
+++ trunk/aisleriot/window.c Sun Nov 23 19:34:44 2008
@@ -1067,9 +1067,7 @@
AisleriotWindow *window)
{
AisleriotWindowPrivate *priv = window->priv;
- SCM hint, string1, string2;
- char *message = NULL;
- char *str1, *str2;
+ char *message;
#ifndef HAVE_HILDON
GtkWidget *dialog;
#endif
@@ -1088,103 +1086,7 @@
if (aisleriot_game_get_state (priv->game) != GAME_RUNNING)
return;
- hint = aisleriot_game_hint_lambda (priv->game);
-
- if (!SCM_NFALSEP (hint)) {
- message = g_strdup (_("This game does not have hint support yet."));
- } else {
- switch (scm_num2int (SCM_CAR (hint), SCM_ARG1, NULL)) {
-
- case 0:
- string1 = SCM_CADR (hint);
- if (!scm_is_string (string1))
- break;
-
- str1 = scm_to_locale_string (string1);
- if (!str1)
- break;
-
- message = g_strdup (str1);
- free (str1);
- break;
-
- case 1:
- string1 = SCM_CADR (hint);
- string2 = SCM_CADDR (hint);
-
- if (!scm_is_string (string1) || !scm_is_string (string2))
- break;
-
- str1 = scm_to_locale_string (string1);
- if (!str1)
- break;
- str2 = scm_to_locale_string (string2);
- if (!str2) {
- free (str1);
- break;
- }
-
- /* Both %s are card names */
- message = g_strdup_printf (_("Move %s onto %s."), str1, str2);
- free (str1);
- free (str2);
- break;
-
- case 2:
- /* NOTE! This case is exactly the same as case 1, but the strings
- * are different: the first is a card name, the 2nd a sentence fragment.
- * NOTE! FIXMEchpe! This is bad for i18n.
- */
- string1 = SCM_CADR (hint);
- string2 = SCM_CADDR (hint);
-
- if (!scm_is_string (string1) || !scm_is_string (string2))
- break;
-
- str1 = scm_to_locale_string (string1);
- if (!str1)
- break;
- str2 = scm_to_locale_string (string2);
- if (!str2) {
- free (str1);
- break;
- }
-
- /* The first %s is a card name, the 2nd %s a sentence fragment.
- * Yes, we know this is bad for i18n.
- */
- message = g_strdup_printf (_("Move %s onto %s."), str1, str2);
- free (str1);
- free (str2);
- break;
-
- case 3: /* This is deprecated (due to i18n issues) do not use. */
- g_warning ("This game uses a deprecated hint method (case 3).\n"
- "Please file a bug at http://bugzilla.gnome.org "
- "including this message and the name of the game "
- "you were playing, which is %s.\n",
- aisleriot_game_get_game_file (priv->game));
- break;
-
- case 4:
- string1 = SCM_CADR (hint);
- if (!scm_is_string (string1))
- break;
-
- str1 = scm_to_locale_string (string1);
- if (!str1)
- break;
-
- message = g_strdup_printf (_("You are searching for a %s."), str1);
- free (str1);
- break;
-
- default:
- message = g_strdup (_("This game is unable to provide a hint."));
- break;
- }
- }
-
+ message = aisleriot_game_get_hint (priv->game);
if (!message)
return;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]