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() ));
83 string(
"libofx_proc_file(): File format forced to: ") +
85 libofx_context->currentFileType() ));
88 switch (libofx_context->currentFileType())
97 message_out(
ERROR,
string(
"libofx_proc_file(): Detected file format not yet supported ou couldn't detect file format; aborting."));
106 char buffer[READ_BUFFER_SIZE];
108 bool type_found =
false;
110 if (p_filename != NULL && strcmp(p_filename,
"") != 0)
112 message_out(
DEBUG,
string(
"libofx_detect_file_type():Opening file: ") + p_filename);
114 input_file.open(p_filename);
118 message_out(
ERROR,
"libofx_detect_file_type():Unable to open the input file " +
string(p_filename));
125 input_file.getline(buffer,
sizeof(buffer),
'\n');
127 s_buffer.assign(buffer);
129 if (input_file.gcount() < (
sizeof(buffer) - 1))
131 s_buffer.append(
"\n");
133 else if ( !input_file.eof() && input_file.fail())
138 if (s_buffer.find(
"<OFX") != string::npos || s_buffer.find(
"<ofx") != string::npos)
144 else if (s_buffer.find(
"<OFC>") != string::npos || s_buffer.find(
"<ofc>") != string::npos)
152 while (type_found ==
false && !input_file.eof() && !input_file.bad());
161 message_out(
ERROR,
"libofx_detect_file_type(): Failed to identify input file format");