summaryrefslogtreecommitdiff
path: root/support/dktools/htmlbook.h
blob: 5a65abf455ba0b65c35d1922352a78776ee7e3dd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
/*
	WARNING: This file was generated by dkct.
	Changes you make here will be lost if dkct is run again!
	You should modify the original source and run dkct on it.
	Original source: htmlbook.ctr
*/

/*
Copyright (C) 2013-2017, Dirk Krause

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice,
  this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above opyright notice,
  this list of conditions and the following disclaimer in the documentation
  and/or other materials provided with the distribution.
* Neither the name of the author nor the names of contributors may be used
  to endorse or promote products derived from this software without specific
  prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/**	@file htmlbook.h Header file for the htmlbook module.
*/

#ifndef HTMLBOOK_H_INCLUDED
/** Avoid multiple inclusions. */
#define HTMLBOOK_H_INCLUDED 1


#line 10 "htmlbook.ctr"

#include "dk3conf.h"
#include "dk3types.h"
#include "dk3numco.h"



/**	Image dimension cache entry.
*/
typedef struct {
  dkChar		*fn;	/**< Image name. */
  unsigned long		 w;	/**< Image width. */
  unsigned long		 h;	/**< Image height. */
} hb_img_dim_t;



/**	External link.
*/
typedef struct {
  dkChar		*url;	/**< Link URL. */
  unsigned long		 lno;	/**< Link number within current page. */
} hb_link_t;



/**	One contents line.
*/
typedef struct {
  dkChar	*text;		/**< Allocated line text. */
  dkChar	*aname;		/**< The a name text (if any). */
  dkChar	*realtext;	/**< Real start of text for header. */
  unsigned long	 lineno;	/**< Line number. */
  unsigned long	 header;	/**< Running number of header. */
  unsigned	 headlevel;	/**< Header level (1 to 6). */
  int		 lt;		/**< Line type (0=normal, 1=header). */
} hb_line_t;



/**	One node in the document tree.
*/
struct hb__node_t {
  struct hb__node_t	*parent;	/**< Parent node. */
  struct hb__node_t	*curchild;	/**< Current child to edit. */
  struct hb__node_t	*jumpnode;	/**< Link target node. */
  dk3_sto_t		*s_subnodes;	/**< Subnodes collection. */
  dk3_sto_it_t		*i_subnodes;	/**< Subnodes iterator. */
  dk3_sto_t		*s_variables;	/**< Variables storage. */
  dk3_sto_it_t		*i_variables;	/**< Variables iterator. */
  dk3_sto_t		*s_lines;	/**< Contents lines storage. */
  dk3_sto_it_t		*i_lines;	/**< Contents lines iterator. */
  dk3_sto_t		*s_lbyurl;	/**< Storage for links by URL. */
  dk3_sto_it_t		*i_lbyurl;	/**< Iterator for links by URL. */
  dk3_sto_t		*s_lbylno;	/**< Storage for links by number. */
  dk3_sto_it_t		*i_lbylno;	/**< Iterator for links by number. */
  dk3_sto_t		*s_jsfiles;	/**< Storage for JS files. */
  dk3_sto_it_t		*i_jsfiles;	/**< Iterator for JS files. */
  dkChar		*title;		/**< Node title. */
  dkChar		*shorttitle;	/**< Short title (optional). */
  dkChar		*fulltitle;	/**< Full title (browser title bar). */
  dkChar		*filename;	/**< Text file name (optional). */
  dkChar		*suffix;	/**< Output file name suffix (opt). */
  dkChar		*template;	/**< Template file name (optional). */
  dkChar		*stylefile;	/**< Style file. */
  dkChar		*author;	/**< Name of author. */
  dkChar		*location;	/**< Location (city) of author. */
  dkChar		*icontoc;	/**< File name TOC icon. */
  dkChar		*iconprev;	/**< File name previous section icon. */
  dkChar		*iconnext;	/**< File name next section icon. */
  dkChar		*iconindex;	/**< File name index icon. */
  dkChar		*iconhome;	/**< File name home icon. */
  dkChar		*favicon;	/**< favicon. */
  dkChar		*metadesc;	/**< Meta description tag. */
  dkChar		*metakeyw;	/**< Meta keywords tag. */
  dkChar const		*outFileName;	/**< Output file name. */
  unsigned long		 lineno;	/**< Line number in project file. */
  unsigned long		 objno;		/**< Object index. */
  unsigned long		 pobjno;	/**< Printable object number. */
  unsigned long		 nextlink;	/**< Next link number. */
  unsigned long		 nextindex;	/**< Next index entry number. */
  unsigned long		 headno;	/**< Head number. */
  unsigned long		 nextsubheadno;	/**< Next head number for sub node. */
  unsigned long		 nextjs;	/**< Number of next js file. */
  long			 contnum;	/**< Context number. */
  unsigned		 options;	/**< Options for node. */
  int			 indent;	/**< Line indent (number o spaces). */
  int			 depth;		/**< Depth. */
  int			 tocstate;	/**< State when creating TOC. */
  int			 inenc;		/**< Text file input encoding. */
  int			 havenavimenu;	/**< Flag: Already have navi menu. */
};

/**	One node in the document tree.
*/
typedef struct hb__node_t hb_node_t;



/**	Entry in keyword index.
*/
typedef struct {
  dkChar		*tx;	/**< Keyword index text. */
  dkChar		*fn;	/**< File name. */
  dkChar		*an;	/**< Anchor name (optional). */
  unsigned long		 ul;	/**< Anchor number (if no name available). */
  hb_node_t		*no;	/**< Node for file name (needed for title). */
} hb_index_entry_t;



/**	Job type for the htmlbook program.
	The s_nodes storage contains a plain list of all nodes,
	this storage is used to release all nodes at the end of the program.
	The s_pnodes storage contains a plain list of all nodes to
	write output for.
	The tree structure is below the rootnode element.
*/
typedef struct {
  dk3_tm_t		 starttime;	/**< Start time. */
  dk3_app_t		*app;		/**< Application structure. */
  dkChar const * const	*msg;		/**< Localized messages. */
  dkChar const * const	*kwnl;		/**< Keywords, not localized. */
  dk3_option_set_t	*opt;		/**< Command line options. */
  dk3_sto_t		*s_nodes;	/**< All nodes storage. */
  dk3_sto_it_t		*i_nodes;	/**< All nodes storage iterator. */
  dk3_sto_t		*s_pnodes;	/**< Leaf nodes storage. */
  dk3_sto_it_t		*i_pnodes;	/**< Leaf nodes storage iterator. */
  dk3_sto_t		*s_files;	/**< Additional files storage. */
  dk3_sto_it_t		*i_files;	/**< Additional files iterator. */
  dk3_sto_t		*s_index;	/**< Index entries storage. */
  dk3_sto_it_t		*i_index;	/**< Index entries storage iterator. */
  dk3_sto_t		*s_optsect;	/**< Optional sections storage. */
  dk3_sto_it_t		*i_optsect;	/**< Optional sections iterator. */
  dk3_sto_t		*s_imgdim;	/**< Image dimension cache storage. */
  dk3_sto_it_t		*i_imgdim;	/**< Image dimension cache iterator. */
  hb_node_t		*rootnode;	/**< Root node. */
  hb_node_t		*currentnode;	/**< Current node to modify. */
  hb_node_t		*impressumnode;	/**< Impressum node. */
  hb_node_t		*firstnode;	/**< First pnode. */
  hb_node_t		*lastnode;	/**< Last pnode. */
  dkChar const		*infilename;	/**< Input file name (project). */
  dkChar const		*outputdir;	/**< Output directory (allocated). */
  dkChar const		*outputscript;	/**< Name of script to produce. */
  dkChar const		*url;		/**< URL to publish the results. */
  dkChar const		*indexfile;	/**< Typically index html. */
  dkChar const		*impressumlink;	/**< Link to impressum. */
  dkChar const		*chmlang;	/**< Language setting for CHM. */
  dkChar		*shipbuffer;	/**< Shipout buffer. */
  dkChar		*iltemplate;	/**< Input line from template. */
  dkChar		*ilfile;	/**< Input line from file. */
  dkChar		*special;	/**< Buffer for current special. */
  dk3_c32_t		*buffer32;	/**< Buffer for 32-bit characters. */
  FILE			*of;		/**< Output file. */
  unsigned long		 lineno;	/**< Line number. */
  unsigned long		 nextobj;	/**< Next object number. */
  unsigned long		 npobjs;	/**< Number of printable objects. */
  size_t		 bs;		/**< Buffer size. */
  size_t		 spused;	/**< Number elements used in special. */
  size_t		 shipused;	/**< Shipout buffer used. */
  unsigned		 options;	/**< Job options. */
  int			 iecmd;		/**< Input encoding from cmd args. */
  int			 actsect;	/**< Flag: Active section. */
  int			 cmd;		/**< Option processing result. */
  int			 exv;		/**< Exit status code. */
  int			 cs;		/**< Character set for HTML output. */
  int			 secttype;	/**< Section type. */
  int			 non_url;	/**< Flag: Non-URL characters found. */
  int			 maxdepth;	/**< Maximum depth of a node. */
  int			 headlevels;	/**< Maximum depth to print header. */
  int			 coli;		/**< Current code line number. */
  int			 cols;		/**< Code line state. */
} hb_job_t;



/**	File processing help structure.
*/
typedef struct {
  hb_job_t		*job;		/**< Job structure. */
  hb_node_t		*p;		/**< Previous node. */
  hb_node_t		*n;		/**< Next node. */
  int			 in_template;	/**< Flag: Processing template. */
  int			 stm;		/**< State machine. */
} hb_file_processor_t;



/**	@defgroup	hboptions	Node options from project file. */
/**@{*/

/**	Write page TOC.
*/
#define	HB_NODE_OPT_PAGE_TOC			0x0001U

/**	Replace ampersand.
*/
#define	HB_NODE_OPT_REPLACE_AMPERSAND		0x0002U

/**	Use tidy while copying.
*/
#define	HB_NODE_OPT_USE_TIDY			0x0004U

/**	Write header chain.
*/
#define	HB_NODE_OPT_HEADER_CHAIN		0x0008U

/**	Indicate the impressum node.
*/
#define	HB_NODE_OPT_IMPRESSUM			0x0010U

/**	Stop inheritance of JS files at this node.
*/
#define	HB_NODE_OPT_STOP_JS_INHERITANCE		0x0020U

/**@}*/



/**	@defgroup	hbjoboptions	Job options. */
/**@{*/

/**	Create index file.
*/
#define	HB_JOB_OPT_CREATE_INDEX			0x0001U

/**	Create table of contents.
*/
#define	HB_JOB_OPT_CREATE_TOC			0x0002U

/**	Currently processing code.
*/
#define	HB_JOB_OPT_CODE				0x0004U

/**	Produce output for building a chm file.
*/
#define	HB_JOB_OPT_CHM				0x0008U

/**	Use ln instead of cp for resource files.
*/
#define	HB_JOB_OPT_LN				0x0010U

/**	Write section number in positions table.
*/
#define	HB_JOB_OPT_NUM_IN_POS			0x0020U

/**	Write section number in keyword index.
*/
#define	HB_JOB_OPT_NUM_IN_IDX			0x0040U

/**	Write section number in page header.
*/
#define	HB_JOB_OPT_NUM_IN_PAGE_HEADER		0x0080U

/**	Enable full text search in chm output.
*/
#define	HB_JOB_OPT_CHM_FULL_TEXT_SEARCH		0x0100U

/**	Print line numbers for code.
*/
#define	HB_JOB_OPT_CODE_LINE_NUMBERS		0x0200U

/**@}*/



/**	@defgroup	hbcharsets	Character sets used by htmlbook. */
/**@{*/

/**	Character set us-ascii.
*/
#define	HB_CS_ASCII				0

/**	Character set UTF-8.
*/
#define	HB_CS_UTF_8				1

/**@}*/



/**	@defgroup	hbsections	Section types. */
/**@{*/

/**	Section type not yet known.
*/
#define	HB_SECTION_UNKNOWN			0

/**	Options section.
*/
#define	HB_SECTION_OPTIONS			1

/**	Files section.
*/
#define	HB_SECTION_FILES			2

/**	Contents section.
*/
#define	HB_SECTION_CONTENTS			3

/**@}*/



/**	@defgroup	hbtocstate	Node state when creating TOC. */
/**@{*/

/**	Work on this node is not yet in progress.
*/
#define	HB_TOC_STATE_INIT			0
	
/**	Work on this node is in progress.
*/
#define	HB_TOC_STATE_IN_PROGRESS		1

/**	Work on this node is finished.
*/
#define	HB_TOC_STATE_FINISHED			2

/**@}*/



/**	@defgroup	hbcolist	Code line states. */
/**@{*/

/**	Directly after code special command.
*/
#define	HB_COLIST_NONE		0

/**	In a new line, no contents yet thus no opened code tag.
*/
#define	HB_COLIST_NOT_OPENED	1

/**	Code tag was opened and must be closed.
*/
#define	HB_COLIST_OPENED	2

/**@}*/



/**	Maximum line length.
*/
#define	HB_LINE_LENGTH		16383


#include "hbnode.h"
#include "hbconf.h"
#include "hbhtml.h"
#include "hbtool.h"
#include "hbcont.h"
#include "hbindex.h"
#include "hbimgdim.h"
#include "hbchm.h"
#include "dk3strkv.h"
#include "dk3kv.h"
#include "dk3se.h"




#endif