r22682 - gnucash/trunk/src - Move some guile convenience routines to core utils

Geert Janssens gjanssens at code.gnucash.org
Sat Dec 22 13:20:06 EST 2012


Author: gjanssens
Date: 2012-12-22 13:20:05 -0500 (Sat, 22 Dec 2012)
New Revision: 22682
Trac: http://svn.gnucash.org/trac/changeset/22682

Modified:
   gnucash/trunk/src/app-utils/guile-util.c
   gnucash/trunk/src/app-utils/guile-util.h
   gnucash/trunk/src/core-utils/gnc-guile-utils.c
   gnucash/trunk/src/core-utils/gnc-guile-utils.h
Log:
Move some guile convenience routines to core utils

They don't depend on any gui or engine code and are
used throughout the source

Modified: gnucash/trunk/src/app-utils/guile-util.c
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.c	2012-12-22 06:00:54 UTC (rev 22681)
+++ gnucash/trunk/src/app-utils/guile-util.c	2012-12-22 18:20:05 UTC (rev 22682)
@@ -145,173 +145,6 @@
 
 
 /********************************************************************\
- * gnc_guile_call1_to_string                                        *
- *   returns the malloc'ed string returned by the guile function    *
- *   or NULL if it can't be retrieved                               *
- *                                                                  *
- * Args: func - the guile function to call                          *
- *       arg  - the single function argument                        *
- * Returns: g_malloc'ed char * or NULL                              *
-\********************************************************************/
-char *
-gnc_guile_call1_to_string(SCM func, SCM arg)
-{
-    SCM value;
-
-    if (scm_is_procedure(func))
-    {
-        value = scm_call_1(func, arg);
-
-        if (scm_is_string(value))
-        {
-            return scm_to_locale_string(value);
-        }
-        else
-        {
-            PERR("bad value\n");
-        }
-    }
-    else
-    {
-        PERR("not a procedure\n");
-    }
-
-    return NULL;
-}
-
-
-/********************************************************************\
- * gnc_guile_call1_symbol_to_string                                 *
- *   returns the malloc'ed string returned by the guile function    *
- *   or NULL if it can't be retrieved. The return value of the      *
- *   function should be a symbol.                                   *
- *                                                                  *
- * Args: func - the guile function to call                          *
- *       arg  - the single function argument                        *
- * Returns: malloc'ed char * or NULL                                *
-\********************************************************************/
-char *
-gnc_guile_call1_symbol_to_string(SCM func, SCM arg)
-{
-    SCM symbol_value;
-
-    if (scm_is_procedure(func))
-    {
-        symbol_value = scm_call_1(func, arg);
-        return gnc_scm_symbol_to_locale_string (symbol_value);
-    }
-    else
-    {
-        PERR("not a procedure\n");
-    }
-
-    return NULL;
-}
-
-
-/********************************************************************\
- * gnc_guile_call1_to_procedure                                     *
- *   returns the SCM handle to the procedure returned by the guile  *
- *   function, or SCM_UNDEFINED if it couldn't be retrieved.        *
- *                                                                  *
- * Args: func - the guile function to call                          *
- *       arg  - the single function argument                        *
- * Returns: SCM function handle or SCM_UNDEFINED                    *
-\********************************************************************/
-SCM
-gnc_guile_call1_to_procedure(SCM func, SCM arg)
-{
-    SCM value;
-
-    if (scm_is_procedure(func))
-    {
-        value = scm_call_1(func, arg);
-
-        if (scm_is_procedure(value))
-            return value;
-        else
-        {
-            PERR("bad value\n");
-        }
-    }
-    else
-    {
-        PERR("not a procedure\n");
-    }
-
-    return SCM_UNDEFINED;
-}
-
-
-/********************************************************************\
- * gnc_guile_call1_to_list                                          *
- *   returns the SCM handle to the list returned by the guile       *
- *   function, or SCM_UNDEFINED if it couldn't be retrieved.        *
- *                                                                  *
- * Args: func - the guile function to call                          *
- *       arg  - the single function argument                        *
- * Returns: SCM list handle or SCM_UNDEFINED                        *
-\********************************************************************/
-SCM
-gnc_guile_call1_to_list(SCM func, SCM arg)
-{
-    SCM value;
-
-    if (scm_is_procedure(func))
-    {
-        value = scm_call_1(func, arg);
-
-        if (scm_is_list(value))
-            return value;
-        else
-        {
-            PERR("bad value\n");
-        }
-    }
-    else
-    {
-        PERR("not a procedure\n");
-    }
-
-    return SCM_UNDEFINED;
-}
-
-
-/********************************************************************\
- * gnc_guile_call1_to_vector                                        *
- *   returns the SCM handle to the vector returned by the guile     *
- *   function, or SCM_UNDEFINED if it couldn't be retrieved.        *
- *                                                                  *
- * Args: func - the guile function to call                          *
- *       arg  - the single function argument                        *
- * Returns: SCM vector handle or SCM_UNDEFINED                      *
-\********************************************************************/
-SCM
-gnc_guile_call1_to_vector(SCM func, SCM arg)
-{
-    SCM value;
-
-    if (scm_is_procedure(func))
-    {
-        value = scm_call_1(func, arg);
-
-        if (scm_is_vector(value))
-            return value;
-        else
-        {
-            PERR("bad value\n");
-        }
-    }
-    else
-    {
-        PERR("not a procedure\n");
-    }
-
-    return SCM_UNDEFINED;
-}
-
-
-/********************************************************************\
   gnc_scm_lookup
 
     returns the SCM binding associated with the given symbol function,

Modified: gnucash/trunk/src/app-utils/guile-util.h
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.h	2012-12-22 06:00:54 UTC (rev 22681)
+++ gnucash/trunk/src/app-utils/guile-util.h	2012-12-22 18:20:05 UTC (rev 22682)
@@ -31,17 +31,6 @@
 #include "Account.h"
 #include "gnc-guile-utils.h"
 
-
-/* Helpful functions for calling functions that return
- * specific kinds of values. These functions do error
- * checking to verify the result is of the correct type. */
-char * gnc_guile_call1_to_string(SCM func, SCM arg);
-char * gnc_guile_call1_symbol_to_string(SCM func, SCM arg);
-SCM    gnc_guile_call1_to_procedure(SCM func, SCM arg);
-SCM    gnc_guile_call1_to_list(SCM func, SCM arg);
-SCM    gnc_guile_list_ref(SCM list, int index);
-SCM    gnc_guile_call1_to_vector(SCM func, SCM arg);
-
 /* Don't use this to get hold of symbols that are considered private
  * to a given module unless the C code you're writing is considered
  * part of that module.  */

Modified: gnucash/trunk/src/core-utils/gnc-guile-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-guile-utils.c	2012-12-22 06:00:54 UTC (rev 22681)
+++ gnucash/trunk/src/core-utils/gnc-guile-utils.c	2012-12-22 18:20:05 UTC (rev 22682)
@@ -60,3 +60,170 @@
     PERR("bad value\n");
     return NULL;
 }
+
+
+/********************************************************************\
+ * gnc_guile_call1_to_string                                        *
+ *   returns the malloc'ed string returned by the guile function    *
+ *   or NULL if it can't be retrieved                               *
+ *                                                                  *
+ * Args: func - the guile function to call                          *
+ *       arg  - the single function argument                        *
+ * Returns: g_malloc'ed char * or NULL must be freed with g_free    *
+\********************************************************************/
+char *
+gnc_guile_call1_to_string(SCM func, SCM arg)
+{
+    SCM value;
+
+    if (scm_is_procedure(func))
+    {
+        value = scm_call_1(func, arg);
+
+        if (scm_is_string(value))
+        {
+            return gnc_scm_to_locale_string(value);
+        }
+        else
+        {
+            PERR("bad value\n");
+        }
+    }
+    else
+    {
+        PERR("not a procedure\n");
+    }
+
+    return NULL;
+}
+
+
+/********************************************************************\
+ * gnc_guile_call1_symbol_to_string                                 *
+ *   returns the malloc'ed string returned by the guile function    *
+ *   or NULL if it can't be retrieved. The return value of the      *
+ *   function should be a symbol.                                   *
+ *                                                                  *
+ * Args: func - the guile function to call                          *
+ *       arg  - the single function argument                        *
+ * Returns: malloc'ed char * or NULL                                *
+\********************************************************************/
+char *
+gnc_guile_call1_symbol_to_string(SCM func, SCM arg)
+{
+    SCM symbol_value;
+
+    if (scm_is_procedure(func))
+    {
+        symbol_value = scm_call_1(func, arg);
+        return gnc_scm_symbol_to_locale_string (symbol_value);
+    }
+    else
+    {
+        PERR("not a procedure\n");
+    }
+
+    return NULL;
+}
+
+
+/********************************************************************\
+ * gnc_guile_call1_to_procedure                                     *
+ *   returns the SCM handle to the procedure returned by the guile  *
+ *   function, or SCM_UNDEFINED if it couldn't be retrieved.        *
+ *                                                                  *
+ * Args: func - the guile function to call                          *
+ *       arg  - the single function argument                        *
+ * Returns: SCM function handle or SCM_UNDEFINED                    *
+\********************************************************************/
+SCM
+gnc_guile_call1_to_procedure(SCM func, SCM arg)
+{
+    SCM value;
+
+    if (scm_is_procedure(func))
+    {
+        value = scm_call_1(func, arg);
+
+        if (scm_is_procedure(value))
+            return value;
+        else
+        {
+            PERR("bad value\n");
+        }
+    }
+    else
+    {
+        PERR("not a procedure\n");
+    }
+
+    return SCM_UNDEFINED;
+}
+
+
+/********************************************************************\
+ * gnc_guile_call1_to_list                                          *
+ *   returns the SCM handle to the list returned by the guile       *
+ *   function, or SCM_UNDEFINED if it couldn't be retrieved.        *
+ *                                                                  *
+ * Args: func - the guile function to call                          *
+ *       arg  - the single function argument                        *
+ * Returns: SCM list handle or SCM_UNDEFINED                        *
+\********************************************************************/
+SCM
+gnc_guile_call1_to_list(SCM func, SCM arg)
+{
+    SCM value;
+
+    if (scm_is_procedure(func))
+    {
+        value = scm_call_1(func, arg);
+
+        if (scm_is_list(value))
+            return value;
+        else
+        {
+            PERR("bad value\n");
+        }
+    }
+    else
+    {
+        PERR("not a procedure\n");
+    }
+
+    return SCM_UNDEFINED;
+}
+
+
+/********************************************************************\
+ * gnc_guile_call1_to_vector                                        *
+ *   returns the SCM handle to the vector returned by the guile     *
+ *   function, or SCM_UNDEFINED if it couldn't be retrieved.        *
+ *                                                                  *
+ * Args: func - the guile function to call                          *
+ *       arg  - the single function argument                        *
+ * Returns: SCM vector handle or SCM_UNDEFINED                      *
+\********************************************************************/
+SCM
+gnc_guile_call1_to_vector(SCM func, SCM arg)
+{
+    SCM value;
+
+    if (scm_is_procedure(func))
+    {
+        value = scm_call_1(func, arg);
+
+        if (scm_is_vector(value))
+            return value;
+        else
+        {
+            PERR("bad value\n");
+        }
+    }
+    else
+    {
+        PERR("not a procedure\n");
+    }
+
+    return SCM_UNDEFINED;
+}

Modified: gnucash/trunk/src/core-utils/gnc-guile-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-guile-utils.h	2012-12-22 06:00:54 UTC (rev 22681)
+++ gnucash/trunk/src/core-utils/gnc-guile-utils.h	2012-12-22 18:20:05 UTC (rev 22682)
@@ -31,4 +31,13 @@
  *  a guile symbol. */
 gchar * gnc_scm_symbol_to_locale_string(SCM scm_string);
 
+/* Helpful functions for calling functions that return
+ * specific kinds of values. These functions do error
+ * checking to verify the result is of the correct type. */
+char * gnc_guile_call1_to_string(SCM func, SCM arg);
+char * gnc_guile_call1_symbol_to_string(SCM func, SCM arg);
+SCM    gnc_guile_call1_to_procedure(SCM func, SCM arg);
+SCM    gnc_guile_call1_to_list(SCM func, SCM arg);
+SCM    gnc_guile_call1_to_vector(SCM func, SCM arg);
+
 #endif



More information about the gnucash-changes mailing list