mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
Allow the user to specify by namespace which commodities should be
retrieved when getting price quotes. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8839 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
12
ChangeLog
12
ChangeLog
@@ -1,3 +1,15 @@
|
||||
2003-07-03 David Hampton <hampton@employees.org>
|
||||
|
||||
* src/scm/price-quotes.scm:
|
||||
* src/engine/gnc-commodity.[ch]: Allow the user to specify by
|
||||
namespace which commodities should be retrieved when getting price
|
||||
quotes.
|
||||
|
||||
* src/scm/command-line.scm:
|
||||
* src/scm/main.scm: Support a new command line argument for
|
||||
specifying a namespace. To be used in conjunction with the
|
||||
--add-price-quotes argument.
|
||||
|
||||
2003-07-02 Chris Lyttle <chris@wilddev.net>
|
||||
|
||||
* src/scm/help-topics-index.scm: add Jon Lapham's patch
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <glib.h>
|
||||
#include <regex.h>
|
||||
|
||||
#include "gnc-commodity.h"
|
||||
#include "gnc-engine-util.h"
|
||||
@@ -1233,20 +1234,37 @@ get_quotables_helper2 (gnc_commodity *comm, gpointer data)
|
||||
|
||||
GList *
|
||||
gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table,
|
||||
const char * namespace)
|
||||
const char *expression)
|
||||
{
|
||||
gnc_commodity_namespace * ns = NULL;
|
||||
const char *namespace;
|
||||
GList * nslist, * tmp;
|
||||
GList * l = NULL;
|
||||
regex_t pattern;
|
||||
|
||||
ENTER("table=%p, namespace=%s", table, namespace);
|
||||
ENTER("table=%p, expression=%s", table, expression);
|
||||
if (!table)
|
||||
return NULL;
|
||||
|
||||
if (namespace && *namespace) {
|
||||
ns = g_hash_table_lookup(table->table, (gpointer)namespace);
|
||||
DEBUG("ns=%p", ns);
|
||||
if (ns)
|
||||
g_hash_table_foreach(ns->table, &get_quotables_helper1, (gpointer) &l);
|
||||
if (expression && *expression) {
|
||||
if (regcomp(&pattern, expression, REG_EXTENDED|REG_ICASE) != 0) {
|
||||
LEAVE("Cannot compile regex");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
nslist = gnc_commodity_table_get_namespaces(table);
|
||||
for (tmp = nslist; tmp; tmp = tmp->next) {
|
||||
namespace = tmp->data;
|
||||
if (regexec(&pattern, namespace, 0, NULL, 0) == 0) {
|
||||
DEBUG("Running list of %s commodities", namespace);
|
||||
ns = g_hash_table_lookup(table->table, namespace);
|
||||
if (ns) {
|
||||
g_hash_table_foreach(ns->table, &get_quotables_helper1, (gpointer) &l);
|
||||
}
|
||||
}
|
||||
}
|
||||
g_list_free(nslist);
|
||||
regfree(&pattern);
|
||||
} else {
|
||||
gnc_commodity_table_foreach_commodity(table, get_quotables_helper2,
|
||||
(gpointer) &l);
|
||||
|
||||
@@ -747,10 +747,10 @@ GList * gnc_commodity_table_get_commodities(const gnc_commodity_table * t,
|
||||
* @param table A pointer to the commodity table for the current
|
||||
* book.
|
||||
*
|
||||
* @param namespace Use the given namespace as a filter on the
|
||||
* commodities to be returned. If non-null, only commodities in the
|
||||
* specified namespace are checked. If null, all commodities are
|
||||
* checked.
|
||||
* @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
|
||||
@@ -758,7 +758,7 @@ GList * gnc_commodity_table_get_commodities(const gnc_commodity_table * t,
|
||||
*
|
||||
* @note It is the callers responsibility to free the list. */
|
||||
GList * gnc_commodity_table_get_quotable_commodities(const gnc_commodity_table * table,
|
||||
const char * namespace);
|
||||
const char * expression);
|
||||
|
||||
/** Call a function once for each commodity in the commodity table.
|
||||
* This table walk returns whenever the end of the table is reached,
|
||||
|
||||
@@ -31,6 +31,7 @@
|
||||
(define gnc:*config-path* #f)
|
||||
(define gnc:*share-path* #f)
|
||||
(define gnc:*doc-path* #f)
|
||||
(define gnc:*namespace-regexp* #f)
|
||||
|
||||
;; If command line args are present, then those dominate, and take
|
||||
;; effect in order, left-to-right. Otherwise, any envt var setting
|
||||
@@ -85,6 +86,13 @@
|
||||
eq?
|
||||
#f))
|
||||
|
||||
(set! gnc:*namespace-regexp*
|
||||
(gnc:make-config-var
|
||||
(N_ "Limit price quotes retrieved to commodities whose namespace matched this regexp.")
|
||||
(lambda (var value) (if (string? value) (list value) #f))
|
||||
eq?
|
||||
#f))
|
||||
|
||||
;; Convert the temporary startup value into a config var.
|
||||
(let ((current-value gnc:*debugging?*))
|
||||
(set!
|
||||
@@ -292,6 +300,14 @@ the current value of the path.")
|
||||
"FILE"
|
||||
(N_ "Add price quotes to given FILE."))
|
||||
|
||||
(list "namespace"
|
||||
'string
|
||||
(lambda (val)
|
||||
(gnc:debug "parsing --namespace " val)
|
||||
(gnc:config-var-value-set! gnc:*namespace-regexp* #f val))
|
||||
#f
|
||||
(N_ "Regular expression determining which namespace commodities will be retrieved"))
|
||||
|
||||
(list "load-user-config"
|
||||
'boolean
|
||||
gnc:load-user-config-if-needed
|
||||
|
||||
@@ -66,6 +66,7 @@
|
||||
(export gnc:*config-path*)
|
||||
(export gnc:*share-path*)
|
||||
(export gnc:*doc-path*)
|
||||
(export gnc:*namespace-regexp*)
|
||||
|
||||
;; from doc.scm
|
||||
(export gnc:find-doc-file)
|
||||
|
||||
@@ -371,7 +371,10 @@
|
||||
;; ...)
|
||||
|
||||
(let* ((ct (gnc:book-get-commodity-table book))
|
||||
(big-list (gnc:commodity-table-get-quotable-commodities-info ct ""))
|
||||
(big-list
|
||||
(gnc:commodity-table-get-quotable-commodities-info
|
||||
ct
|
||||
(gnc:config-var-value-get gnc:*namespace-regexp*)))
|
||||
(commodity-list #f)
|
||||
(currency-list (filter
|
||||
(lambda (a) (not (equal? (cadr a) (caddr a))))
|
||||
|
||||
Reference in New Issue
Block a user