Skip to content

Commit

Permalink
Fix locale to C for sscanf() so that decimals parse correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
jedi98 committed Jan 4, 2016
1 parent f5423fe commit effdc77
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
5 changes: 5 additions & 0 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,13 @@ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
#include "mainwindow.h"
#include <QApplication>

#include <locale.h>

int main(int argc, char *argv[])
{
//setlocale(LC_NUMERIC, "C");
//setlocale(LC_ALL, "fr_FR.UTF-8");

QApplication a(argc, argv);
MainWindow w;
w.show();
Expand Down
12 changes: 10 additions & 2 deletions mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
*/

#include <stdio.h>
#include <locale.h>

#include <QDir>
#include <QFileDialog>
Expand All @@ -32,7 +33,7 @@ along with Foobar. If not, see <http://www.gnu.org/licenses/>.
#include "ui_mainwindow.h"

const Version
MainWindow::version = Version(0,9,11,"rc2");
MainWindow::version = Version(0,10,13,"");

ScanData scandata;

Expand All @@ -41,7 +42,12 @@ MainWindow::MainWindow(QWidget *parent) :
ui(new Ui::MainWindow)
{
setlinebuf(stdout);

//{
//char *p;
//printf("setlocale=%p\n",p=setlocale(LC_ALL, "sv_SE.UTF-8"));
//if (p) printf("\t%s\n",p);
//std::setlocale(LC_ALL, "sv_SE");
//}
Config::read();

ui->setupUi(this);
Expand Down Expand Up @@ -99,6 +105,8 @@ setlinebuf(stdout);

montimer.setParent(this);
connect(&montimer, SIGNAL(timeout()), this, SLOT(Slot_montimer_timeout()));

//std::setlocale(LC_ALL, "sv_SE.UTF-8");
}


Expand Down
7 changes: 7 additions & 0 deletions seriallink.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ void SerialLink::Cmd_Scan(long fstart, long fend, long fstep, bool useraw, Event

scandata.points.resize(0);

//TODO: clean this up, why can I not set it globally?
//std::setlocale(LC_ALL, "sv_SE");
std::setlocale(LC_ALL, "C"); //Need sscanf() to use default locale for number parsing.

for (;state<10;)
{
r = RxLine();
Expand Down Expand Up @@ -249,6 +253,9 @@ void SerialLink::Cmd_Raw(Sample &sample)

TxCmd("raw\r");

//TODO: clean this up, why can I not set it globally?
std::setlocale(LC_ALL, "C"); //Need sscanf() to use default locale for number parsing.

for (;state<10;)
{
r = RxLine();
Expand Down

0 comments on commit effdc77

Please sign in to comment.