]> git.cameronkatri.com Git - mandoc.git/blob - mdoc.c
Properly checked in Ingo Schwarze' prologue/body-breaking patch, which I'd munged.
[mandoc.git] / mdoc.c
1 /* $Id: mdoc.c,v 1.122 2010/04/08 07:06:15 kristaps Exp $ */
2 /*
3 * Copyright (c) 2008, 2009 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 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 <stdarg.h>
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <string.h>
29 #include <time.h>
30
31 #include "libmdoc.h"
32 #include "libmandoc.h"
33
34 const char *const __mdoc_merrnames[MERRMAX] = {
35 "trailing whitespace", /* ETAILWS */
36 "unexpected quoted parameter", /* EQUOTPARM */
37 "unterminated quoted parameter", /* EQUOTTERM */
38 "argument parameter suggested", /* EARGVAL */
39 "macro disallowed in prologue", /* EBODYPROL */
40 "macro disallowed in body", /* EPROLBODY */
41 "text disallowed in prologue", /* ETEXTPROL */
42 "blank line disallowed", /* ENOBLANK */
43 "text parameter too long", /* ETOOLONG */
44 "invalid escape sequence", /* EESCAPE */
45 "invalid character", /* EPRINT */
46 "document has no body", /* ENODAT */
47 "document has no prologue", /* ENOPROLOGUE */
48 "expected line arguments", /* ELINE */
49 "invalid AT&T argument", /* EATT */
50 "default name not yet set", /* ENAME */
51 "missing list type", /* ELISTTYPE */
52 "missing display type", /* EDISPTYPE */
53 "too many display types", /* EMULTIDISP */
54 "too many list types", /* EMULTILIST */
55 "NAME section must be first", /* ESECNAME */
56 "badly-formed NAME section", /* ENAMESECINC */
57 "argument repeated", /* EARGREP */
58 "expected boolean parameter", /* EBOOL */
59 "inconsistent column syntax", /* ECOLMIS */
60 "nested display invalid", /* ENESTDISP */
61 "width argument missing", /* EMISSWIDTH */
62 "invalid section for this manual section", /* EWRONGMSEC */
63 "section out of conventional order", /* ESECOOO */
64 "section repeated", /* ESECREP */
65 "invalid standard argument", /* EBADSTAND */
66 "multi-line arguments discouraged", /* ENOMULTILINE */
67 "multi-line arguments suggested", /* EMULTILINE */
68 "line arguments discouraged", /* ENOLINE */
69 "prologue macro out of conventional order", /* EPROLOOO */
70 "prologue macro repeated", /* EPROLREP */
71 "invalid manual section", /* EBADMSEC */
72 "invalid section", /* EBADSEC */
73 "invalid font mode", /* EFONT */
74 "invalid date syntax", /* EBADDATE */
75 "invalid number format", /* ENUMFMT */
76 "superfluous width argument", /* ENOWIDTH */
77 "system: utsname error", /* EUTSNAME */
78 "obsolete macro", /* EOBS */
79 "end-of-line scope violation", /* EIMPBRK */
80 "empty macro ignored", /* EIGNE */
81 "unclosed explicit scope", /* EOPEN */
82 "unterminated quoted phrase", /* EQUOTPHR */
83 "closure macro without prior context", /* ENOCTX */
84 "no description found for library", /* ELIB */
85 "bad child for parent context", /* EBADCHILD */
86 "list arguments preceding type", /* ENOTYPE */
87 };
88
89 const char *const __mdoc_macronames[MDOC_MAX] = {
90 "Ap", "Dd", "Dt", "Os",
91 "Sh", "Ss", "Pp", "D1",
92 "Dl", "Bd", "Ed", "Bl",
93 "El", "It", "Ad", "An",
94 "Ar", "Cd", "Cm", "Dv",
95 "Er", "Ev", "Ex", "Fa",
96 "Fd", "Fl", "Fn", "Ft",
97 "Ic", "In", "Li", "Nd",
98 "Nm", "Op", "Ot", "Pa",
99 "Rv", "St", "Va", "Vt",
100 /* LINTED */
101 "Xr", "%A", "%B", "%D",
102 /* LINTED */
103 "%I", "%J", "%N", "%O",
104 /* LINTED */
105 "%P", "%R", "%T", "%V",
106 "Ac", "Ao", "Aq", "At",
107 "Bc", "Bf", "Bo", "Bq",
108 "Bsx", "Bx", "Db", "Dc",
109 "Do", "Dq", "Ec", "Ef",
110 "Em", "Eo", "Fx", "Ms",
111 "No", "Ns", "Nx", "Ox",
112 "Pc", "Pf", "Po", "Pq",
113 "Qc", "Ql", "Qo", "Qq",
114 "Re", "Rs", "Sc", "So",
115 "Sq", "Sm", "Sx", "Sy",
116 "Tn", "Ux", "Xc", "Xo",
117 "Fo", "Fc", "Oo", "Oc",
118 "Bk", "Ek", "Bt", "Hf",
119 "Fr", "Ud", "Lb", "Lp",
120 "Lk", "Mt", "Brq", "Bro",
121 /* LINTED */
122 "Brc", "%C", "Es", "En",
123 /* LINTED */
124 "Dx", "%Q", "br", "sp",
125 /* LINTED */
126 "%U"
127 };
128
129 const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
130 "split", "nosplit", "ragged",
131 "unfilled", "literal", "file",
132 "offset", "bullet", "dash",
133 "hyphen", "item", "enum",
134 "tag", "diag", "hang",
135 "ohang", "inset", "column",
136 "width", "compact", "std",
137 "filled", "words", "emphasis",
138 "symbolic", "nested", "centered"
139 };
140
141 const char * const *mdoc_macronames = __mdoc_macronames;
142 const char * const *mdoc_argnames = __mdoc_argnames;
143
144 static void mdoc_node_free(struct mdoc_node *);
145 static void mdoc_node_unlink(struct mdoc *,
146 struct mdoc_node *);
147 static void mdoc_free1(struct mdoc *);
148 static void mdoc_alloc1(struct mdoc *);
149 static struct mdoc_node *node_alloc(struct mdoc *, int, int,
150 enum mdoct, enum mdoc_type);
151 static int node_append(struct mdoc *,
152 struct mdoc_node *);
153 static int parsetext(struct mdoc *, int, char *);
154 static int parsemacro(struct mdoc *, int, char *);
155 static int macrowarn(struct mdoc *, int, const char *);
156 static int pstring(struct mdoc *, int, int,
157 const char *, size_t);
158
159 const struct mdoc_node *
160 mdoc_node(const struct mdoc *m)
161 {
162
163 return(MDOC_HALT & m->flags ? NULL : m->first);
164 }
165
166
167 const struct mdoc_meta *
168 mdoc_meta(const struct mdoc *m)
169 {
170
171 return(MDOC_HALT & m->flags ? NULL : &m->meta);
172 }
173
174
175 /*
176 * Frees volatile resources (parse tree, meta-data, fields).
177 */
178 static void
179 mdoc_free1(struct mdoc *mdoc)
180 {
181
182 if (mdoc->first)
183 mdoc_node_delete(mdoc, mdoc->first);
184 if (mdoc->meta.title)
185 free(mdoc->meta.title);
186 if (mdoc->meta.os)
187 free(mdoc->meta.os);
188 if (mdoc->meta.name)
189 free(mdoc->meta.name);
190 if (mdoc->meta.arch)
191 free(mdoc->meta.arch);
192 if (mdoc->meta.vol)
193 free(mdoc->meta.vol);
194 }
195
196
197 /*
198 * Allocate all volatile resources (parse tree, meta-data, fields).
199 */
200 static void
201 mdoc_alloc1(struct mdoc *mdoc)
202 {
203
204 memset(&mdoc->meta, 0, sizeof(struct mdoc_meta));
205 mdoc->flags = 0;
206 mdoc->lastnamed = mdoc->lastsec = SEC_NONE;
207 mdoc->last = mandoc_calloc(1, sizeof(struct mdoc_node));
208 mdoc->first = mdoc->last;
209 mdoc->last->type = MDOC_ROOT;
210 mdoc->next = MDOC_NEXT_CHILD;
211 }
212
213
214 /*
215 * Free up volatile resources (see mdoc_free1()) then re-initialises the
216 * data with mdoc_alloc1(). After invocation, parse data has been reset
217 * and the parser is ready for re-invocation on a new tree; however,
218 * cross-parse non-volatile data is kept intact.
219 */
220 void
221 mdoc_reset(struct mdoc *mdoc)
222 {
223
224 mdoc_free1(mdoc);
225 mdoc_alloc1(mdoc);
226 }
227
228
229 /*
230 * Completely free up all volatile and non-volatile parse resources.
231 * After invocation, the pointer is no longer usable.
232 */
233 void
234 mdoc_free(struct mdoc *mdoc)
235 {
236
237 mdoc_free1(mdoc);
238 free(mdoc);
239 }
240
241
242 /*
243 * Allocate volatile and non-volatile parse resources.
244 */
245 struct mdoc *
246 mdoc_alloc(void *data, int pflags, const struct mdoc_cb *cb)
247 {
248 struct mdoc *p;
249
250 p = mandoc_calloc(1, sizeof(struct mdoc));
251
252 if (cb)
253 memcpy(&p->cb, cb, sizeof(struct mdoc_cb));
254
255 p->data = data;
256 p->pflags = pflags;
257
258 mdoc_hash_init();
259 mdoc_alloc1(p);
260 return(p);
261 }
262
263
264 /*
265 * Climb back up the parse tree, validating open scopes. Mostly calls
266 * through to macro_end() in macro.c.
267 */
268 int
269 mdoc_endparse(struct mdoc *m)
270 {
271
272 if (MDOC_HALT & m->flags)
273 return(0);
274 else if (mdoc_macroend(m))
275 return(1);
276 m->flags |= MDOC_HALT;
277 return(0);
278 }
279
280
281 /*
282 * Main parse routine. Parses a single line -- really just hands off to
283 * the macro (parsemacro()) or text parser (parsetext()).
284 */
285 int
286 mdoc_parseln(struct mdoc *m, int ln, char *buf)
287 {
288
289 if (MDOC_HALT & m->flags)
290 return(0);
291
292 return('.' == *buf ? parsemacro(m, ln, buf) :
293 parsetext(m, ln, buf));
294 }
295
296
297 int
298 mdoc_verr(struct mdoc *mdoc, int ln, int pos,
299 const char *fmt, ...)
300 {
301 char buf[256];
302 va_list ap;
303
304 if (NULL == mdoc->cb.mdoc_err)
305 return(0);
306
307 va_start(ap, fmt);
308 (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
309 va_end(ap);
310
311 return((*mdoc->cb.mdoc_err)(mdoc->data, ln, pos, buf));
312 }
313
314
315 int
316 mdoc_vwarn(struct mdoc *mdoc, int ln, int pos, const char *fmt, ...)
317 {
318 char buf[256];
319 va_list ap;
320
321 if (NULL == mdoc->cb.mdoc_warn)
322 return(0);
323
324 va_start(ap, fmt);
325 (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
326 va_end(ap);
327
328 return((*mdoc->cb.mdoc_warn)(mdoc->data, ln, pos, buf));
329 }
330
331
332 int
333 mdoc_err(struct mdoc *m, int line, int pos, int iserr, enum merr type)
334 {
335 const char *p;
336
337 p = __mdoc_merrnames[(int)type];
338 assert(p);
339
340 if (iserr)
341 return(mdoc_verr(m, line, pos, p));
342
343 return(mdoc_vwarn(m, line, pos, p));
344 }
345
346
347 int
348 mdoc_macro(struct mdoc *m, enum mdoct tok,
349 int ln, int pp, int *pos, char *buf)
350 {
351 assert(tok < MDOC_MAX);
352
353 /* If we're in the body, deny prologue calls. */
354
355 if (MDOC_PROLOGUE & mdoc_macros[tok].flags &&
356 MDOC_PBODY & m->flags)
357 return(mdoc_perr(m, ln, pp, EPROLBODY));
358
359 /* If we're in the prologue, deny "body" macros. */
360
361 if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
362 ! (MDOC_PBODY & m->flags)) {
363 if ( ! mdoc_pwarn(m, ln, pp, EBODYPROL))
364 return(0);
365 if (NULL == m->meta.title)
366 m->meta.title = mandoc_strdup("unknown");
367 if (NULL == m->meta.vol)
368 m->meta.vol = mandoc_strdup("local");
369 if (NULL == m->meta.os)
370 m->meta.os = mandoc_strdup("local");
371 if (0 == m->meta.date)
372 m->meta.date = time(NULL);
373 m->flags |= MDOC_PBODY;
374 }
375
376 return((*mdoc_macros[tok].fp)(m, tok, ln, pp, pos, buf));
377 }
378
379
380 static int
381 node_append(struct mdoc *mdoc, struct mdoc_node *p)
382 {
383
384 assert(mdoc->last);
385 assert(mdoc->first);
386 assert(MDOC_ROOT != p->type);
387
388 switch (mdoc->next) {
389 case (MDOC_NEXT_SIBLING):
390 mdoc->last->next = p;
391 p->prev = mdoc->last;
392 p->parent = mdoc->last->parent;
393 break;
394 case (MDOC_NEXT_CHILD):
395 mdoc->last->child = p;
396 p->parent = mdoc->last;
397 break;
398 default:
399 abort();
400 /* NOTREACHED */
401 }
402
403 p->parent->nchild++;
404
405 if ( ! mdoc_valid_pre(mdoc, p))
406 return(0);
407 if ( ! mdoc_action_pre(mdoc, p))
408 return(0);
409
410 switch (p->type) {
411 case (MDOC_HEAD):
412 assert(MDOC_BLOCK == p->parent->type);
413 p->parent->head = p;
414 break;
415 case (MDOC_TAIL):
416 assert(MDOC_BLOCK == p->parent->type);
417 p->parent->tail = p;
418 break;
419 case (MDOC_BODY):
420 assert(MDOC_BLOCK == p->parent->type);
421 p->parent->body = p;
422 break;
423 default:
424 break;
425 }
426
427 mdoc->last = p;
428
429 switch (p->type) {
430 case (MDOC_TEXT):
431 if ( ! mdoc_valid_post(mdoc))
432 return(0);
433 if ( ! mdoc_action_post(mdoc))
434 return(0);
435 break;
436 default:
437 break;
438 }
439
440 return(1);
441 }
442
443
444 static struct mdoc_node *
445 node_alloc(struct mdoc *m, int line, int pos,
446 enum mdoct tok, enum mdoc_type type)
447 {
448 struct mdoc_node *p;
449
450 p = mandoc_calloc(1, sizeof(struct mdoc_node));
451 p->sec = m->lastsec;
452 p->line = line;
453 p->pos = pos;
454 p->tok = tok;
455 p->type = type;
456
457 return(p);
458 }
459
460
461 int
462 mdoc_tail_alloc(struct mdoc *m, int line, int pos, enum mdoct tok)
463 {
464 struct mdoc_node *p;
465
466 p = node_alloc(m, line, pos, tok, MDOC_TAIL);
467 if ( ! node_append(m, p))
468 return(0);
469 m->next = MDOC_NEXT_CHILD;
470 return(1);
471 }
472
473
474 int
475 mdoc_head_alloc(struct mdoc *m, int line, int pos, enum mdoct tok)
476 {
477 struct mdoc_node *p;
478
479 assert(m->first);
480 assert(m->last);
481
482 p = node_alloc(m, line, pos, tok, MDOC_HEAD);
483 if ( ! node_append(m, p))
484 return(0);
485 m->next = MDOC_NEXT_CHILD;
486 return(1);
487 }
488
489
490 int
491 mdoc_body_alloc(struct mdoc *m, int line, int pos, enum mdoct tok)
492 {
493 struct mdoc_node *p;
494
495 p = node_alloc(m, line, pos, tok, MDOC_BODY);
496 if ( ! node_append(m, p))
497 return(0);
498 m->next = MDOC_NEXT_CHILD;
499 return(1);
500 }
501
502
503 int
504 mdoc_block_alloc(struct mdoc *m, int line, int pos,
505 enum mdoct tok, struct mdoc_arg *args)
506 {
507 struct mdoc_node *p;
508
509 p = node_alloc(m, line, pos, tok, MDOC_BLOCK);
510 p->args = args;
511 if (p->args)
512 (args->refcnt)++;
513 if ( ! node_append(m, p))
514 return(0);
515 m->next = MDOC_NEXT_CHILD;
516 return(1);
517 }
518
519
520 int
521 mdoc_elem_alloc(struct mdoc *m, int line, int pos,
522 enum mdoct tok, struct mdoc_arg *args)
523 {
524 struct mdoc_node *p;
525
526 p = node_alloc(m, line, pos, tok, MDOC_ELEM);
527 p->args = args;
528 if (p->args)
529 (args->refcnt)++;
530 if ( ! node_append(m, p))
531 return(0);
532 m->next = MDOC_NEXT_CHILD;
533 return(1);
534 }
535
536
537 static int
538 pstring(struct mdoc *m, int line, int pos, const char *p, size_t len)
539 {
540 struct mdoc_node *n;
541 size_t sv;
542
543 n = node_alloc(m, line, pos, -1, MDOC_TEXT);
544 n->string = mandoc_malloc(len + 1);
545 sv = strlcpy(n->string, p, len + 1);
546
547 /* Prohibit truncation. */
548 assert(sv < len + 1);
549
550 if ( ! node_append(m, n))
551 return(0);
552 m->next = MDOC_NEXT_SIBLING;
553 return(1);
554 }
555
556
557 int
558 mdoc_word_alloc(struct mdoc *m, int line, int pos, const char *p)
559 {
560
561 return(pstring(m, line, pos, p, strlen(p)));
562 }
563
564
565 void
566 mdoc_node_free(struct mdoc_node *p)
567 {
568
569 if (p->string)
570 free(p->string);
571 if (p->args)
572 mdoc_argv_free(p->args);
573 free(p);
574 }
575
576
577 static void
578 mdoc_node_unlink(struct mdoc *m, struct mdoc_node *n)
579 {
580
581 /* Adjust siblings. */
582
583 if (n->prev)
584 n->prev->next = n->next;
585 if (n->next)
586 n->next->prev = n->prev;
587
588 /* Adjust parent. */
589
590 if (n->parent) {
591 n->parent->nchild--;
592 if (n->parent->child == n)
593 n->parent->child = n->prev ? n->prev : n->next;
594 }
595
596 /* Adjust parse point, if applicable. */
597
598 if (m && m->last == n) {
599 if (n->prev) {
600 m->last = n->prev;
601 m->next = MDOC_NEXT_SIBLING;
602 } else {
603 m->last = n->parent;
604 m->next = MDOC_NEXT_CHILD;
605 }
606 }
607
608 if (m && m->first == n)
609 m->first = NULL;
610 }
611
612
613 void
614 mdoc_node_delete(struct mdoc *m, struct mdoc_node *p)
615 {
616
617 while (p->child) {
618 assert(p->nchild);
619 mdoc_node_delete(m, p->child);
620 }
621 assert(0 == p->nchild);
622
623 mdoc_node_unlink(m, p);
624 mdoc_node_free(p);
625 }
626
627
628 /*
629 * Parse free-form text, that is, a line that does not begin with the
630 * control character.
631 */
632 static int
633 parsetext(struct mdoc *m, int line, char *buf)
634 {
635 int i, j;
636 char sv;
637
638 if (SEC_NONE == m->lastnamed)
639 return(mdoc_perr(m, line, 0, ETEXTPROL));
640
641 /*
642 * If in literal mode, then pass the buffer directly to the
643 * back-end, as it should be preserved as a single term.
644 */
645
646 if (MDOC_LITERAL & m->flags)
647 return(mdoc_word_alloc(m, line, 0, buf));
648
649 /* Disallow blank/white-space lines in non-literal mode. */
650
651 for (i = 0; ' ' == buf[i]; i++)
652 /* Skip leading whitespace. */ ;
653
654 if ('\0' == buf[i]) {
655 if ( ! mdoc_pwarn(m, line, 0, ENOBLANK))
656 return(0);
657 /*
658 * Assume that a `Pp' should be inserted in the case of
659 * a blank line. Technically, blank lines aren't
660 * allowed, but enough manuals assume this behaviour
661 * that we want to work around it.
662 */
663 if ( ! mdoc_elem_alloc(m, line, 0, MDOC_Pp, NULL))
664 return(0);
665 }
666
667 /*
668 * Break apart a free-form line into tokens. Spaces are
669 * stripped out of the input.
670 */
671
672 for (j = i; buf[i]; i++) {
673 if (' ' != buf[i])
674 continue;
675
676 /* Escaped whitespace. */
677 if (i && ' ' == buf[i] && '\\' == buf[i - 1])
678 continue;
679
680 sv = buf[i];
681 buf[i++] = '\0';
682
683 if ( ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
684 return(0);
685
686 /* Trailing whitespace? Check at overwritten byte. */
687
688 if (' ' == sv && '\0' == buf[i])
689 if ( ! mdoc_pwarn(m, line, i - 1, ETAILWS))
690 return(0);
691
692 for ( ; ' ' == buf[i]; i++)
693 /* Skip trailing whitespace. */ ;
694
695 j = i;
696
697 /* Trailing whitespace? */
698
699 if (' ' == buf[i - 1] && '\0' == buf[i])
700 if ( ! mdoc_pwarn(m, line, i - 1, ETAILWS))
701 return(0);
702
703 if ('\0' == buf[i])
704 break;
705 }
706
707 if (j != i && ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
708 return(0);
709
710 m->next = MDOC_NEXT_SIBLING;
711 return(1);
712 }
713
714
715
716 static int
717 macrowarn(struct mdoc *m, int ln, const char *buf)
718 {
719 if ( ! (MDOC_IGN_MACRO & m->pflags))
720 return(mdoc_verr(m, ln, 0,
721 "unknown macro: %s%s",
722 buf, strlen(buf) > 3 ? "..." : ""));
723 return(mdoc_vwarn(m, ln, 0, "unknown macro: %s%s",
724 buf, strlen(buf) > 3 ? "..." : ""));
725 }
726
727
728 /*
729 * Parse a macro line, that is, a line beginning with the control
730 * character.
731 */
732 int
733 parsemacro(struct mdoc *m, int ln, char *buf)
734 {
735 int i, j, c;
736 char mac[5];
737
738 /* Empty lines are ignored. */
739
740 if ('\0' == buf[1])
741 return(1);
742
743 i = 1;
744
745 /* Accept whitespace after the initial control char. */
746
747 if (' ' == buf[i]) {
748 i++;
749 while (buf[i] && ' ' == buf[i])
750 i++;
751 if ('\0' == buf[i])
752 return(1);
753 }
754
755 /* Copy the first word into a nil-terminated buffer. */
756
757 for (j = 0; j < 4; j++, i++) {
758 if ('\0' == (mac[j] = buf[i]))
759 break;
760 else if (' ' == buf[i])
761 break;
762
763 /* Check for invalid characters. */
764
765 if (isgraph((u_char)buf[i]))
766 continue;
767 return(mdoc_perr(m, ln, i, EPRINT));
768 }
769
770 mac[j] = 0;
771
772 if (j == 4 || j < 2) {
773 if ( ! macrowarn(m, ln, mac))
774 goto err;
775 return(1);
776 }
777
778 if (MDOC_MAX == (c = mdoc_hash_find(mac))) {
779 if ( ! macrowarn(m, ln, mac))
780 goto err;
781 return(1);
782 }
783
784 /* The macro is sane. Jump to the next word. */
785
786 while (buf[i] && ' ' == buf[i])
787 i++;
788
789 /* Trailing whitespace? */
790
791 if ('\0' == buf[i] && ' ' == buf[i - 1])
792 if ( ! mdoc_pwarn(m, ln, i - 1, ETAILWS))
793 goto err;
794
795 /*
796 * Begin recursive parse sequence. Since we're at the start of
797 * the line, we don't need to do callable/parseable checks.
798 */
799 if ( ! mdoc_macro(m, c, ln, 1, &i, buf))
800 goto err;
801
802 return(1);
803
804 err: /* Error out. */
805
806 m->flags |= MDOC_HALT;
807 return(0);
808 }
809
810