* src/import-export/qif-context.c: add functions to get the list

of used QifAccount and QifCategory objects from the set of
	  transactions.


git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@8970 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Derek Atkins
2003-07-29 22:22:24 +00:00
parent 788d113c86
commit 5f5a7485ee
4 changed files with 114 additions and 4 deletions
+4
View File
@@ -4,6 +4,10 @@
qif file contexts into a single parent context while retaining qif file contexts into a single parent context while retaining
the ability to add/remove new files. the ability to add/remove new files.
* src/import-export/qif-context.c: add functions to get the list
of used QifAccount and QifCategory objects from the set of
transactions.
2003-07-28 Derek Atkins <derek@ihtfp.com> 2003-07-28 Derek Atkins <derek@ihtfp.com>
* src/business/business-gnome/business-gnome.scm: remove * src/business/business-gnome/business-gnome.scm: remove
+100 -1
View File
@@ -12,6 +12,9 @@
#include <glib.h> #include <glib.h>
#include "qif-import-p.h" #include "qif-import-p.h"
#include "qif-objects-p.h"
static void qif_object_map_get_helper(gpointer key, gpointer value, gpointer listp);
QifContext QifContext
qif_context_new(void) qif_context_new(void)
@@ -59,6 +62,103 @@ qif_context_destroy(QifContext ctx)
g_free(ctx); g_free(ctx);
} }
static GList *
qif_context_get_foo_helper(QifContext ctx, GFunc get_helper)
{
GHashTable *ht;
GList *node, *list = NULL;
QifContext fctx;
g_return_val_if_fail(ctx, NULL);
g_return_val_if_fail(ctx->parsed, NULL);
g_return_val_if_fail(get_helper, NULL);
ht = g_hash_table_new(g_direct_hash, g_direct_equal);
for (node = ctx->files; node; node = node->next) {
fctx = node->data;
qif_object_list_foreach(fctx, QIF_O_TXN, get_helper, ht);
}
g_hash_table_foreach(ht, qif_object_map_get_helper, &list);
g_hash_table_destroy(ht);
return list;
}
static void
qif_split_accts_helper(QifSplit split, GHashTable *ht)
{
if (split->cat.obj && split->cat_is_acct)
g_hash_table_insert(ht, split->cat.acct, split->cat.acct);
}
static void
qif_get_accts_helper(gpointer obj, gpointer htp)
{
QifTxn txn = obj;
QifSplit split;
GHashTable *ht = htp;
GList *node;
if (txn->from_acct)
g_hash_table_insert(ht, txn->from_acct, txn->from_acct);
if (txn->invst_info && txn->invst_info->far_cat.obj &&
txn->invst_info->far_cat_is_acct)
g_hash_table_insert(ht, txn->invst_info->far_cat.acct,
txn->invst_info->far_cat.acct);
if (txn->default_split)
qif_split_accts_helper(txn->default_split, ht);
for (node = txn->splits; node; node = node->next) {
split = node->data;
qif_split_accts_helper(split, ht);
}
}
GList *
qif_context_get_accounts(QifContext ctx)
{
return qif_context_get_foo_helper(ctx, qif_get_accts_helper);
}
static void
qif_split_cats_helper(QifSplit split, GHashTable *ht)
{
if (split->cat.obj && !split->cat_is_acct)
g_hash_table_insert(ht, split->cat.cat, split->cat.cat);
}
static void
qif_get_cats_helper(gpointer obj, gpointer htp)
{
QifTxn txn = obj;
QifSplit split;
GHashTable *ht = htp;
GList *node;
if (txn->invst_info && txn->invst_info->far_cat.obj &&
!txn->invst_info->far_cat_is_acct)
g_hash_table_insert(ht, txn->invst_info->far_cat.cat,
txn->invst_info->far_cat.cat);
if (txn->default_split)
qif_split_cats_helper(txn->default_split, ht);
for (node = txn->splits; node; node = node->next) {
split = node->data;
qif_split_cats_helper(split, ht);
}
}
GList *
qif_context_get_categories(QifContext ctx)
{
return qif_context_get_foo_helper(ctx, qif_get_cats_helper);
}
/*****************************************************************************/ /*****************************************************************************/
/* /*
@@ -302,4 +402,3 @@ qif_object_list_destroy(QifContext ctx)
g_hash_table_foreach_remove(ctx->object_lists, qif_object_list_remove_all, NULL); g_hash_table_foreach_remove(ctx->object_lists, qif_object_list_remove_all, NULL);
g_hash_table_destroy(ctx->object_lists); g_hash_table_destroy(ctx->object_lists);
} }
+10
View File
@@ -125,4 +125,14 @@ void qif_file_set_default_account(QifContext ctx, const char *acct_name);
/* Parse the QIF File */ /* Parse the QIF File */
QifError qif_file_parse(QifContext ctx, gpointer ui_arg); QifError qif_file_parse(QifContext ctx, gpointer ui_arg);
/* Merge all the qif-files from the children and into the context */
void qif_parse_merge_files(QifContext ctx);
/* Obtain the list of USED QifAccounts and QifCategories. Finds all
* references from the transactions in the QifContext. The returned
* GList must be freed by the caller.
*/
GList *qif_context_get_accounts(QifContext ctx);
GList *qif_context_get_categories(QifContext ctx);
#endif /* QIF_IMPORT_H */ #endif /* QIF_IMPORT_H */
-3
View File
@@ -30,7 +30,4 @@ GList * qif_parse_acct_type_guess(QifType type);
/* Parse all objects */ /* Parse all objects */
void qif_parse_all(QifContext ctx, gpointer ui_args); void qif_parse_all(QifContext ctx, gpointer ui_args);
/* Merge all the qif-files from the children and into the context */
void qif_parse_merge_files(QifContext ctx);
#endif /* QIF_PARSE_H */ #endif /* QIF_PARSE_H */