mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
add support for categories
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@170 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
parent
5589cf6222
commit
1f38e5434e
118
src/QIFIO.c
118
src/QIFIO.c
@ -112,8 +112,10 @@ char * xaccReadQIFDiscard( int fd )
|
|||||||
}
|
}
|
||||||
|
|
||||||
/********************************************************************\
|
/********************************************************************\
|
||||||
* xaccReadQIFAccount *
|
* xaccReadQIFCategory *
|
||||||
* reads in account name, description, etc. *
|
* reads in category account name, description, etc. *
|
||||||
|
* *
|
||||||
|
* implementation resembles xaccReadQIFCategory *
|
||||||
* *
|
* *
|
||||||
* Args: fd -- file descriptor *
|
* Args: fd -- file descriptor *
|
||||||
* Args: acc -- account structure to fill in *
|
* Args: acc -- account structure to fill in *
|
||||||
@ -132,6 +134,105 @@ char * xaccReadQIFDiscard( int fd )
|
|||||||
if (!(str)) { (str) = (char *)XtMalloc (sizeof(char)); (str)[0] = 0x0; } \
|
if (!(str)) { (str) = (char *)XtMalloc (sizeof(char)); (str)[0] = 0x0; } \
|
||||||
}
|
}
|
||||||
|
|
||||||
|
char * xaccReadQIFCategory (int fd, Account * acc)
|
||||||
|
{
|
||||||
|
char * qifline;
|
||||||
|
|
||||||
|
if (!acc) return NULL;
|
||||||
|
|
||||||
|
acc -> flags = 0x0; /* flags is byte */
|
||||||
|
acc -> type = -1; /* type is byte */
|
||||||
|
acc -> accountName = 0x0; /* string */
|
||||||
|
acc -> description = 0x0; /* string */
|
||||||
|
|
||||||
|
qifline = xaccReadQIFLine (fd);
|
||||||
|
if (!qifline) return NULL;
|
||||||
|
if ('!' == qifline [0]) return qifline;
|
||||||
|
|
||||||
|
/* scan for account name, description, type */
|
||||||
|
while (qifline) {
|
||||||
|
|
||||||
|
if ('N' == qifline [0]) {
|
||||||
|
XACC_PREP_STRING (acc->accountName);
|
||||||
|
} else
|
||||||
|
|
||||||
|
if ('D' == qifline [0]) {
|
||||||
|
XACC_PREP_STRING (acc->description);
|
||||||
|
} else
|
||||||
|
|
||||||
|
if ('T' == qifline [0]) {
|
||||||
|
if ('\r' != qifline[1]) {
|
||||||
|
printf ("QIF Parse: Unsupported category type %s \n", &qifline[1]);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
|
||||||
|
if ('E' == qifline [0]) {
|
||||||
|
acc->type = EXPENSE;
|
||||||
|
} else
|
||||||
|
|
||||||
|
if ('I' == qifline [0]) {
|
||||||
|
acc->type = INCOME;
|
||||||
|
} else
|
||||||
|
|
||||||
|
if ('R' == qifline [0]) {
|
||||||
|
/* hack alert -- some number that I don't understand */
|
||||||
|
} else
|
||||||
|
|
||||||
|
/* check for end-of-transaction marker */
|
||||||
|
if (!strcmp (qifline, "^^\r\n")) {
|
||||||
|
break;
|
||||||
|
} else
|
||||||
|
if ('!' == qifline [0]) break;
|
||||||
|
|
||||||
|
qifline = xaccReadQIFLine (fd);
|
||||||
|
}
|
||||||
|
|
||||||
|
XACC_PREP_NULL_STRING (acc->accountName);
|
||||||
|
XACC_PREP_NULL_STRING (acc->description);
|
||||||
|
|
||||||
|
return qifline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************\
|
||||||
|
* read a sequence of categories, inserting them into
|
||||||
|
* the indicated group
|
||||||
|
\********************************************************************/
|
||||||
|
|
||||||
|
char * xaccReadQIFCatList (int fd, AccountGroup *grp)
|
||||||
|
{
|
||||||
|
char * qifline;
|
||||||
|
Account *acc;
|
||||||
|
|
||||||
|
if (!grp) return 0x0;
|
||||||
|
do {
|
||||||
|
acc = mallocAccount();
|
||||||
|
qifline = xaccReadQIFCategory (fd, acc);
|
||||||
|
if ('!' == qifline [0]) break;
|
||||||
|
|
||||||
|
if (-1 == acc->type) { /* free up malloced data if unknown account type */
|
||||||
|
freeAccount(acc);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (!qifline) { /* free up malloced data if the read bombed. */
|
||||||
|
freeAccount(acc);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
insertAccount( grp, acc );
|
||||||
|
|
||||||
|
} while (qifline);
|
||||||
|
|
||||||
|
return qifline;
|
||||||
|
}
|
||||||
|
|
||||||
|
/********************************************************************\
|
||||||
|
* xaccReadQIFAccount *
|
||||||
|
* reads in account name, description, etc. *
|
||||||
|
* *
|
||||||
|
* Args: fd -- file descriptor *
|
||||||
|
* Args: acc -- account structure to fill in *
|
||||||
|
* Return: first new line after end of transaction *
|
||||||
|
\********************************************************************/
|
||||||
|
|
||||||
char * xaccReadQIFAccount (int fd, Account * acc)
|
char * xaccReadQIFAccount (int fd, Account * acc)
|
||||||
{
|
{
|
||||||
char * qifline;
|
char * qifline;
|
||||||
@ -139,7 +240,7 @@ char * xaccReadQIFAccount (int fd, Account * acc)
|
|||||||
if (!acc) return NULL;
|
if (!acc) return NULL;
|
||||||
|
|
||||||
acc -> flags = 0x0; /* flags is byte */
|
acc -> flags = 0x0; /* flags is byte */
|
||||||
acc -> type = 0x0; /* type is byte */
|
acc -> type = -1; /* type is byte */
|
||||||
acc -> accountName = 0x0; /* string */
|
acc -> accountName = 0x0; /* string */
|
||||||
acc -> description = 0x0; /* string */
|
acc -> description = 0x0; /* string */
|
||||||
|
|
||||||
@ -164,9 +265,8 @@ char * xaccReadQIFAccount (int fd, Account * acc)
|
|||||||
if (!strcmp (&qifline[1], "Invst\r\n")) {
|
if (!strcmp (&qifline[1], "Invst\r\n")) {
|
||||||
acc -> type = STOCK;
|
acc -> type = STOCK;
|
||||||
} else {
|
} else {
|
||||||
DEBUG ("Unsupported account type\n");
|
printf ("QIF Parse: Unsupported account type %s \n", &qifline[1]);
|
||||||
DEBUG (&qifline[1]);
|
acc -> type = -1; /* hack alert -- */
|
||||||
acc -> type = 0x0; /* hack alert -- */
|
|
||||||
}
|
}
|
||||||
} else
|
} else
|
||||||
|
|
||||||
@ -701,7 +801,7 @@ xaccReadQIFData( char *datafile )
|
|||||||
|
|
||||||
if (!strcmp (qifline, "!Type:Cat\r\n")) {
|
if (!strcmp (qifline, "!Type:Cat\r\n")) {
|
||||||
DEBUG ("got category\n");
|
DEBUG ("got category\n");
|
||||||
qifline = xaccReadQIFDiscard (fd);
|
qifline = xaccReadQIFCatList (fd, grp);
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
@ -761,6 +861,10 @@ xaccReadQIFData( char *datafile )
|
|||||||
freeAccount(acc);
|
freeAccount(acc);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
if (-1 == acc->type) { /* free up malloced data if unknown account type */
|
||||||
|
freeAccount(acc);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
insertAccount( grp, acc );
|
insertAccount( grp, acc );
|
||||||
|
|
||||||
/* spin until start of transaction records */
|
/* spin until start of transaction records */
|
||||||
|
Loading…
Reference in New Issue
Block a user