31 #include "gnc-xml-helper.h"
35 #include "sixtp-utils.h"
36 #include "sixtp-parsers.h"
37 #include "sixtp-utils.h"
38 #include "sixtp-dom-parsers.h"
39 #include "sixtp-dom-generators.h"
45 #include "sixtp-dom-parsers.h"
49 const gchar *freqspec_version_string =
"1.0.0";
63 {
"monthly", MONTHLY },
64 {
"month_relative", MONTH_RELATIVE },
65 {
"composite", COMPOSITE },
77 {
"none", UIFREQ_NONE },
78 {
"once", UIFREQ_ONCE },
79 {
"daily", UIFREQ_DAILY },
80 {
"daily_mf", UIFREQ_DAILY_MF },
81 {
"weekly", UIFREQ_WEEKLY },
82 {
"bi_weekly", UIFREQ_BI_WEEKLY },
83 {
"semi_monthly", UIFREQ_SEMI_MONTHLY },
84 {
"monthly", UIFREQ_MONTHLY },
85 {
"quarterly", UIFREQ_QUARTERLY },
86 {
"tri_anually", UIFREQ_TRI_ANUALLY },
87 {
"semi_yearly", UIFREQ_SEMI_YEARLY },
88 {
"yearly", UIFREQ_YEARLY },
100 GList *recurrence_list;
119 fspd->recurrence_list = NULL;
120 fspd->uift = UIFREQ_NONE;
126 fspd->weekend_adj = WEEKEND_ADJ_NONE;
127 g_date_clear( &fspd->once_day, 1 );
132 gnc_fs_handler( xmlNodePtr node, gpointer d );
136 fs_uift_handler( xmlNodePtr node, gpointer data)
143 nodeTxt = dom_tree_to_text( node );
145 g_return_val_if_fail( nodeTxt, FALSE );
146 for ( i = 0; (tmp = uiFreqTypeStrs[i].str) != NULL; i++ )
148 if ( g_strcmp0( nodeTxt, tmp ) == 0 )
150 fspd->uift = uiFreqTypeStrs[i].uift;
161 fs_date_handler( xmlNodePtr node, gpointer data )
165 foo = dom_tree_to_gdate( node );
168 fspd->once_day = *foo;
175 fs_interval_handler( xmlNodePtr node, gpointer data )
181 ret = dom_tree_to_integer( node, &foo );
186 fspd->interval = foo;
192 fs_offset_handler( xmlNodePtr node, gpointer data )
198 ret = dom_tree_to_integer( node, &foo );
207 fs_day_handler( xmlNodePtr node, gpointer data )
213 ret = dom_tree_to_integer( node, &foo );
222 fs_weekday_handler( xmlNodePtr node, gpointer data)
227 ret = dom_tree_to_integer( node, &foo );
236 fs_occurrence_handler( xmlNodePtr node, gpointer data )
241 ret = dom_tree_to_integer( node, &foo );
244 fspd->occurrence = foo;
250 fs_weekend_adj_handler( xmlNodePtr node, gpointer data )
255 ret = dom_tree_to_integer( node, &foo );
258 fspd->weekend_adj = foo;
264 fs_subelement_handler( xmlNodePtr node, gpointer data )
269 recurrences = dom_tree_freqSpec_to_recurrences(node, fspd->book);
270 if (recurrences == NULL)
275 for (r_iter = recurrences; r_iter != NULL; r_iter = r_iter->next)
278 GDate recurrence_date;
279 if (fspd->uift == UIFREQ_SEMI_MONTHLY)
282 recurrence_date = recurrenceGetDate(r);
283 recurrenceSet(r, recurrenceGetMultiplier(r), PERIOD_MONTH, &recurrence_date, recurrenceGetWeekendAdjust(r));
285 fspd->recurrence_list = g_list_append(fspd->recurrence_list, r);
293 {
"fs:date", fs_date_handler, 0, 0 },
294 {
"fs:interval", fs_interval_handler, 0, 0 },
295 {
"fs:offset", fs_offset_handler, 0, 0 },
296 {
"fs:day", fs_day_handler, 0, 0 },
297 {
"fs:weekday", fs_weekday_handler, 0, 0 },
298 {
"fs:occurrence", fs_occurrence_handler, 0, 0 },
299 {
"fs:weekend_adj", fs_weekend_adj_handler, 0, 0 },
300 {
"gnc:freqspec", fs_subelement_handler, 0, 0 },
301 { NULL, NULL, 0, 0 },
305 fs_none_handler( xmlNodePtr node, gpointer data )
309 successful = dom_tree_generic_parse( node,
310 fs_union_dom_handlers,
317 fs_once_handler( xmlNodePtr node, gpointer data )
322 successful = dom_tree_generic_parse( node,
323 fs_union_dom_handlers,
327 recurrenceSet(fspd->recurrence, 0, PERIOD_ONCE, &fspd->once_day, WEEKEND_ADJ_NONE);
333 fs_daily_handler(xmlNodePtr node, gpointer data)
338 successful = dom_tree_generic_parse(node, fs_union_dom_handlers, fspd );
342 g_date_clear(&offset_date, 1);
343 g_date_set_julian(&offset_date, fspd->offset == 0 ? 7 : fspd->offset);
344 recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_DAY, &offset_date, WEEKEND_ADJ_NONE);
351 fs_weekly_handler( xmlNodePtr node, gpointer data )
356 successful = dom_tree_generic_parse( node,
357 fs_union_dom_handlers,
362 g_date_clear(&offset_date, 1);
363 g_date_set_julian(&offset_date, fspd->offset == 0 ? 7 : fspd->offset);
364 recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_WEEK, &offset_date, WEEKEND_ADJ_NONE);
371 fs_monthly_handler( xmlNodePtr node, gpointer data)
376 successful = dom_tree_generic_parse( node,
377 fs_union_dom_handlers,
383 g_date_clear(&offset_date, 1);
384 g_date_set_julian(&offset_date, 1);
385 g_date_add_months(&offset_date, fspd->offset);
386 g_date_set_day(&offset_date, fspd->day);
387 if (fspd->uift == UIFREQ_ONCE)
390 recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_ONCE, &offset_date, WEEKEND_ADJ_NONE);
394 recurrenceSet(fspd->recurrence, fspd->interval, PERIOD_MONTH, &offset_date, fspd->weekend_adj);
402 fs_month_relative_handler( xmlNodePtr node, gpointer data)
404 g_critical(
"this was never supported, how is it in the datafile?");
410 fs_guid_handler( xmlNodePtr node, gpointer data)
417 fs_composite_handler( xmlNodePtr node, gpointer data)
421 successful = dom_tree_generic_parse( node,
422 fs_union_dom_handlers,
429 {
"gnc:freqspec", gnc_fs_handler, 0, 0 },
430 {
"fs:ui_type", fs_uift_handler, 1, 0 },
431 {
"fs:id", fs_guid_handler, 1, 0 },
432 {
"fs:none", fs_none_handler, 0, 0 },
433 {
"fs:once", fs_once_handler, 0, 0 },
434 {
"fs:daily", fs_daily_handler, 0, 0 },
435 {
"fs:weekly", fs_weekly_handler, 0, 0 },
436 {
"fs:monthly", fs_monthly_handler, 0, 0 },
437 {
"fs:month_relative", fs_month_relative_handler, 0, 0 },
438 {
"fs:composite", fs_composite_handler, 0, 0 },
444 gnc_fs_handler( xmlNodePtr node, gpointer d )
446 return dom_tree_generic_parse( node, fs_dom_handlers, d );
451 gnc_freqSpec_end_handler(gpointer data_for_children,
452 GSList* data_from_children, GSList* sibling_data,
453 gpointer parent_data, gpointer global_data,
454 gpointer *result,
const gchar *tag)
457 gboolean successful = FALSE;
458 xmlNodePtr tree = (xmlNodePtr)data_for_children;
462 fspd.book = globaldata->book;
472 g_return_val_if_fail( tree, FALSE );
474 successful = dom_tree_generic_parse( tree, fs_dom_handlers, &fspd );
477 xmlElemDump( stdout, NULL, tree );
486 gnc_freqSpec_sixtp_parser_create(
void)
488 return sixtp_dom_parser_new( gnc_freqSpec_end_handler, NULL, NULL );
497 successful = dom_tree_generic_parse( node, fs_dom_handlers, fspd );
500 xmlElemDump(stdout, NULL, node);
505 dom_tree_freqSpec_to_recurrences(xmlNodePtr node,
QofBook *book)
509 common_parse(&fspd, node, book);
510 if (fspd.recurrence_list == NULL)
512 fspd.recurrence_list = g_list_append(fspd.recurrence_list, fspd.recurrence);
514 return fspd.recurrence_list;
api for GnuCash version 2 XML-based file format
Period / Date Frequency Specification.
Scheduled Transactions public handling routines.