summaryrefslogtreecommitdiffstats
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2018-12-14 05:18:02 +0000
committerIngo Schwarze <schwarze@openbsd.org>2018-12-14 05:18:02 +0000
commite3863b1460cd9598ecb57705c9b22c2f2c552953 (patch)
treef839c62a271e1da0a9086b6adf22cb9ca99eb7e6 /roff.c
parent62de322fe3ae3638668739b266e3332e94b5acb3 (diff)
downloadmandoc-e3863b1460cd9598ecb57705c9b22c2f2c552953.tar.gz
Almost mechanical diff to remove the "struct mparse *" argument
from mandoc_msg(), where it is no longer used. While here, rename mandoc_vmsg() to mandoc_msg() and retire the old version: There is really no point in having another function merely to save "%s" in a few places. Minus 140 lines of code.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c167
1 files changed, 76 insertions, 91 deletions
diff --git a/roff.c b/roff.c
index 3b3a1996..c8bbde1a 100644
--- a/roff.c
+++ b/roff.c
@@ -1204,8 +1204,9 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
isalnum((unsigned char)*cp) == 0 &&
strchr(cp, '$') != NULL) {
if (r->man->meta.rcsids & rcsid)
- mandoc_msg(MANDOCERR_RCS_REP, r->parse,
- ln, stesc + 1 - buf->buf, stesc + 1);
+ mandoc_msg(MANDOCERR_RCS_REP, ln,
+ (int)(stesc - buf->buf) + 1,
+ "%s", stesc + 1);
r->man->meta.rcsids |= rcsid;
}
@@ -1217,8 +1218,8 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
ep--;
}
if (*ep == ' ' || *ep == '\t')
- mandoc_msg(MANDOCERR_SPACE_EOL, r->parse,
- ln, ep - buf->buf, NULL);
+ mandoc_msg(MANDOCERR_SPACE_EOL,
+ ln, (int)(ep - buf->buf), NULL);
/*
* Save comments preceding the title macro
@@ -1327,15 +1328,15 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
if (esc == ESCAPE_ERROR ||
(esc == ESCAPE_SPECIAL &&
mchars_spec2cp(stnam, inaml) < 0))
- mandoc_vmsg(MANDOCERR_ESC_BAD,
- r->parse, ln, (int)(stesc - buf->buf),
+ mandoc_msg(MANDOCERR_ESC_BAD,
+ ln, (int)(stesc - buf->buf),
"%.*s", (int)(cp - stesc), stesc);
stesc--;
continue;
}
if (EXPAND_LIMIT < ++expand_count) {
- mandoc_msg(MANDOCERR_ROFFLOOP, r->parse,
+ mandoc_msg(MANDOCERR_ROFFLOOP,
ln, (int)(stesc - buf->buf), NULL);
return ROFF_IGN;
}
@@ -1376,8 +1377,8 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
arg_complete = 1;
while (maxl == 0 || naml < maxl) {
if (*cp == '\0') {
- mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
- ln, (int)(stesc - buf->buf), stesc);
+ mandoc_msg(MANDOCERR_ESC_BAD, ln,
+ (int)(stesc - buf->buf), "%s", stesc);
arg_complete = 0;
break;
}
@@ -1428,9 +1429,8 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
break;
case '$':
if (r->mstackpos < 0) {
- mandoc_vmsg(MANDOCERR_ARG_UNDEF,
- r->parse, ln, (int)(stesc - buf->buf),
- "%.3s", stesc);
+ mandoc_msg(MANDOCERR_ARG_UNDEF, ln,
+ (int)(stesc - buf->buf), "%.3s", stesc);
break;
}
ctx = r->mstack + r->mstackpos;
@@ -1445,9 +1445,8 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
else if (stesc[2] == '@')
quote_args = 1;
else {
- mandoc_vmsg(MANDOCERR_ARG_NONUM,
- r->parse, ln, (int)(stesc - buf->buf),
- "%.3s", stesc);
+ mandoc_msg(MANDOCERR_ARG_NONUM, ln,
+ (int)(stesc - buf->buf), "%.3s", stesc);
break;
}
asz = 0;
@@ -1506,12 +1505,12 @@ roff_res(struct roff *r, struct buf *buf, int ln, int pos)
if (res == NULL) {
if (stesc[1] == '*')
- mandoc_vmsg(MANDOCERR_STR_UNDEF,
- r->parse, ln, (int)(stesc - buf->buf),
+ mandoc_msg(MANDOCERR_STR_UNDEF,
+ ln, (int)(stesc - buf->buf),
"%.*s", (int)naml, stnam);
res = "";
} else if (buf->sz + strlen(res) > SHRT_MAX) {
- mandoc_msg(MANDOCERR_ROFFLOOP, r->parse,
+ mandoc_msg(MANDOCERR_ROFFLOOP,
ln, (int)(stesc - buf->buf), NULL);
return ROFF_IGN;
}
@@ -1664,8 +1663,7 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
/* Skip empty request lines. */
if (buf->buf[pos] == '"') {
- mandoc_msg(MANDOCERR_COMMENT_BAD, r->parse,
- ln, pos, NULL);
+ mandoc_msg(MANDOCERR_COMMENT_BAD, ln, pos, NULL);
return ROFF_IGN;
} else if (buf->buf[pos] == '\0')
return ROFF_IGN;
@@ -1690,8 +1688,8 @@ roff_parseln(struct roff *r, int ln, struct buf *buf, int *offs)
if (r->tbl != NULL && (t == TOKEN_NONE || t == ROFF_TS ||
t == ROFF_br || t == ROFF_ce || t == ROFF_rj || t == ROFF_sp)) {
- mandoc_msg(MANDOCERR_TBLMACRO, r->parse,
- ln, pos, buf->buf + spos);
+ mandoc_msg(MANDOCERR_TBLMACRO,
+ ln, pos, "%s", buf->buf + spos);
if (t != TOKEN_NONE)
return ROFF_IGN;
while (buf->buf[pos] != '\0' && buf->buf[pos] != ' ')
@@ -1750,12 +1748,11 @@ void
roff_endparse(struct roff *r)
{
if (r->last != NULL)
- mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
- r->last->line, r->last->col,
- roff_name[r->last->tok]);
+ mandoc_msg(MANDOCERR_BLK_NOEND, r->last->line,
+ r->last->col, "%s", roff_name[r->last->tok]);
if (r->eqn != NULL) {
- mandoc_msg(MANDOCERR_BLK_NOEND, r->parse,
+ mandoc_msg(MANDOCERR_BLK_NOEND,
r->eqn->node->line, r->eqn->node->pos, "EQ");
eqn_parse(r->eqn);
r->eqn = NULL;
@@ -1823,8 +1820,7 @@ roff_cblock(ROFF_ARGS)
*/
if (r->last == NULL) {
- mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
- ln, ppos, "..");
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, ln, ppos, "..");
return ROFF_IGN;
}
@@ -1838,13 +1834,12 @@ roff_cblock(ROFF_ARGS)
case ROFF_ig:
break;
default:
- mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
- ln, ppos, "..");
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, ln, ppos, "..");
return ROFF_IGN;
}
if (buf->buf[pos] != '\0')
- mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
+ mandoc_msg(MANDOCERR_ARG_SKIP, ln, pos,
".. %s", buf->buf + pos);
roffnode_pop(r);
@@ -1871,8 +1866,7 @@ static int
roff_ccond(struct roff *r, int ln, int ppos)
{
if (NULL == r->last) {
- mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
- ln, ppos, "\\}");
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, ln, ppos, "\\}");
return 0;
}
@@ -1883,14 +1877,12 @@ roff_ccond(struct roff *r, int ln, int ppos)
case ROFF_while:
break;
default:
- mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
- ln, ppos, "\\}");
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, ln, ppos, "\\}");
return 0;
}
if (r->last->endspan > -1) {
- mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
- ln, ppos, "\\}");
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, ln, ppos, "\\}");
return 0;
}
@@ -1934,8 +1926,8 @@ roff_block(ROFF_ARGS)
deftype = ROFFDEF_USER;
name = roff_getstrn(r, iname, namesz, &deftype);
if (name == NULL) {
- mandoc_vmsg(MANDOCERR_STR_UNDEF,
- r->parse, ln, (int)(iname - buf->buf),
+ mandoc_msg(MANDOCERR_STR_UNDEF,
+ ln, (int)(iname - buf->buf),
"%.*s", (int)namesz, iname);
namesz = 0;
} else
@@ -1944,8 +1936,8 @@ roff_block(ROFF_ARGS)
name = iname;
if (namesz == 0 && tok != ROFF_ig) {
- mandoc_msg(MANDOCERR_REQ_EMPTY, r->parse,
- ln, ppos, roff_name[tok]);
+ mandoc_msg(MANDOCERR_REQ_EMPTY,
+ ln, ppos, "%s", roff_name[tok]);
return ROFF_IGN;
}
@@ -2003,8 +1995,8 @@ roff_block(ROFF_ARGS)
deftype = ROFFDEF_USER;
name = roff_getstrn(r, iname, namesz, &deftype);
if (name == NULL) {
- mandoc_vmsg(MANDOCERR_STR_UNDEF,
- r->parse, ln, (int)(iname - buf->buf),
+ mandoc_msg(MANDOCERR_STR_UNDEF,
+ ln, (int)(iname - buf->buf),
"%.*s", (int)namesz, iname);
namesz = 0;
} else
@@ -2016,7 +2008,7 @@ roff_block(ROFF_ARGS)
r->last->end = mandoc_strndup(name, namesz);
if (*cp != '\0')
- mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse,
+ mandoc_msg(MANDOCERR_ARG_EXCESS,
ln, pos, ".%s ... %s", roff_name[tok], cp);
return ROFF_IGN;
@@ -2417,8 +2409,7 @@ static int
roff_insec(ROFF_ARGS)
{
- mandoc_msg(MANDOCERR_REQ_INSEC, r->parse,
- ln, ppos, roff_name[tok]);
+ mandoc_msg(MANDOCERR_REQ_INSEC, ln, ppos, "%s", roff_name[tok]);
return ROFF_IGN;
}
@@ -2426,8 +2417,7 @@ static int
roff_unsupp(ROFF_ARGS)
{
- mandoc_msg(MANDOCERR_REQ_UNSUPP, r->parse,
- ln, ppos, roff_name[tok]);
+ mandoc_msg(MANDOCERR_REQ_UNSUPP, ln, ppos, "%s", roff_name[tok]);
return ROFF_IGN;
}
@@ -2501,8 +2491,8 @@ roff_cond(ROFF_ARGS)
*/
if (buf->buf[pos] == '\0')
- mandoc_msg(MANDOCERR_COND_EMPTY, r->parse,
- ln, ppos, roff_name[tok]);
+ mandoc_msg(MANDOCERR_COND_EMPTY,
+ ln, ppos, "%s", roff_name[tok]);
r->last->endspan = 1;
@@ -2705,7 +2695,7 @@ roff_evalnum(struct roff *r, int ln, const char *v,
case '/':
if (operand2 == 0) {
mandoc_msg(MANDOCERR_DIVZERO,
- r->parse, ln, *pos, v);
+ ln, *pos, "%s", v);
*res = 0;
break;
}
@@ -2714,7 +2704,7 @@ roff_evalnum(struct roff *r, int ln, const char *v,
case '%':
if (operand2 == 0) {
mandoc_msg(MANDOCERR_DIVZERO,
- r->parse, ln, *pos, v);
+ ln, *pos, "%s", v);
*res = 0;
break;
}
@@ -2994,8 +2984,8 @@ roff_it(ROFF_ARGS)
/* Parse the number of lines. */
if ( ! roff_evalnum(r, ln, buf->buf, &pos, &iv, 0)) {
- mandoc_msg(MANDOCERR_IT_NONUM, r->parse,
- ln, ppos, buf->buf + 1);
+ mandoc_msg(MANDOCERR_IT_NONUM,
+ ln, ppos, "%s", buf->buf + 1);
return ROFF_IGN;
}
@@ -3049,8 +3039,7 @@ static int
roff_TE(ROFF_ARGS)
{
if (r->tbl == NULL) {
- mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
- ln, ppos, "TE");
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, ln, ppos, "TE");
return ROFF_IGN;
}
if (tbl_end(r->tbl, 0) == 0) {
@@ -3070,8 +3059,7 @@ roff_T_(ROFF_ARGS)
{
if (NULL == r->tbl)
- mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse,
- ln, ppos, "T&");
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, ln, ppos, "T&");
else
tbl_restart(ln, ppos, r->tbl);
@@ -3167,7 +3155,7 @@ roff_EQ(ROFF_ARGS)
r->eqn->node = n;
if (buf->buf[pos] != '\0')
- mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
+ mandoc_msg(MANDOCERR_ARG_SKIP, ln, pos,
".EQ %s", buf->buf + pos);
return ROFF_IGN;
@@ -3180,9 +3168,9 @@ roff_EN(ROFF_ARGS)
eqn_parse(r->eqn);
r->eqn = NULL;
} else
- mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, ln, ppos, "EN");
+ mandoc_msg(MANDOCERR_BLK_NOTOPEN, ln, ppos, "EN");
if (buf->buf[pos] != '\0')
- mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
+ mandoc_msg(MANDOCERR_ARG_SKIP, ln, pos,
"EN %s", buf->buf + pos);
return ROFF_IGN;
}
@@ -3191,8 +3179,7 @@ static int
roff_TS(ROFF_ARGS)
{
if (r->tbl != NULL) {
- mandoc_msg(MANDOCERR_BLK_BROKEN, r->parse,
- ln, ppos, "TS breaks TS");
+ mandoc_msg(MANDOCERR_BLK_BROKEN, ln, ppos, "TS breaks TS");
tbl_end(r->tbl, 0);
}
r->tbl = tbl_alloc(ppos, ln, r->parse, r->last_tbl);
@@ -3229,8 +3216,8 @@ roff_onearg(ROFF_ARGS)
while (*cp == ' ')
*cp++ = '\0';
if (*cp != '\0')
- mandoc_vmsg(MANDOCERR_ARG_EXCESS,
- r->parse, ln, cp - buf->buf,
+ mandoc_msg(MANDOCERR_ARG_EXCESS,
+ ln, (int)(cp - buf->buf),
"%s ... %s", roff_name[tok], cp);
roff_word_alloc(r->man, ln, pos, buf->buf + pos);
}
@@ -3243,8 +3230,8 @@ roff_onearg(ROFF_ARGS)
npos = 0;
if (roff_evalnum(r, ln, r->man->last->string, &npos,
&roffce_lines, 0) == 0) {
- mandoc_vmsg(MANDOCERR_CE_NONUM,
- r->parse, ln, pos, "ce %s", buf->buf + pos);
+ mandoc_msg(MANDOCERR_CE_NONUM,
+ ln, pos, "ce %s", buf->buf + pos);
roffce_lines = 1;
}
if (roffce_lines < 1) {
@@ -3319,7 +3306,7 @@ roff_br(ROFF_ARGS)
man_breakscope(r->man, ROFF_br);
roff_elem_alloc(r->man, ln, ppos, ROFF_br);
if (buf->buf[pos] != '\0')
- mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos,
+ mandoc_msg(MANDOCERR_ARG_SKIP, ln, pos,
"%s %s", roff_name[tok], buf->buf + pos);
r->man->last->flags |= NODE_LINE | NODE_VALID | NODE_ENDED;
r->man->next = ROFF_NEXT_SIBLING;
@@ -3337,7 +3324,7 @@ roff_cc(ROFF_ARGS)
r->control = '\0';
if (*p != '\0')
- mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse,
+ mandoc_msg(MANDOCERR_ARG_EXCESS,
ln, p - buf->buf, "cc ... %s", p);
return ROFF_IGN;
@@ -3357,8 +3344,7 @@ roff_char(ROFF_ARGS)
if (*kp == '\0' || (*kp == '\\' &&
mandoc_escape(&p, NULL, NULL) != ESCAPE_SPECIAL) ||
(*p != ' ' && *p != '\0')) {
- mandoc_vmsg(MANDOCERR_CHAR_ARG, r->parse,
- ln, pos, "char %s", kp);
+ mandoc_msg(MANDOCERR_CHAR_ARG, ln, pos, "char %s", kp);
return ROFF_IGN;
}
ksz = p - kp;
@@ -3391,8 +3377,8 @@ roff_char(ROFF_ARGS)
}
}
if (font > 1)
- mandoc_msg(MANDOCERR_CHAR_FONT, r->parse,
- ln, vp - buf->buf, vp);
+ mandoc_msg(MANDOCERR_CHAR_FONT,
+ ln, (int)(vp - buf->buf), "%s", vp);
/*
* Approximate the effect of .char using the .tr tables.
@@ -3425,8 +3411,8 @@ roff_ec(ROFF_ARGS)
else {
r->escape = *p;
if (*++p != '\0')
- mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse,
- ln, p - buf->buf, "ec ... %s", p);
+ mandoc_msg(MANDOCERR_ARG_EXCESS, ln,
+ (int)(p - buf->buf), "ec ... %s", p);
}
return ROFF_IGN;
}
@@ -3436,7 +3422,7 @@ roff_eo(ROFF_ARGS)
{
r->escape = '\0';
if (buf->buf[pos] != '\0')
- mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse,
+ mandoc_msg(MANDOCERR_ARG_SKIP,
ln, pos, "eo %s", buf->buf + pos);
return ROFF_IGN;
}
@@ -3460,7 +3446,7 @@ roff_tr(ROFF_ARGS)
p = buf->buf + pos;
if (*p == '\0') {
- mandoc_msg(MANDOCERR_REQ_EMPTY, r->parse, ln, ppos, "tr");
+ mandoc_msg(MANDOCERR_REQ_EMPTY, ln, ppos, "tr");
return ROFF_IGN;
}
@@ -3471,8 +3457,8 @@ roff_tr(ROFF_ARGS)
if (*first == '\\') {
esc = mandoc_escape(&p, NULL, NULL);
if (esc == ESCAPE_ERROR) {
- mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
- ln, (int)(p - buf->buf), first);
+ mandoc_msg(MANDOCERR_ESC_BAD, ln,
+ (int)(p - buf->buf), "%s", first);
return ROFF_IGN;
}
fsz = (size_t)(p - first);
@@ -3482,14 +3468,14 @@ roff_tr(ROFF_ARGS)
if (*second == '\\') {
esc = mandoc_escape(&p, NULL, NULL);
if (esc == ESCAPE_ERROR) {
- mandoc_msg(MANDOCERR_ESC_BAD, r->parse,
- ln, (int)(p - buf->buf), second);
+ mandoc_msg(MANDOCERR_ESC_BAD, ln,
+ (int)(p - buf->buf), "%s", second);
return ROFF_IGN;
}
ssz = (size_t)(p - second);
} else if (*second == '\0') {
- mandoc_vmsg(MANDOCERR_TR_ODD, r->parse,
- ln, first - buf->buf, "tr %s", first);
+ mandoc_msg(MANDOCERR_TR_ODD, ln,
+ (int)(first - buf->buf), "tr %s", first);
second = " ";
p--;
}
@@ -3524,7 +3510,7 @@ roff_return(ROFF_ARGS)
if (r->mstackpos >= 0)
return ROFF_IGN | ROFF_USERRET;
- mandoc_msg(MANDOCERR_REQ_NOMAC, r->parse, ln, ppos, "return");
+ mandoc_msg(MANDOCERR_REQ_NOMAC, ln, ppos, "return");
return ROFF_IGN;
}
@@ -3587,17 +3573,17 @@ roff_shift(ROFF_ARGS)
levels = 1;
if (buf->buf[pos] != '\0' &&
roff_evalnum(r, ln, buf->buf, &pos, &levels, 0) == 0) {
- mandoc_vmsg(MANDOCERR_CE_NONUM, r->parse,
+ mandoc_msg(MANDOCERR_CE_NONUM,
ln, pos, "shift %s", buf->buf + pos);
levels = 1;
}
if (r->mstackpos < 0) {
- mandoc_msg(MANDOCERR_REQ_NOMAC, r->parse, ln, ppos, "shift");
+ mandoc_msg(MANDOCERR_REQ_NOMAC, ln, ppos, "shift");
return ROFF_IGN;
}
ctx = r->mstack + r->mstackpos;
if (levels > ctx->argc) {
- mandoc_vmsg(MANDOCERR_SHIFT, r->parse,
+ mandoc_msg(MANDOCERR_SHIFT,
ln, pos, "%d, but max is %d", levels, ctx->argc);
levels = ctx->argc;
}
@@ -3617,7 +3603,7 @@ roff_so(ROFF_ARGS)
char *name, *cp;
name = buf->buf + pos;
- mandoc_vmsg(MANDOCERR_SO, r->parse, ln, ppos, "so %s", name);
+ mandoc_msg(MANDOCERR_SO, ln, ppos, "so %s", name);
/*
* Handle `so'. Be EXTREMELY careful, as we shouldn't be
@@ -3627,8 +3613,7 @@ roff_so(ROFF_ARGS)
*/
if (*name == '/' || strstr(name, "../") || strstr(name, "/..")) {
- mandoc_vmsg(MANDOCERR_SO_PATH, r->parse, ln, ppos,
- ".so %s", name);
+ mandoc_msg(MANDOCERR_SO_PATH, ln, ppos, ".so %s", name);
buf->sz = mandoc_asprintf(&cp,
".sp\nSee the file %s.\n.sp", name) + 1;
free(buf->buf);
@@ -3741,7 +3726,7 @@ roff_getname(struct roff *r, char **cpp, int ln, int pos)
cp++;
if ('\\' == *cp)
continue;
- mandoc_vmsg(MANDOCERR_NAMESC, r->parse, ln, pos,
+ mandoc_msg(MANDOCERR_NAMESC, ln, pos,
"%.*s", (int)(cp - name + 1), name);
mandoc_escape((const char **)&cp, NULL, NULL);
break;