=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.135 retrieving revision 1.138 diff -u -p -r1.135 -r1.138 --- mandoc/roff.c 2011/04/17 09:08:19 1.135 +++ mandoc/roff.c 2011/05/14 16:06:08 1.138 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.135 2011/04/17 09:08:19 kristaps Exp $ */ +/* $Id: roff.c,v 1.138 2011/05/14 16:06:08 kristaps Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -20,12 +20,9 @@ #endif #include -#include #include -#include #include #include -#include #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) @@ -829,8 +804,7 @@ roff_block_sub(ROFF_ARGS) * pulling it out of the hashtable. */ - if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos))) - return(ROFF_IGN); + t = roff_parse(r, *bufp, &pos); /* * Macros other than block-end are only significant @@ -1091,6 +1065,7 @@ roff_nr(ROFF_ARGS) { const char *key; char *val; + int iv; struct reg *rg; val = *bufp + pos; @@ -1099,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); @@ -1238,7 +1215,7 @@ roff_userdef(ROFF_ARGS) cp = *bufp + pos; for (i = 0; i < 9; i++) arg[i] = '\0' == *cp ? "" : - mandoc_getarg(r->parse, &cp, ln, 1, &pos); + mandoc_getarg(r->parse, &cp, ln, &pos); /* * Expand macro arguments.