]> git.cameronkatri.com Git - mandoc.git/blob - mdoc_argv.c
Clean-up in mdoc_argv.c args_checkpunct().
[mandoc.git] / mdoc_argv.c
1 /* $Id: mdoc_argv.c,v 1.69 2011/03/17 11:09:36 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
4 *
5 * Permission to use, copy, modify, and distribute this software for any
6 * purpose with or without fee is hereby granted, provided that the above
7 * copyright notice and this permission notice appear in all copies.
8 *
9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
16 */
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <sys/types.h>
22
23 #include <assert.h>
24 #include <ctype.h>
25 #include <stdlib.h>
26 #include <stdio.h>
27 #include <string.h>
28
29 #include "mandoc.h"
30 #include "libmdoc.h"
31 #include "libmandoc.h"
32
33 #define MULTI_STEP 5 /* pre-allocate argument values */
34
35 static enum mdocargt argv_a2arg(enum mdoct, const char *);
36 static enum margserr args(struct mdoc *, int, int *,
37 char *, int, char **);
38 static int args_checkpunct(struct mdoc *,
39 const char *, int, int, int);
40 static int argv(struct mdoc *, int,
41 struct mdoc_argv *, int *, char *);
42 static int argv_single(struct mdoc *, int,
43 struct mdoc_argv *, int *, char *);
44 static int argv_opt_single(struct mdoc *, int,
45 struct mdoc_argv *, int *, char *);
46 static int argv_multi(struct mdoc *, int,
47 struct mdoc_argv *, int *, char *);
48
49 enum argvflag {
50 ARGV_NONE, /* no args to flag (e.g., -split) */
51 ARGV_SINGLE, /* one arg to flag (e.g., -file xxx) */
52 ARGV_MULTI, /* multiple args (e.g., -column xxx yyy) */
53 ARGV_OPT_SINGLE /* optional arg (e.g., -offset [xxx]) */
54 };
55
56 static const enum argvflag argvflags[MDOC_ARG_MAX] = {
57 ARGV_NONE, /* MDOC_Split */
58 ARGV_NONE, /* MDOC_Nosplit */
59 ARGV_NONE, /* MDOC_Ragged */
60 ARGV_NONE, /* MDOC_Unfilled */
61 ARGV_NONE, /* MDOC_Literal */
62 ARGV_SINGLE, /* MDOC_File */
63 ARGV_OPT_SINGLE, /* MDOC_Offset */
64 ARGV_NONE, /* MDOC_Bullet */
65 ARGV_NONE, /* MDOC_Dash */
66 ARGV_NONE, /* MDOC_Hyphen */
67 ARGV_NONE, /* MDOC_Item */
68 ARGV_NONE, /* MDOC_Enum */
69 ARGV_NONE, /* MDOC_Tag */
70 ARGV_NONE, /* MDOC_Diag */
71 ARGV_NONE, /* MDOC_Hang */
72 ARGV_NONE, /* MDOC_Ohang */
73 ARGV_NONE, /* MDOC_Inset */
74 ARGV_MULTI, /* MDOC_Column */
75 ARGV_SINGLE, /* MDOC_Width */
76 ARGV_NONE, /* MDOC_Compact */
77 ARGV_NONE, /* MDOC_Std */
78 ARGV_NONE, /* MDOC_Filled */
79 ARGV_NONE, /* MDOC_Words */
80 ARGV_NONE, /* MDOC_Emphasis */
81 ARGV_NONE, /* MDOC_Symbolic */
82 ARGV_NONE /* MDOC_Symbolic */
83 };
84
85 static const int argflags[MDOC_MAX] = {
86 0, /* Ap */
87 0, /* Dd */
88 0, /* Dt */
89 0, /* Os */
90 0, /* Sh */
91 0, /* Ss */
92 0, /* Pp */
93 ARGS_DELIM, /* D1 */
94 ARGS_DELIM, /* Dl */
95 0, /* Bd */
96 0, /* Ed */
97 0, /* Bl */
98 0, /* El */
99 0, /* It */
100 ARGS_DELIM, /* Ad */
101 ARGS_DELIM, /* An */
102 ARGS_DELIM, /* Ar */
103 0, /* Cd */
104 ARGS_DELIM, /* Cm */
105 ARGS_DELIM, /* Dv */
106 ARGS_DELIM, /* Er */
107 ARGS_DELIM, /* Ev */
108 0, /* Ex */
109 ARGS_DELIM, /* Fa */
110 0, /* Fd */
111 ARGS_DELIM, /* Fl */
112 ARGS_DELIM, /* Fn */
113 ARGS_DELIM, /* Ft */
114 ARGS_DELIM, /* Ic */
115 0, /* In */
116 ARGS_DELIM, /* Li */
117 0, /* Nd */
118 ARGS_DELIM, /* Nm */
119 ARGS_DELIM, /* Op */
120 0, /* Ot */
121 ARGS_DELIM, /* Pa */
122 0, /* Rv */
123 ARGS_DELIM, /* St */
124 ARGS_DELIM, /* Va */
125 ARGS_DELIM, /* Vt */
126 ARGS_DELIM, /* Xr */
127 0, /* %A */
128 0, /* %B */
129 0, /* %D */
130 0, /* %I */
131 0, /* %J */
132 0, /* %N */
133 0, /* %O */
134 0, /* %P */
135 0, /* %R */
136 0, /* %T */
137 0, /* %V */
138 ARGS_DELIM, /* Ac */
139 0, /* Ao */
140 ARGS_DELIM, /* Aq */
141 ARGS_DELIM, /* At */
142 ARGS_DELIM, /* Bc */
143 0, /* Bf */
144 0, /* Bo */
145 ARGS_DELIM, /* Bq */
146 ARGS_DELIM, /* Bsx */
147 ARGS_DELIM, /* Bx */
148 0, /* Db */
149 ARGS_DELIM, /* Dc */
150 0, /* Do */
151 ARGS_DELIM, /* Dq */
152 ARGS_DELIM, /* Ec */
153 0, /* Ef */
154 ARGS_DELIM, /* Em */
155 0, /* Eo */
156 ARGS_DELIM, /* Fx */
157 ARGS_DELIM, /* Ms */
158 ARGS_DELIM, /* No */
159 ARGS_DELIM, /* Ns */
160 ARGS_DELIM, /* Nx */
161 ARGS_DELIM, /* Ox */
162 ARGS_DELIM, /* Pc */
163 ARGS_DELIM, /* Pf */
164 0, /* Po */
165 ARGS_DELIM, /* Pq */
166 ARGS_DELIM, /* Qc */
167 ARGS_DELIM, /* Ql */
168 0, /* Qo */
169 ARGS_DELIM, /* Qq */
170 0, /* Re */
171 0, /* Rs */
172 ARGS_DELIM, /* Sc */
173 0, /* So */
174 ARGS_DELIM, /* Sq */
175 0, /* Sm */
176 ARGS_DELIM, /* Sx */
177 ARGS_DELIM, /* Sy */
178 ARGS_DELIM, /* Tn */
179 ARGS_DELIM, /* Ux */
180 ARGS_DELIM, /* Xc */
181 0, /* Xo */
182 0, /* Fo */
183 0, /* Fc */
184 0, /* Oo */
185 ARGS_DELIM, /* Oc */
186 0, /* Bk */
187 0, /* Ek */
188 0, /* Bt */
189 0, /* Hf */
190 0, /* Fr */
191 0, /* Ud */
192 0, /* Lb */
193 0, /* Lp */
194 ARGS_DELIM, /* Lk */
195 ARGS_DELIM, /* Mt */
196 ARGS_DELIM, /* Brq */
197 0, /* Bro */
198 ARGS_DELIM, /* Brc */
199 0, /* %C */
200 0, /* Es */
201 0, /* En */
202 0, /* Dx */
203 0, /* %Q */
204 0, /* br */
205 0, /* sp */
206 0, /* %U */
207 0, /* Ta */
208 };
209
210 /*
211 * Parse an argument from line text. This comes in the form of -key
212 * [value0...], which may either have a single mandatory value, at least
213 * one mandatory value, an optional single value, or no value.
214 */
215 enum margverr
216 mdoc_argv(struct mdoc *m, int line, enum mdoct tok,
217 struct mdoc_arg **v, int *pos, char *buf)
218 {
219 char *p, sv;
220 struct mdoc_argv tmp;
221 struct mdoc_arg *arg;
222
223 if ('\0' == buf[*pos])
224 return(ARGV_EOLN);
225
226 assert(' ' != buf[*pos]);
227
228 /* Parse through to the first unescaped space. */
229
230 p = &buf[++(*pos)];
231
232 assert(*pos > 0);
233
234 /* LINTED */
235 while (buf[*pos]) {
236 if (' ' == buf[*pos])
237 if ('\\' != buf[*pos - 1])
238 break;
239 (*pos)++;
240 }
241
242 /* XXX - save zeroed byte, if not an argument. */
243
244 sv = '\0';
245 if (buf[*pos]) {
246 sv = buf[*pos];
247 buf[(*pos)++] = '\0';
248 }
249
250 memset(&tmp, 0, sizeof(struct mdoc_argv));
251 tmp.line = line;
252 tmp.pos = *pos;
253
254 /* See if our token accepts the argument. */
255
256 if (MDOC_ARG_MAX == (tmp.arg = argv_a2arg(tok, p))) {
257 /* XXX - restore saved zeroed byte. */
258 if (sv)
259 buf[*pos - 1] = sv;
260 return(ARGV_WORD);
261 }
262
263 while (buf[*pos] && ' ' == buf[*pos])
264 (*pos)++;
265
266 if ( ! argv(m, line, &tmp, pos, buf))
267 return(ARGV_ERROR);
268
269 if (NULL == (arg = *v))
270 arg = *v = mandoc_calloc(1, sizeof(struct mdoc_arg));
271
272 arg->argc++;
273 arg->argv = mandoc_realloc
274 (arg->argv, arg->argc * sizeof(struct mdoc_argv));
275
276 memcpy(&arg->argv[(int)arg->argc - 1],
277 &tmp, sizeof(struct mdoc_argv));
278
279 return(ARGV_ARG);
280 }
281
282 void
283 mdoc_argv_free(struct mdoc_arg *p)
284 {
285 int i;
286
287 if (NULL == p)
288 return;
289
290 if (p->refcnt) {
291 --(p->refcnt);
292 if (p->refcnt)
293 return;
294 }
295 assert(p->argc);
296
297 for (i = (int)p->argc - 1; i >= 0; i--)
298 mdoc_argn_free(p, i);
299
300 free(p->argv);
301 free(p);
302 }
303
304 void
305 mdoc_argn_free(struct mdoc_arg *p, int iarg)
306 {
307 struct mdoc_argv *arg;
308 int j;
309
310 arg = &p->argv[iarg];
311
312 if (arg->sz && arg->value) {
313 for (j = (int)arg->sz - 1; j >= 0; j--)
314 free(arg->value[j]);
315 free(arg->value);
316 }
317
318 for (--p->argc; iarg < (int)p->argc; iarg++)
319 p->argv[iarg] = p->argv[iarg+1];
320 }
321
322 enum margserr
323 mdoc_zargs(struct mdoc *m, int line, int *pos,
324 char *buf, int flags, char **v)
325 {
326
327 return(args(m, line, pos, buf, flags, v));
328 }
329
330 enum margserr
331 mdoc_args(struct mdoc *m, int line, int *pos,
332 char *buf, enum mdoct tok, char **v)
333 {
334 int fl;
335 struct mdoc_node *n;
336
337 fl = argflags[tok];
338
339 if (MDOC_It != tok)
340 return(args(m, line, pos, buf, fl, v));
341
342 /*
343 * We know that we're in an `It', so it's reasonable to expect
344 * us to be sitting in a `Bl'. Someday this may not be the case
345 * (if we allow random `It's sitting out there), so provide a
346 * safe fall-back into the default behaviour.
347 */
348
349 for (n = m->last; n; n = n->parent)
350 if (MDOC_Bl == n->tok)
351 break;
352
353 if (n && LIST_column == n->norm->Bl.type) {
354 fl |= ARGS_TABSEP;
355 fl &= ~ARGS_DELIM;
356 }
357
358 return(args(m, line, pos, buf, fl, v));
359 }
360
361 static enum margserr
362 args(struct mdoc *m, int line, int *pos,
363 char *buf, int fl, char **v)
364 {
365 char *p, *pp;
366 enum margserr rc;
367
368 /*
369 * Parse out the terms (like `val' in `.Xx -arg val' or simply
370 * `.Xx val'), which can have all sorts of properties:
371 *
372 * ARGS_DELIM: use special handling if encountering trailing
373 * delimiters in the form of [[::delim::][ ]+]+.
374 *
375 * ARGS_NOWARN: don't post warnings. This is only used when
376 * re-parsing delimiters, as the warnings have already been
377 * posted.
378 *
379 * ARGS_TABSEP: use special handling for tab/`Ta' separated
380 * phrases like in `Bl -column'.
381 */
382
383 assert(' ' != buf[*pos]);
384
385 if ('\0' == buf[*pos]) {
386 if (MDOC_PPHRASE & m->flags)
387 return(ARGS_EOLN);
388 /*
389 * If we're not in a partial phrase and the flag for
390 * being a phrase literal is still set, the punctuation
391 * is unterminated.
392 */
393 if (MDOC_PHRASELIT & m->flags)
394 mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE);
395
396 m->flags &= ~MDOC_PHRASELIT;
397 return(ARGS_EOLN);
398 }
399
400 *v = &buf[*pos];
401
402 if (ARGS_DELIM & fl && args_checkpunct(m, buf, *pos, line, fl))
403 return(ARGS_PUNCT);
404
405 /*
406 * First handle TABSEP items, restricted to `Bl -column'. This
407 * ignores conventional token parsing and instead uses tabs or
408 * `Ta' macros to separate phrases. Phrases are parsed again
409 * for arguments at a later phase.
410 */
411
412 if (ARGS_TABSEP & fl) {
413 /* Scan ahead to tab (can't be escaped). */
414 p = strchr(*v, '\t');
415 pp = NULL;
416
417 /* Scan ahead to unescaped `Ta'. */
418 if ( ! (MDOC_PHRASELIT & m->flags))
419 for (pp = *v; ; pp++) {
420 if (NULL == (pp = strstr(pp, "Ta")))
421 break;
422 if (pp > *v && ' ' != *(pp - 1))
423 continue;
424 if (' ' == *(pp + 2) || '\0' == *(pp + 2))
425 break;
426 }
427
428 /* By default, assume a phrase. */
429 rc = ARGS_PHRASE;
430
431 /*
432 * Adjust new-buffer position to be beyond delimiter
433 * mark (e.g., Ta -> end + 2).
434 */
435 if (p && pp) {
436 *pos += pp < p ? 2 : 1;
437 rc = pp < p ? ARGS_PHRASE : ARGS_PPHRASE;
438 p = pp < p ? pp : p;
439 } else if (p && ! pp) {
440 rc = ARGS_PPHRASE;
441 *pos += 1;
442 } else if (pp && ! p) {
443 p = pp;
444 *pos += 2;
445 } else {
446 rc = ARGS_PEND;
447 p = strchr(*v, 0);
448 }
449
450 /* Whitespace check for eoln case... */
451 if ('\0' == *p && ' ' == *(p - 1) && ! (ARGS_NOWARN & fl))
452 mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE);
453
454 *pos += (int)(p - *v);
455
456 /* Strip delimiter's preceding whitespace. */
457 pp = p - 1;
458 while (pp > *v && ' ' == *pp) {
459 if (pp > *v && '\\' == *(pp - 1))
460 break;
461 pp--;
462 }
463 *(pp + 1) = 0;
464
465 /* Strip delimiter's proceeding whitespace. */
466 for (pp = &buf[*pos]; ' ' == *pp; pp++, (*pos)++)
467 /* Skip ahead. */ ;
468
469 return(rc);
470 }
471
472 /*
473 * Process a quoted literal. A quote begins with a double-quote
474 * and ends with a double-quote NOT preceded by a double-quote.
475 * Whitespace is NOT involved in literal termination.
476 */
477
478 if (MDOC_PHRASELIT & m->flags || '\"' == buf[*pos]) {
479 if ( ! (MDOC_PHRASELIT & m->flags))
480 *v = &buf[++(*pos)];
481
482 if (MDOC_PPHRASE & m->flags)
483 m->flags |= MDOC_PHRASELIT;
484
485 for ( ; buf[*pos]; (*pos)++) {
486 if ('\"' != buf[*pos])
487 continue;
488 if ('\"' != buf[*pos + 1])
489 break;
490 (*pos)++;
491 }
492
493 if ('\0' == buf[*pos]) {
494 if (ARGS_NOWARN & fl || MDOC_PPHRASE & m->flags)
495 return(ARGS_QWORD);
496 mdoc_pmsg(m, line, *pos, MANDOCERR_BADQUOTE);
497 return(ARGS_QWORD);
498 }
499
500 m->flags &= ~MDOC_PHRASELIT;
501 buf[(*pos)++] = '\0';
502
503 if ('\0' == buf[*pos])
504 return(ARGS_QWORD);
505
506 while (' ' == buf[*pos])
507 (*pos)++;
508
509 if (0 == buf[*pos] && ! (ARGS_NOWARN & fl))
510 mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE);
511
512 return(ARGS_QWORD);
513 }
514
515 /*
516 * A non-quoted term progresses until either the end of line or
517 * a non-escaped whitespace.
518 */
519
520 for ( ; buf[*pos]; (*pos)++)
521 if (*pos && ' ' == buf[*pos] && '\\' != buf[*pos - 1])
522 break;
523
524 if ('\0' == buf[*pos])
525 return(ARGS_WORD);
526
527 buf[(*pos)++] = '\0';
528
529 while (' ' == buf[*pos])
530 (*pos)++;
531
532 if ('\0' == buf[*pos] && ! (ARGS_NOWARN & fl))
533 mdoc_pmsg(m, line, *pos, MANDOCERR_EOLNSPACE);
534
535 return(ARGS_WORD);
536 }
537
538 /*
539 * Check if the string consists only of space-separated closing
540 * delimiters. This is a bit of a dance: the first must be a close
541 * delimiter, but it may be followed by middle delimiters. Arbitrary
542 * whitespace may separate these tokens.
543 */
544 static int
545 args_checkpunct(struct mdoc *m, const char *buf, int i, int ln, int fl)
546 {
547 int j;
548 char dbuf[DELIMSZ];
549 enum mdelim d;
550
551 /* First token must be a close-delimiter. */
552
553 for (j = 0; buf[i] && ' ' != buf[i] && j < DELIMSZ; j++, i++)
554 dbuf[j] = buf[i];
555
556 if (DELIMSZ == j)
557 return(0);
558
559 dbuf[j] = '\0';
560 if (DELIM_CLOSE != mandoc_isdelim(dbuf))
561 return(0);
562
563 while (' ' == buf[i])
564 i++;
565
566 /* Remaining must NOT be open/none. */
567
568 while (buf[i]) {
569 j = 0;
570 while (buf[i] && ' ' != buf[i] && j < DELIMSZ)
571 dbuf[j++] = buf[i++];
572
573 if (DELIMSZ == j)
574 return(0);
575
576 dbuf[j] = '\0';
577 d = mandoc_isdelim(dbuf);
578 if (DELIM_NONE == d || DELIM_OPEN == d)
579 return(0);
580
581 while (' ' == buf[i])
582 i++;
583 }
584
585 if ( ! (ARGS_NOWARN & fl) && i && ' ' == buf[i - 1])
586 mdoc_pmsg(m, ln, i - 1, MANDOCERR_EOLNSPACE);
587
588 return('\0' == buf[i]);
589 }
590
591 /*
592 * Match up an argument string (e.g., `-foo bar' having "foo") with the
593 * correrct identifier. It must apply to the given macro. If none was
594 * found (including bad matches), return MDOC_ARG_MAX.
595 */
596 static enum mdocargt
597 argv_a2arg(enum mdoct tok, const char *p)
598 {
599 enum mdocargt args[MDOC_ARG_MAX];
600 int i, len;
601
602 len = 0;
603
604 switch (tok) {
605 case (MDOC_An):
606 args[len++] = MDOC_Split;
607 args[len++] = MDOC_Nosplit;
608 break;
609 case (MDOC_Bd):
610 args[len++] = MDOC_Ragged;
611 args[len++] = MDOC_Unfilled;
612 args[len++] = MDOC_Filled;
613 args[len++] = MDOC_Literal;
614 args[len++] = MDOC_File;
615 args[len++] = MDOC_Offset;
616 args[len++] = MDOC_Compact;
617 args[len++] = MDOC_Centred;
618 break;
619 case (MDOC_Bf):
620 args[len++] = MDOC_Emphasis;
621 args[len++] = MDOC_Literal;
622 args[len++] = MDOC_Symbolic;
623 break;
624 case (MDOC_Bk):
625 args[len++] = MDOC_Words;
626 break;
627 case (MDOC_Bl):
628 args[len++] = MDOC_Bullet;
629 args[len++] = MDOC_Dash;
630 args[len++] = MDOC_Hyphen;
631 args[len++] = MDOC_Item;
632 args[len++] = MDOC_Enum;
633 args[len++] = MDOC_Tag;
634 args[len++] = MDOC_Diag;
635 args[len++] = MDOC_Hang;
636 args[len++] = MDOC_Ohang;
637 args[len++] = MDOC_Inset;
638 args[len++] = MDOC_Column;
639 args[len++] = MDOC_Width;
640 args[len++] = MDOC_Offset;
641 args[len++] = MDOC_Compact;
642 args[len++] = MDOC_Nested;
643 break;
644 case (MDOC_Rv):
645 /* FALLTHROUGH */
646 case (MDOC_Ex):
647 args[len++] = MDOC_Std;
648 break;
649 default:
650 break;
651 }
652
653 for (i = 0; i < len; i++)
654 if (0 == strcmp(p, mdoc_argnames[args[i]]))
655 return(args[i]);
656
657 return(MDOC_ARG_MAX);
658 }
659
660 static int
661 argv_multi(struct mdoc *m, int line,
662 struct mdoc_argv *v, int *pos, char *buf)
663 {
664 enum margserr ac;
665 char *p;
666
667 for (v->sz = 0; ; v->sz++) {
668 if ('-' == buf[*pos])
669 break;
670 ac = args(m, line, pos, buf, 0, &p);
671 if (ARGS_ERROR == ac)
672 return(0);
673 else if (ARGS_EOLN == ac)
674 break;
675
676 if (0 == v->sz % MULTI_STEP)
677 v->value = mandoc_realloc(v->value,
678 (v->sz + MULTI_STEP) * sizeof(char *));
679
680 v->value[(int)v->sz] = mandoc_strdup(p);
681 }
682
683 return(1);
684 }
685
686 static int
687 argv_opt_single(struct mdoc *m, int line,
688 struct mdoc_argv *v, int *pos, char *buf)
689 {
690 enum margserr ac;
691 char *p;
692
693 if ('-' == buf[*pos])
694 return(1);
695
696 ac = args(m, line, pos, buf, 0, &p);
697 if (ARGS_ERROR == ac)
698 return(0);
699 if (ARGS_EOLN == ac)
700 return(1);
701
702 v->sz = 1;
703 v->value = mandoc_malloc(sizeof(char *));
704 v->value[0] = mandoc_strdup(p);
705
706 return(1);
707 }
708
709 /*
710 * Parse a single, mandatory value from the stream.
711 */
712 static int
713 argv_single(struct mdoc *m, int line,
714 struct mdoc_argv *v, int *pos, char *buf)
715 {
716 int ppos;
717 enum margserr ac;
718 char *p;
719
720 ppos = *pos;
721
722 ac = args(m, line, pos, buf, 0, &p);
723 if (ARGS_EOLN == ac) {
724 mdoc_pmsg(m, line, ppos, MANDOCERR_SYNTARGVCOUNT);
725 return(0);
726 } else if (ARGS_ERROR == ac)
727 return(0);
728
729 v->sz = 1;
730 v->value = mandoc_malloc(sizeof(char *));
731 v->value[0] = mandoc_strdup(p);
732
733 return(1);
734 }
735
736 /*
737 * Determine rules for parsing arguments. Arguments can either accept
738 * no parameters, an optional single parameter, one parameter, or
739 * multiple parameters.
740 */
741 static int
742 argv(struct mdoc *mdoc, int line,
743 struct mdoc_argv *v, int *pos, char *buf)
744 {
745
746 v->sz = 0;
747 v->value = NULL;
748
749 switch (argvflags[v->arg]) {
750 case (ARGV_SINGLE):
751 return(argv_single(mdoc, line, v, pos, buf));
752 case (ARGV_MULTI):
753 return(argv_multi(mdoc, line, v, pos, buf));
754 case (ARGV_OPT_SINGLE):
755 return(argv_opt_single(mdoc, line, v, pos, buf));
756 case (ARGV_NONE):
757 break;
758 default:
759 abort();
760 /* NOTREACHED */
761 }
762
763 return(1);
764 }