1*95c635efSGarrett D'Amore /* $Id: html.h,v 1.47 2011/10/05 21:35:17 kristaps Exp $ */ 2*95c635efSGarrett D'Amore /* 3*95c635efSGarrett D'Amore * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> 4*95c635efSGarrett D'Amore * 5*95c635efSGarrett D'Amore * Permission to use, copy, modify, and distribute this software for any 6*95c635efSGarrett D'Amore * purpose with or without fee is hereby granted, provided that the above 7*95c635efSGarrett D'Amore * copyright notice and this permission notice appear in all copies. 8*95c635efSGarrett D'Amore * 9*95c635efSGarrett D'Amore * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10*95c635efSGarrett D'Amore * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11*95c635efSGarrett D'Amore * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12*95c635efSGarrett D'Amore * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13*95c635efSGarrett D'Amore * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14*95c635efSGarrett D'Amore * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15*95c635efSGarrett D'Amore * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16*95c635efSGarrett D'Amore */ 17*95c635efSGarrett D'Amore #ifndef HTML_H 18*95c635efSGarrett D'Amore #define HTML_H 19*95c635efSGarrett D'Amore 20*95c635efSGarrett D'Amore __BEGIN_DECLS 21*95c635efSGarrett D'Amore 22*95c635efSGarrett D'Amore enum htmltag { 23*95c635efSGarrett D'Amore TAG_HTML, 24*95c635efSGarrett D'Amore TAG_HEAD, 25*95c635efSGarrett D'Amore TAG_BODY, 26*95c635efSGarrett D'Amore TAG_META, 27*95c635efSGarrett D'Amore TAG_TITLE, 28*95c635efSGarrett D'Amore TAG_DIV, 29*95c635efSGarrett D'Amore TAG_H1, 30*95c635efSGarrett D'Amore TAG_H2, 31*95c635efSGarrett D'Amore TAG_SPAN, 32*95c635efSGarrett D'Amore TAG_LINK, 33*95c635efSGarrett D'Amore TAG_BR, 34*95c635efSGarrett D'Amore TAG_A, 35*95c635efSGarrett D'Amore TAG_TABLE, 36*95c635efSGarrett D'Amore TAG_TBODY, 37*95c635efSGarrett D'Amore TAG_COL, 38*95c635efSGarrett D'Amore TAG_TR, 39*95c635efSGarrett D'Amore TAG_TD, 40*95c635efSGarrett D'Amore TAG_LI, 41*95c635efSGarrett D'Amore TAG_UL, 42*95c635efSGarrett D'Amore TAG_OL, 43*95c635efSGarrett D'Amore TAG_DL, 44*95c635efSGarrett D'Amore TAG_DT, 45*95c635efSGarrett D'Amore TAG_DD, 46*95c635efSGarrett D'Amore TAG_BLOCKQUOTE, 47*95c635efSGarrett D'Amore TAG_P, 48*95c635efSGarrett D'Amore TAG_PRE, 49*95c635efSGarrett D'Amore TAG_B, 50*95c635efSGarrett D'Amore TAG_I, 51*95c635efSGarrett D'Amore TAG_CODE, 52*95c635efSGarrett D'Amore TAG_SMALL, 53*95c635efSGarrett D'Amore TAG_MAX 54*95c635efSGarrett D'Amore }; 55*95c635efSGarrett D'Amore 56*95c635efSGarrett D'Amore enum htmlattr { 57*95c635efSGarrett D'Amore ATTR_HTTPEQUIV, 58*95c635efSGarrett D'Amore ATTR_CONTENT, 59*95c635efSGarrett D'Amore ATTR_NAME, 60*95c635efSGarrett D'Amore ATTR_REL, 61*95c635efSGarrett D'Amore ATTR_HREF, 62*95c635efSGarrett D'Amore ATTR_TYPE, 63*95c635efSGarrett D'Amore ATTR_MEDIA, 64*95c635efSGarrett D'Amore ATTR_CLASS, 65*95c635efSGarrett D'Amore ATTR_STYLE, 66*95c635efSGarrett D'Amore ATTR_WIDTH, 67*95c635efSGarrett D'Amore ATTR_ID, 68*95c635efSGarrett D'Amore ATTR_SUMMARY, 69*95c635efSGarrett D'Amore ATTR_ALIGN, 70*95c635efSGarrett D'Amore ATTR_COLSPAN, 71*95c635efSGarrett D'Amore ATTR_MAX 72*95c635efSGarrett D'Amore }; 73*95c635efSGarrett D'Amore 74*95c635efSGarrett D'Amore enum htmlfont { 75*95c635efSGarrett D'Amore HTMLFONT_NONE = 0, 76*95c635efSGarrett D'Amore HTMLFONT_BOLD, 77*95c635efSGarrett D'Amore HTMLFONT_ITALIC, 78*95c635efSGarrett D'Amore HTMLFONT_MAX 79*95c635efSGarrett D'Amore }; 80*95c635efSGarrett D'Amore 81*95c635efSGarrett D'Amore struct tag { 82*95c635efSGarrett D'Amore struct tag *next; 83*95c635efSGarrett D'Amore enum htmltag tag; 84*95c635efSGarrett D'Amore }; 85*95c635efSGarrett D'Amore 86*95c635efSGarrett D'Amore struct tagq { 87*95c635efSGarrett D'Amore struct tag *head; 88*95c635efSGarrett D'Amore }; 89*95c635efSGarrett D'Amore 90*95c635efSGarrett D'Amore struct htmlpair { 91*95c635efSGarrett D'Amore enum htmlattr key; 92*95c635efSGarrett D'Amore const char *val; 93*95c635efSGarrett D'Amore }; 94*95c635efSGarrett D'Amore 95*95c635efSGarrett D'Amore #define PAIR_INIT(p, t, v) \ 96*95c635efSGarrett D'Amore do { \ 97*95c635efSGarrett D'Amore (p)->key = (t); \ 98*95c635efSGarrett D'Amore (p)->val = (v); \ 99*95c635efSGarrett D'Amore } while (/* CONSTCOND */ 0) 100*95c635efSGarrett D'Amore 101*95c635efSGarrett D'Amore #define PAIR_ID_INIT(p, v) PAIR_INIT(p, ATTR_ID, v) 102*95c635efSGarrett D'Amore #define PAIR_CLASS_INIT(p, v) PAIR_INIT(p, ATTR_CLASS, v) 103*95c635efSGarrett D'Amore #define PAIR_HREF_INIT(p, v) PAIR_INIT(p, ATTR_HREF, v) 104*95c635efSGarrett D'Amore #define PAIR_STYLE_INIT(p, h) PAIR_INIT(p, ATTR_STYLE, (h)->buf) 105*95c635efSGarrett D'Amore #define PAIR_SUMMARY_INIT(p, v) PAIR_INIT(p, ATTR_SUMMARY, v) 106*95c635efSGarrett D'Amore 107*95c635efSGarrett D'Amore enum htmltype { 108*95c635efSGarrett D'Amore HTML_HTML_4_01_STRICT, 109*95c635efSGarrett D'Amore HTML_XHTML_1_0_STRICT 110*95c635efSGarrett D'Amore }; 111*95c635efSGarrett D'Amore 112*95c635efSGarrett D'Amore struct html { 113*95c635efSGarrett D'Amore int flags; 114*95c635efSGarrett D'Amore #define HTML_NOSPACE (1 << 0) /* suppress next space */ 115*95c635efSGarrett D'Amore #define HTML_IGNDELIM (1 << 1) 116*95c635efSGarrett D'Amore #define HTML_KEEP (1 << 2) 117*95c635efSGarrett D'Amore #define HTML_PREKEEP (1 << 3) 118*95c635efSGarrett D'Amore #define HTML_NONOSPACE (1 << 4) /* never add spaces */ 119*95c635efSGarrett D'Amore #define HTML_LITERAL (1 << 5) /* literal (e.g., <PRE>) context */ 120*95c635efSGarrett D'Amore struct tagq tags; /* stack of open tags */ 121*95c635efSGarrett D'Amore struct rofftbl tbl; /* current table */ 122*95c635efSGarrett D'Amore struct tag *tblt; /* current open table scope */ 123*95c635efSGarrett D'Amore struct mchars *symtab; /* character-escapes */ 124*95c635efSGarrett D'Amore char *base_man; /* base for manpage href */ 125*95c635efSGarrett D'Amore char *base_includes; /* base for include href */ 126*95c635efSGarrett D'Amore char *style; /* style-sheet URI */ 127*95c635efSGarrett D'Amore char buf[BUFSIZ]; /* see bufcat and friends */ 128*95c635efSGarrett D'Amore size_t buflen; 129*95c635efSGarrett D'Amore struct tag *metaf; /* current open font scope */ 130*95c635efSGarrett D'Amore enum htmlfont metal; /* last used font */ 131*95c635efSGarrett D'Amore enum htmlfont metac; /* current font mode */ 132*95c635efSGarrett D'Amore enum htmltype type; /* output media type */ 133*95c635efSGarrett D'Amore int oflags; /* output options */ 134*95c635efSGarrett D'Amore #define HTML_FRAGMENT (1 << 0) /* don't emit HTML/HEAD/BODY */ 135*95c635efSGarrett D'Amore }; 136*95c635efSGarrett D'Amore 137*95c635efSGarrett D'Amore void print_gen_decls(struct html *); 138*95c635efSGarrett D'Amore void print_gen_head(struct html *); 139*95c635efSGarrett D'Amore struct tag *print_otag(struct html *, enum htmltag, 140*95c635efSGarrett D'Amore int, const struct htmlpair *); 141*95c635efSGarrett D'Amore void print_tagq(struct html *, const struct tag *); 142*95c635efSGarrett D'Amore void print_stagq(struct html *, const struct tag *); 143*95c635efSGarrett D'Amore void print_text(struct html *, const char *); 144*95c635efSGarrett D'Amore void print_tblclose(struct html *); 145*95c635efSGarrett D'Amore void print_tbl(struct html *, const struct tbl_span *); 146*95c635efSGarrett D'Amore void print_eqn(struct html *, const struct eqn *); 147*95c635efSGarrett D'Amore 148*95c635efSGarrett D'Amore void bufcat_fmt(struct html *, const char *, ...); 149*95c635efSGarrett D'Amore void bufcat(struct html *, const char *); 150*95c635efSGarrett D'Amore void bufcat_id(struct html *, const char *); 151*95c635efSGarrett D'Amore void bufcat_style(struct html *, 152*95c635efSGarrett D'Amore const char *, const char *); 153*95c635efSGarrett D'Amore void bufcat_su(struct html *, const char *, 154*95c635efSGarrett D'Amore const struct roffsu *); 155*95c635efSGarrett D'Amore void bufinit(struct html *); 156*95c635efSGarrett D'Amore void buffmt_man(struct html *, 157*95c635efSGarrett D'Amore const char *, const char *); 158*95c635efSGarrett D'Amore void buffmt_includes(struct html *, const char *); 159*95c635efSGarrett D'Amore 160*95c635efSGarrett D'Amore int html_strlen(const char *); 161*95c635efSGarrett D'Amore 162*95c635efSGarrett D'Amore __END_DECLS 163*95c635efSGarrett D'Amore 164*95c635efSGarrett D'Amore #endif /*!HTML_H*/ 165