1 /***********************************************************************
2 *                                                                      *
3 *               This software is part of the ast package               *
4 *          Copyright (c) 1996-2011 AT&T Intellectual Property          *
5 *                      and is licensed under the                       *
6 *                 Eclipse Public License, Version 1.0                  *
7 *                    by AT&T Intellectual Property                     *
8 *                                                                      *
9 *                A copy of the License is available at                 *
10 *          http://www.eclipse.org/org/documents/epl-v10.html           *
11 *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12 *                                                                      *
13 *              Information and Software Systems Research               *
14 *                            AT&T Research                             *
15 *                           Florham Park NJ                            *
16 *                                                                      *
17 *               Glenn Fowler <glenn.s.fowler@gmail.com>                *
18 *                                                                      *
19 ***********************************************************************/
20 #pragma prototyped
21 /*
22  * Glenn Fowler
23  * AT&T Research
24  *
25  * troff to html definitions
26  */
27 
28 #ifndef _MM2HTML_H
29 #define _MM2HTML_H	1
30 
31 #include <ast.h>
32 #include <ccode.h>
33 #include <ctype.h>
34 #include <debug.h>
35 #include <hash.h>
36 
37 #define ARGS		512
38 #define STKS		512
39 #define MAXNAME		1024
40 
41 #define COND_BLOCK	(1<<0)
42 #define COND_EL		(1<<1)
43 #define COND_IE		(1<<2)
44 #define COND_IF		(1<<3)
45 #define COND_KEPT	(1<<4)
46 #define COND_SKIP	(1<<5)
47 
48 #define TAG_BREAK	(1<<0)
49 #define TAG_COPY	(1<<1)
50 #define TAG_DO		(1<<2)
51 #define TAG_PASS	(1<<3)
52 #define TAG_RAW		(1<<4)
53 #define TAG_STATIC	(1<<5)
54 #define TAG_STATIC_BODY	(1<<6)
55 #define TAG_TRACE_GET	(1<<7)
56 #define TAG_TRACE_SET	(1<<8)
57 #define TAG_TRIGGER	(1<<9)
58 
59 typedef struct Arg_s
60 {
61 	int		argc;		/* number of args		*/
62 	char*		argv[ARGS];	/* arg values			*/
63 	Sfio_t*		sp;		/* arg string stream		*/
64 } Arg_t;
65 
66 struct Tag_s;
67 
68 typedef void (*Call_f)(struct Tag_s*, Arg_t*);
69 
70 typedef struct Tag_s
71 {
72 	char*		name;		/* mm tag name			*/
73 	Call_f		call;		/* tag implementation		*/
74 	unsigned long	flags;		/* TAG_* flags			*/
75 	char*		body;		/* macro body			*/
76 	char*		file;		/* definition file		*/
77 	int		line;		/* definition line		*/
78 	int		size;		/* body size (0 if static)	*/
79 } Tag_t;
80 
81 typedef struct Dir_s
82 {
83 	struct Dir_s*	next;		/* next in list			*/
84 	char*		name;		/* directory name		*/
85 } Dir_t;
86 
87 typedef struct Num_s
88 {
89 	char*		name;		/* register name		*/
90 	char		value[64];	/* representation value		*/
91 	long		number;		/* numeric value		*/
92 	int		flags;		/* TAG_* flags (yes)		*/
93 	int		increment;	/* auto increment amount	*/
94 	char		format;		/* {0,1,a,A,i,I}		*/
95 	char		internal;	/* internal readonly		*/
96 } Num_t;
97 
98 typedef struct
99 {
100 	char*		path;		/* last path on stream		*/
101 	Sfio_t*		sp;		/* io stream			*/
102 } Stream_t;
103 
104 typedef struct Pushin_s
105 {
106 	unsigned char*	in;		/* previous state.in		*/
107 	char*		file;		/* previous error_info.file	*/
108 	int		line;		/* previous error_info.line	*/
109 	Arg_t*		mac;		/* previous state.mac		*/
110 	Arg_t*		tag;		/* previous state.tag		*/
111 	Arg_t		top;		/* new state.tag		*/
112 	Sfio_t*		ip;		/* input file stream		*/
113 	unsigned char*	buf;		/* input buffer			*/
114 	unsigned char*	end;		/* end of input buffer		*/
115 	Sfio_t*		loop;		/* loop body stream		*/
116 } Pushin_t;
117 
118 typedef struct Trap_s
119 {
120 	struct Trap_s*	next;		/* next in list			*/
121 	char		name[1];	/* trap name			*/
122 } Trap_t;
123 
124 typedef struct Value_s
125 {
126 	int		current;	/* current value		*/
127 	int		previous;	/* previous value		*/
128 } Value_t;
129 
130 typedef struct Var_s
131 {
132 	char*		name;		/* variable name		*/
133 	char*		value;		/* variable value		*/
134 } Var_t;
135 
136 typedef struct Env_s
137 {
138 	int		generation;	/* environment generation	*/
139 
140 	int		c2;		/* no-br tag control character	*/
141 	int		cc;		/* tag control character	*/
142 	int		ce;		/* center state			*/
143 	int		dl;		/* output line length		*/
144 	int		dn;		/* output line count		*/
145 	int		nf;		/* output fill state		*/
146 	int		ss;		/* sub/super script state	*/
147 
148 	Value_t		ft;		/* font index			*/
149 	Value_t		in;		/* left indent			*/
150 	Value_t		ll;		/* line length			*/
151 	Value_t		po;		/* page offset			*/
152 	Value_t		ps;		/* font size			*/
153 	Value_t		ti;		/* temporary indent		*/
154 	Value_t		vs;		/* vertical spacing		*/
155 
156 	char*		name;		/* environment name		*/
157 
158 } Env_t;
159 
160 typedef struct Divert_s
161 {
162 	struct Divert_s*next;		/* next in list			*/
163 	Env_t		environment;	/* diversion environment	*/
164 	Env_t*		env;		/* previous state.env		*/
165 	Sfio_t*		sp;		/* diversion stream		*/
166 	Tag_t*		tag;		/* diversion tag		*/
167 } Divert_t;
168 
169 typedef struct List_s
170 {
171 	int		dl;		/* dl code emitted		*/
172 	int		in;		/* data indent			*/
173 	int		ti;		/* label indent			*/
174 } List_t;
175 
176 typedef struct State_s
177 {
178 	int		generation;	/* evnironment generation	*/
179 	Env_t*		env;		/* current environment		*/
180 	Env_t*		env_stack[STKS];/* environment stack		*/
181 	Env_t**		env_sp;		/* environment stack pointer	*/
182 	unsigned char	tag_stack[STKS];/* tag nest stack		*/
183 	unsigned char*	tag_top;	/* tag nest stack pointer	*/
184 
185 	List_t*		list;		/* current list state		*/
186 	List_t		list_stack[STKS];/* current list stack		*/
187 
188 	unsigned long	test;		/* test mask			*/
189 
190 	int		groff;		/* groff extensions		*/
191 	int		groff_init;	/* groff extensions init	*/
192 	int		dl;		/* diversion line length	*/
193 	int		dn;		/* diversion line count		*/
194 	int		ec;		/* escape character		*/
195 	int		footer;		/* footer title emitted		*/
196 	int		head;		/* document has head		*/
197 	int		eo;		/* ec disabled			*/
198 	int		link;		/* current \h...\h'0' code	*/
199 	int		ln;		/* output line count		*/
200 	int		n;		/* last output line length	*/
201 	int		nl;		/* output line position		*/
202 	int		noline;		/* '\n' is not line terminator	*/
203 	int		pass;		/* pass state			*/
204 	int		pc;		/* title page number character	*/
205 	int		silent;		/* minimal error messages	*/
206 	int		t;		/* distance to next trap	*/
207 	int		verbose;	/* verbose messages		*/
208 
209 	time_t		date;		/* global date			*/
210 
211 	char*		address;	/* author address		*/
212 	char*		author;		/* document author		*/
213 	char*		background;	/* background image		*/
214 	char*		company;	/* author company		*/
215 	char*		corporation;	/* author corporation		*/
216 	char*		font[6];	/* font index to name map	*/
217 	char*		input;		/* first input file		*/
218 	char*		location;	/* author location		*/
219 	char*		logo;		/* logo/banner image		*/
220 	char*		mailto;		/* mail contact			*/
221 	char*		organization;	/* author organization		*/
222 	char*		package;	/* title prefix			*/
223 	char*		phone;		/* author phone			*/
224 	char*		title;		/* document title		*/
225 	char*		toolbar;	/* junk before </BODY>		*/
226 
227 	Arg_t*		mac;		/* current macro args		*/
228 	Arg_t*		tag;		/* current tag args		*/
229 	Arg_t		top;		/* top tag arg data		*/
230 
231 	Dir_t*		dirs;		/* include dir list		*/
232 	Dir_t*		hot;		/* hot text list		*/
233 	Dir_t*		macros;		/* macro packages		*/
234 
235 	Divert_t*	divert;		/* diversion stack		*/
236 
237 	Hash_table_t*	symbols;	/* symbol dictionary		*/
238 
239 	Sfio_t*		arg;		/* arg buffer			*/
240 	Sfio_t*		nul;		/* ignored buffer		*/
241 	Sfio_t*		out;		/* output file pointer		*/
242 	Sfio_t*		ref;		/* reference buffer		*/
243 	Sfio_t*		req;		/* request buffer		*/
244 	Sfio_t*		tmp;		/* temporary buffer		*/
245 
246 	unsigned char*	in;		/* input buffer pointer		*/
247 
248 	unsigned char	ta[ARGS];	/* .ta stops			*/
249 
250 	Pushin_t	in_stack[STKS];	/* input stream stack		*/
251 	Pushin_t*	in_top;		/* input stream stack top	*/
252 	Sfio_t*		out_stack[STKS];/* output stream stack		*/
253 	Sfio_t**	out_top;	/* output stream stack top	*/
254 
255 	Tag_t*		define;		/* defining this macro		*/
256 	Tag_t*		end;		/* end collection with this tag	*/
257 
258 	struct
259 	{
260 	int		level;		/* conditional nesting level	*/
261 	int		flags[STKS];	/* COND_* flags			*/
262 	}		cond;
263 
264 	struct
265 	{
266 	char		trap[MAXNAME+4];/* inline trap invocation	*/
267 	int		center;		/* remaining center lines	*/
268 	int		count;		/* remaining input lines	*/
269 	int		dc;		/* check list indent		*/
270 	int		dd;		/* end of list item		*/
271 	int		dl;		/* start of list		*/
272 	int		dt;		/* start of list item		*/
273 	int		interrupt;	/* text interrupted by \c	*/
274 	int		right;		/* right justify `center'	*/
275 	int		text;		/* output text line count	*/
276 	}		it;
277 
278 	struct
279 	{
280 	char*		file;		/* original file		*/
281 	int		line;		/* original line		*/
282 	}		original;
283 
284 	Trap_t*		fini;		/* fini trap list		*/
285 	Trap_t*		trap;		/* normal trap list		*/
286 
287 } State_t;
288 
289 extern State_t		state;
290 
291 #endif
292