new, improved debug printing macros

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2308 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 2000-05-14 20:54:20 +00:00
parent 42fa37831d
commit e92c343927
12 changed files with 108 additions and 87 deletions

View File

@ -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;
}

View File

@ -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;
}
}

View File

@ -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 <linas@linas.org> *
* *
* 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 *********************************************************/

View File

@ -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 <linas@linas.org> *
* *
* 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<numAcc; i++ )
{
Account * acc = readAccount( fd, grp, token );
if( NULL == acc ) {
printf("Error: readGroup(): Short group read: \n");
printf("expected %d, got %d accounts\n",numAcc,i);
PERR("Short group read: \n");
"\texpected %d, got %d accounts\n",numAcc,i);
break;
}
}
@ -454,7 +454,7 @@ readAccount( int fd, AccountGroup *grp, int token )
Account *acc;
char * tmp;
ENTER ("readAccount");
ENTER ("");
/* version 1 does not store the account number */
if (1 < token) {
@ -500,7 +500,7 @@ readAccount( int fd, AccountGroup *grp, int token )
tmp = readString( fd, token );
if( NULL == tmp) return NULL;
DEBUG ("readAccount(): reading acct %s \n", tmp);
DEBUG ("reading acct %s \n", tmp);
xaccAccountSetName (acc, tmp);
free (tmp);
@ -548,7 +548,7 @@ readAccount( int fd, AccountGroup *grp, int token )
if( err != sizeof(int) ) { return NULL; }
XACC_FLIP_INT (numTrans);
DEBUG ("Info: readAccount(): expecting %d transactions \n", numTrans);
DEBUG ("expecting %d transactions \n", numTrans);
/* read the transactions */
for( i=0; i<numTrans; i++ )
{
@ -556,8 +556,8 @@ readAccount( int fd, AccountGroup *grp, int token )
trans = readTransaction( fd, acc, token );
if( trans == NULL )
{
PERR ("readAccount(): Short Transaction Read: \n");
printf (" expected %d got %d transactions \n",numTrans,i);
PERR ("Short Transaction Read: \n"
"\texpected %d got %d transactions \n",numTrans,i);
break;
}
#ifdef DELINT_BLANK_SPLITS_HACK
@ -653,8 +653,7 @@ springAccount (int acc_id)
/* first, see if we're confused about the account */
acc = xaccGetAccountFromID (maingrp, acc_id);
if (acc) {
printf ("Internal Error: springAccount(): \n");
printf ("account already parented \n");
PERR ("account already parented \n");
return NULL;
}
@ -666,8 +665,7 @@ springAccount (int acc_id)
}
/* if we got to here, its an error */
printf ("Internal Error: springAccount(): \n");
printf ("Couldn't find account \n");
PERR ("Couldn't find account \n");
return NULL;
}
@ -738,7 +736,7 @@ readTransaction( int fd, Account *acc, int token )
double num_shares = 0.0;
double share_price = 0.0;
ENTER ("readTransaction");
ENTER ("");
/* create a transaction structure */
trans = xaccMallocTransaction();
@ -944,7 +942,7 @@ readTransaction( int fd, Account *acc, int token )
xaccSplitSetSharePriceAndAmount (s, share_price, num_shares);
}
DEBUG ("readTransaction(): num_shares %f \n", num_shares);
DEBUG ("num_shares %f \n", num_shares);
/* Read the account numbers for double-entry */
/* These are first used in Version 2 of the file format */
@ -960,7 +958,7 @@ readTransaction( int fd, Account *acc, int token )
return NULL;
}
XACC_FLIP_INT (acc_id);
DEBUG ("readTransaction(): credit %d\n", acc_id);
DEBUG ("credit %d\n", acc_id);
peer_acc = locateAccount (acc_id);
/* insert the split part of the transaction into
@ -978,7 +976,7 @@ readTransaction( int fd, Account *acc, int token )
return NULL;
}
XACC_FLIP_INT (acc_id);
DEBUG ("readTransaction(): debit %d\n", acc_id);
DEBUG ("debit %d\n", acc_id);
peer_acc = locateAccount (acc_id);
if (peer_acc) {
Split *split;
@ -1067,7 +1065,7 @@ readSplit ( int fd, int token )
/* create a split structure */
split = xaccMallocSplit();
ENTER ("readSplit");
ENTER ("");
tmp = readString( fd, token );
if( NULL == tmp )
@ -1161,7 +1159,7 @@ readSplit ( int fd, int token )
XACC_FLIP_DOUBLE (share_price);
xaccSplitSetSharePriceAndAmount (split, share_price, num_shares);
DEBUG ("readSplit(): num_shares %f \n", num_shares);
DEBUG ("num_shares %f \n", num_shares);
/* Read the account number */
@ -1173,7 +1171,7 @@ readSplit ( int fd, int token )
return NULL;
}
XACC_FLIP_INT (acc_id);
DEBUG ("readSplit(): account id %d\n", acc_id);
DEBUG ("account id %d\n", acc_id);
peer_acc = locateAccount (acc_id);
xaccAccountInsertSplit (peer_acc, split);
@ -1204,7 +1202,7 @@ readString( int fd, int token )
err = read( fd, str, size );
if( err != size )
{
printf( "Error: readString: size = %d err = %d str = %s\n", size, err, str );
PERR("size = %d err = %d str = %s\n", size, err, str );
free(str);
return NULL;
}
@ -1408,7 +1406,7 @@ xaccWriteAccountGroup (int fd, AccountGroup *grp )
int token = VERSION; /* The file format version */
int err = 0;
ENTER ("xaccWriteAccountGroup");
ENTER ("");
if( 0 > 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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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);
}
}
}

View File

@ -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) {

View File

@ -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;
}

View File

@ -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);

View File

@ -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 <linas@linas.org> *
* *
* 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 *
\********************************************************************/

View File

@ -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 <linas@linas.org> *
* *
* 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; }}