|
GnuCash 2.4.99
|
00001 /********************************************************************\ 00002 * This program is free software; you can redistribute it and/or * 00003 * modify it under the terms of the GNU General Public License as * 00004 * published by the Free Software Foundation; either version 2 of * 00005 * the License, or (at your option) any later version. * 00006 * * 00007 * This program is distributed in the hope that it will be useful, * 00008 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00009 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00010 * GNU General Public License for more details. * 00011 * * 00012 * You should have received a copy of the GNU General Public License* 00013 * along with this program; if not, contact: * 00014 * * 00015 * Free Software Foundation Voice: +1-617-542-5942 * 00016 * 51 Franklin Street, Fifth Floor Fax: +1-617-542-2652 * 00017 * Boston, MA 02110-1301, USA gnu@gnu.org * 00018 \********************************************************************/ 00019 00027 #ifndef GNC_CSV_MODEL_H 00028 #define GNC_CSV_MODEL_H 00029 00030 #include "config.h" 00031 00032 #include "Account.h" 00033 #include "Transaction.h" 00034 00035 #include "stf/stf-parse.h" 00036 00041 enum GncCsvColumnType {GNC_CSV_NONE, 00042 GNC_CSV_DATE, 00043 GNC_CSV_DESCRIPTION, 00044 GNC_CSV_ACCOUNT, 00045 GNC_CSV_BALANCE, 00046 GNC_CSV_DEPOSIT, 00047 GNC_CSV_WITHDRAWAL, 00048 GNC_CSV_NUM, 00049 GNC_CSV_NUM_COL_TYPES 00050 }; 00051 00055 enum GncCsvErrorType {GNC_CSV_FILE_OPEN_ERR, 00056 GNC_CSV_ENCODING_ERR 00057 }; 00058 00062 typedef struct 00063 { 00064 char* begin; 00065 char* end; 00066 } GncCsvStr; 00067 00068 /* TODO We now sort transactions by date, not line number, so we 00069 * should probably get rid of this struct and uses of it. */ 00070 00078 typedef struct 00079 { 00080 int line_no; 00081 Transaction* trans; 00082 gnc_numeric balance; 00083 gboolean balance_set; 00084 } GncCsvTransLine; 00085 00086 /* A set of currency formats that the user sees. */ 00087 extern const int num_currency_formats; 00088 extern const gchar* currency_format_user[]; 00089 00090 /* A set of date formats that the user sees. */ 00091 extern const int num_date_formats; 00092 extern const gchar* date_format_user[]; 00093 00094 /* This array contains all of the different strings for different column types. */ 00095 extern gchar* gnc_csv_column_type_strs[]; 00096 00098 typedef struct 00099 { 00100 gchar* encoding; 00101 GMappedFile* raw_mapping; 00102 GncCsvStr raw_str; 00103 GncCsvStr file_str; 00104 GPtrArray* orig_lines; 00105 GArray* orig_row_lengths; 00107 int orig_max_row; 00108 GStringChunk* chunk; 00109 StfParseOptions_t* options; 00110 GArray* column_types; 00111 GList* error_lines; 00112 GList* transactions; 00113 int date_format; 00114 int start_row; 00115 int end_row; 00116 int currency_format; 00117 } GncCsvParseData; 00118 00119 GncCsvParseData* gnc_csv_new_parse_data(void); 00120 00121 void gnc_csv_parse_data_free(GncCsvParseData* parse_data); 00122 00123 int gnc_csv_load_file(GncCsvParseData* parse_data, const char* filename, 00124 GError** error); 00125 00126 int gnc_csv_convert_encoding(GncCsvParseData* parse_data, const char* encoding, GError** error); 00127 00128 int gnc_csv_parse(GncCsvParseData* parse_data, gboolean guessColTypes, GError** error); 00129 00130 int gnc_csv_parse_to_trans(GncCsvParseData* parse_data, Account* account, gboolean redo_errors); 00131 00132 time_t parse_date(const char* date_str, int format); 00133 00134 #endif
1.7.4