Bug fixes.

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2356 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Dave Peticolas 2000-05-19 10:27:33 +00:00
parent 297b5c0e53
commit 00b82a2b87
2 changed files with 62 additions and 18 deletions

View File

@ -1494,7 +1494,7 @@ xaccAccountMatchPredicate(Split * s, PredicateData * pd) {
assert(s && pd); assert(s && pd);
assert(pd->type == PD_ACCOUNT); assert(pd->type == PD_ACCOUNT);
parent = xaccSplitGetParent(s); parent = xaccSplitGetParent(s);
assert(parent); assert(parent);
switch(pd->acct.how) { switch(pd->acct.how) {
@ -1668,14 +1668,15 @@ xaccAmountMatchPredicate(Split * s, PredicateData * pd) {
switch(pd->amount.amt_sgn) { switch(pd->amount.amt_sgn) {
case AMT_SGN_MATCH_CREDIT: case AMT_SGN_MATCH_CREDIT:
if(splitamt < 0.0) return 0; if(splitamt > 0.0) return 0;
break; break;
case AMT_SGN_MATCH_DEBIT: case AMT_SGN_MATCH_DEBIT:
if(splitamt > 0.0) return 0; if(splitamt < 0.0) return 0;
break; break;
default: default:
break; break;
} }
return value_match_predicate(splitamt, pd); return value_match_predicate(splitamt, pd);
} }

View File

@ -675,15 +675,17 @@ xaccPrintAmountArgs (double val, gncBoolean print_currency_symbol,
double xaccParseAmount (const char * instr, gncBoolean monetary) double xaccParseAmount (const char * instr, gncBoolean monetary)
{ {
struct lconv *lc = gnc_localeconv(); struct lconv *lc = gnc_localeconv();
gncBoolean isneg = GNC_F;
char *mstr, *str, *tok; char *mstr, *str, *tok;
double amount = 0.0; double amount = 0.0;
char negative_sign; char negative_sign;
char thousands_sep; char thousands_sep;
char decimal_point; char decimal_point;
int len; int len;
int isneg = 0;
if (!instr) return 0.0; if (!instr) return 0.0;
if (*instr == '\0') return 0.0;
mstr = strdup (instr); mstr = strdup (instr);
str = mstr; str = mstr;
@ -699,23 +701,64 @@ double xaccParseAmount (const char * instr, gncBoolean monetary)
decimal_point = lc->decimal_point[0]; decimal_point = lc->decimal_point[0];
} }
/* strip off garbage at end of the line */ /* strip off garbage at the beginning of the line */
tok = strchr (str, '\r'); while (*str != '\0')
if (tok) *tok = 0x0; {
tok = strchr (str, '\n'); switch (*str)
if (tok) *tok = 0x0; {
case '\r':
case '\n':
case ' ':
case '\t':
str++;
continue;
break;
}
/* search for a negative sign */ break;
tok = strchr (str, negative_sign);
if (tok) {
isneg = 1;
str = tok + sizeof(char);
} }
/* look for a negative sign */
if (*str == negative_sign) {
isneg = GNC_T;
str++;
}
if (*str == '\0') return 0.0;
/* go to end of string */
for (tok = str; *tok != '\0'; tok++)
;
/* strip off garbage at end of the line */
while (--tok != str)
{
switch (*tok)
{
case '\r':
case '\n':
case ' ':
case '\t':
continue;
break;
}
break;
}
/* look for a negative sign at the end, some locales allow it,
* we'll just allow it everywhere. */
if (*tok == negative_sign) {
isneg = GNC_T;
*tok = '\0';
}
if (*str == '\0') return 0.0;
/* remove thousands separator */ /* remove thousands separator */
tok = strchr (str, thousands_sep); tok = strchr (str, thousands_sep);
while (tok) { while (tok) {
*tok = 0x0; *tok = '\0';
amount *= 1000.0; amount *= 1000.0;
amount += ((double) (1000 * atoi (str))); amount += ((double) (1000 * atoi (str)));
str = tok + sizeof(char); str = tok + sizeof(char);
@ -725,7 +768,7 @@ double xaccParseAmount (const char * instr, gncBoolean monetary)
/* search for a decimal point */ /* search for a decimal point */
tok = strchr (str, decimal_point); tok = strchr (str, decimal_point);
if (tok) { if (tok) {
*tok = 0x0; *tok = '\0';
amount += ((double) (atoi (str))); amount += ((double) (atoi (str)));
str = tok + sizeof(char); str = tok + sizeof(char);
@ -735,7 +778,7 @@ double xaccParseAmount (const char * instr, gncBoolean monetary)
/* strip off garbage at end of the line */ /* strip off garbage at end of the line */
tok = strchr (str, ' '); tok = strchr (str, ' ');
if (tok) *tok = 0x0; if (tok) *tok = '\0';
/* adjust for number of decimal places */ /* adjust for number of decimal places */
len = strlen(str); len = strlen(str);