1*698f87a4SGarrett D'Amore /* $Id: html.h,v 1.49 2013/08/08 20:07:47 schwarze Exp $ */ 295c635efSGarrett D'Amore /* 395c635efSGarrett D'Amore * Copyright (c) 2008, 2009, 2010, 2011 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 #ifndef HTML_H 1895c635efSGarrett D'Amore #define HTML_H 1995c635efSGarrett D'Amore 2095c635efSGarrett D'Amore __BEGIN_DECLS 2195c635efSGarrett D'Amore 2295c635efSGarrett D'Amore enum htmltag { 2395c635efSGarrett D'Amore TAG_HTML, 2495c635efSGarrett D'Amore TAG_HEAD, 2595c635efSGarrett D'Amore TAG_BODY, 2695c635efSGarrett D'Amore TAG_META, 2795c635efSGarrett D'Amore TAG_TITLE, 2895c635efSGarrett D'Amore TAG_DIV, 2995c635efSGarrett D'Amore TAG_H1, 3095c635efSGarrett D'Amore TAG_H2, 3195c635efSGarrett D'Amore TAG_SPAN, 3295c635efSGarrett D'Amore TAG_LINK, 3395c635efSGarrett D'Amore TAG_BR, 3495c635efSGarrett D'Amore TAG_A, 3595c635efSGarrett D'Amore TAG_TABLE, 3695c635efSGarrett D'Amore TAG_TBODY, 3795c635efSGarrett D'Amore TAG_COL, 3895c635efSGarrett D'Amore TAG_TR, 3995c635efSGarrett D'Amore TAG_TD, 4095c635efSGarrett D'Amore TAG_LI, 4195c635efSGarrett D'Amore TAG_UL, 4295c635efSGarrett D'Amore TAG_OL, 4395c635efSGarrett D'Amore TAG_DL, 4495c635efSGarrett D'Amore TAG_DT, 4595c635efSGarrett D'Amore TAG_DD, 4695c635efSGarrett D'Amore TAG_BLOCKQUOTE, 4795c635efSGarrett D'Amore TAG_P, 4895c635efSGarrett D'Amore TAG_PRE, 4995c635efSGarrett D'Amore TAG_B, 5095c635efSGarrett D'Amore TAG_I, 5195c635efSGarrett D'Amore TAG_CODE, 5295c635efSGarrett D'Amore TAG_SMALL, 5395c635efSGarrett D'Amore TAG_MAX 5495c635efSGarrett D'Amore }; 5595c635efSGarrett D'Amore 5695c635efSGarrett D'Amore enum htmlattr { 5795c635efSGarrett D'Amore ATTR_HTTPEQUIV, 5895c635efSGarrett D'Amore ATTR_CONTENT, 5995c635efSGarrett D'Amore ATTR_NAME, 6095c635efSGarrett D'Amore ATTR_REL, 6195c635efSGarrett D'Amore ATTR_HREF, 6295c635efSGarrett D'Amore ATTR_TYPE, 6395c635efSGarrett D'Amore ATTR_MEDIA, 6495c635efSGarrett D'Amore ATTR_CLASS, 6595c635efSGarrett D'Amore ATTR_STYLE, 6695c635efSGarrett D'Amore ATTR_WIDTH, 6795c635efSGarrett D'Amore ATTR_ID, 6895c635efSGarrett D'Amore ATTR_SUMMARY, 6995c635efSGarrett D'Amore ATTR_ALIGN, 7095c635efSGarrett D'Amore ATTR_COLSPAN, 7195c635efSGarrett D'Amore ATTR_MAX 7295c635efSGarrett D'Amore }; 7395c635efSGarrett D'Amore 7495c635efSGarrett D'Amore enum htmlfont { 7595c635efSGarrett D'Amore HTMLFONT_NONE = 0, 7695c635efSGarrett D'Amore HTMLFONT_BOLD, 7795c635efSGarrett D'Amore HTMLFONT_ITALIC, 78*698f87a4SGarrett D'Amore HTMLFONT_BI, 7995c635efSGarrett D'Amore HTMLFONT_MAX 8095c635efSGarrett D'Amore }; 8195c635efSGarrett D'Amore 8295c635efSGarrett D'Amore struct tag { 8395c635efSGarrett D'Amore struct tag *next; 8495c635efSGarrett D'Amore enum htmltag tag; 8595c635efSGarrett D'Amore }; 8695c635efSGarrett D'Amore 8795c635efSGarrett D'Amore struct tagq { 8895c635efSGarrett D'Amore struct tag *head; 8995c635efSGarrett D'Amore }; 9095c635efSGarrett D'Amore 9195c635efSGarrett D'Amore struct htmlpair { 9295c635efSGarrett D'Amore enum htmlattr key; 9395c635efSGarrett D'Amore const char *val; 9495c635efSGarrett D'Amore }; 9595c635efSGarrett D'Amore 9695c635efSGarrett D'Amore #define PAIR_INIT(p, t, v) \ 9795c635efSGarrett D'Amore do { \ 9895c635efSGarrett D'Amore (p)->key = (t); \ 9995c635efSGarrett D'Amore (p)->val = (v); \ 10095c635efSGarrett D'Amore } while (/* CONSTCOND */ 0) 10195c635efSGarrett D'Amore 10295c635efSGarrett D'Amore #define PAIR_ID_INIT(p, v) PAIR_INIT(p, ATTR_ID, v) 10395c635efSGarrett D'Amore #define PAIR_CLASS_INIT(p, v) PAIR_INIT(p, ATTR_CLASS, v) 10495c635efSGarrett D'Amore #define PAIR_HREF_INIT(p, v) PAIR_INIT(p, ATTR_HREF, v) 10595c635efSGarrett D'Amore #define PAIR_STYLE_INIT(p, h) PAIR_INIT(p, ATTR_STYLE, (h)->buf) 10695c635efSGarrett D'Amore #define PAIR_SUMMARY_INIT(p, v) PAIR_INIT(p, ATTR_SUMMARY, v) 10795c635efSGarrett D'Amore 10895c635efSGarrett D'Amore enum htmltype { 10995c635efSGarrett D'Amore HTML_HTML_4_01_STRICT, 11095c635efSGarrett D'Amore HTML_XHTML_1_0_STRICT 11195c635efSGarrett D'Amore }; 11295c635efSGarrett D'Amore 11395c635efSGarrett D'Amore struct html { 11495c635efSGarrett D'Amore int flags; 11595c635efSGarrett D'Amore #define HTML_NOSPACE (1 << 0) /* suppress next space */ 11695c635efSGarrett D'Amore #define HTML_IGNDELIM (1 << 1) 11795c635efSGarrett D'Amore #define HTML_KEEP (1 << 2) 11895c635efSGarrett D'Amore #define HTML_PREKEEP (1 << 3) 11995c635efSGarrett D'Amore #define HTML_NONOSPACE (1 << 4) /* never add spaces */ 12095c635efSGarrett D'Amore #define HTML_LITERAL (1 << 5) /* literal (e.g., <PRE>) context */ 121*698f87a4SGarrett D'Amore #define HTML_SKIPCHAR (1 << 6) /* skip the next character */ 12295c635efSGarrett D'Amore struct tagq tags; /* stack of open tags */ 12395c635efSGarrett D'Amore struct rofftbl tbl; /* current table */ 12495c635efSGarrett D'Amore struct tag *tblt; /* current open table scope */ 12595c635efSGarrett D'Amore struct mchars *symtab; /* character-escapes */ 12695c635efSGarrett D'Amore char *base_man; /* base for manpage href */ 12795c635efSGarrett D'Amore char *base_includes; /* base for include href */ 12895c635efSGarrett D'Amore char *style; /* style-sheet URI */ 12995c635efSGarrett D'Amore char buf[BUFSIZ]; /* see bufcat and friends */ 13095c635efSGarrett D'Amore size_t buflen; 13195c635efSGarrett D'Amore struct tag *metaf; /* current open font scope */ 13295c635efSGarrett D'Amore enum htmlfont metal; /* last used font */ 13395c635efSGarrett D'Amore enum htmlfont metac; /* current font mode */ 13495c635efSGarrett D'Amore enum htmltype type; /* output media type */ 13595c635efSGarrett D'Amore int oflags; /* output options */ 13695c635efSGarrett D'Amore #define HTML_FRAGMENT (1 << 0) /* don't emit HTML/HEAD/BODY */ 13795c635efSGarrett D'Amore }; 13895c635efSGarrett D'Amore 13995c635efSGarrett D'Amore void print_gen_decls(struct html *); 14095c635efSGarrett D'Amore void print_gen_head(struct html *); 14195c635efSGarrett D'Amore struct tag *print_otag(struct html *, enum htmltag, 14295c635efSGarrett D'Amore int, const struct htmlpair *); 14395c635efSGarrett D'Amore void print_tagq(struct html *, const struct tag *); 14495c635efSGarrett D'Amore void print_stagq(struct html *, const struct tag *); 14595c635efSGarrett D'Amore void print_text(struct html *, const char *); 14695c635efSGarrett D'Amore void print_tblclose(struct html *); 14795c635efSGarrett D'Amore void print_tbl(struct html *, const struct tbl_span *); 14895c635efSGarrett D'Amore void print_eqn(struct html *, const struct eqn *); 14995c635efSGarrett D'Amore 15095c635efSGarrett D'Amore void bufcat_fmt(struct html *, const char *, ...); 15195c635efSGarrett D'Amore void bufcat(struct html *, const char *); 15295c635efSGarrett D'Amore void bufcat_id(struct html *, const char *); 15395c635efSGarrett D'Amore void bufcat_style(struct html *, 15495c635efSGarrett D'Amore const char *, const char *); 15595c635efSGarrett D'Amore void bufcat_su(struct html *, const char *, 15695c635efSGarrett D'Amore const struct roffsu *); 15795c635efSGarrett D'Amore void bufinit(struct html *); 15895c635efSGarrett D'Amore void buffmt_man(struct html *, 15995c635efSGarrett D'Amore const char *, const char *); 16095c635efSGarrett D'Amore void buffmt_includes(struct html *, const char *); 16195c635efSGarrett D'Amore 16295c635efSGarrett D'Amore int html_strlen(const char *); 16395c635efSGarrett D'Amore 16495c635efSGarrett D'Amore __END_DECLS 16595c635efSGarrett D'Amore 16695c635efSGarrett D'Amore #endif /*!HTML_H*/ 167