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