mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add some reality to the journalling system
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1067 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
5eab083a70
commit
faa3eed1c5
@ -83,6 +83,7 @@
|
||||
|
||||
static int gen_logs = 1;
|
||||
static FILE * trans_log = 0x0;
|
||||
static char * log_base_name = 0x0;
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
@ -93,23 +94,54 @@ void xaccLogEnable (void) { gen_logs = 1; }
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
void
|
||||
xaccLogSetBaseName (const char *basepath)
|
||||
{
|
||||
if (!basepath) return;
|
||||
|
||||
if (log_base_name) free (log_base_name);
|
||||
log_base_name = strdup (basepath);
|
||||
|
||||
if (trans_log) {
|
||||
xaccCloseLog();
|
||||
xaccOpenLog();
|
||||
}
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
void
|
||||
xaccOpenLog (void)
|
||||
{
|
||||
char filename[1000];
|
||||
char * filename;
|
||||
char * timestamp;
|
||||
|
||||
if (!gen_logs) return;
|
||||
if (trans_log) return;
|
||||
|
||||
if (!log_base_name) log_base_name = strdup ("translog");
|
||||
|
||||
/* tag each filename with a timestamp */
|
||||
timestamp = xaccDateUtilGetStampNow ();
|
||||
|
||||
strcpy (filename, "translog.");
|
||||
filename = (char *) malloc (strlen (log_base_name) + 50);
|
||||
strcpy (filename, log_base_name);
|
||||
strcat (filename, ".");
|
||||
strcat (filename, timestamp);
|
||||
strcat (filename, ".log");
|
||||
|
||||
trans_log = fopen (filename, "a");
|
||||
if (!trans_log) {
|
||||
int norr = errno;
|
||||
printf ("Error: xaccOpenLog(): cannot open journal \n"
|
||||
"\t %d %s\n", norr, strerror (norr));
|
||||
free (filename);
|
||||
free (timestamp);
|
||||
return;
|
||||
}
|
||||
free (filename);
|
||||
free (timestamp);
|
||||
|
||||
/* use tab-separated fields */
|
||||
fprintf (trans_log, "mod id time_now " \
|
||||
@ -119,7 +151,18 @@ xaccOpenLog (void)
|
||||
"amount price date_reconciled\n");
|
||||
fprintf (trans_log, "-----------------\n");
|
||||
|
||||
free (timestamp);
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
\********************************************************************/
|
||||
|
||||
void
|
||||
xaccCloseLog (void)
|
||||
{
|
||||
if (!trans_log) return;
|
||||
fflush (trans_log);
|
||||
fclose (trans_log);
|
||||
trans_log = 0x0;
|
||||
}
|
||||
|
||||
/********************************************************************\
|
||||
|
@ -27,10 +27,18 @@
|
||||
#include "Transaction.h"
|
||||
|
||||
void xaccOpenLog (void);
|
||||
void xaccCloseLog (void);
|
||||
void xaccTransWriteLog (Transaction *, char);
|
||||
void xaccLogEnable (void);
|
||||
void xaccLogDisable (void);
|
||||
|
||||
/* The xaccLogSetBaseName() method sets the base filepath and the
|
||||
* root part of the journal file name. If the journal file is
|
||||
* already open, it will close it and reopen it with the new
|
||||
* base name.
|
||||
*/
|
||||
void xaccLogSetBaseName (const char *);
|
||||
|
||||
/* returned strings will have been allocated with malloc, free with free() */
|
||||
char *xaccSplitAsString(Split *s, const char prefix[]);
|
||||
char *xaccTransAsString(Transaction *t, const char prefix[]);
|
||||
|
Loading…
Reference in New Issue
Block a user