]>
git.cameronkatri.com Git - mandoc.git/blob - macro.c
1 /* $Id: macro.c,v 1.40 2009/01/17 16:15:27 kristaps Exp $ */
3 * Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
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
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.
30 /* FIXME: maxlineargs should be per LINE, no per TOKEN. */
32 static int rewind_alt(int);
33 static int rewind_dohalt(int, enum mdoc_type
,
34 const struct mdoc_node
*);
35 #define REWIND_REWIND (1 << 0)
36 #define REWIND_NOHALT (1 << 1)
37 #define REWIND_HALT (1 << 2)
38 static int rewind_dobreak(int, enum mdoc_type
,
39 const struct mdoc_node
*);
42 static int rewind_elem(struct mdoc
*, int);
43 static int rewind_impblock(struct mdoc
*, int, int, int);
44 static int rewind_expblock(struct mdoc
*, int, int, int);
45 static int rewind_subblock(enum mdoc_type
, struct mdoc
*, int);
46 static int rewind_last(int, int,
47 struct mdoc
*, struct mdoc_node
*);
48 static int append_delims(struct mdoc
*,
49 int, int, int *, char *);
50 static int lookup(struct mdoc
*, int, int, int, const char *);
54 lookup(struct mdoc
*mdoc
, int line
, int pos
, int from
, const char *p
)
58 res
= mdoc_find(mdoc
, p
);
59 if (MDOC_PARSED
& mdoc_macros
[from
].flags
)
64 if ( ! mdoc_pwarn(mdoc
, line
, pos
, WARN_SYNTAX
, "macro-like parameter"))
71 rewind_last(int tok
, int type
, struct mdoc
*mdoc
, struct mdoc_node
*to
)
75 mdoc
->next
= MDOC_NEXT_SIBLING
;
76 if (mdoc
->last
== to
) {
77 if ( ! mdoc_valid_post(mdoc
))
79 if ( ! mdoc_action_post(mdoc
))
81 mdoc_msg(mdoc
, "rewound %s %s to %s %s",
84 mdoc_type2a(mdoc
->last
->type
),
85 mdoc_macronames
[mdoc
->last
->tok
]);
90 mdoc
->last
= mdoc
->last
->parent
;
92 if ( ! mdoc_valid_post(mdoc
))
94 if ( ! mdoc_action_post(mdoc
))
96 mdoc_msg(mdoc
, "rewound %s %s to %s %s",
99 mdoc_type2a(mdoc
->last
->type
),
100 mdoc_macronames
[mdoc
->last
->tok
]);
101 } while (mdoc
->last
!= to
);
150 rewind_dohalt(int tok
, enum mdoc_type type
, const struct mdoc_node
*p
)
153 if (MDOC_ROOT
== p
->type
)
155 if (MDOC_TEXT
== p
->type
)
156 return(REWIND_NOHALT
);
157 if (MDOC_ELEM
== p
->type
)
158 return(REWIND_NOHALT
);
161 /* One-liner implicit-scope. */
181 assert(MDOC_BODY
!= type
);
182 assert(MDOC_TAIL
!= type
);
183 if (type
== p
->type
&& tok
== p
->tok
)
184 return(REWIND_REWIND
);
187 /* Multi-line implicit-scope. */
189 assert(MDOC_TAIL
!= type
);
190 if (type
== p
->type
&& tok
== p
->tok
)
191 return(REWIND_REWIND
);
192 if (MDOC_BODY
== p
->type
&& MDOC_Bl
== p
->tok
)
196 if (type
== p
->type
&& tok
== p
->tok
)
197 return(REWIND_REWIND
);
200 assert(MDOC_TAIL
!= type
);
201 if (type
== p
->type
&& tok
== p
->tok
)
202 return(REWIND_REWIND
);
203 if (MDOC_BODY
== p
->type
&& MDOC_Sh
== p
->tok
)
207 /* Multi-line explicit scope start. */
237 if (type
== p
->type
&& tok
== p
->tok
)
238 return(REWIND_REWIND
);
241 /* Multi-line explicit scope close. */
271 if (type
== p
->type
&& rewind_alt(tok
) == p
->tok
)
272 return(REWIND_REWIND
);
279 return(REWIND_NOHALT
);
284 rewind_dobreak(int tok
, enum mdoc_type type
, const struct mdoc_node
*p
)
287 assert(MDOC_ROOT
!= p
->type
);
288 if (MDOC_ELEM
== p
->type
)
290 if (MDOC_TEXT
== p
->type
)
294 /* Implicit rules. */
296 return(MDOC_It
== p
->tok
);
298 return(MDOC_Ss
== p
->tok
);
300 if (MDOC_Ss
== p
->tok
)
302 return(MDOC_Sh
== p
->tok
);
304 /* Extra scope rules. */
306 if (MDOC_It
== p
->tok
)
313 if (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)
314 return(p
->tok
== rewind_alt(tok
));
315 else if (MDOC_BLOCK
== p
->type
)
318 return(tok
== p
->tok
);
323 rewind_elem(struct mdoc
*mdoc
, int tok
)
328 if (MDOC_ELEM
!= n
->type
)
330 assert(MDOC_ELEM
== n
->type
);
331 assert(tok
== n
->tok
);
333 return(rewind_last(tok
, MDOC_ELEM
, mdoc
, n
));
338 rewind_subblock(enum mdoc_type type
, struct mdoc
*mdoc
, int tok
)
343 c
= rewind_dohalt(tok
, type
, mdoc
->last
);
344 if (REWIND_HALT
== c
)
346 if (REWIND_REWIND
== c
)
347 return(rewind_last(tok
, type
, mdoc
, mdoc
->last
));
350 for (n
= mdoc
->last
->parent
; n
; n
= n
->parent
) {
351 c
= rewind_dohalt(tok
, type
, n
);
352 if (REWIND_HALT
== c
)
354 if (REWIND_REWIND
== c
)
356 else if (rewind_dobreak(tok
, type
, n
))
358 return(mdoc_nerr(mdoc
, n
, "body scope broken"));
362 return(rewind_last(tok
, type
, mdoc
, n
));
367 rewind_expblock(struct mdoc
*mdoc
, int tok
, int line
, int ppos
)
372 c
= rewind_dohalt(tok
, MDOC_BLOCK
, mdoc
->last
);
373 if (REWIND_HALT
== c
)
374 return(mdoc_perr(mdoc
, line
, ppos
, "closing macro has no context"));
375 if (REWIND_REWIND
== c
)
376 return(rewind_last(tok
, MDOC_BLOCK
, mdoc
, mdoc
->last
));
379 for (n
= mdoc
->last
->parent
; n
; n
= n
->parent
) {
380 c
= rewind_dohalt(tok
, MDOC_BLOCK
, n
);
381 if (REWIND_HALT
== c
)
382 return(mdoc_perr(mdoc
, line
, ppos
, "closing macro has no context"));
383 if (REWIND_REWIND
== c
)
385 else if (rewind_dobreak(tok
, MDOC_BLOCK
, n
))
387 return(mdoc_nerr(mdoc
, n
, "block scope broken"));
391 return(rewind_last(tok
, MDOC_BLOCK
, mdoc
, n
));
396 rewind_impblock(struct mdoc
*mdoc
, int tok
, int line
, int ppos
)
401 c
= rewind_dohalt(tok
, MDOC_BLOCK
, mdoc
->last
);
402 if (REWIND_HALT
== c
)
404 if (REWIND_REWIND
== c
)
405 return(rewind_last(tok
, MDOC_BLOCK
, mdoc
, mdoc
->last
));
408 for (n
= mdoc
->last
->parent
; n
; n
= n
->parent
) {
409 c
= rewind_dohalt(tok
, MDOC_BLOCK
, n
);
410 if (REWIND_HALT
== c
)
412 else if (REWIND_REWIND
== c
)
414 else if (rewind_dobreak(tok
, MDOC_BLOCK
, n
))
416 return(mdoc_nerr(mdoc
, n
, "block scope broken"));
420 return(rewind_last(tok
, MDOC_BLOCK
, mdoc
, n
));
425 append_delims(struct mdoc
*mdoc
, int tok
,
426 int line
, int *pos
, char *buf
)
436 c
= mdoc_args(mdoc
, line
, pos
, buf
, 0, &p
);
439 else if (ARGS_EOLN
== c
)
441 assert(mdoc_isdelim(p
));
442 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
444 mdoc
->next
= MDOC_NEXT_SIBLING
;
453 macro_scoped_close(MACRO_PROT_ARGS
)
455 int tt
, j
, c
, lastarg
, maxargs
, flushed
;
467 tt
= rewind_alt(tok
);
469 mdoc_msg(mdoc
, "parse-quiet: %s closing %s",
470 mdoc_macronames
[tok
], mdoc_macronames
[tt
]);
472 if ( ! (MDOC_CALLABLE
& mdoc_macros
[tok
].flags
)) {
473 if (0 == buf
[*pos
]) {
474 if ( ! rewind_subblock(MDOC_BODY
, mdoc
, tok
))
476 return(rewind_expblock(mdoc
, tok
, line
, ppos
));
478 return(mdoc_perr(mdoc
, line
, ppos
, "macro expects no parameters"));
481 if ( ! rewind_subblock(MDOC_BODY
, mdoc
, tok
))
488 if ( ! mdoc_tail_alloc(mdoc
, line
, ppos
, tt
))
490 mdoc
->next
= MDOC_NEXT_CHILD
;
493 for (j
= 0; j
< MDOC_LINEARG_MAX
; j
++) {
496 if (j
== maxargs
&& ! flushed
) {
497 if ( ! rewind_expblock(mdoc
, tok
, line
, ppos
))
502 c
= mdoc_args(mdoc
, line
, pos
, buf
, ARGS_DELIM
, &p
);
510 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
512 else if (MDOC_MAX
!= c
) {
514 if ( ! rewind_expblock(mdoc
, tok
, line
, ppos
))
518 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
523 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
525 mdoc
->next
= MDOC_NEXT_SIBLING
;
528 if (MDOC_LINEARG_MAX
== j
)
529 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
531 if ( ! flushed
&& ! rewind_expblock(mdoc
, tok
, line
, ppos
))
536 return(append_delims(mdoc
, tok
, line
, pos
, buf
));
541 * A general text domain macro. When invoked, this opens a scope that
542 * accepts words until either end-of-line, only-punctuation, or a
543 * callable macro. If the word is punctuation (not only-punctuation),
544 * then the scope is closed out, the punctuation appended, then the
545 * scope opened again. If any terminating conditions are met, the scope
546 * is closed out. If this is the first macro in the line and
547 * only-punctuation remains, this punctuation is flushed.
550 macro_text(MACRO_PROT_ARGS
)
552 int la
, lastpunct
, c
, sz
, fl
, argc
;
553 struct mdoc_arg argv
[MDOC_LINEARG_MAX
];
559 for (argc
= 0; argc
< MDOC_LINEARG_MAX
; argc
++) {
562 c
= mdoc_argv(mdoc
, line
, tok
, &argv
[argc
], pos
, buf
);
565 if (ARGV_WORD
== c
) {
568 } else if (ARGV_ARG
== c
)
571 mdoc_argv_free(argc
, argv
);
575 if (MDOC_LINEARG_MAX
== argc
) {
576 mdoc_argv_free(argc
, argv
);
577 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
580 c
= mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, argc
, argv
);
583 mdoc_argv_free(argc
, argv
);
587 mdoc
->next
= MDOC_NEXT_CHILD
;
590 if (MDOC_QUOTABLE
& mdoc_macros
[tok
].flags
)
593 for (lastpunct
= sz
= 0; sz
+ argc
< MDOC_LINEARG_MAX
; sz
++) {
596 c
= mdoc_args(mdoc
, line
, pos
, buf
, fl
, &p
);
597 if (ARGS_ERROR
== c
) {
598 mdoc_argv_free(argc
, argv
);
607 if (-1 == (c
= lookup(mdoc
, line
, la
, tok
, p
)))
609 else if (MDOC_MAX
!= c
) {
610 if (0 == lastpunct
&& ! rewind_elem(mdoc
, tok
)) {
611 mdoc_argv_free(argc
, argv
);
614 mdoc_argv_free(argc
, argv
);
616 c
= mdoc_macro(mdoc
, c
, line
, la
, pos
, buf
);
621 return(append_delims(mdoc
, tok
, line
, pos
, buf
));
624 if (mdoc_isdelim(p
)) {
625 if (0 == lastpunct
&& ! rewind_elem(mdoc
, tok
)) {
626 mdoc_argv_free(argc
, argv
);
630 } else if (lastpunct
) {
631 c
= mdoc_elem_alloc(mdoc
, line
,
632 ppos
, tok
, argc
, argv
);
634 mdoc_argv_free(argc
, argv
);
637 mdoc
->next
= MDOC_NEXT_CHILD
;
641 if ( ! mdoc_word_alloc(mdoc
, line
, la
, p
))
643 mdoc
->next
= MDOC_NEXT_SIBLING
;
646 mdoc_argv_free(argc
, argv
);
648 if (sz
== MDOC_LINEARG_MAX
)
649 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
651 if (0 == lastpunct
&& ! rewind_elem(mdoc
, tok
))
655 return(append_delims(mdoc
, tok
, line
, pos
, buf
));
660 * Implicit- or explicit-end multi-line scoped macro.
663 macro_scoped(MACRO_PROT_ARGS
)
665 int c
, lastarg
, argc
, j
, fl
;
666 struct mdoc_arg argv
[MDOC_LINEARG_MAX
];
669 assert ( ! (MDOC_CALLABLE
& mdoc_macros
[tok
].flags
));
671 if ( ! (MDOC_EXPLICIT
& mdoc_macros
[tok
].flags
)) {
672 if ( ! rewind_subblock(MDOC_BODY
, mdoc
, tok
))
674 if ( ! rewind_impblock(mdoc
, tok
, line
, ppos
))
678 for (argc
= 0; argc
< MDOC_LINEARG_MAX
; argc
++) {
680 c
= mdoc_argv(mdoc
, line
, tok
, &argv
[argc
], pos
, buf
);
683 if (ARGV_WORD
== c
) {
686 } else if (ARGV_ARG
== c
)
688 mdoc_argv_free(argc
, argv
);
692 if (MDOC_LINEARG_MAX
== argc
) {
693 mdoc_argv_free(argc
, argv
);
694 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
697 c
= mdoc_block_alloc(mdoc
, line
, ppos
,
698 tok
, (size_t)argc
, argv
);
699 mdoc_argv_free(argc
, argv
);
704 mdoc
->next
= MDOC_NEXT_CHILD
;
706 if (0 == buf
[*pos
]) {
707 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
709 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
))
711 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
713 mdoc
->next
= MDOC_NEXT_CHILD
;
717 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
719 mdoc
->next
= MDOC_NEXT_CHILD
;
722 if (MDOC_TABSEP
& mdoc_macros
[tok
].flags
)
725 for (j
= 0; j
< MDOC_LINEARG_MAX
; j
++) {
727 c
= mdoc_args(mdoc
, line
, pos
, buf
, fl
, &p
);
736 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
738 else if (MDOC_MAX
== c
) {
739 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
741 mdoc
->next
= MDOC_NEXT_SIBLING
;
745 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
750 if (j
== MDOC_LINEARG_MAX
)
751 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
753 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
))
755 if (1 == ppos
&& ! append_delims(mdoc
, tok
, line
, pos
, buf
))
758 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
760 mdoc
->next
= MDOC_NEXT_CHILD
;
767 * When scoped to a line, a macro encompasses all of the contents. This
768 * differs from constants or text macros, where a new macro will
769 * terminate the existing context.
772 macro_scoped_line(MACRO_PROT_ARGS
)
777 if ( ! mdoc_block_alloc(mdoc
, line
, ppos
, tok
, 0, NULL
))
779 mdoc
->next
= MDOC_NEXT_CHILD
;
781 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
783 mdoc
->next
= MDOC_NEXT_CHILD
;
785 /* XXX - no known argument macros. */
787 for (lastarg
= ppos
, j
= 0; j
< MDOC_LINEARG_MAX
; j
++) {
789 c
= mdoc_args(mdoc
, line
, pos
, buf
, ARGS_DELIM
, &p
);
798 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
800 else if (MDOC_MAX
== c
) {
801 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
803 mdoc
->next
= MDOC_NEXT_SIBLING
;
807 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
812 if (j
== MDOC_LINEARG_MAX
)
813 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
816 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
))
818 if ( ! append_delims(mdoc
, tok
, line
, pos
, buf
))
820 } else if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
))
822 return(rewind_impblock(mdoc
, tok
, line
, ppos
));
827 * Constant-scope macros accept a fixed number of arguments and behave
828 * like constant macros except that they're scoped across lines.
831 macro_constant_scoped(MACRO_PROT_ARGS
)
833 int lastarg
, flushed
, j
, c
, maxargs
;
848 if ( ! mdoc_block_alloc(mdoc
, line
, ppos
, tok
, 0, NULL
))
850 mdoc
->next
= MDOC_NEXT_CHILD
;
853 if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
855 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
))
857 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
860 } else if ( ! mdoc_head_alloc(mdoc
, line
, ppos
, tok
))
863 mdoc
->next
= MDOC_NEXT_CHILD
;
865 for (j
= 0; j
< MDOC_LINEARG_MAX
; j
++) {
868 if (j
== maxargs
&& ! flushed
) {
869 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
))
872 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
874 mdoc
->next
= MDOC_NEXT_CHILD
;
877 c
= mdoc_args(mdoc
, line
, pos
, buf
, ARGS_DELIM
, &p
);
885 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
887 else if (MDOC_MAX
!= c
) {
889 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
))
892 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
894 mdoc
->next
= MDOC_NEXT_CHILD
;
896 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
901 if ( ! flushed
&& mdoc_isdelim(p
)) {
902 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
))
905 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
907 mdoc
->next
= MDOC_NEXT_CHILD
;
910 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
912 mdoc
->next
= MDOC_NEXT_SIBLING
;
915 if (MDOC_LINEARG_MAX
== j
)
916 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
919 if ( ! rewind_subblock(MDOC_HEAD
, mdoc
, tok
))
921 if ( ! mdoc_body_alloc(mdoc
, line
, ppos
, tok
))
923 mdoc
->next
= MDOC_NEXT_CHILD
;
928 return(append_delims(mdoc
, tok
, line
, pos
, buf
));
933 * Delimited macros are like text macros except that, should punctuation
934 * be encountered, the macro isn't re-started with remaining tokens
935 * (it's only emitted once). Delimited macros can have a maximum number
939 macro_constant_delimited(MACRO_PROT_ARGS
)
941 int lastarg
, flushed
, j
, c
, maxargs
, argc
;
942 struct mdoc_arg argv
[MDOC_LINEARG_MAX
];
965 for (argc
= 0; argc
< MDOC_LINEARG_MAX
; argc
++) {
967 c
= mdoc_argv(mdoc
, line
, tok
, &argv
[argc
], pos
, buf
);
970 if (ARGV_WORD
== c
) {
973 } else if (ARGV_ARG
== c
)
975 mdoc_argv_free(argc
, argv
);
979 c
= mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, argc
, argv
);
980 mdoc_argv_free(argc
, argv
);
985 mdoc
->next
= MDOC_NEXT_CHILD
;
987 for (j
= 0; j
< MDOC_LINEARG_MAX
; j
++) {
990 if (j
== maxargs
&& ! flushed
) {
991 if ( ! rewind_elem(mdoc
, tok
))
996 c
= mdoc_args(mdoc
, line
, pos
, buf
, ARGS_DELIM
, &p
);
1004 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
1006 else if (MDOC_MAX
!= c
) {
1007 if ( ! flushed
&& ! rewind_elem(mdoc
, tok
))
1010 if ( ! mdoc_macro(mdoc
, c
, line
, lastarg
, pos
, buf
))
1015 if ( ! flushed
&& mdoc_isdelim(p
)) {
1016 if ( ! rewind_elem(mdoc
, tok
))
1021 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
1023 mdoc
->next
= MDOC_NEXT_SIBLING
;
1026 if (MDOC_LINEARG_MAX
== j
)
1027 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
1029 if ( ! flushed
&& rewind_elem(mdoc
, tok
))
1034 return(append_delims(mdoc
, tok
, line
, pos
, buf
));
1039 * Constant macros span an entire line: they constitute a macro and all
1040 * of its arguments and child data.
1043 macro_constant(MACRO_PROT_ARGS
)
1045 int c
, lastarg
, argc
, sz
, fl
;
1046 struct mdoc_arg argv
[MDOC_LINEARG_MAX
];
1050 if (MDOC_QUOTABLE
& mdoc_macros
[tok
].flags
)
1053 for (argc
= 0; argc
< MDOC_LINEARG_MAX
; argc
++) {
1055 c
= mdoc_argv(mdoc
, line
, tok
, &argv
[argc
], pos
, buf
);
1058 if (ARGV_WORD
== c
) {
1061 } else if (ARGV_ARG
== c
)
1064 mdoc_argv_free(argc
, argv
);
1068 c
= mdoc_elem_alloc(mdoc
, line
, ppos
, tok
, argc
, argv
);
1069 mdoc_argv_free(argc
, argv
);
1074 mdoc
->next
= MDOC_NEXT_CHILD
;
1076 if (MDOC_LINEARG_MAX
== argc
)
1077 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
1079 for (sz
= 0; sz
+ argc
< MDOC_LINEARG_MAX
; sz
++) {
1081 c
= mdoc_args(mdoc
, line
, pos
, buf
, fl
, &p
);
1082 if (ARGS_ERROR
== c
)
1087 if (-1 == (c
= lookup(mdoc
, line
, lastarg
, tok
, p
)))
1089 else if (MDOC_MAX
!= c
) {
1090 if ( ! rewind_elem(mdoc
, tok
))
1092 return(mdoc_macro(mdoc
, c
, line
,
1093 lastarg
, pos
, buf
));
1096 if ( ! mdoc_word_alloc(mdoc
, line
, lastarg
, p
))
1098 mdoc
->next
= MDOC_NEXT_SIBLING
;
1101 if (MDOC_LINEARG_MAX
== sz
+ argc
)
1102 return(mdoc_perr(mdoc
, line
, ppos
, "too many arguments"));
1104 return(rewind_elem(mdoc
, tok
));
1110 macro_obsolete(MACRO_PROT_ARGS
)
1113 return(mdoc_pwarn(mdoc
, line
, ppos
, WARN_SYNTAX
, "macro is obsolete"));
1118 macro_end(struct mdoc
*mdoc
)
1121 assert(mdoc
->first
);
1123 return(rewind_last(mdoc
->last
->tok
, mdoc
->last
->type
,
1124 mdoc
, mdoc
->first
));