- if (MDOC_TEXT == n->type)
- term_word(p, n->string);
- else if (termacts[n->tok].pre && ENDBODY_NOT == n->end)
- chld = (*termacts[n->tok].pre)(p, &npair, m, n);
+ /*
+ * Keeps only work until the end of a line. If a keep was
+ * invoked in a prior line, revert it to PREKEEP.
+ */
+
+ if (p->flags & TERMP_KEEP && n->flags & NODE_LINE) {
+ p->flags &= ~TERMP_KEEP;
+ p->flags |= TERMP_PREKEEP;
+ }
+
+ /*
+ * After the keep flags have been set up, we may now
+ * produce output. Note that some pre-handlers do so.
+ */
+
+ act = NULL;
+ switch (n->type) {
+ case ROFFT_TEXT:
+ if (n->flags & NODE_LINE) {
+ switch (*n->string) {
+ case '\0':
+ if (p->flags & TERMP_NONEWLINE)
+ term_newln(p);
+ else
+ term_vspace(p);
+ return;
+ case ' ':
+ if ((p->flags & TERMP_NONEWLINE) == 0)
+ term_newln(p);
+ break;
+ default:
+ break;
+ }
+ }
+ if (NODE_DELIMC & n->flags)
+ p->flags |= TERMP_NOSPACE;
+ term_word(p, n->string);
+ if (NODE_DELIMO & n->flags)
+ p->flags |= TERMP_NOSPACE;
+ break;
+ case ROFFT_EQN:
+ if ( ! (n->flags & NODE_LINE))
+ p->flags |= TERMP_NOSPACE;
+ term_eqn(p, n->eqn);
+ if (n->next != NULL && ! (n->next->flags & NODE_LINE))
+ p->flags |= TERMP_NOSPACE;
+ break;
+ case ROFFT_TBL:
+ if (p->tbl.cols == NULL)
+ term_newln(p);
+ term_tbl(p, n->span);
+ break;
+ default:
+ if (n->tok < ROFF_MAX) {
+ roff_term_pre(p, n);
+ return;
+ }
+ assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX);
+ act = mdoc_term_acts + (n->tok - MDOC_Dd);
+ if (act->pre != NULL &&
+ (n->end == ENDBODY_NOT || n->child != NULL))
+ chld = (*act->pre)(p, &npair, meta, n);
+ break;
+ }