]> git.cameronkatri.com Git - mandoc.git/blob - argv.c
Adding revamped webpage.
[mandoc.git] / argv.c
1 /* $Id: argv.c,v 1.28 2009/02/23 15:19:47 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 lookup(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 ARGS_DELIM, /* 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, c;
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; (c = buf[i]); ) {
294 if ( ! mdoc_iscdelim(c))
295 break;
296 i++;
297 if (0 == buf[i] || ! isspace(c))
298 break;
299 i++;
300 while (buf[i] && isspace(c))
301 i++;
302 }
303 if (0 == buf[i]) {
304 *v = &buf[*pos];
305 return(ARGS_PUNCT);
306 }
307 }
308
309 /* First parse non-quoted strings. */
310
311 if ('\"' != buf[*pos] || ! (ARGS_QUOTED & fl)) {
312 *v = &buf[*pos];
313
314 /*
315 * Thar be dragons here! If we're tab-separated, search
316 * ahead for either a tab or the `Ta' macro. If a tab
317 * is detected, it mustn't be escaped; if a `Ta' is
318 * detected, it must be space-buffered before and after.
319 * If either of these hold true, then prune out the
320 * extra spaces and call it an argument.
321 */
322
323 if (ARGS_TABSEP & fl) {
324 /* Scan ahead to unescaped tab. */
325
326 for (p = *v; ; p++) {
327 if (NULL == (p = strchr(p, '\t')))
328 break;
329 if (p == *v)
330 break;
331 if ('\\' != *(p - 1))
332 break;
333 }
334
335 /* Scan ahead to unescaped `Ta'. */
336
337 for (pp = *v; ; pp++) {
338 if (NULL == (pp = strstr(pp, "Ta")))
339 break;
340 if (pp > *v && ' ' != *(pp - 1))
341 continue;
342 if (' ' == *(pp + 2) || 0 == *(pp + 2))
343 break;
344 }
345
346 /* Choose delimiter tab/Ta. */
347
348 if (p && pp)
349 p = (p < pp ? p : pp);
350 else if ( ! p && pp)
351 p = pp;
352
353 /* Strip delimiter's preceding whitespace. */
354
355 if (p && p > *v) {
356 pp = p - 1;
357 while (pp > *v && ' ' == *pp)
358 pp--;
359 if (pp == *v && ' ' == *pp)
360 *pp = 0;
361 else if (' ' == *pp)
362 *(pp + 1) = 0;
363 }
364
365 /* ...in- and proceding whitespace. */
366
367 if (p && ('\t' != *p)) {
368 *p++ = 0;
369 *p++ = 0;
370 } else if (p)
371 *p++ = 0;
372
373 if (p) {
374 while (' ' == *p)
375 p++;
376 if (0 != *p)
377 *(p - 1) = 0;
378 *pos += p - *v;
379 }
380
381 if (p && 0 == *p)
382 if ( ! pwarn(mdoc, line, *pos, WCOLEMPTY))
383 return(0);
384 if (p && 0 == *p && p > *v && ' ' == *(p - 1))
385 if ( ! pwarn(mdoc, line, *pos, WTAILWS))
386 return(0);
387
388 if (p)
389 return(ARGS_WORD);
390
391 /* Configure the eoln case, too. */
392
393 p = strchr(*v, 0);
394 assert(p);
395
396 if (p > *v && ' ' == *(p - 1))
397 if ( ! pwarn(mdoc, line, *pos, WTAILWS))
398 return(0);
399 *pos += p - *v;
400
401 return(ARGS_WORD);
402 }
403
404 /* Do non-tabsep look-ahead here. */
405
406 if ( ! (ARGS_TABSEP & fl))
407 while ((c = buf[*pos])) {
408 if (isspace(c))
409 if ('\\' != buf[*pos - 1])
410 break;
411 (*pos)++;
412 }
413
414 if (0 == buf[*pos])
415 return(ARGS_WORD);
416
417 buf[(*pos)++] = 0;
418
419 if (0 == buf[*pos])
420 return(ARGS_WORD);
421
422 if ( ! (ARGS_TABSEP & fl))
423 while (buf[*pos] && isspace((int)buf[*pos]))
424 (*pos)++;
425
426 if (buf[*pos])
427 return(ARGS_WORD);
428
429 if ( ! pwarn(mdoc, line, *pos, WTAILWS))
430 return(ARGS_ERROR);
431
432 return(ARGS_WORD);
433 }
434
435 /*
436 * If we're a quoted string (and quoted strings are allowed),
437 * then parse ahead to the next quote. If none's found, it's an
438 * error. After, parse to the next word.
439 */
440
441 *v = &buf[++(*pos)];
442
443 while (buf[*pos] && '\"' != buf[*pos])
444 (*pos)++;
445
446 if (0 == buf[*pos]) {
447 (void)perr(mdoc, line, *pos, EQUOTTERM);
448 return(ARGS_ERROR);
449 }
450
451 buf[(*pos)++] = 0;
452 if (0 == buf[*pos])
453 return(ARGS_QWORD);
454
455 while (buf[*pos] && isspace((int)buf[*pos]))
456 (*pos)++;
457
458 if (buf[*pos])
459 return(ARGS_QWORD);
460
461 if ( ! pwarn(mdoc, line, *pos, WTAILWS))
462 return(ARGS_ERROR);
463
464 return(ARGS_QWORD);
465 }
466
467
468 static int
469 lookup(int tok, const char *argv)
470 {
471
472 switch (tok) {
473 case (MDOC_An):
474 if (xstrcmp(argv, "split"))
475 return(MDOC_Split);
476 else if (xstrcmp(argv, "nosplit"))
477 return(MDOC_Nosplit);
478 break;
479
480 case (MDOC_Bd):
481 if (xstrcmp(argv, "ragged"))
482 return(MDOC_Ragged);
483 else if (xstrcmp(argv, "unfilled"))
484 return(MDOC_Unfilled);
485 else if (xstrcmp(argv, "filled"))
486 return(MDOC_Filled);
487 else if (xstrcmp(argv, "literal"))
488 return(MDOC_Literal);
489 else if (xstrcmp(argv, "file"))
490 return(MDOC_File);
491 else if (xstrcmp(argv, "offset"))
492 return(MDOC_Offset);
493 break;
494
495 case (MDOC_Bf):
496 if (xstrcmp(argv, "emphasis"))
497 return(MDOC_Emphasis);
498 else if (xstrcmp(argv, "literal"))
499 return(MDOC_Literal);
500 else if (xstrcmp(argv, "symbolic"))
501 return(MDOC_Symbolic);
502 break;
503
504 case (MDOC_Bk):
505 if (xstrcmp(argv, "words"))
506 return(MDOC_Words);
507 break;
508
509 case (MDOC_Bl):
510 if (xstrcmp(argv, "bullet"))
511 return(MDOC_Bullet);
512 else if (xstrcmp(argv, "dash"))
513 return(MDOC_Dash);
514 else if (xstrcmp(argv, "hyphen"))
515 return(MDOC_Hyphen);
516 else if (xstrcmp(argv, "item"))
517 return(MDOC_Item);
518 else if (xstrcmp(argv, "enum"))
519 return(MDOC_Enum);
520 else if (xstrcmp(argv, "tag"))
521 return(MDOC_Tag);
522 else if (xstrcmp(argv, "diag"))
523 return(MDOC_Diag);
524 else if (xstrcmp(argv, "hang"))
525 return(MDOC_Hang);
526 else if (xstrcmp(argv, "ohang"))
527 return(MDOC_Ohang);
528 else if (xstrcmp(argv, "inset"))
529 return(MDOC_Inset);
530 else if (xstrcmp(argv, "column"))
531 return(MDOC_Column);
532 else if (xstrcmp(argv, "width"))
533 return(MDOC_Width);
534 else if (xstrcmp(argv, "offset"))
535 return(MDOC_Offset);
536 else if (xstrcmp(argv, "compact"))
537 return(MDOC_Compact);
538 break;
539
540 case (MDOC_Rv):
541 /* FALLTHROUGH */
542 case (MDOC_Ex):
543 if (xstrcmp(argv, "std"))
544 return(MDOC_Std);
545 break;
546
547 case (MDOC_St):
548 if (xstrcmp(argv, "p1003.1-88"))
549 return(MDOC_p1003_1_88);
550 else if (xstrcmp(argv, "p1003.1-90"))
551 return(MDOC_p1003_1_90);
552 else if (xstrcmp(argv, "p1003.1-96"))
553 return(MDOC_p1003_1_96);
554 else if (xstrcmp(argv, "p1003.1-2001"))
555 return(MDOC_p1003_1_2001);
556 else if (xstrcmp(argv, "p1003.1-2004"))
557 return(MDOC_p1003_1_2004);
558 else if (xstrcmp(argv, "p1003.1"))
559 return(MDOC_p1003_1);
560 else if (xstrcmp(argv, "p1003.1b"))
561 return(MDOC_p1003_1b);
562 else if (xstrcmp(argv, "p1003.1b-93"))
563 return(MDOC_p1003_1b_93);
564 else if (xstrcmp(argv, "p1003.1c-95"))
565 return(MDOC_p1003_1c_95);
566 else if (xstrcmp(argv, "p1003.1g-2000"))
567 return(MDOC_p1003_1g_2000);
568 else if (xstrcmp(argv, "p1003.2-92"))
569 return(MDOC_p1003_2_92);
570 else if (xstrcmp(argv, "p1003.2-95"))
571 return(MDOC_p1387_2_95);
572 else if (xstrcmp(argv, "p1003.2"))
573 return(MDOC_p1003_2);
574 else if (xstrcmp(argv, "p1387.2-95"))
575 return(MDOC_p1387_2);
576 else if (xstrcmp(argv, "isoC-90"))
577 return(MDOC_isoC_90);
578 else if (xstrcmp(argv, "isoC-amd1"))
579 return(MDOC_isoC_amd1);
580 else if (xstrcmp(argv, "isoC-tcor1"))
581 return(MDOC_isoC_tcor1);
582 else if (xstrcmp(argv, "isoC-tcor2"))
583 return(MDOC_isoC_tcor2);
584 else if (xstrcmp(argv, "isoC-99"))
585 return(MDOC_isoC_99);
586 else if (xstrcmp(argv, "ansiC"))
587 return(MDOC_ansiC);
588 else if (xstrcmp(argv, "ansiC-89"))
589 return(MDOC_ansiC_89);
590 else if (xstrcmp(argv, "ansiC-99"))
591 return(MDOC_ansiC_99);
592 else if (xstrcmp(argv, "ieee754"))
593 return(MDOC_ieee754);
594 else if (xstrcmp(argv, "iso8802-3"))
595 return(MDOC_iso8802_3);
596 else if (xstrcmp(argv, "xpg3"))
597 return(MDOC_xpg3);
598 else if (xstrcmp(argv, "xpg4"))
599 return(MDOC_xpg4);
600 else if (xstrcmp(argv, "xpg4.2"))
601 return(MDOC_xpg4_2);
602 else if (xstrcmp(argv, "xpg4.3"))
603 return(MDOC_xpg4_3);
604 else if (xstrcmp(argv, "xbd5"))
605 return(MDOC_xbd5);
606 else if (xstrcmp(argv, "xcu5"))
607 return(MDOC_xcu5);
608 else if (xstrcmp(argv, "xsh5"))
609 return(MDOC_xsh5);
610 else if (xstrcmp(argv, "xns5"))
611 return(MDOC_xns5);
612 else if (xstrcmp(argv, "xns5.2d2.0"))
613 return(MDOC_xns5_2d2_0);
614 else if (xstrcmp(argv, "xcurses4.2"))
615 return(MDOC_xcurses4_2);
616 else if (xstrcmp(argv, "susv2"))
617 return(MDOC_susv2);
618 else if (xstrcmp(argv, "susv3"))
619 return(MDOC_susv3);
620 else if (xstrcmp(argv, "svid4"))
621 return(MDOC_svid4);
622 break;
623
624 default:
625 break;
626 }
627
628 return(MDOC_ARG_MAX);
629 }
630
631
632 static int
633 argv_multi(struct mdoc *mdoc, int line,
634 struct mdoc_arg *v, int *pos, char *buf)
635 {
636 int c, ppos;
637 char *p;
638
639 v->sz = 0;
640 v->value = xcalloc(MDOC_LINEARG_MAX, sizeof(char *));
641
642 ppos = *pos;
643
644 for (v->sz = 0; v->sz < MDOC_LINEARG_MAX; v->sz++) {
645 if ('-' == buf[*pos])
646 break;
647 c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
648 if (ARGS_ERROR == c) {
649 free(v->value);
650 return(0);
651 } else if (ARGS_EOLN == c)
652 break;
653 v->value[v->sz] = p;
654 }
655
656 if (0 < v->sz && v->sz < MDOC_LINEARG_MAX)
657 return(1);
658
659 free(v->value);
660 if (0 == v->sz)
661 return(perr(mdoc, line, ppos, EARGVAL));
662
663 return(perr(mdoc, line, ppos, EARGMANY));
664 }
665
666
667 static int
668 argv_single(struct mdoc *mdoc, int line,
669 struct mdoc_arg *v, int *pos, char *buf)
670 {
671 int c, ppos;
672 char *p;
673
674 ppos = *pos;
675
676 c = args(mdoc, line, pos, buf, ARGS_QUOTED, &p);
677 if (ARGS_ERROR == c)
678 return(0);
679 if (ARGS_EOLN == c)
680 return(perr(mdoc, line, ppos, EARGVAL));
681
682 v->sz = 1;
683 v->value = xcalloc(1, sizeof(char *));
684 v->value[0] = p;
685 return(1);
686 }
687
688
689 static int
690 argv(struct mdoc *mdoc, int line,
691 struct mdoc_arg *v, int *pos, char *buf)
692 {
693
694 v->sz = 0;
695 v->value = NULL;
696
697 switch (v->arg) {
698 case(MDOC_Std):
699 /* FALLTHROUGH */
700 case(MDOC_Width):
701 /* FALLTHROUGH */
702 case(MDOC_Offset):
703 return(argv_single(mdoc, line, v, pos, buf));
704 case(MDOC_Column):
705 return(argv_multi(mdoc, line, v, pos, buf));
706 default:
707 break;
708 }
709
710 return(1);
711 }
712
713
714 int
715 mdoc_argv(struct mdoc *mdoc, int line, int tok,
716 struct mdoc_arg *v, int *pos, char *buf)
717 {
718 int i, ppos;
719 char *p;
720
721 (void)memset(v, 0, sizeof(struct mdoc_arg));
722
723 if (0 == buf[*pos])
724 return(ARGV_EOLN);
725
726 assert( ! isspace((int)buf[*pos]));
727
728 if ('-' != buf[*pos])
729 return(ARGV_WORD);
730
731 i = *pos;
732 p = &buf[++(*pos)];
733
734 v->line = line;
735 v->pos = *pos;
736
737 assert(*pos > 0);
738
739 /* LINTED */
740 while (buf[*pos]) {
741 if (isspace((int)buf[*pos]))
742 if ('\\' != buf[*pos - 1])
743 break;
744 (*pos)++;
745 }
746
747 if (buf[*pos])
748 buf[(*pos)++] = 0;
749
750 if (MDOC_ARG_MAX == (v->arg = lookup(tok, p))) {
751 if ( ! pwarn(mdoc, line, i, WARGVPARM))
752 return(ARGV_ERROR);
753 return(ARGV_WORD);
754 }
755
756 while (buf[*pos] && isspace((int)buf[*pos]))
757 (*pos)++;
758
759 /* FIXME: whitespace if no value. */
760
761 ppos = *pos;
762 if ( ! argv(mdoc, line, v, pos, buf))
763 return(ARGV_ERROR);
764
765 return(ARGV_ARG);
766 }
767
768
769 void
770 mdoc_argv_free(int sz, struct mdoc_arg *arg)
771 {
772 int i;
773
774 for (i = 0; i < sz; i++) {
775 if (0 == arg[i].sz) {
776 assert(NULL == arg[i].value);
777 continue;
778 }
779 assert(arg[i].value);
780 free(arg[i].value);
781 }
782 }
783