void terminal_man(void *arg, const struct man *man) { struct termp *p; const struct man_meta *meta; struct man_node *n; struct mtermp mt; p = (struct termp *)arg; p->overstep = 0; p->rmargin = p->maxrmargin = p->defrmargin; p->tabwidth = term_len(p, 5); n = man_node(man)->child; meta = man_meta(man); memset(&mt, 0, sizeof(struct mtermp)); mt.lmargin[mt.lmargincur] = term_len(p, p->defindent); mt.offset = term_len(p, p->defindent); mt.pardist = 1; if (p->synopsisonly) { while (n != NULL) { if (n->tok == MAN_SH && n->child->child->type == MAN_TEXT && !strcmp(n->child->child->string, "SYNOPSIS")) { if (n->child->next->child != NULL) print_man_nodelist(p, &mt, n->child->next->child, meta); term_newln(p); break; } n = n->next; } } else { if (p->defindent == 0) p->defindent = 7; term_begin(p, print_man_head, print_man_foot, meta); p->flags |= TERMP_NOSPACE; if (n != NULL) print_man_nodelist(p, &mt, n, meta); term_end(p); } }
static void print_man_nodelist(MAN_ARGS) { print_man_node(man, n, mh, h); if (n->next) print_man_nodelist(man, n->next, mh, h); }
static void print_man_nodelist(DECL_ARGS) { print_man_node(p, mt, n, m); if ( ! n->next) return; print_man_nodelist(p, mt, n->next, m); }
static int man_UR_pre(MAN_ARGS) { n = n->child; assert(n->type == ROFFT_HEAD); if (n->child != NULL) { assert(n->child->type == ROFFT_TEXT); print_otag(h, TAG_A, "cTh", "Lk", n->child->string); } assert(n->next->type == ROFFT_BODY); if (n->next->child != NULL) n = n->next; print_man_nodelist(man, n->child, h); return 0; }
void terminal_man(void *arg, const struct man *man) { struct termp *p; const struct man_node *n; const struct man_meta *m; struct mtermp mt; 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 = man_node(man); m = man_meta(man); term_begin(p, print_man_head, print_man_foot, m); p->flags |= TERMP_NOSPACE; mt.fl = 0; mt.lmargin = term_len(p, INDENT); mt.offset = term_len(p, INDENT); if (n->child) print_man_nodelist(p, &mt, n->child, m); term_end(p); }
static int man_UR_pre(MAN_ARGS) { struct htmlpair tag[2]; n = n->child; assert(MAN_HEAD == n->type); if (n->nchild) { assert(MAN_TEXT == n->child->type); PAIR_CLASS_INIT(&tag[0], "link-ext"); PAIR_HREF_INIT(&tag[1], n->child->string); print_otag(h, TAG_A, 2, tag); } assert(MAN_BODY == n->next->type); if (n->next->nchild) n = n->next; print_man_nodelist(man, n->child, mh, h); return(0); }
static void print_man(MAN_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_man_head(man, n, mh, 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_man_nodelist(man, n, mh, h); print_tagq(h, t); }
void terminal_man(void *arg, const struct man *man) { struct termp *p; const struct man_node *n; const struct man_meta *meta; struct mtermp mt; p = (struct termp *)arg; if (0 == p->defindent) p->defindent = 7; p->overstep = 0; p->maxrmargin = p->defrmargin; p->tabwidth = term_len(p, 5); if (NULL == p->symtab) p->symtab = mchars_alloc(); n = man_node(man); meta = man_meta(man); term_begin(p, print_man_head, print_man_foot, meta); p->flags |= TERMP_NOSPACE; memset(&mt, 0, sizeof(struct mtermp)); mt.lmargin[mt.lmargincur] = term_len(p, p->defindent); mt.offset = term_len(p, p->defindent); mt.pardist = 1; if (n->child) print_man_nodelist(p, &mt, n->child, meta); term_end(p); }
void html_man(void *arg, const struct roff_man *man) { struct html *h; struct tag *t; h = (struct html *)arg; if ((h->oflags & HTML_FRAGMENT) == 0) { print_gen_decls(h); print_otag(h, TAG_HTML, ""); t = print_otag(h, TAG_HEAD, ""); print_man_head(&man->meta, man->first, h); print_tagq(h, t); print_otag(h, TAG_BODY, ""); } man_root_pre(&man->meta, man->first, h); t = print_otag(h, TAG_DIV, "c", "manual-text"); print_man_nodelist(&man->meta, man->first->child, h); print_tagq(h, t); man_root_post(&man->meta, man->first, h); print_tagq(h, NULL); }
static void print_man_node(DECL_ARGS) { size_t rm, rmax; int c; switch (n->type) { case(MAN_TEXT): /* * If we have a blank line, output a vertical space. * If we have a space as the first character, break * before printing the line's data. */ if ('\0' == *n->string) { term_vspace(p); return; } else if (' ' == *n->string && MAN_LINE & n->flags) term_newln(p); term_word(p, n->string); /* * If we're in a literal context, make sure that words * togehter on the same line stay together. This is a * POST-printing call, so we check the NEXT word. Since * -man doesn't have nested macros, we don't need to be * more specific than this. */ if (MANT_LITERAL & mt->fl && ! (TERMP_NOBREAK & p->flags) && (NULL == n->next || n->next->line > n->line)) { rm = p->rmargin; rmax = p->maxrmargin; p->rmargin = p->maxrmargin = TERM_MAXMARGIN; p->flags |= TERMP_NOSPACE; term_flushln(p); p->rmargin = rm; p->maxrmargin = rmax; } if (MAN_EOS & n->flags) p->flags |= TERMP_SENTENCE; return; case (MAN_EQN): term_eqn(p, n->eqn); return; case (MAN_TBL): /* * Tables are preceded by a newline. Then process a * table line, which will cause line termination, */ if (TBL_SPAN_FIRST & n->span->flags) term_newln(p); term_tbl(p, n->span); return; default: break; } if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) term_fontrepl(p, TERMFONT_NONE); c = 1; if (termacts[n->tok].pre) c = (*termacts[n->tok].pre)(p, mt, n, m); if (c && n->child) print_man_nodelist(p, mt, n->child, m); if (termacts[n->tok].post) (*termacts[n->tok].post)(p, mt, n, m); if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) term_fontrepl(p, TERMFONT_NONE); if (MAN_EOS & n->flags) p->flags |= TERMP_SENTENCE; }
static void print_man_node(MAN_ARGS) { int child; struct tag *t; child = 1; t = h->tags.head; switch (n->type) { case MAN_ROOT: man_root_pre(man, n, mh, h); break; case MAN_TEXT: if ('\0' == *n->string) { print_paragraph(h); return; } if (n->flags & MAN_LINE && (*n->string == ' ' || (n->prev != NULL && mh->fl & MANH_LITERAL && ! (h->flags & HTML_NONEWLINE)))) print_otag(h, TAG_BR, 0, NULL); print_text(h, n->string); return; case MAN_EQN: print_eqn(h, n->eqn); break; case MAN_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 scope of font prior to opening a macro * scope. */ if (HTMLFONT_NONE != h->metac) { h->metal = h->metac; h->metac = HTMLFONT_NONE; } /* * 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; } if (mans[n->tok].pre) child = (*mans[n->tok].pre)(man, n, mh, h); break; } if (child && n->child) print_man_nodelist(man, n->child, mh, h); /* This will automatically close out any font scope. */ print_stagq(h, t); switch (n->type) { case MAN_ROOT: man_root_post(man, n, mh, h); break; case MAN_EQN: break; default: if (mans[n->tok].post) (*mans[n->tok].post)(man, n, mh, h); break; } }
static void print_man_node(MAN_ARGS) { int child; struct tag *t; child = 1; t = h->tags.head; switch (n->type) { case (MAN_ROOT): man_root_pre(man, n, mh, h); break; case (MAN_TEXT): /* * If we have a blank line, output a vertical space. * If we have a space as the first character, break * before printing the line's data. */ if ('\0' == *n->string) { print_otag(h, TAG_P, 0, NULL); return; } if (' ' == *n->string && MAN_LINE & n->flags) print_otag(h, TAG_BR, 0, NULL); else if (MANH_LITERAL & mh->fl && n->prev) print_otag(h, TAG_BR, 0, NULL); print_text(h, n->string); return; case (MAN_EQN): print_eqn(h, n->eqn); break; case (MAN_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 scope of font prior to opening a macro * scope. */ if (HTMLFONT_NONE != h->metac) { h->metal = h->metac; h->metac = HTMLFONT_NONE; } /* * 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; } if (mans[n->tok].pre) child = (*mans[n->tok].pre)(man, n, mh, h); break; } if (child && n->child) print_man_nodelist(man, n->child, mh, h); /* This will automatically close out any font scope. */ print_stagq(h, t); switch (n->type) { case (MAN_ROOT): man_root_post(man, n, mh, h); break; case (MAN_EQN): break; default: if (mans[n->tok].post) (*mans[n->tok].post)(man, n, mh, h); break; } }
static void print_man_node(DECL_ARGS) { size_t rm, rmax; int c; switch (n->type) { case ROFFT_TEXT: /* * If we have a blank line, output a vertical space. * If we have a space as the first character, break * before printing the line's data. */ if ('\0' == *n->string) { term_vspace(p); return; } else if (' ' == *n->string && MAN_LINE & n->flags) term_newln(p); term_word(p, n->string); goto out; case ROFFT_EQN: if ( ! (n->flags & MAN_LINE)) p->flags |= TERMP_NOSPACE; term_eqn(p, n->eqn); if (n->next != NULL && ! (n->next->flags & MAN_LINE)) p->flags |= TERMP_NOSPACE; return; case ROFFT_TBL: if (p->tbl.cols == NULL) term_vspace(p); term_tbl(p, n->span); return; default: break; } if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) term_fontrepl(p, TERMFONT_NONE); c = 1; if (termacts[n->tok].pre) c = (*termacts[n->tok].pre)(p, mt, n, meta); if (c && n->child) print_man_nodelist(p, mt, n->child, meta); if (termacts[n->tok].post) (*termacts[n->tok].post)(p, mt, n, meta); if ( ! (MAN_NOTEXT & termacts[n->tok].flags)) term_fontrepl(p, TERMFONT_NONE); out: /* * If we're in a literal context, make sure that words * together on the same line stay together. This is a * POST-printing call, so we check the NEXT word. Since * -man doesn't have nested macros, we don't need to be * more specific than this. */ if (mt->fl & MANT_LITERAL && ! (p->flags & (TERMP_NOBREAK | TERMP_NONEWLINE)) && (n->next == NULL || n->next->flags & MAN_LINE)) { rm = p->rmargin; rmax = p->maxrmargin; p->rmargin = p->maxrmargin = TERM_MAXMARGIN; p->flags |= TERMP_NOSPACE; if (n->string != NULL && *n->string != '\0') term_flushln(p); else term_newln(p); if (rm < rmax && n->parent->tok == MAN_HP) { p->offset = rm; p->rmargin = rmax; } else p->rmargin = rm; p->maxrmargin = rmax; } if (MAN_EOS & n->flags) p->flags |= TERMP_SENTENCE; }
static void print_man_node(MAN_ARGS) { static int want_fillmode = MAN_fi; static int save_fillmode; struct tag *t; int child; /* * Handle fill mode switch requests up front, * they would just cause trouble in the subsequent code. */ switch (n->tok) { case MAN_nf: case MAN_EX: want_fillmode = MAN_nf; return; case MAN_fi: case MAN_EE: want_fillmode = MAN_fi; if (fillmode(h, 0) == MAN_fi) print_otag(h, TAG_BR, ""); return; default: break; } /* Set up fill mode for the upcoming node. */ switch (n->type) { case ROFFT_BLOCK: save_fillmode = 0; /* Some block macros suspend or cancel .nf. */ switch (n->tok) { case MAN_TP: /* Tagged paragraphs */ case MAN_IP: /* temporarily disable .nf */ case MAN_HP: /* for the head. */ save_fillmode = want_fillmode; /* FALLTHROUGH */ case MAN_SH: /* Section headers */ case MAN_SS: /* permanently cancel .nf. */ want_fillmode = MAN_fi; /* FALLTHROUGH */ case MAN_PP: /* These have no head. */ case MAN_LP: /* They will simply */ case MAN_P: /* reopen .nf in the body. */ case MAN_RS: case MAN_UR: fillmode(h, MAN_fi); break; default: break; } break; case ROFFT_TBL: fillmode(h, MAN_fi); break; case ROFFT_ELEM: /* * Some in-line macros produce tags and/or text * in the handler, so they require fill mode to be * configured up front just like for text nodes. * For the others, keep the traditional approach * of doing the same, for now. */ fillmode(h, want_fillmode); break; case ROFFT_TEXT: if (fillmode(h, want_fillmode) == MAN_fi && want_fillmode == MAN_fi && n->flags & NODE_LINE && *n->string == ' ' && (h->flags & HTML_NONEWLINE) == 0) print_otag(h, TAG_BR, ""); if (*n->string != '\0') break; print_paragraph(h); return; default: break; } /* Produce output for this node. */ child = 1; switch (n->type) { case ROFFT_TEXT: t = h->tag; print_text(h, n->string); break; case ROFFT_EQN: t = h->tag; 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 scope of font prior to opening a macro * scope. */ if (HTMLFONT_NONE != h->metac) { h->metal = h->metac; h->metac = HTMLFONT_NONE; } /* * 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->tag; if (n->tok < ROFF_MAX) { roff_html_pre(h, n); child = 0; break; } assert(n->tok >= MAN_TH && n->tok < MAN_MAX); if (mans[n->tok].pre) child = (*mans[n->tok].pre)(man, n, h); /* Some block macros resume .nf in the body. */ if (save_fillmode && n->type == ROFFT_BODY) want_fillmode = save_fillmode; break; } if (child && n->child) print_man_nodelist(man, n->child, h); /* This will automatically close out any font scope. */ print_stagq(h, t); if (fillmode(h, 0) == MAN_nf && n->next != NULL && n->next->flags & NODE_LINE) print_endline(h); }