summaryrefslogtreecommitdiff
path: root/support/TeX4ht/source/tex4ht-c.tex
blob: 04a01166806e7851b3d366b1d3a00198503013ce (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
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
4781
4782
4783
4784
4785
4786
4787
4788
4789
4790
4791
4792
4793
4794
4795
4796
4797
4798
4799
4800
4801
4802
4803
4804
4805
4806
4807
4808
4809
4810
4811
4812
4813
4814
4815
4816
4817
4818
4819
4820
4821
4822
4823
4824
4825
4826
4827
4828
4829
4830
4831
4832
4833
4834
4835
4836
4837
4838
4839
4840
4841
4842
4843
4844
4845
4846
4847
4848
4849
4850
4851
4852
4853
4854
4855
4856
4857
4858
4859
4860
4861
4862
4863
4864
4865
4866
4867
4868
4869
4870
4871
4872
4873
4874
4875
4876
4877
4878
4879
4880
4881
4882
4883
4884
4885
4886
4887
4888
4889
4890
4891
4892
4893
4894
4895
4896
4897
4898
4899
4900
4901
4902
4903
4904
4905
4906
4907
4908
4909
4910
4911
4912
4913
4914
4915
4916
4917
4918
4919
4920
4921
4922
4923
4924
4925
4926
4927
4928
4929
4930
4931
4932
4933
4934
4935
4936
4937
4938
4939
4940
4941
4942
4943
4944
4945
4946
4947
4948
4949
4950
4951
4952
4953
4954
4955
4956
4957
4958
4959
4960
4961
4962
4963
4964
4965
4966
4967
4968
4969
4970
4971
4972
4973
4974
4975
4976
4977
4978
4979
4980
4981
4982
4983
4984
4985
4986
4987
4988
4989
4990
4991
4992
4993
4994
4995
4996
4997
4998
4999
5000
5001
5002
5003
5004
5005
5006
5007
5008
5009
5010
5011
5012
5013
5014
5015
5016
5017
5018
5019
5020
5021
5022
5023
5024
5025
5026
5027
5028
5029
5030
5031
5032
5033
5034
5035
5036
5037
5038
5039
5040
5041
5042
5043
5044
5045
5046
5047
5048
5049
5050
5051
5052
5053
5054
5055
5056
5057
5058
5059
5060
5061
5062
5063
5064
5065
5066
5067
5068
5069
5070
5071
5072
5073
5074
5075
5076
5077
5078
5079
5080
5081
5082
5083
5084
5085
5086
5087
5088
5089
5090
5091
5092
5093
5094
5095
5096
5097
5098
5099
5100
5101
5102
5103
5104
5105
5106
5107
5108
5109
5110
5111
5112
5113
5114
5115
5116
5117
5118
5119
5120
5121
5122
5123
5124
5125
5126
5127
5128
5129
5130
5131
5132
5133
5134
5135
5136
5137
5138
5139
5140
5141
5142
5143
5144
5145
5146
5147
5148
5149
5150
5151
5152
5153
5154
5155
5156
5157
5158
5159
5160
5161
5162
5163
5164
5165
5166
5167
5168
5169
5170
5171
5172
5173
5174
5175
5176
5177
5178
5179
5180
5181
5182
5183
5184
5185
5186
5187
5188
5189
5190
5191
5192
5193
5194
5195
5196
5197
5198
5199
5200
5201
5202
5203
5204
5205
5206
5207
5208
5209
5210
5211
5212
5213
5214
5215
5216
5217
5218
5219
5220
5221
5222
5223
5224
5225
5226
5227
5228
5229
5230
5231
5232
5233
5234
5235
5236
5237
5238
5239
5240
5241
5242
5243
5244
5245
5246
5247
5248
5249
5250
5251
5252
5253
5254
5255
5256
5257
5258
5259
5260
5261
5262
5263
5264
5265
5266
5267
5268
5269
5270
5271
5272
5273
5274
5275
5276
5277
5278
5279
5280
5281
5282
5283
5284
5285
5286
5287
5288
5289
5290
5291
5292
5293
5294
5295
5296
5297
5298
5299
5300
5301
5302
5303
5304
5305
5306
5307
5308
5309
5310
5311
5312
5313
5314
5315
5316
5317
5318
5319
5320
5321
5322
5323
5324
5325
5326
5327
5328
5329
5330
5331
5332
5333
5334
5335
5336
5337
5338
5339
5340
5341
5342
5343
5344
5345
5346
5347
5348
5349
5350
5351
5352
5353
5354
5355
5356
5357
5358
5359
5360
5361
5362
5363
5364
5365
5366
5367
5368
5369
5370
5371
5372
5373
5374
5375
5376
5377
5378
5379
5380
5381
5382
5383
5384
5385
5386
5387
5388
5389
5390
5391
5392
5393
5394
5395
5396
5397
5398
5399
5400
5401
5402
5403
5404
5405
5406
5407
5408
5409
5410
5411
5412
5413
5414
5415
5416
5417
5418
5419
5420
5421
5422
5423
5424
5425
5426
5427
5428
5429
5430
5431
5432
5433
5434
5435
5436
5437
5438
5439
5440
5441
5442
5443
5444
5445
5446
5447
5448
5449
5450
5451
5452
5453
5454
5455
5456
5457
5458
5459
5460
5461
5462
5463
5464
5465
5466
5467
5468
5469
5470
5471
5472
5473
5474
5475
5476
5477
5478
5479
5480
5481
5482
5483
5484
5485
5486
5487
5488
5489
5490
5491
5492
5493
5494
5495
5496
5497
5498
5499
5500
5501
5502
5503
5504
5505
5506
5507
5508
5509
5510
5511
5512
5513
5514
5515
5516
5517
5518
5519
5520
5521
5522
5523
5524
5525
5526
5527
5528
5529
5530
5531
5532
5533
5534
5535
5536
5537
5538
5539
5540
5541
5542
5543
5544
5545
5546
5547
5548
5549
5550
5551
5552
5553
5554
5555
5556
5557
5558
5559
5560
5561
5562
5563
5564
5565
5566
5567
5568
5569
5570
5571
5572
5573
5574
5575
5576
5577
5578
5579
5580
5581
5582
5583
5584
5585
5586
5587
5588
5589
5590
5591
5592
5593
5594
5595
5596
5597
5598
5599
5600
5601
5602
5603
5604
5605
5606
5607
5608
5609
5610
5611
5612
5613
5614
5615
5616
5617
5618
5619
5620
5621
5622
5623
5624
5625
5626
5627
5628
5629
5630
5631
5632
5633
5634
5635
5636
5637
5638
5639
5640
5641
5642
5643
5644
5645
5646
5647
5648
5649
5650
5651
5652
5653
5654
5655
5656
5657
5658
5659
5660
5661
5662
5663
5664
5665
5666
5667
5668
5669
5670
5671
5672
5673
5674
5675
5676
5677
5678
5679
5680
5681
5682
5683
5684
5685
5686
5687
5688
5689
5690
5691
5692
5693
5694
5695
5696
5697
5698
5699
5700
5701
5702
5703
5704
5705
5706
5707
5708
5709
5710
5711
5712
5713
5714
5715
5716
5717
5718
5719
5720
5721
5722
5723
5724
5725
5726
5727
5728
5729
5730
5731
5732
5733
5734
5735
5736
5737
5738
5739
5740
5741
5742
5743
5744
5745
5746
5747
5748
5749
5750
5751
5752
5753
5754
5755
5756
5757
5758
5759
5760
5761
5762
5763
5764
5765
5766
5767
5768
5769
5770
5771
5772
5773
5774
5775
5776
5777
5778
5779
5780
5781
5782
5783
5784
5785
5786
5787
5788
5789
5790
5791
5792
5793
5794
5795
5796
5797
5798
5799
5800
5801
5802
5803
5804
5805
5806
5807
5808
5809
5810
5811
5812
5813
5814
5815
5816
5817
5818
5819
5820
5821
5822
5823
5824
5825
5826
5827
5828
5829
5830
5831
5832
5833
5834
5835
5836
5837
5838
5839
5840
5841
5842
5843
5844
5845
5846
5847
5848
5849
5850
5851
5852
5853
5854
5855
5856
5857
5858
5859
5860
5861
5862
5863
5864
5865
5866
5867
5868
5869
5870
5871
5872
5873
5874
5875
5876
5877
5878
5879
5880
5881
5882
5883
5884
5885
5886
5887
5888
5889
5890
5891
5892
5893
5894
5895
5896
5897
5898
5899
5900
5901
5902
5903
5904
5905
5906
5907
5908
5909
5910
5911
5912
5913
5914
5915
5916
5917
5918
5919
5920
5921
5922
5923
5924
5925
5926
5927
5928
5929
5930
5931
5932
5933
5934
5935
5936
5937
5938
5939
5940
5941
5942
5943
5944
5945
5946
5947
5948
5949
5950
5951
5952
5953
5954
5955
5956
5957
5958
5959
5960
5961
5962
5963
5964
5965
5966
5967
5968
5969
5970
5971
5972
5973
5974
5975
5976
5977
5978
5979
5980
5981
5982
5983
5984
5985
5986
5987
5988
5989
5990
5991
5992
5993
5994
5995
5996
5997
5998
5999
6000
6001
6002
6003
6004
6005
6006
6007
6008
6009
6010
6011
6012
6013
6014
6015
6016
6017
6018
6019
6020
6021
6022
6023
6024
6025
6026
6027
6028
6029
6030
6031
6032
6033
6034
6035
6036
6037
6038
6039
6040
6041
6042
6043
6044
6045
6046
6047
6048
6049
6050
6051
6052
6053
6054
6055
6056
6057
6058
6059
6060
6061
6062
6063
6064
6065
6066
6067
6068
6069
6070
6071
6072
6073
6074
6075
6076
6077
6078
6079
6080
6081
6082
6083
6084
6085
6086
6087
6088
6089
6090
6091
6092
6093
6094
6095
6096
6097
6098
6099
6100
6101
6102
6103
6104
6105
6106
6107
6108
6109
6110
6111
6112
6113
6114
6115
6116
6117
6118
6119
6120
6121
6122
6123
6124
6125
6126
6127
6128
6129
6130
6131
6132
6133
6134
6135
6136
6137
6138
6139
6140
6141
6142
6143
6144
6145
6146
6147
6148
6149
6150
6151
6152
6153
6154
6155
6156
6157
6158
6159
6160
6161
6162
6163
6164
6165
6166
6167
6168
6169
6170
6171
6172
6173
6174
6175
6176
6177
6178
6179
6180
6181
6182
6183
6184
6185
6186
6187
6188
6189
6190
6191
6192
6193
6194
6195
6196
6197
6198
6199
6200
6201
6202
6203
6204
6205
6206
6207
6208
6209
6210
6211
6212
6213
6214
6215
6216
6217
6218
6219
6220
6221
6222
6223
6224
6225
6226
6227
6228
6229
6230
6231
6232
6233
6234
6235
6236
6237
6238
6239
6240
6241
6242
6243
6244
6245
6246
6247
6248
6249
6250
6251
6252
6253
6254
6255
6256
6257
6258
6259
6260
6261
6262
6263
6264
6265
6266
6267
6268
6269
6270
6271
6272
6273
6274
6275
6276
6277
6278
6279
6280
6281
6282
6283
6284
6285
6286
6287
6288
6289
6290
6291
6292
6293
6294
6295
6296
6297
6298
6299
6300
6301
6302
6303
6304
6305
6306
6307
6308
6309
6310
6311
6312
6313
6314
6315
6316
6317
6318
6319
6320
6321
6322
6323
6324
6325
6326
6327
6328
6329
6330
6331
6332
6333
6334
6335
6336
6337
6338
6339
6340
6341
6342
6343
6344
6345
6346
6347
6348
6349
6350
6351
6352
6353
6354
6355
6356
6357
6358
6359
6360
6361
6362
6363
6364
6365
6366
6367
6368
6369
6370
6371
6372
6373
6374
6375
6376
6377
6378
6379
6380
6381
6382
6383
6384
6385
6386
6387
6388
6389
6390
6391
6392
6393
6394
6395
6396
6397
6398
6399
6400
6401
6402
6403
6404
6405
6406
6407
6408
6409
6410
6411
6412
6413
6414
6415
6416
6417
6418
6419
6420
6421
6422
6423
6424
6425
6426
6427
6428
6429
6430
6431
6432
6433
6434
6435
6436
6437
6438
6439
6440
6441
6442
6443
6444
6445
6446
6447
6448
6449
6450
6451
6452
6453
6454
6455
6456
6457
6458
6459
6460
6461
6462
6463
6464
6465
6466
6467
6468
6469
6470
6471
6472
6473
6474
6475
6476
6477
6478
6479
6480
6481
6482
6483
6484
6485
6486
6487
6488
6489
6490
6491
6492
6493
6494
6495
6496
6497
6498
6499
6500
6501
6502
6503
6504
6505
6506
6507
6508
6509
6510
6511
6512
6513
6514
6515
6516
6517
6518
6519
6520
6521
6522
6523
6524
6525
6526
6527
6528
6529
6530
6531
6532
6533
6534
6535
6536
6537
6538
6539
6540
6541
6542
6543
6544
6545
6546
6547
6548
6549
6550
6551
6552
6553
6554
6555
6556
6557
6558
6559
6560
6561
6562
6563
6564
6565
6566
6567
6568
6569
6570
6571
6572
6573
6574
6575
6576
6577
6578
6579
6580
6581
6582
6583
6584
6585
6586
6587
6588
6589
6590
6591
6592
6593
6594
6595
6596
6597
6598
6599
6600
6601
6602
6603
6604
6605
6606
6607
6608
6609
6610
6611
6612
6613
6614
6615
6616
6617
6618
6619
6620
6621
6622
6623
6624
6625
6626
6627
6628
6629
6630
6631
6632
6633
6634
6635
6636
6637
6638
6639
6640
6641
6642
6643
6644
6645
6646
6647
6648
6649
6650
6651
6652
6653
6654
6655
6656
6657
6658
6659
6660
6661
6662
6663
6664
6665
6666
6667
6668
6669
6670
6671
6672
6673
6674
6675
6676
6677
6678
6679
6680
6681
6682
6683
6684
6685
6686
6687
6688
6689
6690
6691
6692
6693
6694
6695
6696
6697
6698
6699
6700
6701
6702
6703
6704
6705
6706
6707
6708
6709
6710
6711
6712
6713
6714
6715
6716
6717
6718
6719
6720
6721
6722
6723
6724
6725
6726
6727
6728
6729
6730
6731
6732
6733
6734
6735
6736
6737
6738
6739
6740
6741
6742
6743
6744
6745
6746
6747
6748
6749
6750
6751
6752
6753
6754
6755
6756
6757
6758
6759
6760
6761
6762
6763
6764
6765
6766
6767
6768
6769
6770
6771
6772
6773
6774
6775
6776
6777
6778
6779
6780
6781
6782
6783
6784
6785
6786
6787
6788
6789
6790
6791
6792
6793
6794
6795
6796
6797
6798
6799
6800
6801
6802
6803
6804
6805
6806
6807
6808
6809
6810
6811
6812
6813
6814
6815
6816
6817
6818
6819
6820
6821
6822
6823
6824
6825
6826
6827
6828
6829
6830
6831
6832
6833
6834
6835
6836
6837
6838
6839
6840
6841
6842
6843
6844
6845
6846
6847
6848
6849
6850
6851
6852
6853
6854
6855
6856
6857
6858
6859
6860
6861
6862
6863
6864
6865
6866
6867
6868
6869
6870
6871
6872
6873
6874
6875
6876
6877
6878
6879
6880
6881
6882
6883
6884
6885
6886
6887
6888
6889
6890
6891
6892
6893
6894
6895
6896
6897
6898
6899
6900
6901
6902
6903
6904
6905
6906
6907
6908
6909
6910
6911
6912
6913
6914
6915
6916
6917
6918
6919
6920
6921
6922
6923
6924
6925
6926
6927
6928
6929
6930
6931
6932
6933
6934
6935
6936
6937
6938
6939
6940
6941
6942
6943
6944
6945
6946
6947
6948
6949
6950
6951
6952
6953
6954
6955
6956
6957
6958
6959
6960
6961
6962
6963
6964
6965
6966
6967
6968
6969
6970
6971
6972
6973
6974
6975
6976
6977
6978
6979
6980
6981
6982
6983
6984
6985
6986
6987
6988
6989
6990
6991
6992
6993
6994
6995
6996
6997
6998
6999
7000
7001
7002
7003
7004
7005
7006
7007
7008
7009
7010
7011
7012
7013
7014
7015
7016
7017
7018
7019
7020
7021
7022
7023
7024
7025
7026
7027
7028
7029
7030
7031
7032
7033
7034
7035
7036
7037
7038
7039
7040
7041
7042
7043
7044
7045
7046
7047
7048
7049
7050
7051
7052
7053
7054
7055
7056
7057
7058
7059
7060
7061
7062
7063
7064
7065
7066
7067
7068
7069
7070
7071
7072
7073
7074
7075
7076
7077
7078
7079
7080
7081
7082
7083
7084
7085
7086
7087
7088
7089
7090
7091
7092
7093
7094
7095
7096
7097
7098
7099
7100
7101
7102
7103
7104
7105
7106
7107
7108
7109
7110
7111
7112
7113
7114
7115
7116
7117
7118
7119
7120
7121
7122
7123
7124
7125
7126
7127
7128
7129
7130
7131
7132
7133
7134
7135
7136
7137
7138
7139
7140
7141
7142
7143
7144
7145
7146
7147
7148
7149
7150
7151
7152
7153
7154
7155
7156
7157
7158
7159
7160
7161
7162
7163
7164
7165
7166
7167
7168
7169
7170
7171
7172
7173
7174
7175
7176
7177
7178
7179
7180
7181
7182
7183
7184
7185
7186
7187
7188
7189
7190
7191
7192
7193
7194
7195
7196
7197
7198
7199
7200
7201
7202
7203
7204
7205
7206
7207
7208
7209
7210
7211
7212
7213
7214
7215
7216
7217
7218
7219
7220
7221
7222
7223
7224
7225
7226
7227
7228
7229
7230
7231
7232
7233
7234
7235
7236
7237
7238
7239
7240
7241
7242
7243
7244
7245
7246
7247
7248
7249
7250
7251
7252
7253
7254
7255
7256
7257
7258
7259
7260
7261
7262
7263
7264
7265
7266
7267
7268
7269
7270
7271
7272
7273
7274
7275
7276
7277
7278
7279
7280
7281
7282
7283
7284
7285
7286
7287
7288
7289
7290
7291
7292
7293
7294
7295
7296
7297
7298
7299
7300
7301
7302
7303
7304
7305
7306
7307
7308
7309
7310
7311
7312
7313
7314
7315
7316
7317
7318
7319
7320
7321
7322
7323
7324
7325
7326
7327
7328
7329
7330
7331
7332
7333
7334
7335
7336
7337
7338
7339
7340
7341
7342
7343
7344
7345
7346
7347
7348
7349
7350
7351
7352
7353
7354
7355
7356
7357
7358
7359
7360
7361
7362
7363
7364
7365
7366
7367
7368
7369
7370
7371
7372
7373
7374
7375
7376
7377
7378
7379
7380
7381
7382
7383
7384
7385
7386
7387
7388
7389
7390
7391
7392
7393
7394
7395
7396
7397
7398
7399
7400
7401
7402
7403
7404
7405
7406
7407
7408
7409
7410
7411
7412
7413
7414
7415
7416
7417
7418
7419
7420
7421
7422
7423
7424
7425
7426
7427
7428
7429
7430
7431
7432
7433
7434
7435
7436
7437
7438
7439
7440
7441
7442
7443
7444
7445
7446
7447
7448
7449
7450
7451
7452
7453
7454
7455
7456
7457
7458
7459
7460
7461
7462
7463
7464
7465
7466
7467
7468
7469
7470
7471
7472
7473
7474
7475
7476
7477
7478
7479
7480
7481
7482
7483
7484
7485
7486
7487
7488
7489
7490
7491
7492
7493
7494
7495
7496
7497
7498
7499
7500
7501
7502
7503
7504
7505
7506
7507
7508
7509
7510
7511
7512
7513
7514
7515
7516
7517
7518
7519
7520
7521
7522
7523
7524
7525
7526
7527
7528
7529
7530
7531
7532
7533
7534
7535
7536
7537
7538
7539
7540
7541
7542
7543
7544
7545
7546
7547
7548
7549
7550
7551
7552
7553
7554
7555
7556
7557
7558
7559
7560
7561
7562
7563
7564
7565
7566
7567
7568
7569
7570
7571
7572
7573
7574
7575
7576
7577
7578
7579
7580
7581
7582
7583
7584
7585
7586
7587
7588
7589
7590
7591
7592
7593
7594
7595
7596
7597
7598
7599
7600
7601
7602
7603
7604
7605
7606
7607
7608
7609
7610
7611
7612
7613
7614
7615
7616
7617
7618
7619
7620
7621
7622
7623
7624
7625
7626
7627
7628
7629
7630
7631
7632
7633
7634
7635
7636
7637
7638
7639
7640
7641
7642
7643
7644
7645
7646
7647
7648
7649
7650
7651
7652
7653
7654
7655
7656
7657
7658
7659
7660
7661
7662
7663
7664
7665
7666
7667
7668
7669
7670
7671
7672
7673
7674
7675
7676
7677
7678
7679
7680
7681
7682
7683
7684
7685
7686
7687
7688
7689
7690
7691
7692
7693
7694
7695
7696
7697
7698
7699
7700
7701
7702
7703
7704
7705
7706
7707
7708
7709
7710
7711
7712
7713
7714
7715
7716
7717
7718
7719
7720
7721
7722
7723
7724
7725
7726
7727
7728
7729
7730
7731
7732
7733
7734
7735
7736
7737
7738
7739
7740
7741
7742
7743
7744
7745
7746
7747
7748
7749
7750
7751
7752
7753
7754
7755
7756
7757
7758
7759
7760
7761
7762
7763
7764
7765
7766
7767
7768
7769
7770
7771
7772
7773
7774
7775
7776
7777
7778
7779
7780
7781
7782
7783
7784
7785
7786
7787
7788
7789
7790
7791
7792
7793
7794
7795
7796
7797
7798
7799
7800
7801
7802
7803
7804
7805
7806
7807
7808
7809
7810
7811
7812
7813
7814
7815
7816
7817
7818
7819
7820
7821
7822
7823
7824
7825
7826
7827
7828
7829
7830
7831
7832
7833
7834
7835
7836
7837
7838
7839
7840
7841
7842
7843
7844
7845
7846
7847
7848
7849
7850
7851
7852
7853
7854
7855
7856
7857
7858
7859
7860
7861
7862
7863
7864
7865
7866
7867
7868
7869
7870
7871
7872
7873
7874
7875
7876
7877
7878
7879
7880
7881
7882
7883
7884
7885
7886
7887
7888
7889
7890
7891
7892
7893
7894
7895
7896
7897
7898
7899
7900
7901
7902
7903
7904
7905
7906
7907
7908
7909
7910
7911
7912
7913
7914
7915
7916
7917
7918
7919
7920
7921
7922
7923
7924
7925
7926
7927
7928
7929
7930
7931
7932
7933
7934
7935
7936
7937
7938
7939
7940
7941
7942
7943
7944
7945
7946
7947
7948
7949
7950
7951
7952
7953
7954
7955
7956
7957
7958
7959
7960
7961
7962
7963
7964
7965
7966
7967
7968
7969
7970
7971
7972
7973
7974
7975
7976
7977
7978
7979
7980
7981
7982
7983
7984
7985
7986
7987
7988
7989
7990
7991
7992
7993
7994
7995
7996
7997
7998
7999
8000
8001
8002
8003
8004
8005
8006
8007
8008
8009
8010
8011
8012
8013
8014
8015
8016
8017
8018
8019
8020
8021
8022
8023
8024
8025
8026
8027
8028
8029
8030
8031
8032
8033
8034
8035
8036
8037
8038
8039
8040
8041
8042
8043
8044
8045
8046
8047
8048
8049
8050
8051
8052
8053
8054
8055
8056
8057
8058
8059
8060
8061
8062
8063
8064
8065
8066
8067
8068
8069
8070
8071
8072
8073
8074
8075
8076
8077
8078
8079
8080
8081
8082
8083
8084
8085
8086
8087
8088
8089
8090
8091
8092
8093
8094
8095
8096
8097
8098
8099
8100
8101
8102
8103
8104
8105
8106
8107
8108
8109
8110
8111
8112
8113
8114
8115
8116
8117
8118
8119
8120
8121
8122
8123
8124
8125
8126
8127
8128
8129
8130
8131
8132
8133
8134
8135
8136
8137
8138
8139
8140
8141
8142
8143
8144
8145
8146
8147
8148
8149
8150
8151
8152
8153
8154
8155
8156
8157
8158
8159
8160
8161
8162
8163
8164
8165
8166
8167
8168
8169
8170
8171
8172
8173
8174
8175
8176
8177
8178
8179
8180
8181
8182
8183
8184
8185
8186
8187
8188
8189
8190
8191
8192
8193
8194
8195
8196
8197
8198
8199
8200
8201
8202
8203
8204
8205
8206
8207
8208
8209
8210
8211
8212
8213
8214
8215
8216
8217
8218
8219
8220
8221
8222
8223
8224
8225
8226
8227
8228
8229
8230
8231
8232
8233
8234
8235
8236
8237
8238
8239
8240
8241
8242
8243
8244
8245
8246
8247
8248
8249
8250
8251
8252
8253
8254
8255
8256
8257
8258
8259
8260
8261
8262
8263
8264
8265
8266
8267
8268
8269
8270
8271
8272
8273
8274
8275
8276
8277
8278
8279
8280
8281
8282
8283
8284
8285
8286
8287
8288
8289
8290
8291
8292
8293
8294
8295
8296
8297
8298
8299
8300
8301
8302
8303
8304
8305
8306
8307
8308
8309
8310
8311
8312
8313
8314
8315
8316
8317
8318
8319
8320
8321
8322
8323
8324
8325
8326
8327
8328
8329
8330
8331
8332
8333
8334
8335
8336
8337
8338
8339
8340
8341
8342
8343
8344
8345
8346
8347
8348
8349
8350
8351
8352
8353
8354
8355
8356
8357
8358
8359
8360
8361
8362
8363
8364
8365
8366
8367
8368
8369
8370
8371
8372
8373
8374
8375
8376
8377
8378
8379
8380
8381
8382
8383
8384
8385
8386
8387
8388
8389
8390
8391
8392
8393
8394
8395
8396
8397
8398
8399
8400
8401
8402
8403
8404
8405
8406
8407
8408
8409
8410
8411
8412
8413
8414
8415
8416
8417
8418
8419
8420
8421
8422
8423
8424
8425
8426
8427
8428
8429
8430
8431
8432
8433
8434
8435
8436
8437
8438
8439
8440
8441
8442
8443
8444
8445
8446
8447
8448
8449
8450
8451
8452
8453
8454
8455
8456
8457
8458
8459
8460
8461
8462
8463
8464
8465
8466
8467
8468
8469
8470
8471
8472
8473
8474
8475
8476
8477
8478
8479
8480
8481
8482
8483
8484
8485
8486
8487
8488
8489
8490
8491
8492
8493
8494
8495
8496
8497
8498
8499
8500
8501
8502
8503
8504
8505
8506
8507
8508
8509
8510
8511
8512
8513
8514
8515
8516
8517
8518
8519
8520
8521
8522
8523
8524
8525
8526
8527
8528
8529
8530
8531
8532
8533
8534
8535
8536
8537
8538
8539
8540
8541
8542
8543
8544
8545
8546
8547
8548
8549
8550
8551
8552
8553
8554
8555
8556
8557
8558
8559
8560
8561
8562
8563
8564
8565
8566
8567
8568
8569
8570
8571
8572
8573
8574
8575
8576
8577
8578
8579
8580
8581
8582
8583
8584
8585
8586
8587
8588
8589
8590
8591
8592
8593
8594
8595
8596
8597
8598
8599
8600
8601
8602
8603
8604
8605
8606
8607
8608
8609
8610
8611
8612
8613
8614
8615
8616
8617
8618
8619
8620
8621
8622
8623
8624
8625
8626
8627
8628
8629
8630
8631
8632
8633
8634
8635
8636
8637
8638
8639
8640
8641
8642
8643
8644
8645
8646
8647
8648
8649
8650
8651
8652
8653
8654
8655
8656
8657
8658
8659
8660
8661
8662
8663
8664
8665
8666
8667
8668
8669
8670
8671
8672
8673
8674
8675
8676
8677
8678
8679
8680
8681
8682
8683
8684
8685
8686
8687
8688
8689
8690
8691
8692
8693
8694
8695
8696
8697
8698
8699
8700
8701
8702
8703
8704
8705
8706
8707
8708
8709
8710
8711
8712
8713
8714
8715
8716
8717
8718
8719
8720
8721
8722
8723
8724
8725
8726
8727
8728
8729
8730
8731
8732
8733
8734
8735
8736
8737
8738
8739
8740
8741
8742
8743
8744
8745
8746
8747
8748
8749
8750
8751
8752
8753
8754
8755
8756
8757
8758
8759
8760
8761
8762
8763
8764
8765
8766
8767
8768
8769
8770
8771
8772
8773
8774
8775
8776
8777
8778
8779
8780
8781
8782
8783
8784
8785
8786
8787
8788
8789
8790
8791
8792
8793
8794
8795
8796
8797
8798
8799
8800
8801
8802
8803
8804
8805
8806
8807
8808
8809
8810
8811
8812
8813
8814
8815
8816
8817
8818
8819
8820
8821
8822
8823
8824
8825
8826
8827
8828
8829
8830
8831
8832
8833
8834
8835
8836
8837
8838
8839
8840
8841
8842
8843
8844
8845
8846
8847
8848
8849
8850
8851
8852
8853
8854
8855
8856
8857
8858
8859
8860
8861
8862
8863
8864
8865
8866
8867
8868
8869
8870
8871
8872
8873
8874
8875
8876
8877
8878
8879
8880
8881
8882
8883
8884
8885
8886
8887
8888
8889
8890
8891
8892
8893
8894
8895
8896
8897
8898
8899
8900
8901
8902
8903
8904
8905
8906
8907
8908
8909
8910
8911
8912
8913
8914
8915
8916
8917
8918
8919
8920
8921
8922
8923
8924
8925
8926
8927
8928
8929
8930
8931
8932
8933
8934
8935
8936
8937
8938
8939
8940
8941
8942
8943
8944
8945
8946
8947
8948
8949
8950
8951
8952
8953
8954
8955
8956
8957
8958
8959
8960
8961
8962
8963
8964
8965
8966
8967
8968
8969
8970
8971
8972
8973
8974
8975
8976
8977
8978
8979
8980
8981
8982
8983
8984
8985
8986
8987
8988
8989
8990
8991
8992
8993
8994
8995
8996
8997
8998
8999
9000
9001
9002
9003
9004
9005
9006
9007
9008
9009
9010
9011
9012
9013
9014
9015
9016
9017
9018
9019
9020
9021
9022
9023
9024
9025
9026
9027
9028
9029
9030
9031
9032
9033
9034
9035
9036
9037
9038
9039
9040
9041
9042
9043
9044
9045
9046
9047
9048
9049
9050
9051
9052
9053
9054
9055
9056
9057
9058
9059
9060
9061
9062
9063
9064
9065
9066
9067
9068
9069
9070
9071
9072
9073
9074
9075
9076
9077
9078
9079
9080
9081
9082
9083
9084
9085
9086
9087
9088
9089
9090
9091
9092
9093
9094
9095
9096
9097
9098
9099
9100
9101
9102
9103
9104
9105
9106
9107
9108
9109
9110
9111
9112
9113
9114
9115
9116
9117
9118
9119
9120
9121
9122
9123
9124
9125
9126
9127
9128
9129
9130
9131
9132
9133
9134
9135
9136
9137
9138
9139
9140
9141
9142
9143
9144
9145
9146
9147
9148
9149
9150
9151
9152
9153
9154
9155
9156
9157
9158
9159
9160
9161
9162
9163
9164
9165
9166
9167
9168
9169
9170
9171
9172
9173
9174
9175
9176
9177
9178
9179
9180
9181
9182
9183
9184
9185
9186
9187
9188
9189
9190
9191
9192
9193
9194
9195
9196
9197
9198
9199
9200
9201
9202
9203
9204
9205
9206
9207
9208
9209
9210
9211
9212
9213
9214
9215
9216
9217
9218
9219
9220
9221
9222
9223
9224
9225
9226
9227
9228
9229
9230
9231
9232
9233
9234
9235
9236
9237
9238
9239
9240
9241
9242
9243
9244
9245
9246
9247
9248
9249
9250
9251
9252
9253
9254
9255
9256
9257
9258
9259
9260
9261
9262
9263
9264
9265
9266
9267
9268
9269
9270
9271
9272
9273
9274
9275
9276
9277
9278
9279
9280
9281
9282
9283
9284
9285
9286
9287
9288
9289
9290
9291
9292
9293
9294
9295
9296
9297
9298
9299
9300
9301
9302
9303
9304
9305
9306
9307
9308
9309
9310
9311
9312
9313
9314
9315
9316
9317
9318
9319
9320
9321
9322
9323
9324
9325
9326
9327
9328
9329
9330
9331
9332
9333
9334
9335
9336
9337
9338
9339
9340
9341
9342
9343
9344
9345
9346
9347
9348
9349
9350
9351
9352
9353
9354
9355
9356
9357
9358
9359
9360
9361
9362
9363
9364
9365
9366
9367
9368
9369
9370
9371
9372
9373
9374
9375
9376
9377
9378
9379
9380
9381
9382
9383
9384
9385
9386
9387
9388
9389
9390
9391
9392
9393
9394
9395
9396
9397
9398
9399
9400
9401
9402
9403
9404
9405
9406
9407
9408
9409
9410
9411
9412
9413
9414
9415
9416
9417
9418
9419
9420
9421
9422
9423
9424
9425
9426
9427
9428
9429
9430
9431
9432
9433
9434
9435
9436
9437
9438
9439
9440
9441
9442
9443
9444
9445
9446
9447
9448
9449
9450
9451
9452
9453
9454
9455
9456
9457
9458
9459
9460
9461
9462
9463
9464
9465
9466
9467
9468
9469
9470
9471
9472
9473
9474
9475
9476
9477
9478
9479
9480
9481
9482
9483
9484
9485
9486
9487
9488
9489
9490
9491
9492
9493
9494
9495
9496
9497
9498
9499
9500
9501
9502
9503
9504
9505
9506
9507
9508
9509
9510
9511
9512
9513
9514
9515
9516
9517
9518
9519
9520
9521
9522
9523
9524
9525
9526
9527
9528
9529
9530
9531
9532
9533
9534
9535
9536
9537
9538
9539
9540
9541
9542
9543
9544
9545
9546
9547
9548
9549
9550
9551
9552
9553
9554
9555
9556
9557
9558
9559
9560
9561
9562
9563
9564
9565
9566
9567
9568
9569
9570
9571
9572
9573
9574
9575
9576
9577
9578
9579
9580
9581
9582
9583
9584
9585
9586
9587
9588
9589
9590
9591
9592
9593
9594
9595
9596
9597
9598
9599
9600
9601
9602
9603
9604
9605
9606
9607
9608
9609
9610
9611
9612
9613
9614
9615
9616
9617
9618
9619
9620
9621
9622
9623
9624
9625
9626
9627
9628
9629
9630
9631
9632
9633
9634
9635
9636
9637
9638
9639
9640
9641
9642
9643
9644
9645
9646
9647
9648
9649
9650
9651
9652
9653
9654
9655
9656
9657
9658
9659
9660
9661
9662
9663
9664
9665
9666
9667
9668
9669
9670
9671
9672
9673
9674
9675
9676
9677
9678
9679
9680
9681
9682
9683
9684
9685
9686
9687
9688
9689
9690
9691
9692
9693
9694
9695
9696
9697
9698
9699
9700
9701
9702
9703
9704
9705
9706
9707
9708
9709
9710
9711
9712
9713
9714
9715
9716
9717
9718
9719
9720
9721
9722
9723
9724
9725
9726
9727
9728
9729
9730
9731
9732
9733
9734
9735
9736
9737
9738
9739
9740
9741
9742
9743
9744
9745
9746
9747
9748
9749
9750
9751
9752
9753
9754
9755
9756
9757
9758
9759
9760
9761
9762
9763
9764
9765
9766
9767
9768
9769
9770
9771
9772
9773
9774
9775
9776
9777
9778
9779
9780
9781
9782
9783
9784
9785
9786
9787
9788
9789
9790
9791
9792
9793
9794
9795
9796
9797
9798
9799
9800
9801
9802
9803
9804
9805
9806
9807
9808
9809
9810
9811
9812
9813
9814
9815
9816
9817
9818
9819
9820
9821
9822
9823
9824
9825
9826
9827
9828
9829
9830
9831
9832
9833
9834
9835
9836
9837
9838
9839
9840
9841
9842
9843
9844
9845
9846
9847
9848
9849
9850
9851
9852
9853
9854
9855
9856
9857
9858
9859
9860
9861
9862
9863
9864
9865
9866
9867
9868
9869
9870
9871
9872
9873
9874
9875
9876
9877
9878
9879
9880
9881
9882
9883
9884
9885
9886
9887
9888
9889
9890
9891
9892
9893
9894
9895
9896
9897
9898
9899
9900
9901
9902
9903
9904
9905
9906
9907
9908
9909
9910
9911
9912
9913
9914
9915
9916
9917
9918
9919
9920
9921
9922
9923
9924
9925
9926
9927
9928
9929
9930
9931
9932
9933
9934
9935
9936
9937
9938
9939
9940
9941
9942
9943
9944
9945
9946
9947
9948
9949
9950
9951
9952
9953
9954
9955
9956
9957
9958
9959
9960
9961
9962
9963
9964
9965
9966
9967
9968
9969
9970
9971
9972
9973
9974
9975
9976
9977
9978
9979
9980
9981
9982
9983
9984
9985
9986
9987
9988
9989
9990
9991
9992
9993
9994
9995
9996
9997
9998
9999
10000
10001
10002
10003
10004
10005
10006
10007
10008
10009
10010
10011
10012
10013
10014
10015
10016
10017
10018
10019
10020
10021
10022
10023
10024
10025
10026
10027
10028
10029
10030
10031
10032
10033
10034
10035
10036
10037
10038
10039
10040
10041
10042
10043
10044
10045
10046
10047
10048
10049
10050
10051
10052
10053
10054
10055
10056
10057
10058
10059
10060
10061
10062
10063
10064
10065
10066
10067
10068
10069
10070
10071
10072
10073
10074
10075
10076
10077
10078
10079
10080
10081
10082
10083
10084
10085
10086
10087
10088
10089
10090
10091
10092
10093
10094
10095
10096
10097
10098
10099
10100
10101
10102
10103
10104
10105
10106
10107
10108
10109
10110
10111
10112
10113
10114
10115
10116
10117
10118
10119
10120
10121
10122
10123
10124
10125
10126
10127
10128
10129
10130
10131
10132
10133
10134
10135
10136
10137
10138
10139
10140
10141
10142
10143
10144
10145
10146
10147
10148
10149
10150
10151
10152
10153
10154
10155
10156
10157
10158
10159
10160
10161
10162
10163
10164
10165
10166
10167
10168
10169
10170
10171
10172
10173
10174
10175
10176
10177
10178
10179
10180
10181
10182
10183
10184
10185
10186
10187
10188
10189
10190
10191
10192
10193
10194
10195
10196
10197
10198
10199
10200
10201
10202
10203
10204
10205
10206
10207
10208
10209
10210
10211
10212
10213
10214
10215
10216
10217
10218
10219
10220
10221
10222
10223
10224
10225
10226
10227
10228
10229
10230
10231
10232
10233
10234
10235
10236
10237
10238
10239
10240
10241
10242
10243
10244
10245
10246
10247
10248
10249
10250
10251
10252
10253
10254
10255
10256
10257
10258
10259
10260
10261
10262
10263
10264
10265
10266
10267
10268
10269
10270
10271
10272
10273
10274
10275
10276
10277
10278
10279
10280
10281
10282
10283
10284
10285
10286
10287
10288
10289
10290
10291
10292
10293
10294
10295
10296
10297
10298
10299
10300
10301
10302
10303
10304
10305
10306
10307
10308
10309
10310
10311
10312
10313
10314
10315
10316
10317
10318
10319
10320
10321
10322
10323
10324
10325
10326
10327
10328
10329
10330
10331
10332
10333
10334
10335
10336
10337
10338
10339
10340
10341
10342
10343
10344
10345
10346
10347
10348
10349
10350
10351
10352
10353
10354
10355
10356
10357
10358
10359
10360
10361
10362
10363
10364
10365
10366
10367
10368
10369
10370
10371
10372
10373
10374
10375
10376
10377
10378
10379
10380
10381
10382
10383
10384
10385
10386
10387
10388
10389
10390
10391
10392
10393
10394
10395
10396
10397
10398
10399
10400
10401
10402
10403
10404
10405
10406
10407
10408
10409
10410
10411
10412
10413
10414
10415
10416
10417
10418
10419
10420
10421
10422
10423
10424
10425
10426
10427
10428
10429
10430
10431
10432
10433
10434
10435
10436
10437
10438
10439
10440
10441
10442
10443
10444
10445
10446
10447
10448
10449
10450
10451
10452
10453
10454
10455
10456
10457
10458
10459
10460
10461
10462
10463
10464
10465
10466
10467
10468
10469
10470
10471
10472
10473
10474
10475
10476
10477
10478
10479
10480
10481
10482
10483
10484
10485
10486
10487
10488
10489
10490
10491
10492
10493
10494
10495
10496
10497
10498
10499
10500
10501
10502
10503
10504
10505
10506
10507
10508
10509
10510
10511
10512
10513
10514
10515
10516
10517
10518
10519
10520
10521
10522
10523
10524
10525
10526
10527
10528
10529
10530
10531
10532
10533
10534
10535
10536
10537
10538
10539
10540
10541
10542
10543
10544
10545
10546
10547
10548
10549
10550
10551
10552
10553
10554
10555
10556
10557
10558
10559
10560
10561
10562
10563
10564
10565
10566
10567
10568
10569
10570
10571
10572
10573
10574
10575
10576
10577
10578
10579
10580
10581
10582
10583
10584
10585
10586
10587
10588
10589
10590
10591
10592
10593
10594
10595
10596
10597
10598
10599
10600
10601
10602
10603
10604
10605
10606
10607
10608
10609
10610
10611
10612
10613
10614
10615
10616
10617
10618
10619
10620
10621
10622
10623
10624
10625
10626
10627
10628
10629
10630
10631
10632
10633
10634
10635
10636
10637
10638
10639
10640
10641
10642
10643
10644
10645
10646
10647
10648
10649
10650
10651
10652
10653
10654
10655
10656
10657
10658
10659
10660
10661
10662
10663
10664
10665
10666
10667
10668
10669
10670
10671
10672
10673
10674
10675
10676
10677
10678
10679
10680
10681
10682
10683
10684
10685
10686
10687
10688
10689
10690
10691
10692
10693
10694
10695
10696
10697
10698
10699
10700
10701
10702
10703
10704
10705
10706
10707
10708
10709
10710
10711
10712
10713
10714
10715
10716
10717
10718
10719
10720
10721
10722
10723
10724
10725
10726
10727
10728
10729
10730
10731
10732
10733
10734
10735
10736
10737
10738
10739
10740
10741
10742
10743
10744
10745
10746
10747
10748
10749
10750
10751
10752
10753
10754
10755
10756
10757
10758
10759
10760
10761
10762
10763
10764
10765
10766
10767
10768
10769
10770
10771
10772
10773
10774
10775
10776
10777
10778
10779
10780
10781
10782
10783
10784
10785
10786
10787
10788
10789
10790
10791
10792
10793
10794
10795
10796
10797
10798
10799
10800
10801
10802
10803
10804
10805
10806
10807
10808
10809
10810
10811
10812
10813
10814
10815
10816
10817
10818
10819
10820
10821
10822
10823
10824
10825
10826
10827
10828
10829
10830
10831
10832
10833
10834
10835
10836
10837
10838
10839
10840
10841
10842
10843
10844
10845
10846
10847
10848
10849
10850
10851
10852
10853
10854
10855
10856
10857
10858
10859
10860
10861
10862
10863
10864
10865
10866
10867
10868
10869
10870
10871
10872
10873
10874
10875
10876
10877
10878
10879
10880
10881
10882
10883
10884
10885
10886
10887
10888
10889
10890
10891
10892
10893
10894
10895
10896
10897
10898
10899
10900
10901
10902
10903
10904
10905
10906
10907
10908
10909
10910
10911
10912
10913
10914
10915
10916
10917
10918
10919
10920
10921
10922
10923
10924
10925
10926
10927
10928
10929
10930
10931
10932
10933
10934
10935
10936
10937
10938
10939
10940
10941
10942
10943
10944
10945
10946
10947
10948
10949
10950
10951
10952
10953
10954
10955
10956
10957
10958
10959
10960
10961
10962
10963
10964
10965
10966
10967
10968
10969
10970
10971
10972
10973
10974
10975
10976
10977
10978
10979
10980
10981
10982
10983
10984
10985
10986
10987
10988
10989
10990
10991
10992
10993
10994
10995
10996
10997
10998
10999
11000
11001
11002
11003
11004
11005
11006
11007
11008
11009
11010
11011
11012
11013
11014
11015
11016
11017
11018
11019
11020
11021
11022
11023
11024
11025
11026
11027
11028
11029
11030
11031
11032
11033
11034
11035
11036
11037
11038
11039
11040
11041
11042
11043
11044
11045
11046
11047
11048
11049
11050
11051
11052
11053
11054
11055
11056
11057
11058
11059
11060
11061
11062
11063
11064
11065
11066
11067
11068
11069
11070
11071
11072
11073
11074
11075
11076
11077
11078
11079
11080
11081
11082
11083
11084
11085
11086
11087
11088
11089
11090
11091
11092
11093
11094
11095
11096
11097
11098
11099
11100
11101
11102
11103
11104
11105
11106
11107
11108
11109
11110
11111
11112
11113
11114
11115
11116
11117
11118
11119
11120
11121
11122
11123
11124
11125
11126
11127
11128
11129
11130
11131
11132
11133
11134
11135
11136
11137
11138
11139
11140
11141
11142
11143
11144
11145
11146
11147
11148
11149
11150
11151
11152
11153
11154
11155
11156
11157
11158
11159
11160
11161
11162
11163
11164
11165
11166
11167
11168
11169
11170
11171
11172
11173
11174
11175
11176
11177
11178
11179
11180
11181
11182
11183
11184
11185
11186
11187
11188
11189
11190
11191
11192
11193
11194
11195
11196
11197
11198
11199
11200
11201
11202
11203
11204
11205
11206
11207
11208
11209
11210
11211
11212
11213
11214
11215
11216
11217
11218
11219
11220
11221
11222
11223
11224
11225
11226
11227
11228
11229
11230
11231
11232
11233
11234
11235
11236
11237
11238
11239
11240
11241
11242
11243
11244
11245
11246
11247
11248
11249
11250
11251
11252
11253
11254
11255
11256
11257
11258
11259
11260
11261
11262
11263
11264
11265
11266
11267
11268
11269
11270
11271
11272
11273
11274
11275
11276
11277
11278
11279
11280
11281
11282
11283
11284
11285
11286
11287
11288
11289
11290
11291
11292
11293
11294
11295
11296
11297
11298
11299
11300
11301
11302
11303
11304
11305
11306
11307
11308
11309
11310
11311
11312
11313
11314
11315
11316
11317
11318
11319
11320
11321
11322
11323
11324
11325
11326
11327
11328
11329
11330
11331
11332
11333
11334
11335
11336
11337
11338
11339
11340
11341
11342
11343
11344
11345
11346
11347
11348
11349
11350
11351
11352
11353
11354
11355
11356
11357
11358
11359
11360
11361
11362
11363
11364
11365
11366
11367
11368
11369
11370
11371
11372
11373
11374
11375
11376
11377
11378
11379
11380
11381
11382
11383
11384
11385
11386
11387
11388
11389
11390
11391
11392
11393
11394
11395
11396
11397
11398
11399
11400
11401
11402
11403
11404
11405
11406
11407
11408
11409
11410
11411
11412
11413
11414
11415
11416
11417
11418
11419
11420
11421
11422
11423
11424
11425
11426
11427
11428
11429
11430
11431
11432
11433
11434
11435
11436
11437
11438
11439
11440
11441
11442
11443
11444
11445
11446
11447
11448
11449
11450
11451
11452
11453
11454
11455
11456
11457
11458
11459
11460
11461
11462
11463
11464
11465
11466
11467
11468
11469
11470
11471
11472
11473
11474
11475
11476
11477
11478
11479
11480
11481
11482
11483
11484
11485
11486
11487
11488
11489
11490
11491
11492
11493
11494
11495
11496
11497
11498
11499
11500
11501
11502
11503
11504
11505
11506
11507
11508
11509
11510
11511
11512
11513
11514
11515
11516
11517
11518
11519
11520
11521
11522
11523
11524
11525
11526
11527
11528
11529
11530
11531
11532
11533
11534
11535
11536
11537
11538
11539
11540
11541
11542
11543
11544
11545
11546
11547
11548
11549
11550
11551
11552
11553
11554
11555
11556
11557
11558
11559
11560
11561
11562
11563
11564
11565
11566
11567
11568
11569
11570
11571
11572
11573
11574
11575
11576
11577
11578
11579
11580
11581
11582
11583
11584
11585
11586
11587
11588
11589
11590
11591
11592
11593
11594
11595
11596
11597
11598
11599
11600
11601
11602
11603
11604
11605
11606
11607
11608
11609
11610
11611
11612
11613
11614
11615
11616
11617
11618
11619
11620
11621
11622
11623
11624
11625
11626
11627
11628
11629
11630
11631
11632
11633
11634
11635
11636
11637
11638
11639
11640
11641
11642
11643
11644
11645
11646
11647
11648
11649
11650
11651
11652
11653
11654
11655
11656
11657
11658
11659
11660
11661
11662
11663
11664
11665
11666
11667
11668
11669
11670
11671
11672
11673
11674
11675
11676
11677
11678
11679
11680
11681
11682
11683
11684
11685
11686
11687
11688
11689
11690
11691
11692
11693
11694
11695
11696
11697
11698
11699
11700
11701
11702
11703
11704
11705
11706
11707
11708
11709
11710
11711
11712
11713
11714
11715
11716
11717
11718
11719
11720
11721
11722
11723
11724
11725
11726
11727
11728
11729
11730
11731
11732
11733
11734
11735
11736
11737
11738
11739
11740
11741
11742
11743
11744
11745
11746
11747
11748
11749
11750
11751
11752
11753
11754
11755
11756
11757
11758
11759
11760
11761
11762
11763
11764
11765
11766
11767
11768
11769
11770
11771
11772
11773
11774
11775
11776
11777
11778
11779
11780
11781
11782
11783
11784
11785
11786
11787
11788
11789
11790
11791
11792
11793
11794
11795
11796
11797
11798
11799
11800
11801
11802
11803
11804
11805
11806
11807
11808
11809
11810
11811
11812
11813
11814
11815
11816
11817
11818
11819
11820
11821
11822
11823
11824
11825
11826
11827
11828
11829
11830
11831
11832
11833
11834
11835
11836
11837
11838
11839
11840
11841
11842
11843
11844
11845
11846
11847
11848
11849
11850
11851
11852
11853
11854
11855
11856
11857
11858
11859
11860
11861
11862
11863
11864
11865
11866
11867
11868
11869
11870
11871
11872
11873
11874
11875
11876
11877
11878
11879
11880
11881
11882
11883
11884
11885
11886
11887
11888
11889
11890
11891
11892
11893
11894
11895
11896
11897
11898
11899
11900
11901
11902
11903
11904
11905
11906
11907
11908
11909
11910
11911
11912
11913
11914
11915
11916
11917
11918
11919
11920
11921
11922
11923
11924
11925
11926
11927
11928
11929
11930
11931
11932
11933
11934
11935
11936
11937
11938
11939
11940
11941
11942
11943
11944
11945
11946
11947
11948
11949
11950
11951
11952
11953
11954
11955
11956
11957
11958
11959
11960
11961
11962
11963
11964
11965
11966
11967
11968
11969
11970
11971
11972
11973
11974
11975
11976
11977
11978
11979
11980
11981
11982
11983
11984
11985
11986
11987
11988
11989
11990
11991
11992
11993
11994
11995
11996
11997
11998
11999
12000
12001
12002
12003
12004
12005
12006
12007
12008
12009
12010
12011
12012
12013
12014
12015
12016
12017
12018
12019
12020
12021
12022
12023
12024
12025
12026
12027
12028
12029
12030
12031
12032
12033
12034
12035
12036
12037
12038
12039
12040
12041
12042
12043
12044
12045
12046
12047
12048
12049
12050
12051
12052
12053
12054
12055
12056
12057
12058
12059
12060
12061
12062
12063
12064
12065
12066
12067
12068
12069
12070
12071
12072
12073
12074
12075
12076
12077
12078
12079
12080
12081
12082
12083
12084
12085
12086
12087
12088
12089
12090
12091
12092
12093
12094
12095
12096
12097
12098
12099
12100
12101
12102
12103
12104
12105
12106
12107
12108
12109
12110
12111
12112
12113
12114
12115
12116
12117
12118
12119
12120
12121
12122
12123
12124
12125
12126
12127
12128
12129
12130
12131
12132
12133
12134
12135
12136
12137
12138
12139
12140
12141
12142
12143
12144
12145
12146
12147
12148
12149
12150
12151
12152
12153
12154
12155
12156
12157
12158
12159
12160
12161
12162
12163
12164
12165
12166
12167
12168
12169
12170
12171
12172
12173
12174
12175
12176
12177
12178
12179
12180
12181
12182
12183
12184
12185
12186
12187
12188
12189
12190
12191
12192
12193
12194
12195
12196
12197
12198
12199
12200
12201
12202
12203
12204
12205
12206
12207
12208
12209
12210
12211
12212
12213
12214
12215
12216
12217
12218
12219
12220
12221
12222
12223
12224
12225
12226
12227
12228
12229
12230
12231
12232
12233
12234
12235
12236
12237
12238
12239
12240
12241
12242
12243
12244
12245
12246
12247
12248
12249
12250
12251
12252
12253
12254
12255
12256
12257
12258
12259
12260
12261
12262
12263
12264
12265
12266
12267
12268
12269
12270
12271
12272
12273
12274
12275
12276
12277
12278
12279
12280
12281
12282
12283
12284
12285
12286
12287
12288
12289
12290
12291
12292
12293
12294
12295
12296
12297
12298
12299
12300
12301
12302
12303
12304
12305
12306
12307
12308
12309
12310
12311
12312
12313
12314
12315
12316
12317
12318
12319
12320
12321
12322
12323
12324
12325
12326
12327
12328
12329
12330
12331
12332
12333
12334
12335
12336
12337
12338
12339
12340
12341
12342
12343
12344
12345
12346
12347
12348
12349
12350
12351
12352
12353
12354
12355
12356
12357
12358
12359
12360
12361
12362
12363
12364
12365
12366
12367
12368
12369
12370
12371
12372
12373
12374
12375
12376
12377
12378
12379
12380
12381
12382
12383
12384
12385
12386
12387
12388
12389
12390
12391
12392
12393
12394
12395
12396
12397
12398
12399
12400
12401
12402
12403
12404
12405
12406
12407
12408
12409
12410
12411
12412
12413
12414
12415
12416
12417
12418
12419
12420
12421
12422
12423
12424
12425
12426
12427
12428
12429
12430
12431
12432
12433
12434
12435
12436
12437
12438
12439
12440
12441
12442
12443
12444
12445
12446
12447
12448
12449
12450
12451
12452
12453
12454
12455
12456
12457
12458
12459
12460
12461
12462
12463
12464
12465
12466
12467
12468
12469
12470
12471
12472
12473
12474
12475
12476
12477
12478
12479
12480
12481
12482
12483
12484
12485
12486
12487
12488
12489
12490
12491
12492
12493
12494
12495
12496
12497
12498
12499
12500
12501
12502
12503
12504
12505
12506
12507
12508
12509
12510
12511
12512
12513
12514
12515
12516
12517
12518
12519
12520
12521
12522
12523
12524
12525
12526
12527
12528
12529
12530
12531
12532
12533
12534
12535
12536
12537
12538
12539
12540
12541
12542
12543
12544
12545
12546
12547
12548
12549
12550
12551
12552
12553
12554
12555
12556
12557
12558
12559
12560
12561
12562
12563
12564
12565
12566
12567
12568
12569
12570
12571
12572
12573
12574
12575
12576
12577
12578
12579
12580
12581
12582
12583
12584
12585
12586
12587
12588
12589
12590
12591
12592
12593
12594
12595
12596
12597
12598
12599
12600
12601
12602
12603
12604
12605
12606
12607
12608
12609
12610
12611
12612
12613
12614
12615
12616
12617
12618
12619
12620
12621
12622
12623
12624
12625
12626
12627
12628
12629
12630
12631
12632
12633
12634
12635
12636
12637
12638
12639
12640
12641
12642
12643
12644
12645
12646
12647
12648
12649
12650
12651
12652
12653
12654
12655
12656
12657
12658
12659
12660
12661
12662
12663
12664
12665
12666
12667
12668
12669
12670
12671
12672
12673
12674
12675
12676
12677
12678
12679
12680
12681
12682
12683
12684
12685
12686
12687
12688
12689
12690
12691
12692
12693
12694
12695
12696
12697
12698
12699
12700
12701
12702
12703
12704
12705
12706
12707
12708
12709
12710
12711
12712
12713
12714
12715
12716
12717
12718
12719
12720
12721
12722
12723
12724
12725
12726
12727
12728
12729
12730
12731
12732
12733
12734
12735
12736
12737
12738
12739
12740
12741
12742
12743
12744
12745
12746
12747
12748
12749
12750
12751
12752
12753
12754
12755
12756
12757
12758
12759
12760
12761
12762
12763
12764
12765
12766
12767
12768
12769
12770
12771
12772
12773
12774
12775
12776
12777
12778
12779
12780
12781
12782
12783
12784
12785
12786
12787
12788
12789
12790
12791
12792
12793
12794
12795
12796
12797
12798
12799
12800
12801
12802
12803
12804
12805
12806
12807
12808
12809
12810
12811
12812
12813
12814
12815
12816
12817
12818
12819
12820
12821
12822
12823
12824
12825
12826
12827
12828
12829
12830
12831
12832
12833
12834
12835
12836
12837
12838
12839
12840
12841
12842
12843
12844
12845
12846
12847
12848
12849
12850
12851
12852
12853
12854
12855
12856
12857
12858
12859
12860
12861
12862
12863
12864
12865
12866
12867
12868
12869
12870
12871
12872
12873
12874
12875
12876
12877
12878
12879
12880
12881
12882
12883
12884
12885
12886
12887
12888
12889
12890
12891
12892
12893
12894
12895
12896
12897
12898
12899
12900
12901
12902
12903
12904
12905
12906
12907
12908
12909
12910
12911
12912
12913
12914
12915
12916
12917
12918
12919
12920
12921
12922
12923
12924
12925
12926
12927
12928
12929
12930
12931
12932
12933
12934
12935
12936
12937
12938
12939
12940
12941
12942
12943
12944
12945
12946
12947
12948
12949
12950
12951
12952
12953
12954
12955
12956
12957
12958
12959
12960
12961
12962
12963
12964
12965
12966
12967
12968
12969
12970
12971
12972
12973
12974
12975
12976
12977
12978
12979
12980
12981
12982
12983
12984
12985
12986
12987
12988
12989
12990
12991
12992
12993
12994
12995
12996
12997
12998
12999
13000
13001
13002
13003
13004
13005
13006
13007
13008
13009
13010
13011
13012
13013
13014
13015
13016
13017
13018
13019
13020
13021
13022
13023
13024
13025
13026
13027
13028
13029
13030
13031
13032
13033
13034
13035
13036
13037
13038
13039
13040
13041
13042
13043
13044
13045
13046
13047
13048
13049
13050
13051
13052
13053
13054
13055
13056
13057
13058
13059
13060
13061
13062
13063
13064
13065
13066
13067
13068
13069
13070
13071
13072
13073
13074
13075
13076
13077
13078
13079
13080
13081
13082
13083
13084
13085
13086
13087
13088
13089
13090
13091
13092
13093
13094
13095
13096
13097
13098
13099
13100
13101
13102
13103
13104
13105
13106
13107
13108
13109
13110
13111
13112
13113
13114
13115
13116
13117
13118
13119
13120
13121
13122
13123
13124
13125
13126
13127
13128
13129
13130
13131
13132
13133
13134
13135
13136
13137
13138
13139
13140
13141
13142
13143
13144
13145
13146
13147
13148
13149
13150
13151
13152
13153
13154
13155
13156
13157
13158
13159
13160
13161
13162
13163
13164
13165
13166
13167
13168
13169
13170
13171
13172
13173
13174
13175
13176
13177
13178
13179
13180
13181
13182
13183
13184
13185
13186
13187
13188
13189
13190
13191
13192
13193
13194
13195
13196
13197
13198
13199
13200
13201
13202
13203
13204
13205
13206
13207
13208
13209
13210
13211
13212
13213
13214
13215
13216
13217
13218
13219
13220
13221
13222
13223
13224
13225
13226
13227
13228
13229
13230
13231
13232
13233
13234
13235
13236
13237
13238
13239
13240
13241
13242
13243
13244
13245
13246
13247
13248
13249
13250
13251
13252
13253
13254
13255
13256
13257
13258
13259
13260
13261
13262
13263
13264
13265
13266
13267
13268
13269
13270
13271
13272
13273
13274
13275
13276
13277
13278
13279
13280
13281
13282
13283
13284
13285
13286
13287
13288
13289
13290
13291
13292
13293
13294
13295
13296
13297
13298
13299
13300
13301
13302
13303
13304
13305
13306
13307
13308
13309
13310
13311
13312
13313
13314
13315
13316
13317
13318
13319
13320
13321
13322
13323
13324
13325
13326
13327
13328
13329
13330
13331
13332
13333
13334
13335
13336
13337
13338
13339
13340
13341
13342
13343
13344
13345
13346
13347
13348
13349
13350
13351
13352
13353
13354
13355
13356
13357
13358
13359
13360
13361
13362
13363
13364
13365
13366
13367
13368
13369
13370
13371
13372
13373
13374
13375
13376
13377
13378
13379
13380
13381
13382
13383
13384
13385
13386
13387
13388
13389
13390
13391
13392
13393
13394
13395
13396
13397
13398
13399
13400
13401
13402
13403
13404
13405
13406
13407
13408
13409
13410
13411
13412
13413
13414
13415
13416
13417
13418
13419
13420
13421
13422
13423
13424
13425
13426
13427
13428
13429
13430
13431
13432
13433
13434
13435
13436
13437
13438
13439
13440
13441
13442
13443
13444
13445
13446
13447
13448
13449
13450
13451
13452
13453
13454
13455
13456
13457
13458
13459
13460
13461
13462
13463
13464
13465
13466
13467
13468
13469
13470
13471
13472
13473
13474
13475
13476
13477
13478
13479
13480
13481
13482
13483
13484
13485
13486
13487
13488
13489
13490
13491
13492
13493
13494
13495
13496
13497
13498
13499
13500
13501
13502
13503
13504
13505
13506
13507
13508
13509
13510
13511
13512
13513
13514
13515
13516
13517
13518
13519
13520
13521
13522
13523
13524
13525
13526
13527
13528
13529
13530
13531
13532
13533
13534
13535
13536
13537
13538
13539
13540
13541
13542
13543
13544
13545
13546
13547
13548
13549
13550
13551
13552
13553
13554
13555
13556
13557
13558
13559
13560
13561
13562
13563
13564
13565
13566
13567
13568
13569
13570
13571
13572
13573
13574
13575
13576
13577
13578
13579
13580
13581
13582
13583
13584
13585
13586
13587
13588
13589
13590
13591
13592
13593
13594
13595
13596
13597
13598
13599
13600
13601
13602
13603
13604
13605
13606
13607
13608
13609
13610
13611
13612
13613
13614
13615
13616
13617
13618
13619
13620
13621
13622
13623
13624
13625
13626
13627
13628
13629
13630
13631
13632
13633
13634
13635
13636
13637
13638
13639
13640
13641
13642
13643
13644
13645
13646
13647
13648
13649
13650
13651
13652
13653
13654
13655
13656
13657
13658
13659
13660
13661
13662
13663
13664
13665
13666
13667
13668
13669
13670
13671
13672
13673
13674
13675
13676
13677
13678
13679
13680
13681
13682
13683
13684
13685
13686
13687
13688
13689
13690
13691
13692
13693
13694
13695
13696
13697
13698
13699
13700
13701
13702
13703
13704
13705
13706
13707
13708
13709
13710
13711
13712
13713
13714
13715
13716
13717
13718
13719
13720
13721
13722
13723
13724
13725
13726
13727
13728
13729
13730
13731
13732
13733
13734
13735
13736
13737
13738
13739
13740
13741
13742
13743
13744
13745
13746
13747
13748
13749
13750
13751
13752
13753
13754
13755
13756
13757
13758
13759
13760
13761
13762
13763
13764
13765
13766
13767
13768
13769
13770
13771
13772
13773
13774
13775
13776
13777
13778
13779
13780
13781
13782
13783
13784
13785
13786
13787
13788
13789
13790
13791
13792
13793
13794
13795
13796
13797
13798
13799
13800
13801
13802
13803
13804
13805
13806
13807
13808
13809
13810
13811
13812
13813
13814
13815
13816
13817
13818
13819
13820
13821
13822
13823
13824
13825
13826
13827
13828
13829
13830
13831
13832
13833
13834
13835
13836
13837
13838
13839
13840
13841
13842
13843
13844
13845
13846
13847
13848
13849
13850
13851
13852
13853
13854
13855
13856
13857
13858
13859
13860
13861
13862
13863
13864
13865
13866
13867
13868
13869
13870
13871
13872
13873
13874
13875
13876
13877
13878
13879
13880
13881
13882
13883
13884
13885
13886
13887
13888
13889
13890
13891
13892
13893
13894
13895
13896
13897
13898
13899
13900
13901
13902
13903
13904
13905
13906
13907
13908
13909
13910
13911
13912
13913
13914
13915
13916
13917
13918
13919
13920
13921
13922
13923
13924
13925
13926
13927
13928
13929
13930
13931
13932
13933
13934
13935
13936
13937
13938
13939
13940
13941
13942
13943
13944
13945
13946
13947
13948
13949
13950
13951
13952
13953
13954
13955
13956
13957
13958
13959
13960
13961
13962
13963
13964
13965
13966
13967
13968
13969
13970
13971
13972
13973
13974
13975
13976
13977
13978
13979
13980
13981
13982
13983
13984
13985
13986
13987
13988
13989
13990
13991
13992
13993
13994
13995
13996
13997
13998
13999
14000
14001
14002
14003
14004
14005
14006
14007
14008
14009
14010
14011
14012
14013
14014
14015
14016
14017
14018
14019
14020
14021
14022
14023
14024
14025
14026
14027
14028
14029
14030
14031
14032
14033
14034
14035
14036
14037
14038
14039
14040
14041
14042
14043
14044
14045
14046
14047
14048
14049
14050
14051
14052
14053
14054
14055
14056
14057
14058
14059
14060
14061
14062
14063
14064
14065
14066
14067
14068
14069
14070
14071
14072
14073
14074
14075
14076
14077
14078
14079
14080
14081
14082
14083
14084
14085
14086
14087
14088
14089
14090
14091
14092
14093
14094
14095
14096
14097
14098
14099
14100
14101
14102
14103
14104
14105
14106
14107
14108
14109
14110
14111
14112
14113
14114
14115
14116
14117
14118
14119
14120
14121
14122
14123
14124
14125
14126
14127
14128
14129
14130
14131
14132
14133
14134
14135
14136
14137
14138
14139
14140
14141
14142
14143
14144
14145
14146
14147
14148
14149
14150
14151
14152
14153
14154
14155
14156
14157
14158
14159
14160
14161
14162
14163
14164
14165
14166
14167
14168
14169
14170
14171
14172
14173
14174
14175
14176
14177
14178
14179
14180
14181
14182
14183
14184
14185
14186
14187
14188
14189
14190
14191
14192
14193
14194
14195
14196
14197
14198
14199
14200
14201
14202
14203
14204
14205
14206
14207
14208
14209
14210
14211
14212
14213
14214
14215
14216
14217
14218
14219
14220
14221
14222
14223
14224
14225
14226
14227
14228
14229
14230
14231
14232
14233
14234
14235
14236
14237
14238
14239
14240
14241
14242
14243
14244
14245
14246
14247
14248
14249
14250
14251
14252
14253
14254
14255
14256
14257
14258
14259
14260
14261
14262
14263
14264
14265
14266
14267
14268
14269
14270
14271
14272
14273
14274
14275
14276
14277
14278
14279
14280
14281
14282
14283
14284
14285
14286
14287
14288
14289
14290
14291
14292
14293
14294
14295
14296
14297
14298
14299
14300
14301
14302
14303
14304
14305
14306
14307
14308
14309
14310
14311
14312
14313
14314
14315
14316
14317
14318
14319
14320
14321
14322
14323
14324
14325
14326
14327
14328
14329
14330
14331
14332
14333
14334
14335
14336
14337
14338
14339
14340
14341
14342
14343
14344
14345
14346
14347
14348
14349
14350
14351
14352
14353
14354
14355
14356
14357
14358
14359
14360
14361
14362
14363
14364
14365
14366
14367
14368
14369
14370
14371
14372
14373
14374
14375
14376
14377
14378
14379
14380
14381
14382
14383
14384
14385
14386
14387
14388
14389
14390
14391
14392
14393
14394
14395
14396
14397
14398
14399
14400
14401
14402
14403
14404
14405
14406
14407
14408
14409
14410
14411
14412
14413
14414
14415
14416
14417
14418
14419
14420
14421
14422
14423
14424
14425
14426
14427
14428
14429
14430
14431
14432
14433
14434
14435
14436
14437
14438
14439
14440
14441
14442
14443
14444
14445
14446
14447
14448
14449
14450
14451
14452
14453
14454
14455
14456
14457
14458
14459
14460
14461
14462
14463
14464
14465
14466
14467
14468
14469
14470
14471
14472
14473
14474
14475
14476
14477
14478
14479
14480
14481
14482
14483
14484
14485
14486
14487
14488
14489
14490
14491
14492
14493
14494
14495
14496
14497
14498
14499
14500
14501
14502
14503
14504
14505
14506
14507
14508
14509
14510
14511
14512
14513
14514
14515
14516
14517
14518
14519
14520
14521
14522
14523
14524
14525
14526
14527
14528
14529
14530
14531
14532
14533
14534
14535
14536
14537
14538
14539
14540
14541
14542
14543
14544
14545
14546
14547
14548
14549
14550
14551
14552
14553
14554
14555
14556
14557
14558
14559
14560
14561
14562
14563
14564
14565
14566
14567
14568
14569
14570
14571
14572
14573
14574
14575
14576
14577
14578
14579
14580
14581
14582
14583
14584
14585
14586
14587
14588
14589
14590
14591
14592
14593
14594
14595
14596
14597
14598
14599
14600
14601
14602
14603
14604
14605
14606
14607
14608
14609
14610
14611
14612
14613
14614
14615
14616
14617
14618
14619
14620
14621
14622
14623
14624
14625
14626
14627
14628
14629
14630
14631
14632
14633
14634
14635
14636
14637
14638
14639
14640
14641
14642
14643
14644
14645
14646
14647
14648
14649
14650
14651
14652
14653
14654
14655
14656
14657
14658
14659
14660
14661
14662
14663
14664
14665
14666
14667
14668
14669
14670
14671
14672
14673
14674
14675
14676
14677
14678
14679
14680
14681
14682
14683
14684
14685
14686
14687
14688
14689
14690
14691
14692
14693
14694
14695
14696
14697
14698
14699
14700
14701
14702
14703
14704
14705
14706
14707
14708
14709
14710
14711
14712
14713
14714
14715
14716
14717
14718
14719
14720
14721
14722
14723
14724
14725
14726
14727
14728
14729
14730
14731
14732
14733
14734
14735
14736
14737
14738
14739
14740
14741
14742
14743
14744
14745
14746
14747
14748
14749
14750
14751
14752
14753
14754
14755
14756
14757
14758
14759
14760
14761
14762
14763
14764
14765
14766
14767
14768
14769
14770
14771
14772
14773
14774
14775
14776
14777
14778
14779
14780
14781
14782
14783
14784
14785
14786
14787
14788
14789
14790
14791
14792
14793
14794
14795
14796
14797
14798
14799
14800
14801
14802
14803
14804
14805
14806
14807
14808
14809
14810
14811
14812
14813
14814
14815
14816
14817
14818
14819
14820
14821
14822
14823
14824
14825
14826
14827
14828
14829
14830
14831
14832
14833
14834
14835
14836
14837
14838
14839
14840
14841
14842
14843
14844
14845
14846
14847
14848
14849
14850
14851
14852
14853
14854
14855
14856
14857
14858
14859
14860
14861
14862
14863
14864
14865
14866
14867
14868
14869
14870
14871
14872
14873
14874
14875
14876
14877
14878
14879
14880
14881
14882
14883
14884
14885
14886
14887
14888
14889
14890
14891
14892
14893
14894
14895
14896
14897
14898
14899
14900
14901
14902
14903
14904
14905
14906
14907
14908
14909
14910
14911
14912
14913
14914
14915
14916
14917
14918
14919
14920
14921
14922
14923
14924
14925
14926
14927
14928
14929
14930
14931
14932
14933
14934
14935
14936
14937
14938
14939
14940
14941
14942
14943
14944
14945
14946
14947
14948
14949
14950
14951
14952
14953
14954
14955
14956
14957
14958
14959
14960
14961
14962
14963
14964
14965
14966
14967
14968
14969
14970
14971
14972
14973
14974
14975
14976
14977
14978
14979
14980
14981
14982
14983
14984
14985
14986
14987
14988
14989
14990
14991
14992
14993
14994
14995
14996
14997
14998
14999
15000
15001
15002
15003
15004
15005
15006
15007
15008
15009
15010
15011
15012
15013
15014
15015
15016
15017
15018
15019
15020
15021
15022
15023
15024
15025
15026
15027
15028
15029
15030
15031
15032
15033
15034
15035
15036
15037
15038
15039
15040
15041
15042
15043
15044
15045
15046
15047
15048
15049
15050
15051
15052
15053
15054
15055
15056
15057
15058
15059
15060
15061
15062
15063
15064
15065
15066
15067
15068
15069
15070
15071
15072
15073
15074
15075
15076
15077
15078
15079
15080
15081
15082
15083
15084
15085
15086
15087
15088
15089
15090
15091
15092
15093
15094
15095
15096
15097
15098
15099
15100
15101
15102
15103
15104
15105
15106
15107
15108
15109
15110
15111
15112
15113
15114
15115
15116
15117
15118
15119
15120
15121
15122
15123
15124
15125
15126
15127
15128
15129
15130
15131
15132
15133
15134
15135
15136
15137
15138
15139
15140
15141
15142
15143
15144
15145
15146
15147
15148
15149
15150
15151
15152
15153
15154
15155
15156
15157
15158
15159
15160
15161
15162
15163
15164
15165
15166
15167
15168
15169
15170
15171
15172
15173
15174
15175
15176
15177
15178
15179
15180
15181
15182
15183
15184
15185
15186
15187
15188
15189
15190
15191
15192
15193
15194
15195
15196
15197
15198
15199
15200
15201
15202
15203
15204
15205
15206
15207
15208
15209
15210
15211
15212
15213
15214
15215
15216
15217
15218
15219
15220
15221
15222
15223
15224
15225
15226
15227
15228
15229
15230
15231
15232
15233
15234
15235
15236
15237
15238
15239
15240
15241
15242
15243
15244
15245
15246
15247
15248
15249
15250
15251
15252
15253
15254
15255
15256
15257
15258
15259
15260
15261
15262
15263
15264
15265
15266
15267
15268
15269
15270
15271
15272
15273
15274
15275
15276
15277
15278
15279
15280
15281
15282
15283
15284
15285
15286
15287
15288
15289
15290
15291
15292
15293
15294
15295
15296
15297
15298
15299
15300
15301
15302
15303
15304
15305
15306
15307
15308
15309
15310
15311
15312
15313
15314
15315
15316
15317
15318
15319
15320
15321
15322
15323
15324
15325
15326
15327
15328
15329
15330
15331
15332
15333
15334
15335
15336
15337
15338
15339
15340
15341
15342
15343
15344
15345
15346
15347
15348
15349
15350
15351
15352
15353
15354
15355
15356
15357
15358
15359
15360
15361
15362
15363
15364
15365
15366
15367
15368
15369
15370
15371
15372
15373
15374
15375
15376
15377
15378
15379
15380
15381
15382
15383
15384
15385
15386
15387
15388
15389
15390
15391
15392
15393
15394
15395
15396
15397
15398
15399
15400
15401
15402
15403
15404
15405
15406
15407
15408
15409
15410
15411
15412
15413
15414
15415
15416
15417
15418
15419
15420
15421
15422
15423
15424
15425
15426
15427
15428
15429
15430
15431
15432
15433
15434
15435
15436
15437
15438
15439
15440
15441
15442
15443
15444
15445
15446
15447
15448
15449
15450
15451
15452
15453
15454
15455
15456
15457
15458
15459
15460
15461
15462
15463
15464
15465
15466
15467
15468
15469
15470
15471
15472
15473
15474
15475
15476
15477
15478
15479
15480
15481
15482
15483
15484
15485
15486
15487
15488
15489
15490
15491
15492
15493
15494
15495
15496
15497
15498
15499
15500
15501
15502
15503
15504
15505
15506
15507
15508
15509
15510
15511
15512
15513
15514
15515
15516
15517
15518
15519
15520
15521
15522
15523
15524
15525
15526
15527
15528
15529
15530
15531
15532
15533
15534
15535
15536
15537
15538
15539
15540
15541
15542
15543
15544
15545
15546
15547
15548
15549
15550
15551
15552
15553
15554
15555
15556
15557
15558
15559
15560
15561
15562
15563
15564
15565
15566
15567
15568
15569
15570
15571
15572
15573
15574
15575
15576
15577
15578
15579
15580
15581
15582
15583
15584
15585
15586
15587
15588
15589
15590
15591
15592
15593
15594
15595
15596
15597
15598
15599
15600
15601
15602
15603
15604
15605
15606
15607
15608
15609
15610
15611
15612
15613
15614
15615
15616
15617
15618
15619
15620
15621
15622
15623
15624
15625
15626
15627
15628
15629
15630
15631
15632
15633
15634
15635
15636
15637
15638
15639
15640
15641
15642
15643
15644
15645
15646
15647
15648
15649
15650
15651
15652
15653
15654
15655
15656
15657
15658
15659
15660
15661
15662
15663
15664
15665
15666
15667
15668
15669
15670
15671
15672
15673
15674
15675
15676
15677
15678
15679
15680
15681
15682
15683
15684
15685
15686
15687
15688
15689
15690
15691
15692
15693
15694
15695
15696
15697
15698
15699
15700
15701
15702
15703
15704
15705
15706
15707
15708
15709
15710
15711
15712
15713
15714
15715
15716
15717
15718
15719
15720
15721
15722
15723
15724
15725
15726
15727
15728
15729
15730
15731
15732
15733
15734
15735
15736
15737
15738
15739
15740
15741
15742
15743
15744
15745
15746
15747
15748
15749
15750
15751
15752
15753
15754
15755
15756
15757
15758
15759
15760
15761
15762
15763
15764
15765
15766
15767
15768
15769
15770
15771
15772
15773
15774
15775
15776
15777
15778
15779
15780
15781
15782
15783
15784
15785
15786
15787
15788
15789
15790
15791
15792
15793
15794
15795
15796
15797
15798
15799
15800
15801
15802
15803
15804
15805
15806
15807
15808
15809
15810
15811
15812
15813
15814
15815
15816
15817
15818
15819
15820
15821
15822
15823
15824
15825
15826
15827
15828
15829
15830
15831
15832
15833
15834
15835
15836
15837
15838
15839
15840
15841
15842
15843
15844
15845
15846
15847
15848
15849
15850
15851
15852
15853
15854
15855
15856
15857
15858
15859
15860
15861
15862
15863
15864
15865
15866
15867
15868
15869
15870
15871
15872
15873
15874
15875
15876
15877
15878
15879
15880
15881
15882
15883
15884
15885
15886
15887
15888
15889
15890
15891
15892
15893
15894
15895
15896
15897
15898
15899
15900
15901
15902
15903
15904
15905
15906
15907
15908
15909
15910
15911
15912
15913
15914
15915
15916
15917
15918
15919
15920
15921
15922
15923
15924
15925
15926
15927
15928
15929
15930
15931
15932
15933
15934
15935
15936
15937
15938
15939
15940
15941
15942
15943
15944
15945
15946
15947
15948
15949
15950
15951
15952
15953
15954
15955
15956
15957
15958
15959
15960
15961
15962
15963
15964
15965
15966
15967
15968
15969
15970
15971
15972
15973
15974
15975
15976
15977
15978
15979
15980
15981
15982
15983
15984
15985
15986
15987
15988
15989
15990
15991
15992
15993
15994
15995
15996
15997
15998
15999
16000
16001
16002
16003
16004
16005
16006
16007
16008
16009
16010
16011
16012
16013
16014
16015
16016
16017
16018
16019
16020
16021
16022
16023
16024
16025
16026
16027
16028
16029
16030
16031
16032
16033
16034
16035
16036
16037
16038
16039
16040
16041
16042
16043
16044
16045
16046
16047
16048
16049
16050
16051
16052
16053
16054
16055
16056
16057
16058
16059
16060
16061
16062
16063
16064
16065
16066
16067
16068
16069
16070
16071
16072
16073
16074
16075
16076
16077
16078
16079
16080
16081
16082
16083
16084
16085
16086
16087
16088
16089
16090
16091
16092
16093
16094
16095
16096
16097
16098
16099
16100
16101
16102
16103
16104
16105
16106
16107
16108
16109
16110
16111
16112
16113
16114
16115
16116
16117
16118
16119
16120
16121
16122
16123
16124
16125
16126
16127
16128
16129
16130
16131
16132
16133
16134
16135
16136
16137
16138
16139
16140
16141
16142
16143
16144
16145
16146
16147
16148
16149
16150
16151
16152
16153
16154
16155
16156
16157
16158
16159
16160
16161
16162
16163
16164
16165
16166
16167
16168
16169
16170
16171
16172
16173
16174
16175
16176
16177
16178
16179
16180
16181
16182
16183
16184
16185
16186
16187
16188
16189
16190
16191
16192
16193
16194
16195
16196
16197
16198
16199
16200
16201
16202
16203
16204
16205
16206
16207
16208
16209
16210
16211
16212
16213
16214
16215
16216
16217
16218
16219
16220
16221
16222
16223
16224
16225
16226
16227
16228
16229
16230
16231
16232
16233
16234
16235
16236
16237
16238
16239
16240
16241
16242
16243
16244
16245
16246
16247
16248
16249
16250
16251
16252
16253
16254
16255
16256
16257
16258
16259
16260
16261
16262
16263
16264
16265
16266
16267
16268
16269
16270
16271
16272
16273
16274
16275
16276
16277
16278
16279
16280
16281
16282
16283
16284
16285
16286
16287
16288
16289
16290
16291
16292
16293
16294
16295
16296
16297
16298
16299
16300
16301
16302
16303
16304
16305
16306
16307
16308
16309
16310
16311
16312
16313
16314
16315
16316
16317
16318
16319
16320
16321
16322
16323
16324
16325
16326
16327
16328
16329
16330
16331
16332
16333
16334
16335
16336
16337
16338
16339
16340
16341
16342
16343
16344
16345
16346
16347
16348
16349
16350
16351
16352
16353
16354
16355
16356
16357
16358
16359
16360
16361
16362
16363
16364
16365
16366
16367
16368
16369
16370
16371
16372
16373
16374
16375
16376
16377
16378
16379
16380
16381
16382
16383
16384
16385
16386
16387
16388
16389
16390
16391
16392
16393
16394
16395
16396
16397
16398
16399
16400
16401
16402
16403
16404
16405
16406
16407
16408
16409
16410
16411
16412
16413
16414
16415
16416
16417
16418
16419
16420
16421
16422
16423
16424
16425
16426
16427
16428
16429
16430
16431
16432
16433
16434
16435
16436
16437
16438
16439
16440
16441
16442
16443
16444
16445
16446
16447
16448
16449
16450
16451
16452
16453
16454
16455
16456
16457
16458
16459
16460
16461
16462
16463
16464
16465
16466
16467
16468
16469
16470
16471
16472
16473
16474
16475
16476
16477
16478
16479
16480
16481
16482
16483
16484
16485
16486
16487
16488
16489
16490
16491
16492
16493
16494
16495
16496
16497
16498
16499
16500
16501
16502
16503
16504
16505
16506
16507
16508
16509
16510
16511
16512
16513
16514
16515
16516
16517
16518
16519
16520
16521
16522
16523
16524
16525
16526
16527
16528
16529
16530
16531
16532
16533
16534
16535
16536
16537
16538
16539
16540
16541
16542
16543
16544
16545
16546
16547
16548
16549
16550
16551
16552
16553
16554
16555
16556
16557
16558
16559
16560
16561
16562
16563
16564
16565
16566
16567
16568
16569
16570
16571
16572
16573
16574
16575
16576
16577
16578
16579
16580
16581
16582
16583
16584
16585
16586
16587
16588
16589
16590
16591
16592
16593
16594
16595
16596
16597
16598
16599
16600
16601
16602
16603
16604
16605
16606
16607
16608
16609
16610
16611
16612
16613
16614
16615
16616
16617
16618
16619
16620
16621
16622
16623
16624
16625
16626
16627
16628
16629
16630
16631
16632
16633
16634
16635
16636
16637
16638
16639
16640
16641
16642
16643
16644
16645
16646
16647
16648
16649
16650
16651
16652
16653
16654
16655
16656
16657
16658
16659
16660
16661
16662
16663
16664
16665
16666
16667
16668
16669
16670
16671
16672
16673
16674
16675
16676
16677
16678
16679
16680
16681
16682
16683
16684
16685
16686
16687
16688
16689
16690
16691
16692
16693
16694
16695
16696
16697
16698
16699
16700
16701
16702
16703
16704
16705
16706
16707
16708
16709
16710
16711
16712
16713
16714
16715
16716
16717
16718
16719
16720
16721
16722
16723
16724
16725
16726
16727
16728
16729
16730
16731
16732
16733
16734
16735
16736
16737
16738
16739
16740
16741
16742
16743
16744
16745
16746
16747
16748
16749
16750
16751
16752
16753
16754
16755
16756
16757
16758
16759
16760
16761
16762
16763
16764
16765
16766
16767
16768
16769
16770
16771
16772
16773
16774
16775
16776
16777
16778
16779
16780
16781
16782
16783
16784
16785
16786
16787
16788
16789
16790
16791
16792
16793
16794
16795
16796
16797
16798
16799
16800
16801
16802
16803
16804
16805
16806
16807
16808
16809
16810
16811
16812
16813
16814
16815
16816
16817
16818
16819
16820
16821
16822
16823
16824
16825
16826
16827
16828
16829
16830
16831
16832
16833
16834
16835
16836
16837
16838
16839
16840
16841
16842
16843
16844
16845
16846
16847
16848
16849
16850
16851
16852
16853
16854
16855
16856
16857
16858
16859
16860
16861
16862
16863
16864
16865
16866
16867
16868
16869
16870
16871
16872
16873
16874
16875
16876
16877
16878
16879
16880
16881
16882
16883
16884
16885
16886
16887
16888
16889
16890
16891
16892
16893
16894
16895
16896
16897
16898
16899
16900
16901
16902
16903
16904
16905
16906
16907
16908
16909
16910
16911
16912
16913
16914
16915
16916
16917
16918
16919
16920
16921
16922
16923
16924
16925
16926
16927
16928
16929
16930
16931
16932
16933
16934
16935
16936
16937
16938
16939
16940
16941
16942
16943
16944
16945
16946
16947
16948
16949
16950
16951
16952
16953
16954
16955
16956
16957
16958
16959
16960
16961
16962
16963
16964
16965
16966
16967
16968
16969
16970
16971
16972
16973
16974
16975
16976
16977
16978
16979
16980
16981
16982
16983
16984
16985
16986
16987
16988
16989
16990
16991
16992
16993
16994
16995
16996
16997
16998
16999
17000
17001
17002
17003
17004
17005
17006
17007
17008
17009
17010
17011
17012
17013
17014
17015
17016
17017
17018
17019
17020
17021
17022
17023
17024
17025
17026
17027
17028
17029
17030
17031
17032
17033
17034
17035
17036
17037
17038
17039
17040
17041
17042
17043
17044
17045
17046
17047
17048
17049
17050
17051
17052
17053
17054
17055
17056
17057
17058
17059
17060
17061
17062
17063
17064
17065
17066
17067
17068
17069
17070
17071
17072
17073
17074
17075
17076
17077
17078
17079
17080
17081
17082
17083
17084
17085
17086
17087
17088
17089
17090
17091
17092
17093
17094
17095
17096
17097
17098
17099
17100
17101
17102
17103
17104
17105
17106
17107
17108
17109
17110
17111
17112
17113
17114
17115
17116
17117
17118
17119
17120
17121
17122
17123
17124
17125
17126
17127
17128
17129
17130
17131
17132
17133
17134
17135
17136
17137
17138
17139
17140
17141
17142
17143
17144
17145
17146
17147
17148
17149
17150
17151
17152
17153
17154
17155
17156
17157
17158
17159
17160
17161
17162
17163
17164
17165
17166
17167
17168
17169
17170
17171
17172
17173
17174
17175
17176
17177
17178
17179
17180
17181
17182
17183
17184
17185
17186
17187
17188
17189
17190
17191
17192
17193
17194
17195
17196
17197
17198
17199
17200
17201
17202
17203
17204
17205
17206
17207
17208
17209
17210
17211
17212
17213
17214
17215
17216
17217
17218
17219
17220
17221
17222
17223
17224
17225
17226
17227
17228
17229
17230
17231
17232
17233
17234
17235
17236
17237
17238
17239
17240
17241
17242
17243
17244
17245
17246
17247
17248
17249
17250
17251
17252
17253
17254
17255
17256
17257
17258
17259
17260
17261
17262
17263
17264
17265
17266
17267
17268
17269
17270
17271
17272
17273
17274
17275
17276
17277
17278
17279
17280
17281
17282
17283
17284
17285
17286
17287
17288
17289
17290
17291
17292
17293
17294
17295
17296
17297
17298
17299
17300
17301
17302
17303
17304
17305
17306
17307
17308
17309
17310
17311
17312
17313
17314
17315
17316
17317
17318
17319
17320
17321
17322
17323
17324
17325
17326
17327
17328
17329
17330
17331
17332
17333
17334
17335
17336
17337
17338
17339
17340
17341
17342
17343
17344
17345
17346
17347
17348
17349
17350
17351
17352
17353
17354
17355
17356
17357
17358
17359
17360
17361
17362
17363
17364
17365
17366
17367
17368
17369
17370
17371
17372
17373
17374
17375
17376
17377
17378
17379
17380
17381
17382
17383
17384
17385
17386
17387
17388
17389
17390
17391
17392
17393
17394
17395
17396
17397
17398
17399
17400
17401
17402
17403
17404
17405
17406
17407
17408
17409
17410
17411
17412
17413
17414
17415
17416
17417
17418
17419
17420
17421
17422
17423
17424
17425
17426
17427
17428
17429
17430
17431
17432
17433
17434
17435
17436
17437
17438
17439
17440
17441
17442
17443
17444
17445
17446
17447
17448
17449
17450
17451
17452
17453
17454
17455
17456
17457
17458
17459
17460
17461
17462
17463
17464
17465
17466
17467
17468
17469
17470
17471
17472
17473
17474
17475
17476
17477
17478
17479
17480
17481
17482
17483
17484
17485
17486
17487
17488
17489
17490
17491
17492
17493
17494
17495
17496
17497
17498
17499
17500
17501
17502
17503
17504
17505
17506
17507
17508
17509
17510
17511
17512
17513
17514
17515
17516
17517
17518
17519
17520
17521
17522
17523
17524
17525
17526
17527
17528
17529
17530
17531
17532
17533
17534
17535
17536
17537
17538
17539
17540
17541
17542
% $Id: tex4ht-c.tex 417 2018-06-30 22:36:42Z karl $
% tex tex4ht-c
% Copyright 2009-2018 TeX Users Group
% Copyright 1996-2009 Eitan M. Gurari
% Released under LPPL 1.3c+.
% See tex4ht-cpright.tex for license text.

\def\MSVCI{}
\def\MSVCI{NO}

 \def\export{ }

\input common

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
   \input DraTex.sty  \input AlDraTex.sty
   \input tex4ht.sty    
   \Preamble{html,th4,family,sections+,xhtml}
   \EndPreamble

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\expandafter \ifx \csname append:def\endcsname \relax
   \expandafter\def\csname append:def\endcsname#1#2{%
      \def\Xtemp{\def#1}%
      \expandafter\expandafter\expandafter\Xtemp\expandafter{#1#2}}
\fi

\expandafter \ifx \csname Verbatim\endcsname \relax
   \def\Verbatim{\bgroup 
      \catcode`\^=10 \catcode`\\=10  \catcode`\%=10
       \catcode`\{=10    \catcode`\}=10    \catcode`\#=10     \catcode`\#=10
       \XVerbatim}
   \long\def\XVerbatim#1EndVerbatim{\egroup}
\fi

\expandafter \ifx \csname Verb\endcsname \relax
    \def\Verb{\bgroup \catcode`\^=10 \catcode`\\=10  \catcode`\%=10
       \catcode`\{=10    \catcode`\}=10    \catcode`\#=10     \catcode`\#=10
       \leavevmode \Xctgs}
    \def\Xctgs#1{\def\Xeat##1#1{\egroup}\Xeat }
\fi

\ifx \HAssign\UnDef

\csname newcount\endcsname \tmpXxXcnt

\def\advXxX#1{\def\XxXvar{#1}\futurelet\XxXtemp\AdvancXxX}
\def\AdvancXxX{\ifx [\XxXtemp \expandafter\AdvancXxXe
              \else \expandXxXafter{\expandafter\advXxXc\XxXvar}\fi}
\def\AdvancXxXe[#1]{\expandafter\advXxXc\csname
                  \expandafter\string\XxXvar[#1]\endcsname}

\def\gXxXAdvance#1{\bgroup \def\XxXtemp{#1}%
                 \tmpXxXcnt#1\afterassignment\XxXgplus \mthXxXop\tmpXxXcnt}
\def\XxXgplus{\expandafter\xdef\XxXtemp{\the\tmpXxXcnt}\egroup}
\def\XxXAdvance#1{\bgroup \def\XxXtemp{#1}%
                \tmpXxXcnt#1\afterassignment\XxXaplus \mthXxXop\tmpXxXcnt}
\def\XxXaplus{\xdef\XxXtemp{\def\expandafter\noexpand\XxXtemp{\the\tmpXxXcnt}}%
            \egroup \XxXtemp}
\def\HAssign{\XxXssg\edef}
\def\gHAssign{\XxXssg\xdef}

\def\XxXssg#1#2{\let\dXxXfn#1\def\XxXvar{#2}\futurelet\XxXtemp\XxXAssgn}
\def\XxXAssgn{%
   \ifx [\XxXtemp
         \expandafter\dXxXfn\XxXvar[##1]{%
              \noexpand\csname  \expandafter
                                  \string\XxXvar[##1]\noexpand\endcsname}%
         \expandafter\assgXxXm
   \else \afterassignment\assgXxXv \expandafter \tmpXxXcnt \fi }

\def\assgXxXv{\expandafter\dXxXfn\XxXvar{\the\tmpXxXcnt}}
\def\assgXxXm[#1]{%
   \def\XxXtemp{\expandafter\dXxXfn
      \csname \expandafter\string\XxXvar[#1]\endcsname{\the\tmpXxXcnt}}%
   \afterassignment\XxXtemp  \tmpXxXcnt}

\fi
\catcode`\:=11
\csname newcount\endcsname\tmp:cnt
\expandafter\ifx \csname no:catcodes\endcsname\relax
   \def\no:catcodes#1#2#3{%
      \tmp:cnt=#1
      \def\no::catcodes{%
         \catcode\tmp:cnt=#3
         \ifnum\tmp:cnt<#2
             \advance\tmp:cnt by 1  \expandafter\no::catcodes
         \fi }%
      \no::catcodes }
\fi
\let\:oldlq=\`
\let\:oldrq=\'
\def\'{\leavevmode \:cats  \::cats}
\def\::cats#1{\if  #1"\expandafter\:oldrq
              \else  \def\:eat##1#1{\tt ##1\egroup}\expandafter\:eat\fi}
\def\`{\leavevmode \:cats  \:::cats}
\def\:::cats#1{\if #1"\expandafter\:oldlq
               \else \def\:eat##1#1{`{\tt ##1}'\egroup}\expandafter\:eat\fi}
\bgroup
  \catcode`\^=7
  \gdef\:cats{\bgroup  \no:catcodes0{255}{12}\catcode`\ = 10
           \catcode`\^^M = 10 \catcode`\^^I = 10
  }
\egroup
\catcode`\:=12
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\input ProTex.sty

\ifHtml    \AlProTex{c,<<<>>>,`,title,list,ClearCode,_^,CodeLineNo}

    \let\coDE=\<
    \def\<{\vfil\par\coDE}

\else      \AlProTex{c,<<<>>>,`,title,list,[],ClearCode,_^}
\fi


\font\CommentFont=cmitt10
\def\?{\CommentFont}


\ifHtml


\TocAt{Chapter,Section,SubSection,LikeSection,/Appendix,/Part}
\TocAt{Appendix,Section,SubSection,LikeSection,/Chapter,/Part}

%\CutAt{+Part}
\CutAt{Chapter,Part,Appendix}
\CutAt{Appendix,Part,Chapter}

\EveryChapter{\TocChapter %  [\Link[\jobname toc.html]{}{}Expanded toc\EndLink]
             }
\EveryAppendix{\TocAppendix %[\Link[\jobname toc.html]{}{}Expanded toc\EndLink]
              }

\expandafter\let\expandafter\oldbye\expandafter=\csname bye\endcsname

\expandafter\gdef\csname bye\endcsname{%
      \FileStream{\jobname toc.html}%
         \TableOfContents  
      \EndFileStream{\jobname toc.html}%
   \csname oldbye\endcsname}

\else
\hbadness=10000     \vbadness=10000  \hfuzz=99in \vfuzz=99in

\catcode`\:=11

\def\ChildOf{}
\def\ro:nd#1{}
\def\HRefPort\<#1\>{}












\catcode`\:=12

\fi


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% \ChildOf[ChapterCounter]{tex4ht}


\ifx \export\:UnDef \else    \def\CodeId#1#2{} \fi



\def\UnderLine#1{\ifHtml
%   \IgnorePar\EndP
     \HCode{<strong>}#1\HCode{</strong>}\else\underbar{#1}\fi}
\let\CModifyShowCode=\ModifyShowCode
\let\CModifyOutputCode=\ModifyOutputCode
\def\ModifyShowCode{\def\[##1({##1\UnderLine{(}}\def\;{\UnderLine{;}}\CModifyShowCode}
\catcode`\^=7
\catcode`\@=6  \catcode`\#=12 \catcode`\^^M=13\relax%
\def\ModifyOutputCode{%
\def\;{ SEP }%
\def\[@@1(@@2)@@3;{@@1
#ifdef ANSI
#define SEP  ,
(@@3)
#undef  SEP  
#else
#define SEP  ;
(@@2)@@3;
#undef  SEP  
#endif
}%
\CModifyOutputCode}%
\catcode`\^^M=5
\catcode`\@=12
\catcode`\#=6
\catcode`\^=13

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\Part{tex4ht.c}


\TableOfContents[Chapter,Appendix,Section,LikeSection]

\Chapter{Flow of Program}

\input tex4ht-cpright

\Section{Preamble}

A command-line program running in the console environment of the
operating system (MS-DOS, MS-DOS window of Windows 3.1, Unix shell,
etc).  The input is a heavily specialized DVI file.  The main output is
the HTML/XML and \`'.css', also \`'.lg', \`'.idv', and
\`'.tmp'.

\<tex4ht.c\><<< 
/* tex4ht.c (`version), generated from `jobname.tex
   Copyright 2009-2018 TeX Users Group
   Copyright `CopyYear.1996. Eitan M. Gurari
`<TeX4ht copyright`> */
`<tex4ht.h`>
>>>







\<tex4ht.h\><<<
/* Compiler options (uncommented | command line), as comments:

       Classic C (CC)             default
#define ANSI                      ansi-c, c++
#define DOS_C
#define HAVE_STRING_H             <string.h>
#define HAVE_DIRENT_H             <dirent.h>
#define HAVE_SYS_NDIR_H           <sys/ndir.h>
#define HAVE_SYS_DIR_H            <sys/dir.h>
#define HAVE_NDIR_H               <ndir.h>
#define HAVE_IO_H                 <io.h>
#define HAVE_UNISTD_H             <unistd.h>
#define WIN32
#define KPATHSEA             
#define CDECL                     .......
#define BCC32                     bordland c++

*************************************************
    Tex4ht variables                            *
    (uncommented | command line)                *
----------------------------------------------- */
`<h-defines`>
/* ******************************************** */
`<define MSVC-1-52`>
`<bordland: bcc32 -DBCC32 tex4ht`>
`<bordland: bcc -DBCC -mh tex4ht`>
`<DJGPP`>
#ifdef DOS_C
#define DOS
#endif
#ifdef DOS
#define DOS_WIN32
#define HAVE_STRING_H   <string.h>
#endif
#ifdef WIN32
#define DOS_WIN32
#ifndef KPATHSEA
#define HAVE_STRING_H   <string.h>
#endif
#endif
`<h-defines DOS-WIN32`>
`<h-defines KWIN32`>
`<h-include`>
`<h-defines 2`>
>>>

%  lint tex4ht.c -DHAVE_DIRENT_H -DHAVE_STRING_H

\<bordland: bcc32 -DBCC32 tex4ht\><<<
#ifdef BCC32
#define DOS_WIN32 
#define ANSI
#define HAVE_DIRENT_H 
#define PLATFORM "ms-win32"
#endif
>>>

The \`'-mh' below calls for `Huge Memory Model'.

\<bordland: bcc -DBCC -mh tex4ht\><<<
#ifdef BCC
#define DOS_C
#define ANSI       
#define HAVE_DIRENT_H 
#define PLATFORM "ms-dos"
#ifndef PATH_MAX
#define PATH_MAX 256
#endif
#endif
>>>



\ifHtml[\HPage{more}\Verbatim
> 1) I think there is a bug in Tex4ht (perhaps in the Dos'port), because 
> it doesn't find the .tfm files when they are in different directories 
> (with the ! at the end of the "tc:d:\share\texmf\fonts\tfm!"). I am 
> obliged to put all the files in a common directory.

The directory search has been disabled for the DOS port with
the following code.

#define DOS
#define NOSUBDIR
#endif

I'm not sure the decision to disable recursive searches was a good one,
and I'll probably reinstate recursive searches in the next version.

If you compiled the source code, instead of downloading an executable
application, try recompiling the source, after removing the above
segment of code.

\EndVerbatim\EndHPage{}]\fi

 microsoft visual c options: msdos application (.exe), large, ss=sd 

\Verbatim
#define MSVC_1_52_DOS
#define MSVC_1_52_DOS_LIB         not fully implemented 
------------------------------------------------------------
    End options --- Start comments                         *
------------------------------------------------------------
MSVC_1_52_DOS:                                             *
   MS-DOS appl (project type), release (buld mode),        *
     huge, ss==ds, 80286, no debug                         *
   no sub directories (missing opendir,closedir, readdir)  *
MSVC_1_52_DOS_LIB:                                         *
   as above, but opendir,closedir, readdir compiled        *
   with tex4ht                                             *
------------------------------------------------------------
    End comments                                           
\EndVerbatim


\<h-include\><<<
#ifdef KPATHSEA
#include <kpathsea/config.h>
#endif
#include <stdio.h>   `% EOF, FILE `%
#include <stdlib.h>  `% EXIT_FAILURE `%
>>>

\<defines\><<<
#ifndef EXIT_FAILURE
#define EXIT_FAILURE 1
#endif
>>>

\<h-include\><<<
#ifdef HAVE_STRING_H
#include <string.h>
#endif
>>>









  Under ANSI C, all malloc stuff is declared in \`'<stdlib.h>' (which you
also include), hence this non-standard header is redundant.


\SubSection{MSVC-1-52-DOS}


\<define MSVC-1-52\MSVCI\><<<
#ifdef MSVC_1_52_DOS_LIB
#define  MSVC_1_52_DOS
#endif
#ifdef MSVC_1_52_DOS
#define DOS
#define NOSUBDIR
#endif
#ifdef MSVC_1_52_DOS_LIB
#undef NOSUBDIR
#endif
>>>

\<if not-def MSVC-1-52\MSVCI\><<<
#ifndef MSVC_1_52_DOS
>>>

\<endif not-def MSVC-1-52\MSVCI\><<<
#endif
>>>





\SubSection{KPATHSEA Windows}






% #define NOSUBDIR

%  MSVC_1_52_DOS -> DOS, NOSUBDIR,   not  <dirent.h>

% ANSI  --> PROTOTYPE
% DOS ->  <string.h>







\<h-defines KWIN32\><<<
#ifdef KPATHSEA
#ifdef WIN32
#define KWIN32  
#endif
#endif
>>>


Here are the promised patch. However I have not yet tested it very
much. It is unlikely that I test it with non-kpathsea setting. At
least the patch compiles in both kpathsea and non-kpathsea setting.
 The following patch is very similar
to some code  in kpathsea / web2c.


\<h-include\><<<
#ifdef WIN32
#ifdef KPATHSEA 
#undef CDECL 
#define CDECL                     __cdecl
#else
#include <windows.h>
#endif
#else
#ifdef KPATHSEA 
#define CDECL                  
#endif
#endif
>>> 

\<if not-WIN32\><<<
#ifndef WIN32
>>>

\<endif not-WIN32\><<<
#endif
>>>



\<header functions\><<<
#ifdef WIN32
static BOOL sigint_handler(ARG_I(DWORD));
#endif
>>>

\<functions\><<< 
#ifdef WIN32


`[
static BOOL  sigint_handler(dwCtrlType)  DWORD dwCtrlType
;{  
  `<avoid warning of unused dwCtrlType`>
  err_i(32);
  return FALSE;      `% return value obligatory `%
}
#endif
>>>

\<avoid warning of unused dwCtrlType\><<<  
if( dwCtrlType ){ (IGNORED) printf(" "); }
>>>


\<CDECL\><<< 
#ifdef CDECL
CDECL
#endif
>>>
 

 
Forgetting \`'_pascal' and \`'_cdecl' modifiers: Each C function may
be either \`'_pascal' or \`'_cdecl'. This modifier defines how
parameters are passed to it. Default for Smalltalk definition is
\`'_cdecl'. Default for C functions depends on compiler settings, and
you can use other types uncompatible with Smalltalk. In Windows API
16-bit functions are \`'_pascal' and 32-bit \`'_cdecl'.
 


The following  Shared across recursive calls, it acts like a stack.



\<vars\><<<
#ifdef WIN32
static U_CHAR dirname[PATH_MAX];
#endif
>>>

Recursive directory search relies on some Windows API similar to
opendir/readdir  

\<file = search WIN32 subdir (name,str)\><<<
{
    WIN32_FIND_DATA find_file_data;
    HANDLE hnd;
    int proceed;
    (IGNORED) strcpy((char *) dirname, (char *) str);
    strct(dirname, "/*.*");       `% "*.*" or "*" -- seems equivalent. `%
    hnd = FindFirstFile(dirname, &find_file_data);    
    if (hnd != INVALID_HANDLE_VALUE) {
      `<valid WIN32 handle`>
    }
}
>>>
 
\<valid WIN32 handle\><<<
proceed = 1;
while (proceed) {
  if( !eq_str(find_file_data.cFileName, ".")  &&
      !eq_str(find_file_data.cFileName, "..") )
    { 
      (IGNORED) strcpy((char *)  str+n, (char *) find_file_data.cFileName );
      str[n-1] = dir_path_slash(str);
      if (find_file_data.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
  if( (file = search_file_ext(name, str, flags)) != NULL ){
    FindClose(hnd);
    return file; }
      }
    }
  proceed = FindNextFile(hnd, &find_file_data);
}
FindClose(hnd);
>>>


SIGFPE is handled by the C library, SIGSEGV too but not generated by
the system, so it does nothing but is harmless 

SetConsoleCtrlHandler is need to catch Ctrl+C and Ctrl+Break under
Windows, SIGINT is not generated by the system.
 
\<KWIN32 signals\><<<
SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
>>>






\SubSection{DJGPP}


\Verbatim

        * tex4ht.c [__DJGPP__] (ANSI, DOS_GIF_FILE): Define.
        (LSTAT): Define to stat for every system that doesn't define
        S_ISLNK.
        (WRITE_BIN_FLAGS, READ_BIN_FLAGS): Use binary mode with DJGPP.
        (dos_file_names): New variable.
        [WIN32] (sigint_handler): Add missing semi-colon in prototype
        declaration.
        (sig_err): If got fatal signal other than SIGINT or SIGQUIT, don't
        return to caller, since the program will be aborted otherwise.
        (search_file_ext): Allow use of both forward- and back-slashes on
        DOS and Windows platforms.
        (insert_ch) [DOS_GIF_FILE]: Only use butchered file name if long
        file names aren't supported (dos_file_names is TRUE).
        (main) [KPATHSEA]: If input is from stdin which is not a console
        device, switch it to binary mode.  Set dos_file_names to TRUE for
        all DOS platforms, FALSE on Unix and WIN32, and compute at runtime
        for DJGPP.  Simplify logic of finding the init file by pushing
        HOME=C: into environment if $HOME isn't defined on DOSISH systems.
        Only use butchered file names for GIF files if long file names
        aren't supported (dos_file_names is TRUE).
\EndVerbatim



\<DJGPP\><<<
#ifdef __DJGPP__
#define DOS_WIN
#define ANSI
#ifndef HAVE_STRING_H
#define HAVE_STRING_H 1
#endif
#endif
>>>

\<vars\><<<
static BOOL dos_file_names =
#ifdef DOS_GIF_FILE 
  TRUE
#else
  FALSE
#endif
;
>>>



 Set dos\_file\_names to TRUE for
        all DOS platforms, FALSE on Unix and WIN32, and compute at
runtime
        for DJGPP.

\<DJGPP gif names for pictorial symbols\><<<
#if !defined(DOS_GIF_FILE) && !defined(WIN32) && defined(__DJGPP__)
   dos_file_names = !_use_lfn(NULL);
#endif
>>>


\<extra options\><<<
switch( *(p+2) ){
  case 's':{   dos_file_names = TRUE;  break; }
   default:{ bad_arg; }
}
>>>


\Verbatim

 > The diffs are attached below.  The first hunk is because HAVE_STRING_H is 
 > already defined by c-auto.h that's generated by configure, and GCC 
 > complained about redefinition.  The second hunk just moves the call to 
 > _use_lfn to a place where the variable "name" is defined.  _use_lfn needs 
 > an actual file name as argument, because the support for long file names 
 > is determined dynamically for each filesystem.  (There can be cases where 
 > you run on Windows 9X, where DJGPP supports long file names, but one or 
 > more of the file names passed to tex4ht reside on some networked drive 
 > mounted with a network client which doesn't support long file names.)




> Now, do we want tex4ht to propose a long and a short name for each
> output file, and determine in each case which of the two names to
> assign according to whether `use_lfn(name)' accepts the long name?

That's what I had in mind, yes.

The philosophy behind that is that DJGPP executables should use long
file names whenever they are available.  However, given that there are
several different filesystems accessible from the machine (via a
network), long names might be supported by some of these filesystems,
but not by others.  So the DJGPP version needs to decide whether or
not to use the long name for every command-line argument it processes,
since each such argument can belong to a different filesystem.

For example, suppose tex4ht.exe is invoked like this:

             tex4ht c:/foo/bar/baz.dvi d:/dvi/xyz.dvi

If the C: drive supports long file names, but D: does not (because it
is mounted by a network software which doesn't support long file
names), my intent was that tex4ht will behave differently with each
file.


This feature turns out to be too expensive to utilize in tex4ht.c.
The problem is that tex4ht first creates the html files from the dvi
source, and during this phase it determines which pictorial symbols
are needed. The gif files of the pictorial symbols get their names
during this phase. However, the gif files themselves are created only
at the end of the compilation, after all the names have been already
determined and used.


Anyway, the fallback should be to determine the value of dos_file_names
(sp?) once, in the beginning of `main', by calling _use_lfn(NULL).  This
checks long file name support by the default filesystem, which is usually
a good indication of other filesystems as well.



Corrections to my previous email:

In the first phase, tex4ht.c extracts the html code from the dvi file
and, along this process, determines the names of the gif files for the
pictorial symbols in use.  The following code fragement is responsible
for getting the names.

   if( !dos_file_names ){
      print_f(font_tbl[cur_fnt].name);
      if( mag == 10 )  (IGNORED) sprintf(str, GIF_I,   design_ch, gif);
      else             (IGNORED) sprintf(str, GIF_II,  mag, design_ch,
   gif);
   }

In the second phase, tex4ht.c creates a dvi page for each of the
pictorial symbols in use, places the code in the idv file, and puts in
the lg file requests for translating the dvi pages into gif files of
the specified names.  The file names are provided by the following
code.

   if( !dos_file_names ){
      if( mag == 10 ) (IGNORED) sprintf(str, ``%s-%x%s'',
                              font_tbl[cur_fnt].name, ch, gif);
      else            (IGNORED) sprintf(str, ``%s-%x-%x%s'',
                              font_tbl[cur_fnt].name, mag, ch, gif);
   }

tex4ht.c never gets to create the gif files.  Instead, t4ht.c scans
the lg file, and use that information to invoke auxiliary tools for
translating the dvi pages into gif files.



Added also a command line switch -xs to allow forcing of short names
for the gif files.
\EndVerbatim


\<DJGPP signals\><<<
#ifdef __DJGPP__
  if (s != SIGINT && s != SIGQUIT)
    exit(EXIT_FAILURE);
#endif
>>>

\SubSection{Compatibity}

\Verbatim
 > The style file provides a set of commands for requesting html code.
 > The user may insert these commands to the source code, and tex4ht will
 > use them to create the desired output.  I placed a more detailed
 > overview with examples in
 >       http://www.cse.ohio-state.edu/~gurari/temp/XXX/

  I've downloaded the Essential Tex example, and managed to convert it
(sort of). There are a few problems with file name lengths - I had to
rename the file to es.tex to get it to be processed properly. According
to the .lg file I should have a lot of es.idv[xx] files; since DOS only
supports 3 character extentions, they had all overwritten each other
(truncating the extention to .idv), so I only had one file. Trying to
view this file made my driver complain that it was corrupt (it lacked a
postamble).

  Basically, most of the functionality seems to work under DOS, but the
file naming conventions appear to be a problem. If you want a more
detailed report of the problems, let me know.

 > I have no problems dealing with C code, but I'm not familiar with the
 > different standards (including ANSI C) and libraries that exist
 > around.  I'll need to overcome this deficiency to make tex4ht.c a
 > portable utility.

  I've been following comp.lang.c for quite a while now, which focuses
strongly on portable (ANSI) C, so I have some insight in that. If you
solely use the ANSI C library functions (which should be possible, I
think), you don't need to worry about portability - any conforming
compiler can generate the code. For example, I noticed that your code
includes:


  Under ANSI C, all malloc stuff is declared in <stdlib.h> (which you
also include), hence this non-standard header is redundant.

  Looking a bit better at the source code, I found that I could rid
myself of all the prototype problems by defining ARG. For ANSI, this
should be the default. If you really want to go for ANSI, you can get
rid of all these ARG_I macro's and fully and unconditionally prototype
everything.

All of the "const is long" warnings can be fixed by appending a "L"
after all constants bigger than 32767. The "conversion may loose
significant digits" warnings appear to be related with indexing arrays
with longs - I haven't figured this one out yet, as far as I know ANSI
allows this. (DOS compilers generally don't support it, though - I can
just turn off this warning).

  A few warnings result from using an assignment inside an if-clause,
mostly with file opening code (e.g. "if(name = fopen(stuff)){file is
open}"). Changing this to an explicit comparison to NULL ("if((name =
fopen(stuff)) != NULL)") kills the warnings while allowing the compiler
to warn you when you typed "=" where you ment "==".

  One last thing I noticed: after other attempts at opening "tex4ht.env"
have failed, you try to open "C:\.tex4ht". Since DOS doesn't allow files
with no name (only an extention), and the maximum size of the extention
is 3 chars anyway, this will always fail - so this code can be deleted.

 > I'll get an ANSI C compiler for my PC, and will fix tex4ht.c to deal
 > also with that standard.  I'll might ask your advice regarding
 > searching directories and files on pc's, but if this will be the case
 > I'll prepare a small toy example capturing the features I need.

  You may be used to stuff like opendir/readdir/closedir; I believe
there is code in the snippets maintained by Bob Stout that emulates
these calls under DOS. If you place this stuff in a separate module,
your main code can remain portable (it is a good idea to separate the
non-portable stuff from the portable code).

  Note that a port of gcc to DOS exists (djgpp), which eliminates many
of the porting problems. It still would be nice if it compiled
error-free on my native DOS compiler, though.

\EndVerbatim


\Verbatim
  Good - I'm glad that I'm of some help. The code snippet you sent me
compiled without a single warning here, so you're on the right track
(although stuff like stat() isn't ANSI, it appears supported by a lot of
compilers).

  I compiled the source with the defines DOS and ANSI - and most of it
worked. You forgot the terminating quote for "tex4ht.env on line 1715. I
also get warnings that denominator and numerator are not being used
(only assigned to) and, from the source, the warning appears to be
correct.

  If I turn on my compilers ANSI flag, I have a few problems. First,
your function declarations are still in K&R style C. Although ANSI
allows that, it prohibits type checking, and gives some problems with
argument promotion. Specifically, the function insert_ch_map() gives
problems. Your declaration looks like this (I reformatted it a bit for
readability ;-):

void  insert_ch_map(ch, tag)
  char ch;
  BOOL tag;
{ /* etc */

  Changing this to the normal ANSI definition shuts up my compiler:

void  insert_ch_map(char ch, BOOL tag) { /* etc */

  I suggest that you change your other function definitions to ANSI
style too (if you still want to go for ANSI, that is).

  Another problem I ran into is that _fileno is unavailable to both
compiler and linker if I turn on ANSI compilation. I checked where you
use it, and it is in only one place, to find the file length of the DVI
file. Your code:

  struct STSTAT temp;
  (IGNORED) fstat (fileno(dvi_file), &temp);
  file_len = (long) temp.st_size;
  if( (file_len % 4) != 0 )  bad_dvi;

If you change this to use ftell and fseek, you'll have gained ANSI
compatibility (and therewith portability). I tried the following code
instead of yours:

  long  curr_pos;

  curr_pos = ftell(dvi_file);
  fseek(dvi_file, 0, SEEK_END);
  file_len = ftell(dvi_file);
  fseek(dvi_file, curr_pos, SEEK_SET);
  if( (file_len % 4) != 0 )  bad_dvi;

  To the best of my nowledge, this works exactly like your code (I
tested it). My executable is compiled with this code.

  I've found other non-ANSI stuff that you may want to remove; if you'd
like me to check for it (and, if I can, suggest an ANSI alternative),
let me know. I've found at least access() - I haven't looked into how to
do that portably.

 > With the new versions of the tools,  and the parameter `htm' (instead of
 > `html') in \Preamble, the full name gentle.tex can be used.

  Yes, this appears to be working now.

 > A line of the form

 >      -+- needs -+- es.idv[xx] ==> abc.gif -+-

 > in the .lg file asks that the xx'th page of es.idv will be translated
 > into a gif picture and be stored in file abc.gif.

  OK, I misunderstood that. I will hold off looking into the picture
translation for a bit - but this seems like a job for perl. There is a
DOS port of perl, and I'm just familiarizing myself with it. I don't
know if the port is able to launch sub-processes. If not, I could
probably come up with an awk or perl script that creates a batch file to
do the job. (Requiring awk may be nicer than requiring perl, since the
DOS port of awk is only a little over 90 KB, while perl is seven times
as large). Alternatively, you could perhaps change the format of the lg
file a bit, to contain lines like:

convert es.idv xx abc.gif

i.e., provide the required information as dvi file, page number, and
output filename on the commandline of "convert" (or however you want to
call it). This could that be used almost without effort as shell script
or batch file.

 > After getting your last email, I bought Turbo C++ 4.5 for windows (I
 > couldn't find one for dos without reaching to a very fat system). I
 > tried the attached program in different modes, including ANSI C, and
 > to my surprise opendir/readdir/closedir worked fine.

  Here too. Strange. Opendir etc is not ANSI, but it is Posix - and
apparently Borland added some posix stuff to their libraries. I'm not
sure if you should stick with them or not. I haven't studied that part
of your source code yet, so I can't say if it can be easily ANSIfied. If
we stick with this, and later you want to port to Apple, Amiga,
whatever, you're probably in trouble.

 > That left me even more puzzled to why my version of MSVC doesn't
 > support these functions.

  They're Posix - a Unix standard. Apparently they felt is wasn't
appropriate for DOS.

  A few notes on the working of tex4ht.sty: Some of my code doesn't
compile because I have \label{}s inside sectioning commands. LaTeX
itself does allow this. Also, all headings are links to themselves -
why?

  Below, I included a LaTeX source that both your code and LaTeX2HTML
can't seem to translate properly - but then, I hardly know anything of
the possibilities of tex4ht.sty. Have you started any form of
documentation yet? (I don't read TeX, only LaTeX, so looking at the sty
file myself didn't help much).



\documentclass[11pt]{article}
\usepackage{alltt}

%% Environment to typeset screen text, menus etc. in: verbatim-style
%% and boxed.

\newsavebox{\scrntxt}
\newenvironment{boxedfig}[2]%
 % First argument is width of box, second is caption text
 { \newcommand{\capt}{#2}% To transport caption to end of environment
   \begin{minipage}[b]{#1}%
   \begin{lrbox}{\scrntxt}\begin{minipage}{\textwidth}%
   \fontsize{10}{11}\selectfont\begin{alltt}%
 } %
 { \end{alltt}\end{minipage}\end{lrbox}\setlength{\fboxsep}{3pt}%
   \framebox[\textwidth][l]{\usebox{\scrntxt}}\caption{\capt}%
   \end{minipage}%
 }

\begin{document}

Below you will find two figures. They are boxed neatly, and typeset in a
fixed-width font of a size independent of the main font size.

\begin{figure}[htb]
\begin{boxedfig}{0.495\textwidth}{The MBR 1 boot menu\label{bootmenu:1}}
Please select partition too boot.
Choose from:

1. 123456789AB
2. 123456789AB
3. 123456789AB
4. 123456789AB

?
\end{boxedfig}\hfill
\begin{boxedfig}{0.495\textwidth}{The MBR 2 boot menu\label{bootmenu:2}}
Please select partition too boot.
Choose from:

1. 12345678
2. 12345678
3. 12345678
4. 12345678

Boot?
\end{boxedfig}
\end{figure}

I want to be able to reference both
figure~\ref{bootmenu:1} and figure~\ref{bootmenu:2} from my HTML file.
How to achieve this?

\end{document}

\EndVerbatim

\<defines\><<<
#if INT_MAX < 2147483647L  `%2^31`%
#define LONG L
#endif
>>>

Lint does not like non-null pointers to be cast.
\`'free(void *)'  instead of \`'free()' will make lint to stop
complaining, but is this really the problem. For this function we have a
definition \`'void free(void *)'.


\`'1<<20'  should be \`'1L<<20' for short integer.

Integers on Dos they are just 16 bits!!!  Also, ordering of bytes is
inconsistence.





\<h-include\><<<
#include <limits.h> `% INT_MAX `%
>>>

\<defines\><<<
#ifdef LONG 
#define INTEGER long
#else
#define INTEGER int
#endif
#define U_CHAR char
>>>






\Verbatim
string.h:     extern int strlen( );
string.h:          extern size_t strlen(char *);
string.h:          extern size_t strlen(const char *);
string.h:       extern size_t strlen( );

void * realloc( void *, size_t) 
\EndVerbatim


\<resplit argv for windows\><<<
#ifdef WIN32
  /* The idea here is to split options apart at spaces: a single argument
     "-foo -bar" becomes the two options "-foo" and "-bar".  We need to
     do this for Windows because mk4ht passes this sort of combined
     option in one string to scripts like htlatex.{unix,bat}.  In the
     Unix case, the shell resplits words when calling t4ht and tex4ht,
     so the program see two options.  But this does not happen with the
     .bat; %4, for instance, remains "-foo -bar".  So we fix it here.  */
  if (argc > 2) {
    int  i, nargc;
    char **nargv, **pnargv, **pargv;

    nargv = (char **) xmalloc (2 * argc * sizeof (char *));
    pnargv = nargv;
    pargv = argv;
    *pnargv++ = xstrdup (*pargv++);
    *pnargv++ = xstrdup (*pargv++);
    nargc = 2;

    for (i=2; i < argc; i++) {
      char *p, *q, *r;
      p = q = *pargv++;
      while (*p == ' ' || *p == '\t') {
        p++;
        q++;
      }
      while (*p != ' ' && *p != '\t' && *p) {
        p++;
        if (*p == '\0') {
          *pnargv++ = xstrdup(q);
          nargc++;
        } else if (*p == ' ' || *p == '\t') {
          r = p;
          while (*p == ' ' || *p == '\t')
            p++;
          if (*p == '-' || *p == '\0') {
            *r = '\0';
            *pnargv++ = xstrdup(q);
            nargc++;
            q = p;
          }
        }
      }
    }

    nargv[nargc] = NULL;
    argv = nargv;
    argc = nargc;
  }
#endif
>>>


\SubSection{Signals}

\<h-include\><<<
#include <signal.h>
>>>

\<header functions\><<<
static  void 
`<CDECL`>
sig_err(ARG_I(int));
>>>




\<functions\><<<
`[
static void
`<CDECL`>
sig_err(s)  int s
;{
  (void) signal(s,SIG_IGN);  `%ignore the signal`%
  switch( s ){
#ifdef SIGSEGV
    case SIGSEGV: err_i(30); 
#endif
    case SIGFPE : err_i(31);  
#if defined(SIGINT) && !defined(WIN32)
    case SIGINT : err_i(32);
#endif
  } 
  `<DJGPP signals`>
}
>>>

DJGPP:(sig\_err): If got fatal signal other than SIGINT or SIGQUIT, don't
        return to caller, since the program will be aborted otherwise.




\<set signals\><<<

#ifdef SIGSEGV
  (void) signal(SIGSEGV,sig_err);
#endif
  (void) signal(SIGFPE,sig_err);
#ifdef WIN32
  `<KWIN32 signals`>
#else 
#ifdef SIGINT
  (void) signal(SIGINT,sig_err);    `%Control-c, user interrupt`%
#endif
#endif
>>>


SIGSEGV, SIGILL, SIGTERM not implemented in MS-DOS. They are supplied just for
compatibility. Looks like that SIGINT is defined for windows but not for dos.
\ifHtml[\HPage{more}\Verbatim
    Eitan> I also wonder whether the WIN32 really needs to discard the
    Eitan> following code fragment.

signal() is supported through the standard libc, but is mostly
ineffective. An example of the kind of code needed is attached.


/* Interrupt handler. mt_exit() is a cleanup_and_exit function */
#ifdef _WIN32
BOOL sigint_handler(DWORD dwCtrlType)
{
  mt_exit(3);
  return FALSE;      /* return value obligatory */
}
#else
void sigint_handler (int sig)
{
  mt_exit(3);
}
#endif

  /* Catch signals, so we clean up if the child is interrupted.
     This emulates "trap 'whatever' 1 2 15".  */
#ifdef _WIN32
  SetConsoleCtrlHandler((PHANDLER_ROUTINE)sigint_handler, TRUE);
#else
# ifdef SIGINT
  signal (SIGINT, sigint_handler);
# endif
# ifdef SIGHUP
  signal (SIGHUP, sigint_handler);
# endif
# ifdef SIGTERM
  signal (SIGTERM, sigint_handler);
# endif
#endif
\EndVerbatim\EndHPage{}]\fi

Msvc recommends not using printf, but we ignoring this recommendation
here with the assumption that the recommendation relates to I/O
interrupts that are not considered here.

\<signals messages: 30-32\><<<
"Illegal storage address\n", `%30 segmentation`%
"Floating-point\n",          `%31 `%
"Interrupt with Cntr-C\n",   `%32 `% 
>>>



\Section{Kpathsea}


\<KPATHSEA h-include\><<<
#ifdef KPATHSEA
#include <kpathsea/c-errno.h>
#include <kpathsea/c-ctype.h>
#include <kpathsea/c-fopen.h>
#include <kpathsea/c-pathmx.h>
#include <kpathsea/proginit.h>
#include <kpathsea/tex-file.h>
#include <kpathsea/tex-make.h>
#include <kpathsea/variable.h>
#include <signal.h>
#if !defined(_AMIGA) && !defined(WIN32)
#include <sys/time.h>
#endif
#include <fcntl.h>
#include <setjmp.h>
#endif `%/* KPATHSEA */`%
>>>

\List{*}
\item
The \`'__cdecl' is defined in KPATHSEA: kpathsea/c-protos.h 
is defined to nothing for compilers
other than MS.
\item
Compiling for kpathsea:
\List{*}
\item Download \Link[http://www.xs4all.nl/\string
~infovore/tex4htk.tgz]{}{}{http://www.xs4all.nl/\string
~infovore/tex4htk.tgz}\EndLink.
\item At texk, issue the commands \`'./configure' and \`'make'.
\EndList
\item
In the presence of kpathsea, there is no reason for the explicit
t-records in tex4ht.env.  All tex4ht needs is just the information
available to latex about the tfm files, and kpathsea already embeds
it.
\item
To my understanding, the value of @texmf@ is known to kpathsea within
some variable (TEXMF?). The value of that variable can be accessed by
tex4ht through \`'kpse_var_value( "TEXMF" )'.  So i-records similar to the
following ones may provide to tex4ht the information needed to locate
the files.

\Verbatim
  ikpatsea{TEXMF}\tex4ht\ht-fonts\
  ikpatsea{.....}\tex4ht\ht-fonts\

\EndVerbatim

Of course, I rather have texht request kpathsea to perform the search,
but I don't know how to request it through a command similar to the
following one.

\Verbatim
     extended_kpse_find_file(filename, var, path, ...)
                                       ^^^
                                     "TEXMF"
                                            ^^^^^
                                           "\tex4ht\ht-fonts\"
\EndVerbatim

I don't yet follow the details of \`'client_path' but I suspect it might
provide support for instructions similar to the above.

\EndList







%%%%%%%%%%%%%%%%%%
\Section{Outline}
%%%%%%%%%%%%%%%%%%

\<tex4ht.c\><<<
`<defines`>
`<types`>
`<vars`>
`<header functions`>
`<functions`>
`[
int `<CDECL`> main(argc, argv)
       int  argc`;  
       U_CHAR **argv
;{  `<main's vars`> 
   `<resplit argv for windows`>
   `<set signals`>
   `<program signature`>
   `<init traces`>
   `<main's init`> 
   `<main's body`>  
   return 0;
}
>>>

The operating system claims that
`Compilation exited abnormally with code 255' even on cases that
come back through return. why?  Was this corrected?




\<program signature\><<<
(IGNORED) printf("----------------------------\n");
#ifndef KPATHSEA
#ifdef PLATFORM
   (IGNORED) printf("tex4ht.c (`version %s)\n",PLATFORM);
#else
   (IGNORED) printf("tex4ht.c (`version)\n");
#endif
#else
#ifdef PLATFORM
   (IGNORED) printf("tex4ht.c (`version %s kpathsea)\n",PLATFORM);
#else
   (IGNORED) printf("tex4ht.c (`version kpathsea)\n");
#endif
#endif
for(i=0; i<argc; i++){ 
    (IGNORED) printf("%s%s ", (i>1)?"\n  " : "", argv[i]); }
(IGNORED) printf("\n");
>>>


\SubSection{Main's Body}


\<main's body\><<<
{      long   file_len;
  `<scan job args`>
  `<find tex4ht.env`>
  `<get from tex4ht.env file`>
  `<file-len = size of file`>
  `<open log file`>
  `<export TEX4HTFONTSET`>
  `<scan postamble`>
  (IGNORED) fclose(dot_file);
}
`<scan preamble`>
`<scan pages`>
put_char('\n');put_char('\n');
`<close active output files`> 
{    `<idv vars`>  
  `<extract dvi chunks`> }
>>>



\<vars\><<<
static FILE*  dot_file;
>>>

\<main's vars\><<<
register INTEGER  i;
int  ch;
>>>


\SubSection{Utilities}




\<defines\><<<
#define m_alloc(typ,n) (typ *) malloc_chk((int) ((n) * sizeof(typ)))
>>>



\<header functions\><<<
static void* malloc_chk(ARG_I(int));
>>>

\<functions\><<<
`[
static void* malloc_chk( n ) int n
;{      void* p;
   if((p = (void *) malloc( (size_t) n)) == NULL ) bad_mem;
   return p;
}
>>>




\<header functions\><<<
static void* r_alloc(ARG_II(void *, size_t));
>>>

\<functions\><<<
`[
static void* r_alloc( q, n ) 
      void   *q`;
      size_t  n
;{    void*   p;
   if((p = (void *) realloc( q, (size_t) n)) == NULL) bad_mem;
   return p;
}
>>>

\Section{Installers and Makefiles}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Command Line Switches}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

% q, *

\<scan job args\><<<
{      int i;
       U_CHAR *p;
       const U_CHAR *in_name = "", *out_name = "";
  `<kpathsea arg 0`>
  `<DJGPP gif names for pictorial symbols`>
  if( argc == 1 ){ bad_arg; }
  for(i=1; i<argc; i++) {
    if( *( p=argv[i] ) == '-' ){ `<scan flaged args`> }
    else in_name = argv[i];
  }
  `<post scan comm ln args`>
  `<open input file`>
  { `<pre open output file`> }
}
>>>


If \`'strlen()  argv[i] ) == 2' the switch is followed by a
space to be deleted when more input is awaited.





\<scan flaged args\><<<
if( (int) strlen((char *)  argv[i] ) == 2 ){
   if( ++i == argc ) bad_arg;  
} 
switch( *(p+1) ){
  case 'b':{ `<get start char-gif from com ln`>     break; }
  case 'c':{ `<env blocks selector`>  break;}   
  case 'e':{ `<get .env directory from com ln`>break; }
  case 'f':{ `<get file name wo dir`>break; }
  case 'F':{ `<get ignored chars`>             break; }
  case 'g':{ `<get gif-type from com ln`>      break; }
  case 'h':{ `<trace context`>  break; }
  case 'i':{ `<get htf font dir from com ln`>  break; }
  case 'l':{ `<get tex4ht.fls from com ln`>  break; }
  case 'P':{ `<permission for system calls`>  break; }
  case 'S':{ `<get gif script from com ln`>    break; }
  case 's':{ `<get cascade style sheet data`>    break; }
  case 't':{ `<get tfm font dir from com ln`>  break; }
  case 'u':{ `<get unicode entity representations`>  break; }
  case 'v':{ `<idv version replacement num`>  break; }
  case 'x':{ `<extra options`>  break; }
  case '.':{ `<default extension`>  break; }
   default:{ bad_arg; }
}
>>>



The following is to allow for commands \`'htlatex
-f/../source/foo.tex' which draw files from other directories for
latex, but use the current directory for tex4ht.c (and t4ht.c). The
character immediately after \`'-f' is a directory indicator character.
The \`'-f/' requests a search for the indicated file to take place in
the current directory, not in a remote one.

\<get file name wo dir\><<<
p = p + 2;
in_name = p + (int) strlen((char *)  p );
while( *in_name != *p ){ in_name--; }
in_name++;
>>>


Suboptions for \`'-h'.

\<trace context\><<<
{
  char trace = *(p+2);
  if (trace == 'A' || trace == 'e') { `<context for warn and errs`> }
  if (trace == 'A' || trace == 'f') { `<dump htf files`> }
  if (trace == 'A' || trace == 'F') { `<trace htf search`> }
  if (trace == 'A' || trace == 's') { `<trace specials in dvi`> }
  if (trace == 'A' || trace == 'g') { `<cmd line trace groups`> }
  if (trace == 'A' || trace == 'v') { `<dump env file`> }
  if (trace == 'A' || trace == 'V') { `<trace env search`> }
  else { bad_arg; }
}
>>>

The following is incomplete!!!


\<command line options\><<<
"improper command line\ntex4ht [-f<path-separator-ch>]in-file[.dvi]\n"
"   [-.<ext>]            replacement to default file extension name .dvi\n"
"   [-c<tag name>]       choose named segment in env file\n"
"   [-e<env-file>]\n"
"   [-f<path-separator-ch>]        remove path from the file name\n"
"   [-F<ch-code>]        replacement for missing font characters; 0--255; default 0\n"
"   [-g<bitmap-file-ext>]\n"
"   [-h[efFgsvVA]]       trace: e-errors/warnings, f-htf, F-htf search\n"
"                           g-groups, s-specials, v-env, V-env search, A-all\n"
"   [-i<htf-font-dir>]\n"
"   [-l<bookkeeping-file>]\n"
"   [-P(*|<filter>)]     permission for system calls: *-always, filter\n"
"   [-S<image-script>]\n"
"   [-s<css-file-ext>]   default: -s4cs; multiple entries allowed\n"
"   [-t<tfm-font-dir>]\n"
"   [-u10]               base 10 for unicode characters\n"
"   [-utf8]              utf-8 encoding for unicode characters\n"
"   [-v<idv version>]    replacement for the given dvi version\n"
"   [-xs]           ms-dos file names for automatically generated gifs\n"
>>>



Line breaks within command lines should be physically given.

\Section{I/O Files}

\<defines\><<<
#ifndef PATH_MAX
#define PATH_MAX 512
#endif
>>>


\Verbatim
  ../html.dir/a.out a -s"--- needs --- %%1.idv[%%2] ==> %%3 ---
" -b"--- characters ---
\EndVerbatim

\SubSection{Open Input}

\<vars\><<<
static FILE* dvi_file;
>>>

\<main's init\><<<
dvi_file = stdin;
>>>



Below:  If input is from stdin which is not a console
        device, switch it to binary mode. 

Warning `statement with no effect' under \`'gcc -Wall' on non-Windows.
This is not a problem; SET_BINARY is a no-op.

\<open input file\><<<
if( *in_name != '\0' ){ `<file = non-piped input file`> }
#ifdef KWIN32
   else if (!isatty(fileno(stdin))) SET_BINARY(fileno(stdin));
#endif
>>>


\<file = non-piped input file\><<<
      BOOL tag;
job_name_n = (int) strlen( in_name );
job_name = m_alloc(char, job_name_n+6);
(IGNORED) strcpy((char *) job_name, in_name);
tag = job_name_n < 3;
if( !tag ){
   tag = !eq_str( job_name+job_name_n-`<dvi ext name length`>,`<dvi ext name`>);
}
if( tag ){
   job_name_n+=`<dvi ext name length`>; (IGNORED) strct(job_name, `<dvi ext name`>);  
}
if( (dvi_file = fopen(job_name, READ_BIN_FLAGS)) == NULL )
   { `<try jobname with extension`> }
`<open idv file`>
>>>


\<dvi ext name length\><<<
(
  (ext==NULL)? 4 : (int) strlen((char *) ext) 
)
>>>

\<dvi ext name\><<<
(
  (ext==NULL)? ".dvi" : ext 
)
>>>




\<vars\><<<
static U_CHAR *ext = NULL;
>>>


\<default extension\><<<
ext = p+1;
>>>




The following tries to remove an extension from the filename,
before adding the `.dvi' extension.
This can help with ht scripts of the form

\Verbatim
     $1 $2
     $1 $2
     $1 $2
     tex4ht $2
     t4ht $2
\EndVerbatim

in cases that the users insert for \`'$2' file names with extension.

\<try jobname with extension\><<<
{                             int i;
   for(i=job_name_n-5; i; i--){ 
     if( job_name[i] == '.' ){
       job_name[i] = '\0';
       job_name_n = i + `<dvi ext name length`>;
       (IGNORED) strct(job_name, `<dvi ext name`>);  
       break; 
   } }
   if( (dvi_file = fopen(job_name, READ_BIN_FLAGS)) == NULL ){
      warn_i_str(1, job_name); bad_in_file(job_name);
}  }
>>>


\<vars\><<<
static char* job_name;
static int   job_name_n;
>>>


strcat should be in string.h, but c++ doesn't find it there.
We use it just for concatenating an extension of 
file name. Should have the interface
\`'char *strcat( (char *, const U_CHAR *) );'.

\<header functions\><<<
static void strct( ARG_II(char *, const U_CHAR *) );
>>>

\<functions\><<<
`[
static void strct( str1, str2 ) 
     U_CHAR * str1`;
     const U_CHAR * str2

;{   U_CHAR * ch;
   ch = str1 + (int) strlen((char *) str1);
   (IGNORED) strcpy((char *)  ch, str2 );
}
>>>


\SubSection{Open Root Html File}

\<pre open output file\><<<
   U_CHAR *name=0;
if( *out_name == '\0' ) 
  { if( *in_name == '\0' ){ `<name = "tex4htput.html"`> }
    else                  { `<name = derived from input file name`> }
  }
else{ `<name = output file from arg list`> }
no_root_file = name;
>>>

We want to wait with actually opening the file output file until the
last minute, to allow a special to change the extension name from the
tex file. That last minute is taken to be when a cll to openning
ort closing a file occurs, or when output is to be written into the file.

\<open output file\><<<
if( no_root_file ){  open_o_file(); }
>>>


\<header functions\><<<
static void open_o_file( ARG_I(void) );
>>>

\<functions\><<<
static void open_o_file(MYVOID)
{        
   `<open root tex4ht file`>
   cur_o_file = root_file = open_html_file(no_root_file);
   no_root_file = (char *) 0;
}
>>>

%    free((void *)  no_root_file);

\<open root tex4ht file\><<<
    struct files_rec* p;
p = m_alloc(struct files_rec, 1);
if( opened_files != (struct files_rec*) 0 ) opened_files->prev = p;
p->prev = (struct files_rec *) 0;
p->next = opened_files;     opened_files = p;
p->name = no_root_file;
p->file =
>>>




\<cond insert new line\><<<
if( !no_root_file ){  
  `<end text accent`>
  if( !`<radical-line-off`> ){  put_char('\n'); }
}
>>>





\<change ext of root file\><<<
if( no_root_file ){
   U_CHAR *name;
   name = m_alloc(char, 256);
   (IGNORED) strcpy((char *)  name, (char *) no_root_file );
   free((void *)  no_root_file);
   no_root_file = name;
   name += (size_t) strlen((char *) name);  while( *(--name) != '.' ); name++;
   while( special_n-- ){
       if( (no_root_file+253) == name ) name--;
       *name++ = get_char();
  }
   *name = '\0'; 
} else { 
          U_CHAR str[256], *p;
   p = str;  while( special_n-- ){ *p++ = get_char(); }  *p = '\0';
   warn_i_str(43,str); 
}
>>>

\<vars\><<<
static U_CHAR *no_root_file;
>>>



\<name = "tex4htput.html"\><<<
bad_arg;
>>>


\<name = derived from input file name\><<<
int n = (int) strlen((char *)  job_name );
name = m_alloc(char, 6 + n);
(IGNORED) strcpy((char *) name, (char *) job_name); 
n -= 4; *(name + n) = '\0'; 
(IGNORED) strct(name,".html");
#ifdef HTM
name[n+4] ='\0';
#endif
>>>








\<name = output file from arg list\><<<
   int tag = 1;
   int n = (int) strlen( out_name );
name = m_alloc(char, 6 + n);
(IGNORED) strcpy((char *) name, out_name);
while( n-- )   tag = tag && (*(name+n) != '.') ;
if( tag ) (IGNORED) strct(name,".html");
#ifdef HTM
name[n+4] = '\0';
#endif
>>>

\<header functions\><<<
static FILE* open_html_file( ARG_I(char*) );
>>>

\<functions\><<<
`[ 
static FILE* open_html_file(name)
     char* name
;{   FILE* file;
     char* str;
  str = m_alloc(char, (int) strlen((char *) name) +  1);
  (IGNORED) strcpy((char *) str, (char *) name);
  (IGNORED) printf(" file %s\n", str);
  (IGNORED) fprintf(log_file, "File: %s\n", str);
  if( (file = fopen(str, WRITE_TEXT_FLAGS)) == NULL )  bad_in_file(str);
  free((void *)  str);
  return file;
}
>>>

\<vars\><<<
static FILE *out_file  = (FILE *) 0, 
     *root_file = (FILE *) 0,
     *cur_o_file = (FILE *) 0;
>>>




\SubSection{Close Output}

\<close active output filesNO\><<<
if( root_file != (FILE *) 0 )  (IGNORED) fclose(root_file);
>>>

\SubSection{Get Input-File Length}

Files must have length divisible by four and have 4 to 7 \`'trail' characters.





  Another problem I ran into is that fileno is unavailable to both
compiler and linker if I turn on ANSI compilation. I checked where you
use it, and it is in only one place, to find the file length of the DVI
file. Your code:

\Verbatim
{    struct STSTAT temp;
  (IGNORED) fstat (fileno(dvi_file), &temp);
  file_len = (long) temp.st_size;
  if( (file_len % 4) != 0 )  bad_dvi;
}
\EndVerbatim

If you change this to use ftell and fseek, you'll have gained ANSI
compatibility (and therewith portability). I tried the following code
instead of yours:

\<file-len = size of file\><<<
{      long  curr_pos;
  curr_pos = ftell(dvi_file);
  (IGNORED) fseek(dvi_file, 0, SEEK_END);
  file_len = ftell(dvi_file);
  (IGNORED) fseek(dvi_file, curr_pos, `<abs file addr`>);
  if( (file_len % 4) != 0 )  bad_dvi;
}
>>>

% SEEK_SET);

  To the best of my nowledge, this works exactly like your code (I
tested it). My executable is compiled with this code.



see also fgetpos and fsetpos.

\Section{Coding Hints}
\ifHtml[\HPage{ini (initialization) files in windows}\Verbatim

\Verbatim
/*************** foo.c file *******************/

#include<stdio.h>
#include<string.h>
#include<conio.h>
#include<windows.h>


// Windows-specific functions used:
//    _fullpath : make filename into full path
//     _splitpath : split a _fullpath into its component parts 
//     GetPrivateProfileString: handle the .ini file 

_fullpath(path,argv[0],250);
_splitpath(path,drive,dir,filname,ext);

char TEXINAME[100], NOBATCHNAME[MV2];

GetPrivateProfileString("Files", "TEXINAME", NOBATCHNAME, TEXINAME, 100, "foo.ini");
GetPrivateProfileString("Strings", "SWPPACK", dSWPPACK, SWPPACK, 100,"foo.ini");
DEBFLAG=GetPrivateProfileInt("integers", "DEBFLAG",0, "foo.ini");

/*************** foo.ini file  ********************/ 

[integers]
; DEBFLAG = 1 prints additional details
DEBFLAG = 0

[files]
; texinfo
TexiName = texis.bat

[strings]
; swp package
SWPPACK = {swpht}

\EndVerbatim\EndHPage{}]\fi

\ifHtml[\HPage{detecting tex tree}\Verbatim
 > > on a Windows machine? (How can the installer know where to put files
 > > without actually searching the entire hard disc.) Any ideas?
 > 
 > Unfortunately, I have no idea on how to avoid a global search. 

a) create a file foo.tex containing
   hello
   \bye
b) run
    tex foo.tex
c) open foo.log and analyze the results. you should be able to get all 
the clues you need about their setup

\EndVerbatim\EndHPage{}]\fi



\ifHtml[\HPage{kpathsea}\Verbatim
My key discovery was the library `kpathsea' which does file name look up.
And in particular `kpsewhich --show-path TEXFILETYPE'. So, for example,
`kpsewhich --show-path tfm' returns a colon separated list of paths to tfm
files.

\EndVerbatim\EndHPage{}]\fi

\ifHtml[\HPage{more}\Verbatim
with some help from my neighbour, i got this working at last....

you had

   if( *(p = gif_open[gif_flag]) ) IGNORED) strct(str,p);

which we changed to

   p = gif_open[gif_flag];
   if( p && *p) (IGNORED) strct(str,p);

because if gif_open[fig_flag] is NULL (which you initialize it to
be!), then the *p points to a dead end.....


this applied in some other places too, see appended diff.
     
  {     struct group_info *p, *last;
    p = stack[ stack_n ].begin;
\EndVerbatim\EndHPage{}]\fi


\Chapter{Structure of Dvi Files}

\Section{Background}
\Link[http://www.rpi.edu/\string~sofkam/DVI/dvi.html]{}{}DVI driver standards  \EndLink


Dvi files are consisted of three parts.


\bgroup
\def\.#1.#2.{%
   \ifcase #1
        \Link{#2}{dvistrct}\or
        \Link{#2}{}\or
        \Link{#2}{}\fi
   #2\EndLink}
\Verbatim-\
+-----------+ 
| \.0.preamble.  | 
+-----------+ 
|   \.1.pages.   |     
+-----------+
| \.2.postamble. |
+-----------+
\EndVerbatim
\egroup


\SubSection{Example}

\Link{}{dvcd} \EndLink{}

\Verbatim
000000: PRE       version          : 2
000002:           numerator        : 25400000
000006:           denominator      : 473628672
000010:           magnification    : 1000
000014:           job name ( 27)   : TeX output 1995.02.22:0104
000042: BOP       page number      : 1
000047:                0       0       0
000059:                0       0       0
000071:                0       0       0
000083:           prev page offset : -00001
000087: PUSH
000088: DOWN3:    -917504
000092: POP
000093: DOWN4:    42152922
000098: PUSH
000099: DOWN4:    -41497562
000104: PUSH
000105: FNT_DEF1: 29
000107:           checksum         : -538297224
000111:           scale            : 655360
000115:           design           : 655360
000119:           name             : cmtt10
000127: FONT_29
000128: Char:     <HTML><TITLE>try.htex</TITLE><BODY>
000163: POP
000164: Y3:       786432
000168: PUSH
000169: PUSH
000170: RIGHT3:   1310720
000174: Char:     <P>
000177: POP
000178: RIGHT3:   2342903
000182: FNT_DEF1: 12
000184:           checksum         : 555887770
000188:           scale            : 655360
000192:           design           : 655360
000196:           name             : cmsy10
000204: FONT_12
000205: Char:     ff         /* ligature (non-printing) */
000206: W3:       145632
000210: Char:     0x 0
000211: W0
000212: Char:     A
000213: PUSH
000214: DOWN3:    -237825
000218: Char:     ffi        /* ligature (non-printing) */
000219: POP
000220: RIGHT3:   704510
000224: FONT_29
000225: Char:     A
000226: RIGHT3:   344061
000230: Char:     B
000231: POP
000232: Y0
000233: PUSH
000234: Char:     </BODY></HTML>
000248: POP
000249: POP
000250: DOWN3:    1572864
000254: EOP
000255: POST      last page offset : 000042
000260:           numerator        : 25400000
000264:           denominator      : 473628672
000268:           magnification    : 1000
000272:           max page height  : 43725786
000276:           max page width   : 30785863
000280:           stack size needed: 3
000282:           number of pages  : 1
000284: FNT_DEF1: 29
000286:           checksum         : -538297224
000290:           scale            : 655360
000294:           design           : 655360
000298:           name             : cmtt10
000306: FNT_DEF1: 12
000308:           checksum         : 555887770
000312:           scale            : 655360
000316:           design           : 655360
000320:           name             : cmsy10
000328: POSTPOST  postamble offset : 000255
000333:           version          : 2
000334: TRAILER
000335: TRAILER
000336: TRAILER
000337: TRAILER
000338: TRAILER
000339: TRAILER
\EndVerbatim

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Scan Postamble}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The postamble of a \Link{dvistrct}{postamble}dvi file\EndLink{} has the
following structure. It should be consistent with the preamble.

\bgroup
\def\.#1.{\Link{fntdef}{}#1\EndLink}
\Verbatim-\
no_ops ???      >= 0 bytes     NOPS, I think they are allowed here...
postamble_marker   1 ubyte     POST
last_page_offset   4 sbytes    
numerator          4 ubytes    
denominator        4 ubytes    
magnification      4 ubytes    
max_page_height    4 ubytes    
max_page_width     4 ubytes    
max_stack          2 ubytes    
total_pages        2 ubytes    number of pages in file
... \.FONT DEFINITIONS. ...  
POST_POST          1 byte      
postamble_offset   4 sbytes    offset in file where postamble starts
version_id         1 ubyte     
trailer         >= 4 ubytes    TRAILER
<EOF>
\EndVerbatim
\egroup

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{No Op's at the End of File}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Verify \LinkPort\<eof op\>{}eof op\EndLink{} and version number
 at postamble. There should be at least four trailing characters, and
 normally there are no more than seven. They act as signatyre and
 provide for file lengths that are divisible by four, aimed at
 machines that pack four bytes into a word.

\<scan postamble\><<<
i=0;
do{
  i++; file_len -= 1;
  (IGNORED) fseek(dvi_file, file_len, `<abs file addr`>);
}   while( (ch=get_char()) == `<eof op`> );
eof_op_n = file_len;
if( (i<4) 
    || 
    ((ch != `<version dvi`>) && (ch > `<version xdv`>))
  )  bad_dvi; 
version_id = ch;
>>>



\<vars\><<<
static int version_id;
>>>



The function \`'(IGNORED) fseek' enables random access to file.

\<abs file addr\><<<
0>>>

\<relative file addr\><<<
1>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Find Start of Postamble}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<scan postamble\><<<
file_len -= 5;
(IGNORED) fseek(dvi_file, file_len, `<abs file addr`>);
if( get_char() != `<end-postamble op`> )  bad_dvi;
eof_op_n -= begin_postamble = get_unt(4);
(IGNORED) fseek(dvi_file, begin_postamble, `<abs file addr`>);
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Find Stack Size and Number of Pages}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<scan postamble\><<<
if( get_char() != `<begin-postamble op`> )  bad_dvi;
(IGNORED) fseek(dvi_file, 16L, `<relative file addr`>);
`<max page dimensions`>
if( (stack_len = (int) get_unt(2)) < 1)     bad_dvi;
`<stack = m-alloc...`>
unread_pages = (int) get_unt(2);
>>>



\<main's vars\><<<
int unread_pages;
>>>


\<vars\><<<
static int  stack_len;
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Font Definitions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<scan postamble\><<<
{      `<scan fonts vars`>
       BOOL missing_fonts;
#ifndef KPATHSEA
       `<fls var`>
   `<get dir of tex4ht.fls`>
   `<open old cache file`>
#endif
   `<init scan fonts vars`>
   missing_fonts = FALSE;
   `<check env font variables`>
   `<start loading fonts`>
   `<load unicode.4hf`>   
   while( (ch =  get_char()) != `<end-postamble op`> ){
     `<scan font entry`> 
   } 
   `<end loading fonts`>
   if( missing_fonts ) err_i(14);
#ifndef KPATHSEA
   `<close old cache file`>
   `<set new cache file`>
#endif
   `<free html font memory`>
}
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Scan Preamble}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The preamble of a \Link{dvistrct}{preamble}dvi file\EndLink{} has the
following structure.

\Verbatim
no_ops          >= 0 bytes     NOP, nops before the preamble
preamble_marker    1 ubyte     PRE
version_id         1 ubyte     
numerator          4 ubytes    
denominator        4 ubytes    
magnification      4 ubytes    
id_len             1 ubyte     lenght of identification string
id_string     id_len ubytes    identification string
\EndVerbatim



\<scan preamble\><<<
(IGNORED) fseek(dvi_file, 0L, `<abs file addr`>);
ch = get_noop();
if( ch != `<start of preamble op`> )   bad_dvi;
if( ((int) get_char()) != version_id ) bad_dvi;
(void) get_unt(4);     `%numerator   = (INTEGER) get_unt(4);`%
(void) get_unt(4);     `%denominator = (INTEGER) get_unt(4);`%
`%magnification =`% (void) get_unt(4);
for( i= get_char(); i>0; i-- ) ch = get_char();
>>>





\<version dvi\><<<
2 >>>


The following is from xetex.  As of XeTeX 3.14159265-2.6-0.99996 (TeX
Live 2016), the id value is 7, but it seems prudent and harmless to
allow for a few future updates without recompiling.  Or perhaps we
should not check this value at all with xdv.

\<version xdv\><<<
10
>>>


%%%%%%%%%%%%%%%%%%%%
\Section{Scan Pages}
%%%%%%%%%%%%%%%%%%

The pages in a \Link{dvistrct}{pages}dvi file\EndLink{} have the
following structure.


\Verbatim
no_ops          >= 0 bytes     NOP
begin_of_page      1 ubyte     BOP
page_nr            4 sbytes    page number
                  36 bytes     
prev_page_offset   4 sbytes    offset in file where previous
                                             page starts, -1 for none
... PAGE DATA ...
end_of_page        1 ubyte     EOP
\EndVerbatim



\<scan pages\><<<
{   
  dis_pages = unread_pages;
  while( unread_pages-- ){
    (IGNORED) printf("[%d", dis_pages - unread_pages);
    `<initial values for new page`>
    if( get_noop() != `<start page op`> )  bad_dvi;
    for( i = 1; i<45; i++ )   
      if( get_char() == EOF )   bad_dvi; 
    while( (ch = get_char()) != `<end page op`> ){
      `<process ch according to the case`>
    }
    `<dump ch-map at end of page`>
    (IGNORED) printf("]%c",unread_pages % 10 == 0? '\n' : ' ');
    put_char('\n');
} }
>>>


The new line at end of pages is  importnant and problematic for
verbatim environment that are expressed by \`'<pre>' elements




\<initial values for new page\><<<
x_val = dx_1 = dx_2 = 0;  max_x_val = -10000; `%temp`%
y_val = max_y_val = prev_y_val = dy_1 = dy_2 = 0;
>>>

[\Link{dvcd}{}example of a dvi file\EndLink]




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Dvi Trace}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Good for post processing by plug-ins of `tex4ht.c'. That is, we set  
\ifHtml[\HPage{hints}\Verbatim
Date: Fri, 22 Aug 1997 20:50:03 -0400 (EDT)
From: Eitan Gurari <gurari@cse.ohio-state.edu>
To: ...
Subject: LaTeX (TeX?) to MathML converter


The way that I understand it, the current proposal is to build a new
engine for math formulas, modeled after the one used by TeX.  It seems
to me that, with a little change of a direction, we might have here a
golden opportunity to get much more than just a converter to MathML
from a subset of (La)TeX.

The alternative approach I have in mind consists of a minor
modification to the TeX engine, for optionally seeding dvi files with
\special-hints.  Specifically, in standard mode, TeX will output the
standard dvi output, and ignore the modifications made to its
engine. On the other hand, in `special' mode (activated, e.g., by a
switch in a command line), TeX will output self-created \special
instructions into the dvi code.

The specials will mark strategic points in the dvi code, with the
objective of acting as hints to drivers which process the dvi code.
In the case of formulas, the hints will identify the boundaries of the
formulas, the subscripts and superscripts, and other entities of
significance. In the case of halign and valign tables, the specials
will be placed around the tables, around the rows, around the entries,
and at omitted boundaries. Other locations of possible interest might
be page, paragraph, and line breaks.  Hence, creating sgml-oriented
tagging, with desirable interpretations provided by dvi drivers.

The following are the main advantages that I can see for the
alternative approach.

1. Compatibility.  The marking by the special hints will work with
   all TeX-based source documents, no matter what instructions and
   style files they employ (including the rich collection of amstex
   and amslatex documents).

2. Flexibility. Alternative sgml tags to MathML will be possible, 
   including tags customized by users with realizations in
   style sheets.  Non-hypertext applications might also find uses for
   structural hints emitted by TeX.

3. Usability. The original proposal is oriented toward
   latex2html like systems that try to emulate, only with partial
   success, the behavior of TeX. The alternative proposal will serve
   such systems, as well as more recent systems that rely on the
   native engine of TeX to do the job (e.g., vtex, tex4ht--my system).

   In fact, latex2html will need to do only a minor adjustment
   to its current implementation.  Instead of placing <IMG> pointers to
   gif's created externally for the figures, it will import 
   the MathML code created externally.

4. Portability.  The same as for TeX.

5. Effort.  It seems to me that the effort needed to modify the
   TeX program should be minimal, for someone who is familiar with
   the program (not me).  I guess the following statement 
   from the TeX program is applicable here.

      1340. Extensions.   The program above includes a bunch of "hooks" that
      allow further capabilities to be added without upsetting TeX's basic
      structure. Most of these hooks are concerned with "whatsit" nodes,
      which are intended to be used for special purposes; whenever a new
      extension to TeX involves a new kind of whatsit node, a corresponding
      change needs to be made to the routines below that deal with such
      nodes, but it will usually be unnecessary to make many changes to the
      other parts of this program.
   
      In order to demonstrate how extensions can be made, we shall treat
      `\write', `\openout', `\closeout', `\immediate', `\special', and

   Extracting the code from the dvi files should be a straightforward
   task for a driver, when the special hints are present.

   On the other hand, the following quote from the TeX program might
   also be of interest, if the original proposal intends to include tables.

      768. Alignment.   It's sort of a miracle whenever \halign and \valign
      work, because they cut across so many of the control structures of
      TeX.

6. Stability.  The core of the TeX engine is a frozen component, probably
   untouched even by its recent extensions (etex, pdftex, ...). Hence, a 
   well thought set of \special-hints will provide a stable base for
   different drivers to play with.

Thanks for your attention, -eitan


> Consultant/Programmer sought to develop an LaTeX to MathML converter:
> 
<snip>
> 
> The MathML specificaion was written with an eye toward the ability to
> convert other mathematical data formats into MathML.  Translators that
> can convert mathematical documents utilizing TeX markup will be
> especially useful due to the large quantity of TeX documents that the
> research mathematics community has authored over the past decade.
> 
> The AMS, the Geometry Center, and SIAM intend to collaborate to
> support the development of a general purpose LaTeX to MathML
> translator, using the popular public-domain LaTeX2HTML utility as
> model.  LaTeX2HTML converts a LaTeX document into an HTML document in
> two general passes.  First, LaTeX document structures are converted
> into HTML (e.g. \section to <H1>) and second, each piece of LaTeX math
> is converted into a GIF graphic and inserted into the HTML document
> with an <IMG> command.
> 
> We are seeking a consultant/programmer skilled in both TeX and Perl
> (LaTeX2HTML is written in Perl) to adapt LaTeX2HTML to create MathML
> code for each piece of LaTeX math rather than producing GIF graphics.
> Since the end result must be completely compatible with LaTeX, we are
> envisioning the job in terms of modifying TeX to convert its internal
> math list structures into MathML.  However, the exact methodology
> employed would be at the discretion of the consultant.
> 
<snip>




\EndVerbatim\EndHPage{}]\fi{}
for the postprocessors.


\List{disc}
\item \`'@%P' --- On-off modes for traceing of POP, PUSH in DVI
\item \`'@%C' --- On-off modes for traceing CHAR...RAHC in DVI
\item \`'@%H' --- On-off modes for traceing h spaces
\item \`'@%V' --- On-off modes for traceing v spaces
\item \`'@%R' --- On-off modes for traceing x rulers


In all the above, uppercase for plus, lowercase for minus 1

\item \`'@%%Zx...pre...x...post...' --- Group tracing.
    Default \`'<!-- DVI ' and \`'\n-->', where \''\n' represents
    new line char (i.e., \`'\EolnCh').
    \`'x' can be any character. if it is not there, 
    the postfix is assumed to be empty.

Z: P, p, D, d,....

\item \`'@%...' --- Not used, if not of the above format
\EndList




\<dvi trace\><<<
if( special_n>1 ) {
   special_n--;
   if (  get_char() == '%' ) {
      if( special_n>2 ) { `<delimiters for trace dvi`> }
      else { `<consume unused specials`> }
   } else { `<consume unused specials`> }
} else if( special_n ) {
  special_n--;
  switch ( get_char() ){
     case 'P': { trace_dvi_P++; break; }
     case 'C': { trace_dvi_C++; break; }
     case 'V': { trace_dvi_V++; break; }
     case 'H': { trace_dvi_H++; break; }
     case 'R': { trace_dvi_R++; break; }
     case 'p': { trace_dvi_P--; break; }
     case 'c': { trace_dvi_C--; break; }
     case 'v': { trace_dvi_V--; break; }
     case 'h': { trace_dvi_H--; break; }
     case 'r': { trace_dvi_R--; break; }
      default: { ; }
} }
>>>
   
Options 'h' and 'v' are not in use.







\<css for chars\><<<
if( span_on && (default_font != font_tbl[cur_fnt].num) ){
  if( !ch_map_flag && start_span ){
    if( span_name_on ){
       `<open output file`>
       if( span_open[0] )  if( *span_open[0] )
           (IGNORED) fprintf(cur_o_file, "%s", span_open[0]);
       if( span_name[0] )  if( *span_name[0] )
           (IGNORED) fprintf(cur_o_file,
               span_name[0], font_tbl[cur_fnt].family_name);      
       if( span_size[0] )  if( *span_size[0] ) 
           (IGNORED) fprintf(cur_o_file,
               span_size[0], font_tbl[cur_fnt].font_size);      
       if( span_mag[0] )
         if( *span_mag[0]  && (font_tbl[cur_fnt].mag != 100))
           (IGNORED) fprintf(cur_o_file,
                       span_mag[0], font_tbl[cur_fnt].mag);      
       if( span_ch[0] )  if( *span_ch[0] )
           (IGNORED) fprintf(cur_o_file, "%s", span_ch[0]);
    }
    start_span = FALSE;
  } 
}
>>>

%       `<...gif font mag...`>












\<vars\><<<
static BOOL start_span = FALSE, in_span_ch = FALSE;
>>>



\<span char block\><<<
if( span_on && !in_span_ch  && !ignore_chs && !in_accenting
            && (default_font != font_tbl[cur_fnt].num) ){
  if(  (ch < 137) && (ch != `<insert rule + move op`>) ){
    in_span_ch = TRUE; start_span = TRUE;    
} }
else if ( in_span_ch ){
  if( !span_on ||
     (ch == `<insert rule + move op`>) ||
     ((136 < ch) && (ch < `<mv hor 1-byte`>)) || 
     (ch > `<dx.2 store and mv hor 4-byte`>) 
  ){
    in_span_ch = FALSE;
    if( *end_span[0] ){
       `<open output file`>
       (IGNORED) fprintf(cur_o_file, "%s", end_span[0]);  
    }
} }
>>>



\<end accented span\><<<
if( span_on && in_span_ch ){
   if( *end_span[0] ){
       in_span_ch = FALSE;
       `<open output file`>
       (IGNORED) fprintf(cur_o_file, "%s", end_span[0]);  
}  }
>>>


\<end css for chars\><<<

>>>




\<trace dvi char block\><<<
if( trace_dvi_C && !in_trace_char ){
   if( (ch < 137) && (ch != `<insert rule + move op`>) ){
     in_trace_char = TRUE; block_start = TRUE;
} }
else if ( in_trace_char ){
  if( !trace_dvi_C || (ch > 136) || (ch == `<insert rule + move op`>) ){
   in_trace_char = FALSE;
} }
>>>






\SubSection{Setting the Delimiters}

The special is assumed to offer a pattern of the form \`'type-ch
del-ch ..... del-ch ....'.


\<delimiters for trace dvi\><<<
     U_CHAR  type, ch, *p, *q, *pp=0, *qq=0, pre[256], post[256];
special_n -= 2;   type = get_char();  ch = get_char();
p = pre;  
while( special_n-- > 0 ) { 
  if ( (*(p++)=get_char() ) == ch ) { p--; break; }
} 
*p = '\0';
p = post;  
while( special_n-- > 0 ) { *(p++)=get_char(); }    *p='\0';
>>>


\<delimiters for trace dvi\><<<        
p = m_alloc(char, 1 + (int) strlen((char *) pre));
(IGNORED) strcpy((char *) p, (char *) pre );
q = m_alloc(char, 1 + (int) strlen((char *) post));
(IGNORED) strcpy((char *) q, (char *) post );
>>>



\<delimiters for trace dvi\><<<
switch ( type ){
   case 'P': { 
     pp = trace_dvi_del_P;      trace_dvi_del_P = p;
     qq = end_trace_dvi_del_P;  end_trace_dvi_del_P = q; 
     break; }
   case 'C': { 
     pp = trace_dvi_del_C;      trace_dvi_del_C = p;
     qq = end_trace_dvi_del_C;  end_trace_dvi_del_C = q; 
     break; }
   case 'V': { 
     pp = trace_dvi_del_V;      trace_dvi_del_V = p;
     qq = end_trace_dvi_del_V;  end_trace_dvi_del_V = q; 
     break; }
   case 'H': { 
     pp = trace_dvi_del_H;      trace_dvi_del_H = p;
     qq = end_trace_dvi_del_H;  end_trace_dvi_del_H = q; 
     break; }
   case 'R': { 
     pp = trace_dvi_del_R;      trace_dvi_del_R = p;
     qq = end_trace_dvi_del_R;  end_trace_dvi_del_R = q; 
     break; }
   case 'p': { 
     pp = trace_dvi_del_p;      trace_dvi_del_p = p;
     qq = end_trace_dvi_del_p;  end_trace_dvi_del_p = q; 
     break; }
   case 'c': { 
     pp = trace_dvi_del_c;      trace_dvi_del_c = p;
     qq = end_trace_dvi_del_c;  end_trace_dvi_del_c = q; 
     break; }
   case 'v': { 
     pp = trace_dvi_del_v;      trace_dvi_del_v = p;
     qq = end_trace_dvi_del_v;  end_trace_dvi_del_v = q; 
     break; }
   case 'h': { 
     pp = trace_dvi_del_h;      trace_dvi_del_h = p;
     qq = end_trace_dvi_del_h;  end_trace_dvi_del_h = q; 
     break; }
   case 'r': { 
     pp = trace_dvi_del_r;      trace_dvi_del_r = p;
     qq = end_trace_dvi_del_r;  end_trace_dvi_del_r = q; 
     break; }
  default: { ; }
}
free((void *)  pp);   
free((void *)  qq); 
>>>









\<vars\><<<
static BOOL in_trace_char = FALSE, block_start = FALSE;
static int trace_dvi_P = 0, trace_dvi_C = 0,
     trace_dvi_H = 0, trace_dvi_R = 0, trace_dvi_V = 0;
static U_CHAR *trace_dvi_del_P,  *end_trace_dvi_del_P,
     *trace_dvi_del_p,  *end_trace_dvi_del_p,
     *trace_dvi_del_C,  *end_trace_dvi_del_C,
     *trace_dvi_del_c,  *end_trace_dvi_del_c,
     *trace_dvi_del_H,  *end_trace_dvi_del_H,
     *trace_dvi_del_h,  *end_trace_dvi_del_h,
     *trace_dvi_del_R,  *end_trace_dvi_del_R,
     *trace_dvi_del_r,  *end_trace_dvi_del_r,
     *trace_dvi_del_V,  *end_trace_dvi_del_V,
     *trace_dvi_del_v,  *end_trace_dvi_del_v;
static int push_depth=0, push_id=0, push_st[256];
>>>











\<cmd line trace groups\><<<
trace_dvi_P++;
if( !(   *trace_dvi_del_P || *end_trace_dvi_del_P
      || *trace_dvi_del_p || *end_trace_dvi_del_p
     )
 ){
   trace_dvi_del_P = 
            (char *)  r_alloc((void *) trace_dvi_del_P,
                              (size_t) 4);
   (IGNORED) strcpy((char *) trace_dvi_del_P, "[G " );
   end_trace_dvi_del_P = 
            (char *)  r_alloc((void *) end_trace_dvi_del_P,
                              (size_t) 2);
   (IGNORED) strcpy((char *) end_trace_dvi_del_P, "]" );
   trace_dvi_del_p = 
            (char *)  r_alloc((void *) trace_dvi_del_p,
                              (size_t) 5);
   (IGNORED) strcpy((char *) trace_dvi_del_p, "[/G " );
   end_trace_dvi_del_p = 
            (char *)  r_alloc((void *) end_trace_dvi_del_p,
                              (size_t) 2);
   (IGNORED) strcpy((char *) end_trace_dvi_del_p, "]" );
}
>>>




\<init traces\><<<
set_del( &trace_dvi_del_P, &end_trace_dvi_del_P);
set_del( &trace_dvi_del_p, &end_trace_dvi_del_p);
set_del( &trace_dvi_del_C, &end_trace_dvi_del_C);
set_del( &trace_dvi_del_c, &end_trace_dvi_del_c);
set_del( &trace_dvi_del_H, &end_trace_dvi_del_H);
set_del( &trace_dvi_del_h, &end_trace_dvi_del_h);
set_del( &trace_dvi_del_R, &end_trace_dvi_del_R);
set_del( &trace_dvi_del_r, &end_trace_dvi_del_r);
set_del( &trace_dvi_del_V, &end_trace_dvi_del_V);
set_del( &trace_dvi_del_v, &end_trace_dvi_del_v);
>>>





\<header functions\><<<
static void set_del( ARG_II(char **, U_CHAR **) );
>>>

\<functions\><<<
`[
static  void set_del( del, end_del ) 
     U_CHAR ** del`;
     U_CHAR ** end_del
;{   
  *del = m_alloc(char, 1);       **del = '\0';
  *end_del = m_alloc(char, 1);   **end_del = '\0';
}
>>>






\SubSection{Using the Delimiters}



\<trace h spaces\><<<
if( trace_dvi_H && !ch_map_flag ){
   if( *trace_dvi_del_H != '\0' ){
      (IGNORED) fprintf(cur_o_file, "%s%d", trace_dvi_del_H, (int) dx);
   }
   (IGNORED) fprintf(cur_o_file, "%s", end_trace_dvi_del_H);
}
>>>

\<trace v spaces\><<<
if( trace_dvi_V && !ch_map_flag ){
   if( *trace_dvi_del_V != '\0' ){   
     (IGNORED) fprintf(cur_o_file, "%s%d", trace_dvi_del_V, d);
   }
   (IGNORED) fprintf(cur_o_file, "%s", end_trace_dvi_del_V);
}
>>>



         

\<trace x rules\><<<
if( trace_dvi_R && !ch_map_flag ){
   if( *trace_dvi_del_R != '\0' ){   
      (IGNORED) fprintf(cur_o_file, "%s%d %d",
         trace_dvi_del_R, (int) x_val, (int) y_val);
   }
   (IGNORED) fprintf(cur_o_file, "%s", end_trace_dvi_del_R);
}
>>>


\<end trace x rules\><<<
if( trace_dvi_R && !ch_map_flag ){
   if( *trace_dvi_del_r != '\0' ){   
      (IGNORED) fprintf(cur_o_file, "%s%d %d",
         trace_dvi_del_R, (int) right, (int) up);
   }
   (IGNORED) fprintf(cur_o_file, "%s", end_trace_dvi_del_r);
}
>>>



\<trace dvi push\><<<
if( push_depth<256 ) { push_st[push_depth] = push_id++; }
if( trace_dvi_P && !ch_map_flag ){
   `<open output file`>
   if( *trace_dvi_del_P != '\0' ){   
      (IGNORED) fprintf(cur_o_file, "%s%d %d",
         trace_dvi_del_P, push_depth, 
         push_st[(push_depth<256)? push_depth:256]);
   }
   (IGNORED) fprintf(cur_o_file, "%s", end_trace_dvi_del_P);      
}
push_depth++;
>>>



\<trace dvi pop\><<<
push_depth--;
if( trace_dvi_P && !ch_map_flag ){
   `<open output file`>
   if( *trace_dvi_del_p != '\0' ){   
      (IGNORED) fprintf(cur_o_file, "%s%d %d",
         trace_dvi_del_p,  push_depth, 
         push_st[(push_depth<256)? push_depth:256]);
   }
   (IGNORED) fprintf(cur_o_file, "%s", end_trace_dvi_del_p);      
}
>>>


\<trace dvi char\><<<
if( trace_dvi_C ){
   if( !ch_map_flag ){
     `<open output file`>
     if( *trace_dvi_del_C != '\0' ){   
        (IGNORED) fprintf(cur_o_file,
            block_start? "%s%s %d B" : "%s%s %d",
            trace_dvi_del_C, font_tbl[cur_fnt].name, ch);      
     }
     (IGNORED) fprintf(cur_o_file,"%s", end_trace_dvi_del_C); 
   }
   block_start = FALSE;
}
>>>


\<end trace dvi char\><<<
if( trace_dvi_C && !ch_map_flag ){
   `<open output file`>
   (IGNORED) fprintf(cur_o_file, "%s%s",
         trace_dvi_del_c, end_trace_dvi_del_c);      
} 
>>>



\Chapter{Semantics of Dvi Code}

[\Link{dvcd}{}example of a dvi file\EndLink]


\Section{Scanning the Characters}

\<process ch according to the case\><<<
{       register int ch_1;
   ch_1 = ch;
   `<auto quit halign`>
   `<process indirect character ch`>
   `<get back sub/sup before ch`>
   `<trace dvi char block`>
   `<span char block`>
   `<pre accent symbol`>
   if( ch < 132 )  {  
      x_val += math_class_on? `<set-ch-class(ch-1)`> 
                            : insert_ch(ch_1);       `%typset and move`%
      if(  max_x_val < x_val ) max_x_val = x_val;
   } else switch( ch ) {
      case 133: case 134: case 135: case 136: {`%typset and don't move`%
           INTEGER w;
         w = math_class_on?  `<set-ch-class(ch-1)`> : insert_ch(ch_1);
         max_x_val = ( x_val + w > max_x_val )?  x_val + w : max_x_val; 
         break;
      }
      `<process dvi op 'ch'`> 
   } 
}
>>>

Characters are inserted into the html file as they are
encountered. Spaces are inserted when \`'x_val' is larger than
\`'max_x_val'. 

\<vars\><<<
static long int x_val = 0, max_x_val = -10000,
     max_y_val = 0, prev_y_val = 0;
>>>




\Section{Spaces}











%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Line Breaks}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





Conditionally start new line.

\<header functions\><<<
static void try_new_line( ARG_I(void) );
>>>

\<functions\><<<
static void try_new_line(MYVOID)
{        long int  v;
         double    dy;
   dy =  (cur_fnt == -1)? 0.0 : (`<sign of ex`> * `<size of ex`>) ;
   v = y_val - prev_y_val;      
   if( !text_on && (y_val > max_y_val) ){
     if( v > dy/2.5 ){
        `<cond insert new line`>  max_x_val = -10000;
        prev_y_val = max_y_val  = stack_n? y_val : 0;
     }
   }else{
      if( v > dy ){ `<cond insert new line`>  max_x_val = x_val;
                    prev_y_val = stack_n? y_val : 0;
      }else if( v < -(dy / 1.4) ) prev_y_val = stack_n? y_val : 0;
}  }        
>>>

The 2.5 divisor provide a line break before b, but not before 5 and a
in \'+${A'}_{5_{a_b}}$+.



\<sign of ex\><<<
(`<size of ex`> < 0? -1 : 1)
>>>

\`+<size of ex>+ is negative in hclassic font of hebrew, and probably also in 
other right-to-left fonts.


In default font, one ex is about 4.5pt.  We take distances greatr than
1.7ex for distance between lines and distances smaller than of
(1.7/1.3)ex from base line to superscript. My TeX inserts superscripts
before subscripts into the dvi files, no matter what order they have
in the input (otherwise, TeX obeys the input order in the output).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Move Horizontally}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<process dvi op 'ch'\><<<
case `<mv hor 1-byte`>: {;}
case `<mv hor 2-byte`>: {;}
case `<mv hor 3-byte`>: {;}
case `<mv hor 4-byte`>: { 
   try_new_line();
   (void) move_x((INTEGER) get_int(ch - `<mv hor 1-byte`> + 1 ));
   break; }
>>>

\<process dvi op 'ch'\><<<
case `<mv hor dist dx.1`>: {                
   (void) move_x( dx_1 ); break; }
case `<dx.1 store and mv hor 1-byte`>: {;}
case `<dx.1 store and mv hor 2-byte`>: {;}
case `<dx.1 store and mv hor 3-byte`>: {;}
case `<dx.1 store and mv hor 4-byte`>: { 
   try_new_line();
   dx_1 = move_x((INTEGER) get_int(ch - `<mv hor dist dx.1`> ));
   break; }
>>>

\<process dvi op 'ch'\><<<
case `<mv hor dist dx.2`>: {                
   (void) move_x( dx_2 ); break; }
case `<dx.2 store and mv hor 1-byte`>: {;}
case `<dx.2 store and mv hor 2-byte`>: {;}
case `<dx.2 store and mv hor 3-byte`>: {;}
case `<dx.2 store and mv hor 4-byte`>: { 
   try_new_line();
   dx_2 = move_x((INTEGER) get_int(ch - `<mv hor dist dx.2`> ));
   break; }
>>>


\<vars\><<<
static INTEGER dx_1 = 0, dx_2 = 0;
>>>




\<header functions\><<<
static INTEGER move_x( ARG_I(register INTEGER) );
>>>

\<functions\><<<
`[ 
static INTEGER move_x( d ) 
      register INTEGER  d
;{    register long     i, dx;
   x_val += d;
   if( (x_val > max_x_val) && x_val ){
     if( max_x_val == -10000) max_x_val = x_val - d;  
     `<insert space`>
   } else    if( d && text_on  && (x_val != max_x_val) ){
      `<space for llap`>
   }  
   return  d;
}
>>>

\''x_val == max_x_val' typically occurs in push after 
\ifHtml[\HPage{hbox}\Verbatim
\documentclass{article}

\usepackage[html,3.2]{tex4ht}

\begin{document}

\parindent=0pt

\section{foo}

\leavevmode=1=\hbox{=2N=}=N3=   %[2694266,1347133,2694266]

\leavevmode=4N=\llap{=N5Y=} =Y6= %[983040,-1347133,2330173]

\leavevmode=4=\llap{= 7 =} = 8 = %[983040,-1347133,2330173]

\leavevmode\llap{= 9 = } = 0 =

\end{document}
\EndVerbatim\EndHPage{}]\fi
to compansate for loss of space due to a pop..



The \''\llap' create problems for spaces, e.g., in section number at
section heads.   The same might happen for \''\hrule'.
The following provides a solution.

\<space for llap\><<<
if( !ignore_spaces ){
   i =  (INTEGER) ( (double) (dx = d) / word_sp + 0.5 );
   if( i<0 ) i=0;
   if( !i ) i = dx>99999L;
   if( i ){ put_char(' '); }
}
>>>

Originally, we had also   \`'(max_x_val == -10000)' in the else part.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Move Vertically}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<process dvi op 'ch'\><<<
case `<mv ver 1-byte`>: {;}
case `<mv ver 2-byte`>: {;}
case `<mv ver 3-byte`>: {;}
case `<mv ver 4-byte`>: { 
  (void) move_y( (INTEGER) get_int(ch - `<mv ver 1-byte`> + 1 ));
  break; }
>>>

\<process dvi op 'ch'\><<<
case `<mv ver dist dy.1`>: { (void) move_y( dy_1 );   break; }
case `<dy.1 store and mv ver 1-byte`>: {;}
case `<dy.1 store and mv ver 2-byte`>: {;}
case `<dy.1 store and mv ver 3-byte`>: {;}
case `<dy.1 store and mv ver 4-byte`>: { 
  dy_1 = move_y( (INTEGER) get_int(ch - `<mv ver dist dy.1`> ));
  break; }
>>>

\<process dvi op 'ch'\><<<
case `<mv ver dist dy.2`>: { (void) move_y( dy_2 );   break; }
case `<dy.2 store and mv ver 1-byte`>: {;}
case `<dy.2 store and mv ver 2-byte`>: {;}
case `<dy.2 store and mv ver 3-byte`>: {;}
case `<dy.2 store and mv ver 4-byte`>: { 
  dy_2 = move_y( (INTEGER) get_int(ch - `<mv ver dist dy.2`> ));
  break; }
>>>

\<vars\><<<
static INTEGER  dy_1 = 0, dy_2 = 0;
static long int y_val = 0;
>>>

\<header functions\><<<
static INTEGER move_y( ARG_I(register INTEGER) );
>>>

\<functions\><<<
`[
static INTEGER move_y( d ) register INTEGER d
;{  y_val += d;                
   `<trace v spaces`>
   return  d;
}
>>>



\SubSection{Typeset Indirect Characters}

Read the character to be typsetted, insert the character, and either
move the cursor (ops 128--131) or don't (ops 133--136).

\<process indirect character ch\><<<
if( (ch > 127) && (ch < 137) && (ch != `<insert rule + move op`>) ){
   ch_1 = (int) get_unt( (ch - (ch>132)) % 4 +1);
}
>>>

NOTE. Didn't take care yet of character codes beyond c[1] (e.g., unicode).



\ifHtml[\HPage{more}\Verbatim
  \documentclass{report}
  \usepackage{t1enc} 

\input tex4ht.sty  \Preamble{html}
   \begin{document}
\EndPreamble

\def\x{ ü (252)  ý   (253)}

\x   ========  \Picture*{} \x \EndPicture{}

\end{document}

\EndVerbatim\EndHPage{}]\fi





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Utilities}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Spaces are inserted when \`'x_val' is larger than
\`'max_x_val'. 



\<insert space\><<<
i =  (INTEGER) (  (double) (dx = x_val - max_x_val) 
            /         (text_on? word_sp : margin_sp)
            +         0.5 );
`<try word space if i=0`>
if( i<0 ) i=0;
if( i==0 ){ `<missing space`> }
if( i ){ `<trace h spaces`> }
if( !ignore_spaces ){
  `<end text accent`>
   while( i-- ) { text_on=TRUE;  put_char(' '); }
} else { recover_spaces = (int) i; }
max_x_val = x_val;
>>>

\<try word space if i=0\><<<
if( i==0 ){
   i =  (INTEGER) (  (double) dx 
            /         word_sp 
            +         0.5 );
}
>>>



\<recover ignored space\><<<
while( recover_spaces-- ){ text_on=TRUE;  put_char(' '); }
recover_spaces = 0;
>>>


\<ignore spaces\><<<
ignore_spaces++;
>>>

\<end ignore spaces\><<<
ignore_spaces--;
>>>



\<unhskip vars\><<<
U_CHAR *unhskip_mark;
long retract_addr;
BOOL unhskip;
int cr_fnt, ch, unskip_depth;
>>>




In the case of unhskip we don't want to inore embedded font changes.

\<ignore chs\><<<
if( special_n ){  
                  `<unhskip vars`>
   cr_fnt = cur_fnt;
   unskip_depth = 0;
   unhskip_mark = get_str( (int) special_n );  special_n=0;
   retract_addr = ftell(dvi_file);
   `<conditional unhskip`>  
   cur_fnt = cr_fnt; 
   free((void *)  unhskip_mark); 
} else { ignore_chs++;; }
>>>


\<conditional unhskip\><<<
unhskip = TRUE;
while( unhskip ){
  if( (ch = get_char()) >= 128 ) {
  switch( ch ){ 
    `<ignore font def on preview pass`>
    `<ignore on preview pass`> 
    `<ignore indirect chars on preview pass`>
    `<push/pop for unhskip`> 
    `<hooks for conditional unhskip`>
    `<fonts and default ignored on preview pass`>
  }
} }
`<scan condition`>
>>>

\<scan condition\><<<
do{
                               long int i;
                               char *mark;
  ch = get_char();
  if(
      ( ch==`<special 1`>) ||  ( ch==`<special 2`>) || 
      ( ch==`<special 3`>) ||  ( ch==`<special 4`>) 
    ) 
  {
     if( tex4ht_special( &ch, &i ) ){ 
         mark = get_str( (int) i );
         if( (ch=='@') && ( *mark=='?') && eq_str(mark+1,unhskip_mark)){
           break;
     }  }
  }
  (IGNORED) fseek(dvi_file, (long) retract_addr, `<abs file addr`>);
} while(FALSE);
>>>



\<ignore indirect chars on preview pass\><<<
case 128: case 129: case 130: case 131: case 133:
case 134: case 135: case 136: {
  (void) get_unt( (ch-(ch>132)) % 4 +1);  
  break; 
}
>>>






\<push/pop for unhskip\><<<
case `<sv loc op`>: 
case `<retrieve loc op`>: {  break; }
>>>





\<hooks for conditional unhskip\><<<
case `<special 1`>:  case `<special 2`>: 
case `<special 3`>:  case `<special 4`>: {  long int i;
  if( tex4ht_special( &ch, &i ) ){    char *mark;
    mark = get_str( (int) i );
    if( i ){
      if( (ch=='@') && eq_str(mark+1,unhskip_mark) ){     
         switch( *mark ){
           case '[': { unskip_depth++; break; }
           case ']': { 
                unhskip = !(--unskip_depth);
                break; 
             }
            default: { ; }
    }  }  }
  }else{ `<ignore non-t4ht special`>  }
  break; 
}
>>>







\<end ignore chs\><<<
if( special_n ){
   while( special_n-- > 0 ){  (void) get_char(); }
} else { ignore_chs--; }
>>>


\<cond ignore chs\><<<
while( special_n-- > 0 ){  (void) get_char(); }
>>>


\<get eoln str\><<<
if( eoln_str ){ free((void *)  eoln_str); }
if( special_n ){
   eoln_str = get_str( (int) special_n );  special_n=0;
} else { eoln_str = (char *) 0; }
>>>

\<insert eoln ch\><<<
if( eoln_str ){ print_f(eoln_str); }
else { (IGNORED) put_4ht_ch( ch, cur_o_file ); }
recover_spaces = 0; 
>>>

\<vars\><<<
static U_CHAR *eoln_str = (char *)0;
>>>






\<get space str\><<<
if( space_str ){ free((void *) space_str); }
if( special_n ){
   space_str = get_str( (int) special_n );  special_n=0;
} else { space_str = (char *) 0; }
>>>

\<insert space ch\><<<
if( space_str ){ print_f(space_str); }
else { (IGNORED) put_4ht_ch( ch, cur_o_file ); }
>>>

\<vars\><<<
static U_CHAR *space_str = (char *)0;
>>>








\<vars\><<<
static int ignore_chs=0, ignore_spaces=0, recover_spaces=0;
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Out of Place Spaces}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<missing space\><<<
         long  curr_pos;    
         BOOL  done;
         int ch, cr_fnt;
curr_pos = ftell(dvi_file);
done = FALSE;
while( !done ){
   ch = get_char();
   switch( ch ){
     `<h-move get space info`>
     `<h-move skip font loading`>
     `<case: skip font def`>
     case `<sv loc op`>:
     case `<retrieve loc op`>: { break; }
     default: { 
        if( (ch < `<font 0`>) || (ch > `<font 63`>)   ){
           done = TRUE; 
        } else {
           `<check alternative space`>
}  } }  }
(IGNORED) fseek(dvi_file, curr_pos, `<abs file addr`>);
>>>



\<check alternative space\><<<
         double word_sp;
cr_fnt = ch - `<font 0`>;
cr_fnt = search_font_tbl( cr_fnt );
word_sp = design_size_to_pt( font_tbl[cr_fnt].word_sp )
             * (double) font_tbl[cr_fnt].scale;
i =  (INTEGER) (  (double) dx
            /         (text_on? word_sp : margin_sp)
            +         0.5 );
`<try word space if i=0`>
if( i>0 ){ i =1; }
>>>




\<h-move get space info-WAIT\><<<
case  `<font 1-byte`>:
case `<font 2-bytes`>:
case `<font 3-bytes`>:
case     `<font int`>: {
                              INTEGER n;
                              int ch;
   n = ch - `<font 1-byte`> + 1;
   cr_fnt = (int)  ((n==4)? get_int(4) : get_unt((int) n));
   cr_fnt = search_font_tbl( cr_fnt );
   break; 
}
>>>



Removed \`'if( !i ) i = dx>99999L;' after \`'if( i<0 ) i=0;', and
insertex \`+<missing space>+ instead. It created problems for cases
like


\List{*}
\item
\Verbatim
\documentclass{article}

\begin{document}
 $\mathcal{ABCDEFGHIJKLMNOPQRSTUVWXYTJZ}$
\end{document}
\EndVerbatim

It gives \`'dx=121058' on    \`'word_sp=500255.625000'.
A 0.24 ratio with a large space.

\item
But that is problematic for:

\Verbatim
\documentclass{article}

\renewcommand{\rmdefault}{ptm} 
\immediate\write16{........\the\textwidth}
\setlength\textwidth{478.00812pt}%

\begin{document}

The first is stylistic - there is inconsistent indenting, the
constants are given non-meaningful names, and are not shared between
\texttt{func} and

\end{document}
\EndVerbatim



The end is disassebled into

\Verbatim
006066: Y0
006067: PUSH
006068: FNT_DEF1: 16
006070:           checksum         : -538297224
006074:           scale            : 655360
006078:           design           : 655360
006082:           name             : cmtt10
006090: FONT_16
006091: Char:     func
006095: RIGHT3:   163840
006099: FONT_15
006100: Char:     and
006103: POP
006104: Y0
\EndVerbatim

We have \`'dx=163840' with \`'word_sp=344061.25' for font 16 and 
\`'word_sp=163840' fot font 15. The space of 163840 seems fitting the 
font that follows.

TeX is cheating here, it should have placed the font change before 
the space.
\EndList



%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Rulers}
%%%%%%%%%%%%%%%%%%%%%%%%%%

\<process dvi op 'ch'\><<<
case `<insert rule + move op`>: {
   (void) rule_x( TRUE );   break;
}
case `<insert rule + nomove op`>: { 
   (void) rule_x( FALSE );  break;
}
>>>






\<vars\><<<
static BOOL text_on = FALSE;
>>>

Originally, we didn't have \`'text_on' in the computation of i within
\`'rule_x' and \`'move_x'. This caused a problem in case that we have
a line of the form \`'<math stuff><regular stuff>', because changes to
the variable (WHICH VARIABLE? \''x_val'?)  are lost once we get out of
the math stuff.  The foollowing example had the problem also after the
introduction of \Verb+text_on+, and got fixed with the 
segment \Verb+<try word space if i=0>+.

\Verbatim
\documentclass[twocolumn]{article} 
 
\def\chem#1{\ensuremath {\mathrm {#1}}} 
\def\un#1{\ensuremath {\unskip \,\mathrm {#1}}} 
 
\setlength{\textwidth}{180mm} 
 
\begin{document} 
 
The bands we have identified as linear chains come in pairs, the 
states are parity doublets. The structure of the intrinsic shapes 
has been discussed in many works as given in the introduction 
(sect.~xx). We compare the moments of inertia of the 
bands in \chem{{\HCode{}}^{14}C} with the moments of inertia of other 
molecular bands in light nuclei in table~xx. The 
proposed bands in \chem{{\HCode{}}^{14}C} have very large values of 
$\hbar^2/2\theta\approx 120$\un{keV}, consistent with the concept 
of chain states.  
 
\end{document} 
\EndVerbatim













\<header functions\><<<
static void rule_x( ARG_I(BOOL) );
>>>


\<functions\><<<
`[ 
static  void rule_x( tag ) 
      BOOL  tag
;{    long i, right, up;
   up = (INTEGER) get_int(4);                       
   right = (INTEGER) get_int(4);
   if( ch_map_flag ){ `<ruler into ch map`> }
   else if( pos_dvi ){ 
      `<pos dvi x rule`> 
      if( tag ) x_val += right;
   } else if( (up>0) && (right>0) ) {
      `<typset positive rule x`>       
      if( tag ) x_val += right;
   } else {
      `<don't typset rule x`>
      if( tag ) x_val += right;
}  }  
>>>


\<vars\><<<
static U_CHAR rule_ch = '_';
static BOOL `<radical-line-off`> = FALSE;
>>>

\<ruler ch\><<<
if( !special_n ){ rule_ch = '\0'; }
else            { while( special_n-- > 0 ){ rule_ch = get_char(); }
                }
>>>



\<write to lg file with loc stamp\><<<
          struct files_rec *p;
while( special_n-- > 0 ) (void)  putc( get_char(), log_file );  
for( p = opened_files; p != (struct files_rec*) 0;  p = p->next ){
   if( p->file == cur_o_file) {  
        (IGNORED) fprintf(log_file, "%d %s\n", 
               (int) ftell(cur_o_file), p->name); 
        break;
}  }
>>>







\<typset positive rule x\><<<
if( (x_val + right)  && 
        (    ((x_val + right) > max_x_val)
          || ( !text_on && !ignore_chs )
        )
){ 
   if( (max_x_val == -10000) || ((x_val + right) <= max_x_val) )
   {  max_x_val = x_val;  }        
   i =  (INTEGER) (  (double) (x_val + right - max_x_val) 
                   /         (text_on? word_sp : margin_sp)
                   +         0.5 );
   `<try word size if i=0`>
   if( i && !text_on )  try_new_line();
   `<trace x rules`> 
   while( i-- ) { text_on=TRUE;  
      if( rule_ch && !`<radical-line-off`> ){ put_char(rule_ch); }
   }
   `<end trace x rules`> 
   max_x_val = x_val + right;   
}
>>>




\<try word size if i=0\><<<
if( i==0 ){
   i =  (INTEGER) (  (double) (x_val + right - max_x_val) 
                   /         word_sp
                   +         0.5 );
}
>>>




\<radical-line-off\><<<
rule_ch_off
>>>




\<don't typset rule x\><<<
`<trace x rules`>
`<end trace x rules`>
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Command Characters}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Fonts}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<process dvi op 'ch'\><<<
`<case: skip font def`>
>>>


\<case: skip font def\><<<
case `<def 4 byte font`>:   (void) get_char();
case `<def 3 byte font`>:   (void) get_char();
case `<def 2 byte font`>:   (void) get_char();
case `<def 1 byte font`>: {   
  for( i=0; i<14; i++ ){ ch = get_char(); }
  for( i=ch + get_char(); i>0; i--) (void) get_char();
  break;
}
>>>


\<process dvi op 'ch'\><<<
case `<xdv-native-font-def op`>:
   if(  version_id == `<version xdv`> ){
     `<skip font xdv def`>
      break;
   }
case `<xdv-glyph-array op`>:
   if(  version_id == `<version xdv`> ){
     `<do glyph array`>
      break;
   }
case `<xdv-glyph-string op`>:
   if(  version_id == `<version xdv`> ){
     `<do glyph string`>
      break;
   }
>>>


\<process dvi op 'ch'\><<<
default: {
  if( (ch < `<font 0`>) || (ch > `<font 63`>) ) {
     bad_char(ch);      
  } else { cur_fnt = ch - `<font 0`>;
         `<search font in font-tbl`> }
  break;   
}
>>>

\<process dvi op 'ch'\><<<
case `<font 1-byte`> :
case `<font 2-bytes`>:
case `<font 3-bytes`>:
case `<font int`>    : { 
        INTEGER n;
   n = ch - `<font 1-byte`> + 1;
   cur_fnt = (int)  ((n==4)? get_int(4) : get_unt((int) n));
   `<search font in font-tbl`>
   break; }
>>>



\<vars\><<<
static int cur_fnt = -1;  `% should be INTEGER for DOS`%
>>>














\Section{Specials: Extensions to dvi Primitives}




\<process dvi op 'ch'\><<<
case `<special 1`>: {;}
case `<special 2`>: {;}
case `<special 3`>: {;}
case `<special 4`>: {  `<process the specials`>  break;  }
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Specials of TeX4ht}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{The Options}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<process the specials\><<<
long int special_n;
  `<end text accent`>
  if( tex4ht_special( &ch, &special_n) )  {    int  sv; sv = ch;
     special_on = TRUE;  `<process tex4ht special`>  special_on = FALSE;  
     `<check for extra special chars`>               
  } else { `<non-t4ht special`>  }    
>>>






\<non-t4ht special\><<<
while( special_n-- )  (void) get_char();
>>>



\<header functions\><<<
static BOOL tex4ht_special( ARG_II( int*, long int*) );
>>>

\<functions\><<<
`[
static BOOL tex4ht_special( chr, special_n)
    int      *chr`;
    long int *special_n

;{  BOOL     tex4ht;
    int      i;
    long unsigned N;
  tex4ht = FALSE;  
  `<get special length`>
  if( *special_n > (long int) 4 ){
    for(i=4; i<9; i++)   special_hd[i]=get_char();  
    special_hd[9]='\0';
    `<t4ht special?`>
    *chr = special_hd[8];
    tex4ht = tex4ht && ( (*chr == '=') || (*chr == '<') || 
        (*chr == '>') || (*chr == '*') || (*chr == '@') || 
        (*chr == ':') || (*chr == '"') || (*chr == '~') ||
        (*chr == ';') || (*chr == '.') || (*chr == '^') ||
        (*chr == '|') || (*chr == '+') || (*chr == '!') );
    *special_n -= 5;  }
  else{ special_hd[4]='\0'; }
  return  tex4ht;
}
>>>

We want to allow both for \`'\special{t4ht...}' and 
\`'\special{T4HT...}', for cases that the \''\special' is within 
\''\uppercase' (e.g., \`'
\def~{\special{t4ht=+}}
\edef\x{\uppercase{a~b}}\x
\uppercase{a~b}').  We end up with all combinations of upper and 
lower case. ELIMINTE/HANDLE also all possible \''\special''s with
letters after the first four!!!!!!!!!


\<t4ht special?\><<<
tex4ht =           (special_hd[4] == 't') || (special_hd[4] == 'T');
tex4ht = tex4ht &&  special_hd[5] == '4';
tex4ht = tex4ht && ((special_hd[6] == 'h') || (special_hd[6] == 'H'));
tex4ht = tex4ht && ((special_hd[7] == 't') || (special_hd[7] == 'T'));
if( tex4ht && trace_special ){
   `<trace specials`>
}
>>>



\<get special length\><<<
*special_n = (long int) (N = get_unt(*chr - `<special 1`> + 1));
for(i=4; i--; ){
  special_hd[i] = (unsigned char) (N & 0xFF);
  N = N >> 8; }
>>>

\<vars\><<<
static U_CHAR special_hd[10];
>>>




\<process tex4ht special\><<<
try_new_line();
switch( ch ){
  case '*': { `<other specials`>  break; }
  case '@': { `<insert char code`>  break; }
  case '+': { `<ivd code in main pass`>  break; }
  case '=': { `<insert verbatim record`> break; }
  case '<': 
  case '>': { `<redirect html output`>  break; }
  case '!': { `<handle char map mode`>  break; } 
  case '|': { gif_ch = !gif_ch;  break; }
  case ':': { `<arithmetics within specials`>  break; }
  case ';': { `<css for characters`>  break; }
  case '"': { `<positioned content`> break; }
  case '~': { `<grouped-base delivery content`> break; }
  case '.': { `<change ext of root file`> break; }
  case '^': { `<classes for math symbols`> break; }
}
>>>


The \LinkPort\<handle requests for dvi to gif code\>{}handle requests ...\EndLink{} is
used for deciding which dvi code should be extracted for gif pictures.


\Verbatim
\specials within current version of TeX4ht
  
  \special{t4ht=...content...}
      Insert the specified content to the html output, under 
      edef mode of processing, and without using the mapping
      of the htf fonts.  Used in \HCode{...}.
  \special{t4ht>...file-name...}
      Open a new file, if needed, and direct future output
      to the specified file.  Used in \File{...}.
  \special{t4ht<...file-name...}
      Close the specified file.  Used in \EndFile{...}.
  \special{t4ht++file-name}...dvi...\special{t4ht+}
      Pipe the dvi code into a dvi page in the secondary dvi file
      `jobname.idv'.  Used by \Picture{...}, e.g., for requesting 
      gif's.
  \special{t4ht+embeded-specials within idv}
  \special{t4ht!...optional-parameters....}...dvi...\special{t4ht!}
      Create an approximated character map for the dvi code.
      Used in \Picture{...}, e.g., for ALT of IMG
  \special{t4ht|}...\special{t4ht|}
      Use the non-pictorial characters of the htf fonts.
      Used for character maps of \Picture{....}
  \special{t4ht@?...} string for marking errors in html output.
  \special{t4ht@-}....\special{t4ht@-}
      Remove left margin from character map.  Used in \Picture{...}.
  \special{t4ht@@}....\special{t4ht@@}
      Insert the character codes, instead of their mappings through
      the htf fonts.  Used in \JavaScript...
  \special{t4ht@...integer...}
      Insert the character code to the output.
      Used in \Char{-...}, typically, for characters out of the range
      of the available keyboards and/or TeX output.
  \special{t4ht@-...integer...}
      Replace the character code introduced by the next character
      with the current char code.
      Used in \Char{...}, typically, for symbols out of the range
      of the available keyboards and/or TeX output.  Unlike \Char{-...},
      the current command inherites the font info from the next character
  \special{t4ht@+...string...}
      Replace the character code introduced by the next character
      with the specified string.
      Used in \Char{+...} and it inherites the font info from the
      next character
  \special{t4ht@+. ...string...} configure insertions at eoln
  \special{t4ht@+(} ignore spaces
  \special{t4ht@+)} end ignore spaces
  \special{t4ht@+[} ignore chs and spaces
  \special{t4ht@+]} end ignore chs and spaces
  \special{t4ht@+!} get last  ignored space (none, if from previous lines).
  \special{t4ht+@...message...}
      Send message to the lg file.  Used in the \Needs{...} command. 
  \special{t4ht@/}  on/off tracing of specials
  \special{t4ht.extension for root file}

Addition to next version  of TeX4ht:
  
  \special{t4ht;....}         
      Decorations for htf characters.  Useful,for instance, where
      style sheets (like css) are available.  Provide a full
      solution for the problem of fonts, and eliminate the need
      for the incomplete 'fonts' option of TeX4ht.  Used in
      \Configure{characters}.....
       
  \special{t4ht;8....}  
      No and EndNo for decorating characters.

The next version of TeX4ht will probably also have the following
\special's, without yet fully employing their capabilities.
  
  \special{t4ht"...}
      Request for positioned elements. Used only experimentally so far,
      due to lack of sufficient support for such feature from
      the available browsers.  A possible alternative for pictorial
      math and drawings.
  \special{t4ht~...}
      Grouped-base two-way delivery for content created by
      inline commands like \over.  Feature for xml-oriented
      code.
  \special{t4ht@_....}
      Control output character for rulers.
  \special{t4ht*<file}
      Input file (with no processing)
  \special{t4ht*! system comamnd}
      System call
  \special{t4ht@%*...open-del....*...close-del....}
      Request partial dvi tracing.  Not in current use, but might become
      handy for postprocessors.
  \special{t4ht:....}
      Dvi-mode arithmetics. Not in current use, but might become
      handy for postprocessors.
  
  

\EndVerbatim


\ifHtml[\HPage{more}\Verbatim
Subject: Re: Dvi->HTML

I attach the list of specials in TeX4ht.  As you probably noticed, the
\special{t4ht=...} is the most prominnet one.  The other specials are
rarely needed; I strongly propose you postpone using them until latter
stages of your work.  I normally refer to such instructions indirectly
through low-level \HCode instructions, and high-level
\Configue... instructions.  The web pages

   http://www.cse.ohio-state.edu/~gurari/tug97/

illustrate such usages.

> My problem is -- glacing through the documentation -- 

Very little documentation is out, in particular for people that want
to change the system.  Please don't hasitate to ask for help when you
need it.

> I tried to find a way to use  \special{t4ht=...} direct.
> Unfortunally do I fail, due to the missing comments in the *.sty and
> *.c files. Moreover the use of several macros makes the .c quite
> illegible :-(

Agree. I can't read these files either.  They are outputs of
literate programs.

> Could you tell me which commands the .c program needs?
> It wouldd be sufficent if you would give the neccessary commands allown
> (a simple \special{t4ht=<HTML><HEAD></HEAD><BODY>...} does not work.)

Try the following.

1.  Prepare a file x.tex having the following content.

           \special{t4ht=<HTML><HEAD></HEAD><BODY>}
           Just trying.
           \special{t4ht=</BODY></HTML>}
           \bye

2.  Compile the file with tex (`tex x.tex').

3.  Compile the outcome with tex4ht (`tex4ht x').

4.  Visit the file x.html

\EndVerbatim\EndHPage{}]\fi

%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Insert Code (HCode)}
%%%%%%%%%%%%%%%%%%%%%%%%%%

\<insert verbatim record\><<<
while( special_n-- > 0 ){
        int ch;
        BOOL flag;
        struct hcode_repl_typ *q;
   ch = get_char();
   q = hcode_repl;
   flag = FALSE;
   while( q != (struct hcode_repl_typ*) 0 ){
      if( ch == *(q->str) ){ flag = TRUE; break; }
      q = q->next;
   }
   if( flag ){
                   char *chr;
      chr = (q->str) + 1;
      while( *chr != 0 ){ put_char( *chr ); chr++; }
   } else { put_char( ch ); }
}
>>>

\List{*}
\item
\''\special{t4ht*=}' clears all the mappings of characters.
\item
\''\special{t4ht*=xx}' clears the mapping of the character `x'.
\item
\''\special{t4ht*=x....}' asigns a mapping to the character `x'.
\EndList


\<configure hcode\><<<
       char *str, *repl;
       struct hcode_repl_typ *p, *q;
       BOOL flag;
if( special_n ){
   repl = str =  m_alloc(char, (int) special_n + 1);
   while( special_n-- > 0 ){
      *str = get_char(); str++;
   }
   *str = 0;
   `<delete old hcode pattern`>
   `<add new hcode pattern`>
} else {
  `<delete all hcode patterns`>
}
>>>

\<delete all hcode patterns\><<<
while( hcode_repl != (struct hcode_repl_typ*) 0 ){
  p = hcode_repl;
  hcode_repl = hcode_repl->next;
  free((void *) p->str);
  free((void *) p);
}
>>>


\<delete old hcode pattern\><<<
if( hcode_repl != (struct hcode_repl_typ*) 0 ){
   if( *(hcode_repl->str) == *repl ){ 
      p = hcode_repl;
      hcode_repl = hcode_repl->next;
      free((void *) p->str);
      free((void *) p); 
   } else {
     p = hcode_repl;
     while( TRUE ){
       q = p->next;
       if( q ==  (struct hcode_repl_typ*) 0 ){ break; }
       if( *(q->str) == *repl ){ 
          p->next = q->next; 
          free((void *) q->str);
          free((void *) q);
          break; 
       }
       p = q;
} }  }
>>>


\<add new hcode pattern\><<<
flag = *repl != *(repl+1);
if( !flag ){ flag = *(repl+2) != 0; }
if( flag ){
   p = (struct hcode_repl_typ *) m_alloc(struct hcode_repl_typ, 1);
   p->str = repl;
   p->next = hcode_repl;      
   hcode_repl = p;
}
>>>



\<types\><<<
struct hcode_repl_typ { char                  *str;
                        struct hcode_repl_typ *next;  };
>>>


\<vars\><<<
static struct hcode_repl_typ *hcode_repl
                       = (struct hcode_repl_typ*) 0;
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Insert Char Code}
%%%%%%%%%%%%%%%%%%%%%%%%%%


\`'\special{t4ht@i}' inserts the character code i, if
i is negative. If i is positive, the font info is sent as a replacement to
the next chracter code (allowing to use that letter character 
font info for decoration).




The following is ignored within char maps, so we don't have 
to worry about the bound of \`'\<design bound\>'.

\<insert char code\><<<
     int code, digit;
special_n--;
switch ( code = get_char() ){
  case '%': { `<dvi trace`>    break; }
  case '@': { verb_ch = !verb_ch;  break; }
  case '/': { `<on/off special trace`>  break; }
  case 'e': { `<get err str`>  break; }
  case '!': { `<recover ignored space`>  break; }
  case '(': { `<ignore spaces`>  break; }
  case ')': { `<end ignore spaces`>  break; }
  case '[': { `<ignore chs`>  break; }
  case ']': { `<end ignore chs`>  break; }
  case '?': { `<cond ignore chs`>  break; }
  case '-': {
     if( special_n ) { code = 0; `<code := ...`> 
       put_char( code );
     }  else  {  nomargin = TRUE; }
     break; }
  case '*': { `<send string to after next ch`>  }
  case '+': { `<send string to next ch`>    break; }
  case '.': { `<get eoln str`>  break; }
  case ',': { `<get space str`>  break; }
  case '_': { `<ruler ch`>  break; }
  case 'D': { `<write to lg file with loc stamp`> break; }
  case 'u': { `<on/off unicode`>  break; }
   default: { `<send ch to next ch`> }
}
>>>

\<vars\><<<
static BOOL nomargin = FALSE;
static int next_char = -1;
static U_CHAR  *next_str = (char *) 0;
>>>

\<defines\><<<
#define IGNORED void
>>>

\<code := ...\><<<
while( special_n-- > 0 ){
  digit = get_char() - '0';
  if ( (digit < 0) || (digit > 9) ) {  warn_i_int(41,digit+'0') ; }
  else { code = code * 10 + digit; }
}
if ( (code < 0) || (code > 255) ) {  code = '?'; warn_i_int(41,'?') ; }
>>>

\<send ch to next ch\><<<
code -= '0';  `<code := ...`> next_char = code; 
if( `<next-str`> ){    print_f(next_str); 
        free((void *) next_str);  next_str = (char *) 0; }
>>>


Before reading a tring to be submitted forward,  we look
for a previous submission. If such exists, we dump it.

\<send string to next ch\><<<
if( `<next-char`> != -1 ) {
   `<open output file`>
   (IGNORED) put_4ht_ch( `<next-char`> , cur_o_file );
   `<next-char`> = -1;
}
if( `<next-str`> ){    print_f(next_str); 
  free((void *) next_str);  next_str = (char *) 0; }
next_str = get_str( (int) special_n );  special_n = 0;
`<set indirect ch codes`>
>>>

Indirect characters are expressed  by character codes enclosed within
braces. For instance, `\Verb!\special{t4ht@+\string&{35}x0142;}x!'.

\<set indirect ch codes\><<<
{     char *front, *back;
      int i;
  back = front = next_str;
  while( *front != '\0' ){
    if( *front == '{' ){
      i = *(++front) - '0';
      while( *(++front) != '}' ){ i = i*10 + (*front - '0'); }
      *front = (char) i;
    }
    *(back++) = *(front++);
  }
  *back = '\0';
}
>>>



\<next-char\><<<
next_char
>>>



\<next-str\><<<
next_str
>>>

\<send string to after next ch\><<<
keepChar=1;
>>>


\<current char for forwarded string\><<<
if( keepChar ){
  keepChar=FALSE;
  { `<insert font char`> }
}
>>>

%  (IGNORED) put_4ht_ch( ch, cur_o_file );


\<vars\><<< 
static BOOL keepChar = FALSE; 
>>> 




%%%%%%%%%%%%%%%%%
\Section{Files}
%%%%%%%%%%%%%%%%%

Whenever a new file is opened (\''\special{t4ht>...}'), its record is
placed on the top of a stack list. Whenever it is closed
(\''\special{t4ht<...}'), the record is removed from the stack, and
the file at the top of the stack get opened. A reopening of a file
doesn't affect the stack.

The top of the stack is pointed by \`'opened_files', the next file
with \`'next', and the backward with \`'prev'.  Each record also holds
a \`'from_file' pointer telling from where the file was last opened.

One can ask for a return to the file that activated the current file
with the command \''\special{t4ht*>}', and to send the record to the
bottom of the stack with \''\special{t4ht*>file-name}'.


\<redirect html output\><<<
`<name = file name`>
`<open output file`>
`<p = pointer to file record`>
if( ch == '>' ){ `<open tex4ht file`> }
else           { `<close tex4ht file`> }
cur_o_file = ( out_file == (FILE *) 0 )? root_file
                                       : out_file;
>>>


\<retreat file\><<<
if( special_n > 0 ){
  `<send file record to bottom`>
} else {
  `<back up to previous output file`>
}
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Open File}

\<open tex4ht file\><<<
if( p !=  (struct files_rec*) 0 ){
  out_file = p->file;  
  p->prev_file = cur_o_file;
  free((void *) name );  
} else {
  if( !(*name) ) out_file = (FILE *) 0;
  else { `<open non-root tex4ht file`> }
}
>>>


\<open non-root tex4ht file\><<<
p = m_alloc(struct files_rec, 1);
if( opened_files != (struct files_rec*) 0 ) opened_files->prev = p; 
p->prev = (struct files_rec *) 0;    
p->next = opened_files;     opened_files = p;
p->name = name;    
p->file = out_file = open_html_file(name);
p->prev_file = cur_o_file;
>>>

\SubSection{Close File}

\<close tex4ht file\><<<
if( p == (struct files_rec *)  0 ) bad_special( name );
else { /* if p is null, do nothing more */
`<fix pointers around file to be closed`>
if( opened_files !=  (struct files_rec*) 0 )
  { if( out_file == p->file )  out_file = opened_files->file; }
else out_file = (FILE *) 0;
(IGNORED) fclose( p->file );   free((void *)  p->name );   
free((void *) p );
}
>>>


\<fix pointers around file to be closed\><<<
if( p->prev != (struct files_rec*) 0 ) (p->prev)->next = p->next;
else                                   opened_files = p->next;
if( p->next != (struct files_rec*) 0 ) (p->next)->prev = p->prev;
>>>





\SubSection{Implicitly Closed Files}

\<close active output files\><<<
while( opened_files != (struct files_rec*) 0 )
{
   (IGNORED) fclose( opened_files->file ); 
   opened_files = opened_files->next; 
}
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Backup to Previous File}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<back up to previous output file\><<<
`<find record of cur output file`>
>>>

\<find record of cur output file\><<<
        static struct files_rec *p, *q;
for( p = opened_files; p != (struct files_rec*) 0;  p = p->next ){ 
  if( (p->file == cur_o_file) && p->prev_file ){
    `<error if prev file is closed`>
    cur_o_file = p->prev_file;
    p->prev_file = (FILE *) 0;
    break; 
  }
}
>>>

\<error if prev file is closed\><<<
for( q = opened_files; q != (struct files_rec*) 0;  q = q->next ){
  if( q->file == p->prev_file ){
     break;
  }
}
if( q == (struct files_rec*) 0 ){
   warn_i_str(51,q->name);
   break;
}
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Intermediate Files to Bottom of Stack}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<send file record to bottom\><<<
        static struct files_rec *p, *q;
        U_CHAR name[256];
        int i;
`<find file record`>
if( p != (struct files_rec*) 0 ){
  `<move the file record`>
}
>>>

\<find file record\><<<
i = 0;
name[(int) special_n] = '\0';
while(  special_n-- > 0 ){  name[i++] = get_char(); }
for( p = opened_files; p != (struct files_rec*) 0;  p = p->next ){ 
  if( eq_str(p->name, name) ){ break; }
}
>>>



\<move the file record\><<<
for( q = p; q->next != (struct files_rec*) 0;  q = q->next ){ }
if( q != p ){
  q->next = p;
  (p->next)->prev = p->prev;
  if( opened_files == p ){ opened_files = p->next; }
  else { (p->prev)->next = p->next; }
  p->prev = q;
  p->next = (struct files_rec*) 0;  
}
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Get File Name}
%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<name = file name\><<<
   int  i=0;
   U_CHAR *name;
name =  m_alloc(char, (int) special_n+1);
*(name + (int) special_n) = '\0';
while(  special_n-- > 0 )  *(name + i++) = get_char();
>>>


\SubSection{Find File Record}




\<p = pointer to file record\><<<
for( p = opened_files; p != (struct files_rec*) 0;  p = p->next )
  { if( eq_str(p->name, name) )  break; }
>>>




\<vars\><<<
static struct files_rec 
   *opened_files = (struct files_rec *) 0, *p;
>>>

\<defines\><<<
struct files_rec{
  FILE *file, *prev_file;
  char* name;
  struct files_rec *next, *prev;
};
>>>





\Section{Import Files, System Calls}




\<other specials\><<<
if( special_n ){
  special_n--;
  switch ( get_char() ){
    case '<': { `<import file`>    break; }
    case '>': { `<retreat file`>    break; }
    case '!': { `<system call`>    break; }
    case '^': { `<accent specials`>    break; }
    case '@': { `<halign specials`>    break; }
    case '=': { `<configure hcode`>    break; }
     default: { `<consume unused specials`> }
  }
} else { `<unused special`> }
>>>



The library \`'<stdlib.h>' includes a function
\`'int system(const char *cmdstring);'.   When cmdstring is NULL,
the return value is 0 iff the platform does not support system calls.

\''mathml.4ht-9-22:   \special{t4ht*!perl m2webeq > tmpa.tmp}%'

\<system call\><<<
              U_CHAR name[256], ch;
              int i=0, n;
              struct sys_call_rec *p;
              BOOL flag;
name[(int) special_n] = '\0';
while(  special_n-- > 0 ){  name[i++] = get_char(); }
(IGNORED) printf("System call: %s\n", name);
`<flag = permission for system calls`>
if( flag ){
  (IGNORED) printf("System return: %d\n",
                    system_yes?  (int) system(name) : -1 );
} else { (IGNORED) printf("No permission for system call\n"); }
>>>




\<get from tex4ht.env file\><<<
(IGNORED) fseek(dot_file, 0L, `<abs file addr`>);
while ( search_dot_file( 'P' ) ){     struct sys_call_rec *q;
                                      U_CHAR *p, str[256];
  q = m_alloc(struct sys_call_rec, 1);
  q->next = system_calls;
  system_calls = q;
  p = str;
  do
     *(p++) = ch = (int) getc(dot_file); 
  while( (ch !='\n') && (ch != EOF) );
  p--;
  *p = '\0';
  q->filter = m_alloc(char, (int) strlen((char *) str)+1);
  (IGNORED) strcpy((char *) q->filter, (char *) str);
}
>>>

\<permission for system calls\><<<
{     struct sys_call_rec *q;
  q = m_alloc(struct sys_call_rec, 1);
  q->next = system_calls;
  q->filter = p + 2;
  system_calls = q;
}
>>>


\<flag = permission for system calls\><<<
flag = FALSE;
p = system_calls;
while( p ){                    
  if( (n = (int) strlen((char *) p->filter)) == 1 ) {
      flag = flag || (*(p->filter) == '*');
  } if(  strlen((char *) name) >= (unsigned int) n ) {
      ch = name[n]; name[n] = '\0';
      flag = flag || eq_str(p->filter,name);
      name[n] = ch;
  }
  p = p->next;
}
>>>

\<defines\><<<
struct sys_call_rec{
  char* filter;
  struct sys_call_rec *next;
};
>>>


\<vars\><<<
static BOOL system_yes;
static struct sys_call_rec *system_calls = (struct sys_call_rec *) 0;
>>>

\<main's init\><<<
{                   U_CHAR   *yes = NULL;
  system_yes =  (system( yes ) != 0);
}
>>>


\<import file\><<<
    U_CHAR name[256];
    int i=0;
    FILE* file;      
name[(int) special_n] = '\0';
while(  special_n-- > 0 ){  name[i++] = get_char(); }
file  = f_open(name, READ_TEXT_FLAGS); 
if( file ) {
  `<open output file`>
  while( (ch = getc(file)) >=0  ){ 
    (IGNORED)  put_4ht_ch(ch,cur_o_file);     
  }
  (IGNORED) fclose(file);
} else { warn_i_str( 1, name ); }
>>>




\Section{Arithmetics}



\List{disc}

\item \`':+...'  increment by 1( define, if not defined)
\item \`':-...'  decrement by 1
\item \`':>...'  push current value
\item \`':<...'  pop current value
\item \`':!...'   display current value
\item \`':|...'   display top value
\EndList

\<arithmetics within specials\><<<
if( special_n-- ){
        int code, n;
        U_CHAR str [255], *p;
        struct count_rec *q;
  code = get_char();    
  while( special_n > 254 ){ (void) get_char(); special_n--; }
  p = str;  n = special_n;
  while( special_n-- ) { *(p++) = get_char(); }
  *p = '\0';
  `<search counter`>
  `<act on counter`>
}
>>>


\<types\><<<
struct count_rec{ 
   char* str;
   int i, depth, max;
   int* stack;
   struct count_rec* next;
};
>>>

\<vars\><<<
static struct count_rec *counter = (struct count_rec *) 0;
>>>

\<search counter\><<<
q = counter;
while( q ){
  if( eq_str(str,q->str) ) break;  q = q->next;
}
if( !q ){
  q = m_alloc(struct count_rec, 1);
  q->i = q->depth = 0;    q->max = 10;
  q->next = counter;  counter = q;
  q->str =  m_alloc(char, (int) n+1);
  (IGNORED) strcpy((char *)  q->str, (char *) str );
  q->stack =  m_alloc(int, q->max);
}
>>>

\<push counter\><<<
if( q->depth == q->max ){      
   q->max += 10;
   if( (q->stack = (int *) r_alloc( (void *) q->stack,
            (size_t) (q->max * sizeof(int)))) == NULL) bad_mem;
}
q->stack[q->depth++] = q->i;
>>>

\<pop counter\><<<
q->depth--;
if( q->max > q->depth + 20 ){ q->max -= 15;
   if( (q->stack = (int *) r_alloc( (void *) q->stack,
            (size_t) (q->max * sizeof(int)))) == NULL) bad_mem;
}
>>>

\<act on counter\><<<
switch ( code ){
  case '+': {  (q->i)++; break; }
  case '-': {  (q->i)--; break; }
  case '>': {  `<push counter`>  break; }
  case '<': {  if( q->depth  ){ `<pop counter`> }
               break; }
  case '!': {  `<open output file`>
               (IGNORED) fprintf(cur_o_file, "%d", q->i); break; }
  case '|': {  if( q->depth  ){ 
      `<open output file`>
      (IGNORED) fprintf(cur_o_file, "%d", q->stack[q->depth - 1] );
            }
      break; }
  default: { ; }
}
>>>












\Chapter{Character Maps}

\Section{Requests}

\<handle char map mode\><<<
ch_map_flag = !ch_map_flag;
if( ch_map_flag ){ `<enter char map`> }
else             { `<exit char map`>  }   
>>>

\Section{Memory}


The character map is a sequence of lines that are dynamically
allocated. Each character is represented by a pair (str,design), where
str is a possible empty string and design is a character holding a
value 0, 1, 2, or 3. 

\<types\><<<
struct ch_map_rec{
  char* line;
  int max, chars;
};
>>>


\<vars\><<<
static struct ch_map_rec  ch_map[HEIGHT];
static   int max_map_line, min_map_line;
>>>

The following might be too high of a bound. The agreed def of html 
allows only 1024 characters in a map. However, with the permissible
def of html,  extra characters hopefully are ignored without causing
problems. Also note that we probably going to have leading and
trailing row that are not in use, and 120 line for a full page figure
is not relly that big of a bound on the numer of lines per page.

\<defines\><<<
#define HEIGHT 120
>>>


\<h ch\><<<
1>>>

\<v ch\><<<
2>>>

\<black ch\><<<
3>>>

\<design bound\><<<
4>>>



The str is a string holding the text that belongs
to the corresponding position: representation for the character,
specials, etc. The design hold a drawing content corresponding to
space, horizontal line, vertical line, and filled area,
respectively. If the str is empty, the design is assumed to be the
content of the character. If the string is not empty, it is assumed to
be the content of the character.


The string holds  character codes in
the range of 32--255. Hence, we still have a room to get more
sophisticated designs.



\<vars\><<<
static BOOL ch_map_flag = FALSE;
>>>





\<defines\><<<
#define NULL_MAP (struct map_line_type*) 0
>>>


\SubSection{Initialization}

\List{$\circ$}

\item \`'\special{t4ht!}' --- Default.
\item \`'\special{t4ht!i}'--- Magnified by i/100.
\item \`'\special{t4ht!i,j}'--- Magnified by (i/100,j/100).
\EndList

\<enter char map\><<<
init_ch_map();
xresolution = yresolution = 0;
while( special_n-- > 0 ){
  ch = get_char();
  if( (ch >= '0') && (ch <= '9') )
     { yresolution = yresolution * 10 + ch - '0'; }
  else if( (ch == ',') && !xresolution && yresolution )
     { xresolution = yresolution;  yresolution = 0; }
  else { `<resolve boundary ch in maps`> }
}
if( !xresolution )  xresolution = yresolution;
if( !xresolution ){ xresolution = XRESOLUTION; 
                    yresolution = YRESOLUTION; }
else { xresolution = xresolution * (INTEGER) (XRESOLUTION / 100);
       yresolution = yresolution * (INTEGER) (YRESOLUTION / 100);  }
>>>


Resolution can be an integer number or a pair of integer numbers
separated by a comma. The first for x-resolution, the second for
y-resolution. Then we can have a map for boundary characters made
up of pairs: character to be replaced followed by replcment.

\<resolve boundary ch in maps\><<<
xresolution = yresolution = 0;
`<special resolution err`>
>>>





\<vars\><<<
static INTEGER xresolution, yresolution;
>>>










\<defines\><<<
#define XRESOLUTION MARGINSP
#ifdef LONG
#define YRESOLUTION 786432L
#else
#define YRESOLUTION 786432
#endif
>>>


\<header functions\><<<v
static void init_ch_map( ARG_I(void) );
>>>

\<functions\><<<
static void init_ch_map(MYVOID)
{   int i; 
  for( i=0; i<HEIGHT; i++ ){
    ch_map[i].max = 0;  ch_map[i].chars = 0;  ch_map[i].line = NULL;  }  
  max_map_line = -1;
  min_map_line = HEIGHT;
}
>>>


\Section{Fill Map}


\SubSection{With Characters}

The 0.75 constant has been derived by trial and error by centering
the nodes of \`'\TreeSpec(\SRectNode)()()
\Tree()(
   3,dog//
0,boxer & 0,cocker & 3, schnauzer //
0,miniature~~schauzer & 0,standard~~schnauzer & 0,giant~~schnauzer//
)'.

\<insert ch to ch-map\><<<
insert_ch_map((char) ch, TRUE);
>>>

\<ch: 1, ruler: 0\><<<
tag>>>



\<header functions\><<<
static void insert_ch_map( ARG_II(char,BOOL) );
>>>

\<functions\><<<
`[
static void insert_ch_map( ch, `<ch: 1, ruler: 0`> )
       U_CHAR ch`;
       BOOL `<ch: 1, ruler: 0`>

;{     int row, col;
   `<get row and col for ch`>
   if(ch != 10){
      if( (ch_map[row].max > MAX_MAP_LINE) || (col > MAX_MAP_LINE) ){
        if( ok_map ){ warn_i_int_2( 25, MAX_MAP_LINE, ch);  
                      ok_map = FALSE; }
      }else{  `<adjust boundary ch`>
         if( row < min_map_line ) min_map_line = row;
         if( row > max_map_line ) max_map_line = row;
         if( ch_map[row].max ){ `<insert char to nonempty map line`> }
         else { `<insert char to empty map line`> }
}  }   }
>>>




Leave the following to the user responsibility of getting the char 
mappings rightly in the `.htf' fonts.

\Verbatim
\<adjust boundary ch NO\><<<
switch( ch ){
  case '>': { ch = 'x'; break; }
  case '&': { ch = ''; break; }
  case '"': { ch = ''; break; }
}
>>>
\EndVerbatim

\<vars\><<<
static U_CHAR ok_map = TRUE;
>>>



\<get row and col for ch\><<<
{          double x;
   row = (int) ( (y_val>0? y_val : 0.0) / (double) yresolution + 0.5);
   if( row >= HEIGHT ){  
     if( ok_map ){ warn_i_int_2( 34, row, ch); ok_map = FALSE; }
     return; }
   x = (x_val>0? x_val : 0.0 ) / (double) xresolution + 0.75;
   col = (int) x;
   if( (ch > ' ') && (ch != '-') && (ch != '|') ){
      if( row == prevrow ){
         if( (col == prevcol + 1) && (x > prev_x + 0.5) )
            insert_ch_map(' ', TRUE);
         else if( (col > prevcol + 1) && (x < prev_x+0.2)
                                      && ( ch != '&' ))
            col = prevcol + 1;
      }else  prevrow = -1;
      prev_x = x
             + (`<(double) char_width( design_ch? design_ch : ch )`>)
             / (double) xresolution;
      prevcol = col;
   }else  prevrow = -1;
   prevrow = row;
}
>>>


The `{\tt( ch != '\&' )}' above is to avoid breaking indirect
unicode characters \`'&...;' in character maps.





\<vars\><<<
static int prevcol = -1, prevrow;
static double prev_x;
>>>


\<defines\><<<
#define MAX_MAP_LINE 500
>>>




\<insert char to empty map line\><<<
   int   n;
   char* p;
ch_map[row].chars = (n = (col + 2 + 5) / 5 * 5) - `<ch: 1, ruler: 0`>;
ch_map[row].max =  n - 1;
ch_map[row].line = p = m_alloc(char, n);
while( n-- ){ *(p++) = 0; }
*(ch_map[row].line + col) = ch;
>>>






\Verbatim
\<insert char to empty map lineNO\><<<
                                               int   n;
                                               char* p;
ch_map[row].chars =  (n = (col + 2 + 5) / 5 * 5)
                                 - `<ch: 1, ruler: 0`>;
ch_map[row].max =  n - 1;
ch_map[row].line = p = m_alloc(char, n);
while( n-- ){ *(p++) = 0; }
*(ch_map[row].line + col) = filter_bound_ch(ch);
>>>

\EndVerbatim



\<insert char to nonempty map line\><<<
    int   n;
    char* p;
if( ch_map[row].chars > col ){
      `<insert char within map line`> }
else{ `<insert char beyond end of map line`> }
>>>

Below: 8 = 1 (col starts at 0) + 2 (new ch=ch+bound) + 5 (rounding)

The rounding to 5 to (hopefully) help garbage collection.



\<insert char beyond end of map line\><<<
n = (col - ch_map[row].chars + 8) / 5 * 5;
ch_map[row].chars += n - `<ch: 1, ruler: 0`>;
ch_map[row].max += n;
ch_map[row].line = (char *) 
    r_alloc((void *) ch_map[row].line,
            (size_t) ch_map[row].max + 1);
while( n-- )  *(ch_map[row].line + ch_map[row].max - n) = 0;
*(ch_map[row].line + ch_map[row].max
         - (ch_map[row].chars - col) + !`<ch: 1, ruler: 0`> ) = ch;
>>>






\Verbatim
\<insert char beyond end of map lineNO\><<<
n = (col - ch_map[row].chars + 8) / 5 * 5;
ch_map[row].chars += n - `<ch: 1, ruler: 0`>;
ch_map[row].max += n;
ch_map[row].line = (char *) 
      r_alloc((void *) ch_map[row].line,
              (size_t) ch_map[row].max + 1);
while( n-- )  *(ch_map[row].line + ch_map[row].max - n) = 0;
*(ch_map[row].line + ch_map[row].max
    - (ch_map[row].chars - col) + !`<ch: 1, ruler: 0`> ) =
                                 filter_bound_ch(ch);
>>>

\EndVerbatim





\<insert char within map line\><<<
if( `<ch: 1, ruler: 0`> ){             
   if(   *(ch_map[row].line + ch_map[row].max - 1) 
      ||  (ch_map[row].chars - col == 1)  ){ `<get room for ch`> }
   col = (ch_map[row].chars--) - col;
   p = ch_map[row].line + ch_map[row].max;
   while( col ){                     unsigned char temp_ch;
     if( ((unsigned char) (*p)) < `<design bound`> ) col--;
       temp_ch = *(--p);  *(p+1) = temp_ch;  }
} else {
   col = ch_map[row].chars - col;
   p = ch_map[row].line + ch_map[row].max;
   while( col ){  
     if( ((unsigned char) (*p)) < `<design bound`> ) col--;  p--;  }
}
*(++p) = ch;
>>>





\Verbatim
\<insert char within map lineNO\><<<
if( `<ch: 1, ruler: 0`> ){
   if(   *(ch_map[row].line + ch_map[row].max - 1) 
      ||  (ch_map[row].chars - col == 1)  ){ `<get room for ch`> }
   col = (ch_map[row].chars--) - col;
   p = ch_map[row].line + ch_map[row].max;
   while( col ){  if( ((unsigned char) (*p)) < `<design bound`> ) col--;
                  *(p+1) = *(--p);  }
} else {
   col = ch_map[row].chars - col;
   p = ch_map[row].line + ch_map[row].max;
   while( col ){  
     if( ((unsigned char) (*p)) < `<design bound`> ) col--;  p--;  }
}
*(++p) = filter_bound_ch(ch);
>>>

\EndVerbatim




\<get room for ch\><<<
ch_map[row].max += 5;
ch_map[row].line = (char *) 
   r_alloc((void *) ch_map[row].line,
           (size_t) ch_map[row].max + 1 );
for( n = 0; n<5; n++ ) 
   *(ch_map[row].line + ch_map[row].max - n) = 0;
ch_map[row].chars += 5;
>>>


REMOVE FILTER!!!!!!

\Verbatim
\<header functionsNO\><<<
INTEGER filter_bound_ch( ARG_I(INTEGER) );
>>>


\EndVerbatim



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{With Rulers}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<ruler into ch map\><<<
   long int  sv_x_val, sv_y_val, sv_right, sv;
   int  ch;
sv_x_val = x_val;   
sv_y_val = y_val;
sv_right = right;
y_val-=up;
if( right < 0 ){ x_val += right;  right = -right; }
if( up < 0 ){ y_val += up;  up = -up; }
ch = ( (right > xresolution) &&  (up > yresolution) ) ?  
       `<black ch`> :  ( ( right > up )? `<h ch`> : `<v ch`> );
right += x_val;
up    += sv = y_val;
for( ; x_val < right; x_val += xresolution )
  for( y_val = sv ; y_val < up;  y_val += yresolution )
     insert_ch_map((char) ch, FALSE);
x_val = sv_x_val;
y_val = sv_y_val;
if( sv_x_val + sv_right > max_x_val ) max_x_val = sv_x_val + sv_right;
if( `<ch: 1, ruler: 0`> ) x_val += sv_right;
>>>


\Section{Dump Map}





\<exit char map\><<<
dump_ch_map();
>>>

We need memory of order 2 times the number of characters.


\<dump ch-map at end of page\><<<
if( ch_map_flag ){ 
   warn_i(27);  `% dump_ch_map();`%  init_ch_map(); }
>>>

\`'dump_ch_map();' creates overflow problems here.

\<header functions\><<<
static void dump_ch_map( ARG_I(void) );
>>>

%  if( (min_map_line < 0) || (max_map_line >= HEIGHT) ){ return; }



\<functions\><<<
static void dump_ch_map(MYVOID)
{     int   n, i, min, k, extra_sp;
      U_CHAR  *p;
      `%  struct map_line_type  *q; `%
  `<min := start of bounding box`>
  for( i=min_map_line; i<=max_map_line; i++ ){  
    if( ( n = ch_map[i].max) > 0 ){
      p = ch_map[i].line;  k = min;    extra_sp = 0;
      `<ignore trailing spaces`>
      while( 1 + n-- ){ 
        if( --k < 0 ){
          if( extra_sp && (((unsigned char) *p)     < `<design bound`>)
                       && (((unsigned char) *(p+1)) < `<design bound`>) ) 
          {  extra_sp--;
          } else { switch( *p ){ `<dump ch`> } }
        }
        p++;
      } 
      free((void *)  ch_map[i].line );
    }               
    if( i<max_map_line )  put_char('\n');
  }
  nomargin = FALSE;
}
>>>




\<min := start of bounding box\><<<
{    int   max;
   min = 100; max = 0;
   for( i=min_map_line; i<=max_map_line; i++ ){
     p = ch_map[i].line;  
     n = ch_map[i].max;  if( max < n )  max = n;
     k = 0;  while( n-- ){ if(*(p++)) break;  k++; }
     if( ch_map[i].max && (k < min) ) min = k;        }
   if( (max < 78) && !nomargin ) min = 0;
}
>>>


\<ignore trailing spaces\><<<
{     U_CHAR  *s;
   s = p + n;
   while( n && !(*s) && !(*(s-1)) ){  n--; s--; }
   if( n && !(*s) && (((unsigned char) *(s-1)) < `<design bound`>) ) n--; 
}
>>>

\<dump ch\><<<
           case 0: { put_char(' '); break; }
    case `<h ch`>: { put_char('-'); break; }
    case `<v ch`>: { put_char('|'); break; }
case `<black ch`>: { put_char('#'); break; }
         case ' ': { extra_sp++; }
          default: { `<insert ch from map into file`>  break; }
>>>

\<insert ch from map into file\><<<
    BOOL    tag;
    INTEGER count;
tag = TRUE;   count = 0;
do{   if( *p == '<' )       tag   = FALSE;
      else  if( *p == '>' ) tag   = TRUE;
            else           count += tag;
      put_char( *p ); n--; 
}while( ((unsigned char) *(++p)) >= `<design bound`> );
if( !count ){ n++; p--; }
>>>


COUNT the number of characters and issue a warning if 
over limit (1024 default).

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Extract Code of Figures}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%
\Section{Outline}
%%%%%%%%%%%%%%%%%%

A figure is taken to be a chunck of dvi code enclosed between
\`'+' specials. They are to be translated to, for instance, gif code.

\<vars\><<<
static BOOL  dvi_flag = FALSE, dvi_page = FALSE;
static FILE *idv_file;
>>>

\<open idv file\><<<
job_name[job_name_n-1] = 'v';
job_name[job_name_n-2] = 'd';
job_name[job_name_n-3] = 'i';
if( (idv_file = fopen(job_name, WRITE_BIN_FLAGS)) == NULL )
   bad_in_file(job_name);
`%job_name[job_name_n-3] = '\0';`%
>>>


\<main's vars\><<<
long int eof_op_n, begin_postamble;
int dis_pages;
>>>


\<extract dvi chunks\><<<
job_name[job_name_n-3] = '\0';
`<extract preamble`>
page_n = 0;   
`<start first idv page`>
while( dis_pages ){ `<extract pages`> }
`<error notice into lg`>
`<extract symbols`>
`<extract postamble`>
>>>




\<error notice into lg\><<<
if( errCode > 0 ){
   (IGNORED) fprintf(log_file, "tex4ht.c error: %d\n", errCode);
}
>>>

\<vars\><<<
static int errCode = 0;
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Ignore in Main Pass}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



We had   \`=case '+': {;}=  before. However, this is wrong because we
want to do nothing here with regarding to directives for the gif part.

\<ivd code in main pass\><<<
while( special_n-- > 0 )  (void) get_char();
>>>

%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Preamble}
%%%%%%%%%%%%%%%%%%%%%%%%

\<extract preamble\><<<
file_n = 14;
(IGNORED) fseek(dvi_file, 0L, `<abs file addr`>);
do{  ch = get_char();
     idv_char( ch );
     file_n++;
}while( ch == `<no op`> );
`<idv version`>
for( i=12; i ; i-- ){  idv_char( get_char() ); }
i = get_char();
idv_char( (int) i );  while( i-- ) idv_copy();
>>>


\<idv version\><<<
ch = get_char();
if( id_version != -1 ){ ch = id_version; }
idv_char( ch );
>>>


\<idv version replacement num\><<<
{          U_CHAR *q;
   q = p + 2;
   id_version = 0;
   while( *q != '\0' ){
     if( id_version != -1 ){
        if( (*q < '0') || (*q > '9') ){
           id_version = -1;
           warn_i(53);
        }
        id_version =  id_version * 10 + *q - '0';
     }  
     q++;
}  }
>>>

\<vars\><<<
static int id_version = -1;
>>>


%%%%%%%%%%%%%%%%%%%%
\Section{Postamble}
%%%%%%%%%%%%%%%%%%%%

\<extract postamble\><<<
idv_char(`<retrieve loc op`>);  file_n += 2;
idv_char( `<end page op`> );    
(IGNORED) fseek(dvi_file, begin_postamble, `<abs file addr`>);
begin_postamble  = file_n;          
idv_char( `<begin-postamble op`> );   file_n += 5;
idv_int( bop_addr );  (IGNORED) fseek(dvi_file, 5L, `<relative file addr`>);
for( i = 20; i;  i-- ) idv_copy();
>>>

\<extract postamble\><<<
i = (INTEGER) get_int(2) + 1;    idv_char( (int) i >> 8 );  `%stack depth`%
idv_char( (int) i & 0xFF );  file_n += 2;
if( !page_n ) page_n++;   idv_char( page_n >> 8 );    `%page number`%
idv_char( (int) page_n & 0xFF );  file_n += 2;
(IGNORED) fseek(dvi_file, 2L, `<relative file addr`>);
>>>

\<extract postamble\><<<
eof_op_n -= 32;                                       `%fonts`%
while( --eof_op_n ) idv_copy();
idv_int(begin_postamble);                   `%start postamble`%
(IGNORED) fseek(dvi_file, 4L, `<relative file addr`>);  file_n += 4;
`<idv version`>
for( i = 8 - file_n % 4;  i;  i-- ) idv_char( `<eof op`> );
>>>

%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Body}
%%%%%%%%%%%%%%%%%%%%%%%%


\<extract pages\><<<
if( (ch = get_char()) < 128 ) { visible_cnt = TRUE;  cond_idv_char( ch );}
else switch( ch ){ `<chars for idv`> }
>>>



\<chars for idv\><<<
case 128: case 129: case 130: case 131: case 133:
case 134: case 135: case 136: {
  visible_cnt = TRUE;  cond_string( ch, (ch - (ch>132)) % 4 +1 ); 
  break; 
}
>>>

Why the \`'cond_string' above?


\<chars for idv\><<<
case   `<start page op`>: { 
  x_val = 0;   y_val = 0;  stack_n = 0;
  (IGNORED) fseek(dvi_file, 44L, `<relative file addr`>);  break; }
case     `<end page op`>: { dis_pages--; }
case           `<no op`>: { break; }
>>>


\<chars for idv\><<<
case `<mv hor dist dx.1`>: {
  cond_idv_char( ch );  x_val += dx_1;  break; }
case `<mv hor dist dx.2`>: { 
  cond_idv_char( ch );  x_val += dx_2;  break; }
case `<mv ver dist dy.1`>: {
  cond_idv_char( ch );  y_val += dy_1;  break; }
case `<mv ver dist dy.2`>: {
  cond_idv_char( ch );  y_val += dy_2;  break; }
>>>


\<chars for idv\><<<
case `<mv hor 1-byte`>: case `<mv hor 2-byte`>: 
case `<mv hor 3-byte`>: case `<mv hor 4-byte`>: {  
    cond_idv_char( ch );
    x_val += cond_int( ch - `<mv hor 1-byte`> + 1 );  break; }
case `<dx.1 store and mv hor 1-byte`>: 
case `<dx.1 store and mv hor 2-byte`>:
case `<dx.1 store and mv hor 3-byte`>: 
case `<dx.1 store and mv hor 4-byte`>: {   
    cond_idv_char( ch );
    dx_1 = (INTEGER) cond_int( ch - `<dx.1 store and mv hor 1-byte`> + 1);  
    x_val += dx_1;   break;  }
case `<dx.2 store and mv hor 1-byte`>: 
case `<dx.2 store and mv hor 2-byte`>: 
case `<dx.2 store and mv hor 3-byte`>: 
case `<dx.2 store and mv hor 4-byte`>: {   
    cond_idv_char( ch );
    dx_2 = (INTEGER) cond_int( ch - `<dx.2 store and mv hor 1-byte`> + 1);  
    x_val += dx_2;   break;  }
>>>

\<chars for idv\><<<
case `<mv ver 1-byte`>: case `<mv ver 2-byte`>: 
case `<mv ver 3-byte`>: case `<mv ver 4-byte`>: {   
    cond_idv_char( ch );
    y_val += cond_int( ch - `<mv ver 1-byte`> + 1);          
    break; }
case `<dy.1 store and mv ver 1-byte`>: 
case `<dy.1 store and mv ver 2-byte`>: 
case `<dy.1 store and mv ver 3-byte`>: 
case `<dy.1 store and mv ver 4-byte`>: {   
    cond_idv_char( ch );
    dy_1 = (INTEGER) cond_int( ch - `<dy.1 store and mv ver 1-byte`> + 1);   
    y_val += dy_1;   break; }
case `<dy.2 store and mv ver 1-byte`>: 
case `<dy.2 store and mv ver 2-byte`>: 
case `<dy.2 store and mv ver 3-byte`>: 
case `<dy.2 store and mv ver 4-byte`>: {   
    cond_idv_char( ch );
    dy_2 = (INTEGER) cond_int( ch - `<dy.2 store and mv ver 1-byte`> + 1);   
    y_val += dy_2;   break; }
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Rules}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<chars for idv\><<<
case   `<insert rule + move op`>:{ 
  visible_cnt = TRUE; cond_string( ch,4 ); x_val += cond_int(4); 
  break; 
}
case `<insert rule + nomove op`>:{ 
  visible_cnt = TRUE; cond_string( ch, 8 );   
  break; 
}
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Specials}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Only \`'+' tex4ht specials are significant here.  The ones of the form
\`'\special{t4ht++...}...\special{t4ht+}' act as delimiters for
segments of dvi code to be trasmitted to the dvi driver (probably
dvips).  The other ones of the form \`'\special{t4ht+...}' are ignored
outside such segments, and are replaced by sub-specilas
\`'\special{...}'  within the segments. For instance,
\`'\special{t4ht+ps:abc}' translates to \`'\special{ps:abc}' within
these segments. That is, the latter ones are indirect transpoters for
special code (why we need this transportes?).

The non-tex4ht specials are introduced into the idv code.   Those that
are parts of the picture environment, are included there (\''dvi_page=TRUE').
Those that not, are included in separate pages.  The latter ones might be
definitions and directives for the pictures, as is the case  for pstricks
which sends them to dvips.

\<chars for idv\><<<
case `<special 1`>:  case `<special 2`>: 
case `<special 3`>:  case `<special 4`>: {  long int i;
                                            int special_nr;
  special_nr = ch;
  if( tex4ht_special( &ch, &i ) ){
     if( ch == '+' ){                  
        `<handle requests for dvi to gif code`> }
     else   while( i-- ) (void)  get_char();
  }else if( dvi_flag ){ `<insert non-t4ht special into picture`>  
  }else { `<insert non-t4ht special on non-picture page`> }
  break; 
}
>>>




\<insert non-t4ht special on non-picture page\><<<
if( dvi_page || !page_n ){ dvi_page = FALSE;  `<advance idv page`>  }
dvi_flag = TRUE;
`<insert non-t4ht special`>
dvi_flag = FALSE;
>>>

\<insert non-t4ht special on non-picture pageNO\><<<
while( i-- )  (IGNORED) get_char();
>>>

Replace the last piece with a seek!
  (IGNORED) fseek(dvi_file, (long)i, `<relative file addr`>);  


\<insert non-t4ht special into picture\><<<
visible_cnt = TRUE;   `<insert non-t4ht special`>
>>>


\<insert non-t4ht special\><<<
{
      U_CHAR *ch;
      int j;
   ch = special_hd;
   (IGNORED) putc( (unsigned) `<special 4`>, idv_file );  file_n++;
   for(j=4; j--; ){  (IGNORED) putc( *ch, idv_file );  file_n++;  ch++; }
   while( *ch ){  (IGNORED) putc( *ch, idv_file );  file_n++;  ch++; }
   file_n += (int) i;
   while( i-- )  (IGNORED) putc( get_char(), idv_file );  
}
>>>





\<handle requests for dvi to gif code\><<<
if( i==0 ){ if( dvi_flag ){ dvi_flag = 0;  `<end dvi page`> } }
else{
  if( dvi_flag ){ `<make a special for dvi driver`> }
  else switch( get_char() ){ 
     case '+': { `<out gif filename`>
                 dvi_flag = TRUE;  dvi_page = TRUE;
                 `<advance idv page`>  break; }
     case '@': { `<write to lg file`> break; }
      default: { while( --i ) (void)  get_char();  break; }
} }
>>>



\<write to lg file\><<<
while( --i ) (void)  putc( get_char(), log_file );  
(IGNORED) putc( '\n', log_file );  
>>>




\Verbatim
\<handle requests for dvi to gif codeNO\><<<
if( i==0 ){ if( dvi_flag ){ dvi_flag = 0;  `<end dvi page`> } }
else{
  if( dvi_flag ){ `<make a special for dvi driver`> }
  else if( '+'==get_char() ){ 
    `<out gif filename`>
    dvi_flag = 1;  `<advance idv page`> }
  else  while( --i ) (void)  get_char(); 
}
>>>

\EndVerbatim



\<out gif filename\><<<
{    U_CHAR str[256], *ch;
   ch = str;   while( --i )  *(ch++) =  get_char();  *ch = '\0';
   script(font_gif, job_name ,page_n+1, str);
}
>>>

\`'printf("%s", str);'--- tooo much info for screen, and not that significant.


\Verbatim
\<handle requests for dvi to gif codeNO\><<<
if( i ){ `<make a special for dvi driver`> }
else{  dvi_flag = !dvi_flag;
       if( dvi_flag ){ `<advance idv page`> }
       else { `<end dvi page`> }                  }
>>>
\EndVerbatim


\<make a special for dvi driver\><<<
cond_idv_char( special_nr );
cond_idv_int( i, special_nr - `<special 1`> + 1 );  
while( i-- )  cond_idv_char( get_char() );
visible_cnt = TRUE;
>>>


\<advance idv page\><<<
visible_cnt = FALSE; 
bop_addr = advance_idv_page( bop_addr, cur_font );
stack_depth = 0;
set_loc( `<mv hor 1-byte`>, x_val );
set_loc( `<mv ver 1-byte`>, y_val );
>>>



\<idv vars\><<<
INTEGER bop_addr;
>>>


\<header functions\><<<
static void  set_loc( ARG_II(int, long int) );
>>>

\<functions\><<<
`[
static void  set_loc( op, d ) 
          int op`;
   long   int d

;{
   idv_char( op + 3 );  int_to_dvi( d, 4 ); file_n += 5;
}
>>>

\SubSection{Stack}

\<chars for idv\><<<
case `<sv loc op`>: {  
   push_stack();   
   stack_depth++;
   cond_idv_char( ch );   
   break; }
case `<retrieve loc op`>: {      INTEGER cur_x, cur_y;
   stack_depth--; 
   cur_x = (INTEGER) x_val;  cur_y = (INTEGER) y_val;  pop_stack();
   if( dvi_flag ){
      if( stack_depth<0 ){ warn_i_int( 24,  page_n );
                           `<push curr state`>     }
      cond_idv_char( ch );                     
   }
   break; }
>>>

\<push curr state\><<<
cond_idv_char( `<mv hor 4-byte`> );
idv_int( x_val - cur_x - dx_1 - dx_2 );
cond_idv_char( `<dx.1 store and mv hor 4-byte`> );
idv_int( dx_1 );
cond_idv_char( `<dx.2 store and mv hor 4-byte`> );
idv_int( dx_2 );
cond_idv_char( `<mv ver 4-byte`> );
idv_int( y_val - cur_y - dy_1 - dy_2 );
cond_idv_char( `<dy.1 store and mv ver 4-byte`> );
idv_int( dy_1 );
cond_idv_char( `<dy.2 store and mv ver 4-byte`> );
idv_int( dy_2 );
cond_idv_char( `<sv loc op`> );  file_n += 24;
>>>

\<end dvi page\><<<
if( !visible_cnt ) {                            U_CHAR  str[256];
   (IGNORED) sprintf(str, "--- empty picture --- %sidv[%d] ---\n",
                          job_name,page_n); 
   (IGNORED) printf("%s", str);  (IGNORED) fprintf(log_file, "%s",str); }
while( stack_depth-- > 0 ){ 
  idv_char(`<retrieve loc op`>);  file_n++; }
>>>


\<idv vars\><<<
int stack_depth=0;
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Fonts Definition}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<chars for idv\><<<
case `<def 4 byte font`>: 
case `<def 3 byte font`>: 
case `<def 2 byte font`>: 
case `<def 1 byte font`>: {  idv_char( ch );             file_n++;
  for( i=14; i; i-- ){  ch = get_char(); idv_char( ch ); file_n++; }
  i = ch;  i += ch = get_char();  idv_char( ch );        file_n++;
  while( i-- ){ idv_copy(); }
  break;  }
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Fonts Activation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


The following must be consisted with the usage 
\`'for( i=1; i<=cur_font[0]; i++ ){'.

\<chars for idv\><<<
case  `<font 1-byte`>:
case `<font 2-bytes`>: 
case `<font 3-bytes`>: 
case     `<font int`>: {    int i;
   idv_char( ch );  file_n++;                 
   cur_font[0] = ch - `<font 1-byte`> + 2;
   cur_font[1] = ch;
   for( i=2; i <= cur_font[0]; i++ ){ 
      ch = get_char();    idv_char( ch );   
      cur_font[i] = ch;   file_n++;         }
   break;  }
>>>

\<chars for idv\><<<
default: {
  if( (ch < `<font 0`>) || (ch > `<font 63`>)   ){
     if( `<font defs for xdv's idv?`> ){
        `<xdv font def for idv`>
     } else { err_i(23); }
  }
  else {  idv_char( ch );  file_n++; 
          cur_font[0] = 1;    cur_font[1] = ch;   }
  break;   
}
>>>

\<idv vars\><<<
char cur_font[6];
BOOL visible_cnt=FALSE; 
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   
\Section{Symbols from Fonts}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%   


\<extract symbols\><<<
{                                               int   ch, i, mag;
                                                U_CHAR  str[256];
   (IGNORED) fprintf(log_file, "%s", begin_char_gif); 
   dvi_flag = TRUE;    
   for( cur_fnt = font_tbl_size; cur_fnt--; ){
      `<output to lg file`>
      for( i = font_tbl[cur_fnt].char_l - font_tbl[cur_fnt].char_f + 1;
           i--; )
         if( get_bit( font_tbl[cur_fnt].gif_on, i) ){
            bop_addr = advance_idv_page( bop_addr, cur_font );
            set_loc( `<mv hor 1-byte`>, (long int) mid_page_x );
            set_loc( `<mv ver 1-byte`>, (long int) mid_page_y );
            `<get font of symbol`>
            `<insert the char code`>        } 
   } 
   (IGNORED) printf("Execute script ``%slg'\n",
                    job_name);   
   (IGNORED) fclose( log_file );                           
}
>>>







\<insert the char code\><<<
if( (ch = i + font_tbl[cur_fnt].char_f) > 127 )  {
  if( ch < 256 ) cond_idv_char(133);  else  warn_i(23);   }
cond_idv_char( ch );    
mag = (int) ((double) font_tbl[cur_fnt].scale /
             font_tbl[cur_fnt].design_sz  * 10 );
`<insert gif symbol to lg file`>
script(font_gif, job_name ,page_n, str);
>>>

\`'printf("%s", str);' --- too mach info

\<open log file\><<<
{      U_CHAR str[256];
   (IGNORED) strcpy((char *) str, (char *) job_name);
   str[job_name_n-1] = '\0';
   str[job_name_n-2] = 'g';
   str[job_name_n-3] = 'l';
   if( (log_file = fopen(str, WRITE_TEXT_FLAGS)) == NULL )
                                           bad_in_file(str);
}
>>>

\<vars\><<<
static FILE*  log_file;
>>>

\<max page dimensions\><<<
mid_page_y = (INTEGER) get_unt(4) / 2;
mid_page_x = (INTEGER) get_unt(4) / 2;
>>>

\<vars\><<<
static INTEGER mid_page_y, mid_page_x;
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Activate Font}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<get font of symbol\><<<
{           INTEGER num;
   num = font_tbl[cur_fnt].num;
   if( num <= `<number of direct fonts`> )
                                cond_idv_char( (int) (num + `<font 0`>) );
   else if( dvi_flag ){ 
     if( (num < 0) || (num > 16777215L) ) idv_int(`<font int`>);
     else if( num < 256 ) { idv_char(`<font 1-byte`>); file_n++; }
     else if( num < 65536L ) int_to_dvi((long int) `<font 2-bytes`>,2);
     else                   int_to_dvi((long int) `<font 3-bytes`>,3);
     cond_idv_char( (int) num );
}  }
>>>

The above seems to be incorrect for big numbers!!!!!!!!!!!!!!

\Section{Utilities}


\<header functions\><<<
static void idv_char( ARG_I(int) );
>>>

\<functions\><<<
`[
static void idv_char( n )         int  n
;{ (IGNORED) putc( n, idv_file ); }
>>>




\<header functions\><<<
static void cond_idv_char( ARG_I(int) );
>>>

\<functions\><<<
`[
static void cond_idv_char( n )         int  n
;{
   if( dvi_flag ){  (IGNORED) putc( n, idv_file );  file_n++;  }
}
>>>




\<header functions\><<<
static void idv_copy( ARG_I(void) );
>>>

\<functions\><<<
static void idv_copy(  MYVOID )       
{  idv_char( get_char() );  file_n++;  }
>>>
\<defines\><<<
#define idv_int(val)     int_to_dvi((long int) val,4)
>>>




\<header functions\><<<
static void cond_idv_int( ARG_II(long int, int) );
>>>

\<functions\><<<
`[
static void cond_idv_int( val, n )  long   int val`;
                             int n
;{
  if( dvi_flag ){  int_to_dvi((long int)  val, n );   file_n += n;  }
}
>>>


\<header functions\><<<
static void  int_to_dvi( ARG_II(long int, int) );
>>>

\<functions\><<<
`[
static void  int_to_dvi( val, n )  long int val`;
                                int n

;{         unsigned U_CHAR ch2, ch3, ch4;
  ch4 = (unsigned char) (val & 0xFF);   val = val >> 8;
  ch3 = (unsigned char) (val & 0xFF);   val = val >> 8;
  ch2 = (unsigned char) (val & 0xFF);   val = val >> 8;
  switch( n ){
    case 4: idv_char( (int) val );
    case 3: idv_char( ch2 );
    case 2: idv_char( ch3 );
    case 1: idv_char( ch4 ); }
`%  if( val & 0x80 )     val -= 0x100;`%
}
>>>

\<header functions\><<<
static void cond_string( ARG_II(int, int) );
>>>

\<functions\><<<
`[
static void cond_string(ch, n)           int  ch`; int n

;{  cond_idv_char( ch );  
   while( n-- )  cond_idv_char( get_char() );
}
>>>


\SubSection{Advance Page}


\<start first idv page\><<<
x_val = 0;   y_val = 0;   stack_n = 0;
idv_char( `<start page op`> );
idv_int( page_n + 1 );  for( i=36; i--; ) idv_char( 0);
idv_int( -1 );  bop_addr = file_n;  file_n += 45;
idv_char(`<sv loc op`>);  file_n++;
>>>

\<vars\><<<
static int page_n,  file_n;
>>>


\<header functions\><<<
static INTEGER advance_idv_page( ARG_II( INTEGER,char*) );
>>>

\<functions\><<<
`[
static INTEGER advance_idv_page( bop_addr, cur_font )  
                                            INTEGER    bop_addr`; 
                                            char*  cur_font

;{                                           int    i;
   if( page_n++ ){
     idv_char(`<retrieve loc op`>);  file_n++;
     idv_char(`<end page op`>);      file_n++;     
     idv_char( `<start page op`> );
     idv_int( page_n );  for( i=36; i--; ) idv_char( 0);
     idv_int( bop_addr );  bop_addr = file_n;  file_n += 45; 
     idv_char(`<sv loc op`>);  file_n++;
     for( i=1; i<=cur_font[0]; i++ ){
        idv_char( cur_font[i] );   file_n++; 
   } }
   `<set dx-1, dx-2, dy-1, dy-2`>
   return  bop_addr;
}
>>>

What \`'cur_font[0]' holds?


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Set Store-Move Variables}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Dvips requires font definitions before the following code in the first
dvi page.

\<set dx-1, dx-2, dy-1, dy-2\><<<
store_mv(`<dx.1 store and mv hor 4-byte`>, dx_1);
store_mv(`<dx.2 store and mv hor 4-byte`>, dx_2);
store_mv(`<dy.1 store and mv ver 4-byte`>, dy_1);
store_mv(`<dy.2 store and mv ver 4-byte`>, dy_2);
>>>

\<header functions\><<<
static void store_mv( ARG_II( int, INTEGER) );
>>>


\<functionsNO-sep-9\><<<
`[
static void store_mv(op, d)  int op`;  INTEGER d

;{
   cond_idv_char(op);  cond_idv_int( (INTEGER) -d);
   cond_idv_char(op);  cond_idv_int( (INTEGER)  d); 
}
>>>




\<functions\><<<
`[
static void store_mv(op, d)  int op`;  INTEGER d

;{
 if( dvi_flag ){  
   cond_idv_char(op);  idv_int( (INTEGER) -d);
   cond_idv_char(op);  idv_int( (INTEGER)  d);  file_n += 8; }
}
>>>


\Chapter{Tables}






\Section{The Options}

In TeX, we initiate tables of the form

\Verbatim
\haligh{
  ... & ... & ... \cr
  ... & ... & ... \cr
}
\EndVerbatim

Such tables translate to dvi tables of the form

\Verbatim
<group>
    <group> ... </group>
    <group> ... </group>
    <group> ... </group>
</group>

<group>
    <group> ... </group>
    <group> ... </group>
    <group> ... </group>
</group>
\EndVerbatim

The option \`'@' asks to start puting the entries over 
the following groups.

Two problems arise: 

\List{a}
\item
 Unless the tables are followed by 
external end-groups, we don't have any mark telling where they end.
 The \`'/' special can be used in the sources to identify the 
ends.

\item The \`'\nohalign' commands provide dirty entries between the rows.

\EndList






\<halign specials\><<<
                                int i;
i = 0;
special_n--;
switch ( get_char() ){
  case '8': { i++; }
  case '7': { i++; }
  case '6': { i++; }
  case '5': { i++; }
  case '4': { i++; }
  case '3': { i++; }
  case '2': { i++; }
  case '1': { `<new halign setting`> break; }
  case '/': { if( special_n ){ 
                `<consume unused specials`>
              } else { `<output end halign table`> }   
              break;
            }
  case '&': { i++; }
  case '@': { i++;
              if( special_n ){ 
                `<consume unused specials`>
              } else { 
                `<start halign table`>
              }   
              break;
            }
   default: { `<consume unused specials`> }
}
>>>









\Section{Info for Entries}

\SubSection{Inilialization of Base}

 The base entries are stored in a set of global variables
  \`'str[i]', and the number of usages is stored in
  \`'refs[i]'.  The strings can be used from the  global shared base
   or the local groups.



\<vars\><<<
static struct halign_rec *halign[8];
>>>

\<defines\><<<
struct halign_rec{
  char * str;
  int    refs;
};
>>>

\<main's init\><<<
{                                         int i;
  for( i=8; i--; ){
    halign[i]         = m_alloc(struct halign_rec, 1);
    halign[i]->str    = m_alloc(char, 1);
    *(halign[i]->str) = '\0';
    halign[i]->refs   = 1;
  }
}
>>>

\SubSection{Modifications to Base}

\<new halign setting\><<<   
if( halign[i]->refs == 1 ){ 
   free((void *) halign[i]->str ); 
} else {  
   (halign[i]->refs)--;
   halign[i]         = m_alloc(struct halign_rec, 1);
   halign[i]->refs   = 1;
}
halign[i]->str = get_str( (int) special_n ); 
special_n=0;
>>>
















\SubSection{Initializations for Groups}


 Each group level has its local set of variables.  Whenever a
  request \`'@' or \`'&'arrives, we verify that the the local entries
  equal to the current global entries. If not, the local entries are
  replaced with copies of the current ones.

\<struct stack_entry\><<<
struct halign_rec *halign[8];
BOOL halign_on, halign_info, row_no, col_no;
>>>


\<initialized entries for grouping stack\><<<
stack[i].halign_info = FALSE;
stack[i].halign_on = FALSE;
>>>





\SubSection{Modifications for Groups at Requests}

Upon requesting an insertion for \''\halign', through
\''\special{t4ht*@}'  or \''\special{t4ht*&}', we modify the
entries on the current group.


\<start halign table\><<<
new_halign = i * TRUE;
>>>

\<vars\><<<
static BOOL new_halign = FALSE;
>>>




\<insert start of halign\><<<
stack[stack_n].halign_on = new_halign;
if( stack[stack_n].halign_info )
{                             int j;                               
   for( j=8; j--; ){
     if( stack[stack_n].halign[j] != halign[j] ){
       if( ! (--(stack[stack_n].halign[j]->refs) ) ){
         free((void *)  stack[stack_n].halign[j]->str );
         free((void *)  stack[stack_n].halign[j] );
       }
       stack[stack_n].halign[j] = halign[j];
       (halign[j]->refs)++;
     }
  }
} else {                                        int j; 
  stack[stack_n].halign_info = TRUE;   
   for( j=8; j--; ){
     stack[stack_n].halign[j] = halign[j];
     (halign[j]->refs)++;
} }
print_f( stack[stack_n].halign[0]->str );
stack[stack_n].row_no = 0;
new_halign = FALSE;
>>>



\SubSection{Release at Starts of Groups}

The following are for introducing tabular tags for containing rows and
cols of tables. They are encounter before \''stack_n' changes its
value.

\<halign at entry to group\><<<
if( new_halign ){
  `<insert start of halign`>
}
if( stack[stack_n].halign_on )
{
   print_f( stack[stack_n].halign[2]->str );
   if( stack[stack_n].halign_on > TRUE ){
      stack[stack_n].row_no++;
      stack[stack_n].col_no = 0;   
      (IGNORED) fprintf(cur_o_file, "%d%s",
            stack[stack_n].row_no, stack[stack_n].halign[6]->str );
}  }  
if( stack_n ){
   if( stack[stack_n-1].halign_on )
   {
     print_f( stack[stack_n-1].halign[4]->str );
     if( stack[stack_n-1].halign_on > TRUE ){
        stack[stack_n-1].col_no ++;   
        (IGNORED) fprintf(cur_o_file, "%d%s",
             stack[stack_n-1].col_no, stack[stack_n-1].halign[7]->str );
     }
}  }
>>>


\SubSection{Release at Ends of Groups}


\<halign at exit from group\><<<
`<output end halign table`>
`<output end halign row`>
`<output end halign col`>
if( stack[stack_n].halign_info )
{                             int j;                               
   for( j=8; j--; ){
     if( ! (--(stack[stack_n].halign[j]->refs) ) ){
       free((void *)  stack[stack_n].halign[j]->str );
       free((void *)  stack[stack_n].halign[j] );
   }  }   
   stack[stack_n].halign_info = FALSE;
}
>>>

The ouput for end of table is for the current level of table, for end
of row is an immediately containig tables, and for a col is for second
generation containing table.

\<auto quit halign\><<<
if( stack[stack_n].halign_on )
{
   switch( ch ){
       case                `<mv ver 1-byte`>: { ; }
       case                `<mv ver 2-byte`>: { ; }
       case                `<mv ver 3-byte`>: { ; }
       case                `<mv ver 4-byte`>: { ; }
       case             `<mv ver dist dy.1`>: { ; }  
       case `<dy.1 store and mv ver 1-byte`>: { ; }
       case `<dy.1 store and mv ver 2-byte`>: { ; }
       case `<dy.1 store and mv ver 3-byte`>: { ; }
       case `<dy.1 store and mv ver 4-byte`>: { ; }
       case             `<mv ver dist dy.2`>: { ; }
       case `<dy.2 store and mv ver 1-byte`>: { ; }
       case `<dy.2 store and mv ver 2-byte`>: { ; }
       case `<dy.2 store and mv ver 3-byte`>: { ; }
       case `<dy.2 store and mv ver 4-byte`>: { ; }
       case        `<insert rule + move op`>: { ; }
       case      `<insert rule + nomove op`>: { ; }
       case                  `<font 1-byte`>: { ; }
       case                 `<font 2-bytes`>: { ; }
       case                 `<font 3-bytes`>: { ; }
       case                     `<font int`>: { ; }
       case                    `<sv loc op`>: 
                                              { break; }
     default: { `<print end of halign table`> }
}  }
>>>

\<output end halign table\><<<
if( stack[stack_n].halign_on )
{  `<print end of halign table`>  }
>>>


\<print end of halign table\><<<
print_f( stack[stack_n].halign[1]->str );
stack[stack_n].halign_on = FALSE;
>>>



\<output end halign row\><<<
if( stack_n ){
  if( stack[stack_n-1].halign_on )
  {
     print_f( stack[stack_n-1].halign[3]->str );
} }
>>>


\<output end halign col\><<<
if( stack_n-1 ){
  if( stack[stack_n-2].halign_on )
  {   
     print_f( stack[stack_n-2].halign[5]->str );
} }
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Groups and Group-Based Inline Operations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

For instance, \''\over'. Such operations require delivery of
information backward and forward to the group boundaries.
For backward delivery, a preprocessing phase is introduced.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Data Transfer}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





Upon encountering a \''\special{t4ht~...}' we arrive here.  An empty
content is an on/off flag.  When it is turned on, we make a
preprocessing pass to collect information.



\List{*}
\item \`'\special{t4ht\string~} ... \special{t4ht\string~}' --- start
/ end switches for backward submissions. 

\item
\`'\special{t4ht\string~<i...}', \`'\special{t4ht\string~>i...}' ---
send to group at relative level i.


\item
\`'\special{t4ht\string~<*...}' --- send back to start of previous
token / group.

\item   \`'\special{t4ht~<[}...\special{t4ht~<]}' --- hide region
from back token / group submission


\item   \`'\special{t4ht~<-} ... \special{t4ht~<+}'  --- latex mode
of token / group submissions  (what is that???)

\item   \`'\special{t4ht~<)} \special{t4ht~<(}...\special{t4ht~<)}'
---  activate / hide  back token / group submissions






\EndList





\<grouped-base delivery content\><<<
if( special_n ){
  `<main pass for group special`>
} else if( (group_dvi = !group_dvi) == TRUE ){
               long  curr_pos;
               int   ch, sv_stack_n;
               `<subp vars`>
  `<init subp vars`>  stack_id = 0;
  curr_pos = ftell(dvi_file);  sv_stack_n = stack_n;
  `<send info backward`>
  `<exit early pass`>
  (IGNORED) fseek(dvi_file, curr_pos, `<abs file addr`>);
  group_dvi = TRUE;  stack_n = sv_stack_n;    stack_id = 0;
} else { `<exit group special`> }
>>>


% SEEK_SET);

\<vars\><<<
static BOOL group_dvi = FALSE;
>>>

\<main's vars\><<<
int stack_id=0;
>>>


\SubSection{Main Pass}
   

\<main pass for group special\><<<
              U_CHAR in_ch;
if( (in_ch = get_char()) == '>' ) {
  `<store forward submissions`>
} else if( in_ch == '!' ) {
  `<store path-based forward submissions`>
} else {
  if( !group_dvi ){ warn_i(42); }
  (IGNORED) fseek(dvi_file, (long) --special_n, 
                             `<relative file addr`>);  
  special_n = 0;  
}
>>>



  








\ifHtml[\HPage{example}\Verbatim


\def\:temp{\special{t4ht\string~<<NOMINATOR>}\HCode{</NOMINATOR><DENOMINATOR>}\o:over:
  \special{t4ht\string~></DENOMINATOR>}}
\Let\over=\:temp


aa
\special{t4ht\string~}$
{A \over B} \over C
$\special{t4ht\string~}


\EndVerbatim\EndHPage{}]\fi








%%%%%%%%%%%%%%%%%%%%%
\SubSection{Memory}
%%%%%%%%%%%%%%%%%%%%%

\<vars\><<<
static int stack_n = 0;
static struct stack_entry* stack;
>>>

\<types\><<<
struct stack_entry{
  long  int x_val, y_val;
  INTEGER dx_1, dx_2, dy_1, dy_2;
  BOOL text_on;
  BOOL `<BOOl stack accented`>;
  `<struct stack_entry`>
};
>>>

\<stack = m-alloc...\><<<
stack = m_alloc(struct stack_entry,`<size of stack for nested boxes`>);
`<initialize grouping stack`>
>>>

\<size of stack for nested boxes\><<<
((int) stack_len + 2)
>>>

The \`'\special{t4ht^>*...*...}' asks for delimiters on the next group
or token, whichever comes first.  That information is stored in the
stack even for characters, which implies an implicit stack greater by
one than that requested by the dvi code. The extra 2 in size reults
from the pointer being on the next empty entry?

%   (IGNORED) fprintf(cur_o_file, "\n..end := begin := 0.......%d-%d",stack_id,stack_n);


\<struct stack_entry\><<<
int stack_id;
struct group_info * begin;
struct stack_end_entry * end;
>>>


\<types\><<<
struct group_info{
  int stack_id;
  U_CHAR *info;
  struct group_info* next;
};
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Initialization}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<initialize grouping stack\><<<
{                   int i;
  for( i=`<size of stack for nested boxes`>-1; i>=0; i--){
    stack[i].begin = (struct group_info *) 0; 
    stack[i].end   = (struct stack_end_entry *) 0;
    stack[i].stack_id = -1;
    `<initialized entries for grouping stack`>
} }
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Submissions and Retievals}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\SubSection{``Forward'' to End of Group}

\<store forward submissions\><<<
if( special_n == 1 ){
   special_n--;
   switch( get_char() ){ 
     case '[': { ignore_end_group++;  break; }
     case ']': { ignore_end_group--;  break; }
      default: { `<unused special`> }
   }
} else {
             struct stack_end_entry *p;
             U_CHAR                   *q;
             int                     j;
   j = get_char() - '0' + stack_n - 1;
   if( --special_n ){
     if (j >= stack_len ) { j = stack_len - 1; }
     p = m_alloc(struct stack_end_entry,1);
     p->next =  stack[ j ].end;
     stack[ j ].end = p;
     q = p->send = m_alloc(char,special_n+1);
     while( --special_n ) *q++ = get_char();
     *q = '\0';
}  }
>>>


We create a linked list for forward submissions.


\<types\><<<
struct stack_end_entry{
  struct stack_end_entry *next;
  U_CHAR *send;
};
>>>


\<retrieve forward submissions\><<<
          struct stack_end_entry *q, *p, *t;
q = stack[ stack_n-1 ].end;
p = stack[ stack_n-1 ].end = (struct stack_end_entry *) 0;
while( q ){
  t = q->next;  q->next  = p;  p = q;  q = t;
}
while( p ){
  if( ! ignore_end_group ){ print_f( p->send ); }
  free((void *)  p->send );   
  q = p;  p = p->next;    free((void *)  q );   
}
>>>



%    (IGNORED) fprintf(cur_o_file, "\n%d. SEND FORWARD.........stack[%d]   [SEND %s]\n",
%  stack_id,       stack_n-1, stack[ stack_n-1 ].end);




\<get forward deliveries\><<<
while( stack[stack_n-1].end ){
  `<retrieve forward submissions`> 
}
>>>

\<vars\><<<
static int ignore_end_group;
>>>





%    (IGNORED) fprintf(cur_o_file, "\n%d. GET FORWARD.........stack[%d] [GET: %s]\n",
% stack_id,       stack_n, stack[ stack_n ].end);





\<exit group special\><<<
{              int stack_n;
  for( stack_n=`<size of stack for nested boxes`>;
       stack_n>0; stack_n--){
    group_dvi = TRUE;    `<get forward deliveries`>
    group_dvi =FALSE;
    `<check forward deliveries`>
} } 
>>>


\<check forward deliveries\><<<
while( stack[stack_n-1].begin ){
                               struct group_info *p;      
   warn_i_str(44, stack[stack_n-1].begin->info);
   p =  stack[stack_n-1].begin;
   stack[stack_n-1].begin = p->next;    
   free((void *)  p );  
} 
stack[stack_n-1].stack_id = -1;
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{``Backward'' to Begin of Groups}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


The following is needed for pops that appear before the leading push.
Such pops can emerge from preceding code.



\<send info back to group open\><<<
          struct group_info *p;
          U_CHAR *q;
          int j;
j = ch - '0' + stack_n - 1;
if (j >= stack_len ) { j = stack_len - 1; }
p = m_alloc(struct group_info,1);
p->next = stack[ j ].begin; stack[ j ].begin = p; 
p->stack_id = stack[ j ].stack_id;
q = p->info = m_alloc(char,i+1);
while( --i ) *q++ = get_char();
*q = '\0';
>>>

``Backward'' submissions to levels higher than 0 are forward
transmission and they can be moved to the main pass.  That will buy
a little saving in memory, and possibly less fragmentation there
due to dynamic allocation of mem.





%    stack[stack_n].end = (struct stack_end_entry *) 0;

\<push/pop on backward submissions\><<<
case `<sv loc op`>: {
   `<stack-id into linked list`>
   stack[stack_n].stack_id = stack_id++;
   `<push-id + 1`>    stack_n++; 
   if( stack_n > `<size of stack for nested boxes`> ){ warn_i(40); }
   break; 
}
case `<retrieve loc op`>: { 
   stack_n--;  `<pop-id + 1`>
   stack[stack_n].stack_id = -1;
   break; 
}
>>>

The following changes the previously unknown stack-id, represented by
-1, of a future deeper PUSH with the stack-id of that PUSH. That PUSH
is just have been reached.  We also want to reverse the order within
that sub-list.

\<stack-id into linked list\><<<
{     struct group_info *p, *last;      
  if( (last = p = stack[ stack_n ].begin) != (struct group_info *)0 )
    if( p->stack_id == -1 ){
      `<modify id of sub sequence`>
      `<reverse stack sub sequence`>
    }
}
>>>

\<modify id of sub sequence\><<<
while( p ){
  if( p->stack_id != -1 ){ break; }
  p->stack_id = stack_id;
  last = p;
  p = p->next;
} 
>>>


\<reverse stack sub sequence\><<<
while ( stack[ stack_n ].begin != last ){
  p = (stack[ stack_n ].begin) -> next;
  (stack[ stack_n ].begin) -> next = last->next;
  last->next = stack[ stack_n ].begin;
  stack[ stack_n ].begin = p;
}
>>>
  


\<get backward deliveries\><<<
{                        struct group_info *p;
  if( group_dvi && 
      ( (p = stack[stack_n].begin )  != (struct group_info *)0)
    ){
     while( p ){
       if( p->stack_id != stack_id ) break;
       print_f(p->info);
       stack[stack_n].begin = p->next;
       free((void *)  p );
       p = stack[stack_n].begin;
     }
  } 
  stack_id++;
}
>>>


% if( group_dvi ){
%    (IGNORED) fprintf(cur_o_file, "\n..%d.......%d-%d",
% stack[stack_n].begin,stack_id,stack_n);
% }



%    (IGNORED) fprintf(cur_o_file,
 %        "\n%d. GET BACKWARD.........stack[%d]=%d   \n",
  %       stack_id,       stack_n,stack_id);


The following reverses the list at the end of the preprocessing pass.

\<exit early pass\><<<
{                  struct group_info  *first, *second, *temp;
                   int i;
for(i = stack_len; i >= 0; i--){
  first = stack[i].begin;
  if( first ) {
     second = first->next;
     while( second  ){
       temp =  second->next;
       second->next = first;
       first = second; 
       second = temp;
     }
     (stack[i].begin)->next = (struct group_info  *) 0;
     stack[i].begin = first;
} } }
>>>




\Section{Preprocessing Pass}

Used for collecting information to be sent backward to the entry
point of the group.  The information is stored in linked lists
of type \`'struct group_info', accessed through
\`'stack[ level-of-nesting ].begin'.   

Each PUSH is offered an id. Upon reaching a PUSH, its id is stored in
\`'stack[ level-of-nesting ].stack_id'.  Upon reaching a
\`'\special{t4ht~<...message...}', the message is inserted into the linked
list, together with its PUSH id.  The messages are retrieved in the
main pass, as the PUSHES are traversed for the second time.


\<send info backward\><<<
while( group_dvi ){
  `<extract backward submissions`>
}
>>>


\SubSection{Specials}

Only \`'~' tex4ht specials are significant here.  The ones of the form
\`'\special{t4ht~}' act as end-points for the preprocessing,
and \`'\special{t4ht~<...}' act as backward info delivers.

\<hooks for backward submissions\><<<
case `<special 1`>:  case `<special 2`>: 
case `<special 3`>:  case `<special 4`>: {  long int i;
  if( tex4ht_special( &ch, &i ) ){
     if( ch == '~' ){                  
        `<handle requests for backward submissions`> 
     } else {
       (IGNORED) fseek(dvi_file, (long) i, `<relative file addr`>);
     }
  }else{ `<ignore non-t4ht special`>  }
  break; 
}
>>>

\<ignore non-t4ht special\><<<
   U_CHAR *ch;
ch = special_hd + 4;
while( *ch ){   ch++; }
(IGNORED) fseek(dvi_file, (long) i, `<relative file addr`>);
>>>

% while( i-- )  (IGNORED)  get_char();  
% change to
% (IGNORED) fseek(dvi_file, (long) i, `<relative file addr`>);
% also in \<chars for idv\>


\<handle requests for backward submissions\><<<
if( i==0 ){ 
  group_dvi = FALSE ; 
}else{
  switch( get_char() ){ 
     case '<': {        
        if( i-- ){         U_CHAR ch;
           if( (ch = get_char()) == '*' )
             { `<send back over token / group`> }
           else if( (ch == '[') && (i==1) ){
             i--;  `<hide back token / group`>
           }
           else if( (ch == ']') && (i==1) ){
             i--;  `<end hide back token / group`>
           }
           else if( (ch == '-') && (i==1) ){
             i--;  `<latex back token / group`>
           }
           else if( (ch == '+') && (i==1) ){
             i--;  `<end latex back token / group`>
           }
           else if( (ch == '(') && (i==1) ){
             i--;  `<back token / group`>
           }
           else if( (ch == ')') && (i==1) ){
             i--;  `<end back token / group`>
           }
           else { `<send info back to group open`> }
        }
        break; }
     default: { (IGNORED) fseek(dvi_file, (long) --i, 
                               `<relative file addr`>);  break; }
} }
>>>

% sv_stack_n<stack_n 

When \''sv_stack_n==stack_n' the sending back NEED NOT be in the level
of the opening \''\special{t4ht~}'.  This is so because it can happen
that we have, for instance, \`'\special ~<POP><PUSH>'


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Fonts and Default}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



Fonts Definition:


\<ignore font def on preview pass\><<<
case `<def 4 byte font`>: (void) get_char();   
case `<def 3 byte font`>: (void) get_char();   
case `<def 2 byte font`>: (void) get_char();   
case `<def 1 byte font`>: {    int i;
  for( i=14; i; i-- ){  ch = get_char(); }
  i = ch +  get_char();  
  (IGNORED) fseek(dvi_file, (long) i, `<relative file addr`>);
  break;  }
>>>

Fonts Activation:

\<fonts and default ignored on preview pass\><<<
case  `<font 1-byte`>:
case `<font 2-bytes`>: 
case `<font 3-bytes`>: 
case     `<font int`>: {    
                              INTEGER n;
  n = ch - `<font 1-byte`> + 1;
  cr_fnt = (int)  ((n==4)? get_int(4) : get_unt((int) n));
  cr_fnt = search_font_tbl( cr_fnt );    
  break; }
default: {
  if( (ch < `<font 0`>) || (ch > `<font 63`>) ) {
     if( ch == `<end page op`> ) { warn_i(46); }
     else { warn_i_int(45,ch); }
  } else { cr_fnt = ch - `<font 0`>;  
         cr_fnt = search_font_tbl( cr_fnt );    
  }
  break;   
}
>>>

\<subp vars\><<<
int cr_fnt;
>>>

\<init subp vars\><<<
cr_fnt = cur_fnt;
>>>



\SubSection{Skipped Content}

\<extract backward submissions\><<<
if( (ch = get_char()) >= 128 ) {
  switch( ch ){ 
    `<indirect chars on early backward submissions pass`>
    `<ignore font def on preview pass`>
    `<ignore on preview pass`> 
    `<push/pop on backward submissions`> 
    `<hooks for backward submissions`>
    `<fonts and default ignored on preview pass`>
  }
} else { `<ch-id + 1`> }
>>>




\<indirect chars on early backward submissions pass\><<<
case 128: case 129: case 130: case 131: case 133:
case 134: case 135: case 136: {
  ch = (int) get_unt( (ch-(ch>132)) % 4 +1);  
  `<ch-id + 1`>
  break; 
}
>>>

\<ignore on preview pass\><<<
case `<insert rule + move op`>:
case `<insert rule + nomove op`>:{ 
  (IGNORED) fseek(dvi_file, 8L, `<relative file addr`>);  
  break; 
}
>>>

\<ignore on preview pass\><<<
case   `<start page op`>: { 
  (IGNORED) fseek(dvi_file, 44L, `<relative file addr`>);  break; }
>>>

\<ignore on preview pass\><<<
case `<mv hor 1-byte`>: case `<mv hor 2-byte`>: 
case `<mv hor 3-byte`>: case `<mv hor 4-byte`>: {
    (IGNORED) (get_int( ch - `<mv hor 1-byte`> + 1 ));  break; }
case `<dx.1 store and mv hor 1-byte`>: 
case `<dx.1 store and mv hor 2-byte`>:
case `<dx.1 store and mv hor 3-byte`>: 
case `<dx.1 store and mv hor 4-byte`>: {   
    (IGNORED) (get_int( ch - `<dx.1 store and mv hor 1-byte`> + 1));  
    break;  }
case `<dx.2 store and mv hor 1-byte`>: 
case `<dx.2 store and mv hor 2-byte`>: 
case `<dx.2 store and mv hor 3-byte`>: 
case `<dx.2 store and mv hor 4-byte`>: {   
    (IGNORED) (get_int( ch - `<dx.2 store and mv hor 1-byte`> + 1));  
    break;  }
case `<mv ver 1-byte`>: case `<mv ver 2-byte`>: 
case `<mv ver 3-byte`>: case `<mv ver 4-byte`>: {   
    (IGNORED) (get_int( ch - `<mv ver 1-byte`> + 1));          
    break; }
case `<dy.1 store and mv ver 1-byte`>: 
case `<dy.1 store and mv ver 2-byte`>: 
case `<dy.1 store and mv ver 3-byte`>: 
case `<dy.1 store and mv ver 4-byte`>: {   
    (IGNORED) (get_int( ch - `<dy.1 store and mv ver 1-byte`> + 1));   
    break; }
case `<dy.2 store and mv ver 1-byte`>: 
case `<dy.2 store and mv ver 2-byte`>: 
case `<dy.2 store and mv ver 3-byte`>: 
case `<dy.2 store and mv ver 4-byte`>: {   
    (IGNORED) (get_int( ch - `<dy.2 store and mv ver 1-byte`> + 1));   
    break; }
>>>



\<ignore on preview pass\><<<
case `<mv hor dist dx.1`>:
case `<mv hor dist dx.2`>: 
case `<mv ver dist dy.1`>: 
case `<mv ver dist dy.2`>: 
   { break; }
>>>








%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Push/Pop Locations}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<process dvi op 'ch'\><<<
case     `<sv loc op`>: { `<push values to stack`>   break; }
case `<retrieve loc op`>: { `<pop values from stack`>  break; }
>>>

The dvi stacking code refers to the information \`'x_val', \`'y_val',
\`'dx_1', \`'dx_2', \`'dy_1', and \`'dy_2'.

\<push values to stack\><<<
`<halign at entry to group`>
`<get backward deliveries`>
stack[stack_n].text_on = text_on;
push_stack();  `<get back sub/sup before group`>
`<path group at entry to group`>
`<trace dvi push`>
`<add push class del`>
>>>

\<header functions\><<<
static void push_stack( ARG_I(void) );
>>>

\<functions\><<<
static void push_stack(MYVOID)
{
   stack[stack_n].x_val = x_val;
   stack[stack_n].dx_1  = dx_1;
   stack[stack_n].dx_2  = dx_2;
   stack[stack_n].y_val = y_val;
   stack[stack_n].dy_1  = dy_1;
   stack[stack_n].dy_2  = dy_2;
   `<push inherit del`>
   stack_n++;              
if( stack_n > `<size of stack for nested boxes`> ){
  warn_i(40);
}
   `<init end math accented`>
}
>>>

\<push inherit del\><<<
stack[stack_n+1].sv_no_left_del = stack[stack_n+1].no_left_del;
stack[stack_n+1].no_left_del = stack[stack_n].no_left_del;
>>>

\<pop uninherit del\><<<
stack[stack_n].no_left_del = stack[stack_n].sv_no_left_del;
>>>


The first statement partially handles spaces after text that is inserterted
to the left of the current location (e.g., items of list).

\<pop values from stack\><<<
`<add pop class del`>
`<path group at exit from group`>
`<get forward deliveries`>
`<trace dvi pop`>
`<halign at exit from group`>
pop_stack();
if( ((x_val+0.6*word_sp) <  stack[stack_n].x_val) )  put_char(' ');
text_on = stack[stack_n].text_on;
>>>


\<header functions\><<<
static void pop_stack( ARG_I(void) );
>>>

\<functions\><<<
static void pop_stack(MYVOID)
{
   `<end math accented`>
   `<pop uninherit del`>
   --stack_n; 
   x_val = stack[stack_n].x_val;
   dx_1  = stack[stack_n].dx_1;
   dx_2  = stack[stack_n].dx_2;
   y_val = stack[stack_n].y_val;
   dy_1  = stack[stack_n].dy_1;
   dy_2  = stack[stack_n].dy_2;
}
>>>




\Section{Backward Token / Group Submissions}

TeX places subscripts and superscripts on the most recent group or
token.  We are looking where the most recent of these tokens starts,
and store there the desired info.

% \`'\special{...[}...\special{...]}'  is ignore when looking for
% tokens.  \`'\special{...]...}' sends back its content to the start of
% the most recent entity.   \`'\special{...[*...*...}' sets open-close
% math codes---how?


\SubSection{Scan to Record Recieving Points}

We keep a delimiter stack for the parenthesis, and include there also
the opening and closing of groups.  The latter one are employed
to deal with parenthese that are not balanced, for instance, 
\`'\left( ... \right.'.

\<pop-id + 1\><<<
if( !back_id_off ){
   if( !id_hide ){  ch_token = FALSE;
                    sv_id = stack[stack_n].stack_id; }
   while( del_stack != (struct del_stack_entry*) 0 ){
                                     struct del_stack_entry* p;
                                     int id;
     del_stack = (p = del_stack)->next;
     id = p->id;  
     free((void *)  p );
     if( id == -1 ) break;
}  }
>>>

\<push-id + 1\><<<
if( !back_id_off )
{                    struct del_stack_entry *p;
   p = m_alloc(struct del_stack_entry,1);
   p->next = del_stack;  
   p->id = p->fnt = -1;
   del_stack = p;
}
>>>






\<ch-id + 1\><<<
ch_id++;   
if(!back_id_off ){
   if( !id_hide ){  ch_token = TRUE;  sv_id = ch_id; }
   switch( math_class_of( ch, cr_fnt ) ){
     case `<math open`>: { del_stack = push_del( (char) ch, cr_fnt);
                           break; }
     case `<math close`>: {
        del_stack = pop_del( (char) ch, id_hide, cr_fnt);   break; }
     default:{ ; }
}  }
>>>



\<math close\><<<
5
>>>

\<math open\><<<
4
>>>




Assumption made: closing del is in the same font as the opening one.




\<header functions\><<<
static struct del_stack_entry* push_del( ARG_II(char, int) );
>>>

\<functions\><<<
`[
static  struct del_stack_entry* push_del(ch, cr_fnt)     U_CHAR ch`;
                                                 int cr_fnt
;{                    struct del_stack_entry *p;
    p = m_alloc(struct del_stack_entry,1);
    p->next = del_stack;  
    p->ch = ch;
    p->fnt = cr_fnt;
    p->id = ch_id;
    return p;
}
>>>




\<header functions\><<<
static struct del_stack_entry* pop_del( ARG_III(char,int,int) );
>>>

\<functions\><<<
`[
static  struct del_stack_entry* pop_del(ch, id_hide, cr_fnt) 
                                                  U_CHAR ch`;
                                                  int  id_hide`;
                                                  int cr_fnt
;{                   
   if( del_stack != (struct del_stack_entry*) 0 ){
      if( (cr_fnt ==  del_stack->fnt) && 
          (  *(font_tbl[cr_fnt].math + (ch - font_tbl[cr_fnt].char_f))
             == del_stack->ch) ){
                                             struct del_stack_entry  * p;
         if( !id_hide && !id_latex ){  sv_id = del_stack->id; }
         del_stack = (p = del_stack)->next;  free((void *)  p );
   }  }
   return del_stack;
}
>>>


What the \''id_latex' does here?




\<vars\><<<
static struct del_stack_entry  *del_stack;
>>>

\<main's init\><<<
del_stack = (struct del_stack_entry  *) 0;
>>>


\<types\><<<
struct del_stack_entry{
  struct del_stack_entry *next;
  U_CHAR ch;
  int  fnt, id;
};
>>>









\<vars\><<<
static int ch_id, sv_id, id_latex, back_id_off; 
>>>

\<main's init\><<<
back_id_off = 1;  id_latex = 0;
>>>



\<init ch-id\><<<
ch_id = 0;
>>>

\<subp vars\><<<
BOOL  ch_token;
int  id_hide;
>>>

\<init subp vars\><<<
sv_id = 0;    `<init ch-id`>
id_hide = 0;    ch_token = TRUE;
while( del_stack != (struct del_stack_entry*) 0 ){
                                  struct del_stack_entry* p;
  del_stack = (p = del_stack)->next;
  free((void *)  p );
}
>>>





\<hide back token / group\><<<
id_hide++;
>>>


\<end hide back token / group\><<<
id_hide--;  
>>>

\<latex back token / group\><<<
id_latex++;
>>>


\<end latex back token / group\><<<
id_latex--;  
>>>



\<back token / group\><<<
back_id_off++;
>>>


\<end back token / group\><<<
back_id_off--;  
>>>







\SubSection{Memory for Linked Lists}

\<types\><<<
struct send_back_entry{
  struct send_back_entry *next;
  U_CHAR *send;
  int  id;
};
>>>


\<vars\><<<
static struct send_back_entry *back_token, *back_group;
>>>

\<main's init\><<<
back_token = back_group = m_alloc(struct send_back_entry,1);
back_token->id = -1;
>>>



\SubSection{Scan Backward Submissions}



\<send back over token / group\><<<
              struct send_back_entry *p, *q, *t=0;
if( back_id_off ){
   while( i-- ){ (IGNORED) get_char();  }
} else {
   p =  m_alloc(struct send_back_entry,1);
   p->send = get_str( (int)( i - 1 ));
   if( ch_token ){  
     `<send back to char`>
   } else {         
     p->id = (sv_id<0? 0 : sv_id) +  push_id;
     if( back_group->id < p->id )
        {  p->next = back_group;   back_group = p;  }
     else
        {  q = back_group; 
           while( q->id >= p->id ) { t = q;  q = q->next;  }
           p->next = t->next;   t->next = p;
        }
   }
}
>>>


Keep \ifHtml[\HPage{consistency}\Verbatim

$
a
\Send{BACK}{1}
\Send{BACK}{2}
\Send{BACK}{3}
\Send{BACK}{4}
\hbox{ab}
\Send{BACK}{1}
\Send{BACK}{2}
\Send{BACK}{3}
\Send{BACK}{4}
$

produce  4321a4321ab   
\EndVerbatim\EndHPage{}]\fi{} between back on group and back on token

\<send back to char\><<<
p->id = sv_id;
if( sv_id >  back_token->id ){
   p->next = back_token;   back_token = p;
} else {
   q = back_token;
   while( sv_id <= q->id ){ t = q;  q = q->next;  }
   p->next = t->next;   t->next = p;
}
>>>

The following reverses the linked lists for ids and groups, so that
the early entries will get at the head instead of the tail.


\<exit early pass\><<<
back_group = rev_list( back_group );
back_token = rev_list( back_token );
back_token = back_insert ( back_token, 0);      
`<init ch-id`>
>>>


\<header functions\><<<
static 
struct send_back_entry * rev_list( ARG_I(struct send_back_entry *) );
>>>

\<functions\><<<
`[
static struct send_back_entry *  rev_list(back_group)      
                             struct send_back_entry *back_group
;{                           struct send_back_entry *p, *q, *t;
    if( back_group->id == -1 ){ return back_group; }
    p = back_group;    q = p->next;
    while( p->id != -1 ){
       t = q->next;  q->next = p;  p = q;  q = t;
    }
    back_group->next = p;
    return  p->next;
}
>>>




\SubSection{Use Backward Submissions}





\<get back sub/sup before group\><<<
if( group_dvi ) {
   back_group = back_insert ( back_group, push_id);
}
>>>



\<get back sub/sup before ch\><<<
if( group_dvi ){
  if( ( ch < 132 ) ||
      ( (ch > 127) && (ch < 137) && (ch != `<insert rule + move op`> ) )
    ){
       ch_id++;
       back_token = back_insert ( back_token, ch_id);
} }
>>>








\<header functions\><<<
static struct send_back_entry * 
   back_insert( ARG_II(struct send_back_entry *, int) );
>>>

\<functions\><<<
`[
static struct send_back_entry *  back_insert(back, id)      
                             struct send_back_entry *back`;
                             int    id
;{                         
  while( back->id == id ){
                         struct send_back_entry *p;
    print_f( back->send );  
    back = (p = back)->next;
    free((void *)  p->send );
    free((void *)  p );
  }
  return back;
}
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Actions on Forward Groups Accessed Through Pathes}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Motivation}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The current instructions are motivated by the \`'\sqrt' structure

\Verbatim
PUSH
   PUSH
      ......sqrt et al symbols, possibly with PUSH-POP......
   POP
   PUSH
      W3:       655361
      DOWN3:    -1020474
      PUT_RULE: height: 26213
                length: 1091179
      DOWN3:    1020474
      PUSH
         .....body.........
      POP
   POP
POP
\EndVerbatim

and the \`'\root ...\of {...}' construct

\Verbatim
PUSH
   ...root value...
POP
PUSH
   PUSH
      PUSH
         ...root sign characters with PUSH-POP...
      POP
      PUSH
         RIGHT4:   15213546
         DOWN3:    -1553322
         PUT_RULE: height: 26213
                   length: 1197667
         DOWN3:    1553322
         PUSH
            ...root content...
         POP
      POP
   POP
POP
\EndVerbatim

For instance,

\Verbatim
$
\special{t4ht\string~}
\special{t4ht=<msqrt>}
%%%%%%%%
\special{t4ht\string~!e<[BEFORE]} %   insert at start of path
\special{t4ht\string~!e>[AFTER]}  %   insert at end of path
\special{t4ht\string~!ee/}        %   ignore content within group
\special{t4ht\string~!ese-}       %   ignore until rulers until next group
%%%%%%
\sqrt 1
\special{t4ht\string~}
$

$
\special{t4ht\string~}%
\special{t4ht=<mroot>}%
%%%%%%%%
\special{t4ht\string~!see<[BEFORE]}
\special{t4ht\string~!see>[AFTER]}
\special{t4ht\string~!seee/}
\special{t4ht\string~!seese-}
%%%%%%
\root 2\of 3%
\special{t4ht\string~}
$
\EndVerbatim




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Record Request}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





\<struct stack_entry\><<<
struct group_path * path_start, * path_end;
>>>


\<types\><<<
struct group_path{
  U_CHAR action;
  U_CHAR *path;
  U_CHAR *info;
  struct group_path * next;
};
>>>


\<initialized entries for grouping stack\><<<
stack[i].path_start = (struct group_path *) 0;
stack[i].path_end   = (struct group_path *) 0;
>>>

\<store path-based forward submissions\><<<
                 struct group_path *p, *t;
                 U_CHAR            *q, str[256];
                 int               n;
p = m_alloc(struct group_path,1);
`<record action and path`>
`<record info for path`>
n = stack_n - 1;
if( p->action == '>' ){
   p->next =  stack[ n ].path_end;
   stack[ n ].path_end = p;
} else {
   p->next = (struct group_path *) 0;
   if( stack[n].path_start == (struct group_path *) 0 ) {
      stack[n].path_start = p;
   } else {
      t = stack[n].path_start;
      while( t->next != (struct group_path *) 0 ) { t = t->next; }
      t->next = p;
}  }
>>>


\<record action and path\><<<
n = 0; 
while( --special_n ) {
   str[n] = get_char();
   if( ( str[n] != 'e') && (str[n] != 's') ){ break; }
   n++;   
}
if((
    ( str[n] != '<') && (str[n] != '>') &&
    ( str[n] != '/') && (str[n] != '-')
   ) || (n==0) ){
  str[n+1] = '\0';
  err_i_str(38,str);  
}
p->action = str[n]; str[n] = '\0';
p->path = m_alloc(char,n+1);
(IGNORED) strcpy((char *) p->path, (char *) str);
>>>

\<record info for path\><<<
q = p->info = m_alloc(char,special_n+1);
while( --special_n ) *q++ = get_char();
*q = '\0';
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Process Path Lists At Entry To Group}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<path group at entry to group\><<<
{
           `<vars for path processing`>
  if( `<radical-line-off`> ){
    `<end ignore spaces`>
    `<radical-line-off`> = FALSE;
  }
  if( stack_n > 1 ){ 
    p = stack[stack_n - 2].path_start;
    if(  p !=  (struct group_path *) 0 ){
      `<traverse path starts on entry`>
    } 
    p = stack[stack_n - 2].path_end;
    if(  p !=  (struct group_path *) 0 ){
      `<traverse path ends on entry`>
    } 
    `<connect the revised path lists`>
} }
>>>

\<vars for path processing\><<<
struct group_path *start_head, *start_tail, 
                  *parent_start_head, *parent_start_tail, 
                  *end_head, *end_tail, 
                  *parent_end_head, *parent_end_tail, 
                  *p, *q;  
int place=0;
start_head = start_tail = parent_start_head = parent_start_tail  
           = end_head   = end_tail          = parent_end_head 
           = parent_end_tail = (struct group_path *) 0;
>>>

\<connect the revised path lists\><<<
  stack[stack_n - 1].path_start = start_head;
  stack[stack_n - 1].path_end   = end_head;
  stack[stack_n - 2].path_start = parent_start_head;
  stack[stack_n - 2].path_end   = parent_end_head;
>>>



\<traverse path starts on entry\><<<
while( p !=  (struct group_path *) 0 ){  
   `<process a path-start at entry`>
   q = p;
   p = p->next; 
   q->next = (struct group_path *) 0;
   `<update temporary start paths`>
}
>>>

\<traverse path ends on entry\><<<
while( p !=  (struct group_path *) 0 ){  
   `<process a path-end at entry`>
   q = p;
   p = p->next; 
   q->next = (struct group_path *) 0;
   `<update temporary end paths`>
}
>>>

\<update temporary start paths\><<<
switch( place ){
 case `<store at parent path-start`>:
   if( parent_start_head == (struct group_path *) 0 ){ 
       parent_start_head = parent_start_tail = q;
   } else { 
       parent_start_tail = parent_start_tail->next = q; 
   }
   break;
 case `<store at path-start`>:
   if( start_head == (struct group_path *) 0 ){ 
       start_head = start_tail = q;
   } else { 
       start_tail = start_tail->next = q; 
   }
   break;
 case `<delete path entry`>:
   `<delete path entry q`>
   break;
}  
>>>

\<update temporary end paths\><<<
switch( place ){
 case `<store at parent path-end`>:
   if( parent_end_head == (struct group_path *) 0 ){ 
       parent_end_head = parent_end_tail = q;
   } else { 
       parent_end_tail = parent_end_tail->next = q; 
   }
   break;
 case `<store at path-end`>:
   if( end_head == (struct group_path *) 0 ){ 
       end_head = end_tail = q;
   } else { 
       end_tail = end_tail->next = q; 
   }
   break;
 case `<delete path entry`>:
   `<delete path entry q`>
   break;
}
>>>

\<store at parent path-start\><<<
0 >>>

\<store at parent path-end\><<<
1 >>>

\<store at path-start\><<<
2 >>>

\<store at path-end\><<<
3 >>>

\<delete path entry\><<<
4 >>>

\<delete path entry q\><<<
free((void *)  q->path );
free((void *)  q->info );
free((void *)  q );
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Process Individual Records at Entry To Group}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



The `e' records at the parent's path-start are moved to the path-start
list of the current group, with the leading `e' removed from the path.
The only exception is for paths of length 1 with actions \`'<' and
\`'-'. They contribute their content to the output, and then
discarded.

The `s' records at the parent's path-start list stay at that list,
with the `s' character removed from the path.  


The other records remain at the parent path-start list, to be removed
at the end of that group.

\<process a path-start at entry\><<<
if( *(p->path ) == 'e' ) {
  (IGNORED) strcpy((char *) p->path, (char *) p->path+1);
  if( *(p->path) == '\0' ) {
     switch( p->action ){
       case '<':  print_f( p->info );
                  place = `<delete path entry`>;
                  break;
       case '/':  ignore_chs++;
                  place = `<store at path-start`>; break; 
       case '-':  `<radical-line-off`> = TRUE;
                  `<ignore spaces`>
                  place = `<delete path entry`>; break;
     }
  } else {     
     place = `<store at path-start`>;
  }
} else {
  if( *(p->path ) == 's' ) {
     (IGNORED) strcpy((char *) p->path, (char *) p->path+1);
  }
  place = `<store at parent path-start`>;
}
>>>


The `s' records at the parent's path-end list stay at that list,
with the `s' character removed from the path.
 
The `e' records are moved to the path-end list of the current group,
with the leading `e' removed from the path.

The other records are left intact at the parent's path-end list.



\<process a path-end at entry\><<<
if( *(p->path ) == 'e' ) {
  (IGNORED) strcpy((char *) p->path, (char *) p->path+1);
  place = `<store at path-end`>;
} else {
  if( *(p->path ) == 's' ) {
     (IGNORED) strcpy((char *) p->path, (char *) p->path+1);
  }
  place = `<store at parent path-end`>;
}
>>>





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Path Group At Exit From Group}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<path group at exit from group\><<<
{
     struct group_path *p, *q;  
  if( stack_n > 1 ){ 
    p = stack[stack_n - 1].path_start;
    if(  p !=  (struct group_path *) 0 ){
      `<traverse path starts on exit`>
    } 
    p = stack[stack_n - 1].path_end;
    if(  p !=  (struct group_path *) 0 ){
      `<traverse path ends on exit`>
} } }
>>>


\<traverse path starts on exit\><<<
while( p !=  (struct group_path *) 0 ){  
   `<process a path-start at exit`>
   q = p;
   p = p->next; 
   `<delete path entry q`>
}
>>>

\<traverse path ends on exit\><<<
while( p !=  (struct group_path *) 0 ){  
   `<process a path-end at exit`>
   q = p;
   p = p->next; 
   `<delete path entry q`>
}
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Process Individual Records at Exit from Group}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<process a path-start at exit\><<<
if( *(p->path) != '\0' ) { 
   `<warn 38 for path`>
} else  {
   switch( p->action ){
     case '/':  ignore_chs--;  break; 
      default:  {
          `<warn 38 for path`>
          break;
}  }  }
>>>

  



\<process a path-end at exit\><<<
if( *(p->path) != '\0' ) {
   `<warn 38 for path`>
} else  {
   switch( p->action ){
     case '>':  print_f( p->info );  break;
      default:  {
          `<warn 38 for path`>
          break;
}  }  }
>>>



\<warn 38 for path\><<<
            char str[256];
(IGNORED) strcpy(str, "...."); *(str+3) = p->action;
(IGNORED) strct(str,p->info); warn_i_str(38,str);
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Position-Based Decoration}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



\Section{Background}

We assume a rectangualar canvase  for which we can provide the
measurements, as well as the location of each character and ruler in it.

A region starts and ends with a \`'\special{t4ht"}'.  The entry point
gets coordinates (0,0). It is configured
wuth

\Verbatim
\special{t4ht"%
    * before-all
    * after-all     %right  %left %height %depth
    .............
    ** before-char   %x %y
    * after-char
    * line          %x %y %thickness %length
    * x-coefficients: A-magnification, B-displacement %A(x) + %B
    * y-coefficients: C-magnification, D-displacement, E/F-origin
                           %C(y + (%E(up) | %F(height+depth))  ) + %D
 }
\EndVerbatim

The \`'*' is a seperator character, and it can be replaced by other 
characters.

We assume C-type templates, where values are assumed to be in float
decimals (e.g., \`'%.2f';  replacing 2 by 0, implies an integer).

The \`'* after-all' can be repeated arbitrary many times (must appear
at least once).  The last one is found when \`'**' is encountered.

The first character in each \`'after-all' is treated as a code: x-min
x, X-max x, y-min , Y-max y, w-dx, h-dy, otherwise-string with no
value. We need the codes to enable arbitrary combinations of values.

The \`'before-char' must be non-empty for   \`'%x %y' to be printed.
The case is similar for the ruler.  If both are empty, we just
measure the dvi dimensions--can be used for applets.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Compute Character Position}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<pos dvi ch\><<< 
if( pos_dvi ){       long int d;
  if( *pos_text ){
    `<open output file`>
    (IGNORED) fprintf(cur_o_file, pos_text,
         pos_x_A * (x_val - base_pos_x) + pos_x_B, 
         pos_y_C * (y_val - base_pos_y) + pos_y_D);
  }
  if( x_val < min_pos_x )                       min_pos_x = x_val;
  if( (d = x_val + `<ch width`>)  > max_pos_x ) max_pos_x = d;
  if( (d = y_val - `<ch height`>) < min_pos_y ) min_pos_y = d;
  if( (d = y_val + `<ch depth`>)  > max_pos_y ) max_pos_y = d;
}
>>>


%      pos_y_D * (`<(double) char_height( ch )`> - base_pos_h) +


\<end pos dvi ch\><<< 
if( pos_dvi ){
   print_f(end_pos_text);
}
>>>

 
\ifHtml[\HPage{more}\Verbatim
                       \ifx \documentclass\undef \else
\documentclass{book}
                       \fi
\input DraTex.sty  \input AlDraTex.sty


\input tex4ht.sty         \Preamble{html,sty,4.0s}
                       \ifx \documentclass\undef \else
\begin{document}
                       \fi



\ScriptCommand{\CssFile}{\HCode{<STYLE>\EolnCh}}{\HCode{</STYLE>}}

\CssFile
 BODY{ font-size : 200% }
 .canvas { position: relative; }
 SPAN.cmr-7 .char ,
 SPAN.cmmi-7 .char ,
 SPAN.cmsy-7 .char { font-size: 70% ; }
 SPAN.cmr-5 .char ,
 SPAN.cmmi-5 .char { font-size: 50% ; }
\EndCssFile


   \EndPreamble %   \Validate{temp/\jobname.html}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%





\special{t4ht"*<SPAN\EolnCh 
    CLASS="canvas">*<SPAN STYLE="position:relative;\EolnCh 
    width:\%.2fex"></SPAN></SPAN>*<SPAN\EolnCh
    STYLE="position:absolute; left:\%.2fex;
    top:\%.2fex"\EolnCh
    CLASS="xy"><SPAN\EolnCh CLASS="char">*</SPAN></SPAN>*<SPAN top="\%.2f"
    left="\%.2f" CLASS="xy">*</SPAN>*0.00000290646*0.0*0.00000290646*0.0*0.5}

aa
\special{t4ht"}$
\SUBSUPOff 
\let\Picture=\empty
..\qquad...............a^{c^1}_{b_2}a^c_bccccc...c
$\special{t4ht"}XX


aa
\special{t4ht"}$
\SUBSUPOff 
\let\Picture=\empty
{A+C \over B+D}+F \over X*Y
$\special{t4ht"}...........



x

\end{document}

1ex = 344061

Addresses in dvi are on baseline. The same is true for
positioned text in html. That is, 
the point of reference of the printed character is placed at 
the specified position (\ifHtml[\HPage{margin}\Verbatim
<DIV STYLE="position:absolute;
            left:100; top:50;">
   (/\/\/\/\/\)
   </DIV>

<DIV STYLE="position:absolute;
            left:100; top:50;">
   ........................
   </DIV>
\EndVerbatim\EndHPage{}]\fi).
  

\ifHtml[\HPage{?}\Verbatim
Positioning of characters?

The attached source tries three renderings for `A<sub>x</sub>'.  My
understanding of the positioning mechanism is that, in all three cases,
the reference point for `x' should be 0.7ex under the right leg of A.
Moreover, the measurement 0.7ex should be with respect to the
dimension of the font of A.

           /\
          /--\
         /    \...........
                \/       } 0.7ex within font of A
               ./\.......}

Is that understanding correct?

NN 4.04 provides the desired outcome in the first case, but not in the
second and third cases.  IE 4.0, on the other hand, produces the
desired outcome for the second and the third cases, but not the first.

-eitan


<HTML><HEAD> <TITLE>aa.html</TITLE> </HEAD><BODY>
<P>                      A<SPAN 
STYLE="position:relative"><SPAN 
STYLE="position:absolute; top:0.7ex"><SPAN 
STYLE="font-size: 70% ;">x</SPAN></SPAN></SPAN>

<P>                      A<SPAN 
STYLE="position:relative"><SPAN 
STYLE="position:relative; top:0.7ex"><SPAN 
STYLE="font-size: 70% ;">x</SPAN></SPAN></SPAN>

<P>                      A<SPAN 
STYLE="position:relative"><SPAN 
STYLE="position:absolute; top:0.7ex"><SPAN 
STYLE="font-size: 100% ;">x</SPAN></SPAN></SPAN>

<P> y
</BODY></HTML>

\EndVerbatim\EndHPage{}]\fi



\Section{Compute Ruler Position}


\<pos dvi x rule\><<<
         long int d;
if( (up > 0) && (right > 0) ){
   if(  *pos_line ){
                      double from_x, from_y;
     `<open output file`>
     from_x = pos_x_A * (x_val - base_pos_x) + pos_x_B;
     from_y = pos_y_C * (y_val - pos_y_E * up - base_pos_y) + pos_y_D;
     switch (rect_pos){
       case 1: {
              (IGNORED) fprintf(cur_o_file, pos_line,
                   from_x, from_y,
                   pos_x_A * right + pos_x_B  + from_x,
                   pos_y_C * up + pos_y_D  + from_y );
               break; }
       case 2: {
              (IGNORED) fprintf(cur_o_file, pos_line,
                   from_x, from_y,
                   pos_x_A * right + pos_x_B + from_x,
                   from_y,
                   pos_y_C * up + pos_y_D  );
               break; }
       default: {
              (IGNORED) fprintf(cur_o_file, pos_line,
                   from_x, from_y,
                   pos_x_A * right,
                   pos_y_C * up);
               }
      }
   }
   if( x_val < min_pos_x )           min_pos_x = x_val;
   if( (d = x_val + right) > max_pos_x ) max_pos_x = d;
   if( (d = y_val - up) < min_pos_y ) min_pos_y = d;
   if( y_val > max_pos_y )           max_pos_y = y_val;
}
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Boundary Conditions}
%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<positioned content\><<<
if( special_n ){
   `<read pos instructions`>
} else if( (pos_dvi = !pos_dvi) == TRUE ){
   print_f(pos_body);
   min_pos_x = max_pos_x = base_pos_x = x_val;   
   min_pos_y = max_pos_y = base_pos_y = y_val ; 
} else {                     U_CHAR   *p;
                             double dim=0.0;
                             BOOL   dim_on;
  `<open output file`>
  p = end_pos_body;
  while( *p ){
    dim_on = TRUE;
    switch( *p ){
       `<dim = pos value`>
        default: { dim_on = FALSE; }
    }
    p++;
    if( dim_on ){    (IGNORED) fprintf(cur_o_file, p, dim);  }
    else        {    (IGNORED) fprintf(cur_o_file, "%s", p); }
    while( * (p++) );  
  }
}
>>>

The pattern of of \`'end_pos_body' has a \`'\0' at the end
of each segment, and the last segment is empty. Hence, it
ends with a \`'\0\0'.

\<dim = pos value\><<<
case 'X': {  dim = pos_x_A * (max_pos_x - base_pos_x) + pos_x_B;
             break; }
case 'x': {  dim = pos_x_A * (base_pos_x - min_pos_x) + pos_x_B;
             break; }
case 'd': {  dim = pos_x_A * (max_pos_x - min_pos_x) + pos_x_B;
             break; }
case 'y': {  dim = pos_y_C * (base_pos_y - min_pos_y - 1) + pos_y_D;
             break; }
case 'Y': {  dim = pos_y_C * (max_pos_y - base_pos_y) + pos_y_D;
             break; }
case 'D': {  dim = pos_y_C * (max_pos_y - min_pos_y) + pos_y_D;
             break; }
>>>


\<vars\><<<
static BOOL pos_dvi = FALSE;
static U_CHAR   *pos_body,     * pos_text,     * pos_line, 
       *end_pos_body, * end_pos_text;
static double   pos_x_A, pos_x_B, pos_y_C, pos_y_D, pos_y_E;
static long int base_pos_x, base_pos_y, min_pos_x, 
         max_pos_x, min_pos_y, max_pos_y;
static short rect_pos;
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Scan Coefficients}
%%%%%%%%%%%%%%%%%%%%%%%%%%%

Note that \`'pos_body' points to the left-most byte in the template.


\<main's init\><<<
pos_text = pos_line = end_pos_body = end_pos_text = pos_body =
                      m_alloc(char, (int) 1);
(IGNORED) strcpy((char *) pos_text, "" );
>>>


\<read pos instructions\><<<
{                       U_CHAR * p, ch, i;
  ch = get_char();  
  p = pos_text = pos_line = end_pos_text
    = end_pos_body = pos_body 
    = (char *)  r_alloc((void *) pos_body,(size_t) special_n + 1);
  i = 0;  `<scan templates for pos`>
  `<scan constants for pos`>
  if( (i != 10) || special_n ){ 
    warn_i_str(39,pos_text); 
    *(pos_text = end_pos_body = pos_line = 
      end_pos_text = pos_body) = '\0';
  }
}
>>>
       



\<scan templates for pos\><<<
{                               BOOL after_star=0;
   while(  special_n-- > 0 ){
      if( (*p = get_char()) == ch ){
         *p = '\0'; i++;
              if( i==1 ){ end_pos_body = p + 1;   after_star = FALSE; }
         else if( i==2 ){ pos_text     = p + 1; 
                          if( !after_star ){  i--;  after_star = TRUE; } 
                        }
         else if( i==3 ){ end_pos_text = p + 1; }
         else if( i==4 ){ pos_line     = p + 1; }
         else           { p++; break; }
      } else { after_star = FALSE; }
      p++;      
   }
}
>>>



\<scan constants for pos\><<<
{                     long int v=0;
                      double w[5];
                      int j;
                      U_CHAR ch, sign;
                      BOOL done;
  for(j=0;j<5;j++){
    `<v = int part; sign = ...`>
    if( done ){
      i++;
      w[j] = sign * ((double) v + pos_dbl( &special_n ));
    }
  }
  pos_x_A = w[0];  pos_x_B = w[1];  
  pos_y_C = w[2];  pos_y_D = w[3]; pos_y_E = w[4]; 
}
rect_pos = (special_n == 2);
if( rect_pos ){  special_n -= 2;  rect_pos = get_char() - '0';}
>>>



\<v = int part; sign = ...\><<<
done = FALSE;  sign = 1; 
if( --special_n > 0 ){
  if( (ch = get_char()) == '-' ){ sign = -1; v=0; }
  else v = ch - '0';
  if( (v<0) || (v>9) ) done = TRUE;
}
if( !done )   
   while(  --special_n > 0 ){
     ch = get_char();
     if( ('0' <= ch ) && (ch <= '9' ) ){
        v =  v * 10 + ch - '0'; }
     else{  done = TRUE;  break; }
   }
>>>



\<header functions\><<<
static double pos_dbl( ARG_I(long int *) );
>>>

\<functions\><<<
`[
static double pos_dbl( special_n )       long  int *  special_n
;{
                U_CHAR ch;
                double v;
                int d;       
  v = 0.0; d = 10;
  while(  --(*special_n) > 0 ){
    ch = get_char();
    if( ('0' <= ch ) && (ch <= '9' ) ){
       v += (double) (ch -'0') / d;  d *= 10; }
    else break;
  }
  return v; 
}
>>>



\<err int pos\><<<
123454321
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Font Information from TeX Font Metric (tfm) Files}
%%%%%%%%%%%%%%%%%%%%%%%%%%%

Managed by load-font (\LinkPort\<font 0\>font 0\EndLink
--\LinkPort\<font 63\>font 63\EndLink,
\LinkPort\<font 1-byte\>font 1-byte\EndLink
--\LinkPort\<font int\>font int\EndLink)  and activate-font 
(\LinkPort\<def 1 byte font\>def 1-byte font\EndLink
--\LinkPort\<def 4 byte font\>def 4 byte font\EndLink) commands.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Memory and Initialization}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

A font def looks like:   \Link{}{fntdef} \EndLink{}

\Verbatim
FNT_DEF1...FNT_DEF4        
            1,2,3 ubytes or 4 bytes     font number 
                           4 ubytes     checksum
                           4 ubytes     scale      
                           4 ubytes     design size
                             1 byte     length of directory name
                             1 byte     length of file name
             dir-ln + file-ln bytes     fontname
\EndVerbatim

Checksums are used to verify consistency between tfm and gf font files.



\Verbatim
000284: FNT_DEF1: 29
000286:           checksum         : -538297224
000290:           scale            : 655360
000294:           design           : 655360
000298:           name             : cmtt10
000306: FNT_DEF1: ....
\EndVerbatim


\<types\><<<
struct font_entry {     
 INTEGER num;        
 INTEGER scale;
 INTEGER design_sz;
 `<mag of font`>
 `<family+size of font`>
 `<entries from font file into font-tbl`>
 `<entries for html chars in font-tbl`>
 `<entries for math classes`>
 `<entries for xetex`>
};
>>>



\<defines\><<<
#define design_size_to_pt(n)    ((double)n / (double)(1L<<20))
>>>

\<vars\><<<
static struct font_entry*  font_tbl;
static int font_tbl_size = 0;
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Storage for New Font}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


The standard fonts of Knuth have design size of 0x90000 for fonts of
size 9, 0xa0000 for size 10, etc.


% INTEGER `%, new_font_dir`%





\<scan font entry\><<<
#ifdef MAXFONTS
if( (font_tbl_size + 1) < MAXFONTS )
#endif
{
              INTEGER new_font_checksum;
              int font_name_n;
   font_tbl = font_tbl_size?
              (struct font_entry *) r_alloc((void *) font_tbl,
                 (size_t) ((font_tbl_size+1)
                           * sizeof(struct font_entry)))
            : m_alloc(struct font_entry, 1);
   if(       (version_id == `<version xdv`>) 
         &&  (ch == `<xdv-native-font-def op`>) 
   ){
      `<scan xdv font entry`> 
   } else {
      `<scan dvi font entry`> 
   }
   `<get html characters`>
   `<get css entries`>
   free((void *)  new_font_name);   font_tbl_size++;
}
#ifdef MAXFONTS
 else err_i_int(17, MAXFONTS);
#endif
>>>







\<scan dvi font entry\><<<
`<scan font id`>
new_font_checksum  = (INTEGER) get_int(4); 
new_font.scale     = (INTEGER) get_unt(4); 
new_font.design_sz = (INTEGER) get_unt(4); 
`<get font name`>
`<get font info`>
>>>




\<vars\><<<
static char*  new_font_name;
>>>



\<defines\><<<
#define new_font   font_tbl[font_tbl_size]
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Get Data}
%%%%%%%%%%%%%%%%%%%%%%%%%%

\<scan font id\><<<
switch( ch ){
  case `<def 1 byte font`>:
  case `<def 2 byte font`>:
  case `<def 3 byte font`>: { 
     new_font.num = (INTEGER)
                      get_unt(ch - `<def 1 byte font`> + 1); break; }
  case `<def 4 byte font`>: {  
     new_font.num = (INTEGER) get_int(4);  break; }
  default: err_i(8); 
}
>>>


\<get font name\><<<
{    int  n, area_ln;
     U_CHAR *ch;
  area_ln = (int) get_unt(1);
  font_name_n = (int) get_unt(1);
  n =  area_ln + font_name_n + 1;
  ch = new_font_name = m_alloc(char, n);
  while( --n ){  *ch = (int) get_unt(1); ch++; }
  *ch = '\0';
}
>>>





\<get font info\><<<
`<first definition of font?`>
`<open font file`>
new_font_name[font_name_n] = '\0';
new_font.name = m_alloc(char, font_name_n + 1);
(IGNORED) strcpy((char *)  new_font.name, (char *) new_font_name );
`<family and size of font`>
`<compute mag of font`>
>>>


The following is computed from \`'scale' and \`'design_sz'.
We take it here relative to 100.


\<compute mag of font\><<<
new_font.mag = new_font.scale / (new_font.design_sz / 100);
>>>

\<mag of font\><<<
INTEGER mag;
>>>

\<family+size of font\><<<
char *family_name, *font_size;
>>>


\<family and size of font\><<<
{    int n, i;
   for( n=0; n<font_name_n; n++ ){
     if(  ( '0' <= new_font_name[n] ) && ( new_font_name[n] <= '9' )){
       break;
     }
   }
   `<real size?`>
   new_font.family_name = m_alloc(char, n + 2);
   new_font.font_size  = m_alloc(char, font_name_n - n + 1 );
   for( i=0; i<n; i++ ){
     new_font.family_name[i] = new_font_name[i];
   }
   new_font.family_name[i] = '\0';   i = 0;
   while(  n<font_name_n ){
     new_font.font_size[i++] = new_font_name[n++];
   }
   new_font.font_size[i] = '\0';
}
>>>


\<real size?\><<<
{                       int m;
   for( m=n; m<font_name_n; m++ ){
     if(  ( new_font_name[m] < '0' ) || ( new_font_name[m] > '9' )){
       n=font_name_n;
       break;
}  } }
>>>


When the size is not zero, n+2 can be reduced to n+1.

\<output to lg file\><<<
(IGNORED) fprintf(log_file, lg_font_fmt,  
  font_tbl[cur_fnt].family_name, 
  font_tbl[cur_fnt].font_size, 
  (int)( font_tbl[cur_fnt].design_sz * 100 / 655360 / 10), 
  font_tbl[cur_fnt].mag);
>>>


Fosome font names (e.g., Chinese: gbkhei65) we don't want the number to
be treated as font-size:

\<check name decomposition\><<<
if( (strlen((char *) new_font.family_name) +
     strlen((char *) new_font.font_size) + 4) == strlen((char *) name) ){
  new_font.family_name = (char *) r_alloc((void *) new_font.family_name,
                         (size_t) (strlen((char *) name)+1));
  (IGNORED) strcat((char *) new_font.family_name, (char *) new_font.font_size);
  *(new_font.font_size)='\0';
}
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Script lg-font-fmt}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Font information to decorate characters, e.g., for style files.

\<h-defines\><<<
#ifndef LGFNT
#define LGFNT "Font(\"%s\",\"%s\",\"%d\",\"%d\")\n"
#endif
>>>


\<vars\><<<
static U_CHAR *lg_font_fmt = NULL;
>>>



\<get from tex4ht.env file\><<<
lg_font_fmt = (char *) get_script(lg_font_fmt,LGFNT,'f');
>>>




%%%%%%%%%%%%%
\Section{XeLaTeX: Scan Xdv Font Entry (Native Font Def)}
%%%%%%%%%%%%%

`xelatex -no-pdf example'

\Link[http://en.wikipedia.org/wiki/XeTeX]{}{}XeTeX\EndLink


 The xetex code is at 
  \Link[http://scripts.sil.org/svn-public/xetex/TRUNK/]{}{}http://scripts.sil.org/svn-public/xetex/TRUNK/\EndLink{} 
  and xdvipdfmx is found under the texk directory. 


%%%%%%%%%%%%%
\SubSection{Font Definition}
%%%%%%%%%%%%%





\<scan xdv font entry\><<<  
   unsigned short flags;
new_font.num       = (INTEGER) get_unt(4); 
new_font.scale     = (INTEGER) get_unt(4);  
new_font.design_sz = new_font.scale;
flags = (INTEGER) get_unt(2); 
`<get xdv font name`>
new_font.layout_dir = (flags & `<xdv flag vertical`>) ? 1 : 0;
new_font.rgba_color = (flags & `<xdv flag colored`>)?
                                   (unsigned long) get_unt(4)
                                   :
                                   0xffffffff; 
if( flags & `<xdv flag variations`> ){ 
   int n =  (INTEGER) get_unt(2);  `%number of variations`%
   int i;
   for (i = 0; i < n; ++i) {       `%ignore axis`%
         (void) get_unt(4); 
   }  
   for (i = 0; i < n; ++i) {       `%ignore value of variation`%
      (void) get_int(4); 
}  }
(IGNORED) printf("(--- xdv font = %s (not implemented) ---)\n", new_font_name);
`<get xdv font info`>
>>>



\<get xdv font name\><<<
{    int  n, family_name_n, style_name_n;
     U_CHAR *ch;
`%     char* family_name;
     char* style_name;`%
  font_name_n =  (INTEGER) get_unt(1); 
  family_name_n = (INTEGER) get_unt(1);    
  style_name_n  = (INTEGER) get_unt(1);
  n =  font_name_n + 1;
  ch = new_font_name = m_alloc(char, n);
  while( --n ){  *ch = (int) get_unt(1); ch++; }
  *ch = '\0';
  n =  family_name_n + 1;
`%  ch = family_name = m_alloc(char, n);`%
  while( --n ){ `%*ch = (int)`% (void) get_unt(1); ch++; }
  *ch = '\0';
  n =  style_name_n + 1;
`%  ch = style_name = m_alloc(char, n);`%
  while( --n ){ `%*ch = (int)`% (void) get_unt(1); ch++; }
  *ch = '\0';
}
>>>

REMOVE allocated mem at end of usage!!




\<entries for xetex\><<<
INTEGER layout_dir;
unsigned long rgba_color;
>>>

% char *fam_name, *sty_name; 
% INTEGER used;  new_font.used = 0;



\<xdv flag vertical\><<<
0x0100
>>>

\<xdv flag colored\><<<            
0x0200
>>>

\<xdv flag variations\><<<
0x0800
>>>




%%%%%%%%%%%%%
\SubSection{Within IVD}
%%%%%%%%%%%%%


\<font defs for xdv's idv?\><<<
(version_id == `<version xdv`>) 
&&  
( 
  (ch == `<xdv-pic-file op`>) 
  ||
  (ch == `<xdv-native-font-def op`>) 
  ||
  (ch == `<xdv-glyph-array op`>) 
  ||
  (ch == `<xdv-glyph-string op`>) 
)
>>>

\<xdv flag fonttype icu\><<<
0x0002
>>>

\<xdv flag fonttype atsui\><<<
0x0001
>>>

\<xdv font def for idv\><<<
switch( ch ){
  case `<xdv-native-font-def op`>:
     `<xdv/ivd native font def`>
     break;
  case `<xdv-glyph-string op`>:
     `<xdv/idv glyph string`>
     break;
  default: 
    printf(" ===> ---------- xdv's idv ------------ <====  %d\n" , ch);
}
>>>

\<xdv/idv glyph string\><<<
{
           int i, glyphCount;  
   (void) get_unt(4);  
   glyphCount = (INTEGER) get_unt(2); 
   for( i = 0; i < glyphCount; ++i ){ 
     (void) get_int(4);  
   } 
   for (i = 0; i < glyphCount; ++i){
     (void) get_unt(2);          
   }
}
>>>


\<xdv/ivd native font def\><<<
{      int i, flags;

(void) get_unt(4);  `%tex_id`%
(void) get_unt(4);  `%scale`%

    flags = (INTEGER) get_unt(2);



if ((flags & `<xdv flag fonttype icu`>) || (flags & `<xdv flag fonttype atsui`>)) { 

for ( 
i =
  (INTEGER) get_unt(1)   `%  font name `%
+  (INTEGER) get_unt(1)     `%  family name `%
 + (INTEGER) get_unt(1)   `%  style name `%
;
i>0;
i--
){ (void) get_unt(1); }





        if( flags & `<xdv flag colored`> ){
           (void) get_unt(4);
        }

if( flags & `<xdv flag variations`> ){ 
   int n =  (INTEGER) get_unt(2);  `%number of variations`%
   for (i = 0; i < n; ++i) {       `%ignore axis`%
         (void) get_unt(4); 
   }  
   for (i = 0; i < n; ++i) {       `%ignore value of variation`%
      (void) get_int(4); 
}  }

}

}
>>>




%%%%%%%%%%%%%
\SubSection{????????????????}
%%%%%%%%%%%%%






\<get xdv font info\><<<
`<first definition of font?`>
`<open xdv font file`>
new_font_name[font_name_n] = '\0';
new_font.name = m_alloc(char, font_name_n + 1);
(IGNORED) strcpy((char *)  new_font.name, (char *) new_font_name );
`<family and size of font`>
`<compute mag of xdv font`>
>>>


\<compute mag of xdv font\><<< 
new_font.mag = new_font.scale / (new_font.design_sz / 100); 
>>> 
 






\<open xdv font file\><<<
{    `%   FILE *font_file;
        U_CHAR  file_name[256]; `%
   `<search dirs for xdv font`>
/*
   if( font_file == NULL ){
      dump_env();      err_i_str(1,file_name);  
      missing_fonts = TRUE;
      new_font.char_f = 2;
      new_font.char_l = 1;
   } else {
*/
      `<get xdv chars dimensions`>
/*
      (IGNORED) fclose(font_file);
   }  
*/
}
>>>


\<get xdv chars dimensions\><<<
{       `<vars for reading xdv font file`>
   `<scan xdv dimension of components of font file`>
   `<scan XDV header of font file`>
   `<scan xdv char info words`>
   `<scan xdv width table`>
   `<scan xdv height table`>
   `<scan XDV depth table`>
   `<scan XDV italic correction table`>
   `<scan XDV lig/kern table`>
   `<scan XDV kern table`>
   `<scan XDV extensible character table`>
   `</xdv fontdimen parameters`>
}
>>>






\</xdv fontdimen parameters\><<<
`<xdv font slant`>             `%all need design_size_to_pt(n)`%
`<xdv interword space`>
`<XDV interword stretch`>
`<XDV interword shrink`>
`<xdv ex height`>
`<XDV em width (=quad width)`>
`<XDV extra space`>
>>>


\<xdv font slant\><<<
new_font.it = 0;
>>>


\<xdv interword space\><<<
new_font.word_sp = 350000;
`<adjust inter-word space`>
>>>

\<ex height\><<<
new_font.ex = 450000;
>>>


\<scan xdv dimension of components of font file\><<<
new_font.char_f = 0;
new_font.char_l = 255;
new_font.wtbl_n = 0;
new_font.htbl_n = 0;
new_font.dtbl_n = 0;
>>>


it_correction_table_length   = 0;
lig_kern_table_length        = 0;
kern_table_length            = 0;
extensible_char_table_length = 0;
num_font_parameters          = 0;

\<vars for reading xdv font file \><<<
 int
     it_correction_table_length,
     lig_kern_table_length,
     kern_table_length,
     extensible_char_table_length,     `%<= 256`%
     num_font_parameters;
>>> 


\<scan xdv char info words\><<<
{      U_CHAR *ch, *hidp;
       int i;
   ch = new_font.char_wi = m_alloc(char, new_font.char_l
                                       - new_font.char_f + 1);
   hidp = new_font.char_hidp = m_alloc(char, new_font.char_l
                                       - new_font.char_f + 1);
   for( i = new_font.char_f; i <= new_font.char_l; i++ ){
      *(ch++) = 10;
      *(hidp++) = 26;
}  }
>>>


\<scan xdv width table\><<<
{       INTEGER *p;         `%needs design_size_to_pt(n)`%
            int  i;
   p = new_font.wtbl = m_alloc( INTEGER, new_font.wtbl_n);
   for( i = 0; i < new_font.wtbl_n; i++ ){
      *(p++) = 600000;
}  }                     
>>>



\<scan xdv height table\><<<
{       INTEGER *p;         `%needs design_size_to_pt(n)`%
            int  i;
   p = new_font.htbl = m_alloc( INTEGER, new_font.htbl_n);
   for( i = 0; i < new_font.htbl_n; i++ ){
      *(p++) = 600000;
}  }                     
>>>






\<skip font xdv def\><<<
        unsigned short flags;
for( i=0; i<8; i++ ){ ch = get_char(); }
flags = (INTEGER) get_unt(2); 
for( i = (INTEGER) get_unt(1) `% font name `%
       + (INTEGER) get_unt(1) `% font family name`%
       + (INTEGER) get_unt(1) `% font style name `%
    ; i>0 
    ; i-- ){ ch = get_char(); }
if( flags & `<xdv flag colored`> ){ (void) get_unt(4); }
if( flags & `<xdv flag variations`> ){ 
   int n =  (INTEGER) get_unt(2);
   int i;
   for (i = 0; i < n; ++i) { 
         (void) get_unt(4); 
   }  
   for (i = 0; i < n; ++i) { 
      (void) get_int(4); 
}  }
>>>



\<do glyph array\><<<
doGlyphArray(TRUE);
>>>


\<do glyph string\><<<
doGlyphArray(FALSE);
>>>





\<header functions\><<<
static void doGlyphArray( ARG_I(BOOL) );
>>>

\<functions\><<<
`[
static void doGlyphArray(yLocs)
     BOOL yLocs
;{         int i, glyphCount;  
   (void) get_unt(4);  
   glyphCount = (INTEGER) get_unt(2); 
   for( i = 0; i < glyphCount; ++i ){ 
     (void) get_int(4);  
     if( yLocs ){  (void) get_int(4);   }
   } 
   for (i = 0; i < glyphCount; ++i){
     (void) get_unt(2);          
   }
}
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Connecting to the Font Table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Verify that Font has not been Already Defined}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<first definition of font?\><<<
{        int i;
   for( i=font_tbl_size-1; i>0;  i-- )
     if( new_font.num == font_tbl[i].num )  warn_i(10);   }
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Access to Fonts}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<search font in font-tbl\><<<
cur_fnt = search_font_tbl( cur_fnt );
word_sp = `<size of space`>;
>>>

\<header functions\><<<
static int search_font_tbl( ARG_I(int) );
>>>

\<functions\><<<
`[
static int search_font_tbl( cur_fnt ) 
        int cur_fnt
;{      int i;
   for( i=0; i<font_tbl_size; i++){
     if( font_tbl[i].num == cur_fnt ){ return i; }
   }
   err_i_int( 6,cur_fnt );
   return 0;
}
>>>









%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Opening a Font File}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<open font file\><<<
{       FILE *font_file;
        U_CHAR  file_name[256];
   `<search dirs for font`>
   if( font_file == NULL ){
      dump_env();      err_i_str(1,file_name);  
      missing_fonts = TRUE;
      new_font.char_f = 2;
      new_font.char_l = 1;
   } else {
      `<get chars dimensions`>
      (IGNORED) fclose(font_file);
}  }
>>>



Some TeX systems provide virtual fonts without tfm files. Instead, they
provide file of aliases with records of the form `{\it virtual font
name}={\it actual font name}'. In such a case, the location of a file of
aliases can be provided within an a-record in \''tex4ht.env'.

The tex4ht program ignores records having form different than `{\it
  virtual font name}={\it actual font name}'.

The full names should be provided, without the .tfm extensions (e.g.,
gbksong33=GBKSONG33).


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Scanning a Font File}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

TFM = TeX font metric

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Layout}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Dimensions are expressed in printers' point units.

\<get chars dimensions\><<<
{       `<vars for reading font file`>
   `<scan dimension of components of font file`>
   `<scan header of font file`>
   `<scan char info words`>
   `<scan width table`>
   `<scan height table`>
   `<scan depth table`>
   `<scan italic correction table`>
   `<scan lig/kern table`>
   `<scan kern table`>
   `<scan extensible character table`>
   `</fontdimen parameters`>
}
>>>

%         (IGNORED) fseek(G_fontfp,(long)0,FROM_START);

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Breakdown}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<scan dimension of components of font file\><<<
file_length                    = (INTEGER) fget_int(font_file,2);
header_length                  = (int) fget_int(font_file,2);
new_font.char_f = (int) fget_int(font_file,2);
new_font.char_l = (int) fget_int(font_file,2);
new_font.wtbl_n = (int) fget_int(font_file,2);
new_font.htbl_n = (int) fget_int(font_file,2);
new_font.dtbl_n = (int) fget_int(font_file,2);
it_correction_table_length     = (int) fget_int(font_file,2);
lig_kern_table_length          = (int) fget_int(font_file,2);
kern_table_length              = (int) fget_int(font_file,2);
extensible_char_table_length   = (int) fget_int(font_file,2);
num_font_parameters            = (int) fget_int(font_file,2);
if( file_length != ( 6                + header_length
     - new_font.char_f              + new_font.char_l + 1
     + new_font.wtbl_n              + new_font.htbl_n
     + new_font.dtbl_n              + it_correction_table_length
     + lig_kern_table_length        + kern_table_length
     + extensible_char_table_length + num_font_parameters  )  
  ){ err_i_str(15,file_name); }
>>>





Shouldn't the hight table be of the same dim of the width and depth table?

\<vars for reading font file\><<<
 INTEGER  file_length;     `%all lengths are in words`%
 int    header_length,      
     it_correction_table_length,
     lig_kern_table_length,
     kern_table_length,
     extensible_char_table_length,     `%<= 256`%
     num_font_parameters;
>>> 


\<entries from font file into font-tbl\><<<
 INTEGER design_pt;     `%needs design_size_to_pt(n)`%
 int char_f, char_l;    `%0 --- 255`%
 U_CHAR *char_wi;        
 U_CHAR *char_hidp;        
 int  wtbl_n;
 int  htbl_n;
 int  dtbl_n;
 INTEGER  *wtbl;              `%needs design_size_to_pt(n)`%
 INTEGER  *htbl;              `%needs design_size_to_pt(n)`%
 INTEGER  *dtbl;              `%needs design_size_to_pt(n)`%
 INTEGER  word_sp;            `%needs design_size_to_pt(n)`%
 INTEGER  it;                 `%needs design_size_to_pt(n)`%
 INTEGER  ex;                 `%needs design_size_to_pt(n)`%
>>>

Character codes beyond 255 assume the same width as their 
counterpart modulo 256 characters.

\Verbatim
  header : array [0  -- lh - 1]  of stuff
char_info: array [bc -- ec]      of char_info_word
   width : array [0  -- nw - 1]  of fix_word
   height: array [0  -- nh - 1]  of fix_word
   depth : array [0  -- nd - 1]  of fix_word
   italic: array [0  -- ni - 1]  of fix_word
 lig_kern: array [0  -- nl - 1]  of lig_kern_command
     kern: array [0  -- nk - 1]  of fix_word
    exten: array [0  -- ne - 1]  of extensible_recipe
   param : array [1  -- np]      of fix_word
\EndVerbatim

\SubSection{Header Information}

\<scan header of font file\><<<
`<scan checksum in font file`>
`<scan design size in font file`>
(IGNORED) fseek(font_file, (long) ((header_length - 2) * 4), `<relative file addr`>);
>>>

Incompatible fonts shouldn't agree in their check sum. A zero check
sum should be disregarded. 

\<scan checksum in font file\><<<
{      INTEGER checksum;
   checksum = ( INTEGER) fget_int(font_file,4);
   if( checksum && new_font_checksum
                && (checksum  != new_font_checksum) )
    {   warn_i(16);
        (IGNORED) fprintf(stderr,"%s: %d\ndvi file: %d\n",file_name,
                     checksum, new_font_checksum);
}   }
>>>

%    if( ((checksum = ( INTEGER) fget_int(font_file,4)) != NULL )

The design size of a font  is represented in 
point units of \TeX, and it must be greater than 1.0.
The representation uses 32-bit words, with the leading 12 bits
providing the integer part and the two-complement of a word providing
negative values. The allowed values are in the range of
$2048-2^{-20}$ to $-2048$.

\<scan design size in font file\><<<
new_font.design_pt = ( INTEGER) fget_int(font_file,4); `%needs design_size_to_pt(n)`%
>>>

Skipped optional identification of coding scheme (40 bytes),
identification of font family (20 bytes), etc.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Character Information}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<scan char info words\><<<
{      U_CHAR *ch, *hidp;
       int i;
   ch = new_font.char_wi = m_alloc(char, new_font.char_l
                                       - new_font.char_f + 1);
   hidp = new_font.char_hidp = m_alloc(char, new_font.char_l
                                       - new_font.char_f + 1);
   for( i = new_font.char_f; i <= new_font.char_l; i++ ){
      *(ch++) = (int) fget_unt(font_file,1);
      *(hidp++) = (int) fget_unt(font_file,1);
      (IGNORED) fseek(font_file, 2L, `<relative file addr`>);
}  }
>>>


Next comes the \`'char_info' array, in which 
each word contains the following information for one character.

\List{$\circ$}

\item Width index: 8 bits
\item Height index: 4 bits
\item Depth index: 4 bits
\item Italic index: 6 bits
\item Tag: 2 bits
\item Other: 8 bits whose interpretation depends on the value of the tag.

\List{}

\item {0.}  Ignore.

\item {1.} An index into the \`'lig_kern' table.

\item {2.} The character code of the next character in
a list of size-inreasing characters.

\item {3.} An index, called extensible index, into the table \`'exten'
where the components of the current composite character are specified.
\EndList

\EndList


 The width of a character is \`'width[width index] * design_pt', etc.
This compression scheme allows characters of a font to choose from 256
width-values, 16 height-values, etc.  Since
\`'width[0]=height[0]=depth[0]=italic[0]=0', a character in the font
should never have a zero index.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Width Table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<scan width table\><<<
{       INTEGER *p;         `%needs design_size_to_pt(n)`%
            int  i;
   p = new_font.wtbl = m_alloc( INTEGER, new_font.wtbl_n);
   for( i = 0; i < new_font.wtbl_n; i++ ){
      *(p++) = ( INTEGER) fget_int(font_file,4);
}  }                     
>>>

The above fits with measurements made for the fixed-sized font cmtt10, but
not with the following measurements made  for cmsy10.

\Verbatim
182045, 327681, 509726, 509726, 436908, 436908, 436908, 509726,
509726, 655361, 327681, 327681, 509726, 509726, 655361, 400498,
509726, 509726, 436908, 436908, 364090, 364090, 509726, 655361,
655361, 655361, 473316, 327681, 509726, 509726, 509726, 436908,
344061, 655361, 327681, 327681, 655361, 655361, 655361, 212991,
655361, 655361, 327681, 400498, 327681, 509726, 436908, 473316,
180223, 655361, 436908, 436908, 582543, 582543, 344061, 344061,
364090, 364090, 436908, 327681, 473316, 473316, 509726, 509726,
400498, 523286, 450377, 383297, 523745, 404502, 536119, 428716,
559789, 405233, 565248, 508817, 452018, 787021, 634289, 539946,
509726, 535213, 555420, 446006, 523509, 475226, 455478, 701238,
563429, 491886, 527019, 436908, 327681, 436908, 436908, 247723,
400498, 400498, 291271, 291271, 291271, 291271, 327681, 327681,
254863, 254863, 182045, 327681, 327681, 400498, 671742, 182045, 
546135, 491521, 546135, 345886, 436908, 436908, 509726, 509726, 
291273, 291271, 291271, 327681, 182045, 327681, 509726, 345886
\EndVerbatim


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Height Table}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<scan height table\><<<
{       INTEGER *p;         `%needs design_size_to_pt(n)`%
            int  i;
   p = new_font.htbl = m_alloc( INTEGER, new_font.htbl_n);
   for( i = 0; i < new_font.htbl_n; i++ ){
      *(p++) = ( INTEGER) fget_int(font_file,4);
}  }                     
>>>

For instance, the following table for cmr10

\Verbatim
0,      110683, 384696, 451470, 524288, 553416, 595357, 611670,
644958, 659002, 675749, 700301, 716526, 728178, 767499, 786432
\EndVerbatim




\SubSection{Depth Table}




\<scan height table\><<<
{       INTEGER *p;         `%needs design_size_to_pt(n)`%
            int  i;
   p = new_font.dtbl = m_alloc( INTEGER, new_font.dtbl_n);
   for( i = 0; i < new_font.dtbl_n; i++ ){
      *(p++) = ( INTEGER) fget_int(font_file,4);
}  }                     
>>>



\<scan depth tableNO\><<<
                  `%needs design_size_to_pt(n)`%
(IGNORED) fseek(font_file, (long) (depth_table_length * 4), 
                           `<relative file addr`>);
>>>


\SubSection{Italic Correction Table}

Used for italic correction explicitly requested with \`'\/', and for
isolated character in math mode (MetaFont 315--316).

\<scan italic correction table\><<<
                                                   `%needs design_size_to_pt(n)`%
(IGNORED) fseek(font_file, (long) (it_correction_table_length * 4),
            `<relative file addr`>);
>>>

\SubSection{Ligature Table}

Substitutions  for specified runs of chrarcters

\<scan lig/kern table\><<<
(IGNORED) fseek(font_file, (long) (lig_kern_table_length * 4),
             `<relative file addr`>);
>>>

\SubSection{kern table}

Space to add between specified pairs of characters.

\<scan kern table\><<<
                          `%needs design_size_to_pt(n)`%
(IGNORED) fseek(font_file, (long) (kern_table_length * 4),
             `<relative file addr`>);
>>>



\SubSection{Extensible Table}

\<scan extensible character table\><<<
(IGNORED) fseek(font_file, (long) (extensible_char_table_length * 4),
             `<relative file addr`>);
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Font Dimension Parameters}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

At least seven parameters used in \''\fontdimen', each occupying four
bytes (= one word).  With the exception of the first parameter, all
the other parameters should be magnified for a font that is magnified
with \`'at' or \`'scaled'.

\</fontdimen parameters\><<<
`<font slant`>             `%all need design_size_to_pt(n)`%
`<interword space`>
`<interword stretch`>
`<interword shrink`>
`<ex height`>
`<em width (=quad width)`>
`<extra space`>
>>>

\List{$\circ$}

\item The slant per point of a font, used for determining the height
  of accent characters.

\<font slant\><<<
new_font.it = ( INTEGER) fget_int(font_file,4);
>>>

\item  In math mode the inner word space is zero and italic correction values are used.

\<interword space\><<<
new_font.word_sp = ( INTEGER) fget_int(font_file,4);
`<adjust inter-word space`>
>>>

The following variable needs initialization that is used before
the loading of any font. Without it, the program will enter an infinite
loop.


\<defines\><<<
#ifdef LONG
#define MARGINSP 344061L        `%tt at 10pt`%
#else
#define MARGINSP 344061 
#endif
>>>

\<vars\><<<
static double word_sp   = 999999.0, margin_sp;
>>>

Turbo C didn't let me to do casting within initialization.

\<main's init\><<<
margin_sp = (double) MARGINSP;     `%/ (double)(1L<<20) * (double) 655360;`%
>>>

\<adjust inter-word space\><<<
if( new_font.word_sp == 0 ) {
        int i;
  for( i = new_font.char_f; i <= new_font.char_l; i++ ){
    new_font.word_sp = 
      ( new_font.word_sp
       +
        *(new_font.wtbl + (int)(*(new_font.char_wi + i - new_font.char_f)))
      )  / (new_font.char_f<i? 2:1);
  } }
if( new_font.word_sp == 0 )  new_font.word_sp = MARGINSP; `%fix`%
>>>

We took for space size an approximated character width.


\<interword stretch\><<<
(IGNORED) fseek(font_file, 4L, `<relative file addr`>);
>>>

\<interword shrink\><<<
(IGNORED) fseek(font_file, 4L, `<relative file addr`>);
>>>

\item The design height of letters. 

\<ex height\><<<
new_font.ex = (INTEGER) fget_int(font_file,4);
>>>

\item   The size of one em in the font.

\<em width (=quad width)\><<<

>>>

\item Extra  interword space at the end of sentences.

\<extra space\><<<

>>>
\EndList


\Section{Computing Font Info}

\SubSection{Characters' Width}

\<return char width\><<<
return (INTEGER)(
    `<(double) char_width( ch )`>  
  );  
>>>


\<(double) char_width( chr )\><<<
design_size_to_pt( *(font_tbl[cur_fnt].wtbl + 
                  (int) `<chr width of`>) )
* (double) font_tbl[cur_fnt].scale 
>>>


\<chr width of\><<<
*(font_tbl[cur_fnt].char_wi +
       (chr - font_tbl[cur_fnt].char_f)% 256)
>>>



\<(double) char_width( design_ch? design_ch : ch )\><<<
design_size_to_pt( *(font_tbl[cur_fnt].wtbl 
                 +  (int) (`<design-ch / ch width of`>)) )
   * (double) font_tbl[cur_fnt].scale
>>>


\<design-ch / ch width of\><<<
*(font_tbl[cur_fnt].char_wi +  (int)
   ( (design_ch? design_ch : ch) - font_tbl[cur_fnt].char_f)% 256)
>>>





\<(double) char_width( ch )\><<<
design_size_to_pt( *(font_tbl[cur_fnt].wtbl 
                     +  (int) (`<ch of width`>) )
                 )  
* (double) font_tbl[cur_fnt].scale
>>>


\<ch of width\><<<
*(font_tbl[cur_fnt].char_wi +  (int)
   ( ch - font_tbl[cur_fnt].char_f)% 256)
>>>


\<ch width\><<<
(int)(`<(double) char_width( ch )`>)
>>>

\SubSection{Characters' Height}




\<(double) char_height( ch )\><<<
design_size_to_pt( *(font_tbl[cur_fnt].htbl 
                 +  (int) (`<ch of height`>)) )
   * (double) font_tbl[cur_fnt].scale
>>>


\<ch of height\><<<
( *(font_tbl[cur_fnt].char_hidp +  (int)
   ( ch - font_tbl[cur_fnt].char_f)% 256)
  >>  4
) & 0x0F
>>>


\<ch height\><<<
(int)(`<(double) char_height( ch )`>)
>>>

\SubSection{Characters' Depth}




\<(double) char_depth( ch )\><<<
design_size_to_pt( *(font_tbl[cur_fnt].dtbl 
                 +  (int) (`<ch of depth`>)) )
* (double) font_tbl[cur_fnt].scale
>>>


\<ch of depth\><<<
( *(font_tbl[cur_fnt].char_hidp +  (int)
   ( ch - font_tbl[cur_fnt].char_f)% 256)
) & 0x0F
>>>


\<ch depth\><<<
(int)(`<(double) char_depth( ch )`>)
>>>

\SubSection{Other Sizes}


\<size of ex\><<<
design_size_to_pt( 1.7 * (double) font_tbl[cur_fnt].ex )
* (double) font_tbl[cur_fnt].scale
>>>


\<size of space\><<<
design_size_to_pt( font_tbl[cur_fnt].word_sp )
                   * (double) font_tbl[cur_fnt].scale 
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Font Information from Htf Tables}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

The htf fonts are used only within the text part of the html files. 

Each char code $i$ in a font may be assigned a string representation
and a gif option. When the gif option is provided, the character is
taken to be a picture with ALT getting the string for nongraphical
reviewers.

For character code i, $0\leq i\leq 255$, we maintain
\List{$\circ$}

\item A bit in \`'*gif' to determine if this option exists: \''*gif[] >>
i & 1'

\item A bit in \`'*gif_on' to determine if this option is used:
\''*gif_on[] >> i & 1'

\item A bit in \`'*ch_str' to determine if the string has length different
than one.

\item A character \`'*ch' that holds the character when the string
is of length one, 
and holds an index to \`'*str' when the string is longer than 1.

\item A pointer  \`'**str[*ch[i]]' to a string, if the character has a
string of length that differs from 1.
\EndList


In the `.htf' files, uses line entries of the form \`'string1string2...',
where the strings have the same arbitrary open and close
delimiters. An empty second string indicate no-option gif.


\<entries for html chars in font-tbl\><<<
char *name, *gif_on, *ch_str, ch255;  `%2000`%
unsigned U_CHAR **str, *ch, *gif1;
>>>

The following provides a value for characters of missing fonts out of
the range 32--127.  Within that range, the character codes are being
used.

\<get ignored chars\><<<
char *digit = p+2;
ignore_ch = 0;
while( *digit != '\0' ){
  if( (*digit < '0') || (*digit > '9') ){
    ignore_ch = 0; break;
  }
  ignore_ch = 10 * ignore_ch + (*digit - '0');
  if( ignore_ch > 255 ){ ignore_ch = 0; break; }
  digit++;
}
>>>

\<vars\><<<
static int ignore_ch = 0;
>>>





%%%%%%%%%%%%%%%%%%%%%%%
\Section{Load Characters}
%%%%%%%%%%%%%%%%%%%%%%%


In case of shared htf fonts, we can have much more sharing below.

Lynx introduces a space before and after each figure.


\<get html characters\><<<
{      U_CHAR str[256];
       int i, design_n, n_gif;
       `<font looping variables`>
   n_gif = new_font.char_l - new_font.char_f + 1;
   new_font.ch255 = 0;  
   `<initiate gif flags`>
   `<initiate htf accents`>
   new_font.ch = m_alloc(unsigned char, n_gif );
   `<set default characters`>
   new_font.str =  m_alloc(unsigned char*, n_gif);  
   new_font.str[0] = &null_str;
   design_n = 0;
      `<load file of characters`>
   new_font.str = (unsigned U_CHAR **) r_alloc((void *)   new_font.str,
                     (size_t) ( (design_n?design_n:1) * sizeof(char *)) );
   `<merge new html font with old ones`>
}
>>>

A value 0 corresponds to an empty string.  A value greater than 0 points to 
a character string.
\`'   design_n = 0;' had value 1 earlier.  Probably because we had \`'design_n',
and not \`'(design_n?design_n:1)', which asked for allocation of memory of size 0.  This caused a problem to mallocate, because it produced a non-valid 0 ( \`'insuffient
memory') error

\<vars\><<<
static unsigned  U_CHAR  null_str = '\0';    `% /*NEW*/ `%
>>>

\<initiate gif flags\><<<
{     int n_gif_bytes;
   n_gif_bytes = (n_gif + 7) / 8;
   new_font.gif_on = m_alloc(char, n_gif_bytes );
   new_font.ch_str = m_alloc(char, n_gif_bytes );
   `<memory for math classes`>
   for( i=n_gif_bytes; i--; ) {
     `<init math-closing`> new_font.ch_str[i] = new_font.gif_on[i] = 0;
   }
   new_font.gif1 = m_alloc(unsigned char, n_gif );
   for( i=n_gif; i--; ) {
       `<init math`> new_font.gif1[i] = 0;
}  }
>>>

\<set default characters\><<<
for( i = new_font.char_f; i <= new_font.char_l ; i++ ){
  new_font.ch[i - new_font.char_f] =
                 (char)  (((31<i) && (i<128))? i : ignore_ch);
} 
>>>




The first iteration searches for the font directly. The second
iteration searches for aliased font.


\<load file of characters\><<<
{  char search_font_name [256];
  (IGNORED) strcpy((char *) search_font_name, (char *) new_font.name);
  while( 1 ){                         BOOL flag;
     `<font looping test`>
     flag = TRUE;
     for( ; font_name_n; font_name_n-- ){  FILE* file;
                                           int   char_f, char_l;
       new_font_name[font_name_n] = '\0';
       `<file = .htf file`>
       if( file != NULL){
                                           INTEGER x_char_l;
         `<scan header line in html font file`>
         if( x_char_l == HTF_ALIAS) {
           `<scan aliased htf file`> 
           (IGNORED) fclose(file);  flag = FALSE; break;
         }
         `<scan info of html font file`>
         `<scan trailer line in html font file`>     
         htf_to_lg(html_font,  new_font_name, fonts_n, file);
         `<trace htf files`>
         (IGNORED) fclose(file);  break;
     } }
     if( flag ){ break; }
  }
  if( font_name_n == 0 ){
     if( errCode == 0 ){ errCode= 21; }
     warn_i_str(21,search_font_name); 
     (IGNORED) fprintf(stderr,
               "%d--%d)\n", new_font.char_f, new_font.char_l);
     dump_env();
  } else { `<trace env file`> }
}
>>>


\<font looping variables\><<<
int loopBound = 0;
U_CHAR loopName[256];
loopName[0] = '\0';
>>>

\<font looping test\><<<
if( eq_str( new_font_name, loopName) ){
     U_CHAR name[256];
   (IGNORED) sprintf(name, "%s.htf", new_font_name);
    err_i_str(1, name);
} else {
   (IGNORED) strcpy((char *) loopName, (char *) new_font_name);
}
loopBound++;
if( loopBound > 10 ){
   U_CHAR name[256];
   (IGNORED) sprintf(name, "%s.htf", new_font_name);
   err_i_str(1, name);
}
>>>


%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Aliases}
%%%%%%%%%%%%%%%%%%%%%%%

\<if alias return 0\><<<
if( ( name == new_font_name ) && (n == 19) && (ch=='.') ){
   return HTF_ALIAS; 
}
>>>



\<defines\><<<
#define  HTF_ALIAS 10000000
>>>







\ifHtml[\HPage{more}
Was \`'   printf("%d--%d)\n", new_font.char_f, new_font.char_l);'

\Verbatim
  Something I noticed while working on the redirection program:

  - When a warning message is given about a missing .htf file, the first
part:

  --- warning --- Couldn't find `.htf' file for font `cmitt10' (char codes:

is printed to stderr, while the second part:

  0--127)

is printed to stdout. This looks silly if you redirect stdout but not
stderr, as you'll see only the second halve in the log file. (I do
intend to expand my redirection utility to include stderr, if desired,
but I think this should be fixed anyway).
\EndVerbatim
\EndHPage{}]\fi











\<scan aliased htf file\><<<
{                                 int chr;
  font_name_n=0;
  while( (chr = get_html_ch(file)) != '\n' ){
    if( chr != ' ' ) search_font_name[font_name_n++] = chr;
  }
  search_font_name[font_name_n]  = '\0';
  if( eq_str( search_font_name, new_font_name) ){ err_i_str(20, new_font_name); }
  (IGNORED) printf("Searching ``%s.htf' for ``%s.htf'\n", 
                                        search_font_name, new_font.name);
  htf_to_lg(html_font, new_font_name, fonts_n, file);
  new_font_name = (char *)  r_alloc((void *) new_font_name,
                                  (size_t) (font_name_n+1));
  (IGNORED) strcpy((char *) new_font_name, (char *) search_font_name);
  font_name_n = strlen((char *) new_font_name);
}
>>>








\<get replacement fontNO\><<<
if( dot_file ){           BOOL  tag;
   (IGNORED) fseek(dot_file, 0L, `<abs file addr`>);
   tag = TRUE;
   while( tag ){
     switch( getc(dot_file) ){
       case  EOF: { j++;  tag = FALSE;  break; } `%no replacement`%
       case 'a': { `<scan replacement font`>   }
        default: {                    int ch; 
                   do ch = getc(dot_file); 
                   while( (ch != '\n') && (ch != EOF) );
                   break; }
}  } }
>>>


\<scan replacement fontNO\><<<
   int   chr; 
   U_CHAR *ch;
ch = new_font.name;
while( *ch++ == (chr = getc(dot_file)) );
if( chr==' ' ){
  tag = FALSE;   
  while( (new_font_name[0] = getc(dot_file)) == ' ' );
  font_name_n=1;
  while( (chr = getc(dot_file)) != '\n' )
    if( chr != ' ' ) new_font_name[font_name_n++] = chr;
  new_font_name[font_name_n]  = '\0';
  (IGNORED) printf("Loading ``%s.htf' for ``%s.htf'\n", 
                                new_font_name, new_font.name);
}
>>>




\Section{Merge Tables}

Don't we loose some vital info here? Were this comes from?

\<merge new html font with old ones\><<<
for( i = fonts_n; i--; )
  if( eq_str(html_font[i].name, new_font_name) ){       int k;
     k = html_font[i].i;
     free((void *)  new_font.gif1 ); new_font.gif1= font_tbl[ k ].gif1;
     free((void *)  new_font.ch );   new_font.ch  = font_tbl[ k ].ch;
     free((void *)  new_font.str );  new_font.str = font_tbl[ k ].str;
     free((void *)  new_font.ch_str );
                               new_font.ch_str = font_tbl[ k ].ch_str;
     `<merge math entries`>
     break;     }
if( i < 0 ){ `<record new tex4ht font`> }
>>>


\<record new tex4ht font\><<<
html_font = fonts_n? (struct html_font_rec *) r_alloc((void *) html_font,
                 (size_t) ((fonts_n+1) * sizeof(struct html_font_rec) ))
                   :  m_alloc(struct html_font_rec, 1);
html_font[fonts_n].name = m_alloc(char, font_name_n + 1);
(IGNORED) strcpy((char *) html_font[fonts_n].name, (char *) new_font_name);
html_font[fonts_n].i    = font_tbl_size;
fonts_n++;
>>>

\<scan fonts vars\><<<
int fonts_n;
struct html_font_rec *html_font=0;
>>>

\<init scan fonts vars\><<<
fonts_n = 0;
>>>

\<free html font memory\><<<
if( html_font ){
  while( fonts_n-- )  free((void *)  html_font[fonts_n].name);
  free((void *)  html_font );
}
>>>

EXPLAIN THE CONTENT OF THE FOLLOWING

\<types\><<<
struct html_font_rec{  char* name;
                       int   i;     };
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Scan Characters}
%%%%%%%%%%%%%%%%%%%%%%%%%

\<scan info of html font file\><<<
if( char_f <= new_font.char_l ){      U_CHAR  del;
                                      int  j, n;
   `<skip front part in font file`>
   n =  ((char_l < new_font.char_l)? char_l : new_font.char_l)
        - char_f + 1;
   for( i = char_f - new_font.char_f; i < n; i++ ){
      `<scan html char in font file`>
      `<store html character`>                     }  
   `<skip back part of font file`>
}
>>>


\<skip front part in font file\><<<
while( char_f < new_font.char_f ){
  while( get_html_ch(file) != '\n' );
  char_f++;   }
>>>

\<skip back part of font file\><<<
while( char_l > new_font.char_l ){
  while( get_html_ch(file) != '\n' );
  char_l--;   }
>>>

We should consider characters having representations of \`'\decimal
digits\', \`'\x hexadecimal digits\', and \`'\o octal digits\'.

\<scan html char in font file\><<<
{      int indirect_ch, base=0, value=0, digit, ch1`%, ch2`%;
  indirect_ch = 0;
  del = get_html_ch(file);   j=0;
  while( (str[j++] = get_html_ch(file)) != del ) 
    { `<check for encoded chars`> };
  str[j-1] = '\0';
  while( get_html_ch(file) != del );
  ch1 = 0;
  while( ((ch = (int) get_html_ch(file)) != del) ){
     if( (ch < '0') || (ch > '9') ) break;
     ch1 = ch1 * 10 + ch - '0'; }
  `<propagate 4hf info into htf`>
  new_font.gif1[i] = ch1 % 256;
  do{  
    if( (ch = get_html_ch(file)) == del ){
      `<scan htf accent`>  break;
    }
  } while( ch != '\n' );
  if( ch != '\n' ){
    do{  
      if( (ch = get_html_ch(file)) == del ){
        `<scan htf accented`>  break;
      }
    } while( ch != '\n' );
  }
  if( ch != '\n' )
  { while( get_html_ch(file) != '\n' ); }
}
>>>




\<check for encoded chars\><<<
if( (digit=str[j-1]) == '\\' )  
  if( (indirect_ch = !indirect_ch) != 0) { 
    switch( value=get_html_ch(file) ){
      case 'x': { base = 16; value = 0;  j--; break; }
      case 'o': { base = 8;  value = 0;  j--; break; }
      default: {  
        if( (value < '0') || (value > '9') ) {
          indirect_ch = !indirect_ch;   str[j-1] = value;
        } else { value -= '0';  base = 10; j--; }
  } } }
  else{ if( value>255 ){ 
            warn_i_int(28,value); 
            value = 32;  dump_htf( file );
        }
        str[j-1] = value; 
  }
else if ( indirect_ch ){
  j--;   digit -=  (digit>'9')?  'A'-10 : '0';
  if( (digit<0) || (digit>=base) ){
      warn_i_int(29, str[j]);
      digit = 0; dump_htf( file );
  }
  value = value*base + digit;
} else if ( str[j-1]==10 ){
   dump_htf( file );
   err_i_int(48, i+1);
}
>>>


We might be able in the following to share strings by comparing with 
corresponding characters in other fonts.




The variable j holds the number of characters in the string plus
one.




\<store html character\><<<
add_bit( new_font.ch_str, i, j!=2 );
switch( j ){
  case 1: { new_font.ch[i] = 0;    break; }
  case 2: { new_font.ch[i] = *str; break; }  
  default: {                           unsigned U_CHAR  *p;
    new_font.str[design_n] = p = m_alloc(unsigned char, j);
    if( design_n>255 ){ design_n--; warn_i(35);}
    if( i==255 ){
       if( design_n == 255 ){
                new_font.ch[i] = 0;           new_font.ch255 = 1; 
       } else { new_font.ch[i] = ++design_n;  }
    } else {    new_font.ch[i] = ++design_n; }
    while( j-- )  p[j] = str[j];  `%2000`%
} }
>>>










\<header functions\><<<
static int get_html_ch( ARG_I(FILE*) );
>>>

\<functions\><<<
`[
static int get_html_ch( file )   FILE*  file

;{                        int ch;
  if( (ch = (int) getc(file)) == EOF ) {
     dump_htf( file );
     err_i_str(20, new_font_name);
  }
  return ch;
}
>>>





\<header functions\><<<
static FILE* f_open( ARG_II(const char*,const char*) );
>>>

\<functions\><<<
`[
static FILE* f_open( name, flags ) 
                          const char*  name `;
                          const char*  flags                           
;{                        FILE* file;
  if( (file = fopen(name,flags) ) != NULL ) {
     (IGNORED)  printf("(%s)\n",name);
  }
  return file;
}
>>>








\<header functions\><<<
static void dump_htf( ARG_I(FILE*) );
>>>

\<functions\><<<
`[
static void dump_htf( file )   FILE*  file

;{       int i, j, ch, chr=0;
  (IGNORED) fseek(file, 0L, 0);
  i=-1; j=0;
  while( (ch = getc(file)) != EOF  ){
    if( !j ){  chr = ch; }
    j += ch==chr;
    (IGNORED)  putc(ch,stderr); 
    if( ch == '\n' ){
       if( (i>-1 ) && (j<4) && (dump_htf_files<2) ){
          (IGNORED) printf("missing delimiter \n");
       }
       (IGNORED) fprintf(stderr,"%d:  ",++i);
       j=0;
} } }
>>>



\<vars\><<<
static short dump_htf_files = 0;
static BOOL dump_env_files = FALSE;
>>>

\<dump htf files\><<<
dump_htf_files = 1;
>>>

\<dump env file\><<<
dump_env_files = TRUE;
>>>

\<trace htf files\><<<
if( dump_htf_files ){
   dump_htf_files++;  dump_htf( file );  dump_htf_files--;
}
>>>

\<trace env file\><<<
if( dump_env_files ){ dump_env(); }
>>>




\<header functions\><<<
static void dump_env( ARG_I(void) );
>>>

\<functions\><<<
static void dump_env( MYVOID )  
{ 
                             int ch;
  if( !dumped_env ){
    dumped_env = TRUE;
    (IGNORED) fseek(dot_file, 0L, `<abs file addr`>);
    (IGNORED) fprintf(stderr,
     "\n----------------------------------------------------\n");
    (IGNORED) fprintf(stderr, "environment file\n");
    (IGNORED) fprintf(stderr,
     "----------------------------------------------------\n");
    while( (ch = getc(dot_file)) != EOF  ){
      (IGNORED)  putc(ch,stderr); 
    }
    (IGNORED) fprintf(stderr,
     "----------------------------------------------------\n");
}  }
>>>

\<vars\><<<
static BOOL dumped_env = FALSE;
>>>






\<header functions\><<<
static void htf_to_lg( ARG_IV(struct html_font_rec*,char*,int,FILE*));
>>>

\<functions\><<<
`[
static void htf_to_lg(html_font,  new_font_name, fonts_n, file)

                      struct html_font_rec*   html_font`;
                      char* new_font_name`;
                      int     fonts_n`;
                      FILE* file
;{                   
                                              int ch, i;
  for( i = 0  ; i<fonts_n; ){
     if( eq_str(html_font[i].name, new_font_name) ){  break; }
     i++;
  }
  if( i == fonts_n ){                       
                                              BOOL content;
                                              int prev_ch;
     prev_ch = '\n';  content = FALSE;
     while( (ch = (int) getc(file)) != EOF ) {
       if( (ch != '\n') || (prev_ch != '\n') ){
         (void)  putc( ch, log_file );  
         prev_ch = ch;  content = TRUE;
     } }
     if( content && (prev_ch != '\n') ){ 
        (void)  putc( '\n', log_file );  
     }
} }
>>>



\<scan header line in html font file\><<<
x_char_l =
      get_html_file_id(file, new_font.char_f, new_font.char_l, 19);
if( x_char_l != HTF_ALIAS) {
     char_f = (int) (x_char_l / 1000.0 + 0.5) + new_font.char_f;
     x_char_l -= (char_f-new_font.char_f) * 1000 - new_font.char_l;
     char_l = (int) x_char_l;
}
>>>


\<scan trailer line in html font file\><<<
(void) get_html_file_id(file, new_font.char_f, new_font.char_l, 18);
>>>

\<header functions\><<<
static INTEGER get_html_file_id( ARG_IV(FILE*, int, int, int) ); 
>>>

\<functions\><<<
`[
static  INTEGER get_html_file_id(file, first, last, n)
                            FILE* file`; 
                            int first`; int last`; int n

;{                          int ch, i, bound, cnt;
                            INTEGER  diff;
                            char* name;
   name = new_font_name;
   while( *name == (ch = get_html_ch(file)) )  name++;
   `<if alias return 0`>
   if( (*name != '\0') || (ch != ' ') )  warn_i_str(n, name);
   bound = first;  diff = 0;
   for( cnt = 0; cnt < 2; cnt++ ){
      while( ch == ' ' )  ch = get_html_ch(file);
      i = 0;
      while( (ch >= '0') && (ch <= '9') ){ 
         i = i * 10 + ch - '0';  ch = get_html_ch(file);  }
      if( i != bound ){
         `<warning(22`>, new_font_name, i, bound); show_err_context();
         diff = diff * 1000 + i - bound;    }
      bound = last;  }
   while( ch != '\n' ) ch = get_html_ch(file);
   return diff;
}
>>>

\<defines\><<<
#ifndef TRUE
#define TRUE 1
#endif
#ifndef FALSE
#define FALSE 0
#endif
#ifndef BOOL
#define BOOL int
#endif
>>>




\Section{Use of Characters}


When \''next_char' is not equal to -1, there is a character waiting to
replace the current character.


\<insert ch to text\><<<
`<set begin accents`>
`<css for chars`> `<trace dvi char`> 
`<left class del`> `<pos dvi ch`> 
`<mark accented ch`>
if( `<next-char`> != -1 ) { 
   `<open output file`>
   (IGNORED) put_4ht_ch( `<next-char`>, cur_o_file );
   `<next-char`> = -1; 
} else if( `<next-str`> ) { 
   `<current char for forwarded string`>
   print_f_4ht(next_str); free((void *) next_str); 
   next_str = (char *) 0;
} else {
   if( verb_ch ){
      `<open output file`>
      (IGNORED) put_4ht_ch( ch, cur_o_file );
   } else {  `<insert font char`> }
}
`<end mark accented ch`>
`<end pos dvi ch`> `<right class del`> 
`<end trace dvi char`> `<end css for chars`> 
`<set end accents`>
>>>


Does \`'verb_ch' correspond to \''\Char'?


\<insert font char\><<<
   int gif_flag, chr, r_ch;
    BOOL  ch_str_flag;
r_ch = ch - font_tbl[cur_fnt].char_f;
gif_flag = font_tbl[cur_fnt].gif1[r_ch];
ch_str_flag = get_bit( font_tbl[cur_fnt].ch_str, r_ch);
chr = ((r_ch == 255) && font_tbl[cur_fnt].ch255 )? 256 :
                         *(font_tbl[cur_fnt].ch + r_ch);
if( (gif_flag % 2) || ch_str_flag ){      design_ch = ch;
             { `<insert design chr`> } design_ch = 0;    }
else { `<insert standard char`> }
>>>



\<vars\><<<
static BOOL verb_ch = FALSE;
>>>


A design character is either a picture (\''gif_flag') or 
a string character (\''ch_str_flag').

\<insert design chr\><<<
      U_CHAR  str[256], *p;
      BOOL sv;
      int mag;
sv = special_on;   special_on = TRUE;   
if( gif_ch && (gif_flag % 2) ){
   `<open output file`>
   if( !gif_open[gif_flag] ){
     `<img char without template`>    
   } else if( !get_bit( class_on, gif_flag ) ) {
      notify_class_info(gif_flag);
      store_bit_I( class_on, gif_flag );  
   } 
   `<<IMG SRC="...`>
   `<..."ALT="...`>
   `<..."CLASS="family...`>
   `<...gif font size...`>
   `<...gif font mag...`>
   `<...gif sym ord...`>
   `<..."/IMG>`>
} else  { `<insert string char`> }
special_on = sv;    
>>>





\<header functions\><<<
static void notify_class_info( ARG_I(int) );
>>>

\<functions\><<<
`[
static void notify_class_info( gif_flag )   int gif_flag
;{                        U_CHAR str[256], *p;
   str[0] = '\0';
   p = gif_open[gif_flag];
   if( p ) 
     if( *p ) (IGNORED) strct(str,p);
   p = gif_alt[gif_flag];
   if( p ) 
     if( *p ) (IGNORED) strct(str,p);
   p = gif_class[gif_flag];
   if( p ) 
     if( *p ) (IGNORED) strct(str,p);
   p = gif_size[gif_flag];
   if( p ) 
     if( *p ) (IGNORED) strct(str,p);
   p = gif_mag[gif_flag];
   if( p ) 
     if( *p ) (IGNORED) strct(str,p);
   p = gif_ord[gif_flag];
   if( p ) 
     if( *p ) (IGNORED) strct(str,p);
   p = gif_end[gif_flag];
   if( p ) 
     if( *p ) (IGNORED) strct(str,p);
   p = str; 
   while( *p ){
     if( *p == '\n' ) *p = ' ';
     p++; 
   }
   (IGNORED) fprintf(log_file, class_fmt, 
      gif_flag,
      gif_id[gif_flag]? gif_id[gif_flag] : "",
      str);
}
>>>

For some reason, bordlan cc+ complains if the
\`'p = gif_open[gif_flag]' are placed within the if's.

\`'configuration for class %d' below stands for
\`'\\special{t4ht;|%d...}'


\<img char without template\><<<
(IGNORED) sprintf(str, 
   "configuration for htf class %d (char %d of %s.htf)",
   gif_flag, ch,font_tbl[cur_fnt].name
  );
warn_i_str(50,str); 
>>>

\<img char without template\><<<
gif_open[gif_flag] = m_alloc(char,
   `<1 + strlen((char *) <IMG SRC="+"ALT="+++++">+)`>);
(IGNORED) strcpy((char *) gif_open[gif_flag],
           `<<IMG SRC="+"ALT="+++++">+`>);
gif_alt[gif_flag] = gif_open[gif_flag]+11;  
  *(gif_alt[gif_flag] - 1) = '\0';
gif_class[gif_flag] = gif_open[gif_flag]+19;
  *(gif_class[gif_flag] - 1) = '\0';
gif_size[gif_flag] = gif_open[gif_flag]+20;
  *(gif_size[gif_flag] - 1) = '\0';
gif_mag[gif_flag] = gif_open[gif_flag]+21;
  *(gif_mag[gif_flag] - 1) = '\0';
gif_ord[gif_flag] = gif_open[gif_flag]+22;
  *(gif_ord[gif_flag] - 1) = '\0';
gif_end[gif_flag] = gif_open[gif_flag]+23;
  *(gif_end[gif_flag] - 1) = '\0';
gif_id[gif_flag] = gif_open[gif_flag]+28;
  *(gif_id[gif_flag] - 1) = '\0';
>>>

\<<IMG SRC="+"ALT="+++++">+\><<<
"<img src=\"+\" alt=\"+++++\" />+"
>>>

\<1 + strlen((char *) <IMG SRC="+"ALT="+++++">+)\><<<
29
>>>

%   `<..."IMG OPTIONS="...NOT`>


What is the difference between the following two cases?


\<insert standard char\><<<
if( !gif_flag || (gif_flag % 2) || ch_map_flag ) {  put_char(chr);  
} else{ `<put char(chr)`> }
>>>

If \`'gif_flag % 2' is the case we have a picture which we want to
insert for it just the string part. (The !gif_flag is for text with
pattermn 0?)

\<insert string char\><<<
if( !gif_flag || (gif_flag % 2)  || ch_map_flag ) {
   put_alt_ch(chr,ch_str_flag);  }
else{ `<put string-char(chr)`> }
>>>

     
\SubSection{Script class-fmt}

Font information, e.g., for style files.

\<h-defines\><<<
#ifndef LGCLS
#define LGCLS "Font_Class(%d,\"%s\"): %s\n"
#endif
>>>


\<vars\><<<
static U_CHAR *class_fmt = NULL;
>>>



\<get from tex4ht.env file\><<<
class_fmt = (char *) get_script(class_fmt,LGCLS,'c');
>>>




\SubSection{File Names for Gifs}

Symbol i from base font x gets into file \`'x-i.gif', and from 
c-magnified  font goes into \`'x-c-i.gif'. In old LaTeX,
\`'\documentstyle[...12p..]{..}' gives a based-10 font magnified into 12.



\<defines\><<<
#define GIF_I      "-%x%s"
#define GIF_II  "-%x-%x%s"
#define GIF_VII       "%s"
>>>



\<h-defines 2\><<<
#ifdef DOS
#define HTM
#endif
>>>

\<defines\><<<
#ifdef HTM
#define DOS_GIF_FILE
#endif
>>>





\<insert gif symbol to html file\><<<
if( !dos_file_names ){
   print_f(font_tbl[cur_fnt].name);
   if( mag == 10 )  (IGNORED) sprintf(str, GIF_I,   design_ch, gif);
   else             (IGNORED) sprintf(str, GIF_II,  mag, design_ch, gif);
}
>>>

\<insert gif symbol to lg file\><<<
if( !dos_file_names ){
   if( mag == 10 ) (IGNORED) sprintf(str, "%s-%x%s", 
                        font_tbl[cur_fnt].name, ch, gif);
   else            (IGNORED) sprintf(str, "%s-%x-%x%s", 
     font_tbl[cur_fnt].name, mag, ch, gif);
}
>>>


Transform long file names to 8 characters.


\<insert gif symbol to html file\><<<
`%
#ifdef DOS_GIF_FILE 
`%
if( dos_file_names ){
   dos_gif_file(str, mag, design_ch);
   print_f(str);
   (IGNORED) sprintf(str, GIF_VII, gif);
}
`%
#endif
`%
>>>


\<insert gif symbol to lg file\><<<
`%
#ifdef DOS_GIF_FILE 
`%
if( dos_file_names ){
   (IGNORED) strcpy((char *) str, (char *) font_tbl[cur_fnt].name);
   dos_gif_file(str, mag, ch);
   strct(str,gif);
}
`%
#endif
`%
>>>





The following writes into the \`'.lg' file.  The \`'templt' ends with
a percent (\''%\0').  The algorithm collects the characters
until a \''%' is encountered. Then it prints out the segment of
characters accumulated, and goes to process whatever follows the \`'%'.


\<header functions\><<<
static void script( ARG_IV(char *, U_CHAR *, int, U_CHAR *) ); 
>>>

\<functions\><<<
`[
static void script(templt, job, page, font)   
      U_CHAR *templt`;
      U_CHAR *job`;
      int  page`;
      U_CHAR *font      
                                      
;{    U_CHAR *ch, *p;
      U_CHAR fmt[256];
   job[ (int) strlen((char *) job) - 1 ] ='\0';
   p = ch = templt;
   while( TRUE ){
     if( *ch == '%' ){
       `<print segment of templet`>
       `<get format of output`>
       switch( *(++ch) ){
          case '1':{ *p = 's'; 
                     (IGNORED) fprintf(log_file, fmt, job);  break;}
          case '2':{ *p = 'd'; 
                     (IGNORED) fprintf(log_file, fmt, page); break;}
          case '3':{ *p = 's'; 
                     (IGNORED) fprintf(log_file, fmt, font); break;}
          case '%':{ *p = 'c'; 
                     (IGNORED) fprintf(log_file, fmt, '%');  break;}
           default:{ job[ (int) strlen((char *) job) ] ='.';         return;}
       }
       p = ++ch;
     }else ch++;
} }
>>>



\<print segment of templet\><<<
*ch = '\0';  (IGNORED) fprintf(log_file, "%s", p);
*(ch++) = '%';  
>>>

The jobname var contains a period at the end, removed
temporarily for the script.  The default case above should have been
an error, or at least a warning.



\<get format of output\><<<
p=fmt;  *(p++) = '%';
if( *ch == '\0' ){ job[ (int) strlen((char *) job) ] ='.';  return; }
while( *ch != '%' ){  *(p++) = *(ch ++);  }
*(p+1) = '\0';
>>>



\Verbatim

 > Instead of a single-line script

 >      scall convert %1 %2 %3\nif errorlevel 1 goto end

 > you are allowed also to have multi-lines scripts

 >      scall convert %1 %2 %3
 >      sif errorlevel 1 goto end

 > Would this work?  If '\n' is a superior solution I
 > see no problems implementing it.

  Yes, this works fine for the "if errorlevel" problem. However, I have
found out in the meantime (RTMF is always a good idea ;-) that the
emTeX driver can create _all_ pcx files in one run, giving them names
like out01.gif, out02.gif, ... (or out001.gif, out002.gif, ... - it
depends on command line options). Display has a similar option. This
would significantly reduce the total conversion time, so I'm inclined to
use this option. (I think it may even outweigh the advantage of not
recreating the gifs after the b line, although I may be able to
implement that anyway with a little trickery). Since DOS has no way to
increase counters, I'd like to see the page numbers tex4ht gives also as
"01" (or "001"), etc. This would make it easy for me to use the emTeX
functionality. I've implemented this in tex4ht.c by changing the page
number format from %d to %03d. I assume this won't break anything else?


 > I didn't get the idea.

  The emTeX dvidot driver, when given an output filename like 'out???',
creates an output file for each page in the dvi file in one run, named
out001, out002, out003, etc. If the page numbers tex4ht produces are of
the same form (001 instead of 1), I can simply append them to 'out' like
this: out%2. This makes it easier to process the created files further.

 > The change is in the following line?

 >           case '2':{ (IGNORED) fprintf(log_file, "%d", page); break;}

  Yes.

 > Is  %03d  the same as  %0.3d?  If not, what is the difference?

  For integers, yes; it is also the same as %.3d. I just prefer the
first form, as it makes more sense to me (things after the dot are
called the precision specifier, and I don't want to specify precision
but field width).
\EndVerbatim

\SubSection{Script for Translation into Gifs}


\<h-defines\><<<
#ifndef LGPIC
#define LGPIC "--- needs --- %%1.idv[%%2] ==> %%3 ---\n%"
#endif
>>>


\<vars\><<<
static U_CHAR *font_gif = NULL;
>>>


\<get gif script from com ln\><<<
font_gif = p+2;
>>>



\<get from tex4ht.env file\><<<
font_gif = (char *) get_script(font_gif,LGPIC,'s');
`<inser percent-ch at end of s-script`>
>>>


\<inser percent-ch at end of s-script\><<<
{    int n;
  n = (int) strlen((char *) font_gif);
  if( font_gif[n-1] != '%' ){ font_gif[n] = '%'; font_gif[n+1] = '\0'; }
}
>>>


\SubSection{Script lg file Seperator}


Separates general picturs from symbols.

\<h-defines\><<<
#ifndef LGSEP
#define LGSEP "--- characters ---\n"
#endif
>>>


\<vars\><<<
static U_CHAR *begin_char_gif = NULL;
>>>



\<get start char-gif from com ln\><<<
begin_char_gif = p+2;
>>>



\<get from tex4ht.env file\><<<
begin_char_gif = (char *) get_script(begin_char_gif,LGSEP,'b');
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Default Format for Pictures}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<h-defines\><<<
#ifndef LGTYP
#define LGTYP ".png"
#endif
>>>


\<vars\><<<
static U_CHAR *gif = NULL;
>>>



\<get gif-type from com ln\><<<
gif = p+2;
>>>

In the extension name we don't want the line break at the end.

\<get from tex4ht.env file\><<<
gif = (char *) get_script(gif,LGTYP,'g');
{              int n;
   n = (int) strlen((char *) gif) - 1;
   if( gif[n] == '%' ){  gif[n] = '%'; }
   else if( gif[n] == '\n' ) {  gif[n] = '\0'; }
}
>>>









%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Encoding for Dos Font Names}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

We set font name + mag (2 chars) + ch number (2 ch). If the length is
no greater than 8, we are done.  Otherwise, we take the first  n-2
characters and map them to a string of length 4.  They are the most 
stable in the names, so they minimize replacements.

\<header functions\><<<
`%
#ifdef DOS_GIF_FILE
`%
static void  dos_gif_file( ARG_III(char *, int, int) );
`%
#endif
`%
>>>

\<functions\><<<
`%
#ifdef DOS_GIF_FILE
`%
`[
static void  dos_gif_file(str, mag, design_ch) 
        U_CHAR *str`;
        int  mag`;
        int  design_ch

;{      int  n, m, i;
        struct gif_file_rec * p, * q;
        U_CHAR *ch;
  m = n = (int) strlen((char *) str);
  if( n > 4 ){
    `<p = prefix of font file`>
    if( p == NULL ){ `<p = new prefix font file`> }
    gif_file = p;   
    for( n=0; n<4; n++ )   str[n] = xeh[(int)(*(p->code + n))];
  }
  str[n++] = xeh[mag<16? 0: mag / 16];
  str[n++] = xeh[mag % 16];
  str[n++] = xeh[design_ch<16? 0: design_ch / 16];
  str[n++] = xeh[design_ch % 16];
  str[n] = '\0';
}
`%
#endif
`%
>>>



We keep collisions table to ensure agains collisions. We do it in
circular linked list so that last visited in previous turn will be the
first to be visited now.  The prefix, and its suggested

\<types\><<<
`%
#ifdef DOS_GIF_FILE
`%
struct gif_file_rec{
    U_CHAR                code[4];
    U_CHAR                *name;
    struct gif_file_rec *next;     };
`%
#endif
`%
>>>

\<vars\><<<
`%
#ifdef DOS_GIF_FILE
`%
static struct gif_file_rec *   gif_file = (struct gif_file_rec *) 0;
`%
#endif
`%
>>>

\<p = prefix of font file\><<<
if( (p = gif_file) != NULL ){
  while( TRUE ){
    if( eq_str( str, p->name ) ) break;
    if( (p = p->next) == gif_file ){ p = NULL;  break; }
} }
>>>






\<p = new prefix font file\><<<
p =  m_alloc(struct gif_file_rec, 1);
`<get tentative prefix replacement`>
`<adjust prefix replacement`>
(IGNORED) printf("\nRenaming ``%s____%s' to ``%c%c%c%c____%s'\n", 
            str, gif,
                 xeh[(int)(ch[0])], xeh[(int)(ch[1])],
                 xeh[(int)(ch[2])], xeh[(int)(ch[3])]
               , gif);
p->name = m_alloc(char,m+1);
(IGNORED) strcpy((char *)  p->name, (char *) str );
if( gif_file ){  p->next = gif_file->next;   gif_file->next = p;  }
          else   p->next = p;  
>>>


We choose the scheme `sum(char codes of str) / 4' to find a number i,
and then we cycle around hex in jumps of i to choose four characters
not starting with digit.

\<get tentative prefix replacement\><<<
for(i=str[n]; n; ){ i+=str[--n];  if( i > (INT_MAX / 8) ) i/=2; }
if( (n=i % BASE) <10 ) n+= 10 + i%(BASE-20);
*(ch = p->code)= n; n += i;
ch[1]          = n%BASE; n += i;
ch[2]          = n%BASE; n += i;
ch[3]          = n%BASE;
>>>


To allow for adjustments, we srtoe indexes  of xeh, and not the
characters themselve.
We allow $BASE^3$ options of adjustments!!!

\<adjust prefix replacement\><<<
if( gif_file ){
   q = gif_file->next;
   while( TRUE ){
     if( (*(q->code) == *ch)   && (*(q->code+1) == ch[1]) &&
         (*(q->code) == ch[2]) && (*(q->code+2) == ch[3])  ){ 
        ch[3] ++;  ch[2] += ch[3]/ BASE;  ch[3] = ch[3] % BASE;
                   ch[1] += ch[2]/ BASE;  ch[2] = ch[2] % BASE;
                                          ch[1] = ch[1] % BASE;
        q = gif_file;
     } else if( q == gif_file ) break;
     q = q->next;
}  }
>>>

Instead of hex we take xeh.


\<defines\><<<
#define BASE  36
>>>

\<vars\><<<
`%
#ifdef DOS_GIF_FILE
`%
static U_CHAR xeh[]="0123456789abcdefghijklmnopqrstuvxyz";
`%
#endif
`%
>>>



\SubSection{Other}

\`'<<' is NOT a safe operation, beyond char size, for transporting across platforms.

\<defines\><<<
#define store_bit_I(ch,i)  ch[(i)/8]|=(1<<((i)%8));
#define store_bit_Z(ch,i)  ch[(i)/8]&=~(1<<((i)%8))
#define add_bit(ch,i,b)   ch[(i)/8] |= ((b) << ((i)%8))
#define get_bit(ch,i)     ((ch[(i)/8] >> ((i)%8)) & 1)
>>>



%#define store_bit(ch,i,b) if(b){ ch[(i)/8]|=(1<<((i)%8));}\
%                          else   ch[(i)/8]&=~(1<<((i)%8))



\<header functions\><<<
static void put_alt_ch( ARG_II( int, BOOL) );
>>>

\<functions\><<<
`[
static void  put_alt_ch(chr,ch_str_flag)
      int  chr`;
      BOOL ch_str_flag
;{
   if( !ch_str_flag ) put_char( chr );
   else if( chr > 0 ){ `<put htf char string`> }
}
>>>


The \`'gif_ch' is true when we put the character outside of
\`'\special{t4ht|}...\special{t4ht|}', and is false inside that range.
Within that range, used in ALT's, we want to eliminate the html
comamnds \`'<...>' and the delimiter characters \`'"'.

\<put htf char string\><<<
    unsigned U_CHAR * p;
p = font_tbl[cur_fnt].str[chr-1];
if( gif_ch )  print_f( (char *) p );  `% /*new*/`%
else while( *p ){
  switch( *p ){
    case '<':  { while( *p && (*p != '>') )  p++;  break; }
    case '>':
    case '"':  { p++;  break; }
   case '\'':  { p++;  break; }
    default:   { put_char( (int) *p  ) ; p++; }
} }
>>>

%     case '&':  { alt_ch_length = strlen((char *) p); }

%\<vars\><<<
%static int alt_ch_length = 0;
%>>>


\<vars\><<<
static BOOL gif_ch = TRUE;
static int design_ch = 0;
>>>



\Section{Css Trace on Characters}

\`'\Configure{characters}{<SPAN\:newlnch NAME="}{">}{</SPAN>}
{<IMG SRC="}{"ALT="}{"NAME="}{">}'



\<css for characters\><<<
        int n, code;
        U_CHAR *p, *q;
code = get_char();
n = 1 + ((--special_n>254)? 254 : special_n);
q = p = m_alloc(char, (int) n);
while( special_n > 254 ){ (void) get_char(); special_n--; }
while( special_n-- ) { *(q++) = get_char(); }
*q = '\0';  q = p;
switch ( code ){
  case '8': {  pause_style--; break; }
  case '9': {  pause_style++;  break; }
  case '-': {  default_font = font_tbl[cur_fnt].num; 
               base_font_size = font_tbl[cur_fnt].scale / 100; 
               break; }
  case '+': {  default_font = -1;                    break; }
  case '%': { `<insert font size`>  break; }
  case '=': { `<insert css name of ch`>  break; }
  case '|': { `<record string for htf class`>  break; }
  case ',': { `<don't report next htf class to lg`>  break; }
  default: { warn_i_int( 36, code); }
}
span_on = span_name_on && !pause_style; 
if( q ) free((void *)  q);
>>>

Since htf fonts are shred within tex fonts, and since they can easily
be modified by scripts in the output html files, changes of their classes
from within the 4ht files is not supported.



By taking integer for \`'pause_style' we allow for nested pausing of fonts.



\<vars\><<<
static int    pause_style = 0, default_font = -1, base_font_size=6533;
static BOOL  
  span_name_on = FALSE,
  span_on = FALSE;
>>>








\SubSection{4: Src Prefix}


\<record img-srcOUT\><<<
q = img_src;  img_src = p;  
>>>

\<varsOUT\><<<
static U_CHAR *  img_src;
>>>

\<main's initOUT\><<<
img_src = m_alloc(char, (int) 12);
(IGNORED) strcpy((char *) img_src, "<img \nsrc=\"" );
>>>


\<<IMG SRC="...\><<<
p= gif_open[gif_flag];
if( p ) 
if( *p ){      
   print_f(p); (IGNORED) strcpy((char *) str, (char *) font_tbl[cur_fnt].name);
   mag = (int) ((double) font_tbl[cur_fnt].scale /
                font_tbl[cur_fnt].design_sz  * 10 );
   `<insert gif symbol to html file`>
   print_f(str);
   add_bit( font_tbl[cur_fnt].gif_on, r_ch, 1 ); 
}
>>>


\SubSection{5: Alt Prefix}



\<record img-altOUT\><<<
q = img_alt;  img_alt = p;  
>>>

\<varsOUT\><<<
static U_CHAR *  img_alt;
>>>

\<main's initOUT\><<<
img_alt = m_alloc(char, (int) 7);
(IGNORED) strcpy((char *) img_alt, "\"alt=\"" );
>>>



\<..."ALT="...\><<<
p = gif_alt[gif_flag];
if( p )
  if( *p ){
     print_f(p);  put_alt_ch(chr,ch_str_flag);   
}
>>>


\SubSection{6: Img-CLASS Prefix}




\<..."CLASS="family...\><<<
p = gif_class[gif_flag];
if( p )
  if( *p ){ 
    (IGNORED) fprintf(cur_o_file, p,
                   font_tbl[cur_fnt].family_name);  }
>>>







%--------------------------------------


\SubSection{s: Img-CLASS Size}






\<...gif font size...\><<<
p = gif_size[gif_flag];
if( p )
  if( *p ){ 
     (IGNORED) fprintf(cur_o_file, p,
                   font_tbl[cur_fnt].font_size);  }
>>>




\SubSection{m: Img-CLASS Magnitude}





\<...gif font mag...\><<<
p = gif_mag[gif_flag];
if( p ) 
  if( *p && (font_tbl[cur_fnt].mag != 100) ){
     (IGNORED) fprintf(cur_o_file, p, font_tbl[cur_fnt].mag); 
}
>>>





\SubSection{o: Img-CLASS Ord}


\<...gif sym ord...\><<<
p = gif_ord[gif_flag];
if( p )
  if( *p ){
    (IGNORED) fprintf(cur_o_file, p, ch); 
}
>>>


%--------------------------------------

\SubSection{7: End Image}





\<..."/IMG>\><<<
p = gif_end[gif_flag];
if( p )
  if( *p ){ print_f( p ); }
>>>



\SubSection{Htf-based Classes}



\<record string for htf class\><<<
{                 int bad_str, m;
                  U_CHAR ch, *t[`<n spans`>], err_str[256];
bad_str=`<n spans-1`>;   (IGNORED) strcpy((char *) err_str, (char *) p);
if( n>`<n spans+2`> ){                     
   m = 100*( *p-'0' ) + 10*( *(p+1)-'0' )+ *(p+2)-'0';
   if( (m>-1) && (m<256) ){
      ch = *(p + 3);  t[0]=p;
      while( (*p = *(p+4)) != '\0' ){
        if( ch == *p ){ *p = '\0';  
          if( bad_str-- > 0 ) t[`<n spans-1`> - bad_str] = p+1;
        }
        p++;
   }  }
   if( !bad_str ){
      if( m==0 ){ span_name_on = n>`<n spans+3`>; }
      q = span_open[m];     span_open[m] = t[0];
      span_name[m] = t[1];  span_size[m] = t[2];
      span_mag[m]  = t[3];  span_ord[m]  = t[4];
      span_ch[m]   = t[5];  end_span[m]  = t[6];
      gif_id[m]   = t[7];
      if( not_notify ) { 
        store_bit_I( class_on, m );
        not_notify = FALSE; 
      } else   store_bit_Z( class_on, m );
   }
}
if( bad_str ){  warn_i_str(37,err_str); }
}
>>>





\<don't report next htf class to lg\><<<
not_notify = TRUE;
>>>

\<vars\><<<
static BOOL not_notify = FALSE;
>>>


\<n spans\><<<
8>>>
\<n spans-1\><<<
7>>>
\<n spans+2\><<<
10>>>
\<n spans+3\><<<
11>>>



\<vars\><<<
static U_CHAR * span_name[256], * span_open[256], * span_size[256],
     * span_mag[256],  * span_ch[256],   * end_span[256],
     * span_ord[256],  * gif_id[256];
static U_CHAR class_on[32];
>>>


\<main's init\><<<
{   int i;  i=256; while( i-- ) { 
     span_name[i] = span_open[i] = span_size[i] =
     span_mag[i]  = span_ch[i]   = end_span[i]  =
     span_ord[i]  = gif_id[i] = NULL; 
       if( (i>0) && !(i%2) ) {  store_bit_Z( class_on, i ); }
       else {   store_bit_I( class_on, i ); }
    }
}
>>>
   
   

\<defines\><<<
#define gif_open  span_open
#define gif_alt   span_name
#define gif_class span_size
#define gif_size  span_mag
#define gif_mag   span_ord
#define gif_ord   span_ch
#define gif_end   end_span
>>>



%\<main's init\><<<
%{   int i;  i=256; while( i-- ) { htf_class[i] = 0 ; } }
%>>>

\`'0': character without decoration; \`'1' gif 
without decoration.  Even numbers
(\`'...0') are reserved for ch with decoration, and odd numbers
(\`'...1') are for gifs with decoration.



A character template takes the form: +open + family-format +
size-format + mag-format + ord + close +after-font-info; The delimiter
can be +, or any other character.



\<put char(chr)\><<<
`<open output file`>
`<ensure for chr`>
if( span_on ){
   `<open for chr`>
   `<font-family of chr`>
   `<font-size of chr`>
   `<font-mag of chr`>
   `<ord of chr`>
   `<close for chr`>
}
put_char(chr);
if( span_on ){
   `<end for chr`>
}
>>>



\<put string-char(chr)\><<<
`<ensure for chr`>
if( span_on ){
   `<open for chr`>
   `<font-family of chr`>
   `<font-size of chr`>
   `<font-mag of chr`>
   `<ord of chr`>
   `<close for chr`>
}
put_alt_ch(chr,ch_str_flag);  
if( span_on ){
   `<end for chr`>
}
>>>

\<ensure for chr\><<<
if( gif_flag && !get_bit( class_on, gif_flag ) ) {
  notify_class_info(gif_flag);
  store_bit_I( class_on, gif_flag );  
} 
>>>




\<open for chr\><<<
if( span_open[gif_flag] )
  if( *span_open[gif_flag] ){
     print_f( span_open[gif_flag] );
}
>>>

\<end for chr\><<<
if( end_span[gif_flag] )
  if( *end_span[gif_flag] ){
     print_f( end_span[gif_flag] );
}
>>>



\<close for chr\><<<
if( span_ch[gif_flag] )
  if( *span_ch[gif_flag] ){
    print_f( span_ch[gif_flag] );
}
>>>


\<font-family of chr\><<<
if( span_name[gif_flag] )
  if( *span_name[gif_flag] ){
    (IGNORED) fprintf(cur_o_file, span_name[gif_flag],
                        font_tbl[cur_fnt].family_name);      
}
>>>



\<font-size of chr\><<<
if( span_size[gif_flag] )
  if( *span_size[gif_flag] ){
    (IGNORED) fprintf(cur_o_file, span_size[gif_flag],
                        font_tbl[cur_fnt].font_size);      
}
>>>


\<font-mag of chr\><<<
if( span_mag[gif_flag] )
  if( *span_mag[gif_flag] ){
    (IGNORED) fprintf(cur_o_file, span_mag[gif_flag],
                        font_tbl[cur_fnt].mag);      
}
>>>


\<ord of chr\><<<
if( span_ord[gif_flag] )
  if( *span_ord[gif_flag] ){
    (IGNORED) fprintf(cur_o_file, span_ord[gif_flag], chr);      
}
>>>





\SubSection{Font Properties}

\<insert font size\><<<
   int f;
f = 0; while( *p ){ f = 10*f + *(p++) - '0'; }
`<open output file`>
(IGNORED) fprintf(cur_o_file, "%d", 
  (font_tbl[cur_fnt].scale / base_font_size - 100) * f / 100 +100
   );      
>>>

\<insert css name of ch\><<<
`<open output file`>
(IGNORED) fprintf(cur_o_file, "%s", font_tbl[cur_fnt].name);      
if( font_tbl[cur_fnt].mag != 100 ){
   (IGNORED) fprintf(cur_o_file,"_%d", font_tbl[cur_fnt].mag);
}
>>>               


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Cascade Style Sheets}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%
\Section{Command Line}
%%%%%%%%%%%%%%%%%%



\<get cascade style sheet data\><<<
struct css_ext_rec * css =  m_alloc(struct css_ext_rec, 1);;
css->name = p + 2;
css->next = css_ext;
css_ext = css;
>>>

\<post scan comm ln args\><<<
if( css_ext == (struct css_ext_rec *) 0 ){
  struct css_ext_rec * css =  m_alloc(struct css_ext_rec, 1);;
  css->name = css_default;
  css->next = css_ext;
  css_ext = css;
}
>>>

\<main's vars\><<<
static struct css_ext_rec * css_ext = (struct css_ext_rec *) 0;
static char css_default[] = "4cs";
>>>

\<types\><<<
struct css_ext_rec{  char* name;
                     struct css_ext_rec *next;     };
>>>


%%%%%%%%%%%%%%%%%%
\Section{Retrieve Data}
%%%%%%%%%%%%%%%%%%


   
\<get css entries\><<<
{    static struct css_ext_rec * search_css_ext;
  for( search_css_ext = css_ext; 
       search_css_ext != (struct css_ext_rec *) 0;
       search_css_ext = search_css_ext->next       ){
     int css_name_n = (int) strlen((char *)  new_font.name );
     char * css_file_name = m_alloc(char, css_name_n + 1);
     (IGNORED) strcpy((char *) css_file_name, (char *) new_font.name);
     for( ; css_name_n; css_name_n-- ){
                                               FILE* file;
       css_file_name[css_name_n] = '\0';
       `<file = .css file`>
     }
     free((void *) css_file_name); 
} }
>>>

\<file = .css file\><<<
{                              U_CHAR name[256];
   (IGNORED) sprintf(name, "%s.%s", css_file_name, 
                                    search_css_ext->name);
   `<search file in htf locations`>
    if( file != NULL ){
      `<write css file to lg file`> 
      (IGNORED) fclose(file);  break;
    }
}
>>>



%%%%%%%%%%%%%
\Section{Copy CSS File}
%%%%%%%%%%%%%




\<write css file to lg file\><<<
`<check visited`>
if( !is_visited ){
  `<mark visited`>
   while( 1 ){
                int ch;
       do{
          ch = (int) getc(file);
       } while ( (ch == ' ') || (ch == '\n') || (ch == '\t') );
       if( ch == EOF ){ break; }
       do{
          (void)  putc( ch, log_file );
          ch = (int) getc(file);
       } while ( (ch != '\n') && (ch != EOF) );
       (void)  putc( '\n', log_file );
       if( ch == EOF ){ break; }
}  }
>>>

%%%%%%%%%%%%%
\Section{Duplicates Avoidance}
%%%%%%%%%%%%%



\<scan fonts vars\><<<
struct visited_file_rec * visited_file =
                       (struct visited_file_rec *) 0;
>>>

\<end loading fonts\><<<
while( visited_file != (struct visited_file_rec *) 0 ){
  struct visited_file_rec * v = visited_file;
  visited_file = visited_file->next;
  free((void *) v->name); 
  free((void *) v); 
}
>>>


\<mark visited\><<<
struct visited_file_rec * v =  m_alloc(struct visited_file_rec, 1);
v->name = m_alloc(char,  (int) strlen((char *)  name ) + 1 );
(IGNORED) strcpy((char *) v->name, (char *) name);
v->next = visited_file;
visited_file = v;
>>>

\<check visited\><<<
BOOL is_visited = FALSE;
struct visited_file_rec * v = visited_file;
while( v != (struct visited_file_rec *) 0 ){
  if(  eq_str(v->name, name) ){
    is_visited = TRUE;  break; 
  }
  v = v->next;
}
>>>


\<types\><<<
struct visited_file_rec{  char *name;
       struct visited_file_rec *next;     };
>>>


   

%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Accents}
%%%%%%%%%%%%%%%%%%%%%%

\Section{Htf Font Info}

Each htf font has between 2 to 4 fields per entry. The first field is
the textual representation, the second is the textual and pictorial
flags and decorations, the third is an the accent code, and the fourth
is a pointer into an accented code table (tex4ht.htf).


font.htf:

\Verbatim
'text-rep'  'text/pic-deco'  'accent-code'  'pointer to tex4ht.htf'
\EndVerbatim


The accent code uses universaly agreed upon codes for accent symbols.
For instance, 18 for \'=\`=, and 94 for \'=\^=.  0 signify no pointer.

The accented code uses universaly agreed upon codes for accented
symbols. We assume a unicode code-based system, but deviate from
it when it is convinient.


tex4ht.c makes move the third and fourt entries of each font into arrays,
and puts into the entries index-pointers to the array. By doing so, we can
allocate just one byte to an entry.


\Draw \ArrowHeads(1)
\DrawRect(80,-150)
\Move(5,-20) 

{\Do(1,10){\Move(0,-10)
{  \PaintRect(10,3)  
\Move(20,0) \PaintRect(10,3)
\Move(20,0) \PaintRect(10,3)
\Move(20,0) \PaintRect(10,3)}}
}

\PaintRect(10,3)  
\Move(20,0) \PaintRect(10,3)
\Move(20,0) \PaintRect(10,3)\FcNode(a)
\Move(20,0) \PaintRect(10,3)\FcNode(a2)


\MoveTo(100,-140) {\Move(5,10) \FcNode(b) \ArrowHeads(1) \Edge(a,b)}
\Do(1,4){\DrawRect(20,10) \Move(20,0)}

\MoveTo(100,-100) 
   {\Move(5,10) \FcNode(b) \ArrowHeads(1) \Edge(a2,b)}
\Do(1,4){\DrawRect(20,10) \Move(20,0)}
  
\MoveTo(130,-30) {\Move(-5,-5) \FcNode(b)  
     \Move(15,0) \Text(--A--)
     \Move(35,0) \Text(--\string^--)
       {\Move(15,25) \Text(--\^A--)}
     \Move(35,0) \Text(--\string^\string^--)
       {\Move(15,25) \Text(--$\hat {\hat A}$--)}
     }
\Do(1,4){\DrawRect(20,10) \Move(0,-10)}

\MoveTo(150,-35)
{\Move(-20,0)\FcNode(a) \Move(-20,-60) \FcNode(b) \VHEdge(b,a)}
\Do(1,4){\FcNode(a) \Move(15,0) \FcNode(b)
         {\Edge(a,b)} \Move(0,-5) \DrawRect(20,10)  
         {\Move(10,10)\FcNode(a) \Move(0,15) \FcNode(b) {\Edge(a,b)}
          \DrawRect(20,10)}
          \Move(20,5)
}





\EndDraw






The accented code matrix tex4ht.htf is the closest file to the font on
the directory path from the root. Different paths may employ a
different tex4ht.htf accent tables.  An
(accent-code,accented-code) pair maps to accented-code in the table,
or the maping is undefined.  Each accented-code in the matrix hold
textual representation.

\<entries for html chars in font-tbl\><<<
unsigned U_CHAR *accent, *accented;
unsigned int *accent_array, *accented_array, accent_N, accented_N;
>>>

\<initiate htf accents\><<<
new_font.accent = m_alloc(unsigned char, n_gif );
new_font.accented = m_alloc(unsigned char, n_gif );
new_font.accent_array = (unsigned int *) 0;
new_font.accented_array = (unsigned int *) 0;
new_font.accent_N = new_font.accented_N = 0;
for( i=n_gif; i--; ) {
   new_font.accent[i] = new_font.accented[i] = 0;
}
>>>


\<scan htf accent\><<<
ch1 = 0;
while( ((ch = (int) get_html_ch(file)) != del) ){
     if( (ch < '0') || (ch > '9') ){ warn_i_int(48,i);  break; }
     ch1 = ch1 * 10 + ch - '0'; }
new_font.accent_array = new_font.accent_N++?
      (unsigned int *) r_alloc((void *) new_font.accent_array,
                 (size_t) (new_font.accent_N * sizeof(unsigned int)))
            :  m_alloc(unsigned int, 1);
new_font.accent_array[new_font.accent_N - 1] = ch1;
new_font.accent[i] = new_font.accent_N;
>>>


\<scan htf accented\><<<
ch1 = 0;
while( ((ch = (int) get_html_ch(file)) != del) ){
     if( (ch < '0') || (ch > '9') ){ warn_i_int(48,i);  break; }
     ch1 = ch1 * 10 + ch - '0'; }
new_font.accented_array = new_font.accented_N++?
      (unsigned int *) r_alloc((void *) new_font.accented_array,
                 (size_t) (new_font.accented_N * sizeof(unsigned int)))
            :  m_alloc(unsigned int, 1);
new_font.accented_array[new_font.accented_N - 1] = ch1;
new_font.accented[i] = new_font.accented_N;
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Integrated accents}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Remote Accents}
%%%%%%%%%%%%%%%%%%%%%%%%

If the accent character is for text (\''\accent'), we'll be looking
for the next character to be the accented character.  If the accent
character is for math (\''\mathaccent'), we'll be looking for the next
group of characters (i.e., subformula) to be the accented. If the
subformula consists of a single character, we probably should assume
an accented character instead of an accented subformula.


\List{*}
\item \''\special{t4ht*\string^t}'---requests to consume the
next character, tailored to be placed just before an \''\accent'. In addition,
if a template exists for text accents, the family-name and
character-code of the accent are printed before the accented
parameter together with the first three parts of the template. In such 
a case, the fourth part of the template is printed after the content.
\item
\''\special{t4ht*\string^t#1 #2 #1 #3 #1 #4 #1 #5 #1 #6}'---provides
template consisting of four parts, where \''#1' is assumed to 
be a distinguished character separating the components.  If the
separators appears only twice or three times, the template is
annihilated.
\item \''\special{t4ht*\string^m...}'---Variants of the above cases
for \''\mathaccent'. However, the fourth part of the template is
ignored, and assumed to be requested througth a
\''Send{EndGroup}{1}{...}' (i.e., \''\special{t4ht\string~>1...}').
\EndList


\SubSection{Open Accent}

\<accent specials\><<<
special_n--;
switch ( get_char() ){
  case 't': { if( special_n ){ 
                `<text accent template`>
              } else { `<text accent`> }   
              break;
            }
  case 'm': { if( special_n ){ 
                `<math accent template`>
              } else { `<math accent`> }   
              break;
            }
  case 'a': { `<accented template`>
              break;
            }
  case 'i': { `<accenting template`>
              break;
            }
   default: { `<consume unused specials`> }
}
>>>



A accent is  a character from a given font. Given a content to be
accented, the text/math accent marks it \`'#1 font #2 char-no #3
content #4' according to the accent/mathaccent template. Each
character in the content is marked by \`'#1 font #2 char-no #3
character #4' according to the accented template.



Text accent can be on empty content or on character, and the accent
itself is empty if it consists of a character code greater than 127.
 Math accent is
placed on the center of a formula.

\<text accent\><<<
needs_accent_sym = TRUE * 2;
>>>

\<math accent\><<<
needs_accent_sym = TRUE;   
>>>

\<accented = true\><<<
needs_accented_sym++;
>>>


The \''\special' tells tex4ht where the accent starts, and tex4ht
consumes the following character for a accent. At that place, tex4ht
also place the opening tag of the element.

  

\<pre accent symbol\><<<
if( in_accenting ){
  `<post accent symbol`>
} else if( `<is accent char?`> ){
  if( needs_accent_sym ){
                                        BOOL needs_end_accent;
    needs_end_accent = (needs_accent_sym == 2 * TRUE);
    if( needs_end_accent && t_accent_template ){
      (IGNORED) fprintf(cur_o_file, "%s%s%s%d%s%d%s",
         t_accent_first,   font_tbl[cur_fnt].family_name, 
         t_accent_second, ch, t_accent_third,
         font_tbl[cur_fnt].accent[ch]? 
           font_tbl[cur_fnt].accent_array[font_tbl[cur_fnt].accent[ch]-1]
           : 0,
         t_accent_fourth); 
    } else if( m_accent_template ){
      (IGNORED) fprintf(cur_o_file, "%s%s%s%d%s%d%s",
         m_accent_first,   font_tbl[cur_fnt].family_name, 
         m_accent_second, ch, m_accent_third,
         font_tbl[cur_fnt].accent[ch]? 
           font_tbl[cur_fnt].accent_array[font_tbl[cur_fnt].accent[ch]-1]
           : 0,
         m_accent_fourth); 
    }
    if( i_accent_template ){ 
      (IGNORED) fprintf(cur_o_file, "%s", i_accent_first); }
    in_accenting = TRUE;
  }
}
>>>


\<post accent symbol\><<<
                                               long int width;
if( i_accent_template ){ 
  (IGNORED) fprintf(cur_o_file, "%s", i_accent_second); }
needs_end_accent = (needs_accent_sym == 2 * TRUE);
if( needs_end_accent && t_accent_template )
{  `<accented = true`> }
else if( m_accent_template )
{  `<accented = true`>  stack[stack_n-1].accented = TRUE; }
needs_accent_sym = FALSE; 
width = (INTEGER)( `<(double) char_width( ch )`> );
if( needs_end_accent ){  needs_end_accent = x_val + 9 * width / 10; }
in_accenting = FALSE;
>>>

\<main's vars\><<<
BOOL in_accenting;
>>>

\<main's init\><<<
in_accenting = FALSE;
>>>

The following needs to be fixed for cases that ch is greater than 127.

\<is accent char?\><<<
needs_accent_sym && (ch < 128)
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Closure for Text Accent}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



\<end text accent\><<<
if( needs_end_accent && t_accent_template ){
   `<end accented span`>
   (IGNORED) fprintf(cur_o_file, "%s", t_accent_fifth);
   needs_end_accent = FALSE; `<exit text accented`>
}
>>>







The following in needed for cases of text-accents on empty content,
immeddiately followed by a character (e.g., \`'\^{}Xx').

\<set begin accents\><<<
if( x_val > needs_end_accent ){
  `<end text accent`>
}
>>>


The following takes care of closing a text accent after a character.

\<set end accents\><<<
`<end text accent`>
>>>

%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Tailoring}
%%%%%%%%%%%%%%%%%%%%%%

before-family-name, between-family-char-number, after char-number

\<text accent template\><<<
(IGNORED) get_open_accent(&t_accent_template,
            &t_accent_first, &t_accent_second,
            &t_accent_third, &t_accent_fourth,
            &t_accent_fifth, &special_n);
>>>

\<math accent template\><<<
(IGNORED) get_open_accent(&m_accent_template,
            &m_accent_first, &m_accent_second,  
            &m_accent_third, &m_accent_fourth,
            &m_accent_fifth, &special_n);
>>>




\<vars\><<<
static BOOL needs_accent_sym = FALSE,  needs_end_accent = FALSE;
static char  * t_accent_template = (char *) 0,
             * t_accent_first, * t_accent_second,
             * t_accent_third, * t_accent_fourth, * t_accent_fifth,
             * m_accent_template = (char *) 0,
             * m_accent_first, * m_accent_second,
             * m_accent_third, * m_accent_fourth, * m_accent_fifth;
>>>




\<header functions\><<<
static void get_open_accent(
    ARG_VII(char**, char**, char**, char**, char**, char**, long int*));
>>>

\<functions\><<<
`[
static void get_open_accent(all,first,second,third,fourth,fifth,n)
      char   **all`;
      char   **first`;
      char   **second`;
      char   **third`;
      char   **fourth`;
      char   **fifth`;
      long int    *n
;{                              char *p, *q;
                                int i;
   if( *all  ){ free((void *) *all);  }
   *all = p = get_str( (int) *n );  *n=0;
   i = 2;
   *first = q = p + 1;  
   while ( TRUE ){
     if( *q == *p ){
       *q = '\0';
       switch( i ){
         case 2:{  *second = q+1; break; }
         case 3:{  *third  = q+1; break; }
         case 4:{  *fourth = q+1; break; }
         case 5:{  *fifth = q+1; break; }
       }
       if( i++ == 5 ){ break; }
     } else if( !*q ){
       free((void *) *all);  *all = (char *) 0;    break;
     }
     q++;
} }
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Mark Accented Content}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



\<mark accented ch\><<<
if( a_accent_template && needs_accented_sym ){
  (IGNORED) fprintf(cur_o_file, "%s%s%s%d%s%d%s",
     a_accent_first,   font_tbl[cur_fnt].family_name, 
     a_accent_second, ch, a_accent_third,
     font_tbl[cur_fnt].accented[ch]? 
       font_tbl[cur_fnt].accented_array[font_tbl[cur_fnt].accented[ch]-1]
       : 0,
     a_accent_fourth); 
}
>>>


\<end mark accented ch\><<<
if( a_accent_template && needs_accented_sym ){
   (IGNORED) fprintf(cur_o_file, "%s", a_accent_fifth);
}
>>>

Accents can be embedde, for instance, \`'\hat{a\hat b}'. Hence,
\''needs_accented_sym' is treated as a number.



The math accented end at the end of the group, sent there by 
\`'\special{t4ht~>...}' in the sty file.

\<exit math accented\><<<
needs_accented_sym--;   
>>>


\<exit text accented\><<<
needs_accented_sym--;   
>>>

\<accented template\><<<
(IGNORED) get_open_accent(&a_accent_template,
            &a_accent_first, &a_accent_second,  
            &a_accent_third, &a_accent_fourth,
            &a_accent_fifth, &special_n);
>>>

\<vars\><<<
static BOOL  needs_accented_sym = 0;
static char  * a_accent_template = (char *) 0,
             * a_accent_first, * a_accent_second,
             * a_accent_third, * a_accent_fourth, * a_accent_fifth;
>>>



\<accenting template\><<<
(IGNORED) get_open_accent(&i_accent_template,
            &i_accent_first, &i_accent_second,  
            &i_accent_third, &i_accent_fourth,
            &i_accent_fifth, &special_n);
>>>

\<vars\><<<
static char  * i_accent_template = (char *) 0,
             * i_accent_first, * i_accent_second,
             * i_accent_third, * i_accent_fourth, * i_accent_fifth;
>>>

\`'* i_accent_second,
             * i_accent_third, * i_accent_fourth;' are dummy 
provided for consistency.




\<BOOl stack accented\><<<
accented
>>>

\<end math accented\><<<
if( stack[stack_n].accented ){ 
   `<exit math accented`>
   stack[stack_n].accented=FALSE;
}
>>>

\<init end math accented\><<<
stack[stack_n].accented  = FALSE;
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Math Classes for  Symbols}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Tex assignes class numbers 0--7 to the atoms of math formulas:
0--ordinary symbol, 1--large operator, 2--binary operation,
3--relational operation, 4--math delimiter, 5--right delimiter,
6--punctuation mark, and 7--adjustable.
We use classes 7, 8, 9 as extra free ones.




\Section{Scanning Requests}

\`'{\everypar{}\special{t4ht^i}$sym... i=0, 1, 2, 3, 4,..., a, b, ...., ~
$\special{t4ht^}}' 


A  right delimiter immediately after a math openimiter ammuses
a matching pair.

\List{*}
\item \`'\special{t4ht^i}' - on    class i-'0' (i='0', '1', ..., \`'~'
\item  \`'\special{t4ht^-}'--pause from processing delimiters
\item  \`'\special{t4ht^+}'--continue processing delimiters
\item
 \`'\special{t4ht^}'--off, if in scan-mode of class values.
on/off show-class, otherwise
\item
\`'\special{t4ht^i*...*...}'---Configure delimiters for class i
\item  \`'\special{t4ht^ix}'--put delimiters of class i on next group.
If x=\`'>' ignore delimiters within the group.
\item  \`'\special{t4ht^i)*...*...}'--put the specified delimiters of
 class  on next group, instead of the default ones.
Ignore delimiters within the group.
\item  \`'\special{t4ht^i(*...*...}'--put the specified delimiters of
 class  on next group, instead of the default ones.
Don't ignore delimiters within the group.
\EndList


 




\<classes for math symbols\><<<
switch( special_n ){ 
  case 0:{ if( math_class_on ){
              open_del = 256;   pause_class = ignore_subclass_del = 0;
              math_class_on = FALSE;  `<recall intrusive flags`>
           } else { show_class = !show_class; }
           break;
         }
  case 1:{ `<save intrusive flags`>  
           special_n--; 
           if( (math_class = scan_class(1)) == `<num of math classes: 79`> )
             { math_class = 0; }
           else math_class_on = TRUE;  
           break;
         } 
  case 2:{  `<class delimiters on group`>
            break; }
 default:{ `<set config class dels`> }
}
>>>





\<vars\><<<
static BOOL math_class_on = FALSE, show_class = FALSE;
static int open_del = 256, math_class, pause_class, ignore_subclass_del;
>>>

\`'open_del' is used by close delimiter, if they are immediate
neighbors.

\<vars\><<<
static int sv_group_dvi, sv_trace_dvi_C, sv_in_trace_char, sv_span_on,
    sv_in_span_ch;
>>>

\<save intrusive flags\><<<
sv_group_dvi     = group_dvi;
sv_trace_dvi_C   = trace_dvi_C;
sv_in_trace_char = in_trace_char;
sv_span_on       = span_on;
sv_in_span_ch    = in_span_ch;
>>>


\<recall intrusive flags\><<<
group_dvi     = sv_group_dvi;
trace_dvi_C   = sv_trace_dvi_C;
in_trace_char = sv_in_trace_char;
span_on       = sv_span_on;
in_span_ch    = sv_in_span_ch;
>>> 







\<header functions\><<<
static int scan_class( ARG_I(int) );
>>>

\<functions\><<<
`[
static int scan_class( flag ) 
        int flag
;{                                    int math_class;
   math_class = get_char();
   if(   (math_class >= '0' )
      && (math_class < '0' + `<num of math classes: 79`>) ){
      { math_class -= '0';    }
   } else {
        if( flag== 1 ) {
           switch( math_class ){
             case '-': { math_class = `<num of math classes: 79`>;
                         pause_class++;  break; }
             case '+': { math_class = `<num of math classes: 79`>;
                         pause_class--;  break; }
              default: { math_class = 0; }
        } } else if( flag== 2 ) {
           switch( math_class ){
             case `<ignore sub dels ch`>: {
                math_class = `<ignore sub dels val`>;  break; }
             case `<end ignore sub dels ch`>:
                { math_class = `<end ignore sub dels val`>;   break; }
              default: { math_class = 0; }
           }    
        } else { math_class = 0; }
   }
   return math_class;
}  
>>>
   


\Section{Setting Requests}


\<header functions\><<<
static INTEGER set_ch_class( ARG_I(int) );
>>>

\<functions\><<<
`[ 
static  INTEGER set_ch_class(ch)    int ch
;{                              int r_ch;
   r_ch = ch - font_tbl[cur_fnt].char_f;
   if( math_class == `<math close`> ){
      store_bit_I( font_tbl[cur_fnt].math_closing, r_ch ); 
      *(font_tbl[cur_fnt].math + r_ch) =
              (char) ((open_del == 256)?  ch : open_del);
   } else {
      store_bit_Z( font_tbl[cur_fnt].math_closing, r_ch ); 
      *(font_tbl[cur_fnt].math + r_ch) = math_class;
   }
   open_del = ( math_class == `<math open`> )? ch : 256;      
   `<return char width`>
}
>>>

\<set-ch-class(ch-1)\><<<
set_ch_class(ch_1)
>>>



\<set config class dels\><<<
{                                    U_CHAR str[256], *p, ch, **q;
   math_class = scan_class(2);  ch = get_char();
   special_n -= 2;   p = str;
   while( special_n-- > 0 ){
      if(  (*(p++) = get_char()) == ch ){ p--; break; }
   }
   *p = '\0';
   q = (math_class > `<math classes 0..78`>)? &(`<push class del := ...`>)
                       : &(open_class[math_class]);
   *q = (char *)  r_alloc((void *) open_class[math_class],
                                 1 + (size_t) strlen((char *) str));
   (IGNORED) strcpy((char *) *q, (char *) str);
   q = (math_class > `<math classes 0..78`>) ? &(`<pop class del := ...`>)
                         :  &(close_class[math_class]);
   p = *q = (char *)  r_alloc((void *) *q,  1 + (size_t) special_n);
   while( special_n-- > 0 ){ *(p++) = get_char();  }
   *p = '\0';
   if( math_class > `<math classes 0..78`>){ `<next delimiters on group`> }
}
>>>


When  \`'math_class > max math class' is true, the delimiters are 
placed on the next group.  In such a case a math class of \`')' also
requests that no subdelimiter will be placed there.

\<header functions\><<<
static int math_class_of( ARG_II(int,int) );
>>>

\<functions\><<<
`[ 
static  int math_class_of(ch,cur_fnt)    int ch`; int cur_fnt
;{                           int math_class;
   math_class = ch - font_tbl[cur_fnt].char_f;
   return ((get_bit( font_tbl[cur_fnt].math_closing, math_class))?
                `<math close`> : *( math_class + font_tbl[cur_fnt].math));

}
>>>




\Section{Memory and Initialization}




\<vars\><<<
static U_CHAR *open_class[`<mems for math classes (79 + 2 )`>],
     *close_class[`<mems for math classes (79 + 2 )`>];
>>>

There are 79  characters in the range between the digit `0' and
the character \`'~'.

\<math classes 0..78\><<<
78
>>>

\<num of math classes: 79\><<<
79
>>>


The following should be characters below the digit `0' 

\<ignore sub dels ch\><<<
')'
>>>

\<end ignore sub dels ch\><<<
'('
>>>

\<ignore sub dels val\><<<
(`<num of math classes: 79`> + 1)
>>>

\<end ignore sub dels val\><<<
(`<num of math classes: 79`> + 2)
>>>


\<mems for math classes (79 + 2 )\><<<
82   `%one extra is needed?`%
>>>







\<main's init\><<<
for( math_class=0; math_class<`<num of math classes: 79`>; math_class++ ){
  open_class[math_class] = m_alloc(char, 1);
  close_class[math_class] = m_alloc(char, 1);
  *(open_class[math_class]) = *(close_class[math_class]) = '\0';
}
>>>




\<entries for math classes\><<<
char *math, *math_closing;
>>>

\<memory for math classes\><<<
new_font.math_closing = m_alloc(char, n_gif_bytes );
new_font.math = m_alloc(char, n_gif );
>>>


\<init math-closing\><<<
new_font.math_closing[i] =
>>>

\<init math\><<<
new_font.math[i] = 
>>>

\<merge math entries\><<<
free((void *)  new_font.math_closing );
           new_font.math_closing = font_tbl[ k ].math_closing;
free((void *)  new_font.math );
                           new_font.math = font_tbl[ k ].math;
>>>





\Section{Delimiters Over Next Group}

\SubSection{Requests}

  \`'\special{t4ht^ix}'--put delimiters of class i on next group/token.  If
{\tt x=`)'} ignore delimiters within the group.


\<class delimiters on group\><<<
special_n -= 2;   math_class = scan_class(0);   
stack[stack_n+1].ignore_subclass_del = 
   (`<ignore sub dels ch`> == get_char()); 
stack[stack_n+1].active_class_del = TRUE;
stack[stack_n+1].temp_class_del = FALSE;
stack[stack_n+1].no_left_del = TRUE;
stack[stack_n+1].class_open = open_class[math_class];
stack[stack_n+1].class_close = close_class[math_class];
>>>


  \`'\special{t4ht^)x*...*...}'--put the specified delimiters of
 class  on next group, instead of the default ones.
If {\tt x=`)'}, ignore delimiters within the group.




\<next delimiters on group\><<<
stack[stack_n+1].ignore_subclass_del = 
  (math_class == `<ignore sub dels val`>); 
stack[stack_n+1].temp_class_del = TRUE;
stack[stack_n+1].active_class_del = TRUE;
>>>



\<pop class del := ...\><<<
stack[stack_n+1].temp_class_close
>>>

\<push class del := ...\><<<
stack[stack_n+1].temp_class_open
>>>




\SubSection{Insertions}

\<add push class del\><<<
if( stack[stack_n].active_class_del ){
   if( show_class && !pause_class && !ignore_subclass_del ){
      `<print open del of group class`>
   }
   ignore_subclass_del =  ignore_subclass_del 
                        + stack[stack_n].ignore_subclass_del;
   stack[stack_n+1].no_left_del= FALSE;
}
>>>


\<add pop class del\><<<
if( stack[stack_n].active_class_del ){
   ignore_subclass_del =  ignore_subclass_del 
                        - stack[stack_n].ignore_subclass_del;
   if( show_class && !pause_class && !ignore_subclass_del ){   
      `<print right del of group class`>
   }
   stack[stack_n].active_class_del = FALSE;
}
>>>



\SubSection{Memory and Initialization}




\<struct stack_entry\><<<
char *class_open, *class_close, 
     *temp_class_open, *temp_class_close;
BOOL temp_class_del, ignore_subclass_del, active_class_del,
    no_left_del, sv_no_left_del;
>>>

The math class can be on a group or a token.  Upon reaching the
\''\special',  the \''no_left_del' is set to false.  Upon reaching to
the start of the next  group (not token), the flag is set to true.





\<initialized entries for grouping stack\><<<
stack[i].class_open = stack[i].class_close 
                    = (char *) 0;
stack[i].temp_class_open  = m_alloc(char, 1 );
stack[i].temp_class_close = m_alloc(char, 1 );
stack[i].ignore_subclass_del = stack[i].temp_class_del
                          = stack[i].active_class_del
                          = FALSE;
>>>


\Section{Delimiters Over Next Character}



\<left class delNO\><<<
if( show_class  && !pause_class && !ignore_subclass_del){ 
   if(stack[stack_n+1].no_left_del && stack[stack_n+1].active_class_del ){
       `<open del of group class on ch`>
   } else {
      math_class = math_class_of( ch, cur_fnt );
      (IGNORED) print_f( open_class[math_class]);
}  }
>>>


\<left class del\><<<
if( show_class  && !pause_class && !ignore_subclass_del){ 
   if( !stack[stack_n].no_left_del && stack[stack_n+1].active_class_del ){
      `<open del of group class on ch`>
      if( !stack[stack_n+1].ignore_subclass_del ){
         `<left del of class on ch`>
      }
   } else {
      `<left del of class on ch`>
}  }
>>>


\<left del of class on ch\><<<
math_class = math_class_of( ch, cur_fnt );
(IGNORED) print_f( open_class[math_class]);
>>>


The \`'stack[stack_n].no_left_del' is true if we have a request for
math delimiters on next group/token, and no left delimiter had 
been placed on a group.  

\<right class delNO\><<<
if( show_class && !pause_class && !ignore_subclass_del ){
   if(stack[stack_n+1].no_left_del && stack[stack_n+1].active_class_del ){
      `<right del of group class on ch`>
      stack[stack_n+1].active_class_del = FALSE;  
   } else {
      (IGNORED) print_f( close_class[math_class]); 
   }
}
>>>

\<right class del\><<<
if( show_class && !pause_class && !ignore_subclass_del ){
   if( !stack[stack_n].no_left_del && stack[stack_n+1].active_class_del ){
      if( !stack[stack_n+1].ignore_subclass_del ){
         `<right del of class on ch`>
      }
      `<right del of group class on ch`>
      stack[stack_n+1].active_class_del = FALSE;  
   } else {
      `<right del of class on ch`>
      stack[stack_n+1].active_class_del = FALSE;  `%%%%%%%%NEW%%%%`%
   }
}
>>>

\<right del of class on ch\><<<
(IGNORED) print_f( close_class[math_class]); 
>>>




\<print right del of group class\><<<
(IGNORED) print_f( (stack[stack_n].temp_class_del)?
                      stack[stack_n].temp_class_close
                   :  stack[stack_n].class_close);
>>>

\<right del of group class on ch\><<<
(IGNORED) print_f( (stack[stack_n+1].temp_class_del)?
                      stack[stack_n+1].temp_class_close
                   :  stack[stack_n+1].class_close);
>>>


\<print open del of group class\><<<
(IGNORED) print_f( (stack[stack_n].temp_class_del)?
                      stack[stack_n].temp_class_open
                   :  stack[stack_n].class_open);
>>>

\<open del of group class on ch\><<<
(IGNORED) print_f( (stack[stack_n+1].temp_class_del)?
                      stack[stack_n+1].temp_class_open
                   :  stack[stack_n+1].class_open);
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Files and Directories}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Environment File (tex4ht.env)}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



\List{1}
\item   Try the file given by the -e switch of tex4ht command.
\item   Search the current directory for one (i.e., open "tex4ht.env").
\item   Search the program's directory  (dos/w32)
\item   Home directory (\`'~` unix; \`'C:' dos/w32)
\item   Compiled directory within ENVFILE
\EndList


First character is a flag character to be consistent with command line
options. Undefined flags signal comment lines.





Search along the path: command line file $\rightarrow$ work
directory $\rightarrow$ home directory $\rightarrow$ system file.

\<get .env directory from com ln\><<<
tex4ht_env_file = p+2; 
>>>


% if( !access(p+2,F_OK) ) tex4ht_env_file = p+2; 
% else warn_i_str(12,p+2);


\<main's vars\><<<
char* tex4ht_env_file = (char *) 0;
char* dos_env_file =
#if defined(__MSDOS__)
  `<get dos env file`>;
#endif
#if !defined(__MSDOS__)
  (char *) 0;
#endif

>>>


In dos we can't have file names consisted only of the extension
\`'.tex4ht', let alone the length of the extension.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{General}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




\<vars\><<<
static BOOL dump_env_search = FALSE;
>>>

\<trace env search\><<<
dump_env_search = TRUE;
>>>

\<find tex4ht.env\><<<
{                              U_CHAR  str[PATH_MAX],  *TEX4HTENV;
   `<env file from command switch`>
   `<env file at work dir`>
   if( !dot_file ){                
     `<TEX4HTENV env`>
   }
   `<env file at root dir`>
   `<ENVFILE env`>
   `<env from prog dir`>
   `<kpathsea env file`>
   if( !dot_file ) { bad_in_file(`<warn 1`>); } /* give up if no tex4ht.env */
}
>>>




\<env file from command switch\><<<
if( dump_env_search && tex4ht_env_file ){
   (IGNORED) printf("-e: %s?\n", tex4ht_env_file);
}
dot_file = tex4ht_env_file?
   f_open_pathed_filename( tex4ht_env_file, READ_TEXT_FLAGS ) : NULL;   
>>>





\<env file at root dir\><<<
if( !dot_file ){                
   if( HOME_DIR ){
      (IGNORED) sprintf(str,`<"s/tex4ht.env"`>, HOME_DIR);
      if( dump_env_search ){ (IGNORED) printf("%s?\n", str); }
      dot_file = f_open(str,READ_TEXT_FLAGS);     
}  }
#ifndef DOS_WIN32
   if( !dot_file ){        
     if( HOME_DIR ){ 
        (IGNORED) sprintf(str,"%s/.tex4ht", HOME_DIR);   
        if( dump_env_search ){ (IGNORED) printf("%s?\n", str); }
        dot_file = f_open(str,READ_TEXT_FLAGS);     
   } }
#endif
#if defined(__MSDOS__)
   if( !dot_file ){                      
      if( dump_env_search ){ (IGNORED) printf("%s?\n", "C:/tex4ht.env"); }
      dot_file = f_open("C:/tex4ht.env",READ_TEXT_FLAGS);     
   }
#endif
>>>




\<env from prog dir\><<<
if( !dot_file && dos_env_file){
   if( dump_env_search ){ (IGNORED) printf("%s?\n", dos_env_file); }
   dot_file = f_open( dos_env_file, READ_TEXT_FLAGS ); 
}
>>>

\<env file at work dir\><<<
if( !dot_file ){
   if( dump_env_search ){ (IGNORED) printf("%s?\n", "tex4ht.env"); }
   dot_file = f_open("tex4ht.env", READ_TEXT_FLAGS);
}
#ifndef DOS_WIN32
   if( !dot_file ){      
      if( dump_env_search ){ (IGNORED) printf("%s?\n", ".tex4ht"); }
      dot_file = f_open(".tex4ht", READ_TEXT_FLAGS);
      if( dot_file ){
         printf("(%s)\n", ".tex4ht"); 
   }  }
#endif   
>>>


\<ENVFILE env\><<<
#ifdef ENVFILE
   if( !dot_file ){
      if( dump_env_search ){ (IGNORED) printf("ENVFILE: %s?\n", ENVFILE); }
      dot_file = f_open_pathed_filename( ENVFILE,READ_TEXT_FLAGS);
   }
#else
   if( dump_env_search ){
        (IGNORED) printf("tex4ht compiled without ENVFILE\n"); 
   }
#endif
>>>

\<TEX4HTENV env\><<<
TEX4HTENV = getenv("TEX4HTENV");
if( TEX4HTENV ){ 
   if( dump_env_search ){
        (IGNORED) printf("TEX4HTENV: %s?\n", TEX4HTENV); }
   dot_file = f_open_pathed_filename(TEX4HTENV,READ_TEXT_FLAGS); 
} else {
   if( dump_env_search ){
        (IGNORED) printf("getenv(\"TEX4HTENV\")=\n"); 
}  }
>>>

\<h-defines\><<<
#ifndef ENVFILE

#endif
>>>


\<"s/tex4ht.env"\><<<
#if defined(__DJGPP__)
  is_forward_slash(HOME_DIR)?  "%s/tex4ht.env" :  "%s\\tex4ht.env"
#else
  "%s/tex4ht.env"
#endif
>>>



\<warn 1\><<<
#ifdef  DOS_WIN32
   "tex4ht.env"
#else
   "tex4ht.env | .tex4ht" 
#endif
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{For Dos}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



  One last remark about the source: I have implemented a routine that
changes the functionality of searching for tex4ht.env a bit. DOS
organises programs differently than Unix; it is convention to place the
program and all related files, including configuration files, in a
dedicated directory. In addition, DOS (being single-user) doesn't have
home directories. Knowing this, the best way to find the tex4ht.env file
is:

\List{1}
\item   Search the current directory for one (i.e., open "tex4ht.env").
\item   Search the program's directory
\item   Give up (no point in checking the root directory).
\EndList

  Under DOS, argv[0] usually includes the full path to the program -
even if it wasn't typed in. This can be used to find the program's own
directory, and hence the configuration file. I've implemented this
already as follows:

\<get dos env file\><<<
get_env_dir(argv[0])
>>>

\<functions\><<<
#if defined(__MSDOS__)
`<get tex4ht.env in dos`>
#endif
>>>




\<get tex4ht.env in dos\><<<
`[
static char *get_env_dir(progname) 
      U_CHAR *progname

;{    int  i;
      U_CHAR *p;
  if(! progname || ! *progname)  return NULL;               `% Safety `%
  i = (int) strlen((char *) progname);
  while( (progname[--i] != (int) dir_path_slash(progname) )
          && (i > 0) ) ;                              `%Search for dir`%
  if(i == 0)  return NULL;                        `%Not found? Give up`%
  p = (char *) malloc(i+12);
  if(p == NULL)  return NULL;      `%Space for new extention after dot`%
  strncpy(p, progname, i+1);                        `%Copy up to slash`%
  (IGNORED) strcpy((char *) &p[i+1], "tex4ht.env"); `%Append new extention`%
  return p;
}
>>>

The 12 above is for accomodating \''tex4ht.env'.




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Get Script}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Options

\List{}
\item{s}
Block of lines
starting with the same
character: s (set
format of 
script commands), e.g., \`'s--- needs --- %%1.idv[%%2] ==> %%3 ---'
\item{b} Begin-of-characters/end-of-figures  comment, e.g., \`'b--- characters ---'
\item{g} Gif extension, e.g., \`'g.gif'
\item{a} Font alias, e.g., \`'acmtex cmtt'
\item{t} Directory of tfm fonts, e.g., \`'t/n/candy/0/tex/teTeX/texmf/fonts/tfm/!'
\item{i} Directory of htf fonts, e.g., \`'i/n/gold/5/gurari/tex4ht.dir/
  i/n/gold/5/gurari/tex4ht.dir/ht-fonts/iso88591/!'.
\EndList


Priority (the easier to change, the higher in priority).

\List{disk}
\item   Command line
\item  Environment File
\item Hard coded in program
\EndList

\<header functions\><<<
static char* get_script( ARG_III(char *, const U_CHAR *, int) );
>>>

\<functions\><<<
`[
static char* get_script(name, inln,x) 
     char * name`;
     const U_CHAR * inln`;
     int x

;{
   if( !name )
   {                U_CHAR  str[256], *ch;
      (IGNORED) fseek(dot_file, 0L, `<abs file addr`>);
      if( search_dot_file( x ) ){
           `<read x-script from dot file`>
      } else  {(IGNORED)  strcpy((char *) str, inln); }
      ch = m_alloc(char, (int) strlen((char *) str)+2);
      (IGNORED) strcpy((char *) ch, (char *) str);
      return ch;
   }else return name;
}
>>>
   
We allocate extra character for possible addition of \`'%'
at end of string.   

\<read x-script from dot file\><<<
ch = str;  str[254] = '\0';
do{                                       int int_ch;
  while((*(ch++) = (char)
                        (int_ch = (int) getc(dot_file))
        )       != '\n'){
    if( int_ch == EOF ){ *(ch-1)='\n';  break; }    
    if( str[254] ){ warn_i_int(33, x);  break; }
  }
}while( (int) getc(dot_file) == x );
*ch = '\0';
>>>

The     \`'if( *(ch-1) == EOF ){...}'
is for the case that the last line not terminates with a return.

%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Search Env File}
%%%%%%%%%%%%%%%%%%%%%%%%%



\<header functions\><<<
static BOOL search_dot_file( ARG_I( int) );
>>>

\<functions\><<<
`[
static BOOL search_dot_file( ch ) 
    int ch
;{  int chr;

  while( TRUE ){
    chr = getc(dot_file);
    if( chr == ch ){ return TRUE; }
    if( chr == '<' ) {
      `<skip non -c env segments`>
      continue;
    } 
    if( chr == '\n' ){ continue; }
    do 
       if( chr == EOF ) return FALSE;
    while( (chr = getc(dot_file)) != '\n' );
} }
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%  *p, 

\<skip non -c env segments\><<<
                         U_CHAR match[256];
                         int i;
for( i = 0; (chr != '\n') && (chr != EOF ) ; i++){
  chr = (int) getc(dot_file);
  match[i] = (U_CHAR) chr;
}
match[i-1] = '\0';
if( match[0] != '/' ){
                         BOOL env_skip;     
  for( i = 0;
       (match[i] != '>') && (match[i] != '\n') && (match[i] != EOF );
       i++){}
  if( match[i] == '>' ){  match[i] = '\0'; }
  `<env-skip = skip segment match[1]`>
  if( env_skip ){
     `<skip env segment`>
} }
>>>

\<skip env segment\><<<
                         U_CHAR cur_block[90];                         
                         BOOL status;
(IGNORED) strcpy((char *)  cur_block, (char *) match);
status = FALSE;
while( !status && (chr != EOF) ){
  chr = 'x';
  for( i = 0; (chr != '\n') && (chr != EOF ) ; i++){
    chr = (int) getc(dot_file);
    match[i] = (U_CHAR) chr;
  }
  match[i-1] = '\0';
  for(i=0; match[i]!='\0'; i++){
    if( match[i] == '>' ){ break; }
  }
  if( (match[0] == '<') && (match[1] == '/') 
                        && (match[i] == '>') ){
    match[i]='\0'; 
    status = eq_str(match+2, cur_block); 
  } else { status = FALSE; }
}
>>>





\<defines\><<<
struct env_c_rec{
  char *option;
  struct env_c_rec  *next;
};
>>>

\<vars\><<<
static struct env_c_rec *envChoice
       = (struct env_c_rec*) 0;
>>>


\<env blocks selector\><<<
struct env_c_rec *temp = (struct env_c_rec*)
                   m_alloc(struct env_c_rec, (int) 1);
temp->option = p+2;
temp->next = envChoice;
envChoice = temp;
>>>

\<env-skip = skip segment match[1]\><<<
if( envChoice == (struct env_c_rec*) 0  ){
  env_skip = !eq_str(match, "default" );
} else {
               struct env_c_rec *p;
  env_skip = TRUE;
  for( p=envChoice; p!=(struct env_c_rec*) 0 ; p = p->next ){
    if( eq_str(match, p->option ) ){ env_skip = FALSE; }
} }
>>>





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Locating the TFM Fonts}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



Flag `t' identifies font directories.
Command line (can be multiple) $\rightarrow$ work directory
$\rightarrow$ dot file  $\rightarrow$ system directory.



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Command Line Options}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 

\List{*}
\item Specifying multiple directories is possible; paths are separated
    with ':' under Unix, ';' under DOS. (This isn't really important
    perhaps, but it seems a nice feature).

Instead of concatenated directories we allow multiple ones.

\item If a path specification ends in a '!', it's subdirectories are
    searched too, else only the specified dir is searched. (This is the
    way many TeX installations seem to do it, too).
\EndList



\<get tfm font dir from com ln\><<<
com_dir(p);  fontdir[fontdir_count++] = p+2;
>>>

The \`'access' function returns 0 if the path is fine; -1 for error.



\<vars\><<<
static U_CHAR  *fontdir[MAXFDIRS];
static int fontdir_count = 0;
>>>

What the use of the following? Do we wants to make it h-defines.

\<defines\><<<
#ifndef MAXFDIRS
#define MAXFDIRS 100
#endif
>>>

 Also, check how many directories and fonts are
used. \`'tex4ht.log'  claims 55 fonts with 255 as limit.


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{The Search}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\''      struct cache_font_rec *cur_cache_font; '?

\<search dirs for font\><<<
{                        `%   int  i; `%
   font_file = NULL;
   (IGNORED) sprintf(file_name, "%s.tfm", new_font_name);
   `<if kpathsea tfm files else`>
      `<search font in cache dirs`>
      if( !font_file ){                                     int  i;
         for( i = fontdir_count; i--; ){
           if( (font_file =  search_file_base(file_name, fontdir[i],
                                         READ_BIN_FLAGS, tfm_dirs))
               != NULL )  break;  }
      }
      if( !font_file ) font_file = f_open(file_name, READ_BIN_FLAGS);
      if( !font_file && dot_file )
          font_file = search_in_dot_file( 't', file_name, 
                        READ_BIN_FLAGS, tfm_dirs);
      `<search TFMDIR`>
   `<endif kpathsea tfm files`>
}
>>>





KPATHSEA has a database LS-R which corresponds to a \`'ls -R *'
listing of files and the directories including them.  This allow for a
quick search of files within the image of the directory stored within
the database, instead of live search in the directories themselve which
consume disk access time.


\<search TFMDIR\><<<
#ifdef TFMDIR
   if( !font_file )   
      font_file = search_file_base(file_name, TFMDIR, 
                               READ_BIN_FLAGS, tfm_dirs);
#endif
>>>

\<h-defines\><<<
#ifndef TFMDIR

#endif
>>>



\SubSection{Get Font Env Variables}


The environment variables, if defined, hold a sequence of directory
names.  Each directory name can be an absolute address, or relative to
the home directory (signaled by the prefix \`'~').  The directories must be separated by a distinguished character, which must also act as delimiter at the start and the end of the string.


\<check env font variables\><<<
#ifndef KPATHSEA
tfm_dirs = get_env_var("TEX4HTTFM");
#endif
htf_dirs = get_env_var("TEX4HTHTF");
>>>






\<header functions\><<<
static struct env_var_rec * get_env_var( ARG_I(const char *) );
>>>

\<functions\><<<
`[
static struct env_var_rec * get_env_var( env_var ) 
    const char *env_var
;{                U_CHAR   *TEX4HTTFM,  *from;
                  struct env_var_rec *tfm_dirs, *p;
                  int env_var_len;
   tfm_dirs = (struct  env_var_rec *) 0;
   TEX4HTTFM = getenv( env_var );
   if( TEX4HTTFM ){    
      env_var_len = (int) strlen((char *) TEX4HTTFM);
      if ( *TEX4HTTFM == *(TEX4HTTFM + env_var_len - 1 ) ){
         from = TEX4HTTFM + env_var_len - 1;
         *from = '\0'; 
         do{                             
           from--;
           if( *from == *TEX4HTTFM ){   char * base;
              *from = '\0'; 
              base = from + 1;
             `<verify env var dir`>
             if( base ){
               `<add env var dir`>        
           } }
         } while (from > TEX4HTTFM );
      } else {  warn_i_str2( 49, env_var, TEX4HTTFM); }
    }
    return tfm_dirs;
}
>>>

We preseve the order of the directories founnd in the environment
variables.


\<add env var dir\><<<
p = m_alloc(struct env_var_rec, 1);
p->next = tfm_dirs;
p->base = base; 
tfm_dirs = p;
>>>


\<verify env var dir\><<<
{                         U_CHAR *str;
  if( *(from+1) == '~' ){
     if( HOME_DIR ){ 
         str = m_alloc(char, strlen((char *) HOME_DIR)+strlen((char *) base));
         (IGNORED) sprintf(str,"%s%s", HOME_DIR, base+1);
         if( access(str,F_OK) ) {
            warn_i_str2(49, env_var, str); base = NULL; }
         free((void *)  str);
     } else { 
         if( access(base,F_OK) ) {
            warn_i_str2(49, env_var, base); base = NULL; }
     }
   } else {    
     if( access(base,F_OK) )  { 
        warn_i_str2(49, env_var, base); base = NULL; }
}  }
>>>




\<scan fonts vars\><<<
#ifndef KPATHSEA
struct env_var_rec *tfm_dirs;
#endif
struct env_var_rec *htf_dirs;
>>>

\<types\><<<
struct env_var_rec{  char* base;
                     struct env_var_rec *next;     };
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Cache Directories}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




\<search font in cache dirs\><<<
for( cur_cache_font = cache_font; 
     cur_cache_font;
     cur_cache_font = cur_cache_font->next )
  if( (font_file = search_file(file_name,
                               cur_cache_font->dir,
                               READ_BIN_FLAGS)) 
      != NULL)  break;
>>>




\<put dir in cache\><<<
{     int found;
   found = FALSE;
   for( cur_cache_font = cache_font; 
        cur_cache_font;
        cur_cache_font = cur_cache_font->next )
   { found = found || eq_str(cur_cache_font->dir, dir ) ; 
     if( found ) break;  }
   if( !found ){
      cur_cache_font = m_alloc(struct cache_font_rec, 1);
      `<init new cache list`>
      cur_cache_font->dir = m_alloc(char, n+1);
      (IGNORED) strcpy((char *) cur_cache_font->dir, dir);
      if( !cache_font ){
         cur_cache_font->next = cache_font;
         cache_font = cur_cache_font;
      } else if ( gt_str(cache_font->dir, dir) ) {
         cur_cache_font->next = cache_font;
         cache_font = cur_cache_font;
      } else {
                            struct cache_font_rec *  after_cache_font;
         after_cache_font = cache_font;
         while( after_cache_font->next ){
           if ( gt_str(after_cache_font->next->dir, dir) ) { break; }
           after_cache_font = after_cache_font->next;
         }
         cur_cache_font->next = after_cache_font->next;
         after_cache_font->next = cur_cache_font;
}  }  }
>>>





\<free html font memory\><<<
while( (cur_cache_font = cache_font) != (struct cache_font_rec *)0 ){
   cache_font = cache_font->next;
   free((void *) cur_cache_font->dir ); 
   free((void *) cur_cache_font );        }
>>>


\<vars\><<<
static struct cache_font_rec *cache_font,  *cur_cache_font;
>>>

\<init scan fonts vars\><<<
cache_font = (struct cache_font_rec *) 0;
cur_cache_font = (struct cache_font_rec *) 0;
>>>

\<types\><<<
struct cache_font_rec{  char* dir;
                        struct cache_file_rec * cache_file;
                        struct cache_font_rec* next;     };
struct cache_file_rec{  struct cache_file_rec* next;
                        U_CHAR *                 file;     };
>>>



\SubSection{Default Built-In During Compilation}

  On my HP the standard
TeX fonts are in the directory
%\Link[/usr/local/tex/lib/texmf/fonts/public/cm/tfm/]{}%
\Link[/usr/local/tex/lib/texmf/fonts/public/cm/tfm/]{}{}%
         /usr/local/tex/lib/texmf/fonts/public/cm/tfm/\EndLink,  
and the standard latex fonts are in
\Link[/usr/local/tex/lib/texmf/fonts/public/latex/tfm/]{}{}%
         /usr/local/tex/lib/texmf/fonts/public/latex/tfm/\EndLink,  
on my SUN  the directory is ???.


We also might want to put the current directory in.




The function \`'int access(const U_CHAR *pathname, int mode)', and the mode
\`'F_OK' that tests for the existence of file, are defined in the
following directory. The function returns 0 if ok and -1 on error .

Where access comes from in dos?  in \''<io.h>'

\<h-include\><<<
#ifndef F_OK
#ifdef DOS_WIN32
#define  F_OK 0               `% does file exist `%
#endif
#ifndef KPATHSEA  
#ifndef DOS_WIN32
#define HAVE_UNISTD_H
#endif
#endif
#endif
#ifdef HAVE_IO_H
#include <io.h>
#endif
#ifndef KPATHSEA  
#ifdef HAVE_UNISTD_H
#include <unistd.h>    
#endif
#endif
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Htf Font Files}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

Search along the path: 
command line switch 'i' directory $\rightarrow$ 
work directory $\rightarrow$ directories specified in tex4ht.env
(switch 'i' and aliased 'a') $\rightarrow$ system directory 
specified in HTFDIR. \ifHtml[\HPage{more}\Verbatim

 > This I think leads to a problem  in the parsing of ht-font
 > information (the ``a'' lines in the .env file): according to your rules, only
 > the first setting takes effect.  So of t4ht has previsouly fou nd and read
                                          ^^^^
                                          tex4ht
 > a tex4ht.env file, then the upshot is that the user's ``a'' section doesn't
 > override the default.  At least this is what I think must be happening
 > based on some experiments I'm doing with a custom .env file.

The search for the htf files should be along the following route

   in the directories stated within `-i' switches of the tex4ht command line
   in the work directory
   in the directories specified within `i' records of the env file
   in a directory compiled into tex4ht during its compilation

The search for the env file should be along the following route

   in the file stated within the `-e' switch of the tex4ht command line
   in the work directory
   in the home directory (~-unix; C:-dos/win)
   in a directory compiled into tex4ht during its compilation
\EndVerbatim\EndHPage{}]\fi






\<file = .htf file\><<<
{                              U_CHAR name[256];
   (IGNORED) sprintf(name, "%s.htf", new_font_name);
   `<search file in htf locations`>
   if( file ){ `<check name decomposition`> }
}
>>>


\<search file in htf locations\><<<
   file = NULL;
   `<search htf font along cmd switches`>
   if( !file ){
      if( ((file = f_open(name, READ_TEXT_FLAGS)) == NULL) && dot_file )
         file = search_in_dot_file( 'i', name, READ_TEXT_FLAGS, htf_dirs);
#ifdef HTFDIR
      if( !file )  file = search_file_base(name, HTFDIR, 
                                               READ_TEXT_FLAGS, htf_dirs);
#endif
      `<file = kpathsea .htf file`>
   }  
>>>




\<types\><<<
struct htf_com_rec{  char* name;
                     struct htf_com_rec* next;     };
>>>

\<main's vars\><<<
struct htf_com_rec* htf_font_dir = (struct htf_com_rec *) 0;
>>>

\<get htf font dir from com ln\><<<
   com_dir(p);
   {
                         struct htf_com_rec *q, *t;
   q = m_alloc( struct htf_com_rec, 1);
   q->name = p+2;
   q->next = (struct htf_com_rec *) 0;
   if(  htf_font_dir ){
     t = htf_font_dir;
     while( t->next ){ t = t->next; }
     t->next = q;
   } else {
     htf_font_dir = q;
   }
}
>>>




\<header functions\><<<
static void com_dir( ARG_I(char*) );
>>>

\<functions\><<<
`[ 
static void com_dir(p)
     char* p
;{   int i;   U_CHAR   str[256];
  (IGNORED) strcpy((char *)  str, (char *) p+2 );
  i = (int) strlen((char *) str) - 1;
  if( str[i] == '!' )  str[i] = '\0'; 
}
>>>

%   if( !access(str,F_OK) ) return TRUE;
%  warn_i_str(12,p+2);     return FALSE;





\<search htf font along cmd switches\><<<
{
                               struct htf_com_rec *p;
   p = htf_font_dir;
   while( p ){
      file =  search_file_base(name, p->name, READ_TEXT_FLAGS, htf_dirs);
      if( file ){ 
#ifndef KPATHSEA
         tex4ht_fls = TRUE;
#endif   
         break;
      }
      p = p->next;
   }
}
>>>



\<h-defines\><<<
#ifndef HTFDIR

#endif
>>>

Example \`' #define HTFDIR "/n/gold/5/gurari/tex4ht-fonts.dir/"'






%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{External File Cache}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




\<init new cache list\><<<
cur_cache_font->cache_file = (struct cache_file_rec *) 0;
>>>

\<store filename in cache\><<<
{
             struct cache_file_rec *file_rec, *prev_file_rec;
  prev_file_rec = (struct cache_file_rec *) 0;
  file_rec = cur_cache_font->cache_file;
  while( file_rec ) {
    if( !gt_str(name,file_rec->file) ) break;
    prev_file_rec = file_rec;
    file_rec = file_rec->next;
  }
  {
                         struct cache_file_rec * file_entry;
                         BOOL flag;
    flag = TRUE;
    if( file_rec ) {
      if( eq_str(name,file_rec->file) ){ flag = FALSE; } 
    }
    if( flag ) {
      `<insert file name`>
    }
  } 
}
>>>


\<insert file name\><<<
file_entry = m_alloc(struct cache_file_rec, 1);
file_entry->file = m_alloc(char, strlen(name)+1);
(IGNORED) strcpy((char *) file_entry->file, name);
if( ! cur_cache_font->cache_file ){
  cur_cache_font->cache_file = file_entry;
 file_entry->next = (struct cache_file_rec *) 0;
} else if( !prev_file_rec ){
   file_entry->next = cur_cache_font->cache_file;
   cur_cache_font->cache_file = file_entry;
} else {
   file_entry->next = prev_file_rec->next;
   prev_file_rec->next = file_entry;
}
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Search File in Aux Cache from dot directories}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


The cache file holds directory names and file names.  Directory names 
are preceded by a space, and file names start at column one.

\Verbatim
 /usr/local/share/texmf/tex4ht/ht-fonts/iso8859/1/ae 
ae.htf 
aecsc.htf 
 /usr/local/share/texmf/tex4ht/ht-fonts/iso8859/1/cm 
cmcsc.htf 
cmr.htf 
 /usr/local/share/texmf/tex4ht/ht-fonts/unicode/cm 
cmmi.htf 
\EndVerbatim


We traverse the auxiliary cache file, recording on the way the last
found directory. Upon finding a match on file name, we check the last
recorded directory against the directories mentioned in the
environment file.  If a match is found also there, we 
open the appropriate file.


\<search font in cache files\><<<      
                 U_CHAR cache_dir[256], dot_dir[256], *p, *q;
                 BOOL flag;
                 int  n,  ch;
(IGNORED) fseek(cache_files, 0L, `<abs file addr`>);
ch = (int) getc(cache_files);
while ( ch != EOF ){                     
  if ( ch == ' ' ) { `<cache-dir = cache record`> }
  else { `<flag = (file == cache record)`>
    if( flag ){
       `<flag = (cache-dir == env-dir)`>
       if( flag ){ `<open file and, if success, return`> }
  } }
  if ( ch != EOF ){ ch = (int) getc(cache_files); }
}
>>>

\<cache-dir = cache record\><<<
q = cache_dir;
do
  *(q++) = ch = (int) getc(cache_files); 
while( (ch !='\n') && (ch != EOF) );
*(q-1 - (*(q-2) == `<directory '/'`>) 
#ifdef DOS_WIN32
      - (*(q-2) == '/') 
#endif
 ) = '\0';
>>>

\<flag = (file == cache record)\><<<
p = name;  flag = FALSE;
while( *(p++) == ch ){
  ch = (int) getc(cache_files); 
}
if( (*(p-1) == '\0') && ((ch == '\n') || (ch == EOF)) ){ flag = TRUE; }
else{ 
  while( (ch != '\n') && (ch != EOF) ) {  ch = (int) getc(cache_files); }
}
>>>

\<flag = (cache-dir == env-dir)\><<<
flag = FALSE;
(IGNORED) fseek(dot_file, 0L, `<abs file addr`>);
while( search_dot_file( typ ) && !flag ){        U_CHAR *q, save_ch;
                                                 int  n, m;
  q = dot_dir; 
  do
     *(q++) = ch = (int) getc(dot_file); 
  while( (ch !='\n') && (ch != EOF) );
  flag = *(q - 2) = '!'; 
  q -= (flag? 2 : 1);
  *(q - (*(q-1) == `<directory '/'`>)
#ifdef DOS_WIN32
      - (*(q-1) == '/')
#endif
   ) = '\0'; 
  if( (n = strlen((char *) dot_dir)) > (m = strlen((char *) cache_dir)) ){ flag = FALSE; }
  else {
    save_ch = *(cache_dir + n);
    *(cache_dir + n) = '\0';
    flag = eq_str(dot_dir,cache_dir) && ( flag || (m == n) );
    *(cache_dir + n) = save_ch;
  }
}
>>>

\<open file and, if success, return\><<<
n = (int) strlen((char *) cache_dir);
cache_dir[n] = dir_path_slash(cache_dir);
cache_dir[n+1] = '\0'; 
(IGNORED) strcat((char *) cache_dir, (char *) name);
>>>

\<BROKEN\><<<
if( (file = f_open(cache_dir,flags)) == NULL ) {
   warn_i_str( 47, cache_dir);
} else {
   return file;
}
>>>



\SubSection{Store New Auxiliary Cache}


\<set new cache file\><<<
if( tex4ht_fls ){
               FILE *in_file, *out_file;
               U_CHAR temp_file[256];
   `<set temp file`>
   `<backup cache file`>
   if( (out_file = fopen(tex4ht_fls_name, WRITE_TEXT_FLAGS)) == NULL )
   {  bad_in_file(tex4ht_fls_name);
   } else {
      if( (in_file = fopen(temp_file, READ_TEXT_FLAGS)) != NULL ){ 
        `<output into new cache`>
        (IGNORED) fclose(in_file);  
      }
      (IGNORED) fclose(out_file);  
}  }
>>>





\<set temp file\><<<
(IGNORED) strcpy((char *) temp_file, (char *) job_name);
temp_file[job_name_n] = '\0';
temp_file[job_name_n-1] = 'p';
temp_file[job_name_n-2] = 'm';
temp_file[job_name_n-3] = 't';
>>>







\<vars\><<<
#ifndef KPATHSEA
static BOOL tex4ht_fls = FALSE;
static char *tex4ht_fls_name = (char *) 0;
#endif
>>>

\<cat /\><<<
#if defined(DOS_WIN32) || defined(__DJGPP__)
  (is_forward_slash(files_cache)?  "/" : "\\" )
#else
  "/"
#endif
>>>

\<get dir of tex4ht.fls\><<<
{                    U_CHAR *p;
   if( !tex4ht_fls_name ){
      tex4ht_fls_name = p = files_cache;
      (IGNORED) fseek(dot_file, 0L, `<abs file addr`>);         
      if ( search_dot_file( 'l' ) ){
        do
           *(p++) = ch = (int) getc(dot_file); 
        while( (ch !='\n') && (ch != EOF) );
        p--;       *p = '\0';
      } else { (IGNORED) strcpy((char *) p,
(char *)           getenv("TEX4HTWR")?  "~~/tex4ht.fls" : "tex4ht.fls"); 
      }      
   }
   `<relative tex4ht.fls addr`>
}
>>>


\<relative tex4ht.fls addr\><<<
if( *tex4ht_fls_name == '~' ){
   tex4ht_fls_name = abs_addr(tex4ht_fls_name,getenv("TEX4HTWR"));
} 
>>>



\<relative tex4ht.fls addrNO\><<<
if( *tex4ht_fls_name == '~' ){
                  `<fls temp var`>
   if( HOME_DIR ){  
      (IGNORED) strcpy((char *) p, (char *) tex4ht_fls_name+1); 
      (IGNORED) sprintf(files_cache,"%s%s", HOME_DIR, p);
   } else { 
      (IGNORED) strcpy((char *) files_cache, "tex4ht.fls"); 
   } 
   tex4ht_fls_name = files_cache;
} 
>>>

\<fls var\><<<
U_CHAR files_cache[PATH_MAX];
>>>

\<fls temp var\><<<
U_CHAR p[PATH_MAX];
>>>

\<vars\><<<
static U_CHAR *HOME_DIR;
>>>

\<main's init\><<<
HOME_DIR = getenv("HOME");
>>>

We might want more than one version of \`'tex4ht.fls', for different
combinations of  subtrees of htf fonts.  

\<get tex4ht.fls from com ln\><<<
#ifndef KPATHSEA
tex4ht_fls_name = p+2; 
#endif
>>>



\<backup cache file\><<<
if( (out_file = fopen(temp_file, WRITE_TEXT_FLAGS)) == NULL )
{   bad_in_file(temp_file);
} else {
   if( (in_file = fopen(tex4ht_fls_name, READ_TEXT_FLAGS)) != NULL ){  
                                                      int ch;
      while( (ch = getc(in_file)) != EOF ) {
         (IGNORED) putc( ch, out_file );
      }
      (IGNORED) fclose(in_file); 
   }
   (IGNORED) fclose(out_file);  
}   
>>>
   

\<output into new cache\><<<
              U_CHAR dir[255], prev_dir[255], file[255], *p;
              int ch;
              BOOL is_dir;
              struct cache_file_rec *file_rec, *prev_file_rec;
cur_cache_font = cache_font;
ch = 'n';  prev_dir[0] = '\0';
while( ch != EOF ){
   ch = getc(in_file);
   is_dir = (ch == ' ');
   p = is_dir? dir : file; 
   while( ch != '\n' ) {
     if( ch == EOF ) break;
     if( ch != ' ' ) { *p++ = ch; }
     ch = getc(in_file);
   }
   *p = '\0';
   if( is_dir && (dir[0] != '\0') ){
      `<output smaller internal directories`> 
      (IGNORED) fprintf(out_file," %s\n", dir);
      (IGNORED) strcpy((char *) prev_dir, (char *) dir);
   } else if( !is_dir && (file[0] != '\0') ){
      `<output smaller internal files`> 
      (IGNORED) fprintf(out_file,"%s\n", file);
   }
}
`<output remainder of internal cache`>
>>>


\<output smaller internal directories\><<<
while( cur_cache_font != (struct cache_font_rec *)0 ){
 if( gt_str(dir,cur_cache_font->dir) ){
    `<cache directory in external memory`>
 } else break;
 cur_cache_font = cur_cache_font->next;
}
>>>


\<cache directory in external memory\><<<
file_rec = cur_cache_font->cache_file;
if( file_rec ){
   if( !eq_str( prev_dir, cur_cache_font->dir) ){
      (IGNORED) fprintf(out_file, " %s\n", cur_cache_font->dir);
      (IGNORED) strcpy((char *) prev_dir, (char *) dir);
   }
   cur_cache_font->cache_file = (struct cache_file_rec *) 0;
   while( file_rec ) {
     prev_file_rec = file_rec;
     file_rec = file_rec->next;
     (IGNORED) fprintf(out_file, "%s\n",  prev_file_rec->file);
     free((void *) prev_file_rec );        
   }
}
>>>




\<output smaller internal files\><<<
if( cur_cache_font != (struct cache_font_rec *)0 ){
 if( eq_str(dir,cur_cache_font->dir) ){
    file_rec = cur_cache_font->cache_file;
    while( file_rec ) {
      if( gt_str(file_rec->file,file) ){ break; }
      else if( gt_str(file,file_rec->file) ){ 
          (IGNORED) fprintf(out_file, "%s\n", file_rec->file);
      }
      prev_file_rec = file_rec;
      file_rec = file_rec->next;
      free((void *) prev_file_rec );        
    }
    cur_cache_font->cache_file = file_rec;
 } 
}
>>>



\<output remainder of internal cache\><<<
while( cur_cache_font != (struct cache_font_rec *)0 ){
   `<cache directory in external memory`>
   cur_cache_font = cur_cache_font->next;        
}
>>>








\<vars\><<<
#ifndef KPATHSEA
static FILE* cache_files;
#endif   
>>>

\<open old cache file\><<<
cache_files = f_open(tex4ht_fls_name, READ_BIN_FLAGS);
>>>

\<close old cache file\><<<
if( cache_files != (FILE *) 0 ){  (IGNORED) fclose(cache_files); }
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Export TEX4HTFONTSET for kpathsea}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Background}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%






A system call similar to \`'TEX4HTFONTSET={...}; export TEX4HTFONTSET'
is issued for ordering searches of htf fonts by kpathsea.


The system call assumes a pattern of the form \`'.....%%12...'
in the argument -DTEX4HTFONTSET provided to the compilation of tex4ht.
If none is provided, a default pattern is assumed.  

To allow also opposite order of search, the
code should modify to answer also for patterns of the form
\`'.....%%21...'.


\Verbatim
The i-records (provided e.g., in tex4ht.env) are assumed to refer to
paths relative to the ht-fonts directory.  If a record happens to
include the substring `/ht-fonts/', then only the portion that follows
that substring is considered.

For instance, the records

   i~/tex4ht.dir/ht-fonts/iso8859/1/!
   i~/tex4ht.dir/ht-fonts/alias/!

are equivalent to

   iiso8859/1
   ialias



If i-records are not provided, a ht-like script may contain
a call similar to

   test -z "$3" || TEX4HTFONTSET=$3;export TEX4HTFONTSET
on unix and

   set TEX4HTFONTSET={%%12}

on windows.

In texmf.cnf:  TEX4HTFONTSET=iso8859/1,alias


   TEX4HTFONTSET={iso8859/1,alias}; export TEX4HTFONTSET
   set TEX4HTFONTSET={iso8859/1,alias}
\EndVerbatim


 The user has two options of hand-made entries:  i-records and
 exportation.   Tex4ht  assumes the following priority schema:


\List{1}
\item
  Entries provided in i-records (e.g., within tex4ht.env)
\item  Entries exported by TEX4HTFONTSET from scripts  (e.g., in htlatex)
\item  Entries hard wired in TEX4HTFONTSET within texmf.cnf
(In such a case, i-records should not be provided. That is, in
 the default setting, i-records should not be provided in tex4ht.env,
 within tex4ht.c, or over tex4ht.c (in the ht... scripts).  Users may
 add such records, but the default installations should not contain
 i-records.)
\EndList


xputenv()  is a kpathsea routine for writing environment variables 




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Collect Information}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<export TEX4HTFONTSET\><<<
#ifdef KPATHSEA
{           char str [256], *export_str, *postfix;
   export_str = m_alloc(char, 1);
   *export_str = '\0';
   `<set the exported list`>
   if( (int) strlen((char *) export_str) > 0 ){
      (IGNORED) strcpy((char *) str, "%%12");
      export_str = (char *) r_alloc((void *) export_str, 
          (int) strlen((char *) export_str) + (int) strlen((char *) str) +  1 );      
      postfix = str - 1;
      while( *(++postfix) != '\0' ){
        if( (*postfix=='%')     && (*(postfix+1)=='%') &&
            (*(postfix+2)=='1') && (*(postfix+3)=='2') ){
          *postfix='\0'; postfix += 4; break;
      } }
      if( (int) strlen((char *) export_str) != 0 ){
        `<insert export into pattern`>
        `<system call for export`>
      }
   } 
   `<recording TEX4HTFONTSET`>
   free((void *) export_str);        
   `<debug info about TEX4HTFONTSET`>
}
#endif
>>>

  


\<insert export into pattern\><<<
{                       char *from_ch;
                        int i, n, m;  
  n = (int) strlen((char *) str);
  m = (int) strlen((char *) export_str);
  from_ch = export_str + m;
  for( i = 0; i<=m; i++){
    *(from_ch + n) = *(from_ch);
    from_ch--;
  }
  for( i = 0; i<n; i++){
    export_str[i] = str[i];
  }
  (IGNORED) strcat((char *) export_str, (char *) postfix);
}
>>>

An entry similar to the following one is assumed in texmf.cnf.

\Verbatim
TEX4HTINPUTS=.;$TEXMF/tex4ht/base//;$TEXMF/tex4ht/ht-fonts/{$TEX4HTFONTSET}//
\EndVerbatim



\<system call for export\><<<
{                     U_CHAR * q;
  if( dump_htf_search ) {                       U_CHAR *p, *q;
     `<trace TEX4HTFONTSET`>
  }
  q = (U_CHAR *) kpse_var_value( "TEX4HTFONTSET" );
  if( q ){
     xputenv("TEX4HTFONTSET", export_str);
     if( dump_htf_search ){
        (IGNORED) printf("setting TEX4HTFONTSET={%s}\n", export_str);
     }
  } else if( dump_htf_search ) {
     warn_i_str( 50, "TEX4HTFONTSET for kpathsea" );
  }
}
>>>






\List{*}
\item
   in the directories stated within `-i' switches of the tex4ht command line
\item
   in the directories specified within `i' records of the env file
\item
   in a directory compiled into tex4ht during its compilation
\EndList


\<set the exported list\><<<
{
      struct htf_com_rec *q;
  q = htf_font_dir;
  while( q != (struct htf_com_rec *) 0 ){
    (IGNORED) strcpy((char *) str, (char *) q->name);
    export_htf( &export_str, str );
    q = q->next;
} }
(IGNORED) fseek(dot_file, 0L, `<abs file addr`>);         
while ( search_dot_file( 'i' ) ){
           int ch;
           char* p;
  p = str;
  do {
     ch = (int) getc(dot_file);
     if( ch != EOF) { *(p++) = ch;}
  } while( (ch !='\n') && (ch != EOF) );
  *p = '\0';
  export_htf( &export_str, str );
}
#ifdef HTFDIR
  (IGNORED) strcpy((char *) str, (char *) HTFDIR);
    export_htf( &export_str, str );
#endif
`<pre assigned TEX4HTFONTSET`>
>>>



\<pre assigned TEX4HTFONTSET\><<<
{                    U_CHAR * q;
  q = (U_CHAR *) kpse_var_value( "TEX4HTFONTSET" );
  if( q ){
    if( (int) strlen((char *) q) > 0 ){ 
        export_str = (char *) r_alloc((void *) export_str,
            (int) strlen((char *) export_str) + (int) strlen((char *) q) +  2);
        if( (int) strlen((char *) export_str) > 0 ){ 
             (IGNORED) strcat((char *) export_str, ",");
        }
        (IGNORED) strcat((char *) export_str, (char *)  q);
} } }
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Appending a Segment}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<header functions\><<<
#ifdef KPATHSEA
static void export_htf( ARG_II(char**, char[]) );
#endif
>>>

\<functions\><<<
#ifdef KPATHSEA
`[ 
static void export_htf(export_str, str)
     char** export_str `;
     char str[]
;{        int i;
          char* p;
          BOOL found;
  i = (int) strlen((char *) str) - 1;
  while( (i>=0) && (str[i] == '\n') ){  str[i--] = '\0';  }
  while( (i>=0) && (str[i] == ' ') ) {  str[i--] = '\0';  }
  if( (i>=0) && (str[i] == '!') ){      str[i--] = '\0';  }
  if( (i>=0) && ((str[i] == '/') || (str[i] == '\\')) ){
                                        str[i--] = '\0';  }
  i -= 8; found = FALSE;
  while( --i>=0 ){
    if( ((str[i] == '/') || (str[i] == '\\')) && (str[i+1]== 'h')
        && (str[i+2]=='t') && (str[i+3]=='-') 
        && (str[i+4]=='f') && (str[i+5]=='o') 
        && (str[i+6]=='n') && (str[i+7]=='t') 
        && (str[i+8]=='s')
        && ((str[i+9] == '/') || (str[i+9] == '\\'))
      ){
         p = str + i + 10; i=0;
         while( *p ){ str[i++] = *(p++); }
         str[i] = '\0';
         found = TRUE;   break;
  } }
  if( found ){
     *export_str = (char *) r_alloc((void *) *export_str, 
     (int) strlen((char *) *export_str) + (int) strlen((char *) str) +  2 );
     if( (int) strlen((char *) *export_str) > 0 ){
        (IGNORED) strcat((char *) *export_str, ",");
     }
     (IGNORED) strcat((char *) *export_str, (char *) str);
  }
}
#endif
>>>





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Recording TEX4HTFONTSET}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



Kpathsea ignores the under ht-fonts paths requests coming from tex4ht.c,
exported like in \`'TEX4HTFONTSET={mozilla,iso8859/1,alias,unicode}'.  
So tex4ht.c lets kpathsea find whatever path it likes, such as

\Verbatim
/n/gold/5/gurari/tex4ht.dir/texmf/tex4ht/ht-fonts/iso8859/1/cm/cmr.htf
\EndVerbatim   

and then tex4ht.c tries to fix the path based on the information it
collected for TEX4HTFONTSET,

\Verbatim
/n/gold/5/gurari/tex4ht.dir/texmf/tex4ht/ht-fonts/unicode/cm/cmr.htf
\EndVerbatim


To that end, tex4ht.c breaks the first approximation to head
\`'.../ht-fonts/' and tail \`'....htf', while removing the path
segment \`'iso8859' just after \`'ht-fonts/'. 

Then, tex4ht.c tries the intermediate path segments from
\`'TEX4HTFONTSET={mozilla,iso8859/1,alias,unicode}', possibly with
removing prefixes from tail. 


\<vars\><<<

#ifdef KPATHSEA
static char * export_str_chars = (char *) 0;
#endif   
>>>

\<scan fonts vars\><<<

#ifdef KPATHSEA
`<scan kpathsea vars`>
#endif   
>>>




\<recording TEX4HTFONTSET\><<<
{                                  int n;
   n = (int) strlen((char *) export_str);
   if( n > 0 ){
      export_str_chars = m_alloc(char, n+1);      
      (IGNORED) strcpy((char *) export_str_chars, (char *) export_str);
}  }
>>>


\<scan kpathsea vars\><<<
int cardinality=0;
char ** fontset=0;
>>>

\<start loading fonts\><<<

#ifdef KPATHSEA
if( export_str_chars ){
  `<decompose TEX4HTFONTSET`>
}
#endif
>>>


\<end loading fonts\><<<

#ifdef KPATHSEA
if( export_str_chars ){
   free((void *) export_str_chars);
   free((void *) fontset);
}
#endif
>>>


\<decompose TEX4HTFONTSET\><<<
{                   U_CHAR   *p;
                    int n;
   cardinality = 1;
   p = (U_CHAR *) export_str_chars;
   while( *p != '\0' ){ 
     if( *p == ',' ){ cardinality++; }
     p++;
   }
   fontset = m_alloc(char *, cardinality);
   p = (U_CHAR *) export_str_chars;
   fontset[0] = p;
   n=1;
   while( *p != '\0' ){ 
      if( *p == ',' ){ fontset[n++] = p+1; *p = '\0';  }
      p++;
}  }
>>>


\<correct htfname\><<<
{                    U_CHAR  * head, * tail, *p;
                     int n;
   `<decompose htfname`>
   htfname =  (U_CHAR *) 0;
   `<try alternative htfname`>
}
>>>


\<decompose htfname\><<<
n = (int) strlen((char *) htfname);
tail = head = m_alloc(char, n+1);
(IGNORED) strcpy((char *) head, (char *) htfname);
while( n>11 ){
  if( (*tail=='\\') || (*tail=='/') ){
     if( (*tail == *(tail+9)) && (*(tail+1) == 'h') 
         && (*(tail+2) == 't') && (*(tail+3) == '-')
         && (*(tail+4) == 'f') && (*(tail+5) == 'o')
         && (*(tail+6) == 'n') && (*(tail+7) == 't')
         && (*(tail+8) == 's') ){  
        p = tail + 9;  *(tail + 10) = '\0';  tail += 11;
        while( (*tail != *p) && (*tail != '\0') ){  tail++; }
        break;
  }  }
  tail++; n--;
}
>>>




\<try alternative htfname\><<<
for( n = 0 ; (n < cardinality) && !htfname ; n++){
  p = tail;
  while( *p != '\0' ){
                               char * s, *nm;
     s = m_alloc(char, (int) strlen((char *)  head )       +
                       (int) strlen((char *)  fontset[n] ) +
                       (int) strlen((char *)  p )          + 1);
     (IGNORED) strcpy((char *) s, (char *) head);
     (IGNORED) strcat((char *) s, (char *) fontset[n]);
     (IGNORED) strcat((char *) s, (char *) p);
     nm = kpse_find_file (s, kpse_program_text_format, 0);
     free((void *) s); 
     if ( nm ){
        htfname = nm; break; 
     }
     p++;
     while( (*p != '\\') && (*p != '/')  && (*p != '\0') ){ p++; }
} }
>>>





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Debugging info}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<debug info about TEX4HTFONTSET\><<<
if( dump_htf_search || dump_env_search ) {                     
                                U_CHAR *p, *q; 
   `<trace TEX4HTINPUTS`>
}  
>>>


NOTE: The following code, activated by -hV or -hF, stops tex4ht.c with 
and error under miktex/kpathse.
The execution arrives to 
`\Verb+kpse_find_file ( "texmf.cnf", kpse_cnf_format, 0);+'
but does not print a message in the line that follows. The problem 
probably was in \Verb=warn_i_str=.  The code was modified from

\Verbatim
     static U_CHAR warning[] = "--- warning --- ";
     ....
     fprintf(stderr,"--- warning --- "); 
\EndVerbatim

to

\Verbatim
     fprintf(stderr,"--- warning --- "); 
\EndVerbatim

with the assumption/hope  that  it will take care of the problem.


\<trace TEX4HTINPUTS\><<<
p = kpse_find_file ( "texmf.cnf", kpse_cnf_format, 0);
if( p ){
   (IGNORED) printf( "texmf.cnf = %s\n", p);
} else { warn_i_str(1, "texmf.cnf" ); }
p = (U_CHAR *) kpse_var_value( "TEX4HTINPUTS" );
if( p ){
   (IGNORED) printf("TEX4HTINPUTS = %s\n", p);
}
q = getenv("TEX4HTINPUTS");
if( q ){  (IGNORED) printf(
   "Environment var TEX4HTINPUTS:  %s\n", q);
}
if( !p && !q ){
   (IGNORED) printf( "Missing TEX4HTINPUTS for kpathsea\n" );
}
>>>





\<trace TEX4HTFONTSET\><<<
p = (U_CHAR *) kpse_var_value( "TEX4HTFONTSET" );
if( p ){
   (IGNORED) printf("given TEX4HTFONTSET = %s\n", p);
}
q = getenv("TEX4HTFONTSET");
if( q ){  (IGNORED) printf(
   "Environmet var TEX4HTFONTSET:  %s\n", q);
}
if( !p && !q ){
   (IGNORED) printf( "Missing TEX4HTFONTSET for kpathsea\n" );
}
>>>









%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Searching with KPATHSEA}
%%%%%%%%%%%%%%%%%%%%%%

\Link[http://www.fptex.org/kpathsea/kpathsea\string_toc.html]{}{}Kpathsea
manual\EndLink 


\<h-include\><<<
`<KPATHSEA h-include`>
>>>



\<kpathsea arg 0\><<<

#ifdef KPATHSEA
   kpse_set_program_name (argv[0], "tex4ht");
#endif
>>>



\<kpathsea env file\><<<

#ifdef KPATHSEA
if( !dot_file ) {                    U_CHAR * envfile;
                             char *arch, *p, str[256];
  `<arch = tail of SELFAUTOLOC`>
  envfile = (char *) 0;
  `<envfile = kpse-find-file architecture/tex4ht.env`>
  if ( !envfile ){ `<envfile = kpse-find-file tex4ht.env`> }
  if ( !envfile ){ `<envfile = kpathsea tex4ht.env`> }
  if ( envfile ){
    dot_file = kpse_open_file (envfile,
                              kpse_program_text_format);
    (IGNORED) printf("(%s)\n",  envfile);
  } else if( dump_env_search ){
    p = (char *) kpse_var_value( "TEX4HTINPUTS" );
    if( p ){
       (IGNORED)  printf( "TEX4HTINPUTS = %s\n", p );
    } else {  warn_i_str( 50, "kpathsea variable TEX4HTINPUTS"); }
  }
}
#endif
>>>

The location of tex4ht.c can be found from the kpathsea variable
`SELFAUTOLOC = /n/gold/5/gurari/tex4ht.dir/bin/solaris', from which
one can determine the architecture in use.


\Verbatim
 > I still cannot catch why you need to determine the architecture, since
 > all stuff belongs to texmf tree which is always the same for all systems, 
 > and tex4ht.env is found without problem.
 > And T4HTINPUTS=  should be set in texmf.cnf

In case we have different tex4ht.env files for different architectures

  /usr/TeX/texmf/tex4ht/base/i386-linux/tex4ht.env 
  /usr/TeX/texmf/tex4ht/base/win32/tex4ht.env 

the SELFAUTOLOC provides us information about the architecture in use
by inspecting from what branch tex4ht.c comes

  /usr/TeX/bin/i386-linux
  /usr/TeX/bin/win32

Seems to me that this problem is solved now.

\EndVerbatim



\<arch = tail of SELFAUTOLOC\><<<
p = arch = (char *) kpse_var_value( "SELFAUTOLOC" );
while( *p != '\0' ){
   if( (*p ==   '/') || (*p == '\\') ){
      arch = p;
   }
   p++;
}
>>>


\<envfile = kpse-find-file architecture/tex4ht.env\><<<
if( arch ){
  (IGNORED) sprintf(str,"%s%ctex4ht.env", arch+1, *arch);
  if( dump_env_search ){ 
    (IGNORED) printf("kpse_open_file (\"%s\", ...)?\n", str ); 
  }
  envfile= kpse_find_file (str, kpse_program_text_format, 0);
}
>>>


\<envfile = kpse-find-file tex4ht.env\><<<
if( dump_env_search ){ 
  (IGNORED) printf("kpse_open_file (\"tex4ht.env\", ...)?\n"); 
}
envfile= kpse_find_file ("tex4ht.env", kpse_program_text_format, 0);
>>>




\<if kpathsea tfm files else\><<<
#ifdef KPATHSEA
{
     U_CHAR * tfmfile;
  tfmfile = kpse_find_file (file_name, kpse_tfm_format, 0);
  if( !tfmfile ){ `<tfmfile = kpathsea tfm file`> }
  if ( tfmfile ){
       (IGNORED) printf("(%s)\n",  tfmfile);
       font_file = kpse_open_file (tfmfile, kpse_tfm_format);     
  }
}
#else
>>>

%    font_file = kpse_open_file (file_name, kpse_tfm_format);


\<endif kpathsea tfm files\><<<
#endif
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{kpathsea vs kpse-find-file}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


The \`'kpsewhich' utility can succeed where the \Verb|kpse_find_file|
function fails, if the program is named something other than \`'tex4ht'.
Otherwise, we don't find the \`'TEX4HTINPUTS' definition in
\`'texmf.cnf'.

However, this is not yet enough to actually make the program work under
an arbitrary name, because the \`'.htf' lookups fail; we need to reset
the Kpathsea progname.  Other things to do, so let it stand.  Bottom
line is that the program must be invoked as \`'tex4ht'.



\<envfile = kpathsea tex4ht.env\><<<
#define KPSEWHICH_CMD "kpsewhich --progname=tex4ht --format=othertext tex4ht.env"
if( dump_env_search ){
  (IGNORED) printf("system(" KPSEWHICH_CMD ")?\n"); /* cpp concatenation */
}
if( system(KPSEWHICH_CMD ">tex4ht.tmp") == 0 ){
   `<fileaddr = read tex4ht.tmp`>
   envfile= kpse_find_file (fileaddr, kpse_program_text_format, 0);
   if( envfile ){
      warn_i_str( 50, 
          "search support for kpse_find_file--using kpsewhich calls instead"); 
}  }
>>>

\<tfmfile = kpathsea tfm file\><<<
char s [256]; 
(IGNORED) strcpy(s, "kpsewhich "); 
(IGNORED) strcat(s, file_name); 
(IGNORED) strcat(s, " > tex4ht.tmp "); 
if( system(s) == 0 ){
   `<fileaddr = read tex4ht.tmp`>
   tfmfile = kpse_find_file (fileaddr, kpse_program_text_format, 0);
}
>>>


Don't know how to avoid the use of intermediate file: popen(...) and
fork() are not stadard utilities.  Also the redirection \Verb+>+ might
need to be changed, e.g., to \Verb+>&+.

\<fileaddr = read tex4ht.tmp\><<<
char fileaddr [256];
int loc = 0;
FILE* file =  f_open("tex4ht.tmp", READ_TEXT_FLAGS);
if( file ){
  while( (fileaddr[loc] = getc(file)) >=0  ){
    if( fileaddr[loc] == '\n' ){ fileaddr[loc] = '\0'; break; }
    loc++;
  }
  (IGNORED) fclose(file);
}  
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{HTF Fonts}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


     \<vars\><<<
static BOOL dump_htf_search = FALSE;
>>>

\<trace htf search\><<<
dump_htf_search = TRUE;
>>>




\<file = kpathsea .htf file\><<<

#ifdef KPATHSEA
  if( !file ){ U_CHAR * htfname;
     htfname= kpse_find_file (name, kpse_program_text_format, 0);
     if ( htfname ){ 
         `<correct htfname`>
         if ( htfname ){ 
            (IGNORED) printf("(%s)\n",  htfname);
            file= fopen(htfname,READ_TEXT_FLAGS); 
     }   }
  }
#endif
>>>

web2c/kpathsea version uses texmf.cnf with the following: 

\Verbatim
TEX4HTFONTSET=alias,iso8859
TEX4HTINPUTS=.;$TEXMF/tex4ht/base//;$TEXMF/tex4ht/ht-fonts/{$TEX4HTFONTSET}//
T4HTINPUTS=.;$TEXMF/tex4ht/base//
\EndVerbatim

We can check values of variables of kpathsea with code fragments of
the following form.

\Verbatim
if( q = (U_CHAR *) kpse_var_value( "TEX4HTINPUTS" ) ){
  (IGNORED) printf( "%s\n", q );
}
\EndVerbatim





\ifHtml[\HPage{more}\Verbatim
I'm trying to get tex4ht to work with the kpathsea libraries.
Unfortunately, it seems to be having problems finding tfm files, even
when the relevant tex environment variables appear to have been set
and the file exists:

mclellan:~/test% kpsewhich -progname=tex4ht cmsy10.tfm
/usr/local/tex/texmf/fonts/tfm/public/cm/cmsy10.tfm
mclellan:~/test% ls -l `kpsewhich -progname=tex4ht cmsy10.tfm`
-rw-r--r--   1 tetex    local       1124 Aug 14  1995 /usr/local/tex/texmf/fonts/tfm/public/cm/cmsy10.tfm

The OS is solaris 7, and I compiled tex4ht as follows:
gcc -O2 -DKPATHSEA -I/usr/local/teTeX/include -L/usr/local/teTeX/lib -o tex4ht tex4ht.c  -DHAVE_DIRENT_H -lkpathsea
%
tex4ht: fatal: tfm file `cmtt10.tfm' not found.
%
\EndVerbatim\EndHPage{}]\fi
%
\ifHtml[\HPage{kpathsea note}\Verbatim
Date: Mon, 22 Dec 1997 13:06:18 +0000

There is an issue to resolve, which is how tex4ht finds its support
files, viz its tex4ht.env control file (in which the font-finding
lines are now ignored), and its .htf files. For the present, I have
set it up so that these are searched for on the TEXINPUTS path, and I
have located them in $TDS/tex/generic/tex4ht/base and
$TDS/tex/generic/tex4ht/htf. Ideally, we would invent a new font
category of "htf" to parallel vf, tfm etc, but that is quite a
widespread change to implement. Any views on that sort of thing, Olaf?
\EndVerbatim\EndHPage{}]\fi{}
\ifHtml[\HPage{more}\Verbatim
Date: Tue, 30 Dec 1997 21:32:40 +0000



 > b) Insert the following definition at the beginning of the source file 
 > 
 >    #ifdef KPATHSEA
 >    #define ENVFILE "...dir_in_kpathsea.../tex4ht.env"
 >    #endif
 > 
kpathsea's system allows for programs to locate files depending on the
location of binaries, so anything hard-wired would not work

\EndVerbatim\EndHPage{}]\fi

\ifHtml[\HPage{more}\Verbatim
Subject: tex4htk search paths.
Date: 04 Feb 1998 21:22:46 +0100

Lines: 43
X-Mailer: Gnus v5.4.66/Emacs 19.34

I'm wondering whether the texmf tree really is the proper place for
the tex4htk.env and .htf files.  Unless these need to be read by TeX,
the proper location would be somewhere in
  texmf/tex4htk/
which is accessible by using kpse_program_text_format (or
kpse_program_binary_format) in the kpse_find_file calls, and can be
modified by defining TEX4HTKINPUTS in texmf.cnf or the environment.


If so, the necessary changes would look something like this...

--- tex4ht.c-  Fri Jan 30 17:00:55 1998
+++ tex4ht.c  Wed Feb  4 21:20:33 1998
@@ -3038,7 +3038,7 @@
        char *p, *q, *in_name = "", *out_name = "";
   
 #ifdef KPATHSEA
-   kpse_set_progname (argv[0]);
+   kpse_set_program_name (argv[0], NULL);
 #endif
 
 
@@ -3175,7 +3175,7 @@
    
 #ifdef KPATHSEA
   if( !dot_file )
-    dot_file = kpse_open_file ("tex4ht.env", kpse_tex_format);
+    dot_file = kpse_open_file ("tex4ht.env", kpse_program_text_format);
 #endif
 
 
@@ -3648,7 +3648,7 @@
       
 #ifdef KPATHSEA
   if( !file ){ char * htfname;
-     htfname= kpse_find_file (name, kpse_tex_format, 0);
+     htfname= kpse_find_file (name, kpse_program_text_format, 0);
      if ( htfname) file= fopen(htfname,READ_TEXT_FLAGS);
   }
 #endif

-- 
Olaf Weber

\EndVerbatim\EndHPage{}]\fi
%
\ifHtml[\HPage{more}\Verbatim
 > kpathsea was a valuable addition when tex4ht.c had not a booking 
 > mechanism of its own.  It looks like we are getting to a point 
 > where we need to reevaluate the role of kpathsea within tex4ht.c.

the advantage of kpathsea is that it continues to work if you move the 
entire TeX tree to a new disk, or the like. anything like tex4ht.env,
which has path names in it, cannot work eg on a mounted CD (where you
cannot predict the path)

\EndVerbatim\EndHPage{}]\fi
%
\ifHtml[\HPage{more}\Verbatim
I have
changed the second argument of 'kpse_set_program_name' from NULL (which would
effectively mean argv[0]) to 'tex4ht', as that saves having to add a
'T4HTINPUTS' (or 'T4HTKINPUTS') variable into the kpathsea configuration file
'texmf.cnf' pointing to the same place for 'tex4ht.env' as the 'TEX4HTINPUTS'
variable.

0a1,4
> /* t4htk.c = t4ht.c, but with KPATHSEA support
>  * corrected/adjusted by Andrew Gray <ajpg@debian.org>,
>  * 11 March 1999
>  */
94a99,102
> #ifdef KPATHSEA
> #include <kpathsea/progname.h>
> #include <kpathsea/tex-file.h>
> #endif
943c951
<    kpse_set_program_name (argv[0], NULL);
---
>    kpse_set_program_name (argv[0], ``tex4ht'');
\EndVerbatim\EndHPage{}]\fi
%
\ifHtml[\HPage{more}\Verbatim
I'm trying to get tex4ht to work with the kpathsea libraries.
Unfortunately, it seems to be having problems finding tfm files, even
when the relevant tex environment variables appear to have been set
and the file exists:

mclellan:~/test% kpsewhich -progname=tex4ht cmsy10.tfm
/usr/local/tex/texmf/fonts/tfm/public/cm/cmsy10.tfm
mclellan:~/test% ls -l `kpsewhich -progname=tex4ht cmsy10.tfm`
-rw-r--r--   1 tetex    local       1124 Aug 14  1995 /usr/local/tex/texmf/fonts/tfm/public/cm/cmsy10.tfm

The OS is solaris 7, and I compiled tex4ht as follows:
gcc -O2 -DKPATHSEA -I/usr/local/tex/include -L/usr/local/tex/lib -o tex4ht tex4ht.c  -DHTFDIR='"/usr/contrib/share/tex4ht"' -DHAVE_DIRENT_H -lkpathsea

tex4ht.c (2000-03-01-16:28)
/usr/contrib/share/tex4ht/tex4ht: fatal: tfm file `cmsy10.tfm' not found.

\EndVerbatim\EndHPage{}]\fi
%
\ifHtml[\HPage{more}\Verbatim
 1. Call `kpse_set_program_name' with `argv[0]' as the first argument;
     the second argument is a string or `NULL'.  The second argument is
     used by Kpathsea as the program name for the `.PROGRAM' feature of
     config files (*note Config files::.).  If the second argument is
     `NULL', the value of the first argument is used.  This function
     must be called before any other use of the Kpathsea library.

     If necessary, `kpse_set_program_name' sets the global variables
     `program_invocation_name' and `program_invocation_short_name'.
     These variables are used in the error message macros defined in
     `kpathsea/lib.h'.  It sets the global variable `kpse_program_name'
     to the program name it uses.  It also initializes debugging
     options based on the environment variable `KPATHSEA_DEBUG' (if
     that is set).  Finally, it sets the variables `SELFAUTOLOC',
     `SELFAUTODIR' and `SELFAUTOPARENT' to the location, parent and
     grandparent directory of the executable, removing `.' and `..'
     path elements and resolving symbolic links.  These are used in the
     default configuration file to allow people to invoke TeX from
     anywhere, specifically from a mounted CD-ROM.  (You can use
     `--expand-var=\$SELFAUTOLOC', etc., to see the values finds.)

\EndVerbatim\EndHPage{}]\fi





%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Searching Utilities}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Search Files Listed in Environment File}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


The following is used for start searching files from directories mentioned
in the dot file.

\<header functions\><<<
static FILE*  search_in_dot_file( ARG_IV( int, const U_CHAR *, const U_CHAR *,
                                    struct env_var_rec *) );
>>>

\<functions\><<<
`[
static FILE*  search_in_dot_file( typ, name, flags, env_dirs) 
                                                 int   typ`;
                                                 const U_CHAR  *name`;
                                                 const U_CHAR  *flags`;
                                      struct env_var_rec *env_dirs

;{                                         U_CHAR  *ch, dir[256];
                                          FILE* file;
#ifndef KPATHSEA
   if( cache_files != (FILE *) 0 ){ 
      `<search font in cache files`>
   }
#endif   
   (IGNORED) fseek(dot_file, 0L, `<abs file addr`>);
   while( search_dot_file( typ ) ){
      ch = dir;
      while((*(ch++) = (int) getc(dot_file)) > ' ');
      while(*(ch-1) !=  '\n'){
          *(ch-1) = (int) getc(dot_file);
      }
      *(ch-1) = '\0';
      file = search_file_base(name, dir, flags, env_dirs);
      if( file != NULL ){
#ifndef KPATHSEA
        tex4ht_fls = TRUE;
#endif   
        return file;
   }  }
   return NULL;
}
>>>







\<header functions\><<<
static FILE*  search_file_base( ARG_IV( const U_CHAR *, const U_CHAR *, const U_CHAR *,
                                    struct env_var_rec *) );
>>>

\<functions\><<<
`[
static FILE*  search_file_base( name, dir, flags, env_dirs) 
                                                 const U_CHAR  *name`;
                                                 const U_CHAR  *dir`;
                                                 const U_CHAR  *flags`;
                                      struct env_var_rec *env_dirs

;{                                         U_CHAR  *p;
                                          FILE* file;
   if( *dir == '~' ){
     while( TRUE ){
        p = abs_addr(dir, env_dirs? env_dirs->base : NULL);
        file = search_file(name, p, flags);
        free((void *) p);        
        if( file || !env_dirs ){  return file; }
        env_dirs = env_dirs->next;
     }
   } else {
     file = search_file(name, dir, flags);
   }
   return file;
}
>>>



\<header functions\><<<
static char *  abs_addr( ARG_II( const U_CHAR *, const U_CHAR *) );
>>>

\<functions\><<<
`[
static char *  abs_addr( dir, base) 
                                                 const U_CHAR  *dir`;
                                                 const U_CHAR  *base

;{                                         U_CHAR  *p;
   p = m_alloc(char, (int) strlen( dir )            +
                     (base? (int) strlen( base ):0) +
                     (int) strlen((char *)  HOME_DIR  )      + 1 );
   *p = '\0';    
   if( (*(dir+1) == '~') && base ){  
     if( *base == '~' ){  
       (IGNORED) strct(p, HOME_DIR);   
       (IGNORED) strct(p, base+1);   
     } else {
       (IGNORED) strct(p, base);   
     } 
     (IGNORED) strct(p, dir+2);   
   } else {
     (IGNORED) strct(p, HOME_DIR);   
     (IGNORED) strct(p, dir+1);   
   }
   return p;
}
>>>



\SubSection{Search in Current  Directory and Specified Directory}

 If a path specification ends in a '!', it's subdirectories are
    searched too, else only the specified dir is searched. (This is the
    way many TeX installations seem to do it, too).



\<header functions\><<<
static FILE* search_file( ARG_III(const char *, const U_CHAR *, const U_CHAR *) );
>>>

\<functions\><<<
`[
static FILE* search_file( name, dir, flags ) 
     const char     *name`;
     const U_CHAR   *dir`;
     const U_CHAR   *flags

;{   FILE*  file;
     U_CHAR     str[256];
     int i;
     BOOL subs;
  `<search file in cur dir`>
      (IGNORED) strcpy((char *) str, dir);
      i = (int) strlen((char *) str) - 1;
      subs = str[i] == '!';
      if( subs )  str[i] = '\0';  else i++;
      `<cat / if needed`>

  `<search file in named dir`>
  str[i] = '\0';
  return  subs?  search_file_ext( name, str, flags):
                NULL;
} 
>>>

\<cat / if needed\><<<
(IGNORED) strct(str,
#if defined(__DJGPP__)
 (( dir[i-1] == '/') ||  ( dir[i-1] == '\\')) 
 ?  ""
 :  (is_forward_slash(dir)?  "/" : "\\" )
#else
 (dir[i-1] == '/')? "" : "/"
#endif
  );
>>>





\<search file in cur dir\><<<
if( (file = f_open(name, flags)) != NULL ){
   return file; }
>>>

\<search file in named dir\><<<
(IGNORED) strct(str,name);
if( (file = f_open(str, flags)) != NULL ){
   str[i] = '\0'; add_to_cache(str,name,i);
   return file; }
>>>




\<header functions\><<<
static void add_to_cache( ARG_III(const char*,const char*,int) );
>>>

\<functions\><<<
`[
static void add_to_cache(dir,name,n)   
                         const char*  dir`; const char* name`; int n

;{
                         struct cache_font_rec *cur_cache_font;

   `<put dir in cache`>
   `<store filename in cache`>
}
>>>



\SubSection{Search in SubDirectories}

\<header functions\><<<
static FILE* search_file_ext( ARG_III(const char *, const U_CHAR *, const U_CHAR *) );
>>>

\<functions\><<<
`[
static FILE* search_file_ext( name, dir, flags )  
    const char     *name`; 
    const U_CHAR   *dir`;
    const U_CHAR   *flags

;{  U_CHAR   str[256];
    FILE*  file;
    int    n;
  n = (int) strlen(dir);
  (IGNORED) sprintf(str, 
#if defined(__DJGPP__)
 (( dir[n-1] == '/') ||  ( dir[n-1] == '\\')) 
 ?  "%s%s"
 :  (is_forward_slash(dir)?  "%s/%s" : "%s\\%s" )
#else
   (dir[n-1] == '/')? "%s%s" : "%s/%s" 
#endif 
   , dir, name);
  if( (file = f_open(str,flags)) != NULL ){
     add_to_cache(dir,name,n);
     return file;
  }
  if( (str[n] == `<directory '/'`>) 
#ifdef DOS_WIN32
    ||  (str[n] == '/' ) 
#endif     
    ) n++;
  str[n-1] = '\0';
#ifndef NOSUBDIR
#ifdef WIN32
  `<file = search WIN32 subdir (name,str)`>
#else  
  `<file = search subdir (name,str)`>
#endif
#endif
  return NULL;
}
>>>




Searches in subdirectories require opendir, closedir, readir. I can't
find them for dos, so I disabled them there.

On Windows/dos, both forward slash (\''/') and backslash (\''\') are
used as path separator characters. In other environments, it is the
forward slash (\''/').

\<directory '/'\><<<
#if defined(__DJGPP__)
 '\\'
#else
 '/'
#endif
>>>



\<defines\><<<
#if defined(__DJGPP__)
#define dir_path_slash(str) (is_forward_slash(str)? '/' : '\\')
#else
#define dir_path_slash(str)  '/' 
#endif
>>>



\<header functions\><<<
#if defined(__DJGPP__)
   static BOOL is_forward_slash( ARG_I(const char*) );
#endif
>>>

\<functions\><<<
#if defined(__DJGPP__)
`[ 
static BOOL is_forward_slash(str)
                                    const char* str
;{   
   while( *str ){  if( *(str++) == '/' ) { return TRUE; } }
   return FALSE;
}
#endif
>>>



\<file = search subdir (name,str)\><<<
{      DIR             *dp;
       `<struct dirent`>   *dirp;
       struct STSTAT     buf;
  if( (dp = opendir( str )) != NULL ){
    while( (dirp = readdir(dp)) != NULL ){
      if( !eq_str(dirp->d_name, ".")  &&
          !eq_str(dirp->d_name, "..") )
      { `<reach into the subdirectory`>
    } }
    (void) closedir(dp);
} }
>>>


\<reach into the subdirectory\><<<
(IGNORED) strcpy((char *)  str+n, (char *) dirp->d_name );
str[n-1] = dir_path_slash(str);
if( LSTAT(str, &buf) >= 0 )
   if( S_ISDIR( buf.st_mode ) )
      if( (file = search_file_ext(name, str, flags)) != NULL ){
         (void) closedir(dp);
         return file; }
>>>

\<h-include\><<<
#ifdef DOS_WIN32
#include <io.h>    
#endif
>>>





\<defines\><<<
#ifndef  S_ISDIR 
#define S_ISDIR(M)  (((M) & _S_IFMT)==_S_IFDIR)   `% test for directory `%
#endif

#ifndef _S_IFDIR
#define _S_IFDIR S_IFDIR
#endif

#ifndef _S_IFMT
#define _S_IFMT S_IFMT
#endif
>>>


`lstat' returns info about the symbolic link, not the file referenced by the
symbolic link as `stat' does

STSTAT is for `struct stat', LSTAT is for the function.
 Don't define STAT, aix's {\tt <sys/dir.h>} defines it as 1
(Peter Breitenlohner).

\Verbatim
1998-10-22  Eli Zaretskii  <eliz@is.elta.co.il>  DJGPP:
        (LSTAT): Define to stat for every system that doesn't define
        S_ISLNK.
\EndVerbatim



\<defines\><<<
#if defined(DOS_WIN32) || !defined(S_ISLNK)
#define LSTAT stat
#else
#define LSTAT lstat
#endif
#define STSTAT stat
>>>



\<h-include\><<<
#include <sys/stat.h>    
`%                          stat _IF_DIR
`%
>>>

\SubSection{dirent}

  readdir, opendir, closedir


\<h-defines DOS-WIN32\><<<
#ifdef DOS_WIN32
#define STRUCT_DIRENT
#endif
>>>


\<h-include\><<<
#ifdef HAVE_DIRENT_H
`<needs dirent.h`>
#else
#ifndef STRUCT_DIRENT
#define STRUCT_DIRECT
#endif
`<needs simulated dirent.h`>
#endif 
>>>





\<needs dirent.h\><<<
#include <dirent.h>
>>>


\<needs simulated dirent.h\><<<
#ifdef HAVE_SYS_NDIR_H
#include <sys/ndir.h>
#endif
#ifdef HAVE_SYS_DIR_H
#include <sys/dir.h>
#endif
#ifdef HAVE_NDIR_H
#include <ndir.h>
#endif
>>>




\<struct dirent\><<<

#ifdef STRUCT_DIRECT
   struct direct 
#else
   struct dirent 
#endif
>>>


\ifHtml[\HPage{more}\Verbatim

    I updated all of

    ftp://www.tug.org/private/texk7.2drivers/

A small patch for tex4htk. It won't compile on systems without
<dirent.h>, therefore I copied this from gsftopk. I don't know how to
handle the MSVC_1_52_DOS correctly.





--- tex4ht.c.ORIG       Wed Mar 18 11:07:26 1998
+++ tex4ht.c    Wed Mar 18 11:17:39 1998
@@ -146,7 +146,21 @@


 #ifndef MSVC_1_52_DOS
-#include  <dirent.h>
+#ifdef HAVE_DIRENT_H
+#include <dirent.h>
+typedef        struct dirent   struct_dirent;
+#else /* no <dirent.h> */
+typedef        struct direct   struct_dirent;
+#ifdef HAVE_SYS_NDIR_H
+#include <sys/ndir.h>
+#endif
+#ifdef HAVE_SYS_DIR_H
+#include <sys/dir.h>
+#endif
+#ifdef HAVE_NDIR_H
+#include <ndir.h>
+#endif
+#endif /* no <dirent.h> */

 #endif

@@ -2598,7 +2612,7 @@
 #ifndef NOSUBDIR

 {      DIR             *dp;
-       struct dirent   *dirp;
+       struct_dirent   *dirp;
        struct STSTAT     buf;
   if( (dp = opendir( str )) != NULL ){
     while( (dirp = readdir(dp)) != NULL ){

\EndVerbatim\EndHPage{}]\fi









%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\SubSection{Try to Open Path-Named File}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



\<header functions\><<<
static FILE* f_open_pathed_filename( ARG_II(const char*,const char*) );
>>>

\<functions\><<<
`[
static FILE* f_open_pathed_filename( name, flags ) 
                          const char*  name `;
                          const char*  flags                           
;{                        FILE* file;
                          U_CHAR *str;
  file = NULL;
  if( *name == '~' ){
     if( HOME_DIR ){ 
         str = m_alloc(char, strlen((char *) HOME_DIR)+strlen(name));
         (IGNORED) sprintf(str,"%s%s", HOME_DIR, name+1);
         file = f_open(str,flags);     
         free((void *)  str);         
     } 
  } else {  file = f_open( name, flags );   } 
  return file;
}
>>>


%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Unicode into Character Encoding}
%%%%%%%%%%%%%%%%%%%%%%%%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Put Character}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<header functions\><<<
static INTEGER put_4ht_ch( ARG_II(int,FILE *) );
>>>

\<functions\><<<
`[ 
static  INTEGER put_4ht_ch(ch,htFile)    int ch `; FILE* htFile
;{
                                 int c;  
  c = ch;
  if( ch=='&' ){
     `<flush incomplete unicode`>
     if( put_4ht_off ){
        c = putc( ch, htFile ); 
     } else {
        uni_code[0] = '&';
        uni_code_p = 1;
        put_4ht_file = htFile;
     }
  } else 
  if( uni_code_p ){
    if( ch == ';' ){ `<process unicode`> uni_code_p = 0; }
    else if (     ((uni_code_p+1) == MAX_UNI_CODE)
               ||
                  (    ((ch<'0') || (ch>'9'))
                    && ((ch<'a') || (ch>'f'))
                    && ((ch<'A') || (ch>'F'))
                    && (ch!='#') 
                    && (ch!='x')  
                    && (ch!='X')
                  )
            )
    { `<flush incomplete unicode`> 
      c = putc( ch, htFile );
    } else { uni_code[ uni_code_p++ ] = ch; }
  } else { c = putc( ch, htFile ); }
  return  c;
}
>>>

\<vars\><<<
static FILE* put_4ht_file = (FILE *) 0;
static int put_4ht_off = 1;
static char uni_code[MAX_UNI_CODE];
static short uni_code_p = 0;
>>>

\<defines\><<<
#define MAX_UNI_CODE 20
>>>


\<on/off unicode\><<<
special_n--;
switch ( code = get_char() ){
  case '+': { put_4ht_off++; `<flush incomplete unicode`> break; }
  case '-': { if( put_4ht_off>0 ){ put_4ht_off--; }
              else { warn_i_str(52, "@u-"); }
              break; }
}
>>>


%%%%%%%%%%%%%
\Section{Flash Unrecognized Codes}
%%%%%%%%%%%%%




\<flush incomplete unicode\><<<
flush_uni();
>>>

\<header functions\><<<
static void flush_uni( ARG_I(void) );
>>>

\<functions\><<<
static void flush_uni( MYVOID )     
{
                                   int i;
  for(  i=0; i<uni_code_p; i++ ){
    (IGNORED)  putc( uni_code[i], put_4ht_file );
  }
  uni_code_p = 0;
  put_4ht_file = (FILE *) 0;
}
>>>





%%%%%%%%%%%%%
\Section{Load unicode.4hf Table}
%%%%%%%%%%%%%


\<load unicode.4hf\><<<
{                              U_CHAR name[256];
                               FILE* file;
   (IGNORED) sprintf(name, "%s.4hf", "unicode");
   `<search file in htf locations`>
   if( file ){
            `<unicode.4hf vars`>
      `<mem for charset`>
      `<read unicode.4hf`>
      put_4ht_off = 0; 
   } else{ put_4ht_off = 1; `<no mem for charset`> }
}
>>>


\<unicode.4hf vars\><<<
int chr, delimiter, delimiter_n, line_no, digit, i, j;
U_CHAR in[512], *in_p,  * start[4], *p;
BOOL char_on, err;
int value;
>>>


\<read unicode.4hf\><<<
err = FALSE;
line_no = 0;
while( TRUE ){
  line_no++;
  chr = (int) getc(file);
  if( chr == EOF ){ break; }
  if( (chr>32) && (chr<127) ){
     `<scan 4hf fields`>
     if( delimiter_n == 8 ){ 
        if( *in != '?' ) {
           if( `<not hexa unicode?`> ){ err = TRUE; }
           else {  
              `<value = hex into int`>
              if( start[3] == (in_p-1) ){
                 if( !err ){ `<store type-less 4hf endtry`> }
              } else { `<store typed 4hf endtry`> }
     }  } } 
     else { err = TRUE; }
     `<error 4hf fields`>
  }
  while( (chr != EOF) && (chr!='\n') ){
     chr = (int) getc(file);
  }
  if( chr == EOF ){ break; }
}
>>>


\<not hexa unicode?\><<<
   (*in             != '&')     
|| (*(in+1)         != '#')      
|| ( (*(in+2)       != 'x') && (*(in+2) != 'X')) 
|| (*(start[1] - 2) != ';')      
>>>

\<scan 4hf fields\><<<
delimiter   = chr;
delimiter_n = 1;
char_on     = TRUE;
in_p = in;
while( TRUE ) {
  chr = (int) getc(file);
  if( (chr == EOF) || (chr=='\n') ){ break; }
  if( chr == delimiter ){ 
     if( char_on ){ *(in_p++) = '\0'; }
     else{ start[ delimiter_n/2 ] = in_p; }
     char_on = !char_on;
     delimiter_n++;
  } else if (char_on ) {
     *(in_p++) = chr; 
  }  
  if( delimiter_n==8 ){ break; }
}
>>>

\<process 4hf fields\><<<

>>>



\<error 4hf fields\><<<
if( err ){
   warn_i_int(48,line_no); 
   (IGNORED) printf( "%c", delimiter );
   for( p=in; p != in_p; p++ ){
     if( *p=='\0' ){
       (IGNORED) printf("%c", delimiter); 
       if( p != in_p-1 ){ (IGNORED) printf("  %c", delimiter); }
     }
     else { (IGNORED) printf( "%c", *p ); }
   }
   (IGNORED) printf( "\n" );
   err = FALSE;
}
>>>


%%%%%%%%%%%%%
\Section{Store Entry of Table}
%%%%%%%%%%%%%


\<types\><<<
struct charset_rec{ int  ch;
                    char* str; };
>>>

\<vars\><<<
static int charset_n = 0, max_charset_n;
static struct charset_rec *charset;
>>>


\<mem for charset\><<<
max_charset_n = 256;
charset =   m_alloc(struct charset_rec, 256);
>>>

\<no mem for charset\><<<
max_charset_n = 0;
>>>


\<value = hex into int\><<<
value = 0;
for( p=in+3; *p!=';'; p++){
  digit = (int) *p;
  if( (digit>='0') && (digit<='9') ){ digit -= '0'; }
  else if( (digit>='A') && (digit<='F') ){ digit -= BASE_A; }
  else if( (digit>='a') && (digit<='f') ){ digit -= BASE_a; }
  else { digit=0; err = TRUE; }
  value = 16*value + digit;
}
>>>


\<defines\><<<
#define BASE_A 55
#define BASE_a 87
>>>


\<store type-less 4hf endtry\><<<
`<mem for new 4ht entry`>
p = m_alloc(char, (int) (start[3] - start[2]) );
(IGNORED) strcpy((char *) p, (char *) start[2] );
i = charset_n;
while( i-- > 0 ){
  if( charset[i].ch == value ){
     free((void *) charset[i].str);              
     break;
  } else { 
     if(   (charset[i].ch < value)
        || ((charset[i].ch > value) && (i==0)) ){        
        if( charset[i].ch < value ){ i++; }
        charset_n++;
        for( j=charset_n; j>i; j-- ){
           charset[j].ch  = charset[j-1].ch;
           charset[j].str = charset[j-1].str;
        }
        break;
  }  }
}
if(i == -1){ i = charset_n; }
if( i==charset_n ){ charset_n++; }
charset[i].str = p;
charset[i].ch  = value;
>>>

The above backward search allows sorted files to be loaded in linear time.


\<mem for new 4ht entry\><<<
if( (charset_n+1) == max_charset_n){
  max_charset_n += 10;
  charset = (struct charset_rec *) r_alloc((void *) charset,
        (size_t) ((max_charset_n) * sizeof(struct charset_rec) ));
}
>>>




%%%%%%%%%%%%%
\Section{Use Unicode Substitution}
%%%%%%%%%%%%%



\<process unicode\><<<
if( uni_code[1] != '#' ){
   `<flush incomplete unicode`> 
   (IGNORED)  putc( ch, htFile );
}
else{
      int i, base, value, digit;
  if( (uni_code[2] == 'x') || (uni_code[2] == 'X') ){
     base =16; i=3;
  } else { base=10; i=2; }
  value = 0;
  for( ; i<uni_code_p; i++ ){
    digit = uni_code[i];
    if( (digit>='0') && (digit<='9') ){  digit -= '0'; }
    else if( (digit>='A') && (digit<='F') ){  digit -= BASE_A; }
    else if( (digit>='a') && (digit<='f') ){  digit -= BASE_a; }
    else { value = -1; break; }
    if( digit >= base ){ value=-1; break; }
    value = value*base + digit;
  }
  if( value<0 ){ `<flush incomplete unicode`> 
                 (IGNORED)  putc( ch, htFile );
  } else {
     `<search 4hf table`>
} }
>>>

\<search 4hf table\><<<
    int bottom, mid, top;
    BOOL found=FALSE;
bottom = 0; top = charset_n; 
while( !found ){
   mid = (bottom + top) / 2;
   if( value == charset[mid].ch ){ 
      `<put 4hf replacement`>
      found = TRUE;
   } else if( value < charset[mid].ch ){ 
      if( bottom == top ){ break; }
      top = mid;
   }
   else {
     if ( bottom < mid ){  bottom = mid; }
     else if ( bottom<top ){ bottom++; }
     else{ break; } 
   }
}
if( ! found ){
   if( u10 || utf8 ){ `<hex uni to base 10 or utf8`> }
   `<flush incomplete unicode`> 
   if( !utf8 ){ (IGNORED) putc( ch, htFile ); }
}
>>>

\<put 4hf replacement\><<<
{          U_CHAR *p;
   p = charset[mid].str;
   while( *p != '\0' ){
     if( *p=='\\' ){
       p++;
       if( *p=='\\' ){ 
         (IGNORED) putc( '\\', htFile );
       } else {
             int i;
         i = *p - '0';
         while( *(++p) != '\\' ){ i = 10*i + *p - '0'; }
         (IGNORED) putc( i, htFile );
     } } 
     else { 
       (IGNORED) putc( *p, htFile );
       if ( (*p=='&') && u10 ){ `<u10 for 4hf replacement`> }
     }
     p++;
}  }
>>>

The utf8 option don't apply for unicode symbols coming from a 4hf fonts.


%%%%%%%%%%%%%
\Section{Base 10 for Entity Codes}
%%%%%%%%%%%%%





\<vars\><<<
static BOOL u10 = FALSE;
>>>

\<get unicode entity representations\><<<
if( eq_str(p+2, "10") ){ u10 = TRUE; }
`<else get utf8 unicode encoding`>
else{ bad_arg;}
>>>

\<hex uni to base 10 or utf8\><<<
      short  n;
      long   dec;
      int    ch;
      char   uni_10[MAX_UNI_CODE];
if( (uni_code[2] == 'x') || (uni_code[2] == 'X') ) {
   dec = 0;
   for(  n=3; n<uni_code_p; n++ ){
      ch = uni_code[n];
      dec = 16*dec +  
             ((ch > '9')?
                         ( 10 + ((ch > 'Z')? (ch-'a') : (ch-'A')) )
                       : (ch-'0'));
   }
   if( u10 ){ `<dec to u10`> }
   else     { `<uni in utf8`> }
}
>>>


\<dec to u10\><<<
   if( dec == 0 ){
      uni_code_p = 3;  uni_code[2] = '0'; 
   } else {
      n = 0;
      while( dec > 0 ){  uni_10[ n++ ] = dec % 10 + '0';   dec /= 10;  }
      uni_code_p = 2;
      while( n>0 ){  uni_code[ uni_code_p++ ] = uni_10[ --n ]; }
   }
>>>

\<u10 for 4hf replacement\><<<
if ( *(p+1) == '#' ){ 
  p++;
  (IGNORED) putc( '#', htFile );  
  if ( (*(p+1) == 'x') || (*(p+1) == 'X') ){ 
                 int value, digit;
                 U_CHAR *q; 
     q = p+2;
     value = 0;
     digit = *(q++);
     while( digit!=0 ){
       if( (digit>='0') && (digit<='9') ){
          value = value*16 + digit - '0'; 
       }
       else if( (digit>='A') && (digit<='F') ){
          value = value*16 + digit - 'A'+10; 
       }
       else if( (digit>='a') && (digit<='f') ){
          value = value*16 + digit - 'a'+10; }  
       else { 
         if( digit == ';' ){
           `<display value in u10`> 
           p=q-2; 
         }
         break; 
       }
       digit = *(q++);
     }
} }
>>>
   
\<display value in u10\><<<
              char   uni_10[MAX_UNI_CODE];
              int n;
n = 0;
while( value>0 ){
  uni_10[ n++ ] = value % 10 + '0';
  value /= 10;
}
while( n>0 ){
   (IGNORED) putc(  uni_10[--n], htFile );
}
>>>



%%%%%%%%%%%%%
\Section{UTF-8 for Entity Codes}
%%%%%%%%%%%%%

\Verbatim
U-00000000 - U-0000007F:  0xxxxxxx  
U-00000080 - U-000007FF:  110xxxxx 10xxxxxx  
U-00000800 - U-0000FFFF:  1110xxxx 10xxxxxx 10xxxxxx  
U-00010000 - U-001FFFFF:  11110xxx 10xxxxxx 10xxxxxx 10xxxxxx  
U-00200000 - U-03FFFFFF:  111110xx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx  
U-04000000 - U-7FFFFFFF:  1111110x 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx 10xxxxxx
\EndVerbatim


\<dec to utf8\><<<
if( dec < 0x80 ){
   uni_code_p = 1;  uni_code[0] = dec; 
} 
else if( dec < 0x800 ){
   uni_code_p = 2;  
   uni_code[0] = (dec >> 6)           | 0xC0; 
   uni_code[1] = (dec & 0x3F)         | 0x80; 
} 
else if( dec < 0x10000 ){
   uni_code_p = 3;  
   uni_code[0] = (dec >> 12)          | 0xE0; 
   uni_code[1] = ((dec >> 6)  & 0x3F) | 0x80; 
   uni_code[2] =  (dec        & 0x3F) | 0x80; 
} 
else if( dec < 0x200000 ){
   uni_code_p = 4;  
   uni_code[0] = (dec >> 18)          | 0xF0; 
   uni_code[1] = ((dec >> 12) & 0x3F) | 0x80; 
   uni_code[2] = ((dec >>  6) & 0x3F) | 0x80; 
   uni_code[3] =  (dec        & 0x3F) | 0x80; 
} 
else if( dec < 0x4000000 ){
   uni_code_p = 5;  
   uni_code[0] = (dec >> 24)          | 0xF8; 
   uni_code[1] = ((dec >> 18) & 0x3F) | 0x80; 
   uni_code[2] = ((dec >> 12) & 0x3F) | 0x80; 
   uni_code[3] = ((dec >>  6) & 0x3F) | 0x80; 
   uni_code[4] =  (dec        & 0x3F) | 0x80; 
} 
else if( dec <= 0x7FFFFFFF ){
   uni_code_p = 6;  
   uni_code[0] = (dec >> 30)          | 0xFC; 
   uni_code[1] = ((dec >> 24) & 0x3F) | 0x80; 
   uni_code[2] = ((dec >> 18) & 0x3F) | 0x80; 
   uni_code[3] = ((dec >> 12) & 0x3F) | 0x80; 
   uni_code[4] = ((dec >>  6) & 0x3F) | 0x80; 
   uni_code[5] =  (dec        & 0x3F) | 0x80; 
} 
>>>


\<vars\><<<
static BOOL utf8 = FALSE;
>>>

\<else get utf8 unicode encoding\><<<
else if( eq_str(p+2, "tf8") ){ utf8 = TRUE; }
>>>

\<uni in utf8\><<<
`<dec to utf8`>
else {
   n = 0;
   while( dec > 0 ){  uni_10[ n++ ] = dec % 10 + '0';   dec /= 10;  }
   uni_code_p = 2;
   while( n>0 ){  uni_code[ uni_code_p++ ] = uni_10[ --n ]; }
}
>>>


%%%%%%%%%%%%%
\Section{Replacements for HTF}
%%%%%%%%%%%%%

\<store typed 4hf endtry\><<<
`<mem for new htf-4hf entry`>
(IGNORED) strcpy((char *) p, (char *) start[2] );
i = htf_4hf_n;
while( i-- > 0 ){
  if( htf_4hf[i].ch == value ){
     free((void *) htf_4hf[i].str);              
     break;
  } else { 
     if(   (htf_4hf[i].ch < value)
        || ((htf_4hf[i].ch > value) && (i==0)) ){        
        if( htf_4hf[i].ch < value ){ i++; }
        htf_4hf_n++;
        for( j=htf_4hf_n; j>i; j-- ){
           htf_4hf[j].ch = htf_4hf[j-1].ch;
           htf_4hf[j].str = htf_4hf[j-1].str;
           htf_4hf[j].type1  = htf_4hf[j-1].type1;
           htf_4hf[j].type2  = htf_4hf[j-1].type2;
        }
        break;
}  } }
if(i == -1){ i = htf_4hf_n; }
if(i == htf_4hf_n){ htf_4hf_n++; }
htf_4hf[i].str = p;
htf_4hf[i].ch  = value;
`<htf_4hf[i].type1 = ...`>
`<htf_4hf[i].type2 = ...`>
>>>


\<end loading fonts\><<<
for( i = 0; i<htf_4hf_n; i++){
   free((void *) htf_4hf[i].str);              
}
free((void *) htf_4hf);              
>>>




\<mem for new htf-4hf entry\><<<
if( (htf_4hf_n+1) == max_htf_4hf_n){
  max_htf_4hf_n += 10;
  htf_4hf = (struct htf_4hf_rec *) r_alloc((void *) htf_4hf,
        (size_t) ((max_htf_4hf_n) * sizeof(struct htf_4hf_rec) ));
}
p = m_alloc(char, (int) (start[3] - start[2]) );
>>>


\<htf_4hf[i].type1 = ...\><<<
value = 0;
p = start[1];
while( *p != '\0' ){
   if( (*p < '0') || (*p > '9') ) break;
   value = value * 10 + *p - '0'; 
   p++;
}
htf_4hf[i].type1  =  value;
>>>

\<htf_4hf[i].type1 = ...\><<<
value = 0;
p = start[3];
while( *p != '\0' ){
   if( (*p < '0') || (*p > '9') ) break;
   value = value * 10 + *p - '0'; 
   p++;
}
htf_4hf[i].type2  =  value;
>>>


\<types\><<<
struct htf_4hf_rec { int   ch, type1, type2;
                     char* str; };
>>>

\<vars\><<<
static int htf_4hf_n = 0, max_htf_4hf_n;
static struct htf_4hf_rec *htf_4hf;
>>>


\<mem for charset\><<<
max_htf_4hf_n = 256;
htf_4hf = m_alloc(struct htf_4hf_rec, 256);
>>>

\<no mem for charset\><<<
max_htf_4hf_n = 0;
>>>



%%%%%%%%%%%%%
\Section{Propagate Changes into the HTF Fonts}
%%%%%%%%%%%%%

\<propagate 4hf info into htf\><<<
if( 
       (*str             == '&')
    && (*(str+1)         == '#')
    && ( (*(str+2)       == 'x') || (*(str+2) == 'X'))
    && (*(str + strlen((char *) str) - 1) == ';')
) {
        char* p;              
        int   value = 0;
        BOOL  err = FALSE;
    for( p=str+3; *p!=';'; p++){
      int digit = (int) *p;
      if( (digit>='0') && (digit<='9') ){ digit -= '0'; }
      else if( (digit>='A') && (digit<='F') ){ digit -= BASE_A; }
      else if( (digit>='a') && (digit<='f') ){ digit -= BASE_a; }
      else { digit=0; err = TRUE; }
      value = 16*value + digit;
    }
    if( !err ){
      `<search 4hf replacement in htf-4hf`>
      `<search 4hf replacement in charset`>
}   }
>>>

\<htf replacement from htf-4hf\><<<
if( htf_4hf[mid].type1 == ch1  ){
   ch1 = htf_4hf[mid].type2;
   (IGNORED) strcpy((char *) str, (char *) htf_4hf[mid].str );
}
>>>

\<htf replacement from charset\><<<
if( charset[mid].type1 == ch1  ){
   ch1 = charset[mid].type2;
   (IGNORED) strcpy((char *) str, (char *) charset.str );
}
>>>

\<search 4hf replacement in htf-4hf\><<<
    int bottom, mid, top;
    BOOL found=FALSE;
bottom = 0; top = htf_4hf_n; 
while( !found ){
   mid = (bottom + top) / 2;
   if( value == htf_4hf[mid].ch ){ 
      `<htf replacement from htf-4hf`>
      found = TRUE;
   } else if( value < htf_4hf[mid].ch ){ 
      if( bottom == top ){ break; }
      top = mid;
   }
   else {
     if ( bottom < mid ){  bottom = mid; }
     else if ( bottom<top ){ bottom++; }
     else{ break; } 
   }
}
>>>
   


\<htf replacement from charset\><<<
bottom = 0; top = charset_n; 
while( !found ){
   mid = (bottom + top) / 2;
   if( value == charset[mid].ch ){ 
      `<htf into 4hf`>
      found = TRUE;
   } else if( value < charset[mid].ch ){ 
      if( bottom == top ){ break; }
      top = mid;
   }
   else {
     if ( bottom < mid ){  bottom = mid; }
     else if ( bottom<top ){ bottom++; }
     else{ break; } 
   }
}
>>>


%%%%%%%%%%%%%%%%%%%%%%%
\Chapter{Utilities}
%%%%%%%%%%%%%%%%%%%%%%%%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Output Character}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%




\<header functions\><<<
static INTEGER insert_ch( ARG_I(int) );
>>>

\<functions\><<<
`[ 
static  INTEGER insert_ch(ch)    int ch
;{
   if( !ignore_chs ){ 
        BOOL flag;
     `<flag = empty next-str?`>
     if( !flag ){
        try_new_line();
        `<insert ch to text`>
        text_on = TRUE;          
   } }
   `<return char width`>
}
>>>




  /*   if (ch < 0) ch+=256; /*NEW */


\<flag = empty next-str?\><<<
flag = FALSE;
if( `<next-str`> ) {
  if( eq_str(next_str, "") ) {
    flag = TRUE;
    free((void *) next_str);
    next_str = (char *) 0;
} }
>>>



\<header functions\><<<
static void put_char( ARG_I(int) );
>>>

\<functions\><<<
`[
static void put_char( ch )   int ch
;{
  if(    !ignore_chs 
      && !( ((ch==' ') || (ch=='\n')) && no_root_file ) 
 ){ 
     `<open output file`>
     if( ch_map_flag ){
        if( special_on || ((ch != '\n') && (ch != ' ')) ){ 
            `<insert ch to ch-map`> }
     }else {
        if ( ch == '\n' ){ `<insert eoln ch`> }
        else if ( ch == ' ' ){ `<insert space ch`> }
        else { (IGNORED) put_4ht_ch( ch, cur_o_file ); }
} }  }
>>>

\<vars\><<<
static BOOL special_on = FALSE;
>>>



%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Output String}
%%%%%%%%%%%%%%%%%%%%%%%%%


\<header functions\><<<
static void print_f( ARG_I(const char*) );
>>>

\<functions\><<<
`[
static void print_f(str)    const char* str
;{
  `<open output file`>
  if( ch_map_flag ){  
     while( *str ){ put_char( *str );  str++; }
  }else {
    (IGNORED) print_f_4ht( str );
} }
>>>

% fprintf(cur_o_file, "%s", str);



\<header functions\><<<
static void print_f_4ht( ARG_I(const char*) );
>>>

\<functions\><<<
`[
static void print_f_4ht(str)    const char* str
;{
  `<open output file`>
  if( ch_map_flag ){  
     while( *str ){ put_char( *str );  str++; }
  } else {
     while( *str ){ 
        (IGNORED) put_4ht_ch( *str, cur_o_file );
        str++; 
} } }
>>>




%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Read Character}
%%%%%%%%%%%%%%%%%%%%%%%%%

\<header functions\><<<
static int get_char( ARG_I(void) );
>>>

\<functions\><<<
static int get_char(MYVOID) 
{                   
   return  (int) getc(dvi_file);
}
>>>


\<header functions\><<<
static int get_noop( ARG_I(void) );
>>>

\<functions\><<<
static int get_noop(MYVOID)
{      int ch;
  while(  (ch = get_char())  ==  `<no op`> ){;}
  return ch;
}
>>>



\Section{Read Strings}

\<header functions\><<<
static char* get_str( ARG_I(int) );
>>>

\<functions\><<<
`[
static char* get_str(n)      int n
;{                 U_CHAR *q, *p;
   p = q = m_alloc(char,n+1);
   while( n-- ) *q++ = get_char();
   *q = '\0';
   return p;
}
>>>


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Read Unsigned Integer}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

\<defines\><<<
#define get_unt(n)  fget_unt(dvi_file,n)
>>>

\<header functions\><<<
static long fget_unt( ARG_II(FILE*, int) );
>>>

\<functions\><<<
`[
static long fget_unt( file, n )
    FILE*     file`;
    register int  n

;{  register long val = 0;
  while( n-- ){ val = (val << 8) + (unsigned INTEGER) getc(file) ;  }
  return val;
} 
>>>

\Section{Read Signed Integer}



\<defines\><<<
#define get_int(n)  fget_int(dvi_file,n)
>>>

\<header functions\><<<
static long fget_int( ARG_II(FILE *, int) );
>>>

\<functions\><<<
`[
static long fget_int( file, n )
    FILE *file`;
    int   n

;{  register long val;
  val = (unsigned INTEGER) getc(file);
  if( val & 0x80 )     val -= 0x100;
  while( --n ){ val = (val << 8) + (unsigned INTEGER) getc(file); }
  return val;
} 
>>>

The implementation in dvi2ps takes the following form with the comment
``This code assumes that the right-shift is an arithmetic, rather than
logical, shift which will propagate the sign bit right.  According to
Kernighan and Ritchie, this is compiler dependent!''.


\Verbatim
val = getc(fp); 
n1 = n--;
while (n--) { val <<= 8;
              val |= getc(fp); }
val<<=32-8*n1;
val>>=32-8*n1;  /* sign extend */
\EndVerbatim




\<header functions\><<<
static long cond_int( ARG_I(register  INTEGER) );
>>>

\<functions\><<<
`[
static long cond_int( n )
    register INTEGER  n
;{  register long val;
    int  ch;
  val = (unsigned int) (ch = get_char());
  cond_idv_char( ch );  
  if( val & 0x80 )     val -= 0x100;  
  while( --n ){
    val = (val << 8) + (unsigned int) (ch = get_char()); 
    cond_idv_char( ch );  
  }
  return val;
} 
>>>

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Strings Equality}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


\<defines\><<<
#define eq_str(x,y) (!strcmp(x,y))
#define gt_str(x,y) (strcmp(x,y)>0)
>>>






\Section{Warnings and Errors}


\SubSection{Messages}

\<warn and err messages\><<<
`<command line options`>,                            `%0`%
"Can't find/open file ``%s'\n",                       `%1`%
"Can't open output file for ``%s'\n",                 `%2`%
"Can't close file ``%s' (file is not open)\n",        `%3`%
"Insufficient memory\n",                              `%4`%
"Bad character code: %d\n",                           `%5`%
"Can't find font number %d\n",                        `%6`%
"Improper dvi file\n",                                `%7`%
"Improper op while scanning font defs in postamble\n",`%8`%
"Problem with command line\n",                        `%9`%
"Font definition repeated in postamble\n",            `%10`%
"Empty entry in font environment variable\n",         `%11`%
"Can't access directory ``%s\n'",                     `%12`%
"Too many directories in font environment variable\n",`%13`%
"Missing fonts, can't proceed\n",                     `%14`%
"Invalid header in file ``%s'\n",                     `%15`%
"Checksum inconsistent\n",                            `%16`%
"MAXFONTS too small: %d\n",                           `%17`%
"Improper signature at end of file ``%s.htf'\n",      `%18`%
"Improper signature at start of file ``%s.htf'\n",    `%19`%
"Improper file ``%s.htf'\n",                          `%20`%
"Couldn't find font ``%s.htf' (char codes: ",        `%21`%
"File ``%s.htf' starts/ends with character code %d (instead of %d)\n",`%22`%
"Implementation problem\n",                           `%23`%
"Improper groups in \\special{t4ht+}... idv[%d]\n",   `%24`%
"Too many characters (> %d) for map line: ``%c'\n",   `%25`%
"Extra characters in \\special{t4ht%c...",            `%26`%
"Page break within a ch map/picture\n",               `%27`%
"Char code >255 in htf file: %d\n",                   `%28`%
"Improper char for code in htf file: %c\n",           `%29`%
`<signals messages: 30-32`>                           `%30-32`%
#ifdef DOS_WIN32
"%c-script too long in tex4ht.env \n",                `%33`%
#else
"%c-script too long in tex4ht.env (.tex4ht)\n",       `%33`%
#endif
"Too many rows (> %d) for map: ``%c'\n",              `%34`%
"More than 256 strings in font\n",                    `%35`%
"\\special{t4ht;%c...}?\n",                           `%36`%
"\\special{t4ht;|%s}?\n",                             `%37`%
"\\special{t4ht~!%s}?\n",                             `%38`%
"\\special{t4ht\"...%s}?\n",                          `%39`%
"System error 40\n",                                  `%40`%
"``%c' in \\special{t4ht@...} or \\special{t4ht@-...}?\n",   `%41`%
"\\special{t4ht~...} without \\special{t4ht~}\n",     `%42`%
"Ignoring \\special{t4ht.%s}\n",                      `%43`%
"PUSH for \\special{t4ht<...%s}?\n",                  `%44`%
"Bad character code (%d) in \\special{t4h~}...\n",    `%45`%
"Page break in \\special{t4h~}...\n",                 `%46`%
"tex4ht.fls: Couldn't find file ``%s'\n",             `%47`%
"Improper entry (line %d)\n",                         `%48`%
"Improper environment variable %s: ``%s'\n",           `%49`%
"Missing %s\n",                                       `%50`%
"Can't back from file ``%s\n'",                        `%51`%
"\\special{t4ht%s}?\n",                               `%52`%
"Improper -v option\n",                               `%53`%
>>>

\<vars\><<<
static const U_CHAR *warn_err_mssg[]={ `<warn and err messages`> "" };
>>>


\SubSection{Warnings Commands}

\<header functions\><<<
static void warn_i( ARG_I(int) );
>>>

\<functions\><<<
`[
static  void warn_i(n)     int  n
;{  (IGNORED) fprintf(stderr,"--- warning --- ");
   (IGNORED) fprintf(stderr, "%s", warn_err_mssg[n]);
   show_err_context();
}
>>>

\<warning(22\><<<
(IGNORED) fprintf(stderr,"--- warning --- ");
(IGNORED) fprintf(stderr, warn_err_mssg[22]
>>>

% \<vars\><<< 
% static U_CHAR warning[] = "--- warning --- ";
% >>>



\<header functions\><<<
static void warn_i_int( ARG_II(int,int) );
>>>

\<functions\><<<
`[
static void warn_i_int(n,i)   int  n`; int i

;{  (IGNORED) fprintf(stderr,"--- warning --- ");
   (IGNORED) fprintf(stderr, warn_err_mssg[n], i);
   show_err_context();
}
>>>



\<header functions\><<<
static void warn_i_int_2( ARG_III(int,int,int) );
>>>

\<functions\><<<
`[
static void warn_i_int_2(n,i,j)   int  n`; int i`; int j

;{  (IGNORED) fprintf(stderr,"--- warning --- ");
   (IGNORED) fprintf(stderr, warn_err_mssg[n], i, j);
   show_err_context();
}
>>>



\<header functions\><<<
static void warn_i_str( ARG_II(int,const char *) );
>>>

\<functions\><<<
`[
static void warn_i_str(n,str) 
    int  n`;
    const char *str

;{  
   (IGNORED) fprintf(stderr,"--- warning --- ");
   (IGNORED) fprintf(stderr,warn_err_mssg[n], str);
   show_err_context();
}
>>>




\<header functions\><<<
static void warn_i_str2( ARG_III(int,const char *,const char *) );
>>>

\<functions\><<<
`[
static void warn_i_str2(n,str1,str2) 
    int  n`;
    const char *str1`;
    const char *str2

;{  (IGNORED) fprintf(stderr,"--- warning --- ");
   (IGNORED) fprintf(stderr,warn_err_mssg[n], str1,str2);
   show_err_context();
}
>>>


\SubSection{Error Commands}




\<defines\><<<
#define bad_arg            err_i(0)
#define bad_in_file(name)   err_i_str(1,name)
#define bad_out_file(name)  err_i_str(2,name)
#define bad_special(name)   warn_i_str(3,name)
#define bad_mem             err_i(4)
#define bad_char(chr)       warn_i_int(5,chr)
#define bad_dvi             err_i(7)
>>>


\<header functions\><<<
static void err_i( ARG_I(int) );
>>>

\<functions\><<<
`[
static void err_i(n)      int  n

;{  (IGNORED) fprintf(stderr,"--- error --- ");
   (IGNORED) fprintf(stderr, "%s", warn_err_mssg[n]);
   show_err_context();
   exit(EXIT_FAILURE);  
}
>>>

REPLACE EXIT with somthing that DOS also accept.

\<header functions\><<<
static void err_i_int( ARG_II(int,int) );
>>>

\<functions\><<<
`[
static void err_i_int(n,i)     int  n`;  int i

;{  (IGNORED) fprintf(stderr,"--- error --- ");
   (IGNORED) fprintf(stderr, warn_err_mssg[n], i);
   show_err_context();
   exit(EXIT_FAILURE);  
}
>>>


\<header functions\><<<
static void err_i_str( ARG_II(int,char *) );
>>>

\<functions\><<<
`[
static void err_i_str(n,str) 
     int  n`;
     U_CHAR *str

;{  (IGNORED) fprintf(stderr,"--- error --- ");
   (IGNORED) fprintf(stderr, warn_err_mssg[n], str);
   show_err_context();
   exit(EXIT_FAILURE);  
}
>>>

\SubSection{Extra Characters in Special}




\<check for extra special chars\><<<
if( special_n > 0 ){
   warn_i_int( 26, sv);  
   while( special_n-- )  (IGNORED) putc( get_char(), stderr);
}
>>>

\<special resolution err\><<<
warn_i_int( 26, '!');
(IGNORED) putc( ch, stderr);
while( special_n-- )  (IGNORED) putc( get_char(), stderr);
>>>



\<consume unused specials\><<<
while( special_n-- )  (void) get_char();
>>>


\<unused special\><<<
;
>>>


\<header functions\><<<
static void show_err_context( ARG_I(void) );
>>>

\<functions\><<<
static void show_err_context(MYVOID) 
{                             long  curr_pos;
                              int n, i;
                              U_CHAR ch;
   if( err_context ){
     curr_pos = ftell(dvi_file); 
     for(n=6; n--;){
        (IGNORED) putc( '\n', stderr );
        for(i=70; i--;){
          ch = get_char();
          (IGNORED) putc(( (ch>31) && (ch<127))? ch : ' ', stderr);
        }      
     }
     (IGNORED) fseek(dvi_file, curr_pos, `<abs file addr`>);
     (IGNORED) putc( '\n', stderr ); (IGNORED) putc( '\n', stderr );      
     if( err_mark ){  print_f( err_mark ); }
}  }
>>>



A static informs that the function is defined just locally, preventing
possible errors when the linker detects name conflicts with definitions
that use the same names in other libraries.

\<static\><<<
static 
>>>

\<vars\><<<
static BOOL err_context = FALSE;
>>>

\<context for warn and errs\><<<
err_context = TRUE;
>>>








\SubSection{Trace Errors}

\<vars\><<<
static U_CHAR *err_mark = (char *) 0;
>>>

\<get err str\><<<
if( err_mark ){ free((void *)  err_mark); }
if( special_n ){
   err_mark = get_str( (int) special_n );  special_n=0;
} else { err_mark = (char *) 0; }
>>>



\SubSection{Trace Specials}


\<trace specials in dvi\><<<
trace_special = TRUE;
>>>

\<vars\><<<
static BOOL trace_special = FALSE;
>>>


On off with \''\special{t4ht@/}' 

\<on/off special trace\><<<
trace_special = !trace_special;
>>>


\<trace specials\><<<
{                             long  curr_pos;
                              int n, i;
                              U_CHAR ch;
   
   curr_pos = ftell(dvi_file); 
   print_f("\nSPECIAL:  ");  ch = special_hd[8]; i=60;
   for( n=*special_n - 3; n--;){
      if( !i ){ (IGNORED) putc( '\n', cur_o_file );   i=70; }
      else i--;
      (IGNORED) putc(( (ch>31) && (ch<127))? ch : ' ', cur_o_file);
      ch = get_char();
   }
   (IGNORED) putc( '\n', cur_o_file );
   (IGNORED) fseek(dvi_file, curr_pos, `<abs file addr`>);
}
>>>






\Section{Dos}


\List{disc}

\item
\''open(file, ..._FLAGS)': All
text files should be opened with "r" or "w"; all binary files with "rb"
or "wb". This is the portable way and will work both under Unix and DOS;
as Unix doesn't distinguish between text and binary files, its compilers
will simply ignore the "b" part.

Unix doesn't differentiate between binary  binary and text files.


 In general, the rule of thumb is that DOS/Windows ports should recognize 
 both back- and forward-slashes in their input (such as command-line 
 arguments), but can construct file names by using forward slashes alone 
 (since DOS/Windows kernels support both styles).

  On the subject of the .lg file: you open the tex4ht.env file in binary
mode ("rb"), which results in strange line endings in the .lg file
(CR/CR/LF). Changing the mode to "r" fixes this.

\''(WRITE_BIN_FLAGS, READ_BIN_FLAGS)': Use  binary mode with DJGPP.      ---captured with the \''__MSDOS__'.


\<defines\><<<
#if defined(DOS_WIN32) || defined(__MSDOS__)
#define READ_BIN_FLAGS "rb"
#define READ_TEXT_FLAGS "r"
#define WRITE_BIN_FLAGS "wb"
#ifdef WIN32
#define WRITE_TEXT_FLAGS "wb"
#else
#define WRITE_TEXT_FLAGS "w"
#endif
#else
#define READ_BIN_FLAGS "r"
#define READ_TEXT_FLAGS "r"
#define WRITE_BIN_FLAGS "w"
#define WRITE_TEXT_FLAGS "w"
#endif
>>>



\Verbatim
I've been held up a bit by a
bug in tex4ht.c that caused emTeX to complain that the created .idv file
was corrupt:

*** Fatal error 2106: corrupt DVI file (postamble not found)

  I found the cause, though: you open it with mode "w", which is text
mode. Changing this to "wb" solved the problem.
\EndVerbatim


\item Argument types in declaration of functions

Function prototypes

\<tex4ht.h\><<<
#ifdef DOS
#define PROTOTYP
#endif
#ifdef ANSI
#define PROTOTYP
#endif
#ifdef KWIN32
#define PROTOTYP
#endif
>>>

\<defines\><<<
#ifdef PROTOTYP
#define MYVOID void
#define ARG_I(x) x
#define ARG_II(x,y) x,y
#define ARG_III(x,y,z) x,y,z
#define ARG_IV(x,y,z,w) x,y,z,w
#define ARG_V(x,y,z,w,v) x,y,z,w,v
#define ARG_VI(x,y,z,w,v,u) x,y,z,w,v,u
#define ARG_VII(x,y,z,w,v,u,t) x,y,z,w,v,u,t
#else
#define MYVOID 
#define ARG_I(x) 
#define ARG_II(x,y) 
#define ARG_III(x,y,z) 
#define ARG_IV(x,y,z,w) 
#define ARG_V(x,y,z,w,v)
#define ARG_VI(x,y,z,w,v,u) 
#define ARG_VII(x,y,z,w,v,u,t) 
#endif
>>>

\EndList

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\Section{Op Codes of Dvi}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%



\<insert rule + move op\><<<
132 >>>



\<insert rule + nomove op\><<<
137 >>>

\<no op\><<<
138 >>>

\<start page op\><<<
139 >>>

\<end page op\><<<
140 >>>

\<sv loc op\><<<
141 >>>

\<retrieve loc op\><<<
142 >>>

\<mv hor 1-byte\><<<
143 >>>

\<mv hor 2-byte\><<<
144 >>>

\<mv hor 3-byte\><<<
145 >>>

\<mv hor 4-byte\><<<
146 >>>

\<mv hor dist dx.1\><<<
147 >>>

\<dx.1 store and mv hor 1-byte\><<<
148 >>>

\<dx.1 store and mv hor 2-byte\><<<
149 >>>

\<dx.1 store and mv hor 3-byte\><<<
150 >>>

\<dx.1 store and mv hor 4-byte\><<<
151 >>>

\<mv hor dist dx.2\><<<
152 >>>

\<dx.2 store and mv hor 1-byte\><<<
153  >>>

\<dx.2 store and mv hor 2-byte\><<<
154  >>>

\<dx.2 store and mv hor 3-byte\><<<
155 >>>

\<dx.2 store and mv hor 4-byte\><<<
156 >>>

\<mv ver 1-byte\><<<
157 >>>

\<mv ver 2-byte\><<<
158 >>>

\<mv ver 3-byte\><<<
159 >>>

\<mv ver 4-byte\><<<
160 >>>

\<mv ver dist dy.1\><<<
161 >>>

\<dy.1 store and mv ver 1-byte\><<<
162 >>>

\<dy.1 store and mv ver 2-byte\><<<
163  >>>

\<dy.1 store and mv ver 3-byte\><<<
164 >>>

\<dy.1 store and mv ver 4-byte\><<<
165 >>>

\<mv ver dist dy.2\><<<
166  >>>

\<dy.2 store and mv ver 1-byte\><<<
167 >>>

\<dy.2 store and mv ver 2-byte\><<<
168 >>>

\<dy.2 store and mv ver 3-byte\><<<
169 >>>

\<dy.2 store and mv ver 4-byte\><<<
170 >>>


\<font 0\><<<
171  >>>

\<eof op\><<<
223 >>>

\<font 63\><<<
234  >>>

\<number of direct fonts\><<<
63 >>>

\<font 1-byte\><<<
235  >>>

\<font 2-bytes\><<<
236  >>>

\<font 3-bytes\><<<
237  >>>

\<font int\><<<
238  >>>

\<special 1\><<<
239 >>>
\<special 2\><<<
240 >>>
\<special 3\><<<
241 >>>
\<special 4\><<<
242 >>>


\<def 1 byte font\><<<
243 >>>

\<def 2 byte font\><<<
244 >>>

\<def 3 byte font\><<<
245 >>>

\<def 4 byte font\><<<
246 >>>

\<start preamble op\><<<
247 >>>

\<begin-postamble op\><<<
248 >>>

\<end-postamble op\><<<
249 >>>




\<start of preamble op\><<<
247 >>>



The ops 250--255 have no meaning in dvi.



\<xdv-pic-file op\><<<
251 
>>>



\<xdv-native-font-def op\><<<
252 
>>>



\<xdv-glyph-array op\><<<
253 
>>>


\<xdv-glyph-string op\><<<
254 
>>>



%%%%%%%%%%%%%%%%%%
\Chapter{References}
%%%%%%%%%%%%%%%%%%



\Link[http://www.eskimo.com/\string~scs/C-faq/top.html]{}{}comp.lang.c\EndLink
{ \tt --}
\Link[http://www.cs.tut.fi/\string~leopold/Boar/AnsiLib]{}{}AnsiLib\EndLink



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


%%%Line break needed for #defines !!!!






\Comment{
/*}{*/
}
\ifx \export\:UnDef \else    
\Comment{   
}{}
\fi


             \OutputCodE\<tex4ht.c\>        


\bye