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
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
|
/*
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: hbcont.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 hbcont.c The hbcont module.
*/
#line 58 "hbcont.ctr"
#include "dk3all.h"
#include "htmlbook.h"
#line 65 "hbcont.ctr"
/** Object to process a contents line.
*/
typedef struct {
hb_job_t *job; /**< Job structure. */
hb_node_t *nptr; /**< Current node. */
unsigned long lineno; /**< Current line number. */
unsigned long nheader; /**< Next header number. */
unsigned maxheader; /**< Maximum header number found. */
} hb_contents_line_processor_t;
/** Output keywords.
*/
static char const * const hbcont_c8_kw[] = {
/* 0 */
"\n",
/* 1 */
" ",
/* 2 */
"<h1>",
/* 3 */
"</h1>\n",
/* 4 */
"<table class=\"hb_pos_ta\" summary=\"",
/* 5 */
"</table>\n",
/* 6 */
"<tr class=\"hb_pos_tr\">\n",
/* 7 */
"</tr>\n",
/* 8 */
"<td class=\"hb_pos_td_arrow\">",
/* 9 */
"</td>\n",
/* 10 */
"→",
/* 11 */
"<td class=\"hb_pos_td_text\" colspan=\"%d\">",
/* 12 */
"<h%u>",
/* 13 */
"</h%u>\n",
/* 14 */
"<a name=\"",
/* 15 */
"\"></a>",
/* 16 */
"hb_h",
/* 17 */
"<table class=\"hb_ptoc_ta\" summary=\"",
/* 18 */
"</table>\n",
/* 19 */
"<tr class=\"hb_ptoc_tr\">",
/* 20 */
"</tr>\n",
/* 21 */
"<td class=\"hb_ptoc_td_empty\"> </td>\n",
/* 22 */
"<td class=\"hb_ptoc_td_data\" colspan=\"%u\">",
/* 23 */
"</td>\n",
/* 24 */
"<a href=\"#",
/* 25 */
"\" title=\"",
/* 26 */
"\" class=\"hb_ptoc_a\">",
/* 27 */
"</a>",
/* 28 */
"<div class=\"hb_link_div\">\n<h2>",
/* 29 */
"</h2>\n",
/* 30 */
"</div>",
/* 31 */
"<table class=\"hb_link_ta\" summary=\"",
/* 32 */
"</table>\n",
/* 33 */
"<tr class=\"\">\n",
/* 34 */
"</tr>\n",
/* 35 */
"<td class=\"hb_link_td_number\">",
/* 36 */
"</td>\n",
/* 37 */
" %lu ",
/* 38 */
"<td class=\"hb_link_td_url\">",
/* 39 */
"<div class=\"hb_dtoc_div\">\n<table class=\"hb_dtoc_ta\" summary=\"",
/* 40 */
"</table>\n</div><!-- class=\"hb_dtoc_div\" -->\n",
/* 41 */
"<tr class=\"hb_dtoc_tr\">\n",
/* 42 */
"</tr>\n",
/* 43 */
"<td class=\"hb_dtoc_td_space\"> </td>\n",
/* 44 */
"<td class=\"hb_dtoc_td_entry\" colspan=\"%d\">",
/* 45 */
"<a class=\"hb_dtoc_a\" href=\"",
/* 46 */
"\">",
/* 47 */
"<a name=\"hb_toc\"></a><h2 class=\"hb_dtoc_h2\">",
/* 48 */
"</h2>\n",
/* 49 */
"<div class=\"hb_pos_div\">",
/* 50 */
"<div class=\"hb_ki_div\">",
/* 51 */
"<a name=\"hb_index\"></a><h2 class=\"hb_ki_h2\">",
/* 52 */
"<dl class=\"hb_ki_dl\">",
/* 53 */
"</dl>\n",
/* 54 */
"<dt class=\"hb_ki_dt\">",
/* 55 */
"</dt>\n",
/* 56 */
"<dd class=\"hb_ki_dd\">\n<ul class=\"hb_ki_ul\">\n",
/* 57 */
"</ul>\n</dd>\n",
/* 58 */
"<li class=\"hb_ki_li\">",
/* 59 */
"</li>\n",
/* 60 */
"<a class=\"hb_ki_a\" href=\"",
/* 61 */
"#",
NULL
#line 246 "hbcont.ctr"
};
/** Meta data names.
*/
const char * const hbcont_metadata_names[] = {
/* 0 */ "meta-description",
/* 1 */ "meta-keywords",
/* 2 */ "author",
/* 3 */ "title",
/* 4 */ "short",
/* 5 */ "location",
/* 6 */ "page-toc",
/* 7 */ "replace-ampersand",
/* 8 */ "write-position",
/* 9 */ "suffix",
/* 10 */ "shortcut-icon",
/* 11 */ "js-file",
/* 12 */ "inherit-js",
/* 13 */ "context-number",
NULL
};
/** Number of elements in hbcont_metadata_names including final
NULL pointer.
*/
static const size_t sz_hbcont_metadata_names =
sizeof(hbcont_metadata_names) / sizeof(DK3_PCCHAR);
size_t
hbcont_metadata_length(size_t idx)
{
size_t back = 0;
if (idx < (sz_hbcont_metadata_names - 1)) {
back = strlen(hbcont_metadata_names[idx]);
}
return back;
}
void
hbcont_line_delete(hb_line_t *lp)
{
#line 296 "hbcont.ctr"
if(lp) {
lp->aname = NULL;
lp->realtext = NULL;
lp->lineno = 0UL;
lp->header = 0UL;
lp->headlevel = 0;
lp->lt = 0;
dk3_release(lp->text);
dk3_delete(lp);
}
#line 306 "hbcont.ctr"
}
hb_line_t *
hbcont_line_new(dkChar const *il, unsigned long lineno, dk3_app_t *app)
{
hb_line_t *back = NULL;
#line 315 "hbcont.ctr"
if(il) {
back = dk3_new_app(hb_line_t,1,app);
if(back) {
back->text = NULL;
back->aname = NULL;
back->realtext = NULL;
back->lineno = lineno;
back->header = 0UL;
back->lt = 0;
back->text = dk3str_dup_app(il, app);
if(!(back->text)) {
hbcont_line_delete(back);
back = NULL;
}
}
}
#line 331 "hbcont.ctr"
return back;
}
/** Compare two saved lines.
@param l Left line.
@param r Right line.
@param cr Comparison criteria (ignored).
@return Comparison result.
*/
static
int
hbcont_line_compare(void const *l, void const *r, int cr)
{
hb_line_t *pl;
hb_line_t *pr;
int back = 0;
#line 350 "hbcont.ctr"
if(l) {
if(r) {
pl = (hb_line_t *)l;
pr = (hb_line_t *)r;
if(pl->lineno > pr->lineno) {
back = 1;
} else {
if(pl->lineno < pr->lineno) {
back = -1;
}
}
} else back = 1;
} else {
if(r) back = -1;
}
#line 365 "hbcont.ctr"
return back;
}
/** Prepare current node for content processing (allocate
storage and iterator for lines).
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
hbcont_prepare(hb_job_t *job)
{
int back = 0;
#line 381 "hbcont.ctr"
(job->currentnode)->s_lines = dk3sto_open_app(job->app);
if((job->currentnode)->s_lines) {
dk3sto_set_comp((job->currentnode)->s_lines, hbcont_line_compare, 0);
(job->currentnode)->i_lines = dk3sto_it_open((job->currentnode)->s_lines);
if((job->currentnode)->i_lines) {
back = 1;
}
}
#line 389 "hbcont.ctr"
return back;
}
/** Clean up current node (release contents lines, storage and iterator).
@param job Job structure.
*/
static
void
hbcont_cleanup(hb_job_t *job)
{
hb_line_t *lp;
#line 403 "hbcont.ctr"
if((job->currentnode)->s_lines) {
if((job->currentnode)->i_lines) {
dk3sto_it_reset((job->currentnode)->i_lines);
do {
lp = (hb_line_t *)dk3sto_it_next((job->currentnode)->i_lines);
hbcont_line_delete(lp);
} while(lp);
dk3sto_it_close((job->currentnode)->i_lines);
}
dk3sto_close((job->currentnode)->s_lines);
}
(job->currentnode)->s_lines = NULL;
(job->currentnode)->i_lines = NULL;
#line 417 "hbcont.ctr"
}
/** Check whether a line is a header line.
@param il Line to check.
@return 1 for headers, 0 for normal lines.
*/
static
int
hbcont_check_header(dkChar *il)
{
int back = 0;
#line 431 "hbcont.ctr"
if(dkT('.') == *il) {
il++;
il = dk3str_start(il, NULL);
if(il) {
switch(*il) {
case dkT('1'): case dkT('2'): case dkT('3'):
case dkT('4'): case dkT('5'): case dkT('6'): {
back = 1;
} break;
}
}
}
#line 443 "hbcont.ctr"
return back;
}
#if 0
/** Check whether a line is a special line.
@param il Input line to check.
@return 1 for special line, 0 for line to process normally.
*/
static
int
hbcont_is_special_line(const dkChar *il)
{
int back = 0;
if (dkT('.') == il[0]) {
switch (il[1]) {
case dkT('d') : {
switch (il[2]) {
case dkT('e') : {
switch (il[3]) {
case dkT('s') : {
switch (il[4]) {
case dkT('c') : {
/* .desc
*/
back = 1;
} break;
}
} break;
}
} break;
}
} break;
}
}
return back;
}
#endif
/** Compare input line against one meta data name.
@param il Input line.
@param mdname Metadata name.
@return Comparison result.
*/
static
int
hbcont_compare_metadata(const dkChar *il, const char *mdname)
{
int back = 0;
#line 499 "hbcont.ctr"
do {
if (*il < (dkChar)(*mdname)) {
back = -1;
} else {
if (*il > (dkChar)(*mdname)) {
back = 1;
} else {
il++; mdname++;
}
}
} while(('\0' != *mdname) && (0 == back));
#line 511 "hbcont.ctr"
return back;
}
/** Check whether input line is started by one meta data keyword.
@param il Input line to check.
@return Non-negative index on success, -1 if no meta data.
*/
static
int
hbcont_find_metadata_index(const dkChar *il)
{
const char * const *nptr;
int back = -1;
int curi = 0;
#line 528 "hbcont.ctr"
nptr = hbcont_metadata_names;
do {
if (0 == hbcont_compare_metadata(il, *(nptr++))) {
back = curi;
} else {
curi++;
}
} while ((NULL != *nptr) && (-1 == back));
#line 537 "hbcont.ctr"
return back;
}
int
hbcont_metadata_index(const dkChar *il)
{
int back = -1;
#line 547 "hbcont.ctr"
if (NULL != il) {
if (dkT('.') == il[0]) {
back = hbcont_find_metadata_index(&(il[1]));
}
}
#line 553 "hbcont.ctr"
return back;
}
/** Line handler processing function.
@param obj Handler object.
@param il Input line to process.
@return 1 on success, 0 on error (continue), -1 on error (exit).
*/
static
int
hbcont_line_handler(void *obj, dkChar *il)
{
hb_contents_line_processor_t *proc; /* Processor */
hb_job_t *job; /* Job structure */
hb_node_t *nptr; /* Current node */
hb_line_t *lptr; /* Current line structure */
dkChar *p1; /* Start of line */
dkChar *p2; /* Start of a name */
dkChar *p3; /* Start of real text */
unsigned u; /* Header level */
int back = 0;
dk3str_delnl(il);
#line 578 "hbcont.ctr"
proc = (hb_contents_line_processor_t *)obj;
proc->lineno += 1UL;
job = proc->job;
nptr = job->currentnode;
if (0 > hbcont_metadata_index(il)) {
lptr = hbcont_line_new(il, proc->lineno, job->app);
if(lptr) {
if(dk3sto_add(nptr->s_lines, lptr)) {
back = 1;
p1 = dk3str_start(lptr->text, NULL);
if(p1) {
if(hbcont_check_header(p1)) {
back = 0;
p1++;
p1 = dk3str_start(p1, NULL);
if(p1) {
p2 = dk3str_next(p1, NULL);
if(p2) {
lptr->realtext = p2;
lptr->lt = 1;
#if VERSION_BEFORE_20140716
if(dk3sf_sscanf3(p1, dkT("%u"), &u) == 1)
#else
if (0 != dk3ma_ui_from_string(&u, p1, NULL))
#endif
{
lptr->headlevel = u;
lptr->header = proc->nheader;
if(u > proc->maxheader) { proc->maxheader = u; }
proc->nheader += 1UL;
back = 1;
if(dkT('@') == *p2) {
back = 0;
*(p2++) = dkT('\0');
p2 = dk3str_start(p2, NULL);
if(p2) {
p3 = dk3str_chr(p2, dkT('@'));
if(p3) {
*(p3++) = dkT('\0');
p3 = dk3str_start(p3, NULL);
if(p3) {
lptr->aname = p2;
lptr->realtext = p3;
back = 1;
} else {
#line 623 "hbcont.ctr"
/* ERROR: Missing heading text */
dk3app_log_1(job->app,DK3_LL_ERROR,job->msg,32);
}
} else {
#line 627 "hbcont.ctr"
/* ERROR: Missing closing @ */
dk3app_log_1(job->app,DK3_LL_ERROR,job->msg,33);
}
} else {
#line 631 "hbcont.ctr"
/* ERROR: No a name text */
dk3app_log_1(job->app,DK3_LL_ERROR,job->msg,34);
}
}
} else {
#line 636 "hbcont.ctr"
/* ERROR: No header level */
dk3app_log_1(job->app,DK3_LL_ERROR,job->msg,35);
}
} else {
#line 640 "hbcont.ctr"
/* ERROR: No header text */
dk3app_log_1(job->app,DK3_LL_ERROR,job->msg,32);
}
} else {
#line 644 "hbcont.ctr"
/* ERROR: Syntax, no text after dot */
dk3app_log_1(job->app,DK3_LL_ERROR,job->msg,36);
}
}
}
} else {
#line 650 "hbcont.ctr"
/* 2016-10-24: Destroy line structure when failed to save.
*/
hbcont_line_delete(lptr);
}
} else {
#line 655 "hbcont.ctr"
}
} else {
#line 657 "hbcont.ctr"
back = 1;
}
#line 660 "hbcont.ctr"
return back;
}
/** Read contents into storage.
@param job Job structure.
@param proc Line processing structure.
@return 1 on success, 0 on errors.
*/
static
int
hbcont_read(hb_job_t *job, hb_contents_line_processor_t *proc)
{
int res; /* Result from file processing */
int inenc; /* Input encoding */
int back = 0;
#line 678 "hbcont.ctr"
inenc = dk3app_get_input_file_encoding(job->app);
if(0 <= job->iecmd) { inenc = job->iecmd; }
if(0 <= (job->currentnode)->inenc) { inenc = (job->currentnode)->inenc; }
if((job->currentnode)->filename) {
res = dk3stream_process_filename_lines_app(
(void *)proc, hbcont_line_handler, (job->currentnode)->filename,
job->ilfile, job->bs,
dk3app_get_encoding(job->app),
inenc,
job->app
);
if(1 == res) { back = 1; }
#line 690 "hbcont.ctr"
} else {
if(0UL == (job->currentnode)->objno) {
back = 1;
}
}
return back;
}
/** Write HTML page title.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
hbcont_write_title(hb_job_t *job)
{
int back = 0;
#line 710 "hbcont.ctr"
fputs(hbcont_c8_kw[2], job->of);
if((job->currentnode)->title) {
if (((job->options) & HB_JOB_OPT_NUM_IN_PAGE_HEADER)) {
if (!((job->options) & HB_JOB_OPT_CHM)) {
if((job->currentnode)->depth < job->headlevels) {
if(hbtool_write_header_number(job, job->currentnode)) {
hbhtml_output_for_text(job, (job->kwnl[35]));
}
}
}
}
back = hbhtml_output_for_text(job, (job->currentnode)->title);
}
fputs(hbcont_c8_kw[3], job->of);
#line 725 "hbcont.ctr"
return back;
}
/** Write position of current node.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
hbcont_write_position(hb_job_t *job)
{
hb_node_t *nptr; /* Current node to handle. */
int i;
int rs; /* td width */
int curl = 0; /* Current level */
int maxl = 0; /* Maximum level */
int back = 1;
#line 745 "hbcont.ctr"
nptr = job->rootnode;
while(nptr) {
if((nptr->parent) && (nptr->curchild)) {
maxl++;
}
nptr = nptr->curchild;
}
#if TRACE_DEBUG
/* DEBUG */ fprintf(job->of , "<!-- maxl=%d -->\n", maxl);
#endif
if(0 < maxl) {
fputs(hbcont_c8_kw[49], job->of);
fputs(hbcont_c8_kw[4], job->of);
if(!hbhtml_output_for_text(job, (job->msg)[54])) { back = 1; }
fputs(hbcont_c8_kw[46], job->of);
fputs(hbcont_c8_kw[0], job->of);
nptr = job->rootnode;
while(nptr) {
dk3app_set_source_line(job->app, nptr->lineno);
if((nptr->parent) && (nptr->curchild)) {
#if TRACE_DEBUG
/* DEBUG */ fprintf(job->of, "<!-- curl=%d maxl=%d -->\n", curl, maxl);
#endif
fputs(hbcont_c8_kw[6], job->of);
if(0 < curl) {
for(i = 0; i < (curl - 1); i++) {
fputs(hbcont_c8_kw[8], job->of);
fputs(hbcont_c8_kw[9], job->of);
}
fputs(hbcont_c8_kw[8], job->of);
fputs(hbcont_c8_kw[10], job->of);
fputs(hbcont_c8_kw[9], job->of);
}
rs = maxl - curl;
fprintf(job->of, hbcont_c8_kw[11], rs);
if(nptr->title) {
#if (!(VERSION_BEFORE_20140412))
/* 2014-04-12
Also write header number in position.
*/
if ((job->options) & HB_JOB_OPT_NUM_IN_POS) {
if (hbtool_write_header_number(job, nptr)) {
if (!hbhtml_output_for_text(job, dkT(" "))) {
back = 0;
}
}
}
#endif
if(!hbhtml_output_for_text(job, nptr->title)) {
back = 0;
}
}
fputs(hbcont_c8_kw[9], job->of);
fputs(hbcont_c8_kw[7], job->of);
curl++;
}
nptr = nptr->curchild;
}
fputs(hbcont_c8_kw[5], job->of);
fputs(hbcont_c8_kw[30], job->of);
fputs(hbcont_c8_kw[0], job->of);
}
#line 807 "hbcont.ctr"
return back;
}
/** Write anchor name for a header line.
@param job Job structure.
@param lptr Line to process.
@return 1 on success, 0 on error.
*/
static
int
hbcont_write_anchor_name_for_header(hb_job_t *job, hb_line_t *lptr)
{
char buffer[64]; /* Buffer to convert number to text */
int back = 1;
#line 824 "hbcont.ctr"
if(lptr->aname) {
if(!hbhtml_url_output_for_text(job, lptr->aname)) {
back = 0;
}
} else {
#if DK3_SIZEOF_LONG > 4
sprintf(buffer, "%016lx", lptr->header);
#else
sprintf(buffer, "%08lx", lptr->header);
#endif
fputs(hbcont_c8_kw[16], job->of);
fputs(buffer, job->of);
}
#line 837 "hbcont.ctr"
return back;
}
/** Process the content lines saved before.
@param job Job structure.
@param proc Line processing structure.
@param p Previous node.
@param n Next node.
@return 1 on success, 0 on error.
*/
static
int
hbcont_write_contents(
hb_job_t *job,
hb_contents_line_processor_t *proc,
hb_node_t *p,
hb_node_t *n
)
{
hb_file_processor_t myproc;
hb_line_t *lptr; /* Current line to process */
hb_line_t *tocptr; /* Current TOC line to process */
hb_node_t *nptr; /* Current node to process */
dk3_sto_it_t *i_toc; /* Line traversal for TOC */
unsigned cs = 0; /* Column space */
unsigned sp = 0; /* Spaces before data field */
unsigned hl = 0; /* Header level */
unsigned i = 0; /* Create spaces */
int tocpr = 0; /* Flag: Page TOC already printed */
int back = 0;
#line 870 "hbcont.ctr"
if((job->options) & HB_JOB_OPT_CHM) { tocpr = 1; }
nptr = job->currentnode;
i_toc = dk3sto_it_open(nptr->s_lines);
if(i_toc) {
dk3sto_it_reset(nptr->i_lines);
dk3sto_it_reset(i_toc);
back = 1;
do {
lptr = (hb_line_t *)dk3sto_it_next(nptr->i_lines);
if(lptr) {
dk3app_set_source_line(job->app, lptr->lineno);
if(lptr->lt) {
/* Header line */
if((0 == tocpr) && ((nptr->options) & HB_NODE_OPT_PAGE_TOC)) {
tocpr = 1;
#line 885 "hbcont.ctr"
fputs(hbcont_c8_kw[17], job->of);
if(!hbhtml_output_for_text(job, (job->msg)[55])) { back = 0; }
fputs(hbcont_c8_kw[46], job->of);
fputs(hbcont_c8_kw[0], job->of);
do {
tocptr = (hb_line_t *)dk3sto_it_next(i_toc);
if(tocptr) {
if(tocptr->lt) {
dk3app_set_source_line(job->app, tocptr->lineno);
sp = 0;
#if 0
if(tocptr->headlevel < proc->maxheader) {
sp = proc->maxheader - tocptr->headlevel;
}
#endif
if(tocptr->headlevel > 0) {
sp = tocptr->headlevel - 1;
}
cs = proc->maxheader - sp;
fputs(hbcont_c8_kw[19], job->of);
for(i = 0; i < sp; i++) {
fputs(hbcont_c8_kw[21], job->of);
}
fprintf(job->of, hbcont_c8_kw[22], cs);
fputs(hbcont_c8_kw[24], job->of);
if(!hbcont_write_anchor_name_for_header(job, tocptr)) {
back = 0;
}
fputs(hbcont_c8_kw[25], job->of);
if(!hbhtml_output_for_text(job, tocptr->realtext)) {
back = 0;
}
fputs(hbcont_c8_kw[26], job->of);
if(!hbhtml_output_for_text(job, tocptr->realtext)) {
back = 0;
}
fputs(hbcont_c8_kw[27], job->of);
fputs(hbcont_c8_kw[23], job->of);
fputs(hbcont_c8_kw[20], job->of);
dk3app_set_source_line(job->app, lptr->lineno);
}
}
} while(tocptr);
fputs(hbcont_c8_kw[18], job->of);
}
hl = 1 + lptr->headlevel;
if(6 < hl) {
hl = 6;
/* Warning: Header level corrected to 6! */
dk3app_log_1(job->app,DK3_LL_ERROR,job->msg,37);
}
fprintf(job->of, hbcont_c8_kw[14], hl);
if(!hbcont_write_anchor_name_for_header(job, lptr)) {
back = 0;
#line 939 "hbcont.ctr"
}
fprintf(job->of, hbcont_c8_kw[15], hl);
fprintf(job->of, hbcont_c8_kw[12], hl);
if(!hbhtml_output_for_text(job, lptr->realtext)) {
back = 0;
#line 944 "hbcont.ctr"
}
fprintf(job->of, hbcont_c8_kw[13], hl);
} else {
myproc.job = job;
myproc.in_template = 0;
myproc.stm = 0;
myproc.p = p;
myproc.n = n;
#line 952 "hbcont.ctr"
if(1 != hbhtml_line_handler((void *)(&myproc), lptr->text)) {
back = 0;
#line 954 "hbcont.ctr"
}
}
}
} while(lptr);
dk3sto_it_close(i_toc);
}
#line 960 "hbcont.ctr"
return back;
}
/** Write list of external links for current node.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
hbcont_write_link_list(hb_job_t *job)
{
hb_link_t *linkptr; /* Current link to process */
hb_node_t *nptr; /* Current node to process */
int back = 1;
#line 977 "hbcont.ctr"
nptr = job->currentnode;
if(nptr->nextlink) {
dk3sto_it_reset(nptr->i_lbylno);
fputs(hbcont_c8_kw[28], job->of);
if(!hbhtml_output_for_text(job, (job->msg)[23])) { back = 0; }
fputs(hbcont_c8_kw[29], job->of);
fputs(hbcont_c8_kw[31], job->of);
if(!hbhtml_output_for_text(job, (job->msg)[56])) { back = 0; }
fputs(hbcont_c8_kw[46], job->of);
fputs(hbcont_c8_kw[0], job->of);
while(NULL != (linkptr = (hb_link_t *)dk3sto_it_next(nptr->i_lbylno))) {
fputs(hbcont_c8_kw[33], job->of);
/* Number */
fputs(hbcont_c8_kw[35], job->of);
fprintf(job->of, hbcont_c8_kw[37], (1UL + linkptr->lno));
fputs(hbcont_c8_kw[36], job->of);
/* URL */
fputs(hbcont_c8_kw[38], job->of);
if(!hbhtml_url_output_for_text(job, linkptr->url)) { back = 1; }
fputs(hbcont_c8_kw[36], job->of);
fputs(hbcont_c8_kw[34], job->of);
}
fputs(hbcont_c8_kw[32], job->of);
fputs(hbcont_c8_kw[30], job->of);
}
#line 1002 "hbcont.ctr"
return back;
}
/** Create project table of contents.
@param job Job structure.
@return 1 on success, 0 on error.
*/
static
int
hbcont_create_toc(hb_job_t *job)
{
dkChar ofn[DK3_MAX_PATH]; /* Output file name */
hb_node_t *nptr; /* Current node to process */
hb_node_t *dest; /* Print node for cur node */
dkChar const *oldsourcefile; /* Old source file name saved */
unsigned long oldsourceline; /* Old source file line saved */
int res; /* Result from file name cr */
int i;
int back = 1;
#line 1024 "hbcont.ctr"
oldsourcefile = dk3app_get_source_file(job->app);
oldsourceline = dk3app_get_source_line(job->app);
dk3app_set_source_file(job->app, job->infilename);
dk3app_set_source_line(job->app, 0UL);
fputs(hbcont_c8_kw[47], job->of);
if(!hbhtml_output_for_text(job, (job->msg)[45])) { back = 0; }
fputs(hbcont_c8_kw[48], job->of);
fputs(hbcont_c8_kw[39], job->of);
if(!hbhtml_output_for_text(job, (job->msg)[57])) { back = 0; }
fputs(hbcont_c8_kw[46], job->of);
fputs(hbcont_c8_kw[0], job->of);
nptr = job->rootnode;
while(nptr) {
#line 1038 "hbcont.ctr"
dk3app_set_source_line(job->app, nptr->lineno);
switch(nptr->tocstate) {
case HB_TOC_STATE_INIT: {
#line 1041 "hbcont.ctr"
if(nptr->parent) {
/* Write TOC entry */
dest = NULL;
if(nptr->filename) {
dest = nptr;
} else {
if(nptr->jumpnode) {
dest = nptr->jumpnode;
}
}
if(dest) {
#line 1052 "hbcont.ctr"
res =
hbhtml_create_output_filename(ofn,DK3_SIZEOF(ofn,dkChar),job,dest);
if(res) {
fputs(hbcont_c8_kw[41], job->of);
for(i = 1; i < nptr->depth; i++) {
fputs(hbcont_c8_kw[43], job->of);
}
fprintf(
job->of, hbcont_c8_kw[44], ((job->maxdepth) - (nptr->depth) + 1)
);
fputs(hbcont_c8_kw[45], job->of);
if(!hbhtml_url_output_for_text(job, ofn)) { back = 0; }
fputs(hbcont_c8_kw[25], job->of);
if(hbtool_write_header_number(job, nptr)) {
fputs(hbcont_c8_kw[1], job->of);
}
if(!hbhtml_output_for_text(job, nptr->title)) { back = 0; }
fputs(hbcont_c8_kw[46], job->of);
if(hbtool_write_header_number(job, nptr)) {
fputs(hbcont_c8_kw[1], job->of);
}
if(!hbhtml_output_for_text(job, nptr->title)) { back = 0; }
fputs(hbcont_c8_kw[27], job->of);
fputs(hbcont_c8_kw[9], job->of);
fputs(hbcont_c8_kw[42], job->of);
} else {
/* ERROR: Failed to create output file name */
back = 0;
}
} else {
#line 1082 "hbcont.ctr"
/* ERROR: No destination found */
back = 0;
dk3app_log_1(job->app, DK3_LL_ERROR, job->msg, 51);
}
}
dk3sto_it_reset(nptr->i_subnodes);
nptr->tocstate = HB_TOC_STATE_IN_PROGRESS;
} break;
case HB_TOC_STATE_IN_PROGRESS: {
#line 1091 "hbcont.ctr"
nptr->curchild = dk3sto_it_next(nptr->i_subnodes);
if(nptr->curchild) {
nptr = nptr->curchild;
} else {
nptr->tocstate = HB_TOC_STATE_FINISHED;
}
} break;
case HB_TOC_STATE_FINISHED: {
#line 1099 "hbcont.ctr"
nptr = nptr->parent;
} break;
}
}
fputs(hbcont_c8_kw[40], job->of);
dk3app_set_source_file(job->app, oldsourcefile);
dk3app_set_source_line(job->app, oldsourceline);
#line 1107 "hbcont.ctr"
return back;
}
/** Create keyword index.
@param job Job structure
@return 1 on success, 0 on error.
*/
static
int
hbcont_create_keyword_index(hb_job_t *job)
{
hb_index_entry_t *pp = NULL; /* Previous pointer */
hb_index_entry_t *cp = NULL; /* Current pointer */
#if VERSION_BEFORE_20150821
dk3_c32_t pstc = 0UL; /* Previous start character */
dk3_c32_t cstc = 0UL; /* Start character */
#endif
int nkw = 0; /* Flag: Open new keyword */
int hh2 = 0; /* Flag: Have division and h2 */
int back = 1;
#line 1130 "hbcont.ctr"
dk3sto_it_reset(job->i_index);
while(NULL != (cp = (hb_index_entry_t *)dk3sto_it_next(job->i_index))) {
#line 1133 "hbcont.ctr"
if(!(hh2)) {
#line 1134 "hbcont.ctr"
hh2 = 1;
fputs(hbcont_c8_kw[50], job->of);
fputs(hbcont_c8_kw[51], job->of);
if(!hbhtml_output_for_text(job, (job->msg)[46])) { back = 0; }
fputs(hbcont_c8_kw[29], job->of);
fputs(hbcont_c8_kw[52], job->of);
}
/* Process entry.
*/
nkw = 0;
if(pp) {
#line 1145 "hbcont.ctr"
if(dk3str_cmp(pp->tx, cp->tx)) {
#line 1146 "hbcont.ctr"
nkw = 1;
fputs(hbcont_c8_kw[57], job->of);
}
} else {
nkw = 1;
}
if(nkw) {
fputs(hbcont_c8_kw[54], job->of);
if(!hbhtml_output_for_text(job, cp->tx)) { back = 0; }
fputs(hbcont_c8_kw[55], job->of);
fputs(hbcont_c8_kw[56], job->of);
}
fputs(hbcont_c8_kw[58], job->of);
fputs(hbcont_c8_kw[60], job->of);
if(!hbhtml_url_output_for_text(job, cp->fn)) { back = 0; }
fputs(hbcont_c8_kw[61], job->of);
if(!hb_index_write_anchor(job, cp)) { back = 0; }
#if (!(VERSION_BEFORE_20140412))
fputs(hbcont_c8_kw[25], job->of);
(void)hbtool_write_all_titles(job, cp->no, 1);
#endif
fputs(hbcont_c8_kw[46], job->of);
if(cp->no) {
if((cp->no)->title) {
#if (!(VERSION_BEFORE_20140412))
if ((job->options) & HB_JOB_OPT_NUM_IN_IDX) {
if (hbtool_write_header_number(job, cp->no)) {
hbhtml_output_for_text(job, dkT(" "));
}
}
#endif
if(!hbhtml_output_for_text(job, (cp->no)->title)) { back = 0; }
} else back = 0;
} else { back = 0; }
fputs(hbcont_c8_kw[27], job->of);
fputs(hbcont_c8_kw[59], job->of);
pp = cp;
#if VERSION_BEFORE_20150821
pstc = cstc;
#endif
}
if(hh2) {
fputs(hbcont_c8_kw[57], job->of);
fputs(hbcont_c8_kw[53], job->of);
fputs(hbcont_c8_kw[30], job->of);
fputs(hbcont_c8_kw[0], job->of);
}
#line 1193 "hbcont.ctr"
return back;
}
int
hbcont_process(hb_job_t *job, hb_node_t *p, hb_node_t *n)
{
hb_contents_line_processor_t proc;
dkChar const *oldsourcefile;
unsigned long oldsourceline;
int back = 0;
#line 1206 "hbcont.ctr"
oldsourcefile = dk3app_get_source_file(job->app);
oldsourceline = dk3app_get_source_line(job->app);
proc.job = job;
proc.nptr = job->currentnode;
proc.lineno = 0UL;
proc.nheader = 0UL;
proc.maxheader = 0;
dk3app_set_source_file(job->app, job->infilename);
dk3app_set_source_line(job->app, (job->currentnode)->lineno);
if(hbcont_prepare(job)) {
dk3app_set_source_file(job->app, (job->currentnode)->filename);
dk3app_set_source_line(job->app, 0UL);
if(hbcont_read(job, &proc)) {
back = 1;
/* For the root node we do not write a position.
*/
if((0UL != (job->currentnode)->objno) && ((job->currentnode)->filename)) {
if(!((job->options) & HB_JOB_OPT_CHM)) {
if(((job->currentnode)->options) & HB_NODE_OPT_HEADER_CHAIN) {
dk3app_set_source_file(job->app, job->infilename);
if(!hbcont_write_position(job)) { back = 0; }
}
}
}
dk3app_set_source_file(job->app, job->infilename);
dk3app_set_source_line(job->app, (job->currentnode)->lineno);
if(!hbcont_write_title(job)) { back = 0; }
/* We can write contents only if an input file is specified.
*/
if((job->currentnode)->filename) {
dk3app_set_source_file(job->app, (job->currentnode)->filename);
dk3app_set_source_line(job->app, 0UL);
if(!hbcont_write_contents(job, &proc, p, n)) { back = 0; }
dk3app_set_source_file(job->app, (job->currentnode)->filename);
dk3app_set_source_line(job->app, 0UL);
if((job->currentnode)->nextlink) {
if(!hbcont_write_link_list(job)) { back = 0; }
}
}
if(0UL == (job->currentnode)->objno) {
#line 1252 "hbcont.ctr"
if(!((job->options) & HB_JOB_OPT_CHM)) {
if((job->options) & HB_JOB_OPT_CREATE_TOC) {
#line 1254 "hbcont.ctr"
if(!hbcont_create_toc(job)) { back = 0; }
}
if((job->options) & HB_JOB_OPT_CREATE_INDEX) {
#line 1257 "hbcont.ctr"
/* Eventually create index */
if(!hbcont_create_keyword_index(job)) { back = 0; }
}
}
}
}
dk3app_set_source_file(job->app, job->infilename);
dk3app_set_source_line(job->app, (job->currentnode)->lineno);
}
hbcont_cleanup(job);
dk3app_set_source_file(job->app, oldsourcefile);
dk3app_set_source_line(job->app, oldsourceline);
#line 1270 "hbcont.ctr"
return back;
}
|