aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/roff.c
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2011-05-14 16:06:08 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2011-05-14 16:06:08 +0000
commitbc80934db614d28c7b53a0b013dd68c4e6234c7e (patch)
treebcfd50f5fc85c0ca8c328e04521d96dcd6ff8e67 /roff.c
parentf9f5e761b11d13e40b541734e962b5931fa8f5d9 (diff)
downloadmandoc-bc80934db614d28c7b53a0b013dd68c4e6234c7e.tar.gz
mandoc-bc80934db614d28c7b53a0b013dd68c4e6234c7e.tar.zst
mandoc-bc80934db614d28c7b53a0b013dd68c4e6234c7e.zip
Move roff.c's strtol into libmandoc.h for use by other parts of the code
(which will come).
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c34
1 files changed, 6 insertions, 28 deletions
diff --git a/roff.c b/roff.c
index bb612385..e36138c8 100644
--- a/roff.c
+++ b/roff.c
@@ -1,4 +1,4 @@
-/* $Id: roff.c,v 1.137 2011/04/24 23:51:17 schwarze Exp $ */
+/* $Id: roff.c,v 1.138 2011/05/14 16:06:08 kristaps Exp $ */
/*
* Copyright (c) 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -20,12 +20,9 @@
#endif
#include <assert.h>
-#include <errno.h>
#include <ctype.h>
-#include <limits.h>
#include <stdlib.h>
#include <string.h>
-#include <stdio.h>
#include "mandoc.h"
#include "libroff.h"
@@ -206,7 +203,6 @@ static void roffnode_push(struct roff *, enum rofft,
const char *, int, int);
static void roffnode_pop(struct roff *);
static enum rofft roff_parse(struct roff *, const char *, int *);
-static int roff_parse_nat(const char *, unsigned int *);
/* See roff_hash_find() */
#define ROFF_HASH(p) (p[0] - ASCII_LO)
@@ -593,27 +589,6 @@ roff_parse(struct roff *r, const char *buf, int *pos)
return(t);
}
-
-static int
-roff_parse_nat(const char *buf, unsigned int *res)
-{
- char *ep;
- long lval;
-
- errno = 0;
- lval = strtol(buf, &ep, 10);
- if (buf[0] == '\0' || *ep != '\0')
- return(0);
- if ((errno == ERANGE &&
- (lval == LONG_MAX || lval == LONG_MIN)) ||
- (lval > INT_MAX || lval < 0))
- return(0);
-
- *res = (unsigned int)lval;
- return(1);
-}
-
-
/* ARGSUSED */
static enum rofferr
roff_cblock(ROFF_ARGS)
@@ -1090,6 +1065,7 @@ roff_nr(ROFF_ARGS)
{
const char *key;
char *val;
+ int iv;
struct reg *rg;
val = *bufp + pos;
@@ -1098,8 +1074,10 @@ roff_nr(ROFF_ARGS)
if (0 == strcmp(key, "nS")) {
rg[(int)REG_nS].set = 1;
- if ( ! roff_parse_nat(val, &rg[(int)REG_nS].v.u))
- rg[(int)REG_nS].v.u = 0;
+ if ((iv = mandoc_strntou(val, strlen(val), 10)) >= 0)
+ rg[REG_nS].v.u = (unsigned)iv;
+ else
+ rg[(int)REG_nS].v.u = 0u;
}
return(ROFF_IGN);