add transaction logging

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@767 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1998-04-04 05:58:19 +00:00
parent f312da1739
commit 088931df8a
9 changed files with 276 additions and 7 deletions

65
src/engine/DateUtils.c Normal file
View File

@ -0,0 +1,65 @@
/********************************************************************\
* DateUtils.c -- Date Handling Utilities *
* Copyright (C) 1998 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 *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
\********************************************************************/
#include <stdio.h>
#include <string.h>
#include <time.h>
#include "config.h"
#include "DateUtils.h"
#define BUFFSIZE 100
/* ======================================================== */
char *
xaccDateUtilGetStamp (time_t thyme)
{
struct tm *stm;
char buf[BUFFSIZE];
char * retval;
stm = localtime (&thyme);
sprintf (buf, "%4d%2d%2d%2d%2d%2d",
(stm->tm_year + 1900),
(stm->tm_mon +1),
stm->tm_mday,
stm->tm_hour,
stm->tm_min,
stm->tm_sec
);
retval = strdup (buf);
return retval;
}
/* ======================================================== */
char *
xaccDateUtilGetStampNow (void)
{
time_t now;
time (&now);
return xaccDateUtilGetStamp (now);
}
/************************ END OF ************************************\
\************************* FILE *************************************/

34
src/engine/DateUtils.h Normal file
View File

@ -0,0 +1,34 @@
/********************************************************************\
* DateUtils.h -- Date Handling Utilities *
* Copyright (C) 1998 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 *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
\********************************************************************/
#ifndef __XACC_DATE_UTILS_H__
#define __XACC_DATE_UTILS_H__
#include <time.h>
#include "config.h"
char * xaccDateUtilGetStamp (time_t thyme);
char * xaccDateUtilGetStampNow (void);
#endif /* __XACC_DATE_UTILS_H__ */
/************************ END OF ************************************\
\************************* FILE *************************************/

View File

@ -41,8 +41,8 @@ LIBPATH = -L/lib -L/usr/lib -L/usr/local/lib
TARGET = ../libengine.a
######################################################################
SRCS = Account.c FileIO.c Group.c LedgerUtils.c QIFIO.c \
Transaction.c date.c util.c
SRCS = Account.c DateUtils.c FileIO.c Group.c LedgerUtils.c \
QIFIO.c Transaction.c TransLog.c date.c util.c
OBJS = ${SRCS:.c=.o}
######################################################################

View File

@ -41,8 +41,8 @@ LIBPATH = -L/lib -L/usr/lib -L/usr/local/lib
TARGET = ../libengine.a
######################################################################
SRCS = Account.c FileIO.c Group.c LedgerUtils.c QIFIO.c \
Transaction.c date.c util.c
SRCS = Account.c DateUtils.c FileIO.c Group.c LedgerUtils.c \
QIFIO.c Transaction.c TransLog.c date.c util.c
OBJS = ${SRCS:.c=.o}
######################################################################

96
src/engine/TransLog.c Normal file
View File

@ -0,0 +1,96 @@
/********************************************************************\
* TransLog.c -- the transaction logger *
* Copyright (C) 1998 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 *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
\********************************************************************/
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "Account.h"
#include "AccountP.h"
#include "DateUtils.h"
#include "date.h"
#include "Transaction.h"
#include "TransactionP.h"
#include "TransLog.h"
#include "util.h"
/*
* The logfiles are useful for tracing, journalling.
* Note that the current support for journalling is at best
* embryonic, at worst, sets the wrong expectations.
*/
int gen_logs = 0;
FILE * trans_log;
FILE * split_log;
/********************************************************************\
\********************************************************************/
void
xaccOpenLog (void)
{
char * timestamp;
if (!gen_logs) return;
if (trans_log && split_log) return;
/* tag each filename with a timestamp */
timestamp = xaccDateUtilGetStampNow ();
if (!trans_log) {
char filename[1000];
strcpy (filename, "translog.");
strcat (filename, timestamp);
strcat (filename, ".log");
trans_log = fopen (filename, "a");
fprintf (trans_log, "duhh duhhh\n");
fprintf (trans_log, "-----------------\n");
}
if (!split_log) {
char filename[1000];
strcpy (filename, "splitlog.");
strcat (filename, timestamp);
strcat (filename, ".log");
split_log = fopen (filename, "a");
fprintf (split_log, "duhh duhhh\n");
fprintf (split_log, "-----------------\n");
}
free (timestamp);
}
/********************************************************************\
\********************************************************************/
void
xaccTransWriteLog (Transaction *trans)
{
}
/************************ END OF ************************************\
\************************* FILE *************************************/

33
src/engine/TransLog.h Normal file
View File

@ -0,0 +1,33 @@
/********************************************************************\
* TransLog.h -- the transaction logger *
* Copyright (C) 1998 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 *
* published by the Free Software Foundation; either version 2 of *
* the License, or (at your option) any later version. *
* *
* This program is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License*
* along with this program; if not, write to the Free Software *
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
* *
\********************************************************************/
#ifndef __XACC_TRANS_LOG_H__
#define __XACC_TRANS_LOG_H__
#include "config.h"
#include "Account.h"
#include "Transaction.h"
void xaccOpenLog (void);
void xaccTransWriteLog (Transaction *);
#endif /* __XACC_TRANS_LOG_H__ */

View File

@ -32,16 +32,28 @@
#include "date.h"
#include "Transaction.h"
#include "TransactionP.h"
#include "TransLog.h"
#include "util.h"
/* if the "force_double_entry" flag has a non-zero value,
/*
* If the "force_double_entry" flag has a non-zero value,
* then all transactions will be *forced* to balance.
* This will be forced even if it requires a new split
* to be created.
*/
int force_double_entry = 0;
/*
* The logfiles are useful for tracing, journalling.
* Note that the current support for journalling is at best
* embryonic, at worst, sets the wrong expectations.
*/
int gen_logs = 0;
FILE * trans_log;
/********************************************************************\
* Because I can't use C++ for this project, doesn't mean that I *
* can't pretend too! These functions perform actions on the *
@ -231,6 +243,7 @@ xaccInitTransaction( Transaction * trans )
trans->date.year = 1900;
trans->date.month = 1;
trans->date.day = 1;
trans->open = 0;
}
/********************************************************************\
@ -302,12 +315,31 @@ xaccFreeTransaction( Transaction *trans )
trans->date.month = 1;
trans->date.day = 1;
trans->open = 0;
_free(trans);
}
/********************************************************************\
\********************************************************************/
void
xaccTransBeginEdit (Transaction *trans)
{
trans->open = 1;
xaccOpenLog ();
}
void
xaccTransCommitEdit (Transaction *trans)
{
trans->open = 0;
xaccTransWriteLog (trans);
}
/********************************************************************\
\********************************************************************/
void
xaccTransRebalance (Transaction * trans)
{

View File

@ -68,6 +68,9 @@ void xaccInitTransaction (Transaction *);/* clears a trans struct */
* account. (i.e. if none of the member splits are in an account). */
void xaccFreeTransaction (Transaction *);
void xaccTransBeginEdit (Transaction *);
void xaccTransCommitEdit (Transaction *);
void xaccTransSetDate (Transaction *, int day, int mon, int year);
void xaccTransSetDateStr (Transaction *, char *);

View File

@ -56,7 +56,8 @@
* between "dining", "tips" and "taxes" categories.
*/
struct _split {
struct _split
{
Account *acc; /* back-pointer to debited/credited account */
Transaction *parent; /* parent of split */
char * memo;
@ -78,7 +79,8 @@ struct _split {
};
struct _transaction {
struct _transaction
{
char * num; /* transaction id */
Date date; /* transaction date */
char * description;
@ -87,6 +89,10 @@ struct _transaction {
Split **dest_splits; /* list of splits, null terminated */
char write_flag; /* used only during file IO */
/* the "open" flag indicates if the transaction has been
* opened for editing. */
char open;
};