r22687 - gnucash/trunk/src - Move gnc_guile_strip_comments to core-utils and normalize its name to

Geert Janssens gjanssens at code.gnucash.org
Sat Dec 22 13:21:04 EST 2012


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

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
   gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
Log:
Move gnc_guile_strip_comments to core-utils and normalize its name to
gnc_scm_strip_comments

Also make it a true convenience functions by doing the conversion from
an scm string to a c string internally. This saves the caller a manual
conversion step.

Modified: gnucash/trunk/src/app-utils/guile-util.c
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.c	2012-12-22 18:20:53 UTC (rev 22686)
+++ gnucash/trunk/src/app-utils/guile-util.c	2012-12-22 18:21:03 UTC (rev 22687)
@@ -949,32 +949,6 @@
 }
 
 
-/*  Clean up a scheme options string for use in a key/value file.
- *  This function removes all full line comments, removes all blank
- *  lines, and removes all leading/trailing white space. */
-gchar *gnc_guile_strip_comments (const gchar *raw_text)
-{
-    gchar *text, **splits;
-    gint i, j;
-
-    splits = g_strsplit(raw_text, "\n", -1);
-    for (i = j = 0; splits[i]; i++)
-    {
-        if ((splits[i][0] == ';') || (splits[i][0] == '\0'))
-        {
-            g_free(splits[i]);
-            continue;
-        }
-        splits[j++] = g_strstrip(splits[i]);
-    }
-    splits[j] = NULL;
-
-    text = g_strjoinv(" ", splits);
-    g_strfreev(splits);
-    return text;
-}
-
-
 static void
 on_child_exit (GPid pid, gint status, gpointer data)
 {

Modified: gnucash/trunk/src/app-utils/guile-util.h
===================================================================
--- gnucash/trunk/src/app-utils/guile-util.h	2012-12-22 18:20:53 UTC (rev 22686)
+++ gnucash/trunk/src/app-utils/guile-util.h	2012-12-22 18:21:03 UTC (rev 22687)
@@ -83,15 +83,6 @@
 char * gnc_get_debit_string(GNCAccountType account_type);
 char * gnc_get_credit_string(GNCAccountType account_type);
 
-/** Clean up a scheme options string for use in a key/value file.
- *  This function removes all full line comments, removes all blank
- *  lines, and removes all leading/trailing white space.
- *
- *  @note: This function does not correctly handle comments that occur
- *  at the end of a line. Fortunately there aren't any such
- *  comments. */
-gchar *gnc_guile_strip_comments (const gchar *text);
-
 /** An opaque process structure returned by gnc_spawn_process_async. */
 typedef struct _Process Process;
 

Modified: gnucash/trunk/src/core-utils/gnc-guile-utils.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-guile-utils.c	2012-12-22 18:20:53 UTC (rev 22686)
+++ gnucash/trunk/src/core-utils/gnc-guile-utils.c	2012-12-22 18:21:03 UTC (rev 22687)
@@ -255,3 +255,31 @@
 
     return SCM_UNDEFINED;
 }
+
+
+/*  Clean up a scheme options string for use in a key/value file.
+ *  This function removes all full line comments, removes all blank
+ *  lines, and removes all leading/trailing white space. */
+gchar *gnc_scm_strip_comments (SCM scm_text)
+{
+    gchar *raw_text, *text, **splits;
+    gint i, j;
+
+    raw_text = gnc_scm_to_locale_string (scm_text);
+    splits = g_strsplit(raw_text, "\n", -1);
+    for (i = j = 0; splits[i]; i++)
+    {
+        if ((splits[i][0] == ';') || (splits[i][0] == '\0'))
+        {
+            g_free(splits[i]);
+            continue;
+        }
+        splits[j++] = g_strstrip(splits[i]);
+    }
+    splits[j] = NULL;
+
+    text = g_strjoinv(" ", splits);
+    g_free (raw_text);
+    g_strfreev(splits);
+    return text;
+}

Modified: gnucash/trunk/src/core-utils/gnc-guile-utils.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-guile-utils.h	2012-12-22 18:20:53 UTC (rev 22686)
+++ gnucash/trunk/src/core-utils/gnc-guile-utils.h	2012-12-22 18:21:03 UTC (rev 22687)
@@ -55,4 +55,13 @@
 #define gnc_guile_call1_to_list gnc_scm_call_1_to_list
 #define gnc_guile_call1_to_vector gnc_scm_call_1_to_vector
 
+/** Clean up a scheme options string for use in a key/value file.
+ *  This function removes all full line comments, removes all blank
+ *  lines, and removes all leading/trailing white space.
+ *
+ *  @note: This function does not correctly handle comments that occur
+ *  at the end of a line. Fortunately there aren't any such
+ *  comments. */
+gchar *gnc_scm_strip_comments (SCM scm_text);
+
 #endif

Modified: gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c
===================================================================
--- gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c	2012-12-22 18:20:53 UTC (rev 22686)
+++ gnucash/trunk/src/report/report-gnome/gnc-plugin-page-report.c	2012-12-22 18:21:03 UTC (rev 22687)
@@ -64,7 +64,6 @@
 #include "gnc-ui-util.h"
 #include "gnc-ui.h"
 #include "gnc-window.h"
-#include "guile-util.h"
 #include "option-util.h"
 #include "window-report.h"
 #include "swig-runtime.h"
@@ -732,7 +731,6 @@
     SCM get_embedded_list, embedded, item, tmp_report;
     gint count, id;
     gchar *text, *key_name;
-    char * str;
 
     g_return_if_fail (GNC_IS_PLUGIN_PAGE_REPORT(plugin_page));
     g_return_if_fail (key_file != NULL);
@@ -771,11 +769,9 @@
         }
 
         key_name = g_strdup_printf(SCHEME_OPTIONS_N, id);
-        str = gnc_scm_to_locale_string (scm_text);
-        text = gnc_guile_strip_comments(str);
+        text = gnc_scm_strip_comments(scm_text);
         g_key_file_set_string(key_file, group_name, key_name, text);
         g_free(text);
-        g_free (str);
         g_free(key_name);
     }
 
@@ -786,11 +782,9 @@
         return;
     }
 
-    str = gnc_scm_to_locale_string (scm_text);
-    text = gnc_guile_strip_comments(str);
+    text = gnc_scm_strip_comments(scm_text);
     g_key_file_set_string(key_file, group_name, SCHEME_OPTIONS, text);
     g_free(text);
-    g_free (str);
     LEAVE(" ");
 }
 



More information about the gnucash-changes mailing list