Annotation of src/usr.bin/mandoc/man.c, Revision 1.24
1.24 ! schwarze 1: /* $Id: man.c,v 1.23 2010/03/29 22:56:52 schwarze Exp $ */
1.1 kristaps 2: /*
1.2 schwarze 3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
1.2 schwarze 6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 8: *
1.2 schwarze 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.
1.1 kristaps 16: */
1.14 schwarze 17: #include <sys/types.h>
18:
1.1 kristaps 19: #include <assert.h>
20: #include <ctype.h>
21: #include <stdarg.h>
22: #include <stdlib.h>
23: #include <stdio.h>
24: #include <string.h>
25:
26: #include "libman.h"
1.16 schwarze 27: #include "libmandoc.h"
1.1 kristaps 28:
1.7 schwarze 29: const char *const __man_merrnames[WERRMAX] = {
30: "invalid character", /* WNPRINT */
31: "invalid manual section", /* WMSEC */
32: "invalid date format", /* WDATE */
33: "scope of prior line violated", /* WLNSCOPE */
1.21 schwarze 34: "over-zealous prior line scope violation", /* WLNSCOPE2 */
1.7 schwarze 35: "trailing whitespace", /* WTSPACE */
36: "unterminated quoted parameter", /* WTQUOTE */
37: "document has no body", /* WNODATA */
38: "document has no title/section", /* WNOTITLE */
39: "invalid escape sequence", /* WESCAPE */
1.8 schwarze 40: "invalid number format", /* WNUMFMT */
1.9 schwarze 41: "expected block head arguments", /* WHEADARGS */
42: "expected block body arguments", /* WBODYARGS */
43: "expected empty block head", /* WNHEADARGS */
44: "ill-formed macro", /* WMACROFORM */
1.10 schwarze 45: "scope open on exit", /* WEXITSCOPE */
46: "no scope context", /* WNOSCOPE */
47: "literal context already open", /* WOLITERAL */
1.22 schwarze 48: "no literal context open", /* WNLITERAL */
49: "invalid nesting of roff declarations", /* WROFFNEST */
1.23 schwarze 50: "scope in roff instructions broken", /* WROFFSCOPE */
51: "document title should be uppercase", /* WTITLECASE */
1.7 schwarze 52: };
53:
1.1 kristaps 54: const char *const __man_macronames[MAN_MAX] = {
1.3 schwarze 55: "br", "TH", "SH", "SS",
1.1 kristaps 56: "TP", "LP", "PP", "P",
57: "IP", "HP", "SM", "SB",
58: "BI", "IB", "BR", "RB",
59: "R", "B", "I", "IR",
1.9 schwarze 60: "RI", "na", "i", "sp",
1.10 schwarze 61: "nf", "fi", "r", "RE",
1.20 schwarze 62: "RS", "DT", "UC", "PD",
1.22 schwarze 63: "Sp", "Vb", "Ve", "de",
64: "dei", "am", "ami", "ig",
65: ".",
1.1 kristaps 66: };
67:
68: const char * const *man_macronames = __man_macronames;
69:
70: static struct man_node *man_node_alloc(int, int,
1.22 schwarze 71: enum man_type, enum mant);
1.1 kristaps 72: static int man_node_append(struct man *,
73: struct man_node *);
1.22 schwarze 74: static void man_node_free(struct man_node *);
75: static void man_node_unlink(struct man *,
76: struct man_node *);
1.1 kristaps 77: static int man_ptext(struct man *, int, char *);
78: static int man_pmacro(struct man *, int, char *);
79: static void man_free1(struct man *);
1.16 schwarze 80: static void man_alloc1(struct man *);
1.10 schwarze 81: static int pstring(struct man *, int, int,
82: const char *, size_t);
1.15 schwarze 83: static int macrowarn(struct man *, int, const char *);
1.1 kristaps 84:
85:
86: const struct man_node *
87: man_node(const struct man *m)
88: {
89:
90: return(MAN_HALT & m->flags ? NULL : m->first);
91: }
92:
93:
94: const struct man_meta *
95: man_meta(const struct man *m)
96: {
97:
98: return(MAN_HALT & m->flags ? NULL : &m->meta);
99: }
100:
101:
1.16 schwarze 102: void
1.1 kristaps 103: man_reset(struct man *man)
104: {
105:
106: man_free1(man);
1.16 schwarze 107: man_alloc1(man);
1.1 kristaps 108: }
109:
110:
111: void
112: man_free(struct man *man)
113: {
114:
115: man_free1(man);
116: free(man);
117: }
118:
119:
120: struct man *
121: man_alloc(void *data, int pflags, const struct man_cb *cb)
122: {
123: struct man *p;
124:
1.16 schwarze 125: p = mandoc_calloc(1, sizeof(struct man));
1.1 kristaps 126:
1.16 schwarze 127: if (cb)
128: memcpy(&p->cb, cb, sizeof(struct man_cb));
1.1 kristaps 129:
1.13 schwarze 130: man_hash_init();
1.1 kristaps 131: p->data = data;
132: p->pflags = pflags;
1.16 schwarze 133:
134: man_alloc1(p);
1.1 kristaps 135: return(p);
136: }
137:
138:
139: int
140: man_endparse(struct man *m)
141: {
142:
143: if (MAN_HALT & m->flags)
144: return(0);
145: else if (man_macroend(m))
146: return(1);
147: m->flags |= MAN_HALT;
148: return(0);
149: }
150:
151:
152: int
153: man_parseln(struct man *m, int ln, char *buf)
154: {
155:
1.23 schwarze 156: return('.' == *buf || '\'' == *buf ?
1.1 kristaps 157: man_pmacro(m, ln, buf) :
158: man_ptext(m, ln, buf));
159: }
160:
161:
162: static void
163: man_free1(struct man *man)
164: {
165:
166: if (man->first)
1.22 schwarze 167: man_node_delete(man, man->first);
1.1 kristaps 168: if (man->meta.title)
169: free(man->meta.title);
170: if (man->meta.source)
171: free(man->meta.source);
172: if (man->meta.vol)
173: free(man->meta.vol);
174: }
175:
176:
1.16 schwarze 177: static void
1.1 kristaps 178: man_alloc1(struct man *m)
179: {
180:
1.16 schwarze 181: memset(&m->meta, 0, sizeof(struct man_meta));
1.1 kristaps 182: m->flags = 0;
1.16 schwarze 183: m->last = mandoc_calloc(1, sizeof(struct man_node));
1.1 kristaps 184: m->first = m->last;
185: m->last->type = MAN_ROOT;
1.22 schwarze 186: m->last->tok = MAN_MAX;
1.1 kristaps 187: m->next = MAN_NEXT_CHILD;
188: }
189:
190:
191: static int
192: man_node_append(struct man *man, struct man_node *p)
193: {
194:
195: assert(man->last);
196: assert(man->first);
197: assert(MAN_ROOT != p->type);
198:
199: switch (man->next) {
200: case (MAN_NEXT_SIBLING):
201: man->last->next = p;
202: p->prev = man->last;
203: p->parent = man->last->parent;
204: break;
205: case (MAN_NEXT_CHILD):
206: man->last->child = p;
207: p->parent = man->last;
208: break;
209: default:
210: abort();
211: /* NOTREACHED */
212: }
1.5 schwarze 213:
1.22 schwarze 214: assert(p->parent);
1.5 schwarze 215: p->parent->nchild++;
1.1 kristaps 216:
1.9 schwarze 217: if ( ! man_valid_pre(man, p))
218: return(0);
219:
220: switch (p->type) {
221: case (MAN_HEAD):
222: assert(MAN_BLOCK == p->parent->type);
223: p->parent->head = p;
224: break;
225: case (MAN_BODY):
226: assert(MAN_BLOCK == p->parent->type);
227: p->parent->body = p;
228: break;
229: default:
230: break;
231: }
232:
1.1 kristaps 233: man->last = p;
234:
235: switch (p->type) {
236: case (MAN_TEXT):
237: if ( ! man_valid_post(man))
238: return(0);
239: if ( ! man_action_post(man))
240: return(0);
241: break;
242: default:
243: break;
244: }
245:
246: return(1);
247: }
248:
249:
250: static struct man_node *
1.22 schwarze 251: man_node_alloc(int line, int pos, enum man_type type, enum mant tok)
1.1 kristaps 252: {
253: struct man_node *p;
254:
1.16 schwarze 255: p = mandoc_calloc(1, sizeof(struct man_node));
1.1 kristaps 256: p->line = line;
257: p->pos = pos;
258: p->type = type;
259: p->tok = tok;
260: return(p);
261: }
262:
263:
264: int
1.22 schwarze 265: man_elem_alloc(struct man *m, int line, int pos, enum mant tok)
1.1 kristaps 266: {
267: struct man_node *p;
268:
269: p = man_node_alloc(line, pos, MAN_ELEM, tok);
1.10 schwarze 270: if ( ! man_node_append(m, p))
271: return(0);
272: m->next = MAN_NEXT_CHILD;
273: return(1);
1.1 kristaps 274: }
275:
276:
277: int
1.22 schwarze 278: man_head_alloc(struct man *m, int line, int pos, enum mant tok)
1.9 schwarze 279: {
280: struct man_node *p;
281:
282: p = man_node_alloc(line, pos, MAN_HEAD, tok);
283: if ( ! man_node_append(m, p))
284: return(0);
285: m->next = MAN_NEXT_CHILD;
286: return(1);
287: }
288:
289:
290: int
1.22 schwarze 291: man_body_alloc(struct man *m, int line, int pos, enum mant tok)
1.9 schwarze 292: {
293: struct man_node *p;
294:
295: p = man_node_alloc(line, pos, MAN_BODY, tok);
296: if ( ! man_node_append(m, p))
297: return(0);
298: m->next = MAN_NEXT_CHILD;
299: return(1);
300: }
301:
302:
303: int
1.22 schwarze 304: man_block_alloc(struct man *m, int line, int pos, enum mant tok)
1.9 schwarze 305: {
306: struct man_node *p;
307:
308: p = man_node_alloc(line, pos, MAN_BLOCK, tok);
309: if ( ! man_node_append(m, p))
310: return(0);
311: m->next = MAN_NEXT_CHILD;
312: return(1);
313: }
314:
315:
1.10 schwarze 316: static int
317: pstring(struct man *m, int line, int pos,
318: const char *p, size_t len)
1.1 kristaps 319: {
1.10 schwarze 320: struct man_node *n;
321: size_t sv;
1.1 kristaps 322:
1.22 schwarze 323: n = man_node_alloc(line, pos, MAN_TEXT, MAN_MAX);
1.16 schwarze 324: n->string = mandoc_malloc(len + 1);
1.10 schwarze 325: sv = strlcpy(n->string, p, len + 1);
326:
327: /* Prohibit truncation. */
328: assert(sv < len + 1);
329:
330: if ( ! man_node_append(m, n))
1.1 kristaps 331: return(0);
1.10 schwarze 332: m->next = MAN_NEXT_SIBLING;
333: return(1);
334: }
335:
336:
337: int
338: man_word_alloc(struct man *m, int line, int pos, const char *word)
339: {
340:
341: return(pstring(m, line, pos, word, strlen(word)));
1.1 kristaps 342: }
343:
344:
1.22 schwarze 345: /*
346: * Free all of the resources held by a node. This does NOT unlink a
347: * node from its context; for that, see man_node_unlink().
348: */
349: static void
1.1 kristaps 350: man_node_free(struct man_node *p)
351: {
352:
353: if (p->string)
354: free(p->string);
355: free(p);
356: }
357:
358:
359: void
1.22 schwarze 360: man_node_delete(struct man *m, struct man_node *p)
1.1 kristaps 361: {
362:
1.22 schwarze 363: while (p->child)
364: man_node_delete(m, p->child);
365:
366: man_node_unlink(m, p);
1.1 kristaps 367: man_node_free(p);
368: }
369:
370:
371: static int
372: man_ptext(struct man *m, int line, char *buf)
373: {
1.10 schwarze 374: int i, j;
1.18 schwarze 375: char sv;
1.10 schwarze 376:
377: /* Literal free-form text whitespace is preserved. */
378:
379: if (MAN_LITERAL & m->flags) {
380: if ( ! man_word_alloc(m, line, 0, buf))
381: return(0);
382: goto descope;
383: }
384:
385: /* First de-chunk and allocate words. */
386:
387: for (i = 0; ' ' == buf[i]; i++)
388: /* Skip leading whitespace. */ ;
1.18 schwarze 389:
390: if ('\0' == buf[i]) {
391: /* Trailing whitespace? */
392: if (i && ' ' == buf[i - 1])
393: if ( ! man_pwarn(m, line, i - 1, WTSPACE))
394: return(0);
1.10 schwarze 395: if ( ! pstring(m, line, 0, &buf[i], 0))
396: return(0);
397: goto descope;
398: }
1.1 kristaps 399:
1.10 schwarze 400: for (j = i; buf[i]; i++) {
401: if (' ' != buf[i])
402: continue;
403:
404: /* Escaped whitespace. */
405: if (i && ' ' == buf[i] && '\\' == buf[i - 1])
406: continue;
407:
1.18 schwarze 408: sv = buf[i];
409: buf[i++] = '\0';
410:
1.10 schwarze 411: if ( ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
412: return(0);
413:
1.18 schwarze 414: /* Trailing whitespace? Check at overwritten byte. */
415:
416: if (' ' == sv && '\0' == buf[i])
417: if ( ! man_pwarn(m, line, i - 1, WTSPACE))
418: return(0);
419:
1.10 schwarze 420: for ( ; ' ' == buf[i]; i++)
421: /* Skip trailing whitespace. */ ;
422:
423: j = i;
1.18 schwarze 424:
425: /* Trailing whitespace? */
426:
427: if (' ' == buf[i - 1] && '\0' == buf[i])
428: if ( ! man_pwarn(m, line, i - 1, WTSPACE))
429: return(0);
430:
431: if ('\0' == buf[i])
1.10 schwarze 432: break;
433: }
1.9 schwarze 434:
1.10 schwarze 435: if (j != i && ! pstring(m, line, j, &buf[j], (size_t)(i - j)))
1.1 kristaps 436: return(0);
1.10 schwarze 437:
438: descope:
1.1 kristaps 439:
440: /*
1.9 schwarze 441: * Co-ordinate what happens with having a next-line scope open:
442: * first close out the element scope (if applicable), then close
443: * out the block scope (also if applicable).
1.1 kristaps 444: */
445:
1.9 schwarze 446: if (MAN_ELINE & m->flags) {
447: m->flags &= ~MAN_ELINE;
1.23 schwarze 448: if ( ! man_unscope(m, m->last->parent, WERRMAX))
1.9 schwarze 449: return(0);
450: }
451:
452: if ( ! (MAN_BLINE & m->flags))
1.1 kristaps 453: return(1);
1.9 schwarze 454: m->flags &= ~MAN_BLINE;
1.1 kristaps 455:
1.23 schwarze 456: if ( ! man_unscope(m, m->last->parent, WERRMAX))
1.1 kristaps 457: return(0);
1.9 schwarze 458: return(man_body_alloc(m, line, 0, m->last->tok));
1.1 kristaps 459: }
460:
461:
1.15 schwarze 462: static int
463: macrowarn(struct man *m, int ln, const char *buf)
464: {
465: if ( ! (MAN_IGN_MACRO & m->pflags))
466: return(man_verr(m, ln, 0,
467: "unknown macro: %s%s",
468: buf, strlen(buf) > 3 ? "..." : ""));
469: return(man_vwarn(m, ln, 0, "unknown macro: %s%s",
470: buf, strlen(buf) > 3 ? "..." : ""));
471: }
472:
473:
1.1 kristaps 474: int
475: man_pmacro(struct man *m, int ln, char *buf)
476: {
1.24 ! schwarze 477: int i, j, ppos;
1.22 schwarze 478: enum mant tok;
1.10 schwarze 479: char mac[5];
480: struct man_node *n;
1.1 kristaps 481:
482: /* Comments and empties are quickly ignored. */
483:
1.17 schwarze 484: if ('\0' == buf[1])
485: return(1);
1.1 kristaps 486:
487: i = 1;
488:
1.23 schwarze 489: /*
490: * Skip whitespace between the control character and initial
491: * text. "Whitespace" is both spaces and tabs.
492: */
493: if (' ' == buf[i] || '\t' == buf[i]) {
1.1 kristaps 494: i++;
1.23 schwarze 495: while (buf[i] && (' ' == buf[i] || '\t' == buf[i]))
1.1 kristaps 496: i++;
1.18 schwarze 497: if ('\0' == buf[i])
1.1 kristaps 498: goto out;
499: }
500:
501: ppos = i;
502:
503: /* Copy the first word into a nil-terminated buffer. */
504:
505: for (j = 0; j < 4; j++, i++) {
1.18 schwarze 506: if ('\0' == (mac[j] = buf[i]))
1.1 kristaps 507: break;
508: else if (' ' == buf[i])
509: break;
1.11 schwarze 510:
511: /* Check for invalid characters. */
512:
513: if (isgraph((u_char)buf[i]))
514: continue;
515: return(man_perr(m, ln, i, WNPRINT));
1.1 kristaps 516: }
517:
1.17 schwarze 518: mac[j] = '\0';
1.1 kristaps 519:
520: if (j == 4 || j < 1) {
521: if ( ! (MAN_IGN_MACRO & m->pflags)) {
1.9 schwarze 522: (void)man_perr(m, ln, ppos, WMACROFORM);
1.1 kristaps 523: goto err;
524: }
1.9 schwarze 525: if ( ! man_pwarn(m, ln, ppos, WMACROFORM))
1.1 kristaps 526: goto err;
527: return(1);
528: }
529:
1.22 schwarze 530: if (MAN_MAX == (tok = man_hash_find(mac))) {
1.15 schwarze 531: if ( ! macrowarn(m, ln, mac))
1.1 kristaps 532: goto err;
533: return(1);
534: }
535:
536: /* The macro is sane. Jump to the next word. */
537:
538: while (buf[i] && ' ' == buf[i])
539: i++;
1.18 schwarze 540:
541: /* Trailing whitespace? */
542:
543: if ('\0' == buf[i] && ' ' == buf[i - 1])
544: if ( ! man_pwarn(m, ln, i - 1, WTSPACE))
545: goto err;
1.1 kristaps 546:
1.21 schwarze 547: /*
548: * Remove prior ELINE macro, as it's being clobbering by a new
549: * macro. Note that NSCOPED macros do not close out ELINE
550: * macros---they don't print text---so we let those slip by.
1.24 ! schwarze 551: * NOTE: we don't allow roff blocks (NOCLOSE) to be embedded
! 552: * here because that would stipulate blocks as children of
! 553: * elements!
1.21 schwarze 554: */
555:
1.22 schwarze 556: if ( ! (MAN_NSCOPED & man_macros[tok].flags) &&
1.21 schwarze 557: m->flags & MAN_ELINE) {
558: assert(MAN_TEXT != m->last->type);
559:
560: /*
561: * This occurs in the following construction:
562: * .B
563: * .br
564: * .B
565: * .br
566: * I hate man macros.
567: * Flat-out disallow this madness.
568: */
569: if (MAN_NSCOPED & man_macros[m->last->tok].flags)
570: return(man_perr(m, ln, ppos, WLNSCOPE));
1.10 schwarze 571:
572: n = m->last;
1.21 schwarze 573:
574: assert(n);
1.10 schwarze 575: assert(NULL == n->child);
576: assert(0 == n->nchild);
1.21 schwarze 577:
1.10 schwarze 578: if ( ! man_nwarn(m, n, WLNSCOPE))
579: return(0);
580:
1.22 schwarze 581: man_node_delete(m, n);
1.10 schwarze 582: m->flags &= ~MAN_ELINE;
583: }
584:
1.24 ! schwarze 585: /*
! 586: * Save the fact that we're in the next-line for a block. In
! 587: * this way, embedded roff instructions can "remember" state
! 588: * when they exit.
! 589: */
! 590:
! 591: if (MAN_BLINE & m->flags)
! 592: m->flags |= MAN_BPLINE;
! 593:
! 594: /* Call to handler... */
1.1 kristaps 595:
1.22 schwarze 596: assert(man_macros[tok].fp);
597: if ( ! (*man_macros[tok].fp)(m, tok, ln, ppos, &i, buf))
1.1 kristaps 598: goto err;
599:
600: out:
1.21 schwarze 601: /*
602: * We weren't in a block-line scope when entering the
603: * above-parsed macro, so return.
604: */
605:
1.24 ! schwarze 606: if ( ! (MAN_BPLINE & m->flags)) {
1.21 schwarze 607: m->flags &= ~MAN_ILINE;
1.9 schwarze 608: return(1);
1.21 schwarze 609: }
1.24 ! schwarze 610: m->flags &= ~MAN_BPLINE;
1.21 schwarze 611:
612: /*
613: * If we're in a block scope, then allow this macro to slip by
614: * without closing scope around it.
615: */
616:
617: if (MAN_ILINE & m->flags) {
618: m->flags &= ~MAN_ILINE;
619: return(1);
620: }
1.9 schwarze 621:
622: /*
623: * If we've opened a new next-line element scope, then return
624: * now, as the next line will close out the block scope.
625: */
626:
627: if (MAN_ELINE & m->flags)
628: return(1);
629:
630: /* Close out the block scope opened in the prior line. */
1.1 kristaps 631:
1.9 schwarze 632: assert(MAN_BLINE & m->flags);
633: m->flags &= ~MAN_BLINE;
1.1 kristaps 634:
1.23 schwarze 635: if ( ! man_unscope(m, m->last->parent, WERRMAX))
1.9 schwarze 636: return(0);
637: return(man_body_alloc(m, ln, 0, m->last->tok));
1.1 kristaps 638:
639: err: /* Error out. */
640:
641: m->flags |= MAN_HALT;
642: return(0);
643: }
644:
645:
646: int
647: man_verr(struct man *man, int ln, int pos, const char *fmt, ...)
648: {
649: char buf[256];
650: va_list ap;
651:
652: if (NULL == man->cb.man_err)
653: return(0);
654:
655: va_start(ap, fmt);
656: (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
657: va_end(ap);
658: return((*man->cb.man_err)(man->data, ln, pos, buf));
659: }
660:
661:
662: int
663: man_vwarn(struct man *man, int ln, int pos, const char *fmt, ...)
664: {
665: char buf[256];
666: va_list ap;
667:
668: if (NULL == man->cb.man_warn)
669: return(0);
670:
671: va_start(ap, fmt);
672: (void)vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
673: va_end(ap);
674: return((*man->cb.man_warn)(man->data, ln, pos, buf));
675: }
676:
677:
1.4 schwarze 678: int
1.7 schwarze 679: man_err(struct man *m, int line, int pos, int iserr, enum merr type)
1.4 schwarze 680: {
681: const char *p;
682:
1.7 schwarze 683: p = __man_merrnames[(int)type];
1.4 schwarze 684: assert(p);
685:
686: if (iserr)
687: return(man_verr(m, line, pos, p));
688:
689: return(man_vwarn(m, line, pos, p));
1.21 schwarze 690: }
691:
692:
1.22 schwarze 693: /*
694: * Unlink a node from its context. If "m" is provided, the last parse
695: * point will also be adjusted accordingly.
696: */
697: static void
1.21 schwarze 698: man_node_unlink(struct man *m, struct man_node *n)
699: {
700:
1.22 schwarze 701: /* Adjust siblings. */
702:
703: if (n->prev)
1.21 schwarze 704: n->prev->next = n->next;
1.22 schwarze 705: if (n->next)
706: n->next->prev = n->prev;
707:
708: /* Adjust parent. */
709:
710: if (n->parent) {
711: n->parent->nchild--;
712: if (n->parent->child == n)
713: n->parent->child = n->prev ? n->prev : n->next;
714: }
715:
716: /* Adjust parse point, if applicable. */
717:
718: if (m && m->last == n) {
719: /*XXX: this can occur when bailing from validation. */
720: /*assert(NULL == n->next);*/
721: if (n->prev) {
1.21 schwarze 722: m->last = n->prev;
723: m->next = MAN_NEXT_SIBLING;
1.22 schwarze 724: } else {
1.21 schwarze 725: m->last = n->parent;
726: m->next = MAN_NEXT_CHILD;
727: }
728: }
729:
1.22 schwarze 730: if (m && m->first == n)
731: m->first = NULL;
1.4 schwarze 732: }