diff --git a/src/engine/Account.c b/src/engine/Account.c index 7c17bf5971..7c111672fd 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -1186,8 +1186,8 @@ IthAccount (Account **list, int i) /********************************************************************\ \********************************************************************/ -gncBoolean xaccAccountsHaveCommonCurrency(Account *account_1, - Account *account_2) +gncBoolean +xaccAccountsHaveCommonCurrency(Account *account_1, Account *account_2) { if ((account_1 == NULL) || (account_2 == NULL)) return GNC_F; @@ -1195,5 +1195,28 @@ gncBoolean xaccAccountsHaveCommonCurrency(Account *account_1, return xaccIsCommonCurrency(account_1->currency, account_1->security, account_2->currency, account_2->security); } - + +/********************************************************************\ +\********************************************************************/ + +gncBoolean +xaccAccountHasAncestor (Account *account, Account * ancestor) +{ + Account *parent; + + if ((account == NULL) || (ancestor == NULL)) + return GNC_F; + + parent = xaccAccountGetParentAccount(account); + while (parent != NULL) + { + if (parent == ancestor) + return GNC_T; + + parent = xaccAccountGetParentAccount(parent); + } + + return GNC_F; +} + /*************************** END OF FILE **************************** */ diff --git a/src/engine/Account.h b/src/engine/Account.h index 04efe350be..2400ac27dc 100644 --- a/src/engine/Account.h +++ b/src/engine/Account.h @@ -164,4 +164,8 @@ Account * IthAccount (Account **list, int i); gncBoolean xaccAccountsHaveCommonCurrency(Account *account_1, Account *account_2); +/* Returns true if the account has 'ancestor' as an ancestor. + * Returns false if either is NULL. */ +gncBoolean xaccAccountHasAncestor (Account *, Account * ancestor); + #endif /* __XACC_ACCOUNT_H__ */ diff --git a/src/engine/Query.c b/src/engine/Query.c index 915dc71b94..4ab7bd764a 100644 --- a/src/engine/Query.c +++ b/src/engine/Query.c @@ -29,7 +29,9 @@ #include #include +#include #include +#include #include "config.h" @@ -225,6 +227,42 @@ xaccQuerySetDateRangeL (Query *q, long long early, long long late) q->latest.tv_sec = late; } +void +xaccQuerySetEarliest (Query *q, time_t earliest) +{ + if (!q) return; + q->changed = 1; + q->earliest.tv_sec = earliest; +} + +void +xaccQuerySetLatest (Query *q, time_t latest) +{ + if (!q) return; + q->changed = 1; + q->latest.tv_sec = latest; +} + +/* ================================================== */ + +void +xaccQueryShowEarliestDateFound (Query *q) +{ + if (!q) return; + q->changed = 1; + q->earliest.tv_sec = LONG_LONG_MIN; + q->earliest.tv_nsec = 0; +} + +void +xaccQueryShowLatestDateFound (Query *q) +{ + if (!q) return; + q->changed = 1; + q->latest.tv_sec = LONG_LONG_MAX; + q->latest.tv_nsec = 0; +} + /* ================================================== */ /* ================================================== */ @@ -283,21 +321,65 @@ xaccQuerySetDateRangeL (Query *q, long long early, long long late) } \ } +static gncBoolean +gnc_strisnum(char *s) +{ + if (s == NULL) return GNC_F; + if (*s == 0) return GNC_F; + + while (*s && isspace(*s)) + s++; + + if (*s == 0) return GNC_F; + if (!isdigit(*s)) return GNC_F; + + while (*s && isdigit(*s)) + s++; + + if (*s == 0) return GNC_T; + + while (*s && isspace(*s)) + s++; + + if (*s == 0) return GNC_T; + + return GNC_F; +} + #define CNUM { \ /* sort on transaction number */ \ + unsigned long n1; \ + unsigned long n2; \ da = ta->num; \ db = tb->num; \ - if (da && db) { \ - retval = strcmp (da, db); \ - /* if strings differ, return */ \ - if (retval) return retval; \ - } else \ + if (gnc_strisnum(da)) { \ + if (!gnc_strisnum(db)) { \ + return -1; \ + } \ + sscanf(da, "%lu", &n1); \ + sscanf(db, "%lu", &n2); \ + if (n1 < n2) { \ + return -1; \ + } \ + if (n1 == n2) { \ + return 0; \ + } \ + return +1; \ + } \ + if (gnc_strisnum(db)) { \ + return +1; \ + } \ if (!da && db) { \ return -1; \ - } else \ + } \ if (da && !db) { \ return +1; \ } \ + if (!da && !db) { \ + return 0; \ + } \ + retval = strcmp (da, db); \ + return retval; \ } #define CMEMO { \ diff --git a/src/engine/Query.h b/src/engine/Query.h index fce3537b61..3fa99d9741 100644 --- a/src/engine/Query.h +++ b/src/engine/Query.h @@ -31,6 +31,7 @@ #include +#include "gnc-common.h" #include "Account.h" #include "Transaction.h" @@ -72,9 +73,17 @@ void xaccQuerySetDateRange (Query *, time_t earliest, time_t latest); void xaccQuerySetDateRangeL (Query *, long long earliest, long long latest); #endif +void xaccQuerySetEarliest (Query *, time_t earliest); +void xaccQuerySetLatest (Query *, time_t latest); + +/* The xaccQueryShowEarliestDateFound function and its partner tell + * the Query to use the earliest (resp. latest) splits found. */ +void xaccQueryShowEarliestDateFound (Query *); +void xaccQueryShowLatestDateFound (Query *); + /* The xaccQuerySetSortOrder() method sets the sort order that * should be used on the splits. The three arguments should - * be choosen from the enums above. The first argument has the + * be chosen from the enums above. The first argument has the * sort priority, the next the next, etc. */ void xaccQuerySetSortOrder (Query *, int, int, int); diff --git a/src/engine/date.c b/src/engine/date.c index ed7bcf5d9d..98145e0148 100644 --- a/src/engine/date.c +++ b/src/engine/date.c @@ -28,6 +28,8 @@ * * \********************************************************************/ +#define _GNU_SOURCE + #include #include #include @@ -204,6 +206,20 @@ scanDate(const char *buff, int *day, int *month, int *year) /* get numeric values */ switch(dateFormat) { +#if 0 /* strptime broken in glibc <= 2.1.2 */ + case DATE_FORMAT_LOCALE: + if (buff[0] != 0) + { + struct tm thetime; + + strptime(buff, "%x", &thetime); + + iday = thetime.tm_mday; + imonth = thetime.tm_mon + 1; + iyear = thetime.tm_year + 1900; + } + break; +#endif case DATE_FORMAT_UK: case DATE_FORMAT_CE: if (first_field) iday = atoi (first_field); diff --git a/src/engine/util.c b/src/engine/util.c index 9fd2db470b..e8b6246456 100644 --- a/src/engine/util.c +++ b/src/engine/util.c @@ -390,7 +390,7 @@ xaccSPrintAmount (char * bufp, double val, short shrs) } /* Now see if we print parentheses */ - if (print_sign && (sign_posn == 0)) + if (print_sign && (sign_posn == 0) && (val < 0.0)) bufp = stpcpy(bufp, "("); /* Now print the value */ @@ -398,7 +398,7 @@ xaccSPrintAmount (char * bufp, double val, short shrs) shrs & PRTSEP, ~(shrs & PRTSHR)); /* Now see if we print parentheses */ - if (print_sign && (sign_posn == 0)) + if (print_sign && (sign_posn == 0) && (val < 0.0)) bufp = stpcpy(bufp, ")"); /* Now see if we print currency */ diff --git a/src/engine/util.h b/src/engine/util.h index 8f59ab4d06..bca37fceee 100644 --- a/src/engine/util.h +++ b/src/engine/util.h @@ -37,19 +37,9 @@ /* The debuging macros enable the setting of trace messages */ #include -#ifdef HAVE_NANA_H -#include - -/* override standard system assert with nana I assertion */ -#ifdef assert -#undef assert -#endif -#define assert I -#else /* HAVE_NANA_H */ -/* if there is no nana, use he system assert and mush up LG */ #include + #define LG(condition,args...) if (condition) fprintf(stderr, ##args) -#endif /* HAVE_NANA_H */ #define MOD_ENGINE 1 #define MOD_IO 2 @@ -87,6 +77,7 @@ extern int loglevel[MODULE_MAX]; #define DEBUGCMD(x) { if (LINFO) { x; }} #include + #define ERROR() fprintf(stderr,"%s: Line %d, error = %s\n", \ __FILE__, __LINE__, strerror(errno));