begine modernization of debuggin infrastructure

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1425 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-12-06 07:43:14 +00:00
parent 13479e1ec9
commit 18d991d3d7
4 changed files with 47 additions and 36 deletions

View File

@ -117,6 +117,9 @@
* new/improved account & transaction structures * new/improved account & transaction structures
*/ */
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_IO;
/** GLOBALS *********************************************************/ /** GLOBALS *********************************************************/
/* the default currency is used when importin old-style /* the default currency is used when importin old-style
@ -365,7 +368,7 @@ readGroup (int fd, Account *aparent, int token)
} }
XACC_FLIP_INT (numAcc); XACC_FLIP_INT (numAcc);
INFO_2 ("readGroup(): expecting %d accounts \n", numAcc); DEBUG ("readGroup(): expecting %d accounts \n", numAcc);
/* read in the accounts */ /* read in the accounts */
for( i=0; i<numAcc; i++ ) for( i=0; i<numAcc; i++ )
@ -451,7 +454,7 @@ readAccount( int fd, AccountGroup *grp, int token )
tmp = readString( fd, token ); tmp = readString( fd, token );
if( NULL == tmp) { free (tmp); return NULL; } if( NULL == tmp) { free (tmp); return NULL; }
INFO_2 ("readAccount(): reading acct %s \n", tmp); DEBUG ("readAccount(): reading acct %s \n", tmp);
xaccAccountSetName (acc, tmp); xaccAccountSetName (acc, tmp);
free (tmp); free (tmp);
@ -494,7 +497,7 @@ readAccount( int fd, AccountGroup *grp, int token )
if( err != sizeof(int) ) { return NULL; } if( err != sizeof(int) ) { return NULL; }
XACC_FLIP_INT (numTrans); XACC_FLIP_INT (numTrans);
INFO_2 ("Info: readAccount(): expecting %d transactions \n", numTrans); DEBUG ("Info: readAccount(): expecting %d transactions \n", numTrans);
/* read the transactions */ /* read the transactions */
for( i=0; i<numTrans; i++ ) for( i=0; i<numTrans; i++ )
{ {
@ -846,7 +849,7 @@ readTransaction( int fd, Account *acc, int token )
xaccSplitSetSharePriceAndAmount (s, share_price, num_shares); xaccSplitSetSharePriceAndAmount (s, share_price, num_shares);
} }
INFO_2 ("readTransaction(): num_shares %f \n", num_shares); DEBUG ("readTransaction(): num_shares %f \n", num_shares);
/* Read the account numbers for double-entry */ /* Read the account numbers for double-entry */
/* These are first used in Version 2 of the file format */ /* These are first used in Version 2 of the file format */
@ -862,7 +865,7 @@ readTransaction( int fd, Account *acc, int token )
return NULL; return NULL;
} }
XACC_FLIP_INT (acc_id); XACC_FLIP_INT (acc_id);
INFO_2 ("readTransaction(): credit %d\n", acc_id); DEBUG ("readTransaction(): credit %d\n", acc_id);
peer_acc = locateAccount (acc_id); peer_acc = locateAccount (acc_id);
/* insert the split part of the transaction into /* insert the split part of the transaction into
@ -880,7 +883,7 @@ readTransaction( int fd, Account *acc, int token )
return NULL; return NULL;
} }
XACC_FLIP_INT (acc_id); XACC_FLIP_INT (acc_id);
INFO_2 ("readTransaction(): debit %d\n", acc_id); DEBUG ("readTransaction(): debit %d\n", acc_id);
peer_acc = locateAccount (acc_id); peer_acc = locateAccount (acc_id);
if (peer_acc) { if (peer_acc) {
Split *split; Split *split;
@ -1061,7 +1064,7 @@ readSplit ( int fd, int token )
XACC_FLIP_DOUBLE (share_price); XACC_FLIP_DOUBLE (share_price);
xaccSplitSetSharePriceAndAmount (split, share_price, num_shares); xaccSplitSetSharePriceAndAmount (split, share_price, num_shares);
INFO_2 ("readSplit(): num_shares %f \n", num_shares); DEBUG ("readSplit(): num_shares %f \n", num_shares);
/* Read the account number */ /* Read the account number */
@ -1073,7 +1076,7 @@ readSplit ( int fd, int token )
return NULL; return NULL;
} }
XACC_FLIP_INT (acc_id); XACC_FLIP_INT (acc_id);
INFO_2 ("readSplit(): account id %d\n", acc_id); DEBUG ("readSplit(): account id %d\n", acc_id);
peer_acc = locateAccount (acc_id); peer_acc = locateAccount (acc_id);
xaccAccountInsertSplit (peer_acc, split); xaccAccountInsertSplit (peer_acc, split);
@ -1374,7 +1377,7 @@ writeAccount( int fd, Account *acc )
int numChildren = 0; int numChildren = 0;
char * tmp; char * tmp;
INFO_2 ("writeAccount(): writing acct %s \n", xaccAccountGetName (acc)); DEBUG ("writeAccount(): writing acct %s \n", xaccAccountGetName (acc));
acc_id = acc->id; acc_id = acc->id;
XACC_FLIP_INT (acc_id); XACC_FLIP_INT (acc_id);
@ -1464,7 +1467,7 @@ writeAccount( int fd, Account *acc )
if( err != sizeof(int) ) if( err != sizeof(int) )
return -1; return -1;
INFO_2 ("writeAccount(): will write %d trans\n", numUnwrittenTrans); DEBUG ("writeAccount(): will write %d trans\n", numUnwrittenTrans);
i=0; i=0;
s = acc->splits[i]; s = acc->splits[i];
while (s) { while (s) {
@ -1595,7 +1598,7 @@ writeSplit ( int fd, Split *split )
if( -1 == err ) return err; if( -1 == err ) return err;
damount = xaccSplitGetShareAmount (split); damount = xaccSplitGetShareAmount (split);
INFO_2 ("writeSplit: amount=%f \n", damount); DEBUG ("writeSplit: amount=%f \n", damount);
XACC_FLIP_DOUBLE (damount); XACC_FLIP_DOUBLE (damount);
err = write( fd, &damount, sizeof(double) ); err = write( fd, &damount, sizeof(double) );
if( err != sizeof(double) ) if( err != sizeof(double) )
@ -1611,7 +1614,7 @@ writeSplit ( int fd, Split *split )
xfer_acc = split->acc; xfer_acc = split->acc;
acc_id = -1; acc_id = -1;
if (xfer_acc) acc_id = xfer_acc -> id; if (xfer_acc) acc_id = xfer_acc -> id;
INFO_2 ("writeSplit: credit %d \n", acc_id); DEBUG ("writeSplit: credit %d \n", acc_id);
XACC_FLIP_INT (acc_id); XACC_FLIP_INT (acc_id);
err = write( fd, &acc_id, sizeof(int) ); err = write( fd, &acc_id, sizeof(int) );
if( err != sizeof(int) ) if( err != sizeof(int) )

View File

@ -54,6 +54,9 @@
static int error_code=0; /* error code, if error occurred */ static int error_code=0; /* error code, if error occurred */
/* This static indicates the debugging module that this .o belongs to. */
static short module = MOD_IO;
/*******************************************************/ /*******************************************************/
int int

View File

@ -31,7 +31,13 @@
#include "util.h" #include "util.h"
/** GLOBALS *********************************************************/ /** GLOBALS *********************************************************/
int loglevel = 1; int loglevel[MODULE_MAX] =
{0, /* DUMMY */
4, /* ENGINE */
1, /* IO */
3, /* REGISTER */
2, /* GUI */
};
/********************************************************************\ /********************************************************************\
* DEBUGGING MEMORY ALLOCATION STUFF * * DEBUGGING MEMORY ALLOCATION STUFF *

View File

@ -31,37 +31,36 @@
#define BUFSIZE 1024 #define BUFSIZE 1024
extern int loglevel;
/** DEBUGGING MACROS ************************************************/ /** DEBUGGING MACROS ************************************************/
/* The debuging macros enable the setting of trace messages */
#include <nana.h>
#include <stdio.h> #include <stdio.h>
#define PERR(x) { if (0 <=loglevel) { \ #define MOD_ENGINE 1
fprintf (stderr, "Error: "); \ #define MOD_IO 2
fprintf (stderr, x); }} #define MOD_LEDGER 3
#define MOD_GUI 4
#define MODULE_MAX 5
#define WARN(x) { if (1 <=loglevel) { \ extern int loglevel[MODULE_MAX];
fprintf (stderr, "Warning: "); \
fprintf (stderr, x); }}
#define INFO(x) { if (2 <=loglevel) { \ #define LERR (1 <= loglevel[module])
fprintf (stderr, "Info: "); \ #define LWARN (2 <= loglevel[module])
fprintf (stderr, x); }} #define LINFO (3 <= loglevel[module])
#define LDEBUG (4 <= loglevel[module])
#define LDETAIL (5 <= loglevel[module])
#define INFO_2(x,y) { if (2 <=loglevel) { \
fprintf (stderr, "Info: "); \
fprintf (stderr, x, y); }}
#define DEBUG(x) { if (3 <=loglevel) { \ /* utility macros */
fprintf (stderr, "Debug: "); \ #define PERR(x...) LG(LERR, "Error: "); LG(LERR, ##x);
fprintf (stderr, x); }} #define PWARN(x...) LG(LWARN, "Waring: "); LG(LWARN, ##x);
#define PINFO(x...) LG(LINFO, "Info: "); LG(LINFO, ##x);
#define ENTER(x) { if (3 <=loglevel) { \ #define DEBUG(x...) LG(LDEBUG, "Debug: "); LG(LDEBUG, ##x);
fprintf(stderr,"Entering: %s()\n", x); }} #define ENTER(x...) LG(LDEBUG, "Enter: "); LG(LDEBUG, ##x);
#define LEAVE(x) { if (3 <=loglevel) { \ #define LEAVE(x...) LG(LDEBUG, "Leave: "); LG(LDEBUG, ##x);
fprintf(stderr,"Leaving: %s()\n", x); }} #define DETAIL(x...) LG(LDETAIL, "Detail: "); LG(LDETAIL, ##x);
#define DEBUGCMD(x) { if (3 <=loglevel) { x; }}
#define DEBUGCMD(x) { if (INFO) { x; }}
#include <errno.h> #include <errno.h>
#define ERROR() fprintf(stderr,"%s: Line %d, error = %s\n", \ #define ERROR() fprintf(stderr,"%s: Line %d, error = %s\n", \