Commit 9bb8f962 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Use VNUM() rather than strtod()

parent 4f20b3dc
......@@ -50,6 +50,7 @@
#endif
#include <errno.h>
#include <math.h>
#include <fcntl.h>
#include <poll.h>
#include <stdint.h>
......@@ -61,6 +62,7 @@
#include "vapi/vsm.h"
#include "vas.h"
#include "vcli.h"
#include "vnum.h"
#include "vss.h"
#define RL_EXIT(status) \
......@@ -464,7 +466,9 @@ main(int argc, char * const *argv)
T_arg = optarg;
break;
case 't':
timeout = strtod(optarg, NULL);
timeout = VNUM(optarg);
if (isnan(timeout))
usage();
break;
default:
usage();
......
......@@ -58,6 +58,7 @@
#include "vapi/voptget.h"
#include "vas.h"
#include "vcs.h"
#include "vnum.h"
#include "vsb.h"
#include "vut.h"
#include "vqueue.h"
......@@ -283,16 +284,13 @@ static int __match_proto__(format_f)
format_time(const struct format *format)
{
double t_start, t_end;
char *p;
char buf[64];
time_t t;
struct tm tm;
CHECK_OBJ_NOTNULL(format, FORMAT_MAGIC);
if (CTX.frag[F_tstart].gen == CTX.gen) {
t_start = strtod(CTX.frag[F_tstart].b, &p);
if (p != CTX.frag[F_tstart].e)
t_start = NAN;
t_start = VNUM(CTX.frag[F_tstart].b);
} else
t_start = NAN;
if (isnan(t_start)) {
......@@ -305,8 +303,8 @@ format_time(const struct format *format)
/* Missing t_end defaults to t_start */
if (CTX.frag[F_tend].gen == CTX.gen) {
t_end = strtod(CTX.frag[F_tend].b, &p);
if (p != CTX.frag[F_tend].e)
t_end = VNUM(CTX.frag[F_tend].b);
if (isnan(t_end))
t_end = t_start;
} else
t_end = t_start;
......
......@@ -36,6 +36,7 @@
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
......@@ -49,6 +50,7 @@
#include "vapi/vsl.h"
#include "vapi/vsm.h"
#include "vbm.h"
#include "vnum.h"
#include "vre.h"
#include "vsl_api.h"
#include "vsm_api.h"
......@@ -343,13 +345,11 @@ VSL_Arg(struct VSL_data *vsl, int opt, const char *arg)
vsl->L_opt = (int)l;
return (1);
case 'T':
d = strtod(arg, &p);
while (isspace(*p))
p++;
if (*p != '\0')
return (vsl_diag(vsl, "-P: Syntax error"));
d = VNUM(arg);
if (!isnan(d))
return (vsl_diag(vsl, "-T: Syntax error"));
if (d < 0.)
return (vsl_diag(vsl, "-L: Range error"));
return (vsl_diag(vsl, "-T: Range error"));
vsl->T_opt = d;
return (1);
case 'v': vsl->v_opt = 1; return (1);
......
......@@ -29,17 +29,19 @@
*/
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <math.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <unistd.h>
#include "vas.h"
#include "miniobj.h"
#include "vas.h"
#include "vbm.h"
#include "vnum.h"
#include "vre.h"
#include "vsb.h"
#include "vbm.h"
#include "vapi/vsl.h"
#include "vsl_api.h"
......@@ -141,11 +143,10 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
/* Can't parse - no match */
return (0);
case VEX_FLOAT:
lhs_float = strtod(b, &p);
if (*p == '\0' || isspace(*p))
break;
/* Can't parse - no match */
return (0);
lhs_float = VNUM(b);
if (isnan(lhs_float))
return (0);
break;
default:
WRONG("Wrong RHS type");
}
......
......@@ -30,18 +30,19 @@
#include "config.h"
#include <ctype.h>
#include <errno.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <stdint.h>
#include <string.h>
#include <ctype.h>
#include <stdint.h>
#include "miniobj.h"
#include "vas.h"
#include "vsb.h"
#include "vbm.h"
#include "miniobj.h"
#include "vnum.h"
#include "vsb.h"
#include "vapi/vsl.h"
#include "vsl_api.h"
......@@ -191,10 +192,8 @@ vxp_expr_num(struct vxp *vxp, struct vex_rhs **prhs)
AN(*prhs);
if (strchr(vxp->t->dec, '.')) {
(*prhs)->type = VEX_FLOAT;
(*prhs)->val_float = strtod(vxp->t->dec, &endptr);
while (isspace(*endptr))
endptr++;
if (*endptr != '\0') {
(*prhs)->val_float = VNUM(vxp->t->dec);
if (isnan((*prhs)->val_float)) {
VSB_printf(vxp->sb, "Floating point parse error ");
vxp_ErrWhere(vxp, vxp->t, -1);
return;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment