void html_mdoc(void *arg, const struct roff_man *mdoc) { struct html *h; struct roff_node *n; struct tag *t; h = (struct html *)arg; n = mdoc->first->child; if ((h->oflags & HTML_FRAGMENT) == 0) { print_gen_decls(h); print_otag(h, TAG_HTML, ""); if (n->type == ROFFT_COMMENT) print_gen_comment(h, n); t = print_otag(h, TAG_HEAD, ""); print_mdoc_head(&mdoc->meta, h); print_tagq(h, t); print_otag(h, TAG_BODY, ""); } mdoc_root_pre(&mdoc->meta, h); t = print_otag(h, TAG_DIV, "c", "manual-text"); print_mdoc_nodelist(&mdoc->meta, n, h); print_tagq(h, t); mdoc_root_post(&mdoc->meta, h); print_tagq(h, NULL); }
void terminal_mdoc(void *arg, const struct mdoc *mdoc) { const struct mdoc_node *n; const struct mdoc_meta *meta; struct termp *p; p = (struct termp *)arg; if (0 == p->defindent) p->defindent = 5; p->overstep = 0; p->maxrmargin = p->defrmargin; p->tabwidth = term_len(p, 5); if (NULL == p->symtab) p->symtab = mchars_alloc(); n = mdoc_node(mdoc); meta = mdoc_meta(mdoc); term_begin(p, print_mdoc_head, print_mdoc_foot, meta); if (n->child) print_mdoc_nodelist(p, NULL, meta, n->child); term_end(p); }
void terminal_mdoc(void *arg, const struct mdoc *mdoc) { const struct mdoc_node *n; const struct mdoc_meta *m; struct termp *p; p = (struct termp *)arg; p->overstep = 0; p->maxrmargin = p->defrmargin; p->tabwidth = term_len(p, 5); if (NULL == p->symtab) switch (p->enc) { case (TERMENC_ASCII): p->symtab = chars_init(CHARS_ASCII); break; default: abort(); /* NOTREACHED */ } n = mdoc_node(mdoc); m = mdoc_meta(mdoc); term_begin(p, print_mdoc_head, print_mdoc_foot, m); if (n->child) print_mdoc_nodelist(p, NULL, m, n->child); term_end(p); }
static void print_mdoc_nodelist(MDOC_ARGS) { print_mdoc_node(m, n, h); if (n->next) print_mdoc_nodelist(m, n->next, h); }
static void print_mdoc_nodelist(DECL_ARGS) { print_mdoc_node(p, pair, meta, n); if (n->next) print_mdoc_nodelist(p, pair, meta, n->next); }
static void print_mdoc(MDOC_ARGS) { struct tag *t; t = print_otag(h, TAG_HEAD, 0, NULL); print_mdoc_head(m, n, h); print_tagq(h, t); t = print_otag(h, TAG_BODY, 0, NULL); print_mdoc_nodelist(m, n, h); print_tagq(h, t); }
void terminal_mdoc(void *arg, const struct mdoc *mdoc) { const struct mdoc_meta *meta; struct mdoc_node *n; struct termp *p; p = (struct termp *)arg; p->overstep = 0; p->rmargin = p->maxrmargin = p->defrmargin; p->tabwidth = term_len(p, 5); n = mdoc_node(mdoc)->child; meta = mdoc_meta(mdoc); if (p->synopsisonly) { while (n != NULL) { if (n->tok == MDOC_Sh && n->sec == SEC_SYNOPSIS) { if (n->child->next->child != NULL) print_mdoc_nodelist(p, NULL, meta, n->child->next->child); term_newln(p); break; } n = n->next; } } else { if (p->defindent == 0) p->defindent = 5; term_begin(p, print_mdoc_head, print_mdoc_foot, meta); if (n != NULL) { if (n->tok != MDOC_Sh) term_vspace(p); print_mdoc_nodelist(p, NULL, meta, n); } term_end(p); } }
static void print_mdoc(MDOC_ARGS) { struct tag *t, *tt; struct htmlpair tag; PAIR_CLASS_INIT(&tag, "mandoc"); if ( ! (HTML_FRAGMENT & h->oflags)) { print_gen_decls(h); t = print_otag(h, TAG_HTML, 0, NULL); tt = print_otag(h, TAG_HEAD, 0, NULL); print_mdoc_head(meta, n, h); print_tagq(h, tt); print_otag(h, TAG_BODY, 0, NULL); print_otag(h, TAG_DIV, 1, &tag); } else t = print_otag(h, TAG_DIV, 1, &tag); print_mdoc_nodelist(meta, n, h); print_tagq(h, t); }
static void print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; struct htmlpair tag; child = 1; t = h->tags.head; bufinit(h); switch (n->type) { case (MDOC_ROOT): child = mdoc_root_pre(m, n, h); break; case (MDOC_TEXT): /* No tables in this mode... */ assert(NULL == h->tblt); /* * Make sure that if we're in a literal mode already * (i.e., within a <PRE>) don't print the newline. */ if (' ' == *n->string && MDOC_LINE & n->flags) if ( ! (HTML_LITERAL & h->flags)) print_otag(h, TAG_BR, 0, NULL); if (MDOC_DELIMC & n->flags) h->flags |= HTML_NOSPACE; print_text(h, n->string); if (MDOC_DELIMO & n->flags) h->flags |= HTML_NOSPACE; return; case (MDOC_EQN): PAIR_CLASS_INIT(&tag, "eqn"); print_otag(h, TAG_SPAN, 1, &tag); print_text(h, n->eqn->data); break; case (MDOC_TBL): /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt) { print_tblclose(h); t = h->tags.head; } assert(NULL == h->tblt); if (mdocs[n->tok].pre && ENDBODY_NOT == n->end) child = (*mdocs[n->tok].pre)(m, n, h); break; } if (HTML_KEEP & h->flags) { if (n->prev && n->prev->line != n->line) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } else if (NULL == n->prev) { if (n->parent && n->parent->line != n->line) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } } } if (child && n->child) print_mdoc_nodelist(m, n->child, h); print_stagq(h, t); bufinit(h); switch (n->type) { case (MDOC_ROOT): mdoc_root_post(m, n, h); break; case (MDOC_EQN): break; default: if (mdocs[n->tok].post && ENDBODY_NOT == n->end) (*mdocs[n->tok].post)(m, n, h); break; } }
static void print_mdoc_node(DECL_ARGS) { int chld; struct termpair npair; size_t offset, rmargin; chld = 1; offset = p->offset; rmargin = p->rmargin; n->flags &= ~MDOC_ENDED; n->prev_font = p->fonti; memset(&npair, 0, sizeof(struct termpair)); npair.ppair = pair; /* * 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 & MDOC_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. */ switch (n->type) { case ROFFT_TEXT: if (' ' == *n->string && MDOC_LINE & n->flags) term_newln(p); if (MDOC_DELIMC & n->flags) p->flags |= TERMP_NOSPACE; term_word(p, n->string); if (MDOC_DELIMO & n->flags) p->flags |= TERMP_NOSPACE; break; case ROFFT_EQN: if ( ! (n->flags & MDOC_LINE)) p->flags |= TERMP_NOSPACE; term_eqn(p, n->eqn); if (n->next != NULL && ! (n->next->flags & MDOC_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 (termacts[n->tok].pre && (n->end == ENDBODY_NOT || n->child != NULL)) chld = (*termacts[n->tok].pre) (p, &npair, meta, n); break; } if (chld && n->child) print_mdoc_nodelist(p, &npair, meta, n->child); term_fontpopq(p, (ENDBODY_NOT == n->end ? n : n->body)->prev_font); switch (n->type) { case ROFFT_TEXT: break; case ROFFT_TBL: break; case ROFFT_EQN: break; default: if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags) break; (void)(*termacts[n->tok].post)(p, &npair, meta, n); /* * Explicit end tokens not only call the post * handler, but also tell the respective block * that it must not call the post handler again. */ if (ENDBODY_NOT != n->end) n->body->flags |= MDOC_ENDED; /* * End of line terminating an implicit block * while an explicit block is still open. * Continue the explicit block without spacing. */ if (ENDBODY_NOSPACE == n->end) p->flags |= TERMP_NOSPACE; break; } if (MDOC_EOS & n->flags) p->flags |= TERMP_SENTENCE; if (MDOC_ll != n->tok) { p->offset = offset; p->rmargin = rmargin; } }
static void print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; if (n->type == ROFFT_COMMENT || n->flags & NODE_NOPRT) return; child = 1; t = h->tag; n->flags &= ~NODE_ENDED; switch (n->type) { case ROFFT_TEXT: /* No tables in this mode... */ assert(NULL == h->tblt); /* * Make sure that if we're in a literal mode already * (i.e., within a <PRE>) don't print the newline. */ if (*n->string == ' ' && n->flags & NODE_LINE && (h->flags & (HTML_LITERAL | HTML_NONEWLINE)) == 0) print_otag(h, TAG_BR, ""); if (NODE_DELIMC & n->flags) h->flags |= HTML_NOSPACE; print_text(h, n->string); if (NODE_DELIMO & n->flags) h->flags |= HTML_NOSPACE; return; case ROFFT_EQN: print_eqn(h, n->eqn); break; case ROFFT_TBL: /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt != NULL) { print_tblclose(h); t = h->tag; } assert(h->tblt == NULL); if (n->tok < ROFF_MAX) { roff_html_pre(h, n); child = 0; break; } assert(n->tok >= MDOC_Dd && n->tok < MDOC_MAX); if (mdocs[n->tok].pre != NULL && (n->end == ENDBODY_NOT || n->child != NULL)) child = (*mdocs[n->tok].pre)(meta, n, h); break; } if (h->flags & HTML_KEEP && n->flags & NODE_LINE) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } if (child && n->child) print_mdoc_nodelist(meta, n->child, h); print_stagq(h, t); switch (n->type) { case ROFFT_EQN: break; default: if (n->tok < ROFF_MAX || mdocs[n->tok].post == NULL || n->flags & NODE_ENDED) break; (*mdocs[n->tok].post)(meta, n, h); if (n->end != ENDBODY_NOT) n->body->flags |= NODE_ENDED; break; } }
static void print_mdoc_node(MDOC_ARGS) { int child; struct tag *t; child = 1; t = h->tags.head; n->flags &= ~MDOC_ENDED; switch (n->type) { case MDOC_ROOT: child = mdoc_root_pre(meta, n, h); break; case MDOC_TEXT: /* No tables in this mode... */ assert(NULL == h->tblt); /* * Make sure that if we're in a literal mode already * (i.e., within a <PRE>) don't print the newline. */ if (' ' == *n->string && MDOC_LINE & n->flags) if ( ! (HTML_LITERAL & h->flags)) print_otag(h, TAG_BR, 0, NULL); if (MDOC_DELIMC & n->flags) h->flags |= HTML_NOSPACE; print_text(h, n->string); if (MDOC_DELIMO & n->flags) h->flags |= HTML_NOSPACE; return; case MDOC_EQN: if (n->flags & MDOC_LINE) putchar('\n'); print_eqn(h, n->eqn); break; case MDOC_TBL: /* * This will take care of initialising all of the table * state data for the first table, then tearing it down * for the last one. */ print_tbl(h, n->span); return; default: /* * Close out the current table, if it's open, and unset * the "meta" table state. This will be reopened on the * next table element. */ if (h->tblt != NULL) { print_tblclose(h); t = h->tags.head; } assert(h->tblt == NULL); if (mdocs[n->tok].pre && (n->end == ENDBODY_NOT || n->child)) child = (*mdocs[n->tok].pre)(meta, n, h); break; } if (h->flags & HTML_KEEP && n->flags & MDOC_LINE) { h->flags &= ~HTML_KEEP; h->flags |= HTML_PREKEEP; } if (child && n->child) print_mdoc_nodelist(meta, n->child, h); print_stagq(h, t); switch (n->type) { case MDOC_ROOT: mdoc_root_post(meta, n, h); break; case MDOC_EQN: break; default: if ( ! mdocs[n->tok].post || n->flags & MDOC_ENDED) break; (*mdocs[n->tok].post)(meta, n, h); if (n->end != ENDBODY_NOT) n->body->flags |= MDOC_ENDED; if (n->end == ENDBODY_NOSPACE) h->flags |= HTML_NOSPACE; break; } }
/* ARGSUSED */ static void print_mdoc_node(DECL_ARGS) { int chld; const void *font; struct termpair npair; size_t offset, rmargin; chld = 1; offset = p->offset; rmargin = p->rmargin; font = term_fontq(p); memset(&npair, 0, sizeof(struct termpair)); npair.ppair = pair; /* * Keeps only work until the end of a line. If a keep was * invoked in a prior line, revert it to PREKEEP. * * Also let SYNPRETTY sections behave as if they were wrapped * in a `Bk' block. */ if (TERMP_KEEP & p->flags || MDOC_SYNPRETTY & n->flags) { if (n->prev && n->prev->line != n->line) { p->flags &= ~TERMP_KEEP; p->flags |= TERMP_PREKEEP; } else if (NULL == n->prev) { if (n->parent && n->parent->line != n->line) { p->flags &= ~TERMP_KEEP; p->flags |= TERMP_PREKEEP; } } } /* * Since SYNPRETTY sections aren't "turned off" with `Ek', * we have to intuit whether we should disable formatting. */ if ( ! (MDOC_SYNPRETTY & n->flags) && ((n->prev && MDOC_SYNPRETTY & n->prev->flags) || (n->parent && MDOC_SYNPRETTY & n->parent->flags))) p->flags &= ~(TERMP_KEEP | TERMP_PREKEEP); /* * After the keep flags have been set up, we may now * produce output. Note that some pre-handlers do so. */ switch (n->type) { case (MDOC_TEXT): if (' ' == *n->string && MDOC_LINE & n->flags) term_newln(p); if (MDOC_DELIMC & n->flags) p->flags |= TERMP_NOSPACE; term_word(p, n->string); if (MDOC_DELIMO & n->flags) p->flags |= TERMP_NOSPACE; break; case (MDOC_EQN): term_eqn(p, n->eqn); break; case (MDOC_TBL): term_tbl(p, n->span); break; default: if (termacts[n->tok].pre && ENDBODY_NOT == n->end) chld = (*termacts[n->tok].pre) (p, &npair, m, n); break; } if (chld && n->child) print_mdoc_nodelist(p, &npair, m, n->child); term_fontpopq(p, font); switch (n->type) { case (MDOC_TEXT): break; case (MDOC_TBL): break; case (MDOC_EQN): break; default: if ( ! termacts[n->tok].post || MDOC_ENDED & n->flags) break; (void)(*termacts[n->tok].post)(p, &npair, m, n); /* * Explicit end tokens not only call the post * handler, but also tell the respective block * that it must not call the post handler again. */ if (ENDBODY_NOT != n->end) n->pending->flags |= MDOC_ENDED; /* * End of line terminating an implicit block * while an explicit block is still open. * Continue the explicit block without spacing. */ if (ENDBODY_NOSPACE == n->end) p->flags |= TERMP_NOSPACE; break; } if (MDOC_EOS & n->flags) p->flags |= TERMP_SENTENCE; p->offset = offset; p->rmargin = rmargin; }