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
|
/*
Copyright (C) 2013-2020, Dirk Krause
SPDX-License-Identifier: BSD-3-Clause
*/
/*
WARNING: This file was generated by the dkct program (see
http://dktools.sourceforge.net/ for details).
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: hbtool.ctr
*/
/** @file hbtool.c The hbtool module.
*/
#line 113 "hbtool.ctr"
#include "dk3all.h"
#include "dk3se.h"
#include "htmlbook.h"
#include "dk3unused.h"
#line 123 "hbtool.ctr"
int
hbtool_add_file(hb_job_t *job, dkChar const *fn)
{
dkChar bu[DK3_MAX_PATH]; /* File name buffer */
dkChar *p1; /* Start of file name */
int back = 0;
#line 133 "hbtool.ctr"
if(fn) {
if(dk3str_len(fn) < DK3_SIZEOF(bu,dkChar)) {
p1 = dk3str_start(fn, NULL);
if(p1) {
dk3str_cpy(bu, p1);
dk3str_chomp(bu, NULL);
if(dk3sto_it_find_like(job->i_files, bu, 0)) {
back = 1;
} else {
p1 = dk3str_dup_app(bu, job->app);
if(p1) {
if(dk3sto_add(job->s_files, p1)) {
back = 1;
} else {
dk3_delete(p1);
}
}
}
}
} else {
dk3app_log_i3(job->app, DK3_LL_ERROR, 65, 66, fn);
}
}
#line 156 "hbtool.ctr"
return back;
}
int
hbtool_check_filename_encoding(hb_job_t *job, dkChar const *fn)
{
int back;
int se; /* Standard encoding to check */
#line 167 "hbtool.ctr"
#if DK3_ON_WINDOWS
se = (DK3SE_ANSI | DK3SE_URL);
#else
if((job->options) & HB_JOB_OPT_CHM) {
se = (DK3SE_ANSI | DK3SE_URL);
} else {
se = DK3SE_URL;
}
#endif
back = dk3se_check(fn,dk3app_get_encoding(job->app),se,NULL,NULL,job->app);
#line 178 "hbtool.ctr"
return back;
}
int
hbtool_check_filename(hb_job_t *job, dkChar const *fn)
{
int back;
#line 188 "hbtool.ctr"
back = hbtool_check_filename_encoding(job, fn);
if(dk3str_chr(fn, DK3_CHAR_SEP)) {
dk3app_log_1(job->app, DK3_LL_ERROR, job->msg, 12);
back = 0;
}
#line 193 "hbtool.ctr"
return back;
}
dk3_c32_t
hbtool_get_start_char(
dkChar const *text,
#if DK3_CHAR_SIZE > 1
int DK3_ARG_UNUSED(enc)
#else
int enc
#endif
)
{
dk3_c32_t back = 0UL;
dk3_c32_t c32 = 0UL; /* Start character */
size_t sl; /* String length */
size_t used; /* Number of bytes used */
#if DK3_CHAR_SIZE <= 1
char c; /* Result character */
#endif
#if DK3_CHAR_SIZE > 1
DK3_UNUSED_ARG(enc)
#endif
#line 220 "hbtool.ctr"
if(text) {
sl = dk3str_len(text);
#if DK3_CHAR_SIZE > 1
#if DK3_CHAR_SIZE > 2
back = *text;
#else
used = 0;
if(dk3enc_utf162uc(&c32, text, sl, &used)) {
back = c32;
}
#endif
#else
if(enc == DK3_ENCODING_UTF8) {
used = 0;
if(dk3enc_utf82uc(&c32, (unsigned char const *)text, sl, &used)) {
back = c32;
}
} else {
c = *text;
back = (dk3_c32_t)c;
back &= ((dk3_c32_t)0x000000FFUL);
}
#endif
}
#line 244 "hbtool.ctr"
return back;
}
void
hbtool_enumerate(hb_job_t *job)
{
hb_node_t *nptr; /* Next node */
hb_node_t *cptr; /* Current node */
dk3sto_it_reset(job->i_nodes);
while(NULL != (nptr = (hb_node_t *)dk3sto_it_next(job->i_nodes))) {
nptr->headno = 0UL; nptr->nextsubheadno = 0UL;
nptr->tocstate = HB_TOC_STATE_INIT;
}
cptr = job->rootnode;
while(cptr) {
switch(cptr->tocstate) {
case HB_TOC_STATE_INIT: {
dk3sto_it_reset(cptr->i_subnodes);
nptr = (hb_node_t *)dk3sto_it_next(cptr->i_subnodes);
if(nptr) {
cptr->tocstate = HB_TOC_STATE_IN_PROGRESS;
nptr->headno = cptr->nextsubheadno;
cptr->nextsubheadno += 1UL;
cptr = nptr;
} else {
cptr->tocstate = HB_TOC_STATE_FINISHED;
cptr = cptr->parent;
}
} break;
case HB_TOC_STATE_IN_PROGRESS: {
nptr = (hb_node_t *)dk3sto_it_next(cptr->i_subnodes);
if(nptr) {
nptr->headno = cptr->nextsubheadno;
cptr->nextsubheadno += 1UL;
cptr = nptr;
} else {
cptr->tocstate = HB_TOC_STATE_FINISHED;
cptr = cptr->parent;
}
} break;
case HB_TOC_STATE_FINISHED: {
cptr = cptr->parent;
} break;
}
}
dk3sto_it_reset(job->i_nodes);
while(NULL != (nptr = (hb_node_t *)dk3sto_it_next(job->i_nodes))) {
nptr->tocstate = HB_TOC_STATE_INIT;
}
}
int
hbtool_write_header_number(hb_job_t *job, hb_node_t *nptr)
{
dkChar bu[32];
int back = 0;
#line 305 "hbtool.ctr"
if((job) && (nptr)) {
if(nptr->parent) {
#line 307 "hbtool.ctr"
if(nptr->depth <= job->headlevels) {
#line 308 "hbtool.ctr"
back = 1;
if(job->impressumnode) {
if((job->impressumnode)->objno == nptr->objno) {
back = 0;
#line 312 "hbtool.ctr"
}
}
if(job->privacynode) {
if((job->privacynode)->objno == nptr->objno) {
back = 0;
#line 317 "hbtool.ctr"
}
}
if(back) {
#line 320 "hbtool.ctr"
hbtool_write_header_number(job, nptr->parent);
if(1 < nptr->depth) {
#line 322 "hbtool.ctr"
hbhtml_output_for_text(job, dkT("."));
}
#if VERSION_BEFORE_20140716
dk3sf_sprintf3(bu, dkT("%lu"), (1UL + nptr->headno));
hbhtml_output_for_text(job, bu);
#line 327 "hbtool.ctr"
#else
if (dk3ma_um_to_string(bu, DK3_SIZEOF(bu,dkChar), (dk3_um_t)(1UL + nptr->headno))) {
hbhtml_output_for_text(job, bu);
}
#endif
} else {
#line 333 "hbtool.ctr"
}
} else {
#line 335 "hbtool.ctr"
}
} else {
#line 337 "hbtool.ctr"
}
}
#line 339 "hbtool.ctr"
return back;
}
int
hbtool_add_url(hb_job_t *job, dkChar const *url)
{
dkChar bu[DK3_MAX_PATH]; /* Copy of URL */
dkChar *p1; /* Start of text in url */
int back = 1;
if(!hbhtml_check_link_for_external(url)) {
if(dk3str_len(url) < DK3_SIZEOF(bu,dkChar)) {
dk3str_cpy(bu, url);
p1 = dk3str_chr(bu, dkT('?'));
if(p1) {
*p1 = dkT('\0');
} else {
p1 = dk3str_chr(bu, dkT('#'));
if(p1) {
*p1 = dkT('\0');
}
}
if(NULL == dk3str_chr(bu, dkT('/'))) {
if(0 < dk3str_len(bu)) {
back = hbtool_add_file(job, bu);
}
}
} else {
/* ERROR: File name too long! */
dk3app_log_i3(job->app, DK3_LL_ERROR, 65, 66, url);
back = 0;
}
}
return back;
}
void
hbtool_correct_backslash_to_slash(dkChar * DK3_ARG_UNUSED(str) )
{
#if DK3_ON_WINDOWS
dkChar *ptr;
ptr = str;
while(*ptr) {
if(dkT('\\') == *ptr) { *ptr = dkT('/'); }
ptr++;
}
#else
DK3_UNUSED_ARG(str)
#endif
}
int
hbtool_write_all_titles(hb_job_t *job, hb_node_t *nptr, int isprim)
{
int back = 0;
/* hbhtml_output_for_text(job, dkT(" ")); */
if ((job) && (nptr)) {
if (nptr->parent) {
back = 1;
if (job->impressumnode) {
if ((job->impressumnode)->objno == nptr->objno) {
back = 0;
}
}
if (job->privacynode) {
if ((job->privacynode)->objno == nptr->objno) {
back = 0;
}
}
if (back) {
if (hbtool_write_all_titles(job, nptr->parent, 0)) {
hbhtml_output_for_text(job, dkT(" → "));
}
if (isprim) {
if (nptr->title) {
hbhtml_output_for_text(job, nptr->title);
}
} else {
if (nptr->shorttitle) {
hbhtml_output_for_text(job, nptr->shorttitle);
} else {
if (nptr->title) {
hbhtml_output_for_text(job, nptr->title);
}
}
}
}
}
}
return back;
}
int
hbtool_write_text_utf(hb_job_t *job, dkChar const *src)
{
char bu[(1024 < DK3_MAX_PATH) ? DK3_MAX_PATH : 1024];
int back = 0;
int ie;
if ((job) && (src)) {
ie = dk3app_get_encoding(job->app);
if (dk3str_to_c8u_app(bu, sizeof(bu), src, ie, job->app)) {
if (EOF != fputs(bu, job->of)) {
back = 1;
}
}
}
return back;
}
|