diff --git a/src/engine/AccInfo.c b/src/engine/AccInfo.c index 52d3ae7fb7..30cb0f0a5c 100644 --- a/src/engine/AccInfo.c +++ b/src/engine/AccInfo.c @@ -57,8 +57,7 @@ xaccAccountTypeEnumAsString(int type) { GNC_RETURN_ENUM_AS_STRING(MONEYMRKT); GNC_RETURN_ENUM_AS_STRING(CREDITLINE); default: - fprintf(stderr, - "Big problem asked to translate unknown account type %d.\n", type); + PERR ("asked to translate unknown account type %d.\n", type); break; }; return(NULL); @@ -128,7 +127,7 @@ xaccAccountTypesCompatible (int parent_type, int child_type) compatible = (child_type == EQUITY); break; default: - PERR("xaccAccountTypesCompatible: bad account type: %d", parent_type); + PERR("bad account type: %d", parent_type); break; } diff --git a/src/engine/Account.c b/src/engine/Account.c index c47ae6b7ae..343e29c6b3 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -275,7 +275,7 @@ xaccGetAccountFlags (Account *acc) #define CHECK(acc) { \ if (0 == acc->open) { \ /* not today, some day in the future ... */ \ - /* printf ("Error: Account not open for editing\n"); */ \ + /* PERR ("Account not open for editing\n"); */ \ /* assert (0); */ \ /* return; */ \ } \ @@ -345,7 +345,7 @@ xaccAccountInsertSplit ( Account *acc, Split *split ) } /* Insertion point is now i */ - //fprintf(stderr, "Insertion position is: %d\n", i); + PINFO ("Insertion position is: %d\n", i); /* Move all the other splits down (this could be done faster with memmove)*/ for( j = acc->numSplits; j > i; j--) { @@ -600,8 +600,7 @@ xaccCheckDateOrder (Account * acc, Split *split ) } if (!s) { - printf ("Internal Error: xaccCheckDateOrder(): "); - printf (" split %p not present in account \n", split); + PERR ("split %p not present in account \n", split); return 0; } @@ -1056,13 +1055,11 @@ xaccAccountSetCurrency (Account *acc, const char *str) if (acc->currency && (0x0 != acc->currency[0])) { if (unsafe_ops) { - PWARN ("xaccAccountSetCurrency(): " - "it is dangerous to change the currency denomination of an account! \n" + PWARN ( "it is dangerous to change the currency denomination of an account! \n" "\tAccount=%s old currency=%s new currency=%s \n", acc->accountName, acc->currency, str); } else { - PERR ("xaccAccountSetCurrency(): " - "the currency denomination of an account cannot be changed!\n" + PERR ("the currency denomination of an account cannot be changed!\n" "\tAccount=%s \n", acc->accountName); return; } @@ -1080,14 +1077,12 @@ xaccAccountSetSecurity (Account *acc, const char *str) if (acc->security && (0x0 != acc->security[0])) { if (unsafe_ops) { - PWARN ("xaccAccountSetSecurity(): " - "it is dangerous to change the security denomination of an account! \n" + PWARN ("it is dangerous to change the security denomination of an account! \n" "\tAccount=%s old security=%s new security=%s \n", acc->accountName, acc->security, str); } else { - PERR ("xaccAccountSetSecurity(): " - "the security denomination of an account cannot be changed!\n" - "\tAccount=%s \n", acc->accountName); + PERR ("the security denomination of an account cannot be changed!\n" + "\tAccount=%s \n", acc->accountName); return; } } diff --git a/src/engine/AccountP.h b/src/engine/AccountP.h index bec9e74306..a4d4582b5a 100644 --- a/src/engine/AccountP.h +++ b/src/engine/AccountP.h @@ -1,7 +1,7 @@ /********************************************************************\ - * Account.h -- the Account data structure * + * AccountP.h -- the Account data structure * * Copyright (C) 1997 Robin D. Clark * - * Copyright (C) 1997, 1998, 1999 Linas Vepstas * + * Copyright (C) 1997-2000, Linas Vepstas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -44,8 +44,8 @@ #include "config.h" #include "AccInfo.h" -#include "Transaction.h" #include "GNCId.h" +#include "Transaction.h" /** STRUCTS *********************************************************/ diff --git a/src/engine/FileIO.c b/src/engine/FileIO.c index cc75eedc32..55f32a8820 100644 --- a/src/engine/FileIO.c +++ b/src/engine/FileIO.c @@ -2,7 +2,7 @@ * FileIO.c -- read from and writing to a datafile for gnucash * * (GnuCash/X-Accountant) * * Copyright (C) 1997 Robin D. Clark * - * Copyright (C) 1997, 1998, 1999, 2000 Linas Vepstas * + * Copyright (C) 1997-2000 Linas Vepstas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -399,7 +399,7 @@ readGroup (int fd, Account *aparent, int token) int i; AccountGroup *grp = xaccMallocAccountGroup(); - ENTER ("readGroup"); + ENTER (""); if (NULL == aparent) { maingrp = grp; @@ -414,15 +414,15 @@ readGroup (int fd, Account *aparent, int token) } XACC_FLIP_INT (numAcc); - DEBUG ("readGroup(): expecting %d accounts \n", numAcc); + DEBUG ("expecting %d accounts \n", numAcc); /* read in the accounts */ for( i=0; i fd ) { @@ -1475,7 +1473,7 @@ writeGroup (int fd, AccountGroup *grp ) int i,numAcc; int err = 0; - ENTER ("writeGroup"); + ENTER (""); if (NULL == grp) return 0; @@ -1527,7 +1525,7 @@ writeAccount( int fd, Account *acc ) int numChildren = 0; const char * tmp; - DEBUG ("writeAccount(): writing acct %s \n", xaccAccountGetName (acc)); + DEBUG ("writing acct %s \n", xaccAccountGetName (acc)); acc_id = acc->id; XACC_FLIP_INT (acc_id); @@ -1619,7 +1617,7 @@ writeAccount( int fd, Account *acc ) if( err != sizeof(int) ) return -1; - DEBUG ("writeAccount(): will write %d trans\n", numUnwrittenTrans); + DEBUG ("will write %d trans\n", numUnwrittenTrans); if (0 != xaccAccountStagedTransactionTraversal(acc, 2, _write_transaction_wrapper_, &fd)) { @@ -1659,7 +1657,7 @@ writeTransaction( int fd, Transaction *trans ) int i=0; Timespec ts; - ENTER ("writeTransaction"); + ENTER (""); err = writeString( fd, xaccTransGetNum (trans) ); if( -1 == err ) return err; @@ -1715,7 +1713,7 @@ writeSplit ( int fd, Split *split ) Account *xfer_acc = NULL; char recn; - ENTER ("writeSplit"); + ENTER (""); err = writeString( fd, xaccSplitGetMemo (split) ); if( -1 == err ) @@ -1738,7 +1736,7 @@ writeSplit ( int fd, Split *split ) if( -1 == err ) return err; damount = xaccSplitGetShareAmount (split); - DEBUG ("writeSplit: amount=%f \n", damount); + DEBUG ("amount=%f \n", damount); XACC_FLIP_DOUBLE (damount); err = write( fd, &damount, sizeof(double) ); if( err != sizeof(double) ) @@ -1754,7 +1752,7 @@ writeSplit ( int fd, Split *split ) xfer_acc = split->acc; acc_id = -1; if (xfer_acc) acc_id = xfer_acc -> id; - DEBUG ("writeSplit: credit %d \n", acc_id); + DEBUG ("credit %d \n", acc_id); XACC_FLIP_INT (acc_id); err = write( fd, &acc_id, sizeof(int) ); if( err != sizeof(int) ) @@ -1776,7 +1774,7 @@ writeInvAcct ( int fd, InvAcct * invacct ) { int err=0; - ENTER ("writeInvAcct"); + ENTER (""); if (!invacct) return 0; err = writeString( fd, xaccInvAcctGetPriceSrc (invacct) ); @@ -1800,7 +1798,7 @@ writeAccInfo ( int fd, AccInfo *accinfo ) int err=0; InvAcct *invacct=NULL; - ENTER ("writeAccInfo"); + ENTER (""); if (!accinfo) return err; invacct = xaccCastToInvAcct (accinfo); diff --git a/src/engine/GNCId.c b/src/engine/GNCId.c index 11346b6b90..3c7b3e692a 100644 --- a/src/engine/GNCId.c +++ b/src/engine/GNCId.c @@ -180,7 +180,7 @@ xaccGUIDNew(GUID *guid) if (xaccGUIDType(guid) == GNC_ID_NONE) break; - PWARN("xaccGUIDNew: duplicate id\n"); + PWARN("duplicate id\n"); } while(1); } diff --git a/src/engine/LedgerUtils.c b/src/engine/LedgerUtils.c index cebf7fd7c0..e13e3a614e 100644 --- a/src/engine/LedgerUtils.c +++ b/src/engine/LedgerUtils.c @@ -97,7 +97,7 @@ xaccGroupToList (Account *acc) if (!acc) return NULL; - ENTER ("xaccGroupToList(): acc=%p \n", acc); + ENTER ("acc=%p \n", acc); nacc = xaccGetNumAccounts (acc->children); nacc ++; /* add one for this account */ @@ -132,7 +132,7 @@ xaccGroupToList (Account *acc) } } list[n] = NULL; - LEAVE ("xaccGroupToList(): n=%d nacc=%d \n", n, nacc); + LEAVE ("n=%d nacc=%d \n", n, nacc); assert (n==nacc); return list; diff --git a/src/engine/QIFIO.c b/src/engine/QIFIO.c index ac293ef762..1f6beb9974 100644 --- a/src/engine/QIFIO.c +++ b/src/engine/QIFIO.c @@ -316,7 +316,7 @@ char * xaccReadQIFAccount (int fd, Account * acc) xaccAccountSetType (acc, LIABILITY); } else { - printf ("QIF Parse: Unsupported account type %s \n", &qifline[1]); + PERR("Unsupported account type %s \n", &qifline[1]); xaccAccountSetType (acc, -1); /* hack alert -- */ } break; @@ -914,7 +914,7 @@ xaccReadQIFTransaction (int fd, Account *acc, int guess_name, pute = xaccSplitGetValue (source_split); if (isneg) pute = -pute; - printf ("QIF Warning: Adjustment of %.2f to amount %.2f not handled \n", adjust, pute); + PWARN("Adjustment of %.2f to amount %.2f not handled \n", adjust, pute); } break; case 'P': @@ -998,7 +998,7 @@ xaccReadQIFTransaction (int fd, Account *acc, int guess_name, wanted = (int) (100.0 * parse + 0.5); got = (int) (100.0 * (pute+adjust) + 0.5); if (wanted != got) { - printf ("QIF Parse Error: wanted %f got %f \n", parse, pute); + PERR("Parse $: wanted %f got %f \n", parse, pute); } } } diff --git a/src/engine/Query.c b/src/engine/Query.c index 61c37737a9..3ecdbc5821 100644 --- a/src/engine/Query.c +++ b/src/engine/Query.c @@ -208,8 +208,8 @@ xaccQueryInvert(Query * q) { num_or_terms = g_list_length(q->terms); - /* printf("inverting query: "); - print_query(q); */ + DEBUG("inverting query: "); + DEBUGCMD (print_query(q)); switch(num_or_terms) { case 0: @@ -284,9 +284,8 @@ xaccQueryMerge(Query * q1, Query * q2, QueryOp op) { Query * t1, * t2; GList * i, * j; - /* printf("merging queries: op=%d\n", op); - print_query(q1); - print_query(q2); */ + DEBUG("merging queries: op=%d\n", op); + DEBUGCMD(print_query(q1); print_query(q2);) switch(op) { case QUERY_OR: @@ -758,13 +757,11 @@ xaccQueryGetSplits(Query * q) { gettimeofday(&end, NULL); -#if 0 - printf("xaccQueryGetSplits: elapsed time = %e ms\n", + PINFO("elapsed time = %e ms\n", (end.tv_sec - start.tv_sec)*1000.0 + (end.tv_usec - start.tv_usec)/1000.0); - printf("xaccQueryGetSplits: %d splits checked, %d splits matched.\n", + PINFO("%d splits checked, %d splits matched.\n", total_splits_checked, split_count); -#endif q->changed = 0; if(q->split_list) { diff --git a/src/engine/Queue.c b/src/engine/Queue.c index 1ee9a86c62..35df2f8192 100644 --- a/src/engine/Queue.c +++ b/src/engine/Queue.c @@ -173,7 +173,7 @@ xaccQueuePushHead (Queue *q, Split *s) /* I'm too lazy to code up a more complex feature that no one will use ... */ /* If you are reading this, you are invited to do so yourself :-) */ if ( !DEQ (q->head_amount, 0.0)) { - PERR ("xaccQueuePushHead(): The current implementation does not\n" + PERR ("The current implementation does not\n" "\tsupport pushing onto a queue that has been popped \n"); return; } @@ -342,14 +342,14 @@ xaccQueuePopTailValue (Queue *q, double val) double xaccQueuePopHeadValue (Queue *q, double val) { - PERR("xaccQueuePopHeadValue(): not implemented\n"); + PERR("not implemented\n"); return 0.0; } double xaccQueuePopHeadShares (Queue *q, double val) { - PERR("xaccQueuePopHeadsahres(): not implemented\n"); + PERR("not implemented\n"); return 0.0; } diff --git a/src/engine/Scrub.c b/src/engine/Scrub.c index c751b1499a..0e39e25748 100644 --- a/src/engine/Scrub.c +++ b/src/engine/Scrub.c @@ -87,8 +87,7 @@ xaccAccountScrubOrphans (Account *acc) Transaction *trans; Account * parent; - PINFO ("xaccAccountScrubOrphans(): " - "Looking for orphans in account %s \n", xaccAccountGetName(acc)); + PINFO ("Looking for orphans in account %s \n", xaccAccountGetName(acc)); slist = xaccAccountGetSplitList (acc); split = slist[0]; @@ -102,7 +101,7 @@ xaccAccountScrubOrphans (Account *acc) parent = xaccSplitGetAccount (s); if (!parent) { Account *orph; - DEBUG ("xaccAccountScrubOrphans(): Found an orphan \n"); + DEBUG ("Found an orphan \n"); /* OK, we found an orphan. Put it in an orphan account. */ orph = GetOrMakeAccount (acc, trans, ORPHAN_STR); xaccAccountBeginEdit (orph, 1); @@ -148,8 +147,7 @@ xaccAccountScrubImbalance (Account *acc) Split *split, **slist; Transaction *trans; - PINFO ("xaccAccountScrubImbalance(): " - "Looking for imbalance in account %s \n", xaccAccountGetName(acc)); + PINFO ("Looking for imbalance in account %s \n", xaccAccountGetName(acc)); slist = xaccAccountGetSplitList (acc); split = slist[0]; @@ -161,8 +159,7 @@ xaccAccountScrubImbalance (Account *acc) if (!(DEQ (imbalance, 0.0))) { Split *splat; Account *orph; - DEBUG ("xaccAccountScrubImbalance(): " - "Found imbalance of %g\n", imbalance); + DEBUG ("Found imbalance of %g\n", imbalance); /* OK, we found an imbalanced trans. Put it in the imbal account. */ orph = GetOrMakeAccount (acc, trans, IMBALANCE_STR); diff --git a/src/engine/util.c b/src/engine/util.c index a20115725e..28c9894bfc 100644 --- a/src/engine/util.c +++ b/src/engine/util.c @@ -2,7 +2,7 @@ * util.c -- utility functions that are used everywhere else for * * xacc (X-Accountant) * * Copyright (C) 1997 Robin D. Clark * - * Copyright (C) 1997, 1998, 1999, 2000 Linas Vepstas * + * Copyright (C) 1997-2000 Linas Vepstas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -60,8 +60,39 @@ int loglevel[MODULE_MAX] = 2, /* GUI */ 2, /* SCRUB */ 2, /* GTK_REG */ + 2, /* GUILE */ + 4, /* BACKEND */ }; +/********************************************************************\ +\********************************************************************/ +/* prettify() cleans up subroutine names. + * AIX/xlC has the habit of printing signatures not names; clean this up. + * On other operating systems, truncate name to 30 chars. + * Note this routine is not thread safe. Note we wouldn't need this + * routine if AIX did something more reasonable. Hope thread safety + * doesn't poke us in eye. + */ +char * +prettify (const char *name) +{ + static char bf[35]; + char *p; + strncpy (bf, name, 29); bf[28] = 0; + p = strchr (bf, '('); + if (p) + { + *(p+1) = ')'; + *(p+2) = 0x0; + } + else + { + strcpy (&bf[26], "...()"); + } + return bf; +} + + /********************************************************************\ * DEBUGGING MEMORY ALLOCATION STUFF * \********************************************************************/ diff --git a/src/engine/util.h b/src/engine/util.h index 5532edd83a..8b985e8cda 100644 --- a/src/engine/util.h +++ b/src/engine/util.h @@ -2,7 +2,7 @@ * util.h -- utility functions that are used everywhere for * * gnucash (ex-xacc (X-Accountant)) * * Copyright (C) 1997 Robin D. Clark * - * Copyright (C) 1998, 1999, 2000 Linas Vepstas * + * Copyright (C) 1998-2000 Linas Vepstas * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -51,7 +51,8 @@ #define MOD_SCRUB 7 #define MOD_GTK_REG 8 #define MOD_GUILE 9 -#define MODULE_MAX 10 +#define MOD_BACKEND 10 +#define MODULE_MAX 11 extern int loglevel[MODULE_MAX]; @@ -65,15 +66,18 @@ extern int loglevel[MODULE_MAX]; #undef DEBUG #endif +/* some preprocessors use ugly __FUNCTION__ substitution ... */ +char * prettify (const char *); + /* utility macros */ -#define FATAL(x...) LG(1, "Fatal Error: "); LG(1, ##x); -#define PERR(x...) LG(LERR, "Error: "); LG(LERR, ##x); -#define PWARN(x...) LG(LWARN, "Waring: "); LG(LWARN, ##x); -#define PINFO(x...) LG(LINFO, "Info: "); LG(LINFO, ##x); -#define DEBUG(x...) LG(LDEBUG, "Debug: "); LG(LDEBUG, ##x); -#define ENTER(x...) LG(LDEBUG, "Enter: "); LG(LDEBUG, ##x); -#define LEAVE(x...) LG(LDEBUG, "Leave: "); LG(LDEBUG, ##x); -#define DETAIL(x...) LG(LDETAIL, "Detail: "); LG(LDETAIL, ##x); +#define FATAL(x...) LG(1, "Fatal Error: %s: ", prettify(__FUNCTION__)); LG(1, ##x); +#define PERR(x...) LG(LERR, "Error: %s: ", prettify(__FUNCTION__)); LG(LERR, ##x); +#define PWARN(x...) LG(LWARN, "Waring: %s: ", prettify(__FUNCTION__)); LG(LWARN, ##x); +#define PINFO(x...) LG(LINFO, "Info: %s: ", prettify(__FUNCTION__)); LG(LINFO, ##x); +#define DEBUG(x...) LG(LDEBUG, "Debug: %s: ", prettify(__FUNCTION__)); LG(LDEBUG, ##x); +#define ENTER(x...) LG(LDEBUG, "Enter: %s: ", prettify(__FUNCTION__)); LG(LDEBUG, ##x); +#define LEAVE(x...) LG(LDEBUG, "Leave: %s: ", prettify(__FUNCTION__)); LG(LDEBUG, ##x); +#define DETAIL(x...) LG(LDETAIL, "Detail: %s: ", prettify(__FUNCTION__)); LG(LDETAIL, ##x); #define DEBUGCMD(x) { if (LINFO) { x; }}