* Define a function for the XML-reading workaround in order to clean up a bit.
For the moment we keep to copies of it -- one for the use within the various musrfit programs, one that can be used in user functions. * musrt0 is now again activated in musrgui/musredit by default.
This commit is contained in:
@ -42,6 +42,47 @@ using namespace std;
|
||||
|
||||
ClassImpQ(PStartupHandler)
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// This function is a replacement for the ParseFile method of TSAXParser.
|
||||
// It is needed because in certain environments ParseFile does not work but ParseBuffer does.
|
||||
//--------------------------------------------------------------------------
|
||||
/**
|
||||
* <p> Replacement for the ParseFile method of TSAXParser.
|
||||
*
|
||||
* <p><b>return:</b>
|
||||
* - 1 if file cannot be read
|
||||
* - 0 if the file has been parsed successfully
|
||||
* - parse error code otherwise
|
||||
*
|
||||
* \param saxParser pointer to a TSAXParser object
|
||||
* \param startup_path_name full path to the XML file to be read
|
||||
*/
|
||||
int parseXmlFile(TSAXParser *saxParser, const char *startup_path_name)
|
||||
{
|
||||
int status;
|
||||
fstream xmlFile;
|
||||
unsigned int xmlSize = 0;
|
||||
char *xmlBuffer = 0;
|
||||
|
||||
xmlFile.open(startup_path_name, ios::in | ios::ate); // open file for reading and go to the end of the file
|
||||
if (xmlFile.is_open()) { // check if file has been opened successfully
|
||||
xmlSize = xmlFile.tellg(); // get the position within the stream == size of the file (since we are at the end)
|
||||
xmlFile.seekg(0, ios::beg); // go back to the beginning of the stream
|
||||
xmlBuffer = new char[xmlSize]; // allocate buffer memory for the whole XML file
|
||||
xmlFile.read(xmlBuffer, xmlSize); // read in the whole XML file into the buffer
|
||||
xmlFile.close(); // close the XML file
|
||||
}
|
||||
if (!xmlBuffer) { // file has not been read into the buffer
|
||||
status = 1;
|
||||
} else {
|
||||
status = saxParser->ParseBuffer(xmlBuffer, xmlSize); // parse buffer
|
||||
delete[] xmlBuffer; // free the buffer memory
|
||||
xmlBuffer = 0;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------------
|
||||
// Constructor
|
||||
//--------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user