From 088931df8ab9c636582fddada15fb07a30be386e Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sat, 4 Apr 1998 05:58:19 +0000 Subject: [PATCH] add transaction logging git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@767 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/engine/DateUtils.c | 65 ++++++++++++++++++++++++++ src/engine/DateUtils.h | 34 ++++++++++++++ src/engine/Makefile | 4 +- src/engine/Makefile.in | 4 +- src/engine/TransLog.c | 96 +++++++++++++++++++++++++++++++++++++++ src/engine/TransLog.h | 33 ++++++++++++++ src/engine/Transaction.c | 34 +++++++++++++- src/engine/Transaction.h | 3 ++ src/engine/TransactionP.h | 10 +++- 9 files changed, 276 insertions(+), 7 deletions(-) create mode 100644 src/engine/DateUtils.c create mode 100644 src/engine/DateUtils.h create mode 100644 src/engine/TransLog.c create mode 100644 src/engine/TransLog.h diff --git a/src/engine/DateUtils.c b/src/engine/DateUtils.c new file mode 100644 index 0000000000..2ee7b9a8d0 --- /dev/null +++ b/src/engine/DateUtils.c @@ -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 +#include +#include + +#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 *************************************/ diff --git a/src/engine/DateUtils.h b/src/engine/DateUtils.h new file mode 100644 index 0000000000..44449e1b21 --- /dev/null +++ b/src/engine/DateUtils.h @@ -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 + +#include "config.h" + +char * xaccDateUtilGetStamp (time_t thyme); +char * xaccDateUtilGetStampNow (void); + +#endif /* __XACC_DATE_UTILS_H__ */ + +/************************ END OF ************************************\ +\************************* FILE *************************************/ diff --git a/src/engine/Makefile b/src/engine/Makefile index 41ea2f8a52..db6f13a086 100644 --- a/src/engine/Makefile +++ b/src/engine/Makefile @@ -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} ###################################################################### diff --git a/src/engine/Makefile.in b/src/engine/Makefile.in index 792eeb0661..0c99ad77c3 100644 --- a/src/engine/Makefile.in +++ b/src/engine/Makefile.in @@ -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} ###################################################################### diff --git a/src/engine/TransLog.c b/src/engine/TransLog.c new file mode 100644 index 0000000000..444f416db4 --- /dev/null +++ b/src/engine/TransLog.c @@ -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 +#include + +#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 *************************************/ diff --git a/src/engine/TransLog.h b/src/engine/TransLog.h new file mode 100644 index 0000000000..d1ac02a3be --- /dev/null +++ b/src/engine/TransLog.h @@ -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__ */ + diff --git a/src/engine/Transaction.c b/src/engine/Transaction.c index f3c9e15705..8219734c29 100644 --- a/src/engine/Transaction.c +++ b/src/engine/Transaction.c @@ -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) { diff --git a/src/engine/Transaction.h b/src/engine/Transaction.h index c897302b35..c346ae5394 100644 --- a/src/engine/Transaction.h +++ b/src/engine/Transaction.h @@ -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 *); diff --git a/src/engine/TransactionP.h b/src/engine/TransactionP.h index 957e98db1f..c3308a6b6b 100644 --- a/src/engine/TransactionP.h +++ b/src/engine/TransactionP.h @@ -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; };