mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
fixes of various sorts
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@164 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
6d45cee5c2
commit
043a305fd3
79
src/QIFIO.c
79
src/QIFIO.c
@ -45,6 +45,11 @@
|
|||||||
#define WFLAGS (O_WRONLY | O_CREAT | O_TRUNC)
|
#define WFLAGS (O_WRONLY | O_CREAT | O_TRUNC)
|
||||||
#define RFLAGS O_RDONLY
|
#define RFLAGS O_RDONLY
|
||||||
|
|
||||||
|
#ifdef DEBUG
|
||||||
|
#undef DEBUG
|
||||||
|
#endif
|
||||||
|
#define DEBUG printf
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* xaccReadQIFLine *
|
* xaccReadQIFLine *
|
||||||
* reads in one line of ASCII, until cr-nl *
|
* reads in one line of ASCII, until cr-nl *
|
||||||
@ -275,11 +280,13 @@ char * xaccReadQIFTransaction (int fd, Transaction *trans)
|
|||||||
|
|
||||||
if (!trans) return NULL;
|
if (!trans) return NULL;
|
||||||
|
|
||||||
trans -> memo = 0x0; /* string */
|
|
||||||
trans -> description = 0x0; /* string */
|
|
||||||
trans -> num = 0x0; /* string */
|
trans -> num = 0x0; /* string */
|
||||||
|
trans -> description = 0x0; /* string */
|
||||||
|
trans -> memo = 0x0; /* string */
|
||||||
|
trans -> action = 0x0; /* string */
|
||||||
trans -> catagory = 0; /* category is int */
|
trans -> catagory = 0; /* category is int */
|
||||||
trans -> damount = 0.0; /* amount is double */
|
trans -> damount = 0.0; /* amount is double */
|
||||||
|
trans -> share_price= 1.0; /* share_price is double */
|
||||||
trans -> reconciled = NREC; /* reconciled is byte */
|
trans -> reconciled = NREC; /* reconciled is byte */
|
||||||
/* other possible values ... */
|
/* other possible values ... */
|
||||||
/* trans->reconciled = YREC; trans->reconciled = CREC; */
|
/* trans->reconciled = YREC; trans->reconciled = CREC; */
|
||||||
@ -288,6 +295,9 @@ char * xaccReadQIFTransaction (int fd, Transaction *trans)
|
|||||||
trans -> date.month = 1; /* int */
|
trans -> date.month = 1; /* int */
|
||||||
trans -> date.day = 1; /* int */
|
trans -> date.day = 1; /* int */
|
||||||
|
|
||||||
|
trans -> debit = NULL;
|
||||||
|
trans -> credit = NULL;
|
||||||
|
|
||||||
qifline = xaccReadQIFLine (fd);
|
qifline = xaccReadQIFLine (fd);
|
||||||
|
|
||||||
if (!qifline) return NULL;
|
if (!qifline) return NULL;
|
||||||
@ -340,8 +350,40 @@ char * xaccReadQIFTransaction (int fd, Transaction *trans)
|
|||||||
qifline = xaccReadQIFLine (fd);
|
qifline = xaccReadQIFLine (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
XACC_PREP_NULL_STRING (trans->num);
|
||||||
XACC_PREP_NULL_STRING (trans->memo);
|
XACC_PREP_NULL_STRING (trans->memo);
|
||||||
XACC_PREP_NULL_STRING (trans->description);
|
XACC_PREP_NULL_STRING (trans->description);
|
||||||
|
XACC_PREP_NULL_STRING (trans->action);
|
||||||
|
|
||||||
|
return qifline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************\
|
||||||
|
* read a sequence of transactions, inserting them into
|
||||||
|
* the indicated account
|
||||||
|
\********************************************************************/
|
||||||
|
|
||||||
|
char * xaccReadQIFTransList (int fd, Account *acc)
|
||||||
|
{
|
||||||
|
Transaction *trans;
|
||||||
|
char * qifline;
|
||||||
|
|
||||||
|
if (!acc) return 0x0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
trans = (Transaction *)_malloc(sizeof(Transaction));
|
||||||
|
qifline = xaccReadQIFTransaction (fd, trans);
|
||||||
|
if (!qifline) { /* free up malloced data if the read bombed. */
|
||||||
|
_free (trans);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ('!' == qifline[0]) {
|
||||||
|
_free (trans);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
insertTransaction( acc, trans );
|
||||||
|
} while (qifline);
|
||||||
|
|
||||||
return qifline;
|
return qifline;
|
||||||
}
|
}
|
||||||
@ -385,19 +427,31 @@ xaccReadQIFData( char *datafile )
|
|||||||
|
|
||||||
while (qifline) {
|
while (qifline) {
|
||||||
if (!strcmp (qifline, "!Type:Class\r\n")) {
|
if (!strcmp (qifline, "!Type:Class\r\n")) {
|
||||||
DEBUG ("got class");
|
DEBUG ("got class\n");
|
||||||
qifline = xaccReadQIFDiscard (fd);
|
qifline = xaccReadQIFDiscard (fd);
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
|
if (!strcmp (qifline, "!Type:Bank \r\n")) {
|
||||||
|
Account *acc = mallocAccount();
|
||||||
|
DEBUG ("got bank\n");
|
||||||
|
|
||||||
|
acc->type = BANK;
|
||||||
|
acc->accountName = XtNewString ("Quicken Bank Account");
|
||||||
|
|
||||||
|
insertAccount( grp, acc );
|
||||||
|
qifline = xaccReadQIFTransList (fd, acc);
|
||||||
|
continue;
|
||||||
|
} else
|
||||||
|
|
||||||
if (!strcmp (qifline, "!Type:Cat\r\n")) {
|
if (!strcmp (qifline, "!Type:Cat\r\n")) {
|
||||||
DEBUG ("got category");
|
DEBUG ("got category\n");
|
||||||
qifline = xaccReadQIFDiscard (fd);
|
qifline = xaccReadQIFDiscard (fd);
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if (!strcmp (qifline, "!Option:AutoSwitch\r\n")) {
|
if (!strcmp (qifline, "!Option:AutoSwitch\r\n")) {
|
||||||
DEBUG ("got autoswitch on");
|
DEBUG ("got autoswitch on\n");
|
||||||
skip = 1;
|
skip = 1;
|
||||||
qifline = xaccReadQIFDiscard (fd);
|
qifline = xaccReadQIFDiscard (fd);
|
||||||
continue;
|
continue;
|
||||||
@ -421,7 +475,6 @@ xaccReadQIFData( char *datafile )
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* read account name, followed by dollar data ... */
|
/* read account name, followed by dollar data ... */
|
||||||
Transaction *trans;
|
|
||||||
Account *acc = mallocAccount();
|
Account *acc = mallocAccount();
|
||||||
DEBUG ("got account");
|
DEBUG ("got account");
|
||||||
qifline = xaccReadQIFAccount (fd, acc);
|
qifline = xaccReadQIFAccount (fd, acc);
|
||||||
@ -439,19 +492,7 @@ xaccReadQIFData( char *datafile )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* read transactions */
|
/* read transactions */
|
||||||
while (qifline) {
|
if (qifline) qifline = xaccReadQIFTransList (fd, acc);
|
||||||
trans = (Transaction *)_malloc(sizeof(Transaction));
|
|
||||||
qifline = xaccReadQIFTransaction (fd, trans);
|
|
||||||
if (!qifline) { /* free up malloced data if the read bombed. */
|
|
||||||
_free (trans);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if ('!' == qifline[0]) {
|
|
||||||
_free (trans);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
insertTransaction( acc, trans );
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
Loading…
Reference in New Issue
Block a user