mirror of
https://github.com/Gnucash/gnucash.git
synced 2025-02-25 18:55:30 -06:00
modifications so that CR, CRLF and LF can all mark the end-of-line
git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@183 57a11ea4-9604-0410-9ed3-97b8803252fd
This commit is contained in:
46
src/QIFIO.c
46
src/QIFIO.c
@@ -88,6 +88,8 @@ char * xaccReadQIFLine( int fd )
|
|||||||
* Return: first line of new transaction *
|
* Return: first line of new transaction *
|
||||||
\********************************************************************/
|
\********************************************************************/
|
||||||
|
|
||||||
|
#define NSTRNCMP(x,y) (0==strncmp((x),(y),strlen(y)))
|
||||||
|
|
||||||
char * xaccReadQIFDiscard( int fd )
|
char * xaccReadQIFDiscard( int fd )
|
||||||
{
|
{
|
||||||
char * qifline;
|
char * qifline;
|
||||||
@@ -97,10 +99,10 @@ char * xaccReadQIFDiscard( int fd )
|
|||||||
if ('!' == qifline [0]) return qifline;
|
if ('!' == qifline [0]) return qifline;
|
||||||
|
|
||||||
while (qifline) {
|
while (qifline) {
|
||||||
if (!strcmp (qifline, "^^\r\n")) {
|
if (NSTRNCMP(qifline, "^^")) {
|
||||||
qifline = xaccReadQIFLine (fd);
|
qifline = xaccReadQIFLine (fd);
|
||||||
return qifline;
|
return qifline;
|
||||||
}
|
} else
|
||||||
if ('!' == qifline [0]) return qifline;
|
if ('!' == qifline [0]) return qifline;
|
||||||
qifline = xaccReadQIFLine (fd);
|
qifline = xaccReadQIFLine (fd);
|
||||||
}
|
}
|
||||||
@@ -178,7 +180,7 @@ char * xaccReadQIFCategory (int fd, Account * acc)
|
|||||||
} else
|
} else
|
||||||
|
|
||||||
/* check for end-of-transaction marker */
|
/* check for end-of-transaction marker */
|
||||||
if (!strcmp (qifline, "^^\r\n")) {
|
if (NSTRNCMP(qifline, "^^")) {
|
||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
if ('!' == qifline [0]) break;
|
if ('!' == qifline [0]) break;
|
||||||
@@ -228,22 +230,22 @@ char * xaccReadQIFAccount (int fd, Account * acc)
|
|||||||
} else
|
} else
|
||||||
if ('T' == qifline [0]) {
|
if ('T' == qifline [0]) {
|
||||||
|
|
||||||
if (!strcmp (&qifline[1], "Bank\r\n")) {
|
if (NSTRNCMP (&qifline[1], "Bank")) {
|
||||||
acc -> type = BANK;
|
acc -> type = BANK;
|
||||||
} else
|
} else
|
||||||
if (!strcmp (&qifline[1], "Cash\r\n")) {
|
if (NSTRNCMP (&qifline[1], "Cash")) {
|
||||||
acc -> type = CASH;
|
acc -> type = CASH;
|
||||||
} else
|
} else
|
||||||
if (!strcmp (&qifline[1], "CCard\r\n")) {
|
if (NSTRNCMP (&qifline[1], "CCard")) {
|
||||||
acc -> type = CREDIT;
|
acc -> type = CREDIT;
|
||||||
} else
|
} else
|
||||||
if (!strcmp (&qifline[1], "Invst\r\n")) {
|
if (NSTRNCMP (&qifline[1], "Invst")) {
|
||||||
acc -> type = STOCK;
|
acc -> type = STOCK;
|
||||||
} else
|
} else
|
||||||
if (!strcmp (&qifline[1], "Oth A\r\n")) {
|
if (NSTRNCMP (&qifline[1], "Oth A")) {
|
||||||
acc -> type = ASSET;
|
acc -> type = ASSET;
|
||||||
} else
|
} else
|
||||||
if (!strcmp (&qifline[1], "Oth L\r\n")) {
|
if (NSTRNCMP (&qifline[1], "Oth L")) {
|
||||||
acc -> type = LIABILITY;
|
acc -> type = LIABILITY;
|
||||||
} else
|
} else
|
||||||
{
|
{
|
||||||
@@ -253,7 +255,7 @@ char * xaccReadQIFAccount (int fd, Account * acc)
|
|||||||
} else
|
} else
|
||||||
|
|
||||||
/* check for end-of-transaction marker */
|
/* check for end-of-transaction marker */
|
||||||
if (!strcmp (qifline, "^^\r\n")) {
|
if (NSTRNCMP (qifline, "^^")) {
|
||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
if ('!' == qifline [0]) break;
|
if ('!' == qifline [0]) break;
|
||||||
@@ -360,7 +362,10 @@ void xaccParseQIFDate (Date * dat, char * str)
|
|||||||
|
|
||||||
str = tok+sizeof(char);
|
str = tok+sizeof(char);
|
||||||
tok = strchr (str, '\r');
|
tok = strchr (str, '\r');
|
||||||
|
if (!tok) {
|
||||||
|
tok = strchr (str, '\n');
|
||||||
if (!tok) return;
|
if (!tok) return;
|
||||||
|
}
|
||||||
*tok = 0x0;
|
*tok = 0x0;
|
||||||
dat->year = atoi (str);
|
dat->year = atoi (str);
|
||||||
dat->year += 1900;
|
dat->year += 1900;
|
||||||
@@ -410,7 +415,10 @@ double xaccParseQIFAmount (char * str)
|
|||||||
str = tok+sizeof(char);
|
str = tok+sizeof(char);
|
||||||
|
|
||||||
tok = strchr (str, '\r');
|
tok = strchr (str, '\r');
|
||||||
|
if (!tok) {
|
||||||
|
tok = strchr (str, '\n');
|
||||||
if (!tok) return dollars;
|
if (!tok) return dollars;
|
||||||
|
}
|
||||||
*tok = 0x0;
|
*tok = 0x0;
|
||||||
|
|
||||||
/* strip off garbage at end of the line */
|
/* strip off garbage at end of the line */
|
||||||
@@ -726,7 +734,7 @@ char * xaccReadQIFTransaction (int fd, Account *acc)
|
|||||||
} else
|
} else
|
||||||
|
|
||||||
/* check for end-of-transaction marker */
|
/* check for end-of-transaction marker */
|
||||||
if (!strcmp (qifline, "^^\r\n")) {
|
if (NSTRNCMP (qifline, "^^")) {
|
||||||
break;
|
break;
|
||||||
} else
|
} else
|
||||||
if ('!' == qifline [0]) break;
|
if ('!' == qifline [0]) break;
|
||||||
@@ -864,7 +872,7 @@ xaccReadQIFData( char *datafile )
|
|||||||
}
|
}
|
||||||
|
|
||||||
while (qifline) {
|
while (qifline) {
|
||||||
if (!strcmp (qifline, "!Type:Bank \r\n")) {
|
if (NSTRNCMP (qifline, "!Type:Bank")) {
|
||||||
Account *acc = mallocAccount();
|
Account *acc = mallocAccount();
|
||||||
DEBUG ("got bank\n");
|
DEBUG ("got bank\n");
|
||||||
|
|
||||||
@@ -878,19 +886,19 @@ xaccReadQIFData( char *datafile )
|
|||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if (!strcmp (qifline, "!Type:Cat\r\n")) {
|
if (NSTRNCMP (qifline, "!Type:Cat")) {
|
||||||
DEBUG ("got category\n");
|
DEBUG ("got category\n");
|
||||||
qifline = xaccReadQIFAccList (fd, grp, 1);
|
qifline = xaccReadQIFAccList (fd, grp, 1);
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if (!strcmp (qifline, "!Type:Class\r\n")) {
|
if (NSTRNCMP (qifline, "!Type:Class")) {
|
||||||
DEBUG ("got class\n");
|
DEBUG ("got class\n");
|
||||||
qifline = xaccReadQIFDiscard (fd);
|
qifline = xaccReadQIFDiscard (fd);
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if (!strcmp (qifline, "!Type:Invst\r\n")) {
|
if (NSTRNCMP (qifline, "!Type:Invst")) {
|
||||||
Account *acc = mallocAccount();
|
Account *acc = mallocAccount();
|
||||||
DEBUG ("got Invst\n");
|
DEBUG ("got Invst\n");
|
||||||
|
|
||||||
@@ -904,27 +912,27 @@ xaccReadQIFData( char *datafile )
|
|||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if (!strcmp (qifline, "!Type:Memorized\r\n")) {
|
if (NSTRNCMP (qifline, "!Type:Memorized")) {
|
||||||
DEBUG ("got memorized\n");
|
DEBUG ("got memorized\n");
|
||||||
qifline = xaccReadQIFDiscard (fd);
|
qifline = xaccReadQIFDiscard (fd);
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if (!strcmp (qifline, "!Option:AutoSwitch\r\n")) {
|
if (NSTRNCMP (qifline, "!Option:AutoSwitch")) {
|
||||||
DEBUG ("got autoswitch on\n");
|
DEBUG ("got autoswitch on\n");
|
||||||
skip = 1;
|
skip = 1;
|
||||||
qifline = xaccReadQIFDiscard (fd);
|
qifline = xaccReadQIFDiscard (fd);
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if (!strcmp (qifline, "!Clear:AutoSwitch\r\n")) {
|
if (NSTRNCMP (qifline, "!Clear:AutoSwitch")) {
|
||||||
DEBUG ("got autoswitch clear\n");
|
DEBUG ("got autoswitch clear\n");
|
||||||
skip = 0;
|
skip = 0;
|
||||||
qifline = xaccReadQIFDiscard (fd);
|
qifline = xaccReadQIFDiscard (fd);
|
||||||
continue;
|
continue;
|
||||||
} else
|
} else
|
||||||
|
|
||||||
if (!strcmp (qifline, "!Account\r\n")) {
|
if (NSTRNCMP (qifline, "!Account")) {
|
||||||
if (skip) {
|
if (skip) {
|
||||||
/* loop and read all of the account names and descriptions */
|
/* loop and read all of the account names and descriptions */
|
||||||
/* no actual dollar data is expected to be read here ... */
|
/* no actual dollar data is expected to be read here ... */
|
||||||
|
|||||||
Reference in New Issue
Block a user