1*260e9a87SYuri Pankov /* $Id: html.h,v 1.70 2014/12/02 10:08:06 schwarze Exp $ */ 295c635efSGarrett D'Amore /* 3*260e9a87SYuri Pankov * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> 495c635efSGarrett D'Amore * 595c635efSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any 695c635efSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above 795c635efSGarrett D'Amore * copyright notice and this permission notice appear in all copies. 895c635efSGarrett D'Amore * 995c635efSGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 1095c635efSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 1195c635efSGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 1295c635efSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 1395c635efSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 1495c635efSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 1595c635efSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 1695c635efSGarrett D'Amore */ 1795c635efSGarrett D'Amore 1895c635efSGarrett D'Amore enum htmltag { 1995c635efSGarrett D'Amore TAG_HTML, 2095c635efSGarrett D'Amore TAG_HEAD, 2195c635efSGarrett D'Amore TAG_BODY, 2295c635efSGarrett D'Amore TAG_META, 2395c635efSGarrett D'Amore TAG_TITLE, 2495c635efSGarrett D'Amore TAG_DIV, 2595c635efSGarrett D'Amore TAG_H1, 2695c635efSGarrett D'Amore TAG_H2, 2795c635efSGarrett D'Amore TAG_SPAN, 2895c635efSGarrett D'Amore TAG_LINK, 2995c635efSGarrett D'Amore TAG_BR, 3095c635efSGarrett D'Amore TAG_A, 3195c635efSGarrett D'Amore TAG_TABLE, 3295c635efSGarrett D'Amore TAG_TBODY, 3395c635efSGarrett D'Amore TAG_COL, 3495c635efSGarrett D'Amore TAG_TR, 3595c635efSGarrett D'Amore TAG_TD, 3695c635efSGarrett D'Amore TAG_LI, 3795c635efSGarrett D'Amore TAG_UL, 3895c635efSGarrett D'Amore TAG_OL, 3995c635efSGarrett D'Amore TAG_DL, 4095c635efSGarrett D'Amore TAG_DT, 4195c635efSGarrett D'Amore TAG_DD, 4295c635efSGarrett D'Amore TAG_BLOCKQUOTE, 4395c635efSGarrett D'Amore TAG_PRE, 4495c635efSGarrett D'Amore TAG_B, 4595c635efSGarrett D'Amore TAG_I, 4695c635efSGarrett D'Amore TAG_CODE, 4795c635efSGarrett D'Amore TAG_SMALL, 48*260e9a87SYuri Pankov TAG_STYLE, 49*260e9a87SYuri Pankov TAG_MATH, 50*260e9a87SYuri Pankov TAG_MROW, 51*260e9a87SYuri Pankov TAG_MI, 52*260e9a87SYuri Pankov TAG_MO, 53*260e9a87SYuri Pankov TAG_MSUP, 54*260e9a87SYuri Pankov TAG_MSUB, 55*260e9a87SYuri Pankov TAG_MSUBSUP, 56*260e9a87SYuri Pankov TAG_MFRAC, 57*260e9a87SYuri Pankov TAG_MSQRT, 58*260e9a87SYuri Pankov TAG_MFENCED, 59*260e9a87SYuri Pankov TAG_MTABLE, 60*260e9a87SYuri Pankov TAG_MTR, 61*260e9a87SYuri Pankov TAG_MTD, 62*260e9a87SYuri Pankov TAG_MUNDEROVER, 63*260e9a87SYuri Pankov TAG_MUNDER, 64*260e9a87SYuri Pankov TAG_MOVER, 6595c635efSGarrett D'Amore TAG_MAX 6695c635efSGarrett D'Amore }; 6795c635efSGarrett D'Amore 6895c635efSGarrett D'Amore enum htmlattr { 6995c635efSGarrett D'Amore ATTR_NAME, 7095c635efSGarrett D'Amore ATTR_REL, 7195c635efSGarrett D'Amore ATTR_HREF, 7295c635efSGarrett D'Amore ATTR_TYPE, 7395c635efSGarrett D'Amore ATTR_MEDIA, 7495c635efSGarrett D'Amore ATTR_CLASS, 7595c635efSGarrett D'Amore ATTR_STYLE, 7695c635efSGarrett D'Amore ATTR_ID, 7795c635efSGarrett D'Amore ATTR_COLSPAN, 78*260e9a87SYuri Pankov ATTR_CHARSET, 79*260e9a87SYuri Pankov ATTR_OPEN, 80*260e9a87SYuri Pankov ATTR_CLOSE, 81*260e9a87SYuri Pankov ATTR_MATHVARIANT, 8295c635efSGarrett D'Amore ATTR_MAX 8395c635efSGarrett D'Amore }; 8495c635efSGarrett D'Amore 8595c635efSGarrett D'Amore enum htmlfont { 8695c635efSGarrett D'Amore HTMLFONT_NONE = 0, 8795c635efSGarrett D'Amore HTMLFONT_BOLD, 8895c635efSGarrett D'Amore HTMLFONT_ITALIC, 89698f87a4SGarrett D'Amore HTMLFONT_BI, 9095c635efSGarrett D'Amore HTMLFONT_MAX 9195c635efSGarrett D'Amore }; 9295c635efSGarrett D'Amore 9395c635efSGarrett D'Amore struct tag { 9495c635efSGarrett D'Amore struct tag *next; 9595c635efSGarrett D'Amore enum htmltag tag; 9695c635efSGarrett D'Amore }; 9795c635efSGarrett D'Amore 9895c635efSGarrett D'Amore struct tagq { 9995c635efSGarrett D'Amore struct tag *head; 10095c635efSGarrett D'Amore }; 10195c635efSGarrett D'Amore 10295c635efSGarrett D'Amore struct htmlpair { 10395c635efSGarrett D'Amore enum htmlattr key; 10495c635efSGarrett D'Amore const char *val; 10595c635efSGarrett D'Amore }; 10695c635efSGarrett D'Amore 10795c635efSGarrett D'Amore #define PAIR_INIT(p, t, v) \ 10895c635efSGarrett D'Amore do { \ 10995c635efSGarrett D'Amore (p)->key = (t); \ 11095c635efSGarrett D'Amore (p)->val = (v); \ 11195c635efSGarrett D'Amore } while (/* CONSTCOND */ 0) 11295c635efSGarrett D'Amore 11395c635efSGarrett D'Amore #define PAIR_ID_INIT(p, v) PAIR_INIT(p, ATTR_ID, v) 11495c635efSGarrett D'Amore #define PAIR_CLASS_INIT(p, v) PAIR_INIT(p, ATTR_CLASS, v) 11595c635efSGarrett D'Amore #define PAIR_HREF_INIT(p, v) PAIR_INIT(p, ATTR_HREF, v) 11695c635efSGarrett D'Amore #define PAIR_STYLE_INIT(p, h) PAIR_INIT(p, ATTR_STYLE, (h)->buf) 11795c635efSGarrett D'Amore 11895c635efSGarrett D'Amore struct html { 11995c635efSGarrett D'Amore int flags; 12095c635efSGarrett D'Amore #define HTML_NOSPACE (1 << 0) /* suppress next space */ 12195c635efSGarrett D'Amore #define HTML_IGNDELIM (1 << 1) 12295c635efSGarrett D'Amore #define HTML_KEEP (1 << 2) 12395c635efSGarrett D'Amore #define HTML_PREKEEP (1 << 3) 12495c635efSGarrett D'Amore #define HTML_NONOSPACE (1 << 4) /* never add spaces */ 12595c635efSGarrett D'Amore #define HTML_LITERAL (1 << 5) /* literal (e.g., <PRE>) context */ 126698f87a4SGarrett D'Amore #define HTML_SKIPCHAR (1 << 6) /* skip the next character */ 127*260e9a87SYuri Pankov #define HTML_NOSPLIT (1 << 7) /* do not break line before .An */ 128*260e9a87SYuri Pankov #define HTML_SPLIT (1 << 8) /* break line before .An */ 129*260e9a87SYuri Pankov #define HTML_NONEWLINE (1 << 9) /* No line break in nofill mode. */ 13095c635efSGarrett D'Amore struct tagq tags; /* stack of open tags */ 13195c635efSGarrett D'Amore struct rofftbl tbl; /* current table */ 13295c635efSGarrett D'Amore struct tag *tblt; /* current open table scope */ 133*260e9a87SYuri Pankov const struct mchars *symtab; /* character table */ 13495c635efSGarrett D'Amore char *base_man; /* base for manpage href */ 13595c635efSGarrett D'Amore char *base_includes; /* base for include href */ 13695c635efSGarrett D'Amore char *style; /* style-sheet URI */ 13795c635efSGarrett D'Amore char buf[BUFSIZ]; /* see bufcat and friends */ 13895c635efSGarrett D'Amore size_t buflen; 13995c635efSGarrett D'Amore struct tag *metaf; /* current open font scope */ 14095c635efSGarrett D'Amore enum htmlfont metal; /* last used font */ 14195c635efSGarrett D'Amore enum htmlfont metac; /* current font mode */ 14295c635efSGarrett D'Amore int oflags; /* output options */ 14395c635efSGarrett D'Amore #define HTML_FRAGMENT (1 << 0) /* don't emit HTML/HEAD/BODY */ 14495c635efSGarrett D'Amore }; 14595c635efSGarrett D'Amore 146*260e9a87SYuri Pankov __BEGIN_DECLS 147*260e9a87SYuri Pankov 148*260e9a87SYuri Pankov struct tbl_span; 149*260e9a87SYuri Pankov struct eqn; 150*260e9a87SYuri Pankov 15195c635efSGarrett D'Amore void print_gen_decls(struct html *); 15295c635efSGarrett D'Amore void print_gen_head(struct html *); 15395c635efSGarrett D'Amore struct tag *print_otag(struct html *, enum htmltag, 15495c635efSGarrett D'Amore int, const struct htmlpair *); 15595c635efSGarrett D'Amore void print_tagq(struct html *, const struct tag *); 15695c635efSGarrett D'Amore void print_stagq(struct html *, const struct tag *); 15795c635efSGarrett D'Amore void print_text(struct html *, const char *); 15895c635efSGarrett D'Amore void print_tblclose(struct html *); 15995c635efSGarrett D'Amore void print_tbl(struct html *, const struct tbl_span *); 16095c635efSGarrett D'Amore void print_eqn(struct html *, const struct eqn *); 161*260e9a87SYuri Pankov void print_paragraph(struct html *); 16295c635efSGarrett D'Amore 163*260e9a87SYuri Pankov #if __GNUC__ - 0 >= 4 164*260e9a87SYuri Pankov __attribute__((__format__ (__printf__, 2, 3))) 165*260e9a87SYuri Pankov #endif 16695c635efSGarrett D'Amore void bufcat_fmt(struct html *, const char *, ...); 16795c635efSGarrett D'Amore void bufcat(struct html *, const char *); 16895c635efSGarrett D'Amore void bufcat_id(struct html *, const char *); 16995c635efSGarrett D'Amore void bufcat_style(struct html *, 17095c635efSGarrett D'Amore const char *, const char *); 17195c635efSGarrett D'Amore void bufcat_su(struct html *, const char *, 17295c635efSGarrett D'Amore const struct roffsu *); 17395c635efSGarrett D'Amore void bufinit(struct html *); 17495c635efSGarrett D'Amore void buffmt_man(struct html *, 17595c635efSGarrett D'Amore const char *, const char *); 17695c635efSGarrett D'Amore void buffmt_includes(struct html *, const char *); 17795c635efSGarrett D'Amore 17895c635efSGarrett D'Amore int html_strlen(const char *); 17995c635efSGarrett D'Amore 18095c635efSGarrett D'Amore __END_DECLS 181