Annotation of mandoc/man.c, Revision 1.82
1.82 ! schwarze 1: /* $Id: man.c,v 1.81 2010/07/07 15:04:54 kristaps Exp $ */
1.1 kristaps 2: /*
1.82 ! schwarze 3: * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
1.18 kristaps 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.18 kristaps 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.47 kristaps 17: #ifdef HAVE_CONFIG_H
18: #include "config.h"
19: #endif
20:
1.41 kristaps 21: #include <sys/types.h>
22:
1.1 kristaps 23: #include <assert.h>
24: #include <ctype.h>
25: #include <stdarg.h>
26: #include <stdlib.h>
27: #include <stdio.h>
28: #include <string.h>
29:
1.74 kristaps 30: #include "mandoc.h"
1.1 kristaps 31: #include "libman.h"
1.45 kristaps 32: #include "libmandoc.h"
1.1 kristaps 33:
34: const char *const __man_macronames[MAN_MAX] = {
1.21 kristaps 35: "br", "TH", "SH", "SS",
1.1 kristaps 36: "TP", "LP", "PP", "P",
37: "IP", "HP", "SM", "SB",
38: "BI", "IB", "BR", "RB",
1.11 kristaps 39: "R", "B", "I", "IR",
1.29 kristaps 40: "RI", "na", "i", "sp",
1.30 kristaps 41: "nf", "fi", "r", "RE",
1.52 kristaps 42: "RS", "DT", "UC", "PD",
1.73 joerg 43: "Sp", "Vb", "Ve", "AT",
1.1 kristaps 44: };
45:
46: const char * const *man_macronames = __man_macronames;
47:
1.16 kristaps 48: static struct man_node *man_node_alloc(int, int,
1.53 kristaps 49: enum man_type, enum mant);
1.1 kristaps 50: static int man_node_append(struct man *,
51: struct man_node *);
1.54 kristaps 52: static void man_node_free(struct man_node *);
53: static void man_node_unlink(struct man *,
54: struct man_node *);
1.72 kristaps 55: static int man_ptext(struct man *, int, char *, int);
1.79 kristaps 56: static int man_pmacro(struct man *, int, char *, int);
1.2 kristaps 57: static void man_free1(struct man *);
1.45 kristaps 58: static void man_alloc1(struct man *);
1.72 kristaps 59: static int macrowarn(struct man *, int, const char *, int);
1.1 kristaps 60:
61:
62: const struct man_node *
1.2 kristaps 63: man_node(const struct man *m)
1.1 kristaps 64: {
65:
1.2 kristaps 66: return(MAN_HALT & m->flags ? NULL : m->first);
1.1 kristaps 67: }
68:
69:
70: const struct man_meta *
1.2 kristaps 71: man_meta(const struct man *m)
1.1 kristaps 72: {
73:
1.2 kristaps 74: return(MAN_HALT & m->flags ? NULL : &m->meta);
1.1 kristaps 75: }
76:
77:
1.45 kristaps 78: void
1.1 kristaps 79: man_reset(struct man *man)
80: {
81:
1.2 kristaps 82: man_free1(man);
1.45 kristaps 83: man_alloc1(man);
1.1 kristaps 84: }
85:
86:
87: void
88: man_free(struct man *man)
89: {
90:
1.2 kristaps 91: man_free1(man);
1.1 kristaps 92: free(man);
93: }
94:
95:
96: struct man *
1.80 kristaps 97: man_alloc(struct regset *regs, void *data,
98: int pflags, mandocmsg msg)
1.1 kristaps 99: {
100: struct man *p;
101:
1.45 kristaps 102: p = mandoc_calloc(1, sizeof(struct man));
1.2 kristaps 103:
1.40 kristaps 104: man_hash_init();
1.4 kristaps 105: p->data = data;
1.7 kristaps 106: p->pflags = pflags;
1.74 kristaps 107: p->msg = msg;
1.79 kristaps 108: p->regs = regs;
1.45 kristaps 109:
110: man_alloc1(p);
1.1 kristaps 111: return(p);
112: }
113:
114:
115: int
116: man_endparse(struct man *m)
117: {
118:
1.3 kristaps 119: if (MAN_HALT & m->flags)
120: return(0);
121: else if (man_macroend(m))
122: return(1);
123: m->flags |= MAN_HALT;
124: return(0);
1.1 kristaps 125: }
126:
127:
128: int
1.79 kristaps 129: man_parseln(struct man *m, int ln, char *buf, int offs)
1.1 kristaps 130: {
131:
1.72 kristaps 132: if (MAN_HALT & m->flags)
133: return(0);
134:
135: return(('.' == buf[offs] || '\'' == buf[offs]) ?
1.79 kristaps 136: man_pmacro(m, ln, buf, offs) :
1.72 kristaps 137: man_ptext(m, ln, buf, offs));
1.1 kristaps 138: }
139:
140:
1.2 kristaps 141: static void
142: man_free1(struct man *man)
143: {
144:
145: if (man->first)
1.54 kristaps 146: man_node_delete(man, man->first);
1.2 kristaps 147: if (man->meta.title)
148: free(man->meta.title);
1.6 kristaps 149: if (man->meta.source)
150: free(man->meta.source);
1.75 kristaps 151: if (man->meta.rawdate)
152: free(man->meta.rawdate);
1.2 kristaps 153: if (man->meta.vol)
154: free(man->meta.vol);
1.68 kristaps 155: if (man->meta.msec)
156: free(man->meta.msec);
1.2 kristaps 157: }
158:
159:
1.45 kristaps 160: static void
1.2 kristaps 161: man_alloc1(struct man *m)
162: {
163:
1.44 kristaps 164: memset(&m->meta, 0, sizeof(struct man_meta));
1.2 kristaps 165: m->flags = 0;
1.45 kristaps 166: m->last = mandoc_calloc(1, sizeof(struct man_node));
1.2 kristaps 167: m->first = m->last;
168: m->last->type = MAN_ROOT;
1.54 kristaps 169: m->last->tok = MAN_MAX;
1.2 kristaps 170: m->next = MAN_NEXT_CHILD;
171: }
172:
173:
1.1 kristaps 174: static int
175: man_node_append(struct man *man, struct man_node *p)
176: {
177:
178: assert(man->last);
179: assert(man->first);
180: assert(MAN_ROOT != p->type);
181:
182: switch (man->next) {
183: case (MAN_NEXT_SIBLING):
184: man->last->next = p;
185: p->prev = man->last;
186: p->parent = man->last->parent;
187: break;
188: case (MAN_NEXT_CHILD):
189: man->last->child = p;
190: p->parent = man->last;
191: break;
192: default:
193: abort();
194: /* NOTREACHED */
195: }
1.22 kristaps 196:
1.54 kristaps 197: assert(p->parent);
1.22 kristaps 198: p->parent->nchild++;
1.1 kristaps 199:
1.29 kristaps 200: if ( ! man_valid_pre(man, p))
201: return(0);
202:
203: switch (p->type) {
204: case (MAN_HEAD):
205: assert(MAN_BLOCK == p->parent->type);
206: p->parent->head = p;
207: break;
208: case (MAN_BODY):
209: assert(MAN_BLOCK == p->parent->type);
210: p->parent->body = p;
211: break;
212: default:
213: break;
214: }
215:
1.2 kristaps 216: man->last = p;
217:
1.1 kristaps 218: switch (p->type) {
1.2 kristaps 219: case (MAN_TEXT):
220: if ( ! man_valid_post(man))
221: return(0);
222: if ( ! man_action_post(man))
223: return(0);
1.1 kristaps 224: break;
225: default:
226: break;
227: }
228:
229: return(1);
230: }
231:
232:
233: static struct man_node *
1.53 kristaps 234: man_node_alloc(int line, int pos, enum man_type type, enum mant tok)
1.1 kristaps 235: {
236: struct man_node *p;
237:
1.45 kristaps 238: p = mandoc_calloc(1, sizeof(struct man_node));
1.1 kristaps 239: p->line = line;
240: p->pos = pos;
241: p->type = type;
1.16 kristaps 242: p->tok = tok;
1.1 kristaps 243: return(p);
244: }
245:
246:
247: int
1.53 kristaps 248: man_elem_alloc(struct man *m, int line, int pos, enum mant tok)
1.1 kristaps 249: {
250: struct man_node *p;
251:
1.16 kristaps 252: p = man_node_alloc(line, pos, MAN_ELEM, tok);
1.30 kristaps 253: if ( ! man_node_append(m, p))
254: return(0);
255: m->next = MAN_NEXT_CHILD;
256: return(1);
1.1 kristaps 257: }
258:
259:
260: int
1.53 kristaps 261: man_head_alloc(struct man *m, int line, int pos, enum mant tok)
1.29 kristaps 262: {
263: struct man_node *p;
264:
265: p = man_node_alloc(line, pos, MAN_HEAD, tok);
266: if ( ! man_node_append(m, p))
267: return(0);
268: m->next = MAN_NEXT_CHILD;
269: return(1);
270: }
271:
272:
273: int
1.53 kristaps 274: man_body_alloc(struct man *m, int line, int pos, enum mant tok)
1.29 kristaps 275: {
276: struct man_node *p;
277:
278: p = man_node_alloc(line, pos, MAN_BODY, tok);
279: if ( ! man_node_append(m, p))
280: return(0);
281: m->next = MAN_NEXT_CHILD;
282: return(1);
283: }
284:
285:
286: int
1.53 kristaps 287: man_block_alloc(struct man *m, int line, int pos, enum mant tok)
1.29 kristaps 288: {
289: struct man_node *p;
290:
291: p = man_node_alloc(line, pos, MAN_BLOCK, tok);
292: if ( ! man_node_append(m, p))
293: return(0);
294: m->next = MAN_NEXT_CHILD;
295: return(1);
296: }
297:
298:
1.61 kristaps 299: int
300: man_word_alloc(struct man *m, int line, int pos, const char *word)
1.1 kristaps 301: {
1.31 kristaps 302: struct man_node *n;
1.61 kristaps 303: size_t sv, len;
304:
305: len = strlen(word);
1.1 kristaps 306:
1.53 kristaps 307: n = man_node_alloc(line, pos, MAN_TEXT, MAN_MAX);
1.45 kristaps 308: n->string = mandoc_malloc(len + 1);
1.61 kristaps 309: sv = strlcpy(n->string, word, len + 1);
1.31 kristaps 310:
311: /* Prohibit truncation. */
312: assert(sv < len + 1);
313:
314: if ( ! man_node_append(m, n))
1.30 kristaps 315: return(0);
1.61 kristaps 316:
1.30 kristaps 317: m->next = MAN_NEXT_SIBLING;
318: return(1);
1.1 kristaps 319: }
320:
321:
1.54 kristaps 322: /*
323: * Free all of the resources held by a node. This does NOT unlink a
324: * node from its context; for that, see man_node_unlink().
325: */
326: static void
1.1 kristaps 327: man_node_free(struct man_node *p)
328: {
329:
330: if (p->string)
331: free(p->string);
332: free(p);
333: }
334:
335:
336: void
1.54 kristaps 337: man_node_delete(struct man *m, struct man_node *p)
1.1 kristaps 338: {
339:
1.54 kristaps 340: while (p->child)
341: man_node_delete(m, p->child);
342:
343: man_node_unlink(m, p);
1.1 kristaps 344: man_node_free(p);
345: }
346:
347:
348: static int
1.72 kristaps 349: man_ptext(struct man *m, int line, char *buf, int offs)
1.1 kristaps 350: {
1.61 kristaps 351: int i;
1.60 kristaps 352:
353: /* Ignore bogus comments. */
354:
1.72 kristaps 355: if ('\\' == buf[offs] &&
356: '.' == buf[offs + 1] &&
357: '"' == buf[offs + 2])
1.74 kristaps 358: return(man_pmsg(m, line, offs, MANDOCERR_BADCOMMENT));
1.31 kristaps 359:
1.35 kristaps 360: /* Literal free-form text whitespace is preserved. */
361:
362: if (MAN_LITERAL & m->flags) {
1.72 kristaps 363: if ( ! man_word_alloc(m, line, offs, buf + offs))
1.35 kristaps 364: return(0);
365: goto descope;
366: }
367:
1.61 kristaps 368: /* Pump blank lines directly into the backend. */
1.31 kristaps 369:
1.72 kristaps 370: for (i = offs; ' ' == buf[i]; i++)
1.31 kristaps 371: /* Skip leading whitespace. */ ;
1.48 kristaps 372:
1.49 kristaps 373: if ('\0' == buf[i]) {
1.61 kristaps 374: /* Allocate a blank entry. */
1.72 kristaps 375: if ( ! man_word_alloc(m, line, offs, ""))
1.31 kristaps 376: return(0);
377: goto descope;
378: }
379:
1.63 kristaps 380: /*
381: * Warn if the last un-escaped character is whitespace. Then
382: * strip away the remaining spaces (tabs stay!).
383: */
1.29 kristaps 384:
1.61 kristaps 385: i = (int)strlen(buf);
386: assert(i);
1.49 kristaps 387:
1.63 kristaps 388: if (' ' == buf[i - 1] || '\t' == buf[i - 1]) {
1.64 kristaps 389: if (i > 1 && '\\' != buf[i - 2])
1.74 kristaps 390: if ( ! man_pmsg(m, line, i - 1, MANDOCERR_EOLNSPACE))
1.49 kristaps 391: return(0);
1.63 kristaps 392:
393: for (--i; i && ' ' == buf[i]; i--)
394: /* Spin back to non-space. */ ;
395:
396: /* Jump ahead of escaped whitespace. */
397: i += '\\' == buf[i] ? 2 : 1;
398:
399: buf[i] = '\0';
400: }
1.49 kristaps 401:
1.72 kristaps 402: if ( ! man_word_alloc(m, line, offs, buf + offs))
1.1 kristaps 403: return(0);
1.65 kristaps 404:
405: /*
406: * End-of-sentence check. If the last character is an unescaped
407: * EOS character, then flag the node as being the end of a
408: * sentence. The front-end will know how to interpret this.
409: */
1.67 kristaps 410:
1.65 kristaps 411: assert(i);
1.66 kristaps 412: if (mandoc_eos(buf, (size_t)i))
1.65 kristaps 413: m->last->flags |= MAN_EOS;
1.31 kristaps 414:
415: descope:
1.11 kristaps 416: /*
1.29 kristaps 417: * Co-ordinate what happens with having a next-line scope open:
418: * first close out the element scope (if applicable), then close
419: * out the block scope (also if applicable).
1.11 kristaps 420: */
421:
1.29 kristaps 422: if (MAN_ELINE & m->flags) {
423: m->flags &= ~MAN_ELINE;
1.74 kristaps 424: if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
1.29 kristaps 425: return(0);
426: }
427:
428: if ( ! (MAN_BLINE & m->flags))
1.11 kristaps 429: return(1);
1.29 kristaps 430: m->flags &= ~MAN_BLINE;
1.11 kristaps 431:
1.74 kristaps 432: if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
1.11 kristaps 433: return(0);
1.72 kristaps 434: return(man_body_alloc(m, line, offs, m->last->tok));
1.1 kristaps 435: }
436:
437:
1.43 kristaps 438: static int
1.72 kristaps 439: macrowarn(struct man *m, int ln, const char *buf, int offs)
1.43 kristaps 440: {
1.74 kristaps 441: int rc;
442:
443: rc = man_vmsg(m, MANDOCERR_MACRO, ln, offs,
444: "unknown macro: %s%s",
445: buf, strlen(buf) > 3 ? "..." : "");
446:
447: return(MAN_IGN_MACRO & m->pflags ? rc : 0);
1.43 kristaps 448: }
449:
450:
1.1 kristaps 451: int
1.79 kristaps 452: man_pmacro(struct man *m, int ln, char *buf, int offs)
1.1 kristaps 453: {
1.58 kristaps 454: int i, j, ppos;
1.53 kristaps 455: enum mant tok;
1.34 kristaps 456: char mac[5];
457: struct man_node *n;
1.1 kristaps 458:
459: /* Comments and empties are quickly ignored. */
460:
1.72 kristaps 461: offs++;
462:
463: if ('\0' == buf[offs])
1.46 kristaps 464: return(1);
1.1 kristaps 465:
1.72 kristaps 466: i = offs;
1.9 kristaps 467:
1.56 kristaps 468: /*
469: * Skip whitespace between the control character and initial
470: * text. "Whitespace" is both spaces and tabs.
471: */
1.62 kristaps 472:
1.57 kristaps 473: if (' ' == buf[i] || '\t' == buf[i]) {
1.9 kristaps 474: i++;
1.56 kristaps 475: while (buf[i] && (' ' == buf[i] || '\t' == buf[i]))
1.1 kristaps 476: i++;
1.48 kristaps 477: if ('\0' == buf[i])
1.11 kristaps 478: goto out;
1.1 kristaps 479: }
480:
1.10 kristaps 481: ppos = i;
482:
1.1 kristaps 483: /* Copy the first word into a nil-terminated buffer. */
484:
1.10 kristaps 485: for (j = 0; j < 4; j++, i++) {
1.48 kristaps 486: if ('\0' == (mac[j] = buf[i]))
1.1 kristaps 487: break;
1.10 kristaps 488: else if (' ' == buf[i])
1.1 kristaps 489: break;
1.38 kristaps 490:
491: /* Check for invalid characters. */
492:
493: if (isgraph((u_char)buf[i]))
494: continue;
1.74 kristaps 495: if ( ! man_pmsg(m, ln, i, MANDOCERR_BADCHAR))
496: return(0);
497: i--;
1.1 kristaps 498: }
499:
1.46 kristaps 500: mac[j] = '\0';
1.1 kristaps 501:
1.9 kristaps 502: if (j == 4 || j < 1) {
1.74 kristaps 503: if ( ! macrowarn(m, ln, mac, ppos))
1.7 kristaps 504: goto err;
1.12 kristaps 505: return(1);
1.7 kristaps 506: }
1.1 kristaps 507:
1.53 kristaps 508: if (MAN_MAX == (tok = man_hash_find(mac))) {
1.72 kristaps 509: if ( ! macrowarn(m, ln, mac, ppos))
1.7 kristaps 510: goto err;
1.12 kristaps 511: return(1);
1.1 kristaps 512: }
513:
514: /* The macro is sane. Jump to the next word. */
515:
516: while (buf[i] && ' ' == buf[i])
517: i++;
518:
1.62 kristaps 519: /*
520: * Trailing whitespace. Note that tabs are allowed to be passed
521: * into the parser as "text", so we only warn about spaces here.
522: */
1.48 kristaps 523:
524: if ('\0' == buf[i] && ' ' == buf[i - 1])
1.74 kristaps 525: if ( ! man_pmsg(m, ln, i - 1, MANDOCERR_EOLNSPACE))
1.48 kristaps 526: goto err;
527:
1.50 kristaps 528: /*
1.51 kristaps 529: * Remove prior ELINE macro, as it's being clobbering by a new
530: * macro. Note that NSCOPED macros do not close out ELINE
531: * macros---they don't print text---so we let those slip by.
1.50 kristaps 532: */
1.34 kristaps 533:
1.53 kristaps 534: if ( ! (MAN_NSCOPED & man_macros[tok].flags) &&
1.51 kristaps 535: m->flags & MAN_ELINE) {
536: assert(MAN_TEXT != m->last->type);
537:
538: /*
539: * This occurs in the following construction:
540: * .B
541: * .br
542: * .B
543: * .br
544: * I hate man macros.
545: * Flat-out disallow this madness.
546: */
1.74 kristaps 547: if (MAN_NSCOPED & man_macros[m->last->tok].flags) {
548: man_pmsg(m, ln, ppos, MANDOCERR_SYNTLINESCOPE);
549: return(0);
550: }
1.51 kristaps 551:
1.34 kristaps 552: n = m->last;
1.51 kristaps 553:
554: assert(n);
1.34 kristaps 555: assert(NULL == n->child);
1.37 kristaps 556: assert(0 == n->nchild);
1.51 kristaps 557:
1.74 kristaps 558: if ( ! man_nmsg(m, n, MANDOCERR_LINESCOPE))
1.34 kristaps 559: return(0);
560:
1.54 kristaps 561: man_node_delete(m, n);
1.34 kristaps 562: m->flags &= ~MAN_ELINE;
563: }
564:
1.59 kristaps 565: /*
566: * Save the fact that we're in the next-line for a block. In
567: * this way, embedded roff instructions can "remember" state
568: * when they exit.
569: */
570:
571: if (MAN_BLINE & m->flags)
572: m->flags |= MAN_BPLINE;
573:
574: /* Call to handler... */
1.1 kristaps 575:
1.53 kristaps 576: assert(man_macros[tok].fp);
1.79 kristaps 577: if ( ! (*man_macros[tok].fp)(m, tok, ln, ppos, &i, buf))
1.1 kristaps 578: goto err;
579:
1.11 kristaps 580: out:
1.50 kristaps 581: /*
582: * We weren't in a block-line scope when entering the
583: * above-parsed macro, so return.
584: */
585:
1.58 kristaps 586: if ( ! (MAN_BPLINE & m->flags)) {
1.50 kristaps 587: m->flags &= ~MAN_ILINE;
1.29 kristaps 588: return(1);
1.50 kristaps 589: }
1.58 kristaps 590: m->flags &= ~MAN_BPLINE;
1.50 kristaps 591:
592: /*
593: * If we're in a block scope, then allow this macro to slip by
594: * without closing scope around it.
595: */
596:
597: if (MAN_ILINE & m->flags) {
598: m->flags &= ~MAN_ILINE;
599: return(1);
600: }
1.29 kristaps 601:
602: /*
603: * If we've opened a new next-line element scope, then return
604: * now, as the next line will close out the block scope.
605: */
606:
607: if (MAN_ELINE & m->flags)
608: return(1);
609:
610: /* Close out the block scope opened in the prior line. */
1.11 kristaps 611:
1.29 kristaps 612: assert(MAN_BLINE & m->flags);
613: m->flags &= ~MAN_BLINE;
1.11 kristaps 614:
1.74 kristaps 615: if ( ! man_unscope(m, m->last->parent, MANDOCERR_MAX))
1.29 kristaps 616: return(0);
1.72 kristaps 617: return(man_body_alloc(m, ln, offs, m->last->tok));
1.1 kristaps 618:
619: err: /* Error out. */
620:
1.2 kristaps 621: m->flags |= MAN_HALT;
1.1 kristaps 622: return(0);
623: }
1.3 kristaps 624:
1.4 kristaps 625:
626: int
1.74 kristaps 627: man_vmsg(struct man *man, enum mandocerr t,
628: int ln, int pos, const char *fmt, ...)
1.4 kristaps 629: {
630: char buf[256];
631: va_list ap;
632:
633: va_start(ap, fmt);
1.74 kristaps 634: vsnprintf(buf, sizeof(buf) - 1, fmt, ap);
1.4 kristaps 635: va_end(ap);
1.74 kristaps 636: return((*man->msg)(t, man->data, ln, pos, buf));
1.51 kristaps 637: }
638:
639:
1.54 kristaps 640: /*
641: * Unlink a node from its context. If "m" is provided, the last parse
642: * point will also be adjusted accordingly.
643: */
644: static void
1.51 kristaps 645: man_node_unlink(struct man *m, struct man_node *n)
646: {
647:
1.54 kristaps 648: /* Adjust siblings. */
649:
650: if (n->prev)
1.51 kristaps 651: n->prev->next = n->next;
1.54 kristaps 652: if (n->next)
653: n->next->prev = n->prev;
654:
655: /* Adjust parent. */
656:
657: if (n->parent) {
658: n->parent->nchild--;
659: if (n->parent->child == n)
660: n->parent->child = n->prev ? n->prev : n->next;
661: }
662:
663: /* Adjust parse point, if applicable. */
664:
665: if (m && m->last == n) {
666: /*XXX: this can occur when bailing from validation. */
667: /*assert(NULL == n->next);*/
668: if (n->prev) {
1.51 kristaps 669: m->last = n->prev;
670: m->next = MAN_NEXT_SIBLING;
1.54 kristaps 671: } else {
1.51 kristaps 672: m->last = n->parent;
673: m->next = MAN_NEXT_CHILD;
674: }
675: }
676:
1.54 kristaps 677: if (m && m->first == n)
678: m->first = NULL;
1.23 kristaps 679: }
CVSweb