31const unsigned int READ_BUFFER_SIZE = 1024;
38 const char * retval =
"UNKNOWN (File format couldn't be successfully identified)";
40 for (
int i = 0; LibofxImportFormatList[i].
format !=
LAST; i++)
42 if (LibofxImportFormatList[i].format == file_format)
56 for (
int i = 0; LibofxImportFormatList[i].
format !=
LAST; i++)
58 if (strcmp(LibofxImportFormatList[i].format_name, file_type_string) == 0)
60 retval = LibofxImportFormatList[i].
format;
72 message_out(
INFO, std::string(
"libofx_proc_file(): File format not specified, autodetecting..."));
74 message_out(
INFO, std::string(
"libofx_proc_file(): Detected file format: ") +
76 libofx_context->currentFileType() ));
80 libofx_context->setCurrentFileType(p_file_type);
82 std::string(
"libofx_proc_file(): File format forced to: ") +
84 libofx_context->currentFileType() ));
87 switch (libofx_context->currentFileType())
94 message_out(
ERROR, std::string(
"libofx_proc_file(): Could not detect file format, or unsupported file format; aborting."));
103 std::ifstream input_file;
104 char buffer[READ_BUFFER_SIZE];
105 std::string s_buffer;
106 bool type_found =
false;
108 if (p_filename != NULL && strcmp(p_filename,
"") != 0)
110 message_out(
DEBUG, std::string(
"libofx_detect_file_type():Opening file: ") + p_filename);
112 input_file.open(p_filename);
116 message_out(
ERROR,
"libofx_detect_file_type():Unable to open the input file " + std::string(p_filename));
123 input_file.getline(buffer,
sizeof(buffer),
'\n');
125 s_buffer.assign(buffer);
127 if (input_file.gcount() <
int(
sizeof(buffer) - 1))
129 s_buffer.append(
"\n");
131 else if ( !input_file.eof() && input_file.fail())
136 if (s_buffer.find(
"<OFX") != std::string::npos || s_buffer.find(
"<ofx") != std::string::npos)
142 else if (s_buffer.find(
"<OFC>") != std::string::npos || s_buffer.find(
"<ofc>") != std::string::npos)
150 while (type_found ==
false && !input_file.eof() && !input_file.bad());
159 message_out(
ERROR,
"libofx_detect_file_type(): Failed to identify input file format");
enum LibofxFileFormat libofx_detect_file_type(const char *p_filename)
libofx_detect_file_type tries to analyze a file to determine it's 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.
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.
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.
Preprocessing of the OFX files before parsing.
Main header file containing the LibOfx API.
int message_out(OfxMsgType error_type, const std::string message)
Message output function.
Message IO functionality.
int ofx_proc_file(LibofxContextPtr ctx, const char *p_filename)
File pre-processing of OFX AND for OFC files.
Preprocessing of the OFX files before parsing.