kopia lustrzana https://github.com/Hamlib/Hamlib
Wrap sscanf in order to workaround some locales where the decimal
separator (float format, ...) is not a dot. git-svn-id: https://hamlib.svn.sourceforge.net/svnroot/hamlib/trunk@2711 7ae35d74-ebe9-4afe-98af-79ac388436b8Hamlib-1.2.10
rodzic
e5ae214239
commit
1413d79e5c
|
@ -1,4 +1,4 @@
|
|||
noinst_HEADERS = config.h bandplan.h
|
||||
noinst_HEADERS = config.h bandplan.h num_stdio.h
|
||||
|
||||
nobase_include_HEADERS = hamlib/rig.h hamlib/riglist.h hamlib/rig_dll.h \
|
||||
hamlib/rotator.h hamlib/rotlist.h hamlib/rigclass.h hamlib/rotclass.h
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
/*
|
||||
* Hamlib Interface - numeric locale wrapping helpers
|
||||
* Copyright (c) 2009 by Stephane Fillod
|
||||
*
|
||||
* $Id: bandplan.h,v 1.1 2002-11-16 14:05:16 fillods Exp $
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Library General Public License as
|
||||
* published by the Free Software Foundation; either version 2 of
|
||||
* the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Library General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Library General Public
|
||||
* License along with this library; if not, write to the Free Software
|
||||
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _NUM_STDIO_H
|
||||
#define _NUM_STDIO_H 1
|
||||
|
||||
#include <locale.h>
|
||||
|
||||
/*
|
||||
* This header file is internal to Hamlib and its backends,
|
||||
* thus not part of the API.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Wrapper for sscanf to workaround some locales where the decimal
|
||||
* separator (float, ...) is not the dot.
|
||||
*/
|
||||
#define num_sscanf(a...) \
|
||||
({ int __ret; char *__savedlocale; \
|
||||
__savedlocale = setlocale(LC_NUMERIC, NULL); \
|
||||
setlocale(LC_NUMERIC, "C"); \
|
||||
__ret = sscanf(a); \
|
||||
setlocale(LC_NUMERIC, __savedlocale); \
|
||||
__ret; \
|
||||
})
|
||||
|
||||
#define num_sprintf(a...) \
|
||||
({ int __ret; char *__savedlocale; \
|
||||
__savedlocale = setlocale(LC_NUMERIC, NULL); \
|
||||
setlocale(LC_NUMERIC, "C"); \
|
||||
__ret = sprintf(a); \
|
||||
setlocale(LC_NUMERIC, __savedlocale); \
|
||||
__ret; \
|
||||
})
|
||||
|
||||
#endif /* _NUM_STDIO_H */
|
14
kenwood/th.c
14
kenwood/th.c
|
@ -1,6 +1,6 @@
|
|||
/*
|
||||
* Hamlib Kenwood backend - TH handheld primitives
|
||||
* Copyright (c) 2001-2008 by Stephane Fillod
|
||||
* Copyright (c) 2001-2009 by Stephane Fillod
|
||||
*
|
||||
* $Id: th.c,v 1.39 2009-02-13 19:29:16 azummo Exp $
|
||||
*
|
||||
|
@ -34,6 +34,7 @@
|
|||
#include "th.h"
|
||||
#include "serial.h"
|
||||
#include "misc.h"
|
||||
#include "num_stdio.h"
|
||||
|
||||
/* Note: Currently the code assumes the command termination is a
|
||||
* single character.
|
||||
|
@ -71,7 +72,7 @@ th_decode_event (RIG *rig)
|
|||
int mode;
|
||||
int step, shift, rev, tone, ctcss, tonefq, ctcssfq;
|
||||
|
||||
retval = sscanf(asyncbuf, "BUF %d,%"SCNfreq",%X,%d,%d,%d,%d,,%d,,%d,%"SCNfreq",%d",
|
||||
retval = num_sscanf(asyncbuf, "BUF %d,%"SCNfreq",%X,%d,%d,%d,%d,,%d,,%d,%"SCNfreq",%d",
|
||||
&vfo, &freq, &step, &shift, &rev, &tone,
|
||||
&ctcss, &tonefq, &ctcssfq, &offset, &mode);
|
||||
|
||||
|
@ -217,7 +218,7 @@ th_get_freq (RIG *rig, vfo_t vfo, freq_t *freq)
|
|||
if (retval != RIG_OK)
|
||||
return retval;
|
||||
|
||||
retval = sscanf(ackbuf, "FQ %"SCNfreq",%x",freq,&step);
|
||||
retval = num_sscanf(ackbuf, "FQ %"SCNfreq",%x",freq,&step);
|
||||
if (retval != 2) {
|
||||
rig_debug(RIG_DEBUG_ERR, "%s: Unexpected reply '%s'\n", __func__, freqbuf);
|
||||
return -RIG_ERJCTED;
|
||||
|
@ -1298,7 +1299,8 @@ int th_get_channel(RIG *rig, channel_t *chan)
|
|||
* Lockout is optional on some channels
|
||||
*/
|
||||
strcat(scf,",%"SCNfreq",%x,%d,%d,%d,%d,%d,%d,%d,%d,%"SCNfreq",%d,%d");
|
||||
retval = sscanf(ackbuf, scf,
|
||||
|
||||
retval = num_sscanf(ackbuf, scf,
|
||||
&freq, &step, &shift, &rev, &tone,
|
||||
&ctcss, &dcs, &tonefq, &ctcssfq, &dcscode,
|
||||
&offset, &mode, &lockout
|
||||
|
@ -1311,7 +1313,7 @@ int th_get_channel(RIG *rig, channel_t *chan)
|
|||
else
|
||||
{
|
||||
strcat(scf,",%"SCNfreq",%x,%d,%d,%d,%d,,%d,,%d,%"SCNfreq);
|
||||
retval = sscanf(ackbuf, scf,
|
||||
retval = num_sscanf(ackbuf, scf,
|
||||
&freq, &step, &shift, &rev, &tone,
|
||||
&ctcss, &tonefq, &ctcssfq, &offset);
|
||||
if (retval != 9) {
|
||||
|
@ -1389,7 +1391,7 @@ int th_get_channel(RIG *rig, channel_t *chan)
|
|||
if (retval == RIG_OK) {
|
||||
strcpy(scf,req);
|
||||
strcat(scf,",%"SCNfreq",%x");
|
||||
retval = sscanf(ackbuf, scf, &freq, &step);
|
||||
retval = num_sscanf(ackbuf, scf, &freq, &step);
|
||||
chan->tx_freq=freq;
|
||||
chan->split=RIG_SPLIT_ON;
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue