Use epicsScanFloat/epicsScanDouble rather than sscanf.

This allows proper handling of Nan/Inf on all architectures.
This commit is contained in:
W. Eric Norum
2004-10-12 17:45:31 +00:00
parent 25c797b212
commit 0dc034962c
18 changed files with 53 additions and 52 deletions

View File

@@ -9,7 +9,7 @@
\*************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include "caDiagnostics.h"
@@ -32,7 +32,7 @@ int main ( int argc, char **argv )
}
if ( argc >= 4 ) {
int nConverted = sscanf ( argv[3], "%lf", &delay );
int nConverted = epicsScanDouble( argv[3], &delay );
if ( nConverted != 1 ) {
printf ( "conversion failed, changing delay arg \"%s\" to %f\n",
argv[2], delay );

View File

@@ -17,7 +17,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include <string.h>
#include <alarm.h>
@@ -358,7 +358,7 @@ int main (int argc, char *argv[])
enumAsNr=1;
break;
case 'w': /* Set CA timeout value */
if(sscanf(optarg,"%lf", &caTimeout) != 1)
if(epicsScanDouble(optarg, &caTimeout) != 1)
{
fprintf(stderr, "'%s' is not a valid timeout value "
"- ignored. ('caget -h' for help.)\n", optarg);

View File

@@ -17,7 +17,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include <cadef.h>
#include <epicsGetopt.h>
@@ -136,7 +136,7 @@ int main (int argc, char *argv[])
usage();
return 0;
case 'w': /* Set CA timeout value */
if(sscanf(optarg,"%lf", &caTimeout) != 1)
if(epicsScanDouble(optarg, &caTimeout) != 1)
{
fprintf(stderr, "'%s' is not a valid timeout value "
"- ignored. ('caget -h' for help.)\n", optarg);

View File

@@ -17,7 +17,7 @@
*/
#include <stdio.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include <string.h>
#include <cadef.h>
@@ -205,7 +205,7 @@ int main (int argc, char *argv[])
tsType = incrementalByChan;
break;
case 'w': /* Set CA timeout value */
if(sscanf(optarg,"%lf", &caTimeout) != 1)
if(epicsScanDouble(optarg, &caTimeout) != 1)
{
fprintf(stderr, "'%s' is not a valid timeout value "
"- ignored. ('caget -h' for help.)\n", optarg);

View File

@@ -230,7 +230,7 @@ int main (int argc, char *argv[])
isArray = 1;
break;
case 'w': /* Set CA timeout value */
if(sscanf(optarg,"%lf", &caTimeout) != 1)
if(epicsScanDouble(optarg, &caTimeout) != 1)
{
fprintf(stderr, "'%s' is not a valid timeout value "
"- ignored. ('caput -h' for help.)\n", optarg);

View File

@@ -15,7 +15,7 @@
*/
#include <stddef.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <string.h>
@@ -266,7 +266,7 @@ static long getStringUlong(
/*Convert to double first so that numbers like 1.0e3 convert properly*/
/*Problem was old database access said to get unsigned long as double*/
if(nRequest==1 && offset==0) {
if(sscanf(psrc,"%lf",&value) == 1) {
if(epicsScanDouble(psrc, &value) == 1) {
*pbuffer = (epicsUInt32)value;
return(0);
} else if(strlen(psrc) == 0) {
@@ -278,7 +278,7 @@ static long getStringUlong(
}
psrc += MAX_STRING_SIZE*offset;
while (nRequest) {
if(sscanf(psrc,"%lf",&value) == 1) {
if(epicsScanDouble(psrc, &value) == 1) {
*pbuffer = (epicsUInt32)value;
} else if(strlen(psrc) == 0) {
*pbuffer = 0;
@@ -303,7 +303,7 @@ static long getStringFloat(
float value;
if(nRequest==1 && offset==0) {
if(sscanf(psrc,"%f",&value) == 1) {
if(epicsScanFloat(psrc, &value) == 1) {
*pbuffer = value;
return(0);
} else if(strlen(psrc) == 0) {
@@ -315,7 +315,7 @@ static long getStringFloat(
}
psrc += MAX_STRING_SIZE*offset;
while (nRequest) {
if(sscanf(psrc,"%f",&value) == 1) {
if(epicsScanFloat(psrc, &value) == 1) {
*pbuffer = value;
} else if(strlen(psrc) == 0) {
*pbuffer = 0.0;
@@ -340,7 +340,7 @@ static long getStringDouble(
double value;
if(nRequest==1 && offset==0) {
if(sscanf(psrc,"%lf",&value) == 1) {
if(epicsScanDouble(psrc, &value) == 1) {
*pbuffer = value;
return(0);
} else if(strlen(psrc) == 0) {
@@ -352,7 +352,7 @@ static long getStringDouble(
}
psrc += MAX_STRING_SIZE*offset;
while (nRequest) {
if(sscanf(psrc,"%lf",&value) == 1) {
if(epicsScanDouble(psrc, &value) == 1) {
*pbuffer = value;
} else if(strlen(psrc) == 0) {
*pbuffer = 0.0;
@@ -2368,7 +2368,7 @@ static long putStringUlong(
/*Convert to double first so that numbers like 1.0e3 convert properly*/
/*Problem was old database access said to get unsigned long as double*/
if(nRequest==1 && offset==0) {
if(sscanf(pbuffer,"%lf",&value) == 1) {
if(epicsScanDouble(pbuffer, &value) == 1) {
*pdest = (unsigned long)value;
return(0);
}
@@ -2376,7 +2376,7 @@ static long putStringUlong(
}
pdest += offset;
while (nRequest) {
if(sscanf(pbuffer,"%lf",&value) == 1) {
if(epicsScanDouble(pbuffer, &value) == 1) {
*pdest = (unsigned long)value;
} else {
return(-1);
@@ -2399,7 +2399,7 @@ static long putStringFloat(
float value;
if(nRequest==1 && offset==0) {
if(sscanf(pbuffer,"%f",&value) == 1) {
if(epicsScanFloat(pbuffer, &value) == 1) {
*pdest = value;
return(0);
} else {
@@ -2408,7 +2408,7 @@ static long putStringFloat(
}
pdest += offset;
while (nRequest) {
if(sscanf(pbuffer,"%f",&value) == 1) {
if(epicsScanFloat(pbuffer, &value) == 1) {
*pdest = value;
} else {
return(-1);
@@ -2431,7 +2431,7 @@ static long putStringDouble(
double value;
if(nRequest==1 && offset==0) {
if(sscanf(pbuffer,"%lf",&value) == 1) {
if(epicsScanDouble(pbuffer, &value) == 1) {
*pdest = value;
return(0);
} else {
@@ -2440,7 +2440,7 @@ static long putStringDouble(
}
pdest += offset;
while (nRequest) {
if(sscanf(pbuffer,"%lf",&value) == 1) {
if(epicsScanDouble(pbuffer, &value) == 1) {
*pdest = value;
} else {
return(-1);

View File

@@ -14,7 +14,7 @@
* Date: 12-9-93
*/
#include <stddef.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
@@ -196,7 +196,7 @@ static long cvt_st_ul(
/*Convert to double first so that numbers like 1.0e3 convert properly*/
/*Problem was old database access said to get unsigned long as double*/
if (sscanf(from, "%lf", &value) == 1) {
if (epicsScanDouble(from, &value) == 1) {
*to = (epicsUInt32)value;
return(0);
}
@@ -216,7 +216,7 @@ static long cvt_st_f(
{
float value;
if (sscanf(from, "%f", &value) == 1) {
if (epicsScanFloat(from, &value) == 1) {
*to = value;
return(0);
}
@@ -236,7 +236,7 @@ static long cvt_st_d(
{
double value;
if (sscanf(from, "%lf", &value) == 1) {
if (epicsScanDouble(from, &value) == 1) {
*to = value;
return(0);
}

View File

@@ -15,7 +15,7 @@
* Date: 07/18/91
*/
#include <stdlib.h>
#include <epicsStdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
@@ -515,7 +515,7 @@ static void initPeriodic()
papPeriodic[i] = psl;
psl->lock = epicsMutexMustCreate();
ellInit(&psl->list);
sscanf(pmenu->papChoiceValue[i+SCAN_1ST_PERIODIC],"%lf",&temp);
epicsScanDouble(pmenu->papChoiceValue[i+SCAN_1ST_PERIODIC], &temp);
psl->period = temp;
}
}

View File

@@ -11,7 +11,7 @@
/* base/src/db $Id$ */
/* database access test subroutines */
#include <stdlib.h>
#include <epicsStdlib.h>
#include <stddef.h>
#include <string.h>
#include <stdio.h>
@@ -577,7 +577,7 @@ long epicsShareAPI dbtpf(const char *pname,const char *pvalue)
}
} else printf("sscanf failed for DBR_ULONG\n");
/* DBR_FLOAT */
if(validNumber && sscanf(pvalue,"%e",&fvalue)==1) {
if(validNumber && epicsScanFloat(pvalue, &fvalue)==1) {
status=dbPutField(&addr,DBR_FLOAT,&fvalue,1L);
if(status!=0) errMessage(status,"DBR_FLOAT failed");
else {
@@ -590,7 +590,7 @@ long epicsShareAPI dbtpf(const char *pname,const char *pvalue)
}
} else printf("sscanf failed for DBR_FLOAT\n");
/* DBR_DOUBLE */
if(validNumber && sscanf(pvalue,"%le",&dvalue)==1) {
if(validNumber && epicsScanDouble(pvalue, &dvalue)==1) {
status=dbPutField(&addr,DBR_DOUBLE,&dvalue,1L);
if(status!=0) errMessage(status,"DBR_DOUBLE failed");
else {

View File

@@ -14,7 +14,7 @@
* Date: 4/15/88
*/
#include <stddef.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include <stdio.h>
#include <string.h>
@@ -130,14 +130,14 @@ int epicsShareAPI pft(char *pname,char *pvalue)
printf("\n\t LONG GET failed");
else ca_dump_dbr(DBR_LONG,1,buffer);
}
if(sscanf(pvalue,"%f",&floatvalue)==1) {
if(epicsScanFloat(pvalue, &floatvalue)==1) {
if (db_put_field(paddr,DBR_FLOAT,&floatvalue,1) < 0)
printf("\n\t FLOAT failed ");
if (db_get_field(paddr,DBR_FLOAT,buffer,1,NULL) < 0)
printf("\n\t FLOAT GET failed");
else ca_dump_dbr(DBR_FLOAT,1,buffer);
}
if(sscanf(pvalue,"%f",&floatvalue)==1) {
if(epicsScanFloat(pvalue, &floatvalue)==1) {
doublevalue=floatvalue;
if (db_put_field(paddr,DBR_DOUBLE,&doublevalue,1) < 0)
printf("\n\t DOUBLE failed ");

View File

@@ -16,7 +16,7 @@
*/
#include <stddef.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include <stdio.h>
#include <string.h>
#include <limits.h>
@@ -228,10 +228,10 @@ int epicsShareAPI recGblInitConstantLink(
sscanf(plink->value.constantStr,"%lu",(unsigned long *)pdest);
break;
case DBF_FLOAT :
sscanf(plink->value.constantStr,"%f",(float *)pdest);
epicsScanFloat(plink->value.constantStr, (float *)pdest);
break;
case DBF_DOUBLE :
sscanf(plink->value.constantStr,"%lf",(double *)pdest);
epicsScanDouble(plink->value.constantStr, (double *)pdest);
break;
default:
epicsPrintf("Error in recGblInitConstantLink: Illegal DBF type\n");

View File

@@ -12,7 +12,7 @@
/*The routines in this module are serially reusable NOT reentrant*/
#include <stdlib.h>
#include <epicsStdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
@@ -847,7 +847,7 @@ static void dbBreakBody(void)
praw = (char *)popFirstTemp();
peng = (char *)popFirstTemp();
if((sscanf(praw,"%lf",&raw)!=1) || (sscanf(peng,"%lf",&eng)!=1) ) {
if((epicsScanDouble(praw, &raw)!=1) || (sscanf(peng,"%lf",&eng)!=1) ) {
yyerrorAbort("dbbrkTable: Illegal table value");
}
free((void *)praw);

View File

@@ -1,4 +1,4 @@
/*************************************************************************\
epicsS*************************************************************************\
* Copyright (c) 2002 The University of Chicago, as Operator of Argonne
* National Laboratory.
* Copyright (c) 2002 The Regents of the University of California, as
@@ -16,7 +16,7 @@
#define AIT_CONVERT_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include <limits.h>
#include "epicsStdio.h"
#define epicsExportSharedSymbols
@@ -52,7 +52,7 @@ bool getStringAsDouble ( const char * pString,
ftmp = itmp;
}
else {
int j = sscanf ( pString,"%lf", &ftmp );
int j = epicsScanDouble( pString, &ftmp );
if ( j != 1 ) {
j = sscanf ( pString,"%x", &itmp );
if ( j == 1 ) {

View File

@@ -55,7 +55,7 @@
* FLASE expression element not found
*/
#include <stdlib.h>
#include <epicsStdlib.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
@@ -347,7 +347,7 @@ long epicsShareAPI postfix(const char *pin,char *ppostfix,short *perror)
*ppostfix++ = '\0';
ppostfix = pposthold;
if ( sscanf(ppostfix,"%lg",&constant) != 1) {
if ( epicsScanDouble(ppostfix, &constant) != 1) {
*ppostfix = '\0';
} else {
memcpy(ppostfix,(void *)&constant,8);

View File

@@ -37,7 +37,7 @@
*-***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <epicsStdlib.h>
#include <string.h>
#include <limits.h>
@@ -198,7 +198,7 @@ double *pDouble /* O pointer to place to store value */
ptext = envGetConfigParam(pParam, sizeof text, text);
if (ptext != NULL) {
count = sscanf(text, "%lf", pDouble);
count = epicsScanDouble(text, pDouble);
if (count == 1) {
return 0;
}

View File

@@ -16,7 +16,7 @@
#include "epicsStdio.h"
epicsShareFunc int epicsShareAPI epicsStrScanDouble(const char *str, double *dest)
epicsShareFunc int epicsShareAPI epicsScanDouble(const char *str, double *dest)
{
char *endp;
double dtmp;
@@ -28,7 +28,7 @@ epicsShareFunc int epicsShareAPI epicsStrScanDouble(const char *str, double *des
return 1;
}
epicsShareFunc int epicsShareAPI epicsStrScanFloat(const char *str, float *dest)
epicsShareFunc int epicsShareAPI epicsScanFloat(const char *str, float *dest)
{
char *endp;
double dtmp;

View File

@@ -16,8 +16,8 @@
extern "C" {
#endif
epicsShareFunc int epicsShareAPI epicsStrScanDouble(const char *str, double *dest);
epicsShareFunc int epicsShareAPI epicsStrScanFloat(const char *str, float *dest);
epicsShareFunc int epicsShareAPI epicsScanDouble(const char *str, double *dest);
epicsShareFunc int epicsShareAPI epicsScanFloat(const char *str, float *dest);
#include <stdlib.h>
#include <osdStrtod.h>

View File

@@ -20,6 +20,7 @@
*/
#include <string.h>
#include <stdio.h>
#include <epicsStdlib.h>
#ifndef LOCAL
#define LOCAL static
@@ -258,7 +259,7 @@ char *pvalue
SEVCHK(status, NULL);
verify_value(chan_id, DBR_LONG);
}
if(sscanf(pvalue,"%f",&floatvalue)==1) {
if(epicsScanFloat(pvalue, &floatvalue)==1) {
/*
* single precision float ca_put
*/
@@ -269,7 +270,7 @@ char *pvalue
SEVCHK(status, NULL);
verify_value(chan_id, DBR_FLOAT);
}
if(sscanf(pvalue,"%lf",&doublevalue)==1) {
if(epicsScanDouble(pvalue, &doublevalue)==1) {
/*
* double precision float ca_put
*/