=================================================================== RCS file: /cvs/mandoc/man_macro.c,v retrieving revision 1.5 retrieving revision 1.7 diff -u -p -r1.5 -r1.7 --- mandoc/man_macro.c 2009/03/25 15:17:49 1.5 +++ mandoc/man_macro.c 2009/03/25 16:07:36 1.7 @@ -1,4 +1,4 @@ -/* $Id: man_macro.c,v 1.5 2009/03/25 15:17:49 kristaps Exp $ */ +/* $Id: man_macro.c,v 1.7 2009/03/25 16:07:36 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -56,15 +56,34 @@ man_macro(struct man *man, int tok, int line, man->next = MAN_NEXT_SIBLING; } - for ( ; man->last && man->last != n; - man->last = man->last->parent) + /* + * Note that when TH is pruned, we'll be back at the root, so + * make sure that we don't clobber as its sibling. + */ + + for ( ; man->last; man->last = man->last->parent) { + if (man->last == n) + break; + if (man->last->type == MAN_ROOT) + break; if ( ! man_valid_post(man)) return(0); + if ( ! man_action_post(man)) + return(0); + } assert(man->last); - if ( ! man_valid_post(man)) + + /* + * Same here regarding whether we're back at the root. + */ + + if (man->last->type != MAN_ROOT && ! man_valid_post(man)) return(0); - man->next = MAN_NEXT_SIBLING; + if (man->last->type != MAN_ROOT && ! man_action_post(man)) + return(0); + if (man->last->type != MAN_ROOT) + man->next = MAN_NEXT_SIBLING; return(1); } @@ -74,7 +93,20 @@ int man_macroend(struct man *m) { - /* TODO: validate & actions. */ + for ( ; m->last && m->last != m->first; + m->last = m->last->parent) { + if ( ! man_valid_post(m)) + return(0); + if ( ! man_action_post(m)) + return(0); + } + assert(m->last == m->first); + + if ( ! man_valid_post(m)) + return(0); + if ( ! man_action_post(m)) + return(0); + return(1); }