summaryrefslogtreecommitdiff
path: root/support/dktools/dk3uc2l.c
blob: 56236d21c651fb65f7ce129527f9590e54372fac (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
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
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
/*
	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: dk3uc2l.ctr
*/

/*
Copyright (C) 2011-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 dk3uc2l.c The dk3uc2l module.
*/


#line 162 "dk3uc2l.ctr"

/**	Enable or disable support for dk3_uc2l_pkg_t.
*/
#define	HAVE_PACKAGES	1


#include "dk3all.h"
#include "dk3maih8.h"




#line 173 "dk3uc2l.ctr"



/**	LaTeX commands to start and end math mode.
*/
static char const * const dk3uc2lat_mm[] = {
"\\(",
"\\)",
"% font encodings:",
"% package: ",
"\n",
};



#if 0
/**	Font encoding names.
*/
static char const * const dk3uc2lat_font_encodings[] = {
"ot1",
"!ot1",
"t1",
"!t1",
"t4",
"!t4",
"t5",
"!t5",
NULL
};
#endif



/**	Font encoding names, used in error messages.
*/
static dkChar const * const	dk3uc2l_font_encoding_names[] = {
dkT("OT1"),
dkT("T1"),
dkT("T4"),
dkT("T5"),
NULL
};



/**	Font encoding names written at end of output file.
*/
static const char * const	dk3uc2l_c8_font_encoding_names[] = {
/* 0 */
" OT1",

/* 1 */
" T1",

/* 2 */
" T4",

/* 3 */
" T5",

NULL


#line 227 "dk3uc2l.ctr"
};



/**	Allowed suffixes for conversion data files.
*/
static dkChar const * const	dk3uc2l_suffixes[] = {
dkT(".t2l"),
#if DK3_HAVE_ZLIB_H	&& (DK3_CHAR_SIZE == 1)
dkT(".t2l.gz"),
#endif
#if DK3_HAVE_BZLIB_H	&& (DK3_CHAR_SIZE == 1)
dkT(".t2l.bz2"),
#endif
NULL
};



/**	Compression suffixes.
*/
static dkChar const * const	dk3uc2l_co_suf[] = {
/* 0 */
dkT(".gz"),

/* 1 */
dkT(".bz2"),

NULL


#line 253 "dk3uc2l.ctr"
};



/**	Attribute keywords.
*/
static const char * const	dk3uc2l_kw[] = {
/* 0 */
"b$oth",

/* 1 */
"t$ext",

/* 2 */
"m$ath",

/* 3 */
"e$ncoding",

/* 4 */
"p$ackages",

NULL


#line 267 "dk3uc2l.ctr"
};



/**	Encoding names, used for reporting.
*/
static const char * const	dk3uc2l_enco[] = {
/* 0 */
"ot1",

/* 1 */
"t1",

/* 2 */
"t4",

/* 3 */
"t5",

NULL


#line 280 "dk3uc2l.ctr"
};



/**	Release an array of string pointers.
	@param	ap	Array base address.
	@param	ns	Number of strings.
*/
static
void
dk3uc2lat_release_pointer_array(char const **ap, size_t ns)
{
  char const	**ptr;	/* Current string in array. */
  size_t	  i;	/* Current string index in array. */
  

#line 295 "dk3uc2l.ctr"
  ptr = ap; i = ns;
  while(i--) {
    dk3_release(*ptr);
    ptr++;
  } 

#line 300 "dk3uc2l.ctr"
  dk3_delete(ap);
}



/**	Destroy range structure, release memory.
	@param	rp	Structure to destroy.
*/
static
void
dk3uc2lat_range_delete(dk3_uc2lat_range_t *rp)
{
  size_t	numchar;	/* Number of characters in this range. */
  dkChar const	**ptr;		/* Release all descriptions. */
  dk3_uc2lat_pkg_t	***pkgppp;
  size_t	i;		/* Number of descriptions to release. */
  

#line 317 "dk3uc2l.ctr"
  if(rp) {
    numchar = (size_t)(rp->end - rp->start + 1);
    if(numchar > 0) {
      rp->dir = NULL;
      if(rp->f) {
        dk3_release(rp->f);
      } rp->f = NULL;
      if(rp->dsc) {
        ptr = rp->dsc;
	i = (size_t)(rp->end - rp->start + 1);
	while(i--) {
	  dk3_release(*ptr);
	  ptr++;
	}
      } rp->dsc = NULL;
      if(rp->a) {
        dk3uc2lat_release_pointer_array(rp->a, numchar);
      } rp->a = NULL;
      if(rp->t) {
        dk3uc2lat_release_pointer_array(rp->t, numchar);
      } rp->t = NULL;
      if(rp->m) {
        dk3uc2lat_release_pointer_array(rp->m, numchar);
      } rp->m = NULL;
      if(rp->p) {
        pkgppp = rp->p;
	i = (size_t)(rp->end - rp->start + 1);
	while (i--) {
	  dk3_release(*pkgppp);
	  pkgppp++;
	}
        dk3_delete(rp->p);
      } rp->p = NULL;
      rp->start = (dk3_c32_t)0UL; rp->end = (dk3_c32_t)0UL;
      rp->ia = 0x00;
    }
    dk3_delete(rp);
  } 

#line 355 "dk3uc2l.ctr"
}


#if HAVE_PACKAGES

/**	Destroy package structure, release memory.
	@param	pp	Structure to release.
*/
static
void
dk3uc2lat_pkg_delete(dk3_uc2lat_pkg_t *pp)
{
  

#line 368 "dk3uc2l.ctr"
  if(pp) {	

#line 369 "dk3uc2l.ctr"
    dk3_release(pp->name);
    pp->used = 0x00;
    dk3_delete(pp);
  } 

#line 373 "dk3uc2l.ctr"
}

#endif


/**	Destroy UC to LaTeX directory structure, release memory.
	@param	dp	Structure to destroy.
*/
static
void
dk3uc2lat_dir_delete(dk3_uc2lat_dir_t *dp)
{
  

#line 386 "dk3uc2l.ctr"
  if(dp) {
    if(dp->s_ran) {
      if(dp->i_ran) {
        dk3sto_it_close(dp->i_ran);
      } dp->i_ran = NULL;
      dk3sto_close(dp->s_ran);
    } dp->s_ran = NULL;
    dk3_release(dp->sn);
    dp->loaded = 0x00;
    dk3_delete(dp);
  } 

#line 397 "dk3uc2l.ctr"
}



#if HAVE_PACKAGES

/**	Compare two package records.
	  @param	l	Left record.
	  @param	r	Right record or name.
	  @param	cr	Comparison criteria (0=record/record, 1=record/name).
	  @return	Comparison result.
*/
static
int
dk3uc2lat_pkg_compare(void const *l, void const *r, int cr)
{
  int back = 0;
  dk3_uc2lat_pkg_t const	*pl;	/* Left pointer. */
  dk3_uc2lat_pkg_t const	*pr;	/* Right pointer. */

  pl = (dk3_uc2lat_pkg_t const *)l;
  pr = (dk3_uc2lat_pkg_t const *)r;
  if(l) {
    if(r) {
	switch(cr) {
	  case 1: {
	    if(pl->name) {
	      back = dk3str_c8_cmp(pl->name, (char const *)r);
	    } else { back = -1; }
	  } break;
	  default: {
	    if(pl->name) {
	      if(pr->name) {
		back = dk3str_c8_cmp(pl->name, pr->name);
	      } else { back = 1; }
	    } else {
	      if(pr->name) { back = -1; }
	    }
	  } break;
	}
    } else { back = 1; }
  } else {
    if(r) { back = -1; }
  }
  if(back < -1) { back = -1; }
  if(back >  1) { back =  1; }
  return back;
}

#endif



/**	Compare two range structures by start and end character.
	  @param	l	Left structure.
	  @param	r	Right structure/UC character.
	  @param	cr	Comparison criteria (0=struct/struct, 1=struct/char).
	  @return	Comparison result.
*/
static
int
dk3uc2lat_range_compare(void const *l, void const *r, int cr)
{
  int back = 0;
  dk3_uc2lat_range_t const	*pl;	/* Left pointer. */
  dk3_uc2lat_range_t const	*pr;	/* Right pointer. */
  dk3_c32_t		*ucptr;	/* Right pointer is a character pointer. */

  pl = (dk3_uc2lat_range_t const *)l;
  pr = (dk3_uc2lat_range_t const *)r;
  if(l) {
    if(r) {
	switch(cr) {
	  case 1: {
	    ucptr = (dk3_c32_t *)r;
	    if(pl->start > (*ucptr)) {
	      back = 1;
	    } else {
	      if(pl->end < (*ucptr)) {
		back = -1;
	      }
	    }
	  } break;
	  default: {
	    if(pl->start > pr->end) {
	      back = 1;
	    } else {
	      if(pl->end < pr->start) {
		back = -1;
	      }
	    }
	  } break;
	}
    } else { back = 1; }
  } else {
    if(r) { back = -1; }
  }
  return back;
}



/**	Compare two UC to LaTeX directory structures.
	  @param	l	Left structure.
	  @param	r	Right structure/name.
	  @param	cr	Comparison criteria (0=struct/struct, 1=struct/name).
	  @return	Comparison result.
*/
static
int
dk3uc2lat_dir_compare(void const *l, void const *r, int cr)
{
  int back = 0;
  dk3_uc2lat_dir_t const	*pl;	/* Left pointer. */
  dk3_uc2lat_dir_t const	*pr;	/* Right pointer. */

  pl = (dk3_uc2lat_dir_t const *)l;
  pr = (dk3_uc2lat_dir_t const *)r;
  if(l) {
    if(r) {
	switch(cr) {
	  case 1: {
	    if(pl->sn) {
	      back = dk3str_fncmp(pl->sn, (dkChar const *)r);
	    } else { back = -1; }
	  } break;
	  default: {
	    if(pl->sn) {
	      if(pr->sn) {
		back = dk3str_fncmp(pl->sn, pr->sn);
	      } else { back = 1; }
	    } else {
	      if(pr->sn) { back = -1; }
	    }
	  } break;
	}
    } else { back = 1; }
  } else {
    if(r) { back = -1; }
  }
  return back;
}



void
dk3uc2lat_close(dk3_uc2lat_t *u)
{
#if HAVE_PACKAGES
  dk3_uc2lat_pkg_t	*ppkg;
#endif
  dk3_uc2lat_dir_t	*pdir;
  dk3_uc2lat_range_t	*pran;
  

#line 551 "dk3uc2l.ctr"
  if (NULL != u) {
    u->app = NULL;
    dk3_release(u->dir);
    dk3_release(u->buf);
    if (NULL != u->s_ran) {
      if (NULL != u->i_ran) {
        dk3sto_it_reset(u->i_ran);
	do {
	  pran = (dk3_uc2lat_range_t *)dk3sto_it_next(u->i_ran);
	  if (NULL != pran) {
	    dk3uc2lat_range_delete(pran);
	  }
	} while (NULL != pran);
	dk3sto_it_close(u->i_ran);
      }
      dk3sto_close(u->s_ran);
    }
    u->s_ran = NULL; u->i_ran = NULL;
    if (NULL != u->s_dir) {
      if (NULL != u->i_dir) {
        dk3sto_it_reset(u->i_dir);
	do {
	  pdir = (dk3_uc2lat_dir_t *)dk3sto_it_next(u->i_dir);
	  if (NULL != pdir) {
	    dk3uc2lat_dir_delete(pdir);
	  }
	} while (NULL != pdir);
	dk3sto_it_close(u->i_dir);
      }
      dk3sto_close(u->s_dir);
    }
    u->s_dir = NULL; u->i_dir = NULL;
#if HAVE_PACKAGES
    if (NULL != u->s_pkg) {
      if (NULL != u->i_pkg) {
        dk3sto_it_reset(u->i_pkg);
	do {
	  ppkg = (dk3_uc2lat_pkg_t *)dk3sto_it_next(u->i_pkg);
	  if (NULL != ppkg) {
	    dk3uc2lat_pkg_delete(ppkg);
	  }
	} while (NULL != ppkg);
	dk3sto_it_close(u->i_pkg);
      }
      dk3sto_close(u->s_pkg);
    }
    u->s_pkg = NULL; u->i_pkg = NULL;
#endif
    u->rca = NULL;
    u->szbuf = 0;
    u->f_dsc = 0;
    u->f_utf8 = 0;
    u->fe = 0;
    dk3_delete(u);
  }
  

#line 607 "dk3uc2l.ctr"
}



#if HAVE_PACKAGES

/**	Create package structure, allocate memory.
	@param	pn	Package name.
	@param	app	Application structure for diagnostics.
	@return	Pointer to new structure on success, NULL on error.
*/
static
dk3_uc2lat_pkg_t *
dk3uc2lat_pkg_new(char const *pn, dk3_app_t *app)
{
  dk3_uc2lat_pkg_t *back = NULL;
  

#line 624 "dk3uc2l.ctr"
  back = dk3_new_app(dk3_uc2lat_pkg_t,1,app);
  if(back) {
    back->used = 0x00;
    back->name = dk3str_c8_dup_app(pn,app);
    if(!(back->name)) {
      dk3uc2lat_pkg_delete(back);
      back = NULL;
    }
  } 

#line 633 "dk3uc2l.ctr"
  return back;
}

#endif


/**	Create range structure, allocate memory.
	@param	start	Start character of range.
	@param	end	End character of range.
	@param	dir	Directory structure (parent of this range).
	@param	app	Application structure for diagnostics.
	@return	Pointer to new range structure on success, NULL on error.
*/
static
dk3_uc2lat_range_t *
dk3uc2lat_range_new(
  dk3_c32_t start, dk3_c32_t end, dk3_uc2lat_dir_t *dir, dk3_app_t *app
)
{
  dk3_uc2lat_range_t	*back = NULL;
  char			range_text[32];		/* Buffer for number range. */
  dkChar		dk_range_text[32];	/* Buffer for number range. */
  

#line 656 "dk3uc2l.ctr"
  if(dk3app_max_log_level(app) >= DK3_LL_DEBUG) {
    sprintf(range_text, "%lx-%lx", (long)start, (long)end);
    (void)dk3str_c8_to_str_simple_app(dk_range_text, 32, range_text, app);
    dk3app_log_i3(app, DK3_LL_DEBUG, 238, 239, dk_range_text);
  }
  if(end >= start) {
    back = dk3_new_app(dk3_uc2lat_range_t,1,app);
    if(back) {
      back->dir = dir;
      back->dsc = NULL;
      back->a = NULL;
      back->t = NULL;
      back->m = NULL;
#if HAVE_PACKAGES
      back->p = NULL;
#endif
      back->f = NULL;
      back->start = start;
      back->end = end;
      back->ia = 0x00;
    }
  } else {
    if(app) {
      dk3app_log_i1(app, DK3_LL_ERROR, 220);
    }
  } 

#line 682 "dk3uc2l.ctr"
  return back;
}



/**	Create UC to LaTeX directory structure, allocate memory.
	@param	sn	Short directory file name.
	@param	app	Application structure for diagnostics.
	@return	Pointer to new directory structure on success, NULL on error.
*/
static
dk3_uc2lat_dir_t *
dk3uc2lat_dir_new(dkChar const *sn, dk3_app_t *app)
{
  dk3_uc2lat_dir_t *back = NULL;
  

#line 698 "dk3uc2l.ctr"
  back = dk3_new_app(dk3_uc2lat_dir_t,1,app);
  if(back) {
    back->s_ran = NULL; back->i_ran = NULL; back->sn = NULL;
    back->loaded = 0x00;
    back->s_ran = dk3sto_open_app(app);
    if(back->s_ran) {
      dk3sto_set_comp(back->s_ran, dk3uc2lat_range_compare, 0);
      back->i_ran = dk3sto_it_open(back->s_ran);
      if(back->i_ran) {
        back->sn = dk3str_dup_app(sn,app);
      }
    }
    if(!((back->s_ran) && (back->i_ran) && (back->sn))) {
      dk3uc2lat_dir_delete(back); back = NULL;
    }
  } 

#line 714 "dk3uc2l.ctr"
  return back;
}



/**	Create new LaTeX encoder.
	  @param	dn	Directory containing the data files.
	  @param	f_utf8	Flag: Allowed to write UTF-8 output.
	  @param	app	Application structure for diagnostics, may be NULL.
	  @return	Pointer to new encoder on success, NULL on error.
*/
static
dk3_uc2lat_t *
dk3uc2lat_t_new(
  const dkChar	*dn,
  int		 f_utf8,
  dk3_app_t	*app
)
{
  dk3_uc2lat_t		*back	= NULL;
  int			 ok	= 0;
  

#line 736 "dk3uc2l.ctr"
  back = dk3_new_app(dk3_uc2lat_t,1,app);
  if (NULL != back) {
    back->app = app;
    back->dir = NULL;
    back->buf = NULL;
    back->s_ran = NULL;
    back->i_ran = NULL;
    back->s_dir = NULL;
    back->i_dir = NULL;
#if HAVE_PACKAGES
    back->s_pkg = NULL;
    back->i_pkg = NULL;
#endif
    back->rca = NULL;
    back->szbuf = 0;
    back->f_dsc = 0;
    back->f_utf8 = f_utf8;
    back->fe = 
    DK3_FONT_ENCODING_OT1 + DK3_FONT_ENCODING_T1
    + DK3_FONT_ENCODING_T4 + DK3_FONT_ENCODING_T5;
    back->dir = dk3str_dup_app(dn, app);
    back->buf = dk3_new_app(char,16,app);
    if (NULL != back->buf) { back->szbuf = 16; }
    if ((NULL != back->dir) && (NULL != back->buf)) {
      back->s_ran = dk3sto_open_app(app);
      if (NULL != back->s_ran) {
        dk3sto_set_comp(back->s_ran, dk3uc2lat_range_compare, 0);
        back->s_dir = dk3sto_open_app(app);
        if (NULL != back->s_dir) {
          dk3sto_set_comp(back->s_dir, dk3uc2lat_dir_compare, 0);
#if HAVE_PACKAGES
          back->s_pkg = dk3sto_open_app(app);
          if (NULL != back->s_pkg) {
            dk3sto_set_comp(back->s_pkg, dk3uc2lat_pkg_compare, 0);
#endif
            back->i_ran = dk3sto_it_open(back->s_ran);
            if (NULL != back->i_ran) {
              back->i_dir = dk3sto_it_open(back->s_dir);
              if (NULL != back->i_dir) {
#if HAVE_PACKAGES
                back->i_pkg = dk3sto_it_open(back->s_pkg);
                if (NULL != back->i_pkg) {
#endif
                  ok = 1;
#if HAVE_PACKAGES
		}
#endif
              }
            }
#if HAVE_PACKAGES
	  }
#endif
        }
      }
    }
    if (0 == ok) {
      dk3uc2lat_close(back);
      back = NULL;
    }
  } 

#line 796 "dk3uc2l.ctr"
  return back;
}



/**	Check the file name whether it contains LaTeX conversion data
	and can be processed.
	@param	fn	File name to check.
	@return	1 if yes, 0 otherwise.
*/
static
int
dk3uc2lat_is_suitable_file(const dkChar *fn)
{
  const dkChar * const	*ptr;		/* Traverse allowed suffixes array */
  size_t	 	 szfn	= 0;	/* File name size */
  size_t	 	 szsu	= 0;	/* Allowed suffix size */
  int		 	 back	= 0;
  

#line 815 "dk3uc2l.ctr"
  szfn = dk3str_len(fn);
  ptr = dk3uc2l_suffixes;
  while ((NULL != *ptr) && (0 == back)) {
    szsu = dk3str_len(*ptr);
    if (szfn > szsu) {
      if (0 == dk3str_fncmp(&(fn[szfn - szsu]), *ptr)) {
        back = 1;
      }
    }
    ptr++;
  } 

#line 826 "dk3uc2l.ctr"
  return back;
}



/**	Add one character to the range descriptions of a file directory.
	@param	uptr	Conversion structure to set up.
	@param	pdir	File directory to set up.
	@param	chr	Character to add.
	@param	app	Application structure for diagnostics, may be NULL.
	@return	1 on success, 0 on error.
*/
static
int
dk3uc2l_add_char_to_dir(
  dk3_uc2lat_t		*uptr,
  dk3_uc2lat_dir_t	*pdir,
  dk3_c32_t		 chr,
  dk3_app_t		*app
)
{
  dkChar		 cbuf[64];
  dk3_uc2lat_range_t	*prange;
  dk3_uc2lat_range_t	*pr2;
  size_t		 szcbuf = DK3_SIZEOF(cbuf,dkChar);
  dk3_c32_t		 tchr;
  int			 back = 0;
  

#line 854 "dk3uc2l.ctr"
  prange = dk3sto_it_find_like(uptr->i_ran, &chr, 1);
  if (NULL == prange) {
    prange = dk3sto_it_find_like(pdir->i_ran, &chr, 1);
    if (NULL == prange) {
      if ((dk3_c32_t)0UL < chr) {			

#line 859 "dk3uc2l.ctr"
        tchr = chr - 1;
	prange = dk3sto_it_find_like(pdir->i_ran, &tchr, 1);
	if (NULL != prange) {	

#line 862 "dk3uc2l.ctr"
	  prange->end = chr;
	  back = 1;	

#line 864 "dk3uc2l.ctr"
	  if (0xFFFFFFFFUL > (unsigned long)chr) {
	    tchr = chr + (dk3_c32_t)1UL;
	    pr2 = dk3sto_it_find_like(pdir->i_ran, &tchr, 1);
	    if (NULL != pr2) {	

#line 868 "dk3uc2l.ctr"
	      tchr = pr2->end;
	      dk3sto_remove(pdir->s_ran, pr2);
	      dk3uc2lat_range_delete(pr2);
	      prange->end = tchr;
	      

#line 873 "dk3uc2l.ctr"
	    }
	  }
	}
      }
      if (0 == back) {					

#line 878 "dk3uc2l.ctr"
        if (0xFFFFFFFFUL > (unsigned long)chr) {	

#line 879 "dk3uc2l.ctr"
	  tchr = chr + (dk3_c32_t)1UL;
	  prange = dk3sto_it_find_like(pdir->i_ran, &tchr, 1);
	  if (NULL != prange) {	

#line 882 "dk3uc2l.ctr"
	    prange->start = chr;
	    back = 1;	

#line 884 "dk3uc2l.ctr"
	  }
	}
      }
      if (0 == back) {					

#line 888 "dk3uc2l.ctr"
        prange = dk3uc2lat_range_new(chr, chr, pdir, app);
	if (NULL != prange) {
	  if (dk3sto_add(pdir->s_ran, prange)) {
	    back = 1;	

#line 892 "dk3uc2l.ctr"
	  } else {
	    dk3uc2lat_range_delete(prange);
	  }
	}
      }
    } else {						

#line 898 "dk3uc2l.ctr"
      /* ERROR: Already found! */
      if (0 != dk3ma_um_to_hex_string(cbuf, szcbuf, (dk3_um_t)chr, 8)) {
        dk3app_log_i3(uptr->app, DK3_LL_ERROR, 395, 396, cbuf);
      } else {
        dk3app_log_i1(uptr->app, DK3_LL_ERROR, 397);
      }
    }
  } else {						

#line 906 "dk3uc2l.ctr"
    /* ERROR: Already found ! */
    if (0 != dk3ma_um_to_hex_string(cbuf, szcbuf, (dk3_um_t)chr, 8)) {
      dk3app_log_i3(uptr->app, DK3_LL_ERROR, 395, 396, cbuf);
    } else {
      dk3app_log_i1(uptr->app, DK3_LL_ERROR, 397);
    }
  } 

#line 913 "dk3uc2l.ctr"
  return back;
}



/**	Apply data from stream to directory information for one file.
	@param	uptr	Conversion structure to set up.
	@param	pdir	File directory entry to configure.
	@param	istrm	Input stream for file (normal or compressed).
	@param	fn	Full path name.
	@param	sn	Short file name.
	@param	app	Application structure for diagnostics, may be NULL.
	@return	1 on success, 0 on error.
*/
static
int
dk3uc2l_apply_1(
  dk3_uc2lat_t		*uptr,
  dk3_uc2lat_dir_t	*pdir,
  dk3_stream_t		*istrm,
  const dkChar		*fn,
  const dkChar		*sn,
  dk3_app_t		*app
)
{
  char			 buf[512];
  char			*p1;
  char			*p2;
  dk3_uc2lat_range_t	*prange;
  unsigned long		 lineno	= 0UL;
  unsigned long		 chr;
  int			 back	= 1;
  

#line 946 "dk3uc2l.ctr"
  while ((1 == back) && (1 == dk3stream_c8_fgets(istrm, buf, sizeof(buf)))) {
    dk3app_set_source_line(app, ++lineno);
    buf[sizeof(buf) - 1] = '\0';
    

#line 950 "dk3uc2l.ctr"
    p1 = dk3str_c8_start(buf, NULL);
    if (NULL != p1) {
      if ('#' != *p1) {
        p2 = dk3str_c8_next(p1, NULL);
	if (NULL != p2) {
	  if (0 != dk3ma_ul_from_c8_hex_string(&chr, p1, NULL)) {
	    if (0 == dk3uc2l_add_char_to_dir(uptr, pdir, chr, app)) {
	      back = 0;	

#line 958 "dk3uc2l.ctr"
	    }
	  } else {
	    /* ERROR: Syntax error, not a hexadecimal number */
	    dk3app_log_i1(uptr->app, DK3_LL_ERROR, 398);
	  }
	} else {
	  /* ERROR: Syntax error, missing configuration */
	  dk3app_log_i1(uptr->app, DK3_LL_ERROR, 400);
	}
      }
    }
  }
  if (1 == back) {	

#line 971 "dk3uc2l.ctr"
    dk3sto_it_reset(pdir->i_ran);
    do {
      prange = dk3sto_it_next(pdir->i_ran);
      if (NULL != prange) {	

#line 975 "dk3uc2l.ctr"
        if (0 == dk3sto_add(uptr->s_ran, prange)) {
	  dk3uc2lat_range_delete(prange);
	  back = 0;	

#line 978 "dk3uc2l.ctr"
	}
      }
    } while (NULL != prange);
  } else {		

#line 982 "dk3uc2l.ctr"
    dk3sto_it_reset(pdir->i_ran);
    do {
      prange = dk3sto_it_next(pdir->i_ran);
      if (NULL != prange) {
        dk3uc2lat_range_delete(prange);
      }
    } while (NULL != prange);
  } 

#line 990 "dk3uc2l.ctr"
  return back;
}



/**	Apply directory information for a file.
	@param	uptr	Conversion structure to set up.
	@param	fn	File name containing conversion data.
	@param	app	Application structure for diagnostics, may be NULL.
	@return	1 on success, 0 on error.
*/
static
int
dk3uc2lat_pass_1(
  dk3_uc2lat_t *uptr, const dkChar *fn, const dkChar *sn, dk3_app_t *app
)
{
  dk3_uc2lat_dir_t	*pdir	= NULL;
  dk3_stream_t		*istrm	= NULL;
  FILE			*fipo	= NULL;
  const dkChar		*oldsrc	= NULL;
  const dkChar		*fsuf	= NULL;
#if DK3_HAVE_ZLIB_H	&& (DK3_CHAR_SIZE == 1)
  gzFile		 gzf	= NULL;
#endif
#if DK3_HAVE_BZLIB_H	&& (DK3_CHAR_SIZE == 1)
  BZFILE		*bzf	= NULL;
#endif
  unsigned long		 oldln	= 0UL;
#if DK3_HAVE_FNCASEINS
  int			 fncs	= 0;
#else
  int			 fncs	= 1;
#endif
  int			 back	= 0;
  

#line 1026 "dk3uc2l.ctr"
  pdir = dk3uc2lat_dir_new(sn, app);
  if (NULL != pdir) {
    oldsrc = dk3app_get_source_file(app);
    oldln  = dk3app_get_source_line(app);
    dk3app_set_source_file(app, fn);
    dk3app_set_source_line(app, 0UL);
    if (0 != dk3sto_add(uptr->s_dir, pdir)) {
      fsuf = dk3str_get_suffix(fn);
      switch (dk3str_array_index(dk3uc2l_co_suf, fsuf, fncs)) {
        case 0: {	/* gz */
#if DK3_HAVE_ZLIB_H	&& (DK3_CHAR_SIZE == 1)
	  gzf = gzopen(fn, "r");
	  if (NULL != gzf) {
	    istrm = dk3stream_open_gz_app(gzf, DK3_STREAM_FLAG_READ, app);
	    if (NULL != istrm) {
	      back = dk3uc2l_apply_1(uptr, pdir, istrm, fn, sn, app);
	      (void)dk3stream_close(istrm);
	    }
	    gzclose(gzf);
	  } else {
	    /* ERROR: Failed to open file */
	    dk3app_log_i3(uptr->app, DK3_LL_ERROR, 143, 144, fn);
	  }
#else
	  /* ERROR: No zlib support */
	  dk3app_log_i1(uptr->app, DK3_LL_ERROR, 401);
#endif
	} break;
	case 1: {	/* bz2 */
#if DK3_HAVE_BZLIB_H	&& (DK3_CHAR_SIZE == 1)
	  bzf = BZ2_bzopen(fn, "r");
	  if (NULL != bzf) {
	    istrm = dk3stream_open_bz2_app(bzf, DK3_STREAM_FLAG_READ, app);
	    if (NULL != istrm) {
	      back = dk3uc2l_apply_1(uptr, pdir, istrm, fn, sn, app);
	      (void)dk3stream_close(istrm);
	    }
	    BZ2_bzclose(bzf);
	  } else {
	    /* ERROR: Failed to open file */
	    dk3app_log_i3(uptr->app, DK3_LL_ERROR, 143, 144, fn);
	  }
#else
	  /* ERROR: No bzip2 support */
	  dk3app_log_i1(uptr->app, DK3_LL_ERROR, 402);
#endif
	} break;
	default : {	/* normal file */
	  fipo = dk3sf_fopen_app(fn, dkT("r"), app);
	  if (NULL != fipo) {
	    istrm = dk3stream_open_file_app(fipo, DK3_STREAM_FLAG_READ, app);
	    if (NULL != istrm) {
	      back = dk3uc2l_apply_1(uptr, pdir, istrm, fn, sn, app);
	      (void)dk3stream_close(istrm);
	    }
	    fclose(fipo);
	  }
	} break;
      }
    } else {
      dk3uc2lat_dir_delete(pdir);
    }
    dk3app_set_source_file(app, oldsrc);
    dk3app_set_source_line(app, oldln);
  } 

#line 1091 "dk3uc2l.ctr"
  return back;
}



/**	Read directory information (check existing data files, retrieve ranges.
	@param	d	Directory containing the data files.
	@param	uptr	Conversion structure to initialize.
	@param	app	Application structure for diagnostics, may be NULL.
	@return	1 on success, 0 on error.
*/
static
int
dk3uc2lat_read_dir_info(dk3_uc2lat_t *uptr, dk3_app_t *app)
{
  dk3_dir_t	*dir	= NULL;
  const	dkChar	*fn	= NULL;
  const dkChar	*sn	= NULL;
  int		 back	= 0;
  int		 found	= 0;
  

#line 1112 "dk3uc2l.ctr"
  dir = dk3dir_open_app(uptr->dir, uptr->app);
  if (NULL != dir) {
    back = 1;
    while (0 != dk3dir_get_next_file(dir)) {
      sn = dk3dir_get_shortname(dir);
      fn = dk3dir_get_fullname(dir);
      if ((NULL != sn) && (NULL != fn)) {
        if (0 != dk3uc2lat_is_suitable_file(fn)) {
	  found = 1;
	  if (0 == dk3uc2lat_pass_1(uptr, fn, sn, app)) {
	    back = 0;
	  }
	}
      }
    }
    dk3dir_close(dir);
    if (0 == found) {
      back = 0;
      /* ERROR: No suitable files found */
      dk3app_log_i1(uptr->app, DK3_LL_ERROR, 403);
    }
  }
  

#line 1135 "dk3uc2l.ctr"
  return back;
}



/**	Allocate memory for all ranges details for a file directory.
	@param	uptr	Conversion structure to set up.
	@param	pdir	Directory information to set up.
	@return	1 on success, 0 on error.
*/
static
int
dk3uc2l_allocate_memory(
  dk3_uc2lat_t		*uptr,
  dk3_uc2lat_dir_t	*pdir
)
{
  dk3_uc2lat_range_t	*prange;
  size_t		 sz;
  size_t		 i;
  int			 back	= 1;
  int			 allenc	= 0;

  dk3sto_it_reset(pdir->i_ran);
  allenc = DK3_FONT_ENCODING_OT1
  	   + DK3_FONT_ENCODING_T1
	   + DK3_FONT_ENCODING_T4
	   + DK3_FONT_ENCODING_T5;
  do {
    prange = (dk3_uc2lat_range_t *)dk3sto_it_next(pdir->i_ran);
    if (NULL != prange) {
      sz = (size_t)(prange->end - prange->start) + 1;
      if (NULL == prange->a) {
        prange->a = dk3_new_app(DK3_PCCHAR,sz,uptr->app);
	if (NULL != prange->a) {
	  for (i = 0; i < sz; i++) { (prange->a)[i] = NULL; }
	} else {
	  back = 0;
	}
      }
      if (NULL == prange->t) {
        prange->t = dk3_new_app(DK3_PCCHAR,sz,uptr->app);
	if (NULL != prange->t) {
	  for (i = 0; i < sz; i++) { (prange->t)[i] = NULL; }
	} else {
	  back = 0;
	}
      }
      if (NULL == prange->m) {
        prange->m = dk3_new_app(DK3_PCCHAR,sz,uptr->app);
	if (NULL != prange->m) {
	  for (i = 0; i < sz; i++) { (prange->m)[i] = NULL; }
	} else {
	  back = 0;
	}
      }
#if HAVE_PACKAGES
      if (NULL == prange->p) {
        prange->p = dk3_new_app(dk3_uc2lat_pkg_pptr,sz,uptr->app);
	if (NULL != prange->p) {
	  for (i = 0; i < sz; i++) { (prange->p)[i] = NULL; }
	} else {
	  back = 0;
	}
      }
#endif
      if (NULL == prange->f) {
        prange->f = dk3_new_app(dk3_font_encoding_t,sz,uptr->app);
	if (NULL != prange->f) {
	  for(i = 0; i < sz; i++) { (prange->f)[i] = allenc; }
	} else {
	  back = 0;
	}
      }
    }
  } while (NULL != prange);
  return back;
}



static
void
dk3uc2l_apply_2(
  dk3_uc2lat_t		*uptr,
  dk3_uc2lat_dir_t	*pdir,
  dk3_stream_t		*istrm,
  const dkChar		*filename
)
{
  char			 buf[512];		/* Input line buffer */
#if HAVE_PACKAGES
  char			*parts[16];		/* Package names */
#endif
  char			*p1;			/* Hex value or next item */
  char			*p2;			/* Current item key */
  char			*p3;			/* Current item value */
  char			*p4;			/* Dynamic value copy */
  dk3_uc2lat_range_t	*prange;		/* Current range */
#if HAVE_PACKAGES
  dk3_uc2lat_pkg_t	*ppkg;			/* Current package */
#endif
  unsigned long		 lineno = 0UL;		/* Current line number */
  unsigned long		 chr;			/* Current character */
  size_t		 ind;			/* Index of chr in range */
#if HAVE_PACKAGES
  size_t		 nparts;		/* Number of packages */
  size_t		 i;			/* Traverse */
  size_t		 j;			/* Add new packages */
#endif
  int			 cc	= 1;		/* Flag: Can continue */
  int			 action;		/* Action to take */
  int			 isneg;			/* Flag: Deny encodings */
  int			 encod;			/* Encodings selection */
  

#line 1250 "dk3uc2l.ctr"
  while ((1 == cc) && (1 == dk3stream_c8_fgets(istrm, buf, sizeof(buf)))) {
    dk3app_set_source_line(uptr->app, ++lineno);
    buf[sizeof(buf) - 1] = '\0';
    

#line 1254 "dk3uc2l.ctr"
    p1 = dk3str_c8_start(buf, NULL);
    if (NULL != p1) {				

#line 1256 "dk3uc2l.ctr"
      if ('#' != *p1) {				

#line 1257 "dk3uc2l.ctr"
        p2 = dk3str_c8_next(p1, NULL);
	if (NULL != p2) {			

#line 1259 "dk3uc2l.ctr"
	  if (0 != dk3ma_ul_from_c8_hex_string(&chr, p1, NULL)) {
	    prange =
	    (dk3_uc2lat_range_t *)dk3sto_it_find_like(pdir->i_ran, &chr, 1);
	    if (NULL != prange) {		

#line 1263 "dk3uc2l.ctr"
	      ind = (size_t)(chr - prange->start);
	      while (NULL != p2) {
	        p1 = dk3str_c8_next(p2, NULL);
		p3 = dk3str_c8_chr(p2, '=');
		if (NULL != p3) {
		  *(p3++) = '\0';
#if 0
		  /* 2015-08-10 Bugfix: Must be start */
		  p3 = dk3str_c8_next(p3, NULL);
#endif
		  p3 = dk3str_c8_start(p3, NULL);
		  if (NULL != p3) {	

#line 1275 "dk3uc2l.ctr"
		    action = dk3str_c8_array_abbr(dk3uc2l_kw, p2, '$', 0);
		    

#line 1277 "dk3uc2l.ctr"
		    switch (action) {
		      case 0: {	/* both */		

#line 1279 "dk3uc2l.ctr"
		        if (NULL != prange->a) {
			  p4 = dk3str_c8_dup_app(p3, uptr->app);
			  if (NULL != p4) {
			    dk3_release((prange->a)[ind]);
			    (prange->a)[ind] = p4;
			  }
			}
		      } break;
		      case 1: {	/* text */		

#line 1288 "dk3uc2l.ctr"
		        if (NULL != prange->t) {
			  p4 = dk3str_c8_dup_app(p3, uptr->app);
			  if (NULL != p4) {
			    dk3_release((prange->t)[ind]);
			    (prange->t)[ind] = p4;
			  }
			}
		      } break;
		      case 2: {	/* math */		

#line 1297 "dk3uc2l.ctr"
		        if (NULL != prange->m) {
			  p4 = dk3str_c8_dup_app(p3, uptr->app);
			  if (NULL != p4) {
			    dk3_release((prange->m)[ind]);
			    (prange->m)[ind] = p4;
			  }
			}
		      } break;
		      case 3: {	/* encoding */		

#line 1306 "dk3uc2l.ctr"
		        if (NULL != prange->f) {
			  isneg = 0; encod = 0;
			  if ('!' == *p3) {
			    isneg = 1; p3++;
			  }
			  while (NULL != p3) {
			    p4 = dk3str_c8_chr(p3, ',');
			    if (NULL != p4) {
			      *(p4++) = '\0';
			      p4 = dk3str_c8_start(p4, NULL);
			    }
			    switch (dk3str_c8_array_index(dk3uc2l_enco, p3, 0))
			    {
			      case 0: {	/* OT1 */
			        encod |= DK3_FONT_ENCODING_OT1;
			      } break;
			      case 1: {	/* T1 */
			        encod |= DK3_FONT_ENCODING_T1;
			      } break;
			      case 2: {	/* T4 */
			        encod |= DK3_FONT_ENCODING_T4;
			      } break;
			      case 3: {	/* T5 */
			        encod |= DK3_FONT_ENCODING_T5;
			      } break;
			      default : {
			        /* Syntax error, unknown encoding */
				dk3app_log_i1(uptr->app, DK3_LL_DEBUG, 404);
			      } break;
			    }
			    p3 = p4;
			  }
			  if (0 != isneg) { encod = (~(encod)); }
			  (prange->f)[ind] = encod;
			}
		      } break;
		      case 4: {	/* packages */		

#line 1343 "dk3uc2l.ctr"
#if HAVE_PACKAGES
		        if (NULL != prange->p) {
			  nparts = dk3str_c8_explode(parts, 15, p3, ",");
			  if (0 < nparts) {
			    dk3_release((prange->p)[ind]);
			    (prange->p)[ind] =
			    dk3_new_app(dk3_uc2lat_pkg_ptr,(nparts+1),uptr->app);
			    if (NULL != (prange->p)[ind]) {
			      for (i = 0; i < (nparts+1); i++) {
			        ((prange->p)[ind])[i] = NULL;
			      }
			      j = 0;
			      for (i = 0; i < nparts; i++) {
			        ppkg = (dk3_uc2lat_pkg_t *)dk3sto_it_find_like(
				  uptr->i_pkg, parts[i], 1
				);
				if (NULL != ppkg) {
				  ((prange->p)[ind])[j++] = ppkg;
				} else {
				  ppkg = dk3uc2lat_pkg_new(parts[i], uptr->app);
				  if (NULL != ppkg) {
				    if (dk3sto_add(uptr->s_pkg, ppkg)) {
				      ((prange->p)[ind])[j++] = ppkg;
				    } else {
				      dk3uc2lat_pkg_delete(ppkg);
				    }
				  }
				}
			      }
			    }
			  } else {
			    /* ERROR: Syntax, no packages */
			    dk3app_log_i1(uptr->app, DK3_LL_DEBUG, 405);
			  }
			}
#endif
		      } break;
		      default: {		

#line 1381 "dk3uc2l.ctr"
		      } break;
		    }
		  } else {			

#line 1384 "dk3uc2l.ctr"
		    /* ERROR: Value missing */
		    dk3app_log_i1(uptr->app, DK3_LL_DEBUG, 406);
		  }
		} else {			

#line 1388 "dk3uc2l.ctr"
		  /* ERROR: Syntax, not a key value pair */
		  dk3app_log_i1(uptr->app, DK3_LL_DEBUG, 406);
		}
		p2 = p1;
	      }
	    } else {				

#line 1394 "dk3uc2l.ctr"
	      /* BUG or file changed */
	    }
	  } else {
	    /* ERROR: Syntax error, not a hexadecimal number */
	    dk3app_log_i1(uptr->app, DK3_LL_ERROR, 398);
	  }
	} else {				

#line 1401 "dk3uc2l.ctr"
	  /* ERROR: Syntax error, missing configuration */
	  dk3app_log_i1(uptr->app, DK3_LL_ERROR, 401);
	}
      } else {					

#line 1405 "dk3uc2l.ctr"
      }
    } else {					

#line 1407 "dk3uc2l.ctr"
    }
  } 

#line 1409 "dk3uc2l.ctr"
}



static
void
dk3uc2lat_load_file(dk3_uc2lat_t *u, dk3_uc2lat_dir_t *pdir)
{
  dkChar		 fnb[DK3_MAX_PATH];
  dk3_stream_t		*istrm	= NULL;
  FILE			*fipo	= NULL;
  const dkChar		*oldsrc	= NULL;
  const dkChar		*fsuf	= NULL;
#if DK3_HAVE_ZLIB_H	&& (DK3_CHAR_SIZE == 1)
  gzFile		 gzf	= NULL;
#endif
#if DK3_HAVE_BZLIB_H	&& (DK3_CHAR_SIZE == 1)
  BZFILE		*bzf	= NULL;
#endif
  unsigned long		 oldln	= 0UL;
#if DK3_HAVE_FNCASEINS
  int			 fncs	= 0;
#else
  int			 fncs	= 1;
#endif
  size_t		 sz;
  

#line 1436 "dk3uc2l.ctr"
  sz =  dk3str_len(u->dir);
  sz += dk3str_len(pdir->sn);
  sz += 1;
  if (sizeof(fnb) > sz) {			

#line 1440 "dk3uc2l.ctr"
    dk3str_cpy(fnb, u->dir);
    dk3str_cat(fnb, dk3app_not_localized(20));
    dk3str_cat(fnb, pdir->sn);
    dk3str_correct_filename(fnb);
    oldsrc = dk3app_get_source_file(u->app);
    oldln  = dk3app_get_source_line(u->app);
    dk3app_set_source_file(u->app, fnb);
    dk3app_set_source_line(u->app, 0UL);
    if (0 != dk3uc2l_allocate_memory(u, pdir)) {	

#line 1449 "dk3uc2l.ctr"
      fsuf = dk3str_get_suffix(fnb);
      switch (dk3str_array_index(dk3uc2l_co_suf, fsuf, fncs)) {
        case 0: {				

#line 1452 "dk3uc2l.ctr"
#if DK3_HAVE_ZLIB_H	&& (DK3_CHAR_SIZE == 1)
	  gzf = gzopen(fnb, "r");
	  if (NULL != gzf) {
	    istrm = dk3stream_open_gz_app(gzf, DK3_STREAM_FLAG_READ, u->app);
	    if (NULL != istrm) {
	      dk3uc2l_apply_2(u, pdir, istrm, fnb);
	      (void)dk3stream_close(istrm);
	    }
	    gzclose(gzf);
	  } else {
	    /* ERROR: Failed to open file */
	    dk3app_log_i3(u->app, DK3_LL_ERROR, 143, 144, fnb);
	  }
#else
	/* ERROR: No zlib support */
	dk3app_log_i1(u->app, DK3_LL_ERROR, 401);
#endif
        } break;
        case 1: {				

#line 1471 "dk3uc2l.ctr"
#if DK3_HAVE_BZLIB_H	&& (DK3_CHAR_SIZE == 1)
	  bzf = BZ2_bzopen(fnb, "r");
	  if (NULL != bzf) {
	    istrm = dk3stream_open_bz2_app(bzf, DK3_STREAM_FLAG_READ, u->app);
	    if (NULL != istrm) {
	      dk3uc2l_apply_2(u, pdir, istrm, fnb);
	      (void)dk3stream_close(istrm);
	    }
	    BZ2_bzclose(bzf);
	  } else {
	    /* ERROR: Failed to open file */
	    dk3app_log_i3(u->app, DK3_LL_ERROR, 143, 144, fnb);
	  }
#else
	/* ERROR: No bzip2 support */
	dk3app_log_i1(u->app, DK3_LL_ERROR, 402);
#endif
        } break;
        default: {				

#line 1490 "dk3uc2l.ctr"
	  fipo = dk3sf_fopen_app(fnb, dkT("r"), u->app);
	  if (NULL != fipo) {
	    istrm = dk3stream_open_file_app(fipo, DK3_STREAM_FLAG_READ, u->app);
	    if (NULL != istrm) {
	      dk3uc2l_apply_2(u, pdir, istrm, fnb);
	      (void)dk3stream_close(istrm);
	    }
	    fclose(fipo);
	  }
        } break;
      }
    } else {				

#line 1502 "dk3uc2l.ctr"
    }
    dk3app_set_source_file(u->app, oldsrc);
    dk3app_set_source_line(u->app, oldln);
  } else {				

#line 1506 "dk3uc2l.ctr"
    /* ERROR: Name too long */
    dk3app_log_i3(u->app, DK3_LL_ERROR, 65, 66, pdir->sn);
  }
  pdir->loaded = 0x01;
  

#line 1511 "dk3uc2l.ctr"
}



/**	Open conversion structure for a given directory.
	@param	d	Directory containing conversion files.
	@param	f_desc	Flag: Load glyph descriptions (ignored).
	@param	f_utf8	Flag: UTF-8 output allowed.
	@param	app	Application structure for diagnostics, may be NULL.
	@return	Pointer to new structure on success, NULL on error.
*/
static
dk3_uc2lat_t *
dk3uc2lat_i_open_app(const dkChar *d, int f_desc, int f_utf8, dk3_app_t *app)
{
  dk3_uc2lat_t		*back	= NULL;
  

#line 1528 "dk3uc2l.ctr"
  if (0 != dk3sf_is_dir_app(d, NULL)) {
    back = dk3uc2lat_t_new(d, f_utf8, app);
    if (NULL != back) {
      if (0 == dk3uc2lat_read_dir_info(back, app)) {
        dk3uc2lat_close(back);
	back = NULL;
      }
    }
  } else {
    /* ERROR: Not a directory ... */
    dk3app_log_i3(app, DK3_LL_ERROR, 202, 203, d);
  }
  

#line 1541 "dk3uc2l.ctr"
  return back;
}



dk3_uc2lat_t *
dk3uc2lat_open_app(dkChar const *d, int f_desc, int f_utf8, dk3_app_t *app)
{
  dkChar		 fnb[DK3_MAX_PATH];
  dk3_uc2lat_t		*back	= NULL;
  const dkChar		*shd	= NULL;
  const dkChar		*dirn	= NULL;
  size_t		 szfnb	= DK3_SIZEOF(fnb,dkChar);
  size_t		 szshd	= 0;
  

#line 1556 "dk3uc2l.ctr"
  if (NULL != d) {
    back = dk3uc2lat_i_open_app(d, f_desc, f_utf8, app);
  } else {
    if (NULL != app) {
      if (dk3app_get_dir_from_pref(app,dk3app_not_localized(48),fnb,szfnb,1))
      {
        dk3str_correct_filename(fnb);
        back = dk3uc2lat_i_open_app(fnb, f_desc, f_utf8, app);
      } else
      {
        shd = dk3app_get_sharedir(app);
	if (NULL != shd) {
	  szshd = dk3str_len(shd);
	  if (szfnb > szshd) {
	    dk3str_cpy_not_overlapped(fnb, shd);
	    dirn = dk3app_not_localized(49);
	    if (szfnb > (szshd + dk3str_len(dirn))) {
	      dk3str_cat(fnb, dirn);
	      dk3str_correct_filename(fnb);
	      back = dk3uc2lat_i_open_app(fnb, f_desc, f_utf8, app);
	    } else {
	      /* ERROR: Directory name too long! */
	      dk3app_log_i3(app, DK3_LL_ERROR, 64, 66, dirn);
	    }
	  } else {
	    /* ERROR: Share directory name too long! */
	    dk3app_log_i3(app, DK3_LL_ERROR, 64, 66, shd);
	  }
	} else {
	  /* ERROR: Missing share directory */
	  dk3app_log_i1(app, DK3_LL_ERROR, 407);
	}
      }
    }
  } 

#line 1591 "dk3uc2l.ctr"
  return back;
}



char const *
dk3uc2lat_get(dk3_uc2lat_t *u, dk3_c32_t c32, int ismath)
{
  dkChar		 cbuf[64];
  dk3_uc2lat_range_t	*prange	= NULL;
  dk3_uc2lat_pkg_t	**pkgpp;
  const char		*back	= NULL;
  size_t		 szcbuf = DK3_SIZEOF(cbuf,dkChar);
  

#line 1605 "dk3uc2l.ctr"
  if (NULL != u) {
    if (NULL != u->rca) {			

#line 1607 "dk3uc2l.ctr"
      if ((u->rca)->start <= c32) {		

#line 1608 "dk3uc2l.ctr"
        if ((u->rca)->end >= c32) {		

#line 1609 "dk3uc2l.ctr"
	  prange = u->rca;			

#line 1610 "dk3uc2l.ctr"
	}
      }
    }
    if (NULL == prange) {			

#line 1614 "dk3uc2l.ctr"
      prange = dk3sto_it_find_like(u->i_ran, &c32, 1);
      if (NULL != prange) {			

#line 1616 "dk3uc2l.ctr"
        u->rca = prange;
	if (NULL != prange->p) {		

#line 1618 "dk3uc2l.ctr"
	  pkgpp = (prange->p)[(size_t)(c32 - prange->start)];
	  if (NULL != pkgpp) {
	    while (NULL != *pkgpp) {
	      (*(pkgpp++))->used = 0x01;
	    }					

#line 1623 "dk3uc2l.ctr"
	  }
	}
      } else {					

#line 1626 "dk3uc2l.ctr"
      }
    }
    if (NULL != prange) {			

#line 1629 "dk3uc2l.ctr"
      if (NULL != prange->dir) {		

#line 1630 "dk3uc2l.ctr"
        if (0x00 == (prange->dir)->loaded) {	

#line 1631 "dk3uc2l.ctr"
	  dk3uc2lat_load_file(u, prange->dir);
	}
      }
      if (0 != ismath) {			

#line 1635 "dk3uc2l.ctr"
        if (NULL != prange->m) {		

#line 1636 "dk3uc2l.ctr"
	  back = (prange->m)[(size_t)(c32 - prange->start)];
	}
	if (NULL == back) {
	  if (NULL != prange->a) {		

#line 1640 "dk3uc2l.ctr"
	    back = (prange->a)[(size_t)(c32 - prange->start)];
	  }
	}
      } else {					

#line 1644 "dk3uc2l.ctr"
        if (NULL != prange->t) {		

#line 1645 "dk3uc2l.ctr"
	  back = (prange->t)[(size_t)(c32 - prange->start)];
	}
	if (NULL == back) {			

#line 1648 "dk3uc2l.ctr"
	  if (NULL != prange->a) {
	    back = (prange->a)[(size_t)(c32 - prange->start)];
	  }
	}
      }
      if (NULL != prange->f) {
        u->fe &= ((prange->f)[(size_t)(c32 - prange->start)]);
      }
    } else {
      /* ERROR: Not found */
      if (0 != dk3ma_um_to_hex_string(cbuf, szcbuf, (dk3_um_t)c32, 8)) {
        dk3app_log_i3(u->app, DK3_LL_ERROR, 409, 410, cbuf);
      } else {
        dk3app_log_i1(u->app, DK3_LL_ERROR, 408);
      }
    }
  } 

#line 1665 "dk3uc2l.ctr"
  return back;
}
 


#if HAVE_PACKAGES

void
dk3uc2lat_package_reset(dk3_uc2lat_t *u)
{
  if (NULL != u) {
    dk3sto_it_reset(u->i_pkg);
  }
}



dk3_uc2lat_pkg_t *
dk3uc2lat_package_next(dk3_uc2lat_t *u)
{
  dk3_uc2lat_pkg_t	*back	= NULL;
  if (NULL != u) {
    back = (dk3_uc2lat_pkg_t *)dk3sto_it_next(u->i_pkg);
  }
  return back;
}

#endif



void
dk3uc2lat_font_encoding_reset(dk3_uc2lat_t *u)
{
  /* UNUSED */
}



int
dk3uc2lat_font_encoding_conflict(dk3_uc2lat_t *u)
{
  int		 back	= 0;
  /* UNUSED */
  return back;
}



void
dk3uc2lat_font_encoding_report_conflict(dk3_uc2lat_t *u)
{
  if (0x00 == u->fe) {
    /* Error */
    dk3app_log_i1(u->app, DK3_LL_ERROR, 411);
  }
}



static
void
dk3uc2lat_report_for_encoding(dk3_uc2lat_t *u, const char *eptr)
{
#if DK3_CHAR_SIZE > 1
  dkChar	 buffer[32];
  dkChar	*dkptr		=	NULL;
  size_t	 szbu		=	DK3_SIZEOF(buffer,dkChar);
  if (szbu > strlen(eptr)) {
    dkptr = buffer;
    while ('\0' != *eptr) {
      *(dkptr++) = (dkChar)(*(eptr++));
    }
    *dkptr = dkT('\0');
    dk3app_log_i3(u->app, DK3_LL_INFO, 381, 382, buffer);
  }
#else
  dk3app_log_i3(u->app, DK3_LL_INFO, 381, 382, eptr);
#endif
}



void
dk3uc2lat_font_encoding_report(dk3_uc2lat_t *u)
{
  if (0 != ((u->fe) & DK3_FONT_ENCODING_OT1)) {
    dk3uc2lat_report_for_encoding(u,  dk3uc2l_enco[0]);
  }
  if (0 != ((u->fe) & DK3_FONT_ENCODING_T1)) {
    dk3uc2lat_report_for_encoding(u,  dk3uc2l_enco[1]);
  }
  if (0 != ((u->fe) & DK3_FONT_ENCODING_T4)) {
    dk3uc2lat_report_for_encoding(u,  dk3uc2l_enco[2]);
  }
  if (0 != ((u->fe) & DK3_FONT_ENCODING_T5)) {
    dk3uc2lat_report_for_encoding(u,  dk3uc2l_enco[3]);
  }
}



int
dk3uc2lat_direct(dk3_c32_t c32)
{
  int back = 0;
  char c;	/* 8-bit character version of c32. */
  

#line 1773 "dk3uc2l.ctr"
  if((unsigned long)c32 < 128UL) {
    c = (char)c32;
    switch(c) {
      case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'g':
      case 'h': case 'i': case 'j': case 'k': case 'l': case 'm': case 'n':
      case 'o': case 'p': case 'q': case 'r': case 's': case 't': case 'u':
      case 'v': case 'w': case 'x': case 'y': case 'z': case 'A': case 'B':
      case 'C': case 'D': case 'E': case 'F': case 'G': case 'H': case 'I':
      case 'J': case 'K': case 'L': case 'M': case 'N': case 'O': case 'P':
      case 'Q': case 'R': case 'S': case 'T': case 'U': case 'V': case 'W':
      case 'X': case 'Y': case 'Z': case '0': case '1': case '2': case '3':
      case '4': case '5': case '6': case '7': case '8': case '9': case ',':
      case '.': case ':': case ';': case '+': case '-': case '?': case '!':
      case '|': case '@': case '(': case ')': case '/': case '=': case ' ':
      case '\t':
      {
        back = 1;
      }
      break;
    }
  } 

#line 1794 "dk3uc2l.ctr"
  return back;
}



static
int
dk3uc2lat_stputc(dk3_uc2lat_t *u, dk3_stream_t *st, dk3_c32_t ul, int *mmptr)
{
  char		 buf[16];
  const char	*ptr;
  size_t	 sz;
  int		 back	= 0;
  
  if (0 != dk3uc2lat_direct(ul)) {
    if (0 != *mmptr) {
      dk3stream_c8_fputs(st, dk3uc2lat_mm[1]);
      *mmptr = 0;
    }
    if (u->f_utf8) {
      sz = dk3enc_uc2utf8(ul, (unsigned char *)buf, sizeof(buf));
      buf[sz] = '\0';
    } else {
      buf[0] = (char)ul;
      buf[1] = '\0';
    }
    dk3stream_c8_fputs(st, buf);
    back = 1;
  } else {
    ptr = dk3uc2lat_get(u, ul, 0);
    if (NULL != ptr) {
      if (0 != *mmptr) {
        dk3stream_c8_fputs(st, dk3uc2lat_mm[1]);
	*mmptr = 0;
      }
      dk3stream_c8_fputs(st, ptr);
    } else {
      ptr = dk3uc2lat_get(u, ul, 1);
      if (NULL != ptr) {
        if (0 == *mmptr) {
	  dk3stream_c8_fputs(st, dk3uc2lat_mm[0]);
	  *mmptr = 1;
	}
	dk3stream_c8_fputs(st, ptr);
      } else {
        /* ERROR: Not found, already reported */
      }
    }
  }
  return back;
}



int
dk3uc2lat_c8_plain_stputs(dk3_uc2lat_t *u, dk3_stream_t *st, char const *t)
{
  int 		back = 0;
  int		mm = 0;		/* Flag: In math mode. */
  char const	*ptr;		/* Current position. */
  dk3_c32_t	ul;		/* Output character. */
  char		c;		/* Current character. */
  

#line 1857 "dk3uc2l.ctr"
  if((u) && (st) && (t)) {
    ptr = t; back = 1;
    while(*ptr) {
      c = *ptr;
      ul = (unsigned long)c;
      ul &= 0x000000FFUL;
      if(!dk3uc2lat_stputc(u, st, ul, &mm)) { back = 0; }
      ptr++;
    }
    if(mm) {
      dk3stream_c8_fputs(st, dk3uc2lat_mm[1]);
    }
  }
  

#line 1871 "dk3uc2l.ctr"
  return back;
}



int
dk3uc2lat_c8_utf8_stputs(dk3_uc2lat_t *u, dk3_stream_t *st, char const *t)
{
  int				back = 0;
  int				mm = 0;	/* Flag: Math mode. */
  unsigned char const		*sp;	/* String pointer, current pos. */
  size_t			sl;	/* Remaining bytes. */
  size_t			used;	/* Bytes used for current c32. */
  dk3_c32_t			c32;	/* Current character. */
  

#line 1886 "dk3uc2l.ctr"
  if((u) && (st) && (t)) {
    sp = (unsigned char const *)t; sl = dk3str_c8_len(t); back = 1;
    while(sl) {
      used = 0;
      if(dk3enc_utf82uc(&c32, sp, sl, &used)) {
        if(!dk3uc2lat_stputc(u, st, c32, &mm)) {
	  back = 0;
	}
        if(used) {
	  if(sl >= used) {
	    sl = sl - used;
	    sp = &(sp[used]);
	  } else {
	    sl = 0; back = 0;
	  }
	} else {
	  sl = 0; back = 0; /* No byte used, will appear again and again. */
	}
      } else {
        sl = 0; back = 0;
	if(u->app) {
	  /* ERROR: Decoding failed! */
	  dk3app_log_i1(u->app, DK3_LL_ERROR, 118);
	}
      }
    }
    if(mm) {
      dk3stream_c8_fputs(st, dk3uc2lat_mm[1]);
    }
  }
  

#line 1917 "dk3uc2l.ctr"
  return back;
}



int
dk3uc2lat_c16_stputs(dk3_uc2lat_t *u, dk3_stream_t *st, dk3_c16_t const *t)
{
  int 			back = 0;
  int			mm = 0;	/* Flag: Math mode. */
  dk3_c16_t const	*sp;	/* Current position. */
  size_t		sl;	/* Number of 16-bit characters remaining. */
  size_t		used;	/* Number of 16-bit characters used. */
  dk3_c32_t		c32;	/* Current output character. */
  

#line 1932 "dk3uc2l.ctr"
  if((u) && (st) && (t)) {
    sp = t; sl = dk3str_c16_len(t); back = 1;
    while(sl) {
      used = 0;
      if(dk3enc_utf162uc(&c32, sp, sl, &used)) {
        if(used) {
	  if(!dk3uc2lat_stputc(u, st, c32, &mm)) { back = 0; }
	  if(sl >= used) {
	    sl = sl - used;
	    sp = &(sp[used]);
	  } else {
	    sl = 0;
	  }
	} else {
	  back = 0; sl = 0;
	  if(u->app) {
	    /* ERROR: Decoding */
	    dk3app_log_i1(u->app, DK3_LL_ERROR, 119);
	  }
	}
      } else {
        sl = 0; back = 0;
	if(u->app) {
	  /* Decoding error */
	  dk3app_log_i1(u->app, DK3_LL_ERROR, 119);
	}
      }
    }
    if(mm) {
      dk3stream_c8_fputs(st, dk3uc2lat_mm[1]);
    }
  }
  

#line 1965 "dk3uc2l.ctr"
  return back;
}



int
dk3uc2lat_c32_stputs(dk3_uc2lat_t *u, dk3_stream_t *st, dk3_c32_t const *t)
{
  int			back = 0;
  int			mm = 0;	/* Flag: Math mode. */
  dk3_c32_t const	*ptr;	/* Current position. */
  

#line 1977 "dk3uc2l.ctr"
  if((u) && (st) && (t)) {
    back = 1;
    ptr = t;
    while(*ptr) {
      if(!dk3uc2lat_stputc(u, st, *(ptr++), &mm)) {
        back = 0;
      }
    }
    if(mm) {
      dk3stream_c8_fputs(st, dk3uc2lat_mm[1]);
    }
  }
  

#line 1990 "dk3uc2l.ctr"
  return back;
}



int
dk3uc2lat_stputs(dk3_uc2lat_t *u, dk3_stream_t *st, dkChar const *t, int e)
{
  int back = 0;
  

#line 2000 "dk3uc2l.ctr"
#if DK3_CHAR_SIZE > 1
#if DK3_CHAR_SIZE > 2
  back = dk3uc2lat_c32_stputs(u, st, t);
#else
  back = dk3uc2lat_c16_stputs(u, st, t);
#endif
#else
  switch(e) {
    case DK3_ENCODING_UTF8: {
      back = dk3uc2lat_c8_utf8_stputs(u, st, t);
    } break;
    default: {
      back = dk3uc2lat_c8_plain_stputs(u, st, t);
    } break;
  }
#endif
  

#line 2017 "dk3uc2l.ctr"
  return back;
}



void
dk3uc2lat_final_report(dk3_uc2lat_t *u, dk3_stream_t *st)
{
  dk3_uc2lat_pkg_t	*pkgp;
  dk3stream_c8_fputs(st, dk3uc2lat_mm[2]);
  if (0 != ((u->fe) & DK3_FONT_ENCODING_OT1)) {
    dk3stream_c8_fputs(st, dk3uc2l_c8_font_encoding_names[0]);
  }
  if (0 != ((u->fe) & DK3_FONT_ENCODING_T1)) {
    dk3stream_c8_fputs(st, dk3uc2l_c8_font_encoding_names[1]);
  }
  if (0 != ((u->fe) & DK3_FONT_ENCODING_T4)) {
    dk3stream_c8_fputs(st, dk3uc2l_c8_font_encoding_names[2]);
  }
  if (0 != ((u->fe) & DK3_FONT_ENCODING_T5)) {
    dk3stream_c8_fputs(st, dk3uc2l_c8_font_encoding_names[3]);
  }
  dk3stream_c8_fputs(st, dk3uc2lat_mm[4]);
  dk3uc2lat_package_reset(u);
  do {
    pkgp = dk3uc2lat_package_next(u);
    if (NULL != pkgp) {
      

#line 2045 "dk3uc2l.ctr"
      

#line 2046 "dk3uc2l.ctr"
			

#line 2047 "dk3uc2l.ctr"
      

#line 2048 "dk3uc2l.ctr"
			

#line 2049 "dk3uc2l.ctr"
      

#line 2050 "dk3uc2l.ctr"
      

#line 2051 "dk3uc2l.ctr"
      if ((0x00 != pkgp->used) && (NULL != pkgp->name)) {
        dk3stream_c8_fputs(st, dk3uc2lat_mm[3]);
	dk3stream_c8_fputs(st, pkgp->name);
	dk3stream_c8_fputs(st, dk3uc2lat_mm[4]);
      }
    }
  } while (NULL != pkgp);
}



/* vim: set ai sw=2 : */