]> git.cameronkatri.com Git - mandoc.git/blob - argv.c
Lintified sources.
[mandoc.git] / argv.c
1 /* $Id: argv.c,v 1.33 2009/02/27 09:39:40 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
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
7 * above copyright notice and this permission notice appear in all
8 * copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17 * PERFORMANCE OF THIS SOFTWARE.
18 */
19 #include <assert.h>
20 #include <ctype.h>
21 #include <err.h>
22 #include <stdlib.h>
23 #include <stdio.h>
24 #include <string.h>
25
26 #include "private.h"
27
28 /*
29 * Routines to parse arguments of macros. Arguments follow the syntax
30 * of `-arg [val [valN...]]'. Arguments come in all types: quoted
31 * arguments, multiple arguments per value, no-value arguments, etc.
32 */
33
34 #define ARGS_QUOTED (1 << 0)
35 #define ARGS_DELIM (1 << 1)
36 #define ARGS_TABSEP (1 << 2)
37
38 static int argv_a2arg(int, const char *);
39 static int args(struct mdoc *, int, int *,
40 char *, int, char **);
41 static int argv(struct mdoc *, int,
42 struct mdoc_arg *, int *, char *);
43 static int argv_single(struct mdoc *, int,
44 struct mdoc_arg *, int *, char *);
45 static int argv_multi(struct mdoc *, int,
46 struct mdoc_arg *, int *, char *);
47 static int pwarn(struct mdoc *, int, int, int);
48 static int perr(struct mdoc *, int, int, int);
49
50 /* Warning messages. */
51
52 #define WQUOTPARM (0)
53 #define WARGVPARM (1)
54 #define WCOLEMPTY (2)
55 #define WTAILWS (3)
56
57 /* Error messages. */
58
59 #define EQUOTTERM (0)
60 #define EARGVAL (1)
61 #define EARGMANY (2)
62
63 static int mdoc_argflags[MDOC_MAX] = {
64 0, /* \" */
65 0, /* Dd */
66 0, /* Dt */
67 0, /* Os */
68 0, /* Sh */
69 0, /* Ss */
70 ARGS_DELIM, /* Pp */
71 ARGS_DELIM, /* D1 */
72 ARGS_DELIM, /* Dl */
73 0, /* Bd */
74 0, /* Ed */
75 0, /* Bl */
76 0, /* El */
77 0, /* It */
78 ARGS_DELIM, /* Ad */
79 ARGS_DELIM, /* An */
80 ARGS_DELIM, /* Ar */
81 ARGS_QUOTED, /* Cd */
82 ARGS_DELIM, /* Cm */
83 ARGS_DELIM, /* Dv */
84 ARGS_DELIM, /* Er */
85 ARGS_DELIM, /* Ev */
86 0, /* Ex */
87 ARGS_DELIM | ARGS_QUOTED, /* Fa */
88 0, /* Fd */
89 ARGS_DELIM, /* Fl */
90 ARGS_DELIM | ARGS_QUOTED, /* Fn */
91 ARGS_DELIM | ARGS_QUOTED, /* Ft */
92 ARGS_DELIM, /* Ic */
93 0, /* In */
94 ARGS_DELIM, /* Li */
95 0, /* Nd */
96 ARGS_DELIM, /* Nm */
97 ARGS_DELIM, /* Op */
98 0, /* Ot */
99 ARGS_DELIM, /* Pa */
100 0, /* Rv */
101 ARGS_DELIM, /* St */
102 ARGS_DELIM, /* Va */
103 ARGS_DELIM, /* Vt */
104 ARGS_DELIM, /* Xr */
105 ARGS_QUOTED, /* %A */
106 ARGS_QUOTED, /* %B */
107 ARGS_QUOTED, /* %D */
108 ARGS_QUOTED, /* %I */
109 ARGS_QUOTED, /* %J */
110 ARGS_QUOTED, /* %N */
111 ARGS_QUOTED, /* %O */
112 ARGS_QUOTED, /* %P */
113 ARGS_QUOTED, /* %R */
114 ARGS_QUOTED, /* %T */
115 ARGS_QUOTED, /* %V */
116 ARGS_DELIM, /* Ac */
117 0, /* Ao */
118 ARGS_DELIM, /* Aq */
119 ARGS_DELIM, /* At */
120 ARGS_DELIM, /* Bc */
121 0, /* Bf */
122 0, /* Bo */
123 ARGS_DELIM, /* Bq */
124 ARGS_DELIM, /* Bsx */
125 ARGS_DELIM, /* Bx */
126 0, /* Db */
127 ARGS_DELIM, /* Dc */
128 0, /* Do */
129 ARGS_DELIM, /* Dq */
130 ARGS_DELIM, /* Ec */
131 0, /* Ef */
132 ARGS_DELIM, /* Em */
133 0, /* Eo */
134 ARGS_DELIM, /* Fx */
135 ARGS_DELIM, /* Ms */
136 ARGS_DELIM, /* No */
137 ARGS_DELIM, /* Ns */
138 ARGS_DELIM, /* Nx */
139 ARGS_DELIM, /* Ox */
140 ARGS_DELIM, /* Pc */
141 ARGS_DELIM, /* Pf */
142 0, /* Po */
143 ARGS_DELIM, /* Pq */
144 ARGS_DELIM, /* Qc */
145 ARGS_DELIM, /* Ql */
146 0, /* Qo */
147 ARGS_DELIM, /* Qq */
148 0, /* Re */
149 0, /* Rs */
150 ARGS_DELIM, /* Sc */
151 0, /* So */
152 ARGS_DELIM, /* Sq */
153 0, /* Sm */
154 ARGS_DELIM, /* Sx */
155 ARGS_DELIM, /* Sy */
156 ARGS_DELIM, /* Tn */
157 ARGS_DELIM, /* Ux */
158 ARGS_DELIM, /* Xc */
159 0, /* Xo */
160 0, /* Fo */
161 0, /* Fc */
162 0, /* Oo */
163 ARGS_DELIM, /* Oc */
164 0, /* Bk */
165 0, /* Ek */
166 0, /* Bt */
167 0, /* Hf */
168 0, /* Fr */
169 0, /* Ud */
170 };
171
172
173 static int
174 perr(struct mdoc *mdoc, int line, int pos, int code)
175 {
176 int c;
177
178 switch (code) {
179 case (EQUOTTERM):
180 c = mdoc_perr(mdoc, line, pos,
181 "unterminated quoted parameter");
182 break;
183 case (EARGVAL):
184 c = mdoc_perr(mdoc, line, pos,
185 "argument requires a value");
186 break;
187 case (EARGMANY):
188 c = mdoc_perr(mdoc, line, pos,
189 "too many values for argument");
190 break;
191 default:
192 abort();
193 /* NOTREACHED */
194 }
195 return(c);
196 }
197
198
199 static int
200 pwarn(struct mdoc *mdoc, int line, int pos, int code)
201 {
202 int c;
203
204 switch (code) {
205 case (WQUOTPARM):
206 c = mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX,
207 "unexpected quoted parameter");
208 break;
209 case (WARGVPARM):
210 c = mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX,
211 "argument-like parameter");
212 break;
213 case (WCOLEMPTY):
214 c = mdoc_pwarn(mdoc, line, pos, WARN_SYNTAX,
215 "last list column is empty");
216 break;
217 case (WTAILWS):
218 c = mdoc_pwarn(mdoc, line, pos, WARN_COMPAT,
219 "trailing whitespace");
220 break;
221 default:
222 abort();
223 /* NOTREACHED */
224 }
225 return(c);
226 }
227
228
229 int
230 mdoc_args(struct mdoc *mdoc, int line,
231 int *pos, char *buf, int tok, char **v)
232 {
233 int fl, c, i;
234 struct mdoc_node *n;
235
236 fl = (0 == tok) ? 0 : mdoc_argflags[tok];
237
238 /*
239 * First see if we should use TABSEP (Bl -column). This
240 * invalidates the use of ARGS_DELIM.
241 */
242
243 if (MDOC_It == tok) {
244 for (n = mdoc->last; n; n = n->parent)
245 if (MDOC_BLOCK == n->type)
246 if (MDOC_Bl == n->tok)
247 break;
248 assert(n);
249 c = (int)n->data.block.argc;
250 assert(c > 0);
251
252 /* LINTED */
253 for (i = 0; i < c; i++) {
254 if (MDOC_Column != n->data.block.argv[i].arg)
255 continue;
256 fl |= ARGS_TABSEP;
257 fl &= ~ARGS_DELIM;
258 break;
259 }
260 }
261
262 return(args(mdoc, line, pos, buf, fl, v));
263 }
264
265
266 static int
267 args(struct mdoc *mdoc, int line,
268 int *pos, char *buf, int fl, char **v)
269 {
270 int i;
271 char *p, *pp;
272
273 assert(*pos > 0);
274
275 if (0 == buf[*pos])
276 return(ARGS_EOLN);
277
278 if ('\"' == buf[*pos] && ! (fl & ARGS_QUOTED))
279 if ( ! pwarn(mdoc, line, *pos, WQUOTPARM))
280 return(ARGS_ERROR);
281
282 if ('-' == buf[*pos])
283 if ( ! pwarn(mdoc, line, *pos, WARGVPARM))
284 return(ARGS_ERROR);
285
286 /*
287 * If the first character is a delimiter and we're to look for
288 * delimited strings, then pass down the buffer seeing if it
289 * follows the pattern of [[::delim::][ ]+]+.
290 */
291
292 if ((fl & ARGS_DELIM) && mdoc_iscdelim(buf[*pos])) {
293 for (i = *pos; buf[i]; ) {
294 if ( ! mdoc_iscdelim(buf[i]))
295 break;
296 i++;
297 while (buf[i] && isspace((int)buf[i]))
298 i++;
299 }
300 if (0 == buf[i]) {
301 *v = &buf[*pos];
302 return(ARGS_PUNCT);
303 }
304 }
305
306 /* First parse non-quoted strings. */
307
308 if ('\"' != buf[*pos] || ! (ARGS_QUOTED & fl)) {
309 *v = &buf[*pos];
310
311 /*
312 * Thar be dragons here! If we're tab-separated, search
313 * ahead for either a tab or the `Ta' macro. If a tab
314 * is detected, it mustn't be escaped; if a `Ta' is
315 * detected, it must be space-buffered before and after.
316 * If either of these hold true, then prune out the
317 * extra spaces and call it an argument.
318 */
319
320 if (ARGS_TABSEP & fl) {
321 /* Scan ahead to unescaped tab. */
322
323 for (p = *v; ; p++) {
324 if (NULL == (p = strchr(p, '\t')))
325 break;
326 if (p == *v)
327 break;
328 if ('\\' != *(p - 1))
329 break;
330 }
331
332 /* Scan ahead to unescaped `Ta'. */
333
334 for (pp = *v; ; pp++) {
335 if (NULL == (pp = strstr(pp, "Ta")))
336 break;
337 if (pp > *v && ' ' != *(pp - 1))
338 continue;
339 if (' ' == *(pp + 2) || 0 == *(pp + 2))
340 break;
341 }
342
343 /* Choose delimiter tab/Ta. */
344
345 if (p && pp)
346 p = (p < pp ? p : pp);
347 else if ( ! p && pp)
348 p = pp;
349
350 /* Strip delimiter's preceding whitespace. */
351
352 if (p && p > *v) {
353 pp = p - 1;
354 while (pp > *v && ' ' == *pp)
355 pp--;
356 if (pp == *v && ' ' == *pp)
357 *pp = 0;
358 else if (' ' == *pp)
359 *(pp + 1) = 0;
360 }
361
362 /* ...in- and proceding whitespace. */
363
364 if (p && ('\t' != *p)) {
365 *p++ = 0;
366 *p++ = 0;
367 } else if (p)
368 *p++ = 0;
369
370 if (p) {
371 while (' ' == *p)
372 p++;
373 if (0 != *p)
374 *(p - 1) = 0;
375 *pos += (int)(p - *v);
376 }
377
378 if (p && 0 == *p)
379 if ( ! pwarn(mdoc, line, *pos, WCOLEMPTY))
380 return(0);
381 if (p && 0 == *p && p > *v && ' ' == *(p - 1))
382 if ( ! pwarn(mdoc, line, *pos, WTAILWS))
383 return(0);
384
385 if (p)
386 return(ARGS_WORD);
387
388 /* Configure the eoln case, too. */
389
390 p = strchr(*v, 0);
391 assert(p);
392
393 if (p > *v && ' ' == *(p - 1))
394 if ( ! pwarn(mdoc, line, *pos, WTAILWS))
395 return(0);
396 *pos += (int)(p - *v);
397
398 return(ARGS_WORD);
399 }
400
401 /* Do non-tabsep look-ahead here. */
402
403 if ( ! (ARGS_TABSEP & fl))
404 while (buf[*pos]) {
405 if (isspace((int)buf[*pos]))
406 if ('\\' != buf[*pos - 1])
407 break;
408 (*pos)++;
409 }
410
411 if (0 == buf[*pos])
412 return(ARGS_WORD);
413
414 buf[(*pos)++] = 0;
415
416 if (0 == buf[*pos])
417 return(ARGS_WORD);
418
419 if ( ! (ARGS_TABSEP & fl))
420 while (buf[*pos] && isspace((int)buf[*pos]))
421 (*pos)++;
422
423 if (buf[*pos])
424 return(ARGS_WORD);
425
426 if ( ! pwarn(mdoc, line, *pos, WTAILWS))
427 return(ARGS_ERROR);
428
429 return(ARGS_WORD);
430 }
431
432 /*
433 * If we're a quoted string (and quoted strings are allowed),
434 * then parse ahead to the next quote. If none's found, it's an
435 * error. After, parse to the next word.
436 */
437
438 *v = &buf[++(*pos)];
439
440 while (buf[*pos] && '\"' != buf[*pos])
441 (*pos)++;
442
443 if (0 == buf[*pos]) {
444 (void)perr(mdoc, line, *pos, EQUOTTERM);
445 return(ARGS_ERROR);
446 }
447
448 buf[(*pos)++] = 0;
449 if (0 == buf[*pos])
450 return(ARGS_QWORD);
451
452 while (buf[*pos] && isspace((int)buf[*pos]))
453 (*pos)++;
454
455 if (buf[*pos])
456 return(ARGS_QWORD);
457
458 if ( ! pwarn(mdoc, line, *pos, WTAILWS))
459 return(ARGS_ERROR);
460
461 return(ARGS_QWORD);
462 }
463
464
465 static int
466 argv_a2arg(int tok, const char *argv)
467 {
468
469 switch (tok) {
470 case (MDOC_An):
471 if (xstrcmp(argv, "split"))
472 return(MDOC_Split);
473 else if (xstrcmp(argv, "nosplit"))
474 return(MDOC_Nosplit);
475 break;
476
477 case (MDOC_Bd):
478 if (xstrcmp(argv, "ragged"))
479 return(MDOC_Ragged);
480 else if (xstrcmp(argv, "unfilled"))
481 return(MDOC_Unfilled);
482 else if (xstrcmp(argv, "filled"))
483 return(MDOC_Filled);
484 else if (xstrcmp(argv, "literal"))
485 return(MDOC_Literal);
486 else if (xstrcmp(argv, "file"))
487 return(MDOC_File);
488 else if (xstrcmp(argv, "offset"))
489 return(MDOC_Offset);
490 break;
491
492 case (MDOC_Bf):
493 if (xstrcmp(argv, "emphasis"))
494 return(MDOC_Emphasis);
495 else if (xstrcmp(argv, "literal"))
496 return(MDOC_Literal);
497 else if (xstrcmp(argv, "symbolic"))
498 return(MDOC_Symbolic);
499 break;
500
501 case (MDOC_Bk):
502 if (xstrcmp(argv, "words"))
503 return(MDOC_Words);
504 break;
505
506 case (MDOC_Bl):
507 if (xstrcmp(argv, "bullet"))
508 return(MDOC_Bullet);
509 else if (xstrcmp(argv, "dash"))
510 return(MDOC_Dash);
511 else if (xstrcmp(argv, "hyphen"))
512 return(MDOC_Hyphen);
513 else if (xstrcmp(argv, "item"))
514 return(MDOC_Item);
515 else if (xstrcmp(argv, "enum"))
516 return(MDOC_Enum);
517 else if (xstrcmp(argv, "tag"))
518 return(MDOC_Tag);
519 else if (xstrcmp(argv, "diag"))
520 return(MDOC_Diag);
521 else if (xstrcmp(argv, "hang"))
522 return(MDOC_Hang);
523 else if (xstrcmp(argv, "ohang"))
524 return(MDOC_Ohang);
525 else if (xstrcmp(argv, "inset"))
526 return(MDOC_Inset);
527 else if (xstrcmp(argv, "column"))
528 return(MDOC_Column);
529 else if (xstrcmp(argv, "width"))
530 return(MDOC_Width);
531 else if (xstrcmp(argv, "offset"))
532 return(MDOC_Offset);
533 else if (xstrcmp(argv, "compact"))
534 return(MDOC_Compact);
535 break;
536
537 case (MDOC_Rv):
538 /* FALLTHROUGH */
539 case (MDOC_Ex):
540 if (xstrcmp(argv, "std"))
541 return(MDOC_Std);
542 break;
543
544 case (MDOC_St):
545 if (xstrcmp(argv, "p1003.1-88"))
546 return(MDOC_p1003_1_88);
547 else if (xstrcmp(argv, "p1003.1-90"))
548 return(MDOC_p1003_1_90);
549 else if (xstrcmp(argv, "p1003.1-96"))
550 return(MDOC_p1003_1_96);
551 else if (xstrcmp(argv, "p1003.1-2001"))
552 return(MDOC_p1003_1_2001);
553 else if (xstrcmp(argv, "p1003.1-2004"))
554 return(MDOC_p1003_1_2004);
555 else if (xstrcmp(argv, "p1003.1"))
556 return(MDOC_p1003_1);
557 else if (xstrcmp(argv, "p1003.1b"))
558 return(MDOC_p1003_1b);
559 else if (xstrcmp(argv, "p1003.1b-93"))
560 return(MDOC_p1003_1b_93);
561 else if (xstrcmp(argv, "p1003.1c-95"))
562 return(MDOC_p1003_1c_95);
563 else if (xstrcmp(argv, "p1003.1g-2000"))
564 return(MDOC_p1003_1g_2000);
565 else if (xstrcmp(argv, "p1003.2-92"))
566 return(MDOC_p1003_2_92);
567 else if (xstrcmp(argv, "p1003.2-95"))
568 return(MDOC_p1387_2_95);
569 else if (xstrcmp(argv, "p1003.2"))
570 return(MDOC_p1003_2);
571 else if (xstrcmp(argv, "p1387.2-95"))
572 return(MDOC_p1387_2);
573 else if (xstrcmp(argv, "isoC-90"))
574 return(MDOC_isoC_90);
575 else if (xstrcmp(argv, "isoC-amd1"))
576 return(MDOC_isoC_amd1);
577 else if (xstrcmp(argv, "isoC-tcor1"))
578 return(MDOC_isoC_tcor1);
579 else if (xstrcmp(argv, "isoC-tcor2"))
580 return(MDOC_isoC_tcor2);
581 else if (xstrcmp(argv, "isoC-99"))
582 return(MDOC_isoC_99);
583 else if (xstrcmp(argv, "ansiC"))
584 return(MDOC_ansiC);
585 else if (xstrcmp(argv, "ansiC-89"))
586 return(MDOC_ansiC_89);
587 else if (xstrcmp(argv, "ansiC-99"))
588 return(MDOC_ansiC_99);
589 else if (xstrcmp(argv, "ieee754"))
590 return(MDOC_ieee754);
591 else if (xstrcmp(argv, "iso8802-3"))
592 return(MDOC_iso8802_3);
593 else if (xstrcmp(argv, "xpg3"))
594 return(MDOC_xpg3);
595 else if (xstrcmp(argv, "xpg4"))
596 return(MDOC_xpg4);
597 else if (xstrcmp(argv, "xpg4.2"))
598 return(MDOC_xpg4_2);
599 else if (xstrcmp(argv, "xpg4.3"))
600 return(MDOC_xpg4_3);
601 else if (xstrcmp(argv, "xbd5"))
602 return(MDOC_xbd5);
603 else if (xstrcmp(argv, "xcu5"))
604 return(MDOC_xcu5);
605 else if (xstrcmp(argv, "xsh5"))
606 return(MDOC_xsh5);
607 else if (xstrcmp(argv, "xns5"))
608 return(MDOC_xns5);
609 else if (xstrcmp(argv, "xns5.2d2.0"))
610 return(MDOC_xns5_2d2_0);
611 else if (xstrcmp(argv, "xcurses4.2"))
612 return(MDOC_xcurses4_2);
613 else if (xstrcmp(argv, "susv2"))
614 return(MDOC_susv2);
615 else if (xstrcmp(argv, "susv3"))
616 return(MDOC_susv3);
617 else if (xstrcmp(argv, "svid4"))
618 return(MDOC_svid4);
619 break;
620
621 default:
622 break;
623 }
624
625 return(MDOC_ARG_MAX);
626 }
627
628
629 static int
630 argv_multi(struct mdoc *mdoc, int line,
631 struct mdoc_arg *v, int *pos, char *buf)
632 {
633 int c, ppos;
634 char *p;
635
636 v->sz = 0;
637 v->value = xcalloc(MDOC_LINEARG_MAX, sizeof(char *));
638
639 ppos = *pos;
640
641 for (v->sz = 0; v->sz < MDOC_LINEARG_MAX; v->sz++) {
642 if ('-' == buf[*pos])
643 break;
644 c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
645 if (ARGS_ERROR == c) {
646 free(v->value);
647 return(0);
648 } else if (ARGS_EOLN == c)
649 break;
650 v->value[(int)v->sz] = p;
651 }
652
653 if (0 < v->sz && v->sz < MDOC_LINEARG_MAX)
654 return(1);
655
656 free(v->value);
657 if (0 == v->sz)
658 return(perr(mdoc, line, ppos, EARGVAL));
659
660 return(perr(mdoc, line, ppos, EARGMANY));
661 }
662
663
664 static int
665 argv_single(struct mdoc *mdoc, int line,
666 struct mdoc_arg *v, int *pos, char *buf)
667 {
668 int c, ppos;
669 char *p;
670
671 ppos = *pos;
672
673 c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
674 if (ARGS_ERROR == c)
675 return(0);
676 if (ARGS_EOLN == c)
677 return(perr(mdoc, line, ppos, EARGVAL));
678
679 v->sz = 1;
680 v->value = xcalloc(1, sizeof(char *));
681 v->value[0] = p;
682 return(1);
683 }
684
685
686 static int
687 argv(struct mdoc *mdoc, int line,
688 struct mdoc_arg *v, int *pos, char *buf)
689 {
690
691 v->sz = 0;
692 v->value = NULL;
693
694 switch (v->arg) {
695 case(MDOC_Std):
696 /* FALLTHROUGH */
697 case(MDOC_Width):
698 /* FALLTHROUGH */
699 case(MDOC_Offset):
700 return(argv_single(mdoc, line, v, pos, buf));
701 case(MDOC_Column):
702 return(argv_multi(mdoc, line, v, pos, buf));
703 default:
704 break;
705 }
706
707 return(1);
708 }
709
710
711 int
712 mdoc_argv(struct mdoc *mdoc, int line, int tok,
713 struct mdoc_arg *v, int *pos, char *buf)
714 {
715 int i;
716 char *p;
717
718 (void)memset(v, 0, sizeof(struct mdoc_arg));
719
720 if (0 == buf[*pos])
721 return(ARGV_EOLN);
722
723 assert( ! isspace((int)buf[*pos]));
724
725 if ('-' != buf[*pos])
726 return(ARGV_WORD);
727
728 i = *pos;
729 p = &buf[++(*pos)];
730
731 v->line = line;
732 v->pos = *pos;
733
734 assert(*pos > 0);
735
736 /* LINTED */
737 while (buf[*pos]) {
738 if (isspace((int)buf[*pos]))
739 if ('\\' != buf[*pos - 1])
740 break;
741 (*pos)++;
742 }
743
744 if (buf[*pos])
745 buf[(*pos)++] = 0;
746
747 if (MDOC_ARG_MAX == (v->arg = argv_a2arg(tok, p))) {
748 if ( ! pwarn(mdoc, line, i, WARGVPARM))
749 return(ARGV_ERROR);
750 return(ARGV_WORD);
751 }
752
753 while (buf[*pos] && isspace((int)buf[*pos]))
754 (*pos)++;
755
756 /* FIXME: whitespace if no value. */
757
758 if ( ! argv(mdoc, line, v, pos, buf))
759 return(ARGV_ERROR);
760
761 return(ARGV_ARG);
762 }
763
764
765 void
766 mdoc_argv_free(int sz, struct mdoc_arg *arg)
767 {
768 int i;
769
770 for (i = 0; i < sz; i++) {
771 if (0 == arg[i].sz) {
772 assert(NULL == arg[i].value);
773 continue;
774 }
775 assert(arg[i].value);
776 free(arg[i].value);
777 }
778 }
779