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