mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
added transasction posted dates to file format
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@1281 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
11e82e8845
commit
4236c84d61
@ -81,10 +81,9 @@
|
|||||||
* account ::== int *
|
* account ::== int *
|
||||||
* String ::== size (char)^size *
|
* String ::== size (char)^size *
|
||||||
* size ::== int *
|
* size ::== int *
|
||||||
* Date ::== year month day *
|
* Date ::== seconds nanoseconds *
|
||||||
* month ::== int *
|
* seconds ::== unsigned 32 bit int *
|
||||||
* day ::== int *
|
* nanoseconds ::== unsigned 32 bit int *
|
||||||
* year ::== int *
|
|
||||||
\********************************************************************/
|
\********************************************************************/
|
||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
@ -141,7 +140,8 @@ static Account *readAccount( int fd, AccountGroup *, int token );
|
|||||||
static Transaction *readTransaction( int fd, Account *, int token );
|
static Transaction *readTransaction( int fd, Account *, int token );
|
||||||
static Split *readSplit( int fd, int token );
|
static Split *readSplit( int fd, int token );
|
||||||
static char *readString( int fd, int token );
|
static char *readString( int fd, int token );
|
||||||
static time_t readDate( int fd, int token );
|
static time_t readDMYDate( int fd, int token );
|
||||||
|
static int readTSDate( int fd, Timespec *, int token );
|
||||||
|
|
||||||
static int writeAccountGroupToFile( char *datafile, AccountGroup *grp );
|
static int writeAccountGroupToFile( char *datafile, AccountGroup *grp );
|
||||||
static int writeGroup( int fd, AccountGroup *grp );
|
static int writeGroup( int fd, AccountGroup *grp );
|
||||||
@ -149,7 +149,7 @@ static int writeAccount( int fd, Account *account );
|
|||||||
static int writeTransaction( int fd, Transaction *trans );
|
static int writeTransaction( int fd, Transaction *trans );
|
||||||
static int writeSplit( int fd, Split *split);
|
static int writeSplit( int fd, Split *split);
|
||||||
static int writeString( int fd, char *str );
|
static int writeString( int fd, char *str );
|
||||||
static int writeDate( int fd, time_t secs );
|
static int writeTSDate( int fd, struct timespec *);
|
||||||
|
|
||||||
/*******************************************************/
|
/*******************************************************/
|
||||||
/* backwards compatibility definitions for numeric value
|
/* backwards compatibility definitions for numeric value
|
||||||
@ -634,7 +634,6 @@ readTransaction( int fd, Account *acc, int token )
|
|||||||
char recn;
|
char recn;
|
||||||
double num_shares = 0.0;
|
double num_shares = 0.0;
|
||||||
double share_price = 0.0;
|
double share_price = 0.0;
|
||||||
time_t secs;
|
|
||||||
|
|
||||||
ENTER ("readTransaction");
|
ENTER ("readTransaction");
|
||||||
|
|
||||||
@ -653,15 +652,44 @@ readTransaction( int fd, Account *acc, int token )
|
|||||||
xaccTransSetNum (trans, tmp);
|
xaccTransSetNum (trans, tmp);
|
||||||
free (tmp);
|
free (tmp);
|
||||||
|
|
||||||
secs = readDate( fd, token );
|
if (7 >= token) {
|
||||||
if( 0 == secs )
|
time_t secs;
|
||||||
{
|
secs = readDMYDate( fd, token );
|
||||||
PERR ("Premature end of Transaction at date");
|
if( 0 == secs )
|
||||||
xaccTransDestroy(trans);
|
{
|
||||||
xaccTransCommitEdit (trans);
|
PERR ("Premature end of Transaction at date");
|
||||||
return NULL;
|
xaccTransDestroy(trans);
|
||||||
}
|
xaccTransCommitEdit (trans);
|
||||||
xaccTransSetDateSecs (trans, secs);
|
return NULL;
|
||||||
|
}
|
||||||
|
xaccTransSetDateSecs (trans, secs);
|
||||||
|
xaccTransSetDateEnteredSecs (trans, secs);
|
||||||
|
} else {
|
||||||
|
struct timespec ts;
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* read posted date first ... */
|
||||||
|
rc = readTSDate( fd, &ts, token );
|
||||||
|
if( -1 == rc )
|
||||||
|
{
|
||||||
|
PERR ("Premature end of Transaction at date");
|
||||||
|
xaccTransDestroy(trans);
|
||||||
|
xaccTransCommitEdit (trans);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
xaccTransSetDateTS (trans, &ts);
|
||||||
|
|
||||||
|
/* then the entered date ... */
|
||||||
|
rc = readTSDate( fd, &ts, token );
|
||||||
|
if( -1 == rc )
|
||||||
|
{
|
||||||
|
PERR ("Premature end of Transaction at date");
|
||||||
|
xaccTransDestroy(trans);
|
||||||
|
xaccTransCommitEdit (trans);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
xaccTransSetDateEnteredTS (trans, &ts);
|
||||||
|
}
|
||||||
|
|
||||||
tmp = readString( fd, token );
|
tmp = readString( fd, token );
|
||||||
if( NULL == tmp )
|
if( NULL == tmp )
|
||||||
@ -1034,7 +1062,41 @@ readString( int fd, int token )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* readDate *
|
* readTSDate *
|
||||||
|
* reads in a Date struct from the datafile *
|
||||||
|
* *
|
||||||
|
* Args: fd - the filedescriptor of the data file *
|
||||||
|
* token - the datafile version *
|
||||||
|
* Return: the Date struct *
|
||||||
|
\********************************************************************/
|
||||||
|
static int
|
||||||
|
readTSDate( int fd, struct timespec *ts, int token )
|
||||||
|
{
|
||||||
|
int err=0;
|
||||||
|
unsigned int secs, nsecs;
|
||||||
|
|
||||||
|
err = read( fd, &secs, sizeof(unsigned int) );
|
||||||
|
if( err != sizeof(unsigned int) )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
XACC_FLIP_INT (secs);
|
||||||
|
|
||||||
|
err = read( fd, &nsecs, sizeof(unsigned int) );
|
||||||
|
if( err != sizeof(unsigned int) )
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
XACC_FLIP_INT (nsecs);
|
||||||
|
|
||||||
|
ts->tv_sec = secs;
|
||||||
|
ts->tv_nsec = nsecs;
|
||||||
|
|
||||||
|
return 2*err;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************\
|
||||||
|
* readDMYDate *
|
||||||
* reads in a Date struct from the datafile *
|
* reads in a Date struct from the datafile *
|
||||||
* *
|
* *
|
||||||
* Args: fd - the filedescriptor of the data file *
|
* Args: fd - the filedescriptor of the data file *
|
||||||
@ -1042,7 +1104,7 @@ readString( int fd, int token )
|
|||||||
* Return: the Date struct *
|
* Return: the Date struct *
|
||||||
\********************************************************************/
|
\********************************************************************/
|
||||||
static time_t
|
static time_t
|
||||||
readDate( int fd, int token )
|
readDMYDate( int fd, int token )
|
||||||
{
|
{
|
||||||
int err=0;
|
int err=0;
|
||||||
int day, month, year;
|
int day, month, year;
|
||||||
@ -1395,7 +1457,7 @@ writeTransaction( int fd, Transaction *trans )
|
|||||||
Split *s;
|
Split *s;
|
||||||
int err=0;
|
int err=0;
|
||||||
int i=0;
|
int i=0;
|
||||||
time_t secs;
|
struct timespec ts;
|
||||||
|
|
||||||
ENTER ("writeTransaction");
|
ENTER ("writeTransaction");
|
||||||
/* If we've already written this transaction, don't write
|
/* If we've already written this transaction, don't write
|
||||||
@ -1408,8 +1470,12 @@ writeTransaction( int fd, Transaction *trans )
|
|||||||
err = writeString( fd, trans->num );
|
err = writeString( fd, trans->num );
|
||||||
if( -1 == err ) return err;
|
if( -1 == err ) return err;
|
||||||
|
|
||||||
secs = xaccTransGetDate (trans);
|
xaccTransGetDateTS (trans, &ts);
|
||||||
err = writeDate( fd, secs );
|
err = writeTSDate( fd, &ts);
|
||||||
|
if( -1 == err ) return err;
|
||||||
|
|
||||||
|
xaccTransGetDateEnteredTS (trans, &ts);
|
||||||
|
err = writeTSDate( fd, &ts);
|
||||||
if( -1 == err ) return err;
|
if( -1 == err ) return err;
|
||||||
|
|
||||||
err = writeString( fd, trans->description );
|
err = writeString( fd, trans->description );
|
||||||
@ -1524,7 +1590,7 @@ writeString( int fd, char *str )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* writeDate *
|
* writeTSDate *
|
||||||
* saves a Date to the datafile *
|
* saves a Date to the datafile *
|
||||||
* *
|
* *
|
||||||
* Args: fd - the filedescriptor of the data file *
|
* Args: fd - the filedescriptor of the data file *
|
||||||
@ -1532,29 +1598,21 @@ writeString( int fd, char *str )
|
|||||||
* Return: -1 on failure *
|
* Return: -1 on failure *
|
||||||
\********************************************************************/
|
\********************************************************************/
|
||||||
static int
|
static int
|
||||||
writeDate( int fd, time_t secs )
|
writeTSDate( int fd, struct timespec *ts)
|
||||||
{
|
{
|
||||||
int err=0;
|
int err=0;
|
||||||
int tmp;
|
unsigned int tmp;
|
||||||
struct tm *stm;
|
|
||||||
|
|
||||||
stm = localtime (&secs);
|
/* write 32 bits to file format, even if time_t is 64 bits */
|
||||||
|
tmp = ts->tv_sec;
|
||||||
tmp = stm->tm_year +1900;
|
|
||||||
XACC_FLIP_INT (tmp);
|
XACC_FLIP_INT (tmp);
|
||||||
err = write( fd, &tmp, sizeof(int) );
|
err = write( fd, &tmp, sizeof(unsigned int) );
|
||||||
if( err != sizeof(int) )
|
if( err != sizeof(int) )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
tmp = stm->tm_mon+1;
|
tmp = ts->tv_nsec;
|
||||||
XACC_FLIP_INT (tmp);
|
XACC_FLIP_INT (tmp);
|
||||||
err = write( fd, &tmp, sizeof(int) );
|
err = write( fd, &tmp, sizeof(unsigned int) );
|
||||||
if( err != sizeof(int) )
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
tmp = stm->tm_mday;
|
|
||||||
XACC_FLIP_INT (tmp);
|
|
||||||
err = write( fd, &tmp, sizeof(int) );
|
|
||||||
if( err != sizeof(int) )
|
if( err != sizeof(int) )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
@ -1385,6 +1385,36 @@ xaccTransSetDateSecs (Transaction *trans, time_t secs)
|
|||||||
* that until the commit phase, i.e. until the user has called the
|
* that until the commit phase, i.e. until the user has called the
|
||||||
* xaccTransCommitEdit() routine. So, for now, we are done.
|
* xaccTransCommitEdit() routine. So, for now, we are done.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xaccTransSetDateEnteredSecs (Transaction *trans, time_t secs)
|
||||||
|
{
|
||||||
|
if (!trans) return;
|
||||||
|
CHECK_OPEN (trans);
|
||||||
|
|
||||||
|
trans->date_entered.tv_sec = secs;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xaccTransSetDateTS (Transaction *trans, struct timespec *ts)
|
||||||
|
{
|
||||||
|
if (!trans) return;
|
||||||
|
CHECK_OPEN (trans);
|
||||||
|
|
||||||
|
trans->date_posted.tv_sec = ts->tv_sec;
|
||||||
|
trans->date_posted.tv_nsec = ts->tv_nsec;
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xaccTransSetDateEnteredTS (Transaction *trans, struct timespec *ts)
|
||||||
|
{
|
||||||
|
if (!trans) return;
|
||||||
|
CHECK_OPEN (trans);
|
||||||
|
|
||||||
|
trans->date_entered.tv_sec = ts->tv_sec;
|
||||||
|
trans->date_entered.tv_nsec = ts->tv_nsec;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -1525,6 +1555,20 @@ xaccTransGetDate (Transaction *trans)
|
|||||||
return (trans->date_posted.tv_sec);
|
return (trans->date_posted.tv_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xaccTransGetDateTS (Transaction *trans, Timespec *ts)
|
||||||
|
{
|
||||||
|
if (!trans || !ts) return;
|
||||||
|
*ts = (trans->date_posted);
|
||||||
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
xaccTransGetDateEnteredTS (Transaction *trans, Timespec *ts)
|
||||||
|
{
|
||||||
|
if (!trans || !ts) return;
|
||||||
|
*ts = (trans->date_entered);
|
||||||
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
xaccTransCountSplits (Transaction *trans)
|
xaccTransCountSplits (Transaction *trans)
|
||||||
{
|
{
|
||||||
|
@ -114,6 +114,9 @@ void xaccTransRollbackEdit (Transaction *);
|
|||||||
* The xaccTransSetDate() method does the same thing as
|
* The xaccTransSetDate() method does the same thing as
|
||||||
* xaccTransSetDateSecs(), but takes a convenient day-month-year format.
|
* xaccTransSetDateSecs(), but takes a convenient day-month-year format.
|
||||||
*
|
*
|
||||||
|
* The xaccTransSetDateTS() method does the same thing as
|
||||||
|
* xaccTransSetDateSecs(), but takes a struct timespec.
|
||||||
|
*
|
||||||
* The xaccTransSetDateToday() method does the same thing as
|
* The xaccTransSetDateToday() method does the same thing as
|
||||||
* xaccTransSetDateSecs(), but sets the date to the current system
|
* xaccTransSetDateSecs(), but sets the date to the current system
|
||||||
* date/time.
|
* date/time.
|
||||||
@ -121,6 +124,11 @@ void xaccTransRollbackEdit (Transaction *);
|
|||||||
void xaccTransSetDate (Transaction *, int day, int mon, int year);
|
void xaccTransSetDate (Transaction *, int day, int mon, int year);
|
||||||
void xaccTransSetDateSecs (Transaction *, time_t);
|
void xaccTransSetDateSecs (Transaction *, time_t);
|
||||||
void xaccTransSetDateToday (Transaction *);
|
void xaccTransSetDateToday (Transaction *);
|
||||||
|
void xaccTransSetDateTS (Transaction *, struct timespec *);
|
||||||
|
|
||||||
|
void xaccTransSetDateEnteredSecs (Transaction *, time_t);
|
||||||
|
void xaccTransSetDateEnteredTS (Transaction *, struct timespec *);
|
||||||
|
|
||||||
|
|
||||||
/* set the Num and Description fields ... */
|
/* set the Num and Description fields ... */
|
||||||
void xaccTransSetNum (Transaction *, const char *);
|
void xaccTransSetNum (Transaction *, const char *);
|
||||||
@ -178,6 +186,8 @@ Split * xaccTransGetSplit (Transaction *trans, int i);
|
|||||||
char * xaccTransGetNum (Transaction *);
|
char * xaccTransGetNum (Transaction *);
|
||||||
char * xaccTransGetDescription (Transaction *);
|
char * xaccTransGetDescription (Transaction *);
|
||||||
time_t xaccTransGetDate (Transaction *);
|
time_t xaccTransGetDate (Transaction *);
|
||||||
|
void xaccTransGetDateTS (Transaction *, struct timespec *);
|
||||||
|
void xaccTransGetDateEnteredTS (Transaction *, struct timespec *);
|
||||||
|
|
||||||
/* return the number of splits */
|
/* return the number of splits */
|
||||||
int xaccTransCountSplits (Transaction *trans);
|
int xaccTransCountSplits (Transaction *trans);
|
||||||
|
Loading…
Reference in New Issue
Block a user