[Gnucash-changes] r12911 - gnucash/trunk/src - Process the --namespace command-line option from C, not guile.

Chris Shoemaker chris at cvs.gnucash.org
Fri Jan 20 22:50:25 EST 2006


Author: chris
Date: 2006-01-20 22:50:25 -0500 (Fri, 20 Jan 2006)
New Revision: 12911
Trac: http://svn.gnucash.org/trac/changeset/12911

Added:
   gnucash/trunk/src/core-utils/gnc-main.c
   gnucash/trunk/src/core-utils/gnc-main.h
Modified:
   gnucash/trunk/src/bin/Makefile.am
   gnucash/trunk/src/bin/gnucash-bin.c
   gnucash/trunk/src/core-utils/Makefile.am
   gnucash/trunk/src/engine/Makefile.am
   gnucash/trunk/src/engine/gnc-commodity.c
   gnucash/trunk/src/engine/gnc-commodity.h
   gnucash/trunk/src/engine/gw-engine-spec.scm
   gnucash/trunk/src/scm/price-quotes.scm
Log:
  Process the --namespace command-line option from C, not guile.


Modified: gnucash/trunk/src/bin/Makefile.am
===================================================================
--- gnucash/trunk/src/bin/Makefile.am	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/bin/Makefile.am	2006-01-21 03:50:25 UTC (rev 12911)
@@ -7,6 +7,7 @@
   -DGNC_SHAREDIR=\"${GNC_SHAREDIR}\" \
   -DGNC_HELPDIR=\"${GNC_HELPDIR}\" \
   -I${top_srcdir}/src \
+  -I${top_srcdir}/src/core-utils \
   -I${top_srcdir}/src/app-utils \
   -I${top_srcdir}/src/gnome-utils \
   -I${top_srcdir}/src/engine \
@@ -22,6 +23,7 @@
 ${top_builddir}/src/gnome/libgncgnome.la \
 ${top_builddir}/src/gnome-utils/libgncmod-gnome-utils.la \
 ${top_builddir}/src/app-utils/libgncmod-app-utils.la \
+${top_builddir}/src/core-utils/libcore-utils.la \
 ${top_builddir}/src/gnc-module/libgncmodule.la
 
 gnucash: gnucash.in ${top_builddir}/config.status Makefile

Modified: gnucash/trunk/src/bin/gnucash-bin.c
===================================================================
--- gnucash/trunk/src/bin/gnucash-bin.c	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/bin/gnucash-bin.c	2006-01-21 03:50:25 UTC (rev 12911)
@@ -40,6 +40,7 @@
 #include "gnc-hooks.h"
 #include "top-level.h"
 #include "gfec.h"
+#include "gnc-main.h"
 
 static int gnucash_show_version;
 /* GNUCASH_SVN is defined whenever we're building from an SVN tree */
@@ -149,7 +150,7 @@
     static const gchar *stylesheet_files[] = { "stylesheets-2.0", NULL};
     static int is_user_config_loaded = FALSE;
 
-    if (is_user_config_loaded) 
+    if (is_user_config_loaded)
         return;
     else is_user_config_loaded = TRUE;
 
@@ -183,6 +184,7 @@
     poptContext pc;
     char *p;
     int rc;
+    char *namespace_regexp = NULL;
 
     struct poptOption options[] = {
         POPT_AUTOHELP
@@ -205,7 +207,7 @@
          _("Set the search path for documentation files"), _("DOCPATH")},
         {"add-price-quotes", '\0', POPT_ARG_STRING, NULL, 0,
          _("Add price quotes to given FILE"), _("FILE")},
-        {"namespace", '\0', POPT_ARG_STRING, NULL, 0, 
+        {"namespace", '\0', POPT_ARG_STRING, &namespace_regexp, 0, 
          _("Regular expression determining which namespace commodities will be retrieved"), 
          _("REGEXP")},
         POPT_TABLEEND
@@ -225,6 +227,9 @@
         printf(_("built %s from r%s\n"), GNUCASH_BUILD_DATE, GNUCASH_SVN_REV);
         exit(0);
     }
+
+    if (namespace_regexp)
+        gnc_main_set_namespace_regexp(namespace_regexp);
     
     poptFreeContext(pc);
 }

Modified: gnucash/trunk/src/core-utils/Makefile.am
===================================================================
--- gnucash/trunk/src/core-utils/Makefile.am	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/core-utils/Makefile.am	2006-01-21 03:50:25 UTC (rev 12911)
@@ -2,6 +2,7 @@
 lib_LTLIBRARIES = libcore-utils.la libgw-core-utils.la
 
 libcore_utils_la_SOURCES = \
+  gnc-main.c \
   gnc-gconf-utils.c \
   gnc-gdate-utils.c \
   gnc-gkeyfile-utils.c \
@@ -22,6 +23,7 @@
   ${GUILE_LIBS}
 
 noinst_HEADERS = \
+  gnc-main.h \
   gnc-gconf-utils.h \
   gnc-gdate-utils.h \
   gnc-gkeyfile-utils.h \

Added: gnucash/trunk/src/core-utils/gnc-main.c
===================================================================
--- gnucash/trunk/src/core-utils/gnc-main.c	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/core-utils/gnc-main.c	2006-01-21 03:50:25 UTC (rev 12911)
@@ -0,0 +1,43 @@
+/*
+ * gnc-main.c:
+ *
+ * Copyright (C) 2006 Chris Shoemaker <c.shoemaker at cox.net>
+ *
+ * This program 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 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+#include "config.h"
+#include "gnc-main.h"
+
+static char *namespace_regexp = NULL;
+
+void 
+gnc_main_set_namespace_regexp(const char *str)
+{
+    if (namespace_regexp)
+        g_free(namespace_regexp);
+
+    if (str)
+        namespace_regexp = g_strdup(str);
+}
+
+const char *gnc_main_get_namespace_regexp(void)
+{
+    return namespace_regexp;
+}
+

Added: gnucash/trunk/src/core-utils/gnc-main.h
===================================================================
--- gnucash/trunk/src/core-utils/gnc-main.h	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/core-utils/gnc-main.h	2006-01-21 03:50:25 UTC (rev 12911)
@@ -0,0 +1,33 @@
+/*
+ * gnc-main.h:
+ *
+ * Copyright (C) 2006 Chris Shoemaker <c.shoemaker at cox.net>
+ *
+ * This program 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 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program 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, contact:
+ *
+ * Free Software Foundation           Voice:  +1-617-542-5942
+ * 51 Franklin Street, Fifth Floor    Fax:    +1-617-542-2652
+ * Boston, MA  02110-1301,  USA       gnu at gnu.org
+ */
+
+#ifndef GNC_MAIN_H
+#define GNC_MAIN_H
+
+#include <glib.h>
+
+void gnc_main_set_namespace_regexp(const char *str);
+const char *gnc_main_get_namespace_regexp(void);
+
+
+#endif /* GNC_MAIN_H */

Modified: gnucash/trunk/src/engine/Makefile.am
===================================================================
--- gnucash/trunk/src/engine/Makefile.am	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/engine/Makefile.am	2006-01-21 03:50:25 UTC (rev 12911)
@@ -106,6 +106,7 @@
  libgw-engine.la \
  libgw-kvp.la \
  ../gnc-module/libgncmodule.la \
+ ${top_builddir}/src/core-utils/libcore-utils.la \
  ../../lib/libc/libc-missing.la
 
 libgw_kvp_la_SOURCES = gw-kvp.c kvp-scm.c

Modified: gnucash/trunk/src/engine/gnc-commodity.c
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.c	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/engine/gnc-commodity.c	2006-01-21 03:50:25 UTC (rev 12911)
@@ -36,6 +36,7 @@
 #include <regex.h>
 
 #include "gnc-commodity.h"
+#include "gnc-main.h"
 
 static QofLogModule log_module = GNC_MOD_COMMODITY; 
 
@@ -1364,14 +1365,14 @@
 }
 
 GList * 
-gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table,
-					     const char *expression)
+gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table)
 {
   gnc_commodity_namespace * ns = NULL;
   const char *namespace;
   GList * nslist, * tmp;
   GList * l = NULL;
   regex_t pattern;
+  const char *expression = gnc_main_get_namespace_regexp();
 
   ENTER("table=%p, expression=%s", table, expression);
   if (!table)

Modified: gnucash/trunk/src/engine/gnc-commodity.h
===================================================================
--- gnucash/trunk/src/engine/gnc-commodity.h	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/engine/gnc-commodity.h	2006-01-21 03:50:25 UTC (rev 12911)
@@ -784,22 +784,21 @@
  *  should be retrieved.  It will scan the entire commodity table (or
  *  a subset) and check each commodity to see if the price_quote_flag
  *  field has been set.  All matching commodities are queued onto a
- *  list, and the head of that list is returned.
+ *  list, and the head of that list is returned.  Use the command-line
+ *  given expression as a filter on the commodities to be returned. If
+ *  non-null, only commodities in namespace that match the specified
+ *  regular expression are checked.  If none was given, all
+ *  commodities are checked.
  *
  *  @param table A pointer to the commodity table 
  *
- *  @param expression Use the given expression as a filter on the
- *  commodities to be returned. If non-null, only commodities in
- *  namespace that match the specified regular expression are checked.
- *  If null, all commodities are checked.
- *
  *  @return A pointer to a list of commodities.  NULL if invalid
  *  arguments were supplied or if there no commodities are flagged for
  *  quote retrieval.
  *
  *  @note It is the callers responsibility to free the list. */
-GList * gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table,
-						     const char * expression);
+GList * gnc_commodity_table_get_quotable_commodities(
+    const gnc_commodity_table * table);
 
 /** Call a function once for each commodity in the commodity table.
  *  This table walk returns whenever the end of the table is reached,

Modified: gnucash/trunk/src/engine/gw-engine-spec.scm
===================================================================
--- gnucash/trunk/src/engine/gw-engine-spec.scm	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/engine/gw-engine-spec.scm	2006-01-21 03:50:25 UTC (rev 12911)
@@ -729,7 +729,7 @@
  "xaccAccountFixSplitDateOrder"
  '((<gnc:Account*> a) (<gnc:Split*> s))
  "Check to see if split s is in proper sorted date order with respect
-to the other splits in account a.")
+ to the other splits in account a.")
 
 (gw:wrap-function
  ws
@@ -2172,8 +2172,7 @@
  'gnc:commodity-table-get-quotable-commodities
  '(gw:glist-of <gnc:commodity*> caller-owned)
  "gnc_commodity_table_get_quotable_commodities"
- '((<gnc:commodity-table*> table)
-   ((<gw:mchars> caller-owned const) namespace))
+ '((<gnc:commodity-table*> table))
  "Return a list of all the quotable commodities in a given namespace in the table.")
 
 (gw:wrap-function

Modified: gnucash/trunk/src/scm/price-quotes.scm
===================================================================
--- gnucash/trunk/src/scm/price-quotes.scm	2006-01-20 14:52:57 UTC (rev 12910)
+++ gnucash/trunk/src/scm/price-quotes.scm	2006-01-21 03:50:25 UTC (rev 12911)
@@ -23,9 +23,9 @@
 (define-module (gnucash price-quotes))
 
 (export yahoo-get-historical-quotes)
-(export gnc:fq-check-sources)
-(export gnc:book-add-quotes)
-(export gnc:add-quotes-to-book-at-url)
+(export gnc:fq-check-sources) ;; called in main.scm
+(export gnc:book-add-quotes) ;; called from gnome/dialog-price-edit-db.c
+(export gnc:add-quotes-to-book-at-url) ;; called in command-line.scm
 
 (use-modules (gnucash process))
 (use-modules (www main))
@@ -373,17 +373,16 @@
     (let* ((ct (gnc:book-get-commodity-table book))
 	   (big-list
 	    (gnc:commodity-table-get-quotable-commodities-info
-	     ct
-	     (gnc:config-var-value-get gnc:*namespace-regexp*)))
+	     ct))
 	   (commodity-list #f)
 	   (currency-list (filter
 			   (lambda (a) (not (equal? (cadr a) (caddr a))))
 			   (call-with-values 
-			   (lambda () (partition!
-				       (lambda (cmd)
-					 (not (string=? (car cmd) "currency")))
-				       big-list))
-			   (lambda (a b) (set! commodity-list a) b))))
+                               (lambda () (partition!
+                                           (lambda (cmd)
+                                             (not (string=? (car cmd) "currency")))
+                                           big-list))
+                             (lambda (a b) (set! commodity-list a) b))))
 	   (quote-hash (make-hash-table 31)))
 
       (if (null? big-list)



More information about the gnucash-changes mailing list