-/* $Id: libmandoc.h,v 1.76 2018/12/14 06:33:14 schwarze Exp $ */
+/* $Id: libmandoc.h,v 1.77 2018/12/21 17:15:18 schwarze Exp $ */
/*
* Copyright (c) 2009, 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
struct roff;
struct roff_man;
-char *mandoc_getarg(char **, int, int *);
char *mandoc_normdate(struct roff_man *, char *, int, int);
int mandoc_eos(const char *, size_t);
int mandoc_strntoi(const char *, size_t, int);
void roff_setreg(struct roff *, const char *, int, char sign);
int roff_getreg(struct roff *, const char *);
char *roff_strdup(const struct roff *, const char *);
+char *roff_getarg(struct roff *, char **, int, int *);
int roff_getcontrol(const struct roff *,
const char *, int *);
int roff_getformat(const struct roff *);
-/* $Id: libmdoc.h,v 1.114 2018/12/04 02:53:51 schwarze Exp $ */
+/* $Id: libmdoc.h,v 1.115 2018/12/21 17:15:18 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze <schwarze@openbsd.org>
ARGS_ERROR,
ARGS_EOLN, /* end-of-line */
ARGS_WORD, /* normal word */
+ ARGS_ALLOC, /* normal word from roff_getarg() */
ARGS_PUNCT, /* series of punctuation */
ARGS_PHRASE /* Bl -column phrase */
};
-/* $Id: man_macro.c,v 1.136 2018/12/14 06:33:14 schwarze Exp $ */
+/* $Id: man_macro.c,v 1.137 2018/12/21 17:15:18 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
{
enum roff_tok ctok, ntok;
const struct roff_node *nn;
- char *p;
- int cline, cpos, nrew, target;
+ char *p, *ep;
+ int cline, cpos, la, nrew, target;
nrew = 1;
switch (tok) {
case MAN_RE:
ntok = MAN_RS;
+ la = *pos;
if ( ! man_args(man, line, pos, buf, &p))
break;
for (nn = man->last->parent; nn; nn = nn->parent)
if (nn->tok == ntok && nn->type == ROFFT_BLOCK)
nrew++;
- target = strtol(p, &p, 10);
- if (*p != '\0')
+ target = strtol(p, &ep, 10);
+ if (*ep != '\0')
mandoc_msg(MANDOCERR_ARG_EXCESS, line,
- (int)(p - buf), "RE ... %s", p);
+ la + (buf[la] == '"') + (int)(ep - p),
+ "RE ... %s", ep);
+ free(p);
if (target == 0)
target = 1;
nrew -= target;
roff_setreg(man->roff, "an-margin",
head->aux, '+');
}
+ free(p);
}
if (buf[*pos] != '\0')
if ( ! man_args(man, line, pos, buf, &p))
break;
roff_word_alloc(man, line, la, p);
+ free(p);
}
/*
roff_word_append(man, p);
else
roff_word_alloc(man, line, la, p);
+ free(p);
}
/*
if ('\0' == *start)
return 0;
- *v = mandoc_getarg(v, line, pos);
+ *v = roff_getarg(man->roff, v, line, pos);
return 1;
}
-/* $Id: mdoc_argv.c,v 1.118 2018/12/14 06:33:14 schwarze Exp $ */
+/* $Id: mdoc_argv.c,v 1.119 2018/12/21 17:15:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2012, 2014-2018 Ingo Schwarze <schwarze@openbsd.org>
char *buf, enum roff_tok tok, char **v)
{
struct roff_node *n;
- char *v_local;
enum argsflag fl;
- if (v == NULL)
- v = &v_local;
fl = tok == TOKEN_NONE ? ARGSFL_NONE : mdocargs[tok - MDOC_Dd].flags;
/*
char *buf, enum argsflag fl, char **v)
{
char *p;
+ char *v_local;
int pairs;
if (buf[*pos] == '\0') {
return ARGS_EOLN;
}
+ if (v == NULL)
+ v = &v_local;
*v = buf + *pos;
if (fl == ARGSFL_DELIM && args_checkpunct(buf, *pos))
* Whitespace is NOT involved in literal termination.
*/
- if (mdoc->flags & MDOC_PHRASELIT || buf[*pos] == '\"') {
- if ( ! (mdoc->flags & MDOC_PHRASELIT))
+ if (mdoc->flags & MDOC_PHRASELIT ||
+ (mdoc->flags & MDOC_PHRASE && buf[*pos] == '\"')) {
+ if ((mdoc->flags & MDOC_PHRASELIT) == 0) {
*v = &buf[++(*pos)];
-
- if (mdoc->flags & MDOC_PHRASE)
mdoc->flags |= MDOC_PHRASELIT;
-
+ }
pairs = 0;
for ( ; buf[*pos]; (*pos)++) {
/* Move following text left after quoted quotes. */
}
p = &buf[*pos];
- *v = mandoc_getarg(&p, line, pos);
+ *v = roff_getarg(mdoc->roff, &p, line, pos);
+ if (v == &v_local)
+ free(*v);
/*
* After parsing the last word in this phrase,
mdoc->flags &= ~MDOC_PHRASEQL;
mdoc->flags |= MDOC_PHRASEQF;
}
- return ARGS_WORD;
+ return ARGS_ALLOC;
}
/*
v->value = mandoc_reallocarray(v->value,
v->sz + MULTI_STEP, sizeof(char *));
- v->value[(int)v->sz] = mandoc_strdup(p);
+ if (ac != ARGS_ALLOC)
+ p = mandoc_strdup(p);
+ v->value[(int)v->sz] = p;
}
}
if (ac == ARGS_EOLN)
return;
+ if (ac != ARGS_ALLOC)
+ p = mandoc_strdup(p);
+
v->sz = 1;
v->value = mandoc_malloc(sizeof(char *));
- v->value[0] = mandoc_strdup(p);
+ v->value[0] = p;
}
-/* $Id: mdoc_macro.c,v 1.227 2018/12/14 05:18:02 schwarze Exp $ */
+/* $Id: mdoc_macro.c,v 1.228 2018/12/21 17:15:19 schwarze Exp $ */
/*
* Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2012-2018 Ingo Schwarze <schwarze@openbsd.org>
static int find_pending(struct roff_man *, enum roff_tok,
int, int, struct roff_node *);
static int lookup(struct roff_man *, int, int, int, const char *);
-static int macro_or_word(MACRO_PROT_ARGS, int);
+static int macro_or_word(MACRO_PROT_ARGS, char *, int);
static void break_intermediate(struct roff_node *,
struct roff_node *);
static int parse_rest(struct roff_man *, enum roff_tok,
{
char *p;
int la;
+ enum margserr ac;
if (buf[*pos] == '\0')
return;
for (;;) {
la = *pos;
- if (mdoc_args(mdoc, line, pos, buf, TOKEN_NONE, &p) ==
- ARGS_EOLN)
+ ac = mdoc_args(mdoc, line, pos, buf, TOKEN_NONE, &p);
+ if (ac == ARGS_EOLN)
break;
dword(mdoc, line, la, p, DELIM_MAX, 1);
if (mandoc_eos(p, strlen(p)))
mdoc->last->flags |= NODE_EOS;
+ if (ac == ARGS_ALLOC)
+ free(p);
}
}
* Otherwise, allocate it and return 0.
*/
static int
-macro_or_word(MACRO_PROT_ARGS, int parsed)
+macro_or_word(MACRO_PROT_ARGS, char *p, int parsed)
{
- char *p;
int ntok;
- p = buf + ppos;
- ntok = TOKEN_NONE;
- if (*p == '"')
- p++;
- else if (parsed && ! (mdoc->flags & MDOC_PHRASELIT))
- ntok = lookup(mdoc, tok, line, ppos, p);
+ ntok = buf[ppos] == '"' || parsed == 0 ||
+ mdoc->flags & MDOC_PHRASELIT ? TOKEN_NONE :
+ lookup(mdoc, tok, line, ppos, p);
if (ntok == TOKEN_NONE) {
dword(mdoc, line, ppos, p, DELIM_MAX, tok == TOKEN_NONE ||
if (ntok == TOKEN_NONE) {
dword(mdoc, line, lastarg, p, DELIM_MAX,
mdoc_macro(tok)->flags & MDOC_JOIN);
+ if (ac == ARGS_ALLOC)
+ free(p);
continue;
}
+ if (ac == ARGS_ALLOC)
+ free(p);
if (n != NULL)
rew_last(mdoc, n);
line, la, pos, buf);
if (nl)
append_delims(mdoc, line, pos, buf);
+ if (ac == ARGS_ALLOC)
+ free(p);
return;
}
dword(mdoc, line, la, p, d,
mdoc_macro(tok)->flags & MDOC_JOIN);
+ if (ac == ARGS_ALLOC)
+ free(p);
+
/*
* If the first argument is a closing delimiter,
* do not suppress spacing before it.
static void
blk_full(MACRO_PROT_ARGS)
{
- int la, nl, parsed;
+ int done, la, nl, parsed;
struct mdoc_arg *arg;
struct roff_node *blk; /* Our own or a broken block. */
struct roff_node *head; /* Our own head. */
if (tok == MDOC_Bd || tok == MDOC_Bk) {
mandoc_msg(MANDOCERR_ARG_EXCESS, line, la,
"%s ... %s", roff_name[tok], buf + la);
+ if (ac == ARGS_ALLOC)
+ free(p);
break;
}
if (tok == MDOC_Rs) {
mandoc_msg(MANDOCERR_ARG_SKIP,
line, la, "Rs %s", buf + la);
+ if (ac == ARGS_ALLOC)
+ free(p);
break;
}
if (ac == ARGS_PUNCT)
ac != ARGS_PHRASE &&
mdoc_isdelim(p) == DELIM_OPEN) {
dword(mdoc, line, la, p, DELIM_OPEN, 0);
+ if (ac == ARGS_ALLOC)
+ free(p);
continue;
}
continue;
}
- if (macro_or_word(mdoc, tok, line, la, pos, buf, parsed))
+ done = macro_or_word(mdoc, tok, line, la, pos, buf, p, parsed);
+ if (ac == ARGS_ALLOC)
+ free(p);
+ if (done)
break;
}
static void
blk_part_imp(MACRO_PROT_ARGS)
{
- int la, nl;
+ int done, la, nl;
enum margserr ac;
char *p;
struct roff_node *blk; /* saved block context */
if (body == NULL && mdoc_isdelim(p) == DELIM_OPEN) {
dword(mdoc, line, la, p, DELIM_OPEN, 0);
+ if (ac == ARGS_ALLOC)
+ free(p);
continue;
}
if (body == NULL)
body = roff_body_alloc(mdoc, line, ppos, tok);
- if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
+ done = macro_or_word(mdoc, tok, line, la, pos, buf, p, 1);
+ if (ac == ARGS_ALLOC)
+ free(p);
+ if (done)
break;
}
if (body == NULL)
static void
blk_part_exp(MACRO_PROT_ARGS)
{
- int la, nl;
+ int done, la, nl;
enum margserr ac;
struct roff_node *head; /* keep track of head */
char *p;
if (head == NULL && mdoc_isdelim(p) == DELIM_OPEN) {
dword(mdoc, line, la, p, DELIM_OPEN, 0);
+ if (ac == ARGS_ALLOC)
+ free(p);
continue;
}
dword(mdoc, line, la, p, DELIM_MAX, 0);
rew_last(mdoc, head);
roff_body_alloc(mdoc, line, ppos, tok);
- if (tok == MDOC_Eo)
+ if (tok == MDOC_Eo) {
+ if (ac == ARGS_ALLOC)
+ free(p);
continue;
+ }
}
- if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
+ done = macro_or_word(mdoc, tok, line, la, pos, buf, p, 1);
+ if (ac == ARGS_ALLOC)
+ free(p);
+ if (done)
break;
}
la = *pos;
ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
- if (ac == ARGS_WORD && state == -1 &&
+ if ((ac == ARGS_WORD || ac == ARGS_ALLOC) && state == -1 &&
(mdoc_macro(tok)->flags & MDOC_IGNDELIM) == 0 &&
mdoc_isdelim(p) == DELIM_OPEN) {
dword(mdoc, line, la, p, DELIM_OPEN, 0);
+ if (ac == ARGS_ALLOC)
+ free(p);
continue;
}
}
(*mdoc_macro(ntok)->fp)(mdoc, ntok,
line, la, pos, buf);
+ if (ac == ARGS_ALLOC)
+ free(p);
break;
}
dword(mdoc, line, la, p, DELIM_MAX,
mdoc_macro(tok)->flags & MDOC_JOIN);
+ if (ac == ARGS_ALLOC)
+ free(p);
+ p = mdoc->last->string;
}
if (state == -1) {
parse_rest(struct roff_man *mdoc, enum roff_tok tok,
int line, int *pos, char *buf)
{
- int la;
+ char *p;
+ int done, la;
+ enum margserr ac;
for (;;) {
la = *pos;
- if (mdoc_args(mdoc, line, pos, buf, tok, NULL) == ARGS_EOLN)
+ ac = mdoc_args(mdoc, line, pos, buf, tok, &p);
+ if (ac == ARGS_EOLN)
return 0;
- if (macro_or_word(mdoc, tok, line, la, pos, buf, 1))
+ done = macro_or_word(mdoc, tok, line, la, pos, buf, p, 1);
+ if (ac == ARGS_ALLOC)
+ free(p);
+ if (done)
return 1;
}
}
-.\" $OpenBSD: REarg.in,v 1.3 2017/07/04 14:53:23 schwarze Exp $
-.TH RS-REARG 1 "January 24, 2015"
+.\" $OpenBSD: REarg.in,v 1.4 2018/12/21 16:58:49 schwarze Exp $
+.TH RS-REARG 1 "December 21, 2018"
.SH NAME
RS-REarg \- arguments to the RE macro
.SH DESCRIPTION
+.nr one 1
level 1
.RS 4n 2i
level 2
level 3
.RE 2a
back to 2
-.RE 1b
+.RE \n[one]b
back to 1
.RS 4n
level 2
.RS 2n
level 3
-.RE 1c
+.RE "\\n[one]c"
back to 1
.RS 4n
level 2
level 3
.RE 0d
back to 1
-.RE 1e
+.RE \\n[one]e
-OpenBSD January 24, 2015 RS-REARG(1)
+OpenBSD December 21, 2018 RS-REARG(1)
-mandoc: REarg.in:7:8: ERROR: skipping excess arguments: RS ... 2i
-mandoc: REarg.in:11:6: ERROR: skipping excess arguments: RE ... a
-mandoc: REarg.in:13:6: ERROR: skipping excess arguments: RE ... b
-mandoc: REarg.in:19:6: ERROR: skipping excess arguments: RE ... c
-mandoc: REarg.in:25:6: ERROR: skipping excess arguments: RE ... d
-mandoc: REarg.in:27:6: ERROR: skipping excess arguments: RE ... e
-mandoc: REarg.in:27:2: ERROR: fewer RS blocks open, skipping: RE 1
+mandoc: REarg.in:8:8: ERROR: skipping excess arguments: RS ... 2i
+mandoc: REarg.in:12:6: ERROR: skipping excess arguments: RE ... a
+mandoc: REarg.in:14:6: ERROR: skipping excess arguments: RE ... b
+mandoc: REarg.in:20:7: ERROR: skipping excess arguments: RE ... c
+mandoc: REarg.in:26:6: ERROR: skipping excess arguments: RE ... d
+mandoc: REarg.in:28:6: ERROR: skipping excess arguments: RE ... e
+mandoc: REarg.in:28:2: ERROR: fewer RS blocks open, skipping: RE 1
-# $OpenBSD: Makefile,v 1.31 2016/10/17 19:00:16 schwarze Exp $
+# $OpenBSD: Makefile,v 1.40 2018/12/21 16:58:49 schwarze Exp $
REGRESS_TARGETS = item inset diag ohang bullet dash enum hang tag
REGRESS_TARGETS += column column_nogroff colNoIt
-REGRESS_TARGETS += extend nested offset secstart
+REGRESS_TARGETS += esc extend nested offset secstart
REGRESS_TARGETS += notype multitype badargs
REGRESS_TARGETS += empty noIt emptyhead emptytag emptyitem multitag
--- /dev/null
+.\" $OpenBSD: esc.in,v 1.1 2018/12/21 16:58:49 schwarze Exp $
+.Dd $Mdocdate: December 21 2018 $
+.Dt BL-ESC 1
+.Os
+.Sh NAME
+.Nm Bl-esc
+.Nd escape sequences in full block macro heads
+.Sh DESCRIPTION
+.ds a \(at
+.Bl -tag -width 2n
+.It \*a
+unquoted unescaped
+.It "\*a"
+quoted unescaped
+.It \\*a
+unquoted escaped
+.It "\\*a"
+quoted escaped
+.El
--- /dev/null
+BL-ESC(1) General Commands Manual BL-ESC(1)
+
+N\bNA\bAM\bME\bE
+ B\bBl\bl-\b-e\bes\bsc\bc - escape sequences in full block macro heads
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ @ unquoted unescaped
+
+ @ quoted unescaped
+
+ @ unquoted escaped
+
+ @ quoted escaped
+
+OpenBSD December 21, 2018 OpenBSD
--- /dev/null
+BL-ESC(1) - General Commands Manual
+
+# NAME
+
+**Bl-esc** - escape sequences in full block macro heads
+
+# DESCRIPTION
+
+@
+
+> unquoted unescaped
+
+@
+
+> quoted unescaped
+
+@
+
+> unquoted escaped
+
+@
+
+> quoted escaped
+
+OpenBSD - December 21, 2018
-# $OpenBSD: Makefile,v 1.4 2015/02/11 14:14:53 schwarze Exp $
+# $OpenBSD: Makefile,v 1.8 2018/12/21 16:58:49 schwarze Exp $
-REGRESS_TARGETS = break empty obsolete unclosed
+REGRESS_TARGETS = arg break empty obsolete unclosed
+UTF8_TARGETS = arg
LINT_TARGETS = break obsolete unclosed
# groff-1.22.3 defect:
--- /dev/null
+.\" $OpenBSD: arg.in,v 1.1 2018/12/21 16:58:49 schwarze Exp $
+.Dd $Mdocdate: December 21 2018 $
+.Dt EO-ARG 1
+.Os
+.Sh NAME
+.Nm Eo-arg
+.Nd escapes in arguments of enclosure macros
+.Sh DESCRIPTION
+.ds o \(Fo
+.ds c \(Fc
+.Eo \*o
+unquoted unescaped
+.Ec \*c
+.Pp
+.Eo "\*o"
+quoted unescaped
+.Ec "\*c"
+.Pp
+.Eo \\*o
+unquoted escaped
+.Ec \\*c
+.Pp
+.Eo "\\*o"
+quoted escaped
+.Ec "\\*c"
--- /dev/null
+EO-ARG(1) General Commands Manual EO-ARG(1)
+
+N\bNA\bAM\bME\bE
+ E\bEo\bo-\b-a\bar\brg\bg - escapes in arguments of enclosure macros
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ <<unquoted unescaped>>
+
+ <<quoted unescaped>>
+
+ <<unquoted escaped>>
+
+ <<quoted escaped>>
+
+OpenBSD December 21, 2018 OpenBSD
--- /dev/null
+EO-ARG(1) - General Commands Manual
+
+# NAME
+
+**Eo-arg** - escapes in arguments of enclosure macros
+
+# DESCRIPTION
+
+«unquoted unescaped»
+
+«quoted unescaped»
+
+«unquoted escaped»
+
+«quoted escaped»
+
+OpenBSD - December 21, 2018
--- /dev/null
+EO-ARG(1) General Commands Manual EO-ARG(1)
+
+N\bNA\bAM\bME\bE
+ E\bEo\bo-\b-a\bar\brg\bg – escapes in arguments of enclosure macros
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ «unquoted unescaped»
+
+ «quoted unescaped»
+
+ «unquoted escaped»
+
+ «quoted escaped»
+
+OpenBSD December 21, 2018 OpenBSD
-# $OpenBSD: Makefile,v 1.3 2015/02/06 03:31:11 schwarze Exp $
+# $OpenBSD: Makefile,v 1.7 2018/12/21 16:58:49 schwarze Exp $
-REGRESS_TARGETS = break empty eos font
+REGRESS_TARGETS = arg break empty eos font
LINT_TARGETS = empty
SKIP_TMAN = eos
--- /dev/null
+.\" $OpenBSD: arg.in,v 1.1 2018/12/21 16:58:49 schwarze Exp $
+.Dd $Mdocdate: December 21 2018 $
+.Dt FD-ARG 2
+.Os
+.Sh NAME
+.Nm Fd-arg
+.Nd escape sequences in the arguments of in-line EOL macros
+.Sh DESCRIPTION
+.ds s \(sh
+.Fd \*sunquoted unescaped
+.Pp
+.Fd "\*squoted" unescaped
+.Pp
+.Fd \\*sunquoted escaped
+.Pp
+.Fd "\\*squoted" escaped
--- /dev/null
+FD-ARG(2) System Calls Manual FD-ARG(2)
+
+N\bNA\bAM\bME\bE
+ F\bFd\bd-\b-a\bar\brg\bg - escape sequences in the arguments of in-line EOL macros
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ #\b#u\bun\bnq\bqu\buo\bot\bte\bed\bd u\bun\bne\bes\bsc\bca\bap\bpe\bed\bd
+
+ #\b#q\bqu\buo\bot\bte\bed\bd u\bun\bne\bes\bsc\bca\bap\bpe\bed\bd
+
+ #\b#u\bun\bnq\bqu\buo\bot\bte\bed\bd e\bes\bsc\bca\bap\bpe\bed\bd
+
+ #\b#q\bqu\buo\bot\bte\bed\bd e\bes\bsc\bca\bap\bpe\bed\bd
+
+OpenBSD December 21, 2018 OpenBSD
--- /dev/null
+FD-ARG(2) - System Calls Manual
+
+# NAME
+
+**Fd-arg** - escape sequences in the arguments of in-line EOL macros
+
+# DESCRIPTION
+
+**#unquoted unescaped**
+
+**#quoted unescaped**
+
+**#unquoted escaped**
+
+**#quoted escaped**
+
+OpenBSD - December 21, 2018
-# $OpenBSD: Makefile,v 1.4 2014/07/02 20:18:42 schwarze Exp $
+# $OpenBSD: Makefile,v 1.7 2018/12/21 16:58:49 schwarze Exp $
-REGRESS_TARGETS = punct font
+REGRESS_TARGETS = arg punct font
LINT_TARGETS = punct
.include <bsd.regress.mk>
--- /dev/null
+.\" $OpenBSD: arg.in,v 1.1 2018/12/21 16:58:49 schwarze Exp $
+.Dd $Mdocdate: December 21 2018 $
+.Dt LI-ARG 1
+.Os
+.Sh NAME
+.Nm Li-arg
+.Nd escape sequences in arguments of in-line macros
+.Sh DESCRIPTION
+.ds a \(at
+unquoted unescaped:
+.Li \*a
+.Pp
+quoted unescaped:
+.Li "\*a"
+.Pp
+unquoted escaped:
+.Li \\*a
+.Pp
+quoted escaped:
+.Li "\\*a"
--- /dev/null
+LI-ARG(1) General Commands Manual LI-ARG(1)
+
+N\bNA\bAM\bME\bE
+ L\bLi\bi-\b-a\bar\brg\bg - escape sequences in arguments of in-line macros
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ unquoted unescaped: @
+
+ quoted unescaped: @
+
+ unquoted escaped: @
+
+ quoted escaped: @
+
+OpenBSD December 21, 2018 OpenBSD
--- /dev/null
+LI-ARG(1) - General Commands Manual
+
+# NAME
+
+**Li-arg** - escape sequences in arguments of in-line macros
+
+# DESCRIPTION
+
+unquoted unescaped:
+`@`
+
+quoted unescaped:
+`@`
+
+unquoted escaped:
+`@`
+
+quoted escaped:
+`@`
+
+OpenBSD - December 21, 2018
-# $OpenBSD: Makefile,v 1.5 2014/07/02 11:42:56 schwarze Exp $
+# $OpenBSD: Makefile,v 1.8 2018/12/21 16:58:49 schwarze Exp $
-REGRESS_TARGETS = position punct
+REGRESS_TARGETS = arg position punct
LINT_TARGETS = position
.include <bsd.regress.mk>
--- /dev/null
+.\" $OpenBSD: arg.in,v 1.1 2018/12/21 16:58:49 schwarze Exp $
+.Dd $Mdocdate: December 21 2018 $
+.Dt NS-ARG 1
+.Os
+.Sh NAME
+.Nm Ns-arg
+.Nd escape sequences in the arguments of in-line macros with an argument limit
+.Sh DESCRIPTION
+.ds a \(at
+.No unquoted unescaped Ns \*a
+.No quoted unescaped Ns "\*a"
+.No unquoted escaped Ns \\*a
+.No quoted escaped Ns "\\*a"
--- /dev/null
+NS-ARG(1) General Commands Manual NS-ARG(1)
+
+N\bNA\bAM\bME\bE
+ N\bNs\bs-\b-a\bar\brg\bg - escape sequences in the arguments of in-line macros with an
+ argument limit
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ unquoted unescaped@ quoted unescaped@ unquoted escaped@ quoted escaped@
+
+OpenBSD December 21, 2018 OpenBSD
--- /dev/null
+NS-ARG(1) - General Commands Manual
+
+# NAME
+
+**Ns-arg** - escape sequences in the arguments of in-line macros with an argument limit
+
+# DESCRIPTION
+
+unquoted unescaped@
+quoted unescaped@
+unquoted escaped@
+quoted escaped@
+
+OpenBSD - December 21, 2018
-# $OpenBSD: Makefile,v 1.3 2014/07/02 11:42:56 schwarze Exp $
+# $OpenBSD: Makefile,v 1.7 2018/12/21 16:58:49 schwarze Exp $
-REGRESS_TARGETS = break broken punct
+REGRESS_TARGETS = arg break broken punct
LINT_TARGETS = break broken punct
SKIP_GROFF = break
--- /dev/null
+.\" $OpenBSD: arg.in,v 1.1 2018/12/21 16:58:49 schwarze Exp $
+.Dd $Mdocdate: December 21 2018 $
+.Dt OP-ARG 1
+.Os
+.Sh NAME
+.Nm Op-arg
+.Nd escape sequences in the arguments of partial implicit macros
+.Sh DESCRIPTION
+.ds a \(at
+unquoted unescaped:
+.Op \*a
+.Pp
+quoted unescaped:
+.Op "\*a"
+.Pp
+unquoted escaped:
+.Op \\*a
+.Pp
+quoted escaped:
+.Op "\\*a"
--- /dev/null
+OP-ARG(1) General Commands Manual OP-ARG(1)
+
+N\bNA\bAM\bME\bE
+ O\bOp\bp-\b-a\bar\brg\bg - escape sequences in the arguments of partial implicit macros
+
+D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
+ unquoted unescaped: [@]
+
+ quoted unescaped: [@]
+
+ unquoted escaped: [@]
+
+ quoted escaped: [@]
+
+OpenBSD December 21, 2018 OpenBSD
--- /dev/null
+OP-ARG(1) - General Commands Manual
+
+# NAME
+
+**Op-arg** - escape sequences in the arguments of partial implicit macros
+
+# DESCRIPTION
+
+unquoted unescaped:
+\[@]
+
+quoted unescaped:
+\[@]
+
+unquoted escaped:
+\[@]
+
+quoted escaped:
+\[@]
+
+OpenBSD - December 21, 2018
mandoc: mdoc.in:86:25: STYLE: whitespace at end of input line
mandoc: mdoc.in:90:26: STYLE: whitespace at end of input line
mandoc: mdoc.in:94:27: STYLE: whitespace at end of input line
-mandoc: mdoc.in:102:9: STYLE: unterminated quoted argument
-mandoc: mdoc.in:103:13: STYLE: unterminated quoted argument
-mandoc: mdoc.in:107:10: STYLE: unterminated quoted argument
-mandoc: mdoc.in:108:14: STYLE: unterminated quoted argument
-mandoc: mdoc.in:112:11: STYLE: unterminated quoted argument
-mandoc: mdoc.in:113:15: STYLE: unterminated quoted argument
+mandoc: mdoc.in:102:5: STYLE: unterminated quoted argument
+mandoc: mdoc.in:103:9: STYLE: unterminated quoted argument
+mandoc: mdoc.in:107:5: STYLE: unterminated quoted argument
+mandoc: mdoc.in:107:10: STYLE: whitespace at end of input line
+mandoc: mdoc.in:108:9: STYLE: unterminated quoted argument
+mandoc: mdoc.in:108:14: STYLE: whitespace at end of input line
+mandoc: mdoc.in:112:5: STYLE: unterminated quoted argument
+mandoc: mdoc.in:112:11: STYLE: whitespace at end of input line
+mandoc: mdoc.in:113:9: STYLE: unterminated quoted argument
+mandoc: mdoc.in:113:15: STYLE: whitespace at end of input line
mandoc: mdoc.in:121:1: ERROR: escaped character not allowed in a name: Fl\(
-/* $Id: roff.c,v 1.354 2018/12/20 03:41:54 schwarze Exp $ */
+/* $Id: roff.c,v 1.355 2018/12/21 17:15:19 schwarze Exp $ */
/*
* Copyright (c) 2008-2012, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010-2015, 2017, 2018 Ingo Schwarze <schwarze@openbsd.org>
#include "tbl_parse.h"
#include "eqn_parse.h"
+/*
+ * ASCII_ESC is used to signal from roff_getarg() to roff_expand()
+ * that an escape sequence resulted from copy-in processing and
+ * needs to be checked or interpolated. As it is used nowhere
+ * else, it is defined here rather than in a header file.
+ */
+#define ASCII_ESC 27
+
/* Maximum number of string expansions per line, to break infinite loops. */
#define EXPAND_LIMIT 1000
static int roff_evalpar(struct roff *, int,
const char *, int *, int *, int);
static int roff_evalstrcond(const char *, int *);
+static int roff_expand(struct roff *, struct buf *,
+ int, int, char);
static void roff_free1(struct roff *);
static void roff_freereg(struct roffreg *);
static void roff_freestr(struct roffkv *);
static int roff_parsetext(struct roff *, struct buf *,
int, int *);
static int roff_renamed(ROFF_ARGS);
-static int roff_res(struct roff *, struct buf *, int, int);
static int roff_return(ROFF_ARGS);
static int roff_rm(ROFF_ARGS);
static int roff_rn(ROFF_ARGS);
/* --- main functions of the roff parser ---------------------------------- */
/*
- * In the current line, expand escape sequences that tend to get
- * used in numerical expressions and conditional requests.
- * Also check the syntax of the remaining escape sequences.
+ * In the current line, expand escape sequences that produce parsable
+ * input text. Also check the syntax of the remaining escape sequences,
+ * which typically produce output glyphs or change formatter state.
*/
static int
-roff_res(struct roff *r, struct buf *buf, int ln, int pos)
+roff_expand(struct roff *r, struct buf *buf, int ln, int pos, char newesc)
{
struct mctx *ctx; /* current macro call context */
char ubuf[24]; /* buffer to print the number */
done = 0;
start = buf->buf + pos;
for (stesc = buf->buf + pos; *stesc != '\0'; stesc++) {
- if (stesc[0] != r->escape || stesc[1] == '\0')
+ if (stesc[0] != newesc || stesc[1] == '\0')
continue;
stesc++;
if (*stesc != '"' && *stesc != '#')
* in the syntax tree.
*/
- if (r->format == 0) {
+ if (newesc != ASCII_ESC && r->format == 0) {
while (*ep == ' ' || *ep == '\t')
ep--;
ep[1] = '\0';
expand_count = 0;
while (stesc >= start) {
+ if (*stesc != newesc) {
- /* Search backwards for the next backslash. */
+ /*
+ * If we have a non-standard escape character,
+ * escape literal backslashes because all
+ * processing in subsequent functions uses
+ * the standard escaping rules.
+ */
- if (*stesc != r->escape) {
- if (*stesc == '\\') {
+ if (newesc != ASCII_ESC && *stesc == '\\') {
*stesc = '\0';
buf->sz = mandoc_asprintf(&nbuf, "%s\\e%s",
buf->buf, stesc + 1) + 1;
free(buf->buf);
buf->buf = nbuf;
}
+
+ /* Search backwards for the next escape. */
+
stesc--;
continue;
}
* or to the NUL byte terminating the argument line.
*/
char *
-mandoc_getarg(char **cpp, int ln, int *pos)
+roff_getarg(struct roff *r, char **cpp, int ln, int *pos)
{
- char *start, *cp;
- int quoted, pairs, white;
+ struct buf buf;
+ char *cp, *start;
+ int newesc, pairs, quoted, white;
/* Quoting can only start with a new word. */
start = *cpp;
start++;
}
- pairs = 0;
- white = 0;
+ newesc = pairs = white = 0;
for (cp = start; '\0' != *cp; cp++) {
/*
case 'a':
case 't':
cp[-pairs] = '\t';
- /* FALLTHROUGH */
+ pairs++;
+ cp++;
+ break;
case '\\':
+ newesc = 1;
+ cp[-pairs] = ASCII_ESC;
pairs++;
cp++;
break;
if ('\0' == *cp && (white || ' ' == cp[-1]))
mandoc_msg(MANDOCERR_SPACE_EOL, ln, *pos, NULL);
- return start;
+ start = mandoc_strdup(start);
+ if (newesc == 0)
+ return start;
+
+ buf.buf = start;
+ buf.sz = strlen(start) + 1;
+ buf.next = NULL;
+ if (roff_expand(r, &buf, ln, 0, ASCII_ESC) & ROFF_IGN) {
+ free(buf.buf);
+ buf.buf = mandoc_strdup("");
+ }
+ return buf.buf;
}
/* Expand some escape sequences. */
- e = roff_res(r, buf, ln, pos);
+ e = roff_expand(r, buf, ln, pos, r->escape);
if ((e & ROFF_MASK) == ROFF_IGN)
return e;
assert(e == ROFF_CONT);
ctx->argv = mandoc_reallocarray(ctx->argv,
ctx->argsz, sizeof(*ctx->argv));
}
- arg = mandoc_getarg(&src, ln, &pos);
+ arg = roff_getarg(r, &src, ln, &pos);
sz = 1; /* For the terminating NUL. */
for (ap = arg; *ap != '\0'; ap++)
sz += *ap == '"' ? 4 : 1;
*dst++ = *ap;
}
*dst = '\0';
+ free(arg);
}
/* Replace the macro invocation by the macro definition. */
/*
* We bail out on bad escapes.
* No need to warn: we already did so when
- * roff_res() was called.
+ * roff_expand() was called.
*/
sz = (int)(p - pp);
res = mandoc_realloc(res, ssz + sz + 1);