xref: /illumos-gate/usr/src/cmd/mandoc/mdoc_argv.c (revision 4d131170)
1*4d131170SRobert Mustacchi /*	$Id: mdoc_argv.c,v 1.120 2019/07/11 17:06:17 schwarze Exp $ */
295c635efSGarrett D'Amore /*
395c635efSGarrett D'Amore  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
4*4d131170SRobert Mustacchi  * Copyright (c) 2012, 2014-2019 Ingo Schwarze <schwarze@openbsd.org>
595c635efSGarrett D'Amore  *
695c635efSGarrett D'Amore  * Permission to use, copy, modify, and distribute this software for any
795c635efSGarrett D'Amore  * purpose with or without fee is hereby granted, provided that the above
895c635efSGarrett D'Amore  * copyright notice and this permission notice appear in all copies.
995c635efSGarrett D'Amore  *
10371584c2SYuri Pankov  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
1195c635efSGarrett D'Amore  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12371584c2SYuri Pankov  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
1395c635efSGarrett D'Amore  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
1495c635efSGarrett D'Amore  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
1595c635efSGarrett D'Amore  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
1695c635efSGarrett D'Amore  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1795c635efSGarrett D'Amore  */
1895c635efSGarrett D'Amore #include "config.h"
1995c635efSGarrett D'Amore 
2095c635efSGarrett D'Amore #include <sys/types.h>
2195c635efSGarrett D'Amore 
2295c635efSGarrett D'Amore #include <assert.h>
2395c635efSGarrett D'Amore #include <stdlib.h>
2495c635efSGarrett D'Amore #include <stdio.h>
2595c635efSGarrett D'Amore #include <string.h>
2695c635efSGarrett D'Amore 
27260e9a87SYuri Pankov #include "mandoc_aux.h"
28371584c2SYuri Pankov #include "mandoc.h"
29371584c2SYuri Pankov #include "roff.h"
30371584c2SYuri Pankov #include "mdoc.h"
3195c635efSGarrett D'Amore #include "libmandoc.h"
32a40ea1a7SYuri Pankov #include "roff_int.h"
33371584c2SYuri Pankov #include "libmdoc.h"
3495c635efSGarrett D'Amore 
3595c635efSGarrett D'Amore #define	MULTI_STEP	 5 /* pre-allocate argument values */
36260e9a87SYuri Pankov #define	DELIMSZ		 6 /* max possible size of a delimiter */
3795c635efSGarrett D'Amore 
3895c635efSGarrett D'Amore enum	argsflag {
3995c635efSGarrett D'Amore 	ARGSFL_NONE = 0,
4095c635efSGarrett D'Amore 	ARGSFL_DELIM, /* handle delimiters of [[::delim::][ ]+]+ */
4195c635efSGarrett D'Amore 	ARGSFL_TABSEP /* handle tab/`Ta' separated phrases */
4295c635efSGarrett D'Amore };
4395c635efSGarrett D'Amore 
4495c635efSGarrett D'Amore enum	argvflag {
4595c635efSGarrett D'Amore 	ARGV_NONE, /* no args to flag (e.g., -split) */
4695c635efSGarrett D'Amore 	ARGV_SINGLE, /* one arg to flag (e.g., -file xxx)  */
47698f87a4SGarrett D'Amore 	ARGV_MULTI /* multiple args (e.g., -column xxx yyy) */
4895c635efSGarrett D'Amore };
4995c635efSGarrett D'Amore 
5095c635efSGarrett D'Amore struct	mdocarg {
5195c635efSGarrett D'Amore 	enum argsflag	 flags;
5295c635efSGarrett D'Amore 	const enum mdocargt *argvs;
5395c635efSGarrett D'Amore };
5495c635efSGarrett D'Amore 
5595c635efSGarrett D'Amore static	void		 argn_free(struct mdoc_arg *, int);
56371584c2SYuri Pankov static	enum margserr	 args(struct roff_man *, int, int *,
5795c635efSGarrett D'Amore 				char *, enum argsflag, char **);
5895c635efSGarrett D'Amore static	int		 args_checkpunct(const char *, int);
59371584c2SYuri Pankov static	void		 argv_multi(struct roff_man *, int,
6095c635efSGarrett D'Amore 				struct mdoc_argv *, int *, char *);
61371584c2SYuri Pankov static	void		 argv_single(struct roff_man *, int,
6295c635efSGarrett D'Amore 				struct mdoc_argv *, int *, char *);
6395c635efSGarrett D'Amore 
6495c635efSGarrett D'Amore static	const enum argvflag argvflags[MDOC_ARG_MAX] = {
6595c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Split */
6695c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Nosplit */
6795c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Ragged */
6895c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Unfilled */
6995c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Literal */
7095c635efSGarrett D'Amore 	ARGV_SINGLE,	/* MDOC_File */
71698f87a4SGarrett D'Amore 	ARGV_SINGLE,	/* MDOC_Offset */
7295c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Bullet */
7395c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Dash */
7495c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Hyphen */
7595c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Item */
7695c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Enum */
7795c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Tag */
7895c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Diag */
7995c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Hang */
8095c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Ohang */
8195c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Inset */
8295c635efSGarrett D'Amore 	ARGV_MULTI,	/* MDOC_Column */
83698f87a4SGarrett D'Amore 	ARGV_SINGLE,	/* MDOC_Width */
8495c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Compact */
8595c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Std */
8695c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Filled */
8795c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Words */
8895c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Emphasis */
8995c635efSGarrett D'Amore 	ARGV_NONE,	/* MDOC_Symbolic */
9095c635efSGarrett D'Amore 	ARGV_NONE	/* MDOC_Symbolic */
9195c635efSGarrett D'Amore };
9295c635efSGarrett D'Amore 
9395c635efSGarrett D'Amore static	const enum mdocargt args_Ex[] = {
9495c635efSGarrett D'Amore 	MDOC_Std,
9595c635efSGarrett D'Amore 	MDOC_ARG_MAX
9695c635efSGarrett D'Amore };
9795c635efSGarrett D'Amore 
9895c635efSGarrett D'Amore static	const enum mdocargt args_An[] = {
9995c635efSGarrett D'Amore 	MDOC_Split,
10095c635efSGarrett D'Amore 	MDOC_Nosplit,
10195c635efSGarrett D'Amore 	MDOC_ARG_MAX
10295c635efSGarrett D'Amore };
10395c635efSGarrett D'Amore 
10495c635efSGarrett D'Amore static	const enum mdocargt args_Bd[] = {
10595c635efSGarrett D'Amore 	MDOC_Ragged,
10695c635efSGarrett D'Amore 	MDOC_Unfilled,
10795c635efSGarrett D'Amore 	MDOC_Filled,
10895c635efSGarrett D'Amore 	MDOC_Literal,
10995c635efSGarrett D'Amore 	MDOC_File,
11095c635efSGarrett D'Amore 	MDOC_Offset,
11195c635efSGarrett D'Amore 	MDOC_Compact,
11295c635efSGarrett D'Amore 	MDOC_Centred,
11395c635efSGarrett D'Amore 	MDOC_ARG_MAX
11495c635efSGarrett D'Amore };
11595c635efSGarrett D'Amore 
11695c635efSGarrett D'Amore static	const enum mdocargt args_Bf[] = {
11795c635efSGarrett D'Amore 	MDOC_Emphasis,
11895c635efSGarrett D'Amore 	MDOC_Literal,
11995c635efSGarrett D'Amore 	MDOC_Symbolic,
12095c635efSGarrett D'Amore 	MDOC_ARG_MAX
12195c635efSGarrett D'Amore };
12295c635efSGarrett D'Amore 
12395c635efSGarrett D'Amore static	const enum mdocargt args_Bk[] = {
12495c635efSGarrett D'Amore 	MDOC_Words,
12595c635efSGarrett D'Amore 	MDOC_ARG_MAX
12695c635efSGarrett D'Amore };
12795c635efSGarrett D'Amore 
12895c635efSGarrett D'Amore static	const enum mdocargt args_Bl[] = {
12995c635efSGarrett D'Amore 	MDOC_Bullet,
13095c635efSGarrett D'Amore 	MDOC_Dash,
13195c635efSGarrett D'Amore 	MDOC_Hyphen,
13295c635efSGarrett D'Amore 	MDOC_Item,
13395c635efSGarrett D'Amore 	MDOC_Enum,
13495c635efSGarrett D'Amore 	MDOC_Tag,
13595c635efSGarrett D'Amore 	MDOC_Diag,
13695c635efSGarrett D'Amore 	MDOC_Hang,
13795c635efSGarrett D'Amore 	MDOC_Ohang,
13895c635efSGarrett D'Amore 	MDOC_Inset,
13995c635efSGarrett D'Amore 	MDOC_Column,
14095c635efSGarrett D'Amore 	MDOC_Width,
14195c635efSGarrett D'Amore 	MDOC_Offset,
14295c635efSGarrett D'Amore 	MDOC_Compact,
14395c635efSGarrett D'Amore 	MDOC_Nested,
14495c635efSGarrett D'Amore 	MDOC_ARG_MAX
14595c635efSGarrett D'Amore };
14695c635efSGarrett D'Amore 
147cec8643bSMichal Nowak static	const struct mdocarg mdocargs[MDOC_MAX - MDOC_Dd] = {
14895c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Dd */
14995c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Dt */
15095c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Os */
15195c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Sh */
152260e9a87SYuri Pankov 	{ ARGSFL_NONE, NULL }, /* Ss */
153260e9a87SYuri Pankov 	{ ARGSFL_NONE, NULL }, /* Pp */
15495c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* D1 */
15595c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Dl */
15695c635efSGarrett D'Amore 	{ ARGSFL_NONE, args_Bd }, /* Bd */
15795c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Ed */
15895c635efSGarrett D'Amore 	{ ARGSFL_NONE, args_Bl }, /* Bl */
15995c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* El */
16095c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* It */
161260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Ad */
16295c635efSGarrett D'Amore 	{ ARGSFL_DELIM, args_An }, /* An */
163c66b8046SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Ap */
16495c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Ar */
165698f87a4SGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Cd */
16695c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Cm */
167260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Dv */
168260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Er */
169260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Ev */
17095c635efSGarrett D'Amore 	{ ARGSFL_NONE, args_Ex }, /* Ex */
171260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Fa */
172260e9a87SYuri Pankov 	{ ARGSFL_NONE, NULL }, /* Fd */
17395c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Fl */
174260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Fn */
175260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Ft */
176260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Ic */
177260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* In */
17895c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Li */
179260e9a87SYuri Pankov 	{ ARGSFL_NONE, NULL }, /* Nd */
180260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Nm */
18195c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Op */
182260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Ot */
18395c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Pa */
18495c635efSGarrett D'Amore 	{ ARGSFL_NONE, args_Ex }, /* Rv */
185260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* St */
18695c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Va */
187260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Vt */
18895c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Xr */
18995c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %A */
19095c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %B */
19195c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %D */
19295c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %I */
19395c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %J */
19495c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %N */
19595c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %O */
19695c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %P */
19795c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %R */
19895c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %T */
19995c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %V */
20095c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Ac */
20195c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Ao */
20295c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Aq */
20395c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* At */
20495c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Bc */
205260e9a87SYuri Pankov 	{ ARGSFL_NONE, args_Bf }, /* Bf */
20695c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Bo */
20795c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Bq */
20895c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Bsx */
20995c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Bx */
21095c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Db */
21195c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Dc */
21295c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Do */
21395c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Dq */
21495c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Ec */
21595c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Ef */
216260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Em */
21795c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Eo */
21895c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Fx */
21995c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Ms */
22095c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* No */
22195c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Ns */
22295c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Nx */
22395c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Ox */
22495c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Pc */
22595c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Pf */
22695c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Po */
22795c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Pq */
22895c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Qc */
22995c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Ql */
23095c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Qo */
23195c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Qq */
23295c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Re */
23395c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Rs */
23495c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Sc */
23595c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* So */
23695c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Sq */
23795c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Sm */
23895c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Sx */
23995c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Sy */
24095c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Tn */
24195c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Ux */
24295c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Xc */
24395c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Xo */
244260e9a87SYuri Pankov 	{ ARGSFL_NONE, NULL }, /* Fo */
245260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Fc */
24695c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Oo */
24795c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Oc */
24895c635efSGarrett D'Amore 	{ ARGSFL_NONE, args_Bk }, /* Bk */
24995c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Ek */
25095c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Bt */
25195c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Hf */
252260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* Fr */
25395c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Ud */
254698f87a4SGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Lb */
25595c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Lp */
25695c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Lk */
25795c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Mt */
25895c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Brq */
25995c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Bro */
26095c635efSGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Brc */
26195c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %C */
26295c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Es */
263260e9a87SYuri Pankov 	{ ARGSFL_DELIM, NULL }, /* En */
264698f87a4SGarrett D'Amore 	{ ARGSFL_DELIM, NULL }, /* Dx */
26595c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %Q */
26695c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* %U */
26795c635efSGarrett D'Amore 	{ ARGSFL_NONE, NULL }, /* Ta */
26895c635efSGarrett D'Amore };
26995c635efSGarrett D'Amore 
27095c635efSGarrett D'Amore 
27195c635efSGarrett D'Amore /*
272260e9a87SYuri Pankov  * Parse flags and their arguments from the input line.
273260e9a87SYuri Pankov  * These come in the form -flag [argument ...].
274260e9a87SYuri Pankov  * Some flags take no argument, some one, some multiple.
27595c635efSGarrett D'Amore  */
276260e9a87SYuri Pankov void
mdoc_argv(struct roff_man * mdoc,int line,enum roff_tok tok,struct mdoc_arg ** reta,int * pos,char * buf)277c66b8046SYuri Pankov mdoc_argv(struct roff_man *mdoc, int line, enum roff_tok tok,
278260e9a87SYuri Pankov 	struct mdoc_arg **reta, int *pos, char *buf)
27995c635efSGarrett D'Amore {
280260e9a87SYuri Pankov 	struct mdoc_argv	  tmpv;
281260e9a87SYuri Pankov 	struct mdoc_argv	**retv;
282260e9a87SYuri Pankov 	const enum mdocargt	 *argtable;
283260e9a87SYuri Pankov 	char			 *argname;
284260e9a87SYuri Pankov 	int			  ipos, retc;
285260e9a87SYuri Pankov 	char			  savechar;
28695c635efSGarrett D'Amore 
287260e9a87SYuri Pankov 	*reta = NULL;
28895c635efSGarrett D'Amore 
289260e9a87SYuri Pankov 	/* Which flags does this macro support? */
29095c635efSGarrett D'Amore 
291c66b8046SYuri Pankov 	assert(tok >= MDOC_Dd && tok < MDOC_MAX);
292cec8643bSMichal Nowak 	argtable = mdocargs[tok - MDOC_Dd].argvs;
293260e9a87SYuri Pankov 	if (argtable == NULL)
294260e9a87SYuri Pankov 		return;
29595c635efSGarrett D'Amore 
296260e9a87SYuri Pankov 	/* Loop over the flags on the input line. */
29795c635efSGarrett D'Amore 
298260e9a87SYuri Pankov 	ipos = *pos;
299260e9a87SYuri Pankov 	while (buf[ipos] == '-') {
30095c635efSGarrett D'Amore 
301260e9a87SYuri Pankov 		/* Seek to the first unescaped space. */
30295c635efSGarrett D'Amore 
303260e9a87SYuri Pankov 		for (argname = buf + ++ipos; buf[ipos] != '\0'; ipos++)
304260e9a87SYuri Pankov 			if (buf[ipos] == ' ' && buf[ipos - 1] != '\\')
305260e9a87SYuri Pankov 				break;
30695c635efSGarrett D'Amore 
307260e9a87SYuri Pankov 		/*
308260e9a87SYuri Pankov 		 * We want to nil-terminate the word to look it up.
309260e9a87SYuri Pankov 		 * But we may not have a flag, in which case we need
310260e9a87SYuri Pankov 		 * to restore the line as-is.  So keep around the
311260e9a87SYuri Pankov 		 * stray byte, which we'll reset upon exiting.
312260e9a87SYuri Pankov 		 */
31395c635efSGarrett D'Amore 
314260e9a87SYuri Pankov 		if ((savechar = buf[ipos]) != '\0')
315260e9a87SYuri Pankov 			buf[ipos++] = '\0';
31695c635efSGarrett D'Amore 
317260e9a87SYuri Pankov 		/*
318260e9a87SYuri Pankov 		 * Now look up the word as a flag.  Use temporary
319260e9a87SYuri Pankov 		 * storage that we'll copy into the node's flags.
320260e9a87SYuri Pankov 		 */
32195c635efSGarrett D'Amore 
322260e9a87SYuri Pankov 		while ((tmpv.arg = *argtable++) != MDOC_ARG_MAX)
323260e9a87SYuri Pankov 			if ( ! strcmp(argname, mdoc_argnames[tmpv.arg]))
324260e9a87SYuri Pankov 				break;
325260e9a87SYuri Pankov 
326260e9a87SYuri Pankov 		/* If it isn't a flag, restore the saved byte. */
327260e9a87SYuri Pankov 
328260e9a87SYuri Pankov 		if (tmpv.arg == MDOC_ARG_MAX) {
329260e9a87SYuri Pankov 			if (savechar != '\0')
330260e9a87SYuri Pankov 				buf[ipos - 1] = savechar;
33195c635efSGarrett D'Amore 			break;
332260e9a87SYuri Pankov 		}
33395c635efSGarrett D'Amore 
334260e9a87SYuri Pankov 		/* Read to the next word (the first argument). */
33595c635efSGarrett D'Amore 
336260e9a87SYuri Pankov 		while (buf[ipos] == ' ')
337260e9a87SYuri Pankov 			ipos++;
33895c635efSGarrett D'Amore 
339260e9a87SYuri Pankov 		/* Parse the arguments of the flag. */
340260e9a87SYuri Pankov 
341260e9a87SYuri Pankov 		tmpv.line  = line;
342260e9a87SYuri Pankov 		tmpv.pos   = *pos;
343260e9a87SYuri Pankov 		tmpv.sz    = 0;
344260e9a87SYuri Pankov 		tmpv.value = NULL;
345260e9a87SYuri Pankov 
346260e9a87SYuri Pankov 		switch (argvflags[tmpv.arg]) {
347260e9a87SYuri Pankov 		case ARGV_SINGLE:
348260e9a87SYuri Pankov 			argv_single(mdoc, line, &tmpv, &ipos, buf);
349260e9a87SYuri Pankov 			break;
350260e9a87SYuri Pankov 		case ARGV_MULTI:
351260e9a87SYuri Pankov 			argv_multi(mdoc, line, &tmpv, &ipos, buf);
352260e9a87SYuri Pankov 			break;
353260e9a87SYuri Pankov 		case ARGV_NONE:
354260e9a87SYuri Pankov 			break;
355260e9a87SYuri Pankov 		}
35695c635efSGarrett D'Amore 
357260e9a87SYuri Pankov 		/* Append to the return values. */
35895c635efSGarrett D'Amore 
359260e9a87SYuri Pankov 		if (*reta == NULL)
360260e9a87SYuri Pankov 			*reta = mandoc_calloc(1, sizeof(**reta));
36195c635efSGarrett D'Amore 
362260e9a87SYuri Pankov 		retc = ++(*reta)->argc;
363260e9a87SYuri Pankov 		retv = &(*reta)->argv;
364260e9a87SYuri Pankov 		*retv = mandoc_reallocarray(*retv, retc, sizeof(**retv));
365260e9a87SYuri Pankov 		memcpy(*retv + retc - 1, &tmpv, sizeof(**retv));
366260e9a87SYuri Pankov 
367260e9a87SYuri Pankov 		/* Prepare for parsing the next flag. */
368260e9a87SYuri Pankov 
369260e9a87SYuri Pankov 		*pos = ipos;
370cec8643bSMichal Nowak 		argtable = mdocargs[tok - MDOC_Dd].argvs;
371260e9a87SYuri Pankov 	}
37295c635efSGarrett D'Amore }
37395c635efSGarrett D'Amore 
37495c635efSGarrett D'Amore void
mdoc_argv_free(struct mdoc_arg * p)37595c635efSGarrett D'Amore mdoc_argv_free(struct mdoc_arg *p)
37695c635efSGarrett D'Amore {
37795c635efSGarrett D'Amore 	int		 i;
37895c635efSGarrett D'Amore 
37995c635efSGarrett D'Amore 	if (NULL == p)
38095c635efSGarrett D'Amore 		return;
38195c635efSGarrett D'Amore 
38295c635efSGarrett D'Amore 	if (p->refcnt) {
38395c635efSGarrett D'Amore 		--(p->refcnt);
38495c635efSGarrett D'Amore 		if (p->refcnt)
38595c635efSGarrett D'Amore 			return;
38695c635efSGarrett D'Amore 	}
38795c635efSGarrett D'Amore 	assert(p->argc);
38895c635efSGarrett D'Amore 
38995c635efSGarrett D'Amore 	for (i = (int)p->argc - 1; i >= 0; i--)
39095c635efSGarrett D'Amore 		argn_free(p, i);
39195c635efSGarrett D'Amore 
39295c635efSGarrett D'Amore 	free(p->argv);
39395c635efSGarrett D'Amore 	free(p);
39495c635efSGarrett D'Amore }
39595c635efSGarrett D'Amore 
39695c635efSGarrett D'Amore static void
argn_free(struct mdoc_arg * p,int iarg)39795c635efSGarrett D'Amore argn_free(struct mdoc_arg *p, int iarg)
39895c635efSGarrett D'Amore {
39995c635efSGarrett D'Amore 	struct mdoc_argv *arg;
40095c635efSGarrett D'Amore 	int		  j;
40195c635efSGarrett D'Amore 
40295c635efSGarrett D'Amore 	arg = &p->argv[iarg];
40395c635efSGarrett D'Amore 
40495c635efSGarrett D'Amore 	if (arg->sz && arg->value) {
405260e9a87SYuri Pankov 		for (j = (int)arg->sz - 1; j >= 0; j--)
40695c635efSGarrett D'Amore 			free(arg->value[j]);
40795c635efSGarrett D'Amore 		free(arg->value);
40895c635efSGarrett D'Amore 	}
40995c635efSGarrett D'Amore 
41095c635efSGarrett D'Amore 	for (--p->argc; iarg < (int)p->argc; iarg++)
41195c635efSGarrett D'Amore 		p->argv[iarg] = p->argv[iarg+1];
41295c635efSGarrett D'Amore }
41395c635efSGarrett D'Amore 
41495c635efSGarrett D'Amore enum margserr
mdoc_args(struct roff_man * mdoc,int line,int * pos,char * buf,enum roff_tok tok,char ** v)415371584c2SYuri Pankov mdoc_args(struct roff_man *mdoc, int line, int *pos,
416c66b8046SYuri Pankov 	char *buf, enum roff_tok tok, char **v)
41795c635efSGarrett D'Amore {
418371584c2SYuri Pankov 	struct roff_node *n;
419260e9a87SYuri Pankov 	enum argsflag	  fl;
42095c635efSGarrett D'Amore 
421cec8643bSMichal Nowak 	fl = tok == TOKEN_NONE ? ARGSFL_NONE : mdocargs[tok - MDOC_Dd].flags;
42295c635efSGarrett D'Amore 
42395c635efSGarrett D'Amore 	/*
42495c635efSGarrett D'Amore 	 * We know that we're in an `It', so it's reasonable to expect
42595c635efSGarrett D'Amore 	 * us to be sitting in a `Bl'.  Someday this may not be the case
42695c635efSGarrett D'Amore 	 * (if we allow random `It's sitting out there), so provide a
42795c635efSGarrett D'Amore 	 * safe fall-back into the default behaviour.
42895c635efSGarrett D'Amore 	 */
42995c635efSGarrett D'Amore 
430c66b8046SYuri Pankov 	if (tok == MDOC_It) {
431c66b8046SYuri Pankov 		for (n = mdoc->last; n != NULL; n = n->parent) {
432c66b8046SYuri Pankov 			if (n->tok != MDOC_Bl)
433c66b8046SYuri Pankov 				continue;
434c66b8046SYuri Pankov 			if (n->norm->Bl.type == LIST_column)
43595c635efSGarrett D'Amore 				fl = ARGSFL_TABSEP;
436c66b8046SYuri Pankov 			break;
437c66b8046SYuri Pankov 		}
438c66b8046SYuri Pankov 	}
43995c635efSGarrett D'Amore 
440371584c2SYuri Pankov 	return args(mdoc, line, pos, buf, fl, v);
44195c635efSGarrett D'Amore }
44295c635efSGarrett D'Amore 
44395c635efSGarrett D'Amore static enum margserr
args(struct roff_man * mdoc,int line,int * pos,char * buf,enum argsflag fl,char ** v)444371584c2SYuri Pankov args(struct roff_man *mdoc, int line, int *pos,
44595c635efSGarrett D'Amore 		char *buf, enum argsflag fl, char **v)
44695c635efSGarrett D'Amore {
447371584c2SYuri Pankov 	char		*p;
448cec8643bSMichal Nowak 	char		*v_local;
449698f87a4SGarrett D'Amore 	int		 pairs;
45095c635efSGarrett D'Amore 
451371584c2SYuri Pankov 	if (buf[*pos] == '\0') {
452371584c2SYuri Pankov 		if (mdoc->flags & MDOC_PHRASELIT &&
453371584c2SYuri Pankov 		    ! (mdoc->flags & MDOC_PHRASE)) {
454cec8643bSMichal Nowak 			mandoc_msg(MANDOCERR_ARG_QUOTE, line, *pos, NULL);
455371584c2SYuri Pankov 			mdoc->flags &= ~MDOC_PHRASELIT;
456371584c2SYuri Pankov 		}
457*4d131170SRobert Mustacchi 		mdoc->flags &= ~MDOC_PHRASEQL;
458371584c2SYuri Pankov 		return ARGS_EOLN;
45995c635efSGarrett D'Amore 	}
46095c635efSGarrett D'Amore 
461cec8643bSMichal Nowak 	if (v == NULL)
462cec8643bSMichal Nowak 		v = &v_local;
463371584c2SYuri Pankov 	*v = buf + *pos;
46495c635efSGarrett D'Amore 
465371584c2SYuri Pankov 	if (fl == ARGSFL_DELIM && args_checkpunct(buf, *pos))
466371584c2SYuri Pankov 		return ARGS_PUNCT;
46795c635efSGarrett D'Amore 
46895c635efSGarrett D'Amore 	/*
469371584c2SYuri Pankov 	 * Tabs in `It' lines in `Bl -column' can't be escaped.
470371584c2SYuri Pankov 	 * Phrases are reparsed for `Ta' and other macros later.
47195c635efSGarrett D'Amore 	 */
47295c635efSGarrett D'Amore 
473371584c2SYuri Pankov 	if (fl == ARGSFL_TABSEP) {
474371584c2SYuri Pankov 		if ((p = strchr(*v, '\t')) != NULL) {
475371584c2SYuri Pankov 
476371584c2SYuri Pankov 			/*
477371584c2SYuri Pankov 			 * Words right before and right after
478371584c2SYuri Pankov 			 * tab characters are not parsed,
479371584c2SYuri Pankov 			 * unless there is a blank in between.
480371584c2SYuri Pankov 			 */
481371584c2SYuri Pankov 
482a40ea1a7SYuri Pankov 			if (p > buf && p[-1] != ' ')
483371584c2SYuri Pankov 				mdoc->flags |= MDOC_PHRASEQL;
484371584c2SYuri Pankov 			if (p[1] != ' ')
485371584c2SYuri Pankov 				mdoc->flags |= MDOC_PHRASEQN;
486371584c2SYuri Pankov 
487371584c2SYuri Pankov 			/*
488371584c2SYuri Pankov 			 * One or more blanks after a tab cause
489371584c2SYuri Pankov 			 * one leading blank in the next column.
490371584c2SYuri Pankov 			 * So skip all but one of them.
491371584c2SYuri Pankov 			 */
492371584c2SYuri Pankov 
493371584c2SYuri Pankov 			*pos += (int)(p - *v) + 1;
494371584c2SYuri Pankov 			while (buf[*pos] == ' ' && buf[*pos + 1] == ' ')
495371584c2SYuri Pankov 				(*pos)++;
496371584c2SYuri Pankov 
497371584c2SYuri Pankov 			/*
498371584c2SYuri Pankov 			 * A tab at the end of an input line
499371584c2SYuri Pankov 			 * switches to the next column.
500371584c2SYuri Pankov 			 */
501371584c2SYuri Pankov 
502371584c2SYuri Pankov 			if (buf[*pos] == '\0' || buf[*pos + 1] == '\0')
503371584c2SYuri Pankov 				mdoc->flags |= MDOC_PHRASEQN;
50495c635efSGarrett D'Amore 		} else {
505371584c2SYuri Pankov 			p = strchr(*v, '\0');
506371584c2SYuri Pankov 			if (p[-1] == ' ')
507371584c2SYuri Pankov 				mandoc_msg(MANDOCERR_SPACE_EOL,
508cec8643bSMichal Nowak 				    line, *pos, NULL);
509371584c2SYuri Pankov 			*pos += (int)(p - *v);
51095c635efSGarrett D'Amore 		}
51195c635efSGarrett D'Amore 
512371584c2SYuri Pankov 		/* Skip any trailing blank characters. */
513371584c2SYuri Pankov 		while (p > *v && p[-1] == ' ' &&
514371584c2SYuri Pankov 		    (p - 1 == *v || p[-2] != '\\'))
515371584c2SYuri Pankov 			p--;
516371584c2SYuri Pankov 		*p = '\0';
51795c635efSGarrett D'Amore 
518371584c2SYuri Pankov 		return ARGS_PHRASE;
519698f87a4SGarrett D'Amore 	}
52095c635efSGarrett D'Amore 
521698f87a4SGarrett D'Amore 	/*
52295c635efSGarrett D'Amore 	 * Process a quoted literal.  A quote begins with a double-quote
52395c635efSGarrett D'Amore 	 * and ends with a double-quote NOT preceded by a double-quote.
524698f87a4SGarrett D'Amore 	 * NUL-terminate the literal in place.
525698f87a4SGarrett D'Amore 	 * Collapse pairs of quotes inside quoted literals.
52695c635efSGarrett D'Amore 	 * Whitespace is NOT involved in literal termination.
52795c635efSGarrett D'Amore 	 */
52895c635efSGarrett D'Amore 
529cec8643bSMichal Nowak 	if (mdoc->flags & MDOC_PHRASELIT ||
530cec8643bSMichal Nowak 	    (mdoc->flags & MDOC_PHRASE && buf[*pos] == '\"')) {
531cec8643bSMichal Nowak 		if ((mdoc->flags & MDOC_PHRASELIT) == 0) {
53295c635efSGarrett D'Amore 			*v = &buf[++(*pos)];
533698f87a4SGarrett D'Amore 			mdoc->flags |= MDOC_PHRASELIT;
534cec8643bSMichal Nowak 		}
535698f87a4SGarrett D'Amore 		pairs = 0;
53695c635efSGarrett D'Amore 		for ( ; buf[*pos]; (*pos)++) {
537698f87a4SGarrett D'Amore 			/* Move following text left after quoted quotes. */
538698f87a4SGarrett D'Amore 			if (pairs)
539698f87a4SGarrett D'Amore 				buf[*pos - pairs] = buf[*pos];
54095c635efSGarrett D'Amore 			if ('\"' != buf[*pos])
54195c635efSGarrett D'Amore 				continue;
542698f87a4SGarrett D'Amore 			/* Unquoted quotes end quoted args. */
54395c635efSGarrett D'Amore 			if ('\"' != buf[*pos + 1])
54495c635efSGarrett D'Amore 				break;
545698f87a4SGarrett D'Amore 			/* Quoted quotes collapse. */
546698f87a4SGarrett D'Amore 			pairs++;
54795c635efSGarrett D'Amore 			(*pos)++;
54895c635efSGarrett D'Amore 		}
549698f87a4SGarrett D'Amore 		if (pairs)
550698f87a4SGarrett D'Amore 			buf[*pos - pairs] = '\0';
55195c635efSGarrett D'Amore 
552371584c2SYuri Pankov 		if (buf[*pos] == '\0') {
553371584c2SYuri Pankov 			if ( ! (mdoc->flags & MDOC_PHRASE))
554371584c2SYuri Pankov 				mandoc_msg(MANDOCERR_ARG_QUOTE,
555cec8643bSMichal Nowak 				    line, *pos, NULL);
556c66b8046SYuri Pankov 			return ARGS_WORD;
55795c635efSGarrett D'Amore 		}
55895c635efSGarrett D'Amore 
559698f87a4SGarrett D'Amore 		mdoc->flags &= ~MDOC_PHRASELIT;
56095c635efSGarrett D'Amore 		buf[(*pos)++] = '\0';
56195c635efSGarrett D'Amore 
56295c635efSGarrett D'Amore 		if ('\0' == buf[*pos])
563c66b8046SYuri Pankov 			return ARGS_WORD;
56495c635efSGarrett D'Amore 
56595c635efSGarrett D'Amore 		while (' ' == buf[*pos])
56695c635efSGarrett D'Amore 			(*pos)++;
56795c635efSGarrett D'Amore 
56895c635efSGarrett D'Amore 		if ('\0' == buf[*pos])
569cec8643bSMichal Nowak 			mandoc_msg(MANDOCERR_SPACE_EOL, line, *pos, NULL);
57095c635efSGarrett D'Amore 
571c66b8046SYuri Pankov 		return ARGS_WORD;
57295c635efSGarrett D'Amore 	}
57395c635efSGarrett D'Amore 
57495c635efSGarrett D'Amore 	p = &buf[*pos];
575cec8643bSMichal Nowak 	*v = roff_getarg(mdoc->roff, &p, line, pos);
576cec8643bSMichal Nowak 	if (v == &v_local)
577cec8643bSMichal Nowak 		free(*v);
57895c635efSGarrett D'Amore 
579371584c2SYuri Pankov 	/*
580371584c2SYuri Pankov 	 * After parsing the last word in this phrase,
581371584c2SYuri Pankov 	 * tell lookup() whether or not to interpret it.
582371584c2SYuri Pankov 	 */
583371584c2SYuri Pankov 
584371584c2SYuri Pankov 	if (*p == '\0' && mdoc->flags & MDOC_PHRASEQL) {
585371584c2SYuri Pankov 		mdoc->flags &= ~MDOC_PHRASEQL;
586371584c2SYuri Pankov 		mdoc->flags |= MDOC_PHRASEQF;
587371584c2SYuri Pankov 	}
588cec8643bSMichal Nowak 	return ARGS_ALLOC;
58995c635efSGarrett D'Amore }
59095c635efSGarrett D'Amore 
591260e9a87SYuri Pankov /*
59295c635efSGarrett D'Amore  * Check if the string consists only of space-separated closing
59395c635efSGarrett D'Amore  * delimiters.  This is a bit of a dance: the first must be a close
59495c635efSGarrett D'Amore  * delimiter, but it may be followed by middle delimiters.  Arbitrary
59595c635efSGarrett D'Amore  * whitespace may separate these tokens.
59695c635efSGarrett D'Amore  */
59795c635efSGarrett D'Amore static int
args_checkpunct(const char * buf,int i)59895c635efSGarrett D'Amore args_checkpunct(const char *buf, int i)
59995c635efSGarrett D'Amore {
60095c635efSGarrett D'Amore 	int		 j;
60195c635efSGarrett D'Amore 	char		 dbuf[DELIMSZ];
60295c635efSGarrett D'Amore 	enum mdelim	 d;
60395c635efSGarrett D'Amore 
60495c635efSGarrett D'Amore 	/* First token must be a close-delimiter. */
60595c635efSGarrett D'Amore 
60695c635efSGarrett D'Amore 	for (j = 0; buf[i] && ' ' != buf[i] && j < DELIMSZ; j++, i++)
60795c635efSGarrett D'Amore 		dbuf[j] = buf[i];
60895c635efSGarrett D'Amore 
60995c635efSGarrett D'Amore 	if (DELIMSZ == j)
610371584c2SYuri Pankov 		return 0;
61195c635efSGarrett D'Amore 
61295c635efSGarrett D'Amore 	dbuf[j] = '\0';
61395c635efSGarrett D'Amore 	if (DELIM_CLOSE != mdoc_isdelim(dbuf))
614371584c2SYuri Pankov 		return 0;
61595c635efSGarrett D'Amore 
61695c635efSGarrett D'Amore 	while (' ' == buf[i])
61795c635efSGarrett D'Amore 		i++;
61895c635efSGarrett D'Amore 
61995c635efSGarrett D'Amore 	/* Remaining must NOT be open/none. */
620260e9a87SYuri Pankov 
62195c635efSGarrett D'Amore 	while (buf[i]) {
62295c635efSGarrett D'Amore 		j = 0;
62395c635efSGarrett D'Amore 		while (buf[i] && ' ' != buf[i] && j < DELIMSZ)
62495c635efSGarrett D'Amore 			dbuf[j++] = buf[i++];
62595c635efSGarrett D'Amore 
62695c635efSGarrett D'Amore 		if (DELIMSZ == j)
627371584c2SYuri Pankov 			return 0;
62895c635efSGarrett D'Amore 
62995c635efSGarrett D'Amore 		dbuf[j] = '\0';
63095c635efSGarrett D'Amore 		d = mdoc_isdelim(dbuf);
63195c635efSGarrett D'Amore 		if (DELIM_NONE == d || DELIM_OPEN == d)
632371584c2SYuri Pankov 			return 0;
63395c635efSGarrett D'Amore 
63495c635efSGarrett D'Amore 		while (' ' == buf[i])
63595c635efSGarrett D'Amore 			i++;
63695c635efSGarrett D'Amore 	}
63795c635efSGarrett D'Amore 
638371584c2SYuri Pankov 	return '\0' == buf[i];
63995c635efSGarrett D'Amore }
64095c635efSGarrett D'Amore 
641260e9a87SYuri Pankov static void
argv_multi(struct roff_man * mdoc,int line,struct mdoc_argv * v,int * pos,char * buf)642371584c2SYuri Pankov argv_multi(struct roff_man *mdoc, int line,
64395c635efSGarrett D'Amore 		struct mdoc_argv *v, int *pos, char *buf)
64495c635efSGarrett D'Amore {
64595c635efSGarrett D'Amore 	enum margserr	 ac;
64695c635efSGarrett D'Amore 	char		*p;
64795c635efSGarrett D'Amore 
64895c635efSGarrett D'Amore 	for (v->sz = 0; ; v->sz++) {
649260e9a87SYuri Pankov 		if (buf[*pos] == '-')
65095c635efSGarrett D'Amore 			break;
651698f87a4SGarrett D'Amore 		ac = args(mdoc, line, pos, buf, ARGSFL_NONE, &p);
652260e9a87SYuri Pankov 		if (ac == ARGS_EOLN)
65395c635efSGarrett D'Amore 			break;
65495c635efSGarrett D'Amore 
655260e9a87SYuri Pankov 		if (v->sz % MULTI_STEP == 0)
656260e9a87SYuri Pankov 			v->value = mandoc_reallocarray(v->value,
657260e9a87SYuri Pankov 			    v->sz + MULTI_STEP, sizeof(char *));
65895c635efSGarrett D'Amore 
659cec8643bSMichal Nowak 		if (ac != ARGS_ALLOC)
660cec8643bSMichal Nowak 			p = mandoc_strdup(p);
661cec8643bSMichal Nowak 		v->value[(int)v->sz] = p;
66295c635efSGarrett D'Amore 	}
66395c635efSGarrett D'Amore }
66495c635efSGarrett D'Amore 
665260e9a87SYuri Pankov static void
argv_single(struct roff_man * mdoc,int line,struct mdoc_argv * v,int * pos,char * buf)666371584c2SYuri Pankov argv_single(struct roff_man *mdoc, int line,
66795c635efSGarrett D'Amore 		struct mdoc_argv *v, int *pos, char *buf)
66895c635efSGarrett D'Amore {
66995c635efSGarrett D'Amore 	enum margserr	 ac;
67095c635efSGarrett D'Amore 	char		*p;
67195c635efSGarrett D'Amore 
672698f87a4SGarrett D'Amore 	ac = args(mdoc, line, pos, buf, ARGSFL_NONE, &p);
673260e9a87SYuri Pankov 	if (ac == ARGS_EOLN)
674260e9a87SYuri Pankov 		return;
67595c635efSGarrett D'Amore 
676cec8643bSMichal Nowak 	if (ac != ARGS_ALLOC)
677cec8643bSMichal Nowak 		p = mandoc_strdup(p);
678cec8643bSMichal Nowak 
67995c635efSGarrett D'Amore 	v->sz = 1;
68095c635efSGarrett D'Amore 	v->value = mandoc_malloc(sizeof(char *));
681cec8643bSMichal Nowak 	v->value[0] = p;
68295c635efSGarrett D'Amore }
683