32 const unsigned int READ_BUFFER_SIZE = 1024;
39 const char * retval =
"UNKNOWN (File format couldn't be successfully identified)";
41 for (
int i = 0; LibofxImportFormatList[i].
format !=
LAST; i++)
43 if (LibofxImportFormatList[i].format == file_format)
57 for (
int i = 0; LibofxImportFormatList[i].
format !=
LAST; i++)
59 if (strcmp(LibofxImportFormatList[i].format_name, file_type_string) == 0)
61 retval = LibofxImportFormatList[i].
format;
73 message_out(
INFO,
string(
"libofx_proc_file(): File format not specified, autodetecting..."));
75 message_out(
INFO,
string(
"libofx_proc_file(): Detected file format: ") +
77 libofx_context->currentFileType() ));
81 libofx_context->setCurrentFileType(p_file_type);
83 string(
"libofx_proc_file(): File format forced to: ") +
85 libofx_context->currentFileType() ));
88 switch (libofx_context->currentFileType())
95 message_out(
ERROR,
string(
"libofx_proc_file(): Could not detect file format, or unsupported file format; aborting."));
105 char buffer[READ_BUFFER_SIZE];
107 bool type_found =
false;
109 if (p_filename != NULL && strcmp(p_filename,
"") != 0)
111 message_out(
DEBUG,
string(
"libofx_detect_file_type():Opening file: ") + p_filename);
113 input_file.open(p_filename);
117 message_out(
ERROR,
"libofx_detect_file_type():Unable to open the input file " +
string(p_filename));
124 input_file.getline(buffer,
sizeof(buffer),
'\n');
126 s_buffer.assign(buffer);
128 if (input_file.gcount() < int(
sizeof(buffer) - 1))
130 s_buffer.append(
"\n");
132 else if ( !input_file.eof() && input_file.fail())
137 if (s_buffer.find(
"<OFX") != string::npos || s_buffer.find(
"<ofx") != string::npos)
143 else if (s_buffer.find(
"<OFC>") != string::npos || s_buffer.find(
"<ofc>") != string::npos)
151 while (type_found ==
false && !input_file.eof() && !input_file.bad());
160 message_out(
ERROR,
"libofx_detect_file_type(): Failed to identify input file format");
enum LibofxFileFormat libofx_get_file_format_from_str(const struct LibofxFileFormatInfo format_list[], const char *file_type_string)
libofx_get_file_type returns a proper enum from a file type string.
Preprocessing of the OFX files before parsing.
int libofx_proc_file(LibofxContextPtr p_libofx_context, const char *p_filename, LibofxFileFormat p_file_type)
libofx_proc_file is the entry point of the library.
int message_out(OfxMsgType error_type, const string message)
Message output function.
Preprocessing of the OFX files before parsing.
const char * libofx_get_file_format_description(const struct LibofxFileFormatInfo format_list[], enum LibofxFileFormat file_format)
get_file_format_description returns a string description of a LibofxFileType.
Message IO functionality.
enum LibofxFileFormat libofx_detect_file_type(const char *p_filename)
libofx_detect_file_type tries to analyze a file to determine it's format.
int ofx_proc_file(LibofxContextPtr ctx, const char *p_filename)
File pre-processing of OFX AND for OFC files.