X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Fhomebank;a=blobdiff_plain;f=src%2Fhb-import.c;fp=src%2Fhb-import.c;h=da77c4f041090ff00c58d2dc4e0ca93b52568fad;hp=7520c03a77a76cb6c78947f906f5dcb554d1b08a;hb=5499ff44ef50b751b58f27fd13594f7dd4f959b7;hpb=a6c6b0df5492c2160ed97e3a376bdb2fe7c5ebc4 diff --git a/src/hb-import.c b/src/hb-import.c index 7520c03..da77c4f 100644 --- a/src/hb-import.c +++ b/src/hb-import.c @@ -38,6 +38,97 @@ extern struct Preferences *PREFS; /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =*/ + + +static gint homebank_alienfile_recognize(gchar *filename) +{ +GIOChannel *io; +gint i, retval = FILETYPE_UNKNOWN; +gchar *tmpstr; +gint io_stat; +GError *err = NULL; + + DB( g_print("\n[homebank] alienfile_recognize\n") ); + + io = g_io_channel_new_file(filename, "r", NULL); + if(io != NULL) + { + g_io_channel_set_encoding(io, NULL, NULL); /* set to binary mode */ + + for(i=0;i<25;i++) + { + if( retval != FILETYPE_UNKNOWN ) + break; + + io_stat = g_io_channel_read_line(io, &tmpstr, NULL, NULL, &err); + if( io_stat == G_IO_STATUS_EOF) + break; + if( io_stat == G_IO_STATUS_ERROR ) + { + DB (g_print(" + ERROR %s\n",err->message)); + break; + } + if( io_stat == G_IO_STATUS_NORMAL) + { + if( *tmpstr != '\0' ) + { + DB( g_print(" line %d: '%s' retval=%d\n", i, tmpstr, retval) ); + + // OFX/QFX file ? + if( g_strstr_len(tmpstr, -1, "") != NULL + || g_strstr_len(tmpstr, -1, "") != NULL + /*|| strcasestr(tmpstr, "") != NULL*/ + ) + { + DB( g_print(" type is OFX\n") ); + retval = FILETYPE_OFX; + } + else + + // QIF file ? + if( g_str_has_prefix(tmpstr, "!Type") || + g_str_has_prefix(tmpstr, "!type") || + g_str_has_prefix(tmpstr, "!Option") || + g_str_has_prefix(tmpstr, "!option") || + g_str_has_prefix(tmpstr, "!Account") || + g_str_has_prefix(tmpstr, "!account") + ) + { + DB( g_print(" type is QIF\n") ); + retval = FILETYPE_QIF; + } + else + + // CSV homebank format ? + if( hb_csv_test_line(tmpstr) ) + { + DB( g_print(" type is CSV homebank\n") ); + retval = FILETYPE_CSV_HB; + } + else + + // native homebank file ? + if( g_str_has_prefix(tmpstr, "paymode != PAYMODE_INTXFER ) { if( gentxn->nb_splits > 0 ) @@ -1303,6 +1395,7 @@ guint changes = 0; g_list_free(txnlist); + DB( g_print(" adding %d changes\n", changes) ); GLOBALS->changes_count += changes; }