[ghemical-devel] Bug report and pt_BR Translation of Ghemical
Tommi Hassinen
Tommi.Hassinen at uku.fi
Fri Oct 3 05:10:49 EDT 2008
From: Jean Bréfort [jean.brefort at normalesup.org]
Sent: Thursday, October 02, 2008 11:40 PM
To: Tommi Hassinen
Cc: Ronoaldo JLP; ghemical-devel at bioinformatics.org
Subject: Re: [ghemical-devel] Bug report and pt_BR Translation of Ghemical
OK, found the issue: the numeric locale should be set to "C" in both
project::Import and project::Export.
Cheers,
Jean
Yes, that's true. And it explains why everything works if the numeric locale already is "C"...
Here in the end of this message is how I modified project::ImportFile() and project::ExportFile() methods in src/project.cpp file.
Regards,
Tommi
##########################################################################################
bool project::ImportFile(const char * filename, int index)
{
ifstream ifile;
ostringstream intermed;
file_trans translator;
// store the current (numeric) locale into my_num_locale,
// and switch into the "C" numeric locale...
static char my_num_locale[32] = "C";
strcpy(my_num_locale, setlocale(LC_NUMERIC, NULL));
setlocale(LC_NUMERIC, "C");
if (index == 0) // Automatic detection
{
if (!translator.CanImport(filename))
{
ErrorMessage("Cannot import that file type.");
return false;
}
ifile.open(filename, ios::in);
translator.Import(filename, ifile, intermed);
ifile.close();
}
else // By type picked by the user
{
ifile.open(filename, ios::in);
translator.Import(filename, index - 1, ifile, intermed);
ifile.close();
}
istringstream interInput(intermed.str());
bool retval = ReadGPR((* this), interInput, false);
// change the original locale back...
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
setlocale(LC_NUMERIC, my_num_locale);
return retval;
}
bool project::ExportFile(const char * filename, int index)
{
ofstream ofile;
stringstream intermed;
file_trans translator;
// store the current (numeric) locale into my_num_locale,
// and switch into the "C" numeric locale...
static char my_num_locale[32] = "C";
strcpy(my_num_locale, setlocale(LC_NUMERIC, NULL));
setlocale(LC_NUMERIC, "C");
WriteGPR_v100((* this), intermed); // this is for openbabel-1.100.2
istringstream interInput(intermed.str());
if (index == 0) // Automatic detection
{
if (!translator.CanExport(filename))
{
ErrorMessage("Cannot export that file type.");
return false;
}
ofile.open(filename, ios::out);
translator.Export(filename, interInput, ofile);
ofile.close();
}
else // By type picked by the user
{
ofile.open(filename, ios::out);
translator.Export(filename, index - 1, interInput, ofile);
ofile.close();
}
// change the original locale back...
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
setlocale(LC_NUMERIC, my_num_locale);
return true;
}
More information about the ghemical-devel
mailing list