summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--html.c5
-rw-r--r--man_html.c6
-rw-r--r--man_term.c12
-rw-r--r--mdoc_man.c22
-rw-r--r--mdoc_term.c4
-rw-r--r--out.c13
-rw-r--r--out.h3
-rw-r--r--roff_html.c2
-rw-r--r--roff_term.c4
-rw-r--r--term.c17
-rw-r--r--term_tab.c2
11 files changed, 44 insertions, 46 deletions
diff --git a/html.c b/html.c
index 3bb19cf5..2ff1d84c 100644
--- a/html.c
+++ b/html.c
@@ -950,7 +950,10 @@ print_word(struct html *h, const char *cp)
static void
a2width(const char *p, struct roffsu *su)
{
- if (a2roffsu(p, su, SCALE_MAX) < 2) {
+ const char *end;
+
+ end = a2roffsu(p, su, SCALE_MAX);
+ if (end == NULL || *end != '\0') {
su->unit = SCALE_EN;
su->scale = html_strlen(p);
} else if (su->scale < 0.0)
diff --git a/man_html.c b/man_html.c
index 05f3843b..030558d7 100644
--- a/man_html.c
+++ b/man_html.c
@@ -358,13 +358,9 @@ fillmode(struct html *h, int want)
static int
a2width(const struct roff_node *n, struct roffsu *su)
{
-
if (n->type != ROFFT_TEXT)
return 0;
- if (a2roffsu(n->string, su, SCALE_EN))
- return 1;
-
- return 0;
+ return a2roffsu(n->string, su, SCALE_EN) != NULL;
}
static void
diff --git a/man_term.c b/man_term.c
index 749f342b..763a3949 100644
--- a/man_term.c
+++ b/man_term.c
@@ -260,7 +260,7 @@ pre_PD(DECL_ARGS)
return 0;
}
assert(n->type == ROFFT_TEXT);
- if (a2roffsu(n->string, &su, SCALE_VS))
+ if (a2roffsu(n->string, &su, SCALE_VS) != NULL)
mt->pardist = term_vspan(p, &su);
return 0;
}
@@ -374,7 +374,7 @@ pre_in(DECL_ARGS)
else
cp--;
- if ( ! a2roffsu(++cp, &su, SCALE_EN))
+ if (a2roffsu(++cp, &su, SCALE_EN) == NULL)
return 0;
v = (term_hspan(p, &su) + 11) / 24;
@@ -425,7 +425,7 @@ pre_HP(DECL_ARGS)
/* Calculate offset. */
if ((nn = n->parent->head->child) != NULL &&
- a2roffsu(nn->string, &su, SCALE_EN)) {
+ a2roffsu(nn->string, &su, SCALE_EN) != NULL) {
len = term_hspan(p, &su) / 24;
if (len < 0 && (size_t)(-len) > mt->offset)
len = -mt->offset;
@@ -510,7 +510,7 @@ pre_IP(DECL_ARGS)
/* Calculate the offset from the optional second argument. */
if ((nn = n->parent->head->child) != NULL &&
(nn = nn->next) != NULL &&
- a2roffsu(nn->string, &su, SCALE_EN)) {
+ a2roffsu(nn->string, &su, SCALE_EN) != NULL) {
len = term_hspan(p, &su) / 24;
if (len < 0 && (size_t)(-len) > mt->offset)
len = -mt->offset;
@@ -592,7 +592,7 @@ pre_TP(DECL_ARGS)
if ((nn = n->parent->head->child) != NULL &&
nn->string != NULL && ! (NODE_LINE & nn->flags) &&
- a2roffsu(nn->string, &su, SCALE_EN)) {
+ a2roffsu(nn->string, &su, SCALE_EN) != NULL) {
len = term_hspan(p, &su) / 24;
if (len < 0 && (size_t)(-len) > mt->offset)
len = -mt->offset;
@@ -796,7 +796,7 @@ pre_RS(DECL_ARGS)
n->aux = SHRT_MAX + 1;
if (n->child == NULL)
n->aux = mt->lmargin[mt->lmargincur];
- else if (a2roffsu(n->child->string, &su, SCALE_EN))
+ else if (a2roffsu(n->child->string, &su, SCALE_EN) != NULL)
n->aux = term_hspan(p, &su) / 24;
if (n->aux < 0 && (size_t)(-n->aux) > mt->offset)
n->aux = -mt->offset;
diff --git a/mdoc_man.c b/mdoc_man.c
index 5ce6da22..2929ee7b 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -476,6 +476,7 @@ print_offs(const char *v, int keywords)
{
char buf[24];
struct roffsu su;
+ const char *end;
int sz;
print_line(".RS", MMAN_Bk_susp);
@@ -487,8 +488,11 @@ print_offs(const char *v, int keywords)
sz = 6;
else if (keywords && !strcmp(v, "indent-two"))
sz = 12;
- else if (a2roffsu(v, &su, SCALE_EN) > 1) {
- if (SCALE_EN == su.unit)
+ else {
+ end = a2roffsu(v, &su, SCALE_EN);
+ if (end == NULL || *end != '\0')
+ sz = man_strlen(v);
+ else if (SCALE_EN == su.unit)
sz = su.scale;
else {
/*
@@ -502,8 +506,7 @@ print_offs(const char *v, int keywords)
outflags |= MMAN_nl;
return;
}
- } else
- sz = man_strlen(v);
+ }
/*
* We are inside an enclosing list.
@@ -525,6 +528,7 @@ print_width(const struct mdoc_bl *bl, const struct roff_node *child)
{
char buf[24];
struct roffsu su;
+ const char *end;
int numeric, remain, sz, chsz;
numeric = 1;
@@ -533,15 +537,17 @@ print_width(const struct mdoc_bl *bl, const struct roff_node *child)
/* Convert the width into a number (of characters). */
if (bl->width == NULL)
sz = (bl->type == LIST_hang) ? 6 : 0;
- else if (a2roffsu(bl->width, &su, SCALE_MAX) > 1) {
- if (SCALE_EN == su.unit)
+ else {
+ end = a2roffsu(bl->width, &su, SCALE_MAX);
+ if (end == NULL || *end != '\0')
+ sz = man_strlen(bl->width);
+ else if (SCALE_EN == su.unit)
sz = su.scale;
else {
sz = 0;
numeric = 0;
}
- } else
- sz = man_strlen(bl->width);
+ }
/* XXX Rough estimation, might have multiple parts. */
if (bl->type == LIST_enum)
diff --git a/mdoc_term.c b/mdoc_term.c
index fd7dd53a..9058f055 100644
--- a/mdoc_term.c
+++ b/mdoc_term.c
@@ -533,8 +533,10 @@ static int
a2width(const struct termp *p, const char *v)
{
struct roffsu su;
+ const char *end;
- if (a2roffsu(v, &su, SCALE_MAX) < 2) {
+ end = a2roffsu(v, &su, SCALE_MAX);
+ if (end == NULL || *end != '\0') {
SCALE_HS_INIT(&su, term_strlen(p, v));
su.scale /= term_strlen(p, "0");
}
diff --git a/out.c b/out.c
index 890ccf44..8b912c98 100644
--- a/out.c
+++ b/out.c
@@ -40,10 +40,10 @@ static void tblcalc_number(struct rofftbl *, struct roffcol *,
* Parse the *src string and store a scaling unit into *dst.
* If the string doesn't specify the unit, use the default.
* If no default is specified, fail.
- * Return 2 on complete success, 1 when a conversion was done,
- * but there was trailing garbage, and 0 on total failure.
+ * Return a pointer to the byte after the last byte used,
+ * or NULL on total failure.
*/
-int
+const char *
a2roffsu(const char *src, struct roffsu *dst, enum roffscale def)
{
char *endptr;
@@ -51,7 +51,7 @@ a2roffsu(const char *src, struct roffsu *dst, enum roffscale def)
dst->unit = def == SCALE_MAX ? SCALE_BU : def;
dst->scale = strtod(src, &endptr);
if (endptr == src)
- return 0;
+ return NULL;
switch (*endptr++) {
case 'c':
@@ -89,12 +89,11 @@ a2roffsu(const char *src, struct roffsu *dst, enum roffscale def)
/* FALLTHROUGH */
default:
if (SCALE_MAX == def)
- return 0;
+ return NULL;
dst->unit = def;
break;
}
-
- return *endptr == '\0' ? 2 : 1;
+ return endptr;
}
/*
diff --git a/out.h b/out.h
index 0bee63a7..f7aeea38 100644
--- a/out.h
+++ b/out.h
@@ -1,6 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2014, 2017 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
@@ -63,6 +64,6 @@ struct rofftbl {
struct tbl_span;
-int a2roffsu(const char *, struct roffsu *, enum roffscale);
+const char *a2roffsu(const char *, struct roffsu *, enum roffscale);
void tblcalc(struct rofftbl *tbl,
const struct tbl_span *, size_t);
diff --git a/roff_html.c b/roff_html.c
index 672a7444..30c49db3 100644
--- a/roff_html.c
+++ b/roff_html.c
@@ -83,7 +83,7 @@ roff_html_pre_sp(ROFF_HTML_ARGS)
SCALE_VS_INIT(&su, 1);
if ((n = n->child) != NULL) {
- if (a2roffsu(n->string, &su, SCALE_VS) == 0)
+ if (a2roffsu(n->string, &su, SCALE_VS) == NULL)
su.scale = 1.0;
else if (su.scale < 0.0)
su.scale = 0.0;
diff --git a/roff_term.c b/roff_term.c
index 17c1f043..d2375c3c 100644
--- a/roff_term.c
+++ b/roff_term.c
@@ -157,7 +157,7 @@ roff_term_pre_sp(ROFF_TERM_ARGS)
int len;
if (n->child != NULL) {
- if (a2roffsu(n->child->string, &su, SCALE_VS) == 0)
+ if (a2roffsu(n->child->string, &su, SCALE_VS) == NULL)
su.scale = 1.0;
len = term_vspan(p, &su);
} else
@@ -201,7 +201,7 @@ roff_term_pre_ti(ROFF_TERM_ARGS)
} else
sign = 0;
- if (a2roffsu(cp, &su, SCALE_EM) == 0)
+ if (a2roffsu(cp, &su, SCALE_EM) == NULL)
return;
len = term_hspan(p, &su) / 24;
diff --git a/term.c b/term.c
index ebc1e4ef..2e917c8f 100644
--- a/term.c
+++ b/term.c
@@ -479,7 +479,7 @@ term_word(struct termp *p, const char *word)
p->flags |= (TERMP_NOSPACE | TERMP_NONEWLINE);
continue;
case ESCAPE_HORIZ:
- if (a2roffsu(seq, &su, SCALE_EM) == 0)
+ if (a2roffsu(seq, &su, SCALE_EM) == NULL)
continue;
uc = term_hspan(p, &su) / 24;
if (uc > 0)
@@ -500,7 +500,7 @@ term_word(struct termp *p, const char *word)
}
continue;
case ESCAPE_HLINE:
- if (a2roffsu(seq, &su, SCALE_EM) == 0)
+ if ((seq = a2roffsu(seq, &su, SCALE_EM)) == NULL)
continue;
uc = term_hspan(p, &su) / 24;
if (uc <= 0) {
@@ -509,16 +509,7 @@ term_word(struct termp *p, const char *word)
lsz = p->tcol->rmargin - p->tcol->offset;
} else
lsz = uc;
- while (sz &&
- strchr(" %&()*+-./0123456789:<=>", *seq)) {
- seq++;
- sz--;
- }
- if (sz && strchr("cifMmnPpuv", *seq)) {
- seq++;
- sz--;
- }
- if (sz == 0)
+ if (*seq == '\0')
uc = -1;
else if (*seq == '\\') {
seq++;
@@ -739,7 +730,7 @@ term_setwidth(struct termp *p, const char *wstr)
default:
break;
}
- if (a2roffsu(wstr, &su, SCALE_MAX))
+ if (a2roffsu(wstr, &su, SCALE_MAX) != NULL)
width = term_hspan(p, &su);
else
iop = 0;
diff --git a/term_tab.c b/term_tab.c
index 3e6fa5c1..88c47c18 100644
--- a/term_tab.c
+++ b/term_tab.c
@@ -68,7 +68,7 @@ term_tab_set(const struct termp *p, const char *arg)
arg++;
} else
add = 0;
- if (a2roffsu(arg, &su, SCALE_EM) == 0)
+ if (a2roffsu(arg, &su, SCALE_EM) == NULL)
return;
/* Select the list, and extend it if it is full. */