more quicken file fixes

git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@165 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
Linas Vepstas 1997-11-27 09:20:40 +00:00
parent 043a305fd3
commit a065747f21
2 changed files with 59 additions and 20 deletions

View File

@ -242,7 +242,12 @@ removeTransaction( Account *acc, int num )
void void
xaccRemoveTransaction( Account *acc, Transaction *trans) xaccRemoveTransaction( Account *acc, Transaction *trans)
{ {
int i = getNumOfTransaction (acc, trans); int i;
if (!acc) return;
if (!trans) return;
i = getNumOfTransaction (acc, trans);
if (0 <= i) { if (0 <= i) {
removeTransaction (acc, i); removeTransaction (acc, i);
} }

View File

@ -34,6 +34,7 @@
\********************************************************************/ \********************************************************************/
#include <fcntl.h> #include <fcntl.h>
#include <string.h>
#include <Xm/Xm.h> #include <Xm/Xm.h>
#include "Account.h" #include "Account.h"
@ -273,12 +274,14 @@ double xaccParseQIFAmount (char * str)
* Return: first new line after end of transaction * * Return: first new line after end of transaction *
\********************************************************************/ \********************************************************************/
char * xaccReadQIFTransaction (int fd, Transaction *trans) char * xaccReadQIFTransaction (int fd, Account *acc)
{ {
Transaction *trans;
char * qifline; char * qifline;
int isneg = 0; int isneg = 0;
if (!trans) return NULL; if (!acc) return NULL;
trans = (Transaction *)_malloc(sizeof(Transaction));
trans -> num = 0x0; /* string */ trans -> num = 0x0; /* string */
trans -> description = 0x0; /* string */ trans -> description = 0x0; /* string */
@ -300,7 +303,12 @@ char * xaccReadQIFTransaction (int fd, Transaction *trans)
qifline = xaccReadQIFLine (fd); qifline = xaccReadQIFLine (fd);
if (!qifline) return NULL; if (!qifline) {
xaccRemoveTransaction ((Account *) trans->debit, trans);
xaccRemoveTransaction ((Account *) trans->credit, trans);
freeTransaction (trans);
return NULL;
}
if ('!' == qifline [0]) return qifline; if ('!' == qifline [0]) return qifline;
/* scan for transaction date, description, type */ /* scan for transaction date, description, type */
@ -333,7 +341,38 @@ char * xaccReadQIFTransaction (int fd, Transaction *trans)
/* hack alert */ /* hack alert */
} else } else
if ('L' == qifline [0]) { /* L == name of acount from which transfer occured */ if ('L' == qifline [0]) { /* L == name of acount from which transfer occured */
/* hack alert */ Account *xfer_acc;
AccountGroup *rootgrp;
char * tmp;
/* remove square brackets from name, remove carriage return ... */
qifline = &qifline[1];
if ('[' == qifline[0]) {
qifline = &qifline[1];
tmp = strchr (qifline, ']');
if (tmp) *tmp = 0x0;
}
tmp = strchr (qifline, '\r');
if(tmp) *tmp = 0x0;
tmp = strchr (qifline, '\n');
if(tmp) *tmp = 0x0;
/* see if the account exists */
rootgrp = xaccGetRootGroupOfAcct (acc);
xfer_acc = xaccGetAccountFromName (rootgrp, qifline);
/* if not, create it */
if (!xfer_acc) {
xfer_acc = mallocAccount ();
xfer_acc->accountName = XtNewString (qifline);
xfer_acc->type = BANK;
insertAccount (rootgrp, xfer_acc);
}
/* now, insert the transaction into the transfer account */
trans->debit = (struct _account *) xfer_acc;
insertTransaction (xfer_acc, trans);
} else } else
if ('$' == qifline [0]) { /* $ == dollar amount -- always preceeded by 'L' */ if ('$' == qifline [0]) { /* $ == dollar amount -- always preceeded by 'L' */
/* hack alert */ /* hack alert */
@ -350,11 +389,20 @@ char * xaccReadQIFTransaction (int fd, Transaction *trans)
qifline = xaccReadQIFLine (fd); qifline = xaccReadQIFLine (fd);
} }
if ('!' == qifline[0]) {
xaccRemoveTransaction ((Account *) trans->debit, trans);
xaccRemoveTransaction ((Account *) trans->credit, trans);
freeTransaction (trans);
}
XACC_PREP_NULL_STRING (trans->num); 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); XACC_PREP_NULL_STRING (trans->action);
trans->credit = (struct _account *) acc;
insertTransaction( acc, trans );
return qifline; return qifline;
} }
@ -365,26 +413,12 @@ char * xaccReadQIFTransaction (int fd, Transaction *trans)
char * xaccReadQIFTransList (int fd, Account *acc) char * xaccReadQIFTransList (int fd, Account *acc)
{ {
Transaction *trans;
char * qifline; char * qifline;
if (!acc) return 0x0; if (!acc) return 0x0;
do { do {
trans = (Transaction *)_malloc(sizeof(Transaction)); qifline = xaccReadQIFTransaction (fd, acc);
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); } while (qifline);
return qifline; return qifline;
} }