-/* $OpenBSD: html.c,v 1.82 2017/05/14 12:26:59 schwarze Exp $ */
+/* $OpenBSD: html.c,v 1.83 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
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)
-/* $OpenBSD: man_html.c,v 1.95 2017/05/09 14:09:37 schwarze Exp $ */
+/* $OpenBSD: man_html.c,v 1.96 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
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
-/* $OpenBSD: man_term.c,v 1.156 2017/06/07 17:38:08 schwarze Exp $ */
+/* $OpenBSD: man_term.c,v 1.157 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
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;
}
else
cp--;
- if ( ! a2roffsu(++cp, &su, SCALE_EN))
+ if (a2roffsu(++cp, &su, SCALE_EN) == NULL)
return 0;
v = (term_hspan(p, &su) + 11) / 24;
/* 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;
/* 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;
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;
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;
-/* $OpenBSD: mdoc_man.c,v 1.116 2017/06/06 15:00:56 schwarze Exp $ */
+/* $OpenBSD: mdoc_man.c,v 1.117 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>
*
{
char buf[24];
struct roffsu su;
+ const char *end;
int sz;
print_line(".RS", MMAN_Bk_susp);
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 {
/*
outflags |= MMAN_nl;
return;
}
- } else
- sz = man_strlen(v);
+ }
/*
* We are inside an enclosing list.
{
char buf[24];
struct roffsu su;
+ const char *end;
int numeric, remain, sz, chsz;
numeric = 1;
/* 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)
-/* $OpenBSD: mdoc_term.c,v 1.261 2017/06/07 17:38:08 schwarze Exp $ */
+/* $OpenBSD: mdoc_term.c,v 1.262 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2017 Ingo Schwarze <schwarze@openbsd.org>
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");
}
-/* $OpenBSD: out.c,v 1.35 2017/05/01 20:53:58 schwarze Exp $ */
+/* $OpenBSD: out.c,v 1.36 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
* 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;
dst->unit = def == SCALE_MAX ? SCALE_BU : def;
dst->scale = strtod(src, &endptr);
if (endptr == src)
- return 0;
+ return NULL;
switch (*endptr++) {
case 'c':
/* FALLTHROUGH */
default:
if (SCALE_MAX == def)
- return 0;
+ return NULL;
dst->unit = def;
break;
}
-
- return *endptr == '\0' ? 2 : 1;
+ return endptr;
}
/*
-/* $OpenBSD: out.h,v 1.18 2015/11/07 13:57:55 schwarze Exp $ */
+/* $OpenBSD: out.h,v 1.19 2017/06/08 12:54:40 schwarze Exp $ */
/*
* 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
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);
-/* $OpenBSD: roff_html.c,v 1.7 2017/06/06 15:00:56 schwarze Exp $ */
+/* $OpenBSD: roff_html.c,v 1.8 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2017 Ingo Schwarze <schwarze@openbsd.org>
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;
-/* $OpenBSD: roff_term.c,v 1.9 2017/06/07 17:38:08 schwarze Exp $ */
+/* $OpenBSD: roff_term.c,v 1.10 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2010, 2014, 2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
*
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
} else
sign = 0;
- if (a2roffsu(cp, &su, SCALE_EM) == 0)
+ if (a2roffsu(cp, &su, SCALE_EM) == NULL)
return;
len = term_hspan(p, &su) / 24;
-/* $OpenBSD: term.c,v 1.127 2017/06/07 20:01:07 schwarze Exp $ */
+/* $OpenBSD: term.c,v 1.128 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
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)
}
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) {
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++;
default:
break;
}
- if (a2roffsu(wstr, &su, SCALE_MAX))
+ if (a2roffsu(wstr, &su, SCALE_MAX) != NULL)
width = term_hspan(p, &su);
else
iop = 0;
-/* $OpenBSD: term_tab.c,v 1.1 2017/05/07 17:30:58 schwarze Exp $ */
+/* $OpenBSD: term_tab.c,v 1.2 2017/06/08 12:54:40 schwarze Exp $ */
/*
* Copyright (c) 2017 Ingo Schwarze <schwarze@openbsd.org>
*
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. */