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
|
/*
Copyright (c) 2008-2017 jerome DOT laurens AT u-bourgogne DOT fr
This file is part of the SyncTeX package.
Latest Revision: Thu Mar 9 21:26:27 UTC 2017
Version: 1.19
See synctex_parser_readme.txt for more details
License:
--------
Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without
restriction, including without limitation the rights to use,
copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the
Software is furnished to do so, subject to the following
conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
OTHER DEALINGS IN THE SOFTWARE
Except as contained in this notice, the name of the copyright holder
shall not be used in advertising or otherwise to promote the sale,
use or other dealings in this Software without prior written
authorization from the copyright holder.
Acknowledgments:
----------------
The author received useful remarks from the pdfTeX developers, especially Hahn The Thanh,
and significant help from XeTeX developer Jonathan Kew
Nota Bene:
----------
If you include or use a significant part of the synctex package into a software,
I would appreciate to be listed as contributor and see "SyncTeX" highlighted.
*/
/* We assume that high level application like pdf viewers will want
* to embed this code as is. We assume that they also have locale.h and setlocale.
* For other tools such as TeXLive tools, you must define SYNCTEX_USE_LOCAL_HEADER,
* when building. You also have to create and customize synctex_parser_local.h to fit your system.
* In particular, the HAVE_LOCALE_H and HAVE_SETLOCALE macros should be properly defined.
* With this design, you should not need to edit this file. */
/**
* \file synctex_parser.c
* \brief SyncTeX file parser and controller.
* - author: Jérôme LAURENS
* \version 1.19
* \date Mon Apr 24 07:08:56 UTC 2017
*
* Reads and parse *.synctex[.gz] files,
* performs edit and display queries.
*
* See
* - synctex_scanner_new_with_output_file
* - synctex_scanner_parse
* - synctex_scanner_free
* - synctex_display_query
* - synctex_edit_query
* - synctex_next_result
* - synctex_reset_result
*
* The data is organized in a graph with multiple entries.
* The root object is a scanner, it is created with the contents on a synctex file.
* Each node of the tree is a synctex_node_t object.
* There are 3 subtrees, two of them sharing the same leaves.
* The first tree is the list of input records, where input file names are associated with tags.
* The second tree is the box tree as given by TeX when shipping pages out.
* First level objects are sheets and forms, containing boxes, glues, kerns...
* The third tree allows to browse leaves according to tag and line.
*/
# if defined(SYNCTEX_USE_LOCAL_HEADER)
# include "synctex_parser_local.h"
# else
# define HAVE_LOCALE_H 1
# define HAVE_SETLOCALE 1
# if defined(_MSC_VER)
# define SYNCTEX_INLINE __inline
# else
# define SYNCTEX_INLINE inline
# endif
# endif
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <limits.h>
#if defined(HAVE_LOCALE_H)
#include <locale.h>
#endif
#include "synctex_parser_private.h"
SYNCTEX_INLINE static int _synctex_abs(int x) {
return x>0? x: -x;
}
/* These are the possible extensions of the synctex file */
const char * synctex_suffix = ".synctex";
const char * synctex_suffix_gz = ".gz";
typedef synctex_node_p(*synctex_node_new_f)(synctex_scanner_p);
typedef void(*synctex_node_fld_f)(synctex_node_p);
typedef char *(*synctex_node_str_f)(synctex_node_p);
/**
* Pseudo class.
* - author: J. Laurens
*
* Each nodes has a class, it is therefore called an object.
* Each class has a unique scanner.
* Each class has a type which is a unique identifier.
* Each class has a node mask which identifies node's attributes.
* Each class has an info mask which info's attributes.
* The class points to various methods,
* each of them vary amongst objects.
* The navigator records the offsets of the tree members getters.
* The modelator records the offsets of the data members getters, relative to the last navigator getter.
*/
typedef struct synctex_tree_model_t {
int sibling;
int parent;
int child;
int friend;
int last;
int next_hbox;
int arg_sibling;
int target;
int size;
} synctex_tree_model_s;
typedef const synctex_tree_model_s * synctex_tree_model_p;
typedef struct synctex_data_model_t {
int tag;
int line;
int column;
int h;
int v;
int width;
int height;
int depth;
int mean_line;
int weight;
int h_V;
int v_V;
int width_V;
int height_V;
int depth_V;
int name;
int page;
int size;
} synctex_data_model_s;
static const synctex_data_model_s synctex_data_model_none = {
-1, /* tag */
-1, /* line */
-1, /* column */
-1, /* h */
-1, /* v */
-1, /* width */
-1, /* height */
-1, /* depth */
-1, /* mean_line */
-1, /* weight */
-1, /* h_V */
-1, /* v_V */
-1, /* width_V */
-1, /* height_V */
-1, /* depth_V */
-1, /* name */
-1, /* page */
0
};
typedef const synctex_data_model_s * synctex_data_model_p;
typedef int (*synctex_int_getter_f)(synctex_node_p);
typedef struct synctex_tlcpector_t {
synctex_int_getter_f tag;
synctex_int_getter_f line;
synctex_int_getter_f column;
} synctex_tlcpector_s;
typedef const synctex_tlcpector_s * synctex_tlcpector_p;
static int _synctex_int_none(synctex_node_p node) {
# ifdef __DARWIN_UNIX03
# pragma unused(node)
# endif
return 0;
}
static const synctex_tlcpector_s synctex_tlcpector_none = {
&_synctex_int_none, /* tag */
&_synctex_int_none, /* line */
&_synctex_int_none, /* column */
};
typedef struct synctex_inspector_t {
synctex_int_getter_f h;
synctex_int_getter_f v;
synctex_int_getter_f width;
synctex_int_getter_f height;
synctex_int_getter_f depth;
} synctex_inspector_s;
typedef const synctex_inspector_s * synctex_inspector_p;
static const synctex_inspector_s synctex_inspector_none = {
&_synctex_int_none, /* h */
&_synctex_int_none, /* v */
&_synctex_int_none, /* width */
&_synctex_int_none, /* height */
&_synctex_int_none, /* depth */
};
typedef float (*synctex_float_getter_f)(synctex_node_p);
typedef struct synctex_vispector_t {
synctex_float_getter_f h;
synctex_float_getter_f v;
synctex_float_getter_f width;
synctex_float_getter_f height;
synctex_float_getter_f depth;
} synctex_vispector_s;
static float _synctex_float_none(synctex_node_p node) {
# ifdef __DARWIN_UNIX03
# pragma unused(node)
# endif
return 0;
}
static const synctex_vispector_s synctex_vispector_none = {
&_synctex_float_none, /* h */
&_synctex_float_none, /* v */
&_synctex_float_none, /* width */
&_synctex_float_none, /* height */
&_synctex_float_none, /* depth */
};
typedef const synctex_vispector_s * synctex_vispector_p;
struct synctex_class_t {
synctex_scanner_p scanner;
synctex_node_type_t type;
synctex_node_mask_t node_mask;
synctex_node_new_f new;
synctex_node_fld_f free;
synctex_node_fld_f log;
synctex_node_fld_f display;
synctex_node_str_f abstract;
synctex_tree_model_p navigator;
synctex_data_model_p modelator;
synctex_tlcpector_p tlcpector;
synctex_inspector_p inspector;
synctex_vispector_p vispector;
};
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Abstract OBJECTS and METHODS
# endif
/**
* \def SYNCTEX_TYPE
* \brief Get the type of the argument.
* - parameter NODE: of type synctex_node_p
* - returns: A synctex_node_type_t, synctex_node_type_none for NULL param
*/
# define SYNCTEX_TYPE(NODE) ((NODE)?(((NODE)->class)->type):synctex_node_type_none)
/**
* \def SYNCTEX_NODE_MASK
* \brief Get the node mask of the argument.
* - parameter NODE: of type synctex_node_p
* - returns: A synctex_node_mask_t, 0 for NULL param
*/
# define SYNCTEX_NODE_MASK(NODE) ((NODE)?(((NODE)->class)->node_mask):0)
# define SYNCTEX_IS_BOX(NODE)\
((SYNCTEX_NODE_MASK(NODE)&synctex_mask_box)!=0)
# define SYNCTEX_IS_PROXY(NODE)\
(SYNCTEX_NODE_MASK(NODE)&synctex_mask_proxy)
/**
* Checks if a message can be sent to a node.
* - parameter NODE: of type synctex_node_p
* - parameter SELECTOR: one of the class pointer properties
* - returns: yorn
*/
# define SYNCTEX_CAN_PERFORM(NODE,SELECTOR)\
((NODE) && ((((NODE)->class))->SELECTOR))
# define SYNCTEX_NAV_CAN_PERFORM(NODE,SELECTOR)\
((NODE) && (((((NODE)->class)->navigator))->SELECTOR>=0))
# define SYNCTEX_DATA_CAN_PERFORM(NODE,SELECTOR)\
((NODE) && (((((NODE)->class)->modelator))->SELECTOR>=0))
/**
* \def SYNCTEX_MSG_SEND
* \brief Takes care of sending the given message if possible.
* - parameter NODE: of type synctex_node_p
* - parameter SELECTOR: one of the class pointer properties
*/
# define SYNCTEX_MSG_SEND(NODE,SELECTOR) do {\
synctex_node_p N__ = NODE;\
if (N__ && SYNCTEX_CAN_PERFORM(N__,SELECTOR)) {\
(*(((N__)->class)->SELECTOR))(N__);\
}\
} while (0)
/**
* Free the given node by sending the free message.
* - parameter NODE: of type synctex_node_p
*/
void synctex_node_free(synctex_node_p node) {
SYNCTEX_MSG_SEND(node,free);
}
#define synctex_NON_NULL_node_p synctex_node_p
/**
* The next macros are used to access the node tree info
* SYNCTEX_DATA(node) points to the first synctex integer or pointer data of node
* SYNCTEX_DATA(node)[index] is the information at index
* for example, the page of a sheet is stored in SYNCTEX_DATA(sheet)[_synctex_data_page_idx]
* - parameter NODE: of type synctex_node_p
* If the name starts with "__", the argument is nonullable
*/
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Tree SETGET
# endif
#if SYNCTEX_DEBUG > 1000
#define DEFINE_SYNCTEX_TREE_HAS(WHAT)\
static synctex_bool_t _synctex_tree_has_##WHAT(synctex_node_p node) {\
if (node) {\
if (node->class->navigator->WHAT>=0) {\
return (0==0); \
} else {\
printf("WARNING: NO tree %s for %s\n", #WHAT, synctex_node_isa(node));\
}\
}\
return 0 == 1;\
}
#else
#define DEFINE_SYNCTEX_TREE_HAS(WHAT) \
static synctex_bool_t _synctex_tree_has_##WHAT(synctex_node_p node) {\
return (node && (node->class->navigator->WHAT>=0));\
}
#endif
# define DEFINE_SYNCTEX_TREE__GET(WHAT) \
SYNCTEX_INLINE static synctex_node_p __synctex_tree_##WHAT(synctex_NON_NULL_node_p node) {\
return node->data[node->class->navigator->WHAT].as_node;\
}
# define DEFINE_SYNCTEX_TREE_GET(WHAT) \
DEFINE_SYNCTEX_TREE__GET(WHAT) \
static synctex_node_p _synctex_tree_##WHAT(synctex_node_p node) {\
if (_synctex_tree_has_##WHAT(node)) {\
return __synctex_tree_##WHAT(node);\
}\
return 0;\
}
# define DEFINE_SYNCTEX_TREE__RESET(WHAT) \
SYNCTEX_INLINE static synctex_node_p __synctex_tree_reset_##WHAT(synctex_NON_NULL_node_p node) {\
synctex_node_p old = node->data[node->class->navigator->WHAT].as_node;\
node->data[node->class->navigator->WHAT].as_node=NULL;\
return old;\
}
# define DEFINE_SYNCTEX_TREE_RESET(WHAT) \
DEFINE_SYNCTEX_TREE__RESET(WHAT) \
SYNCTEX_INLINE static synctex_node_p _synctex_tree_reset_##WHAT(synctex_node_p node) {\
if (_synctex_tree_has_##WHAT(node)) {\
return __synctex_tree_reset_##WHAT(node);\
}\
return NULL;\
}
# define DEFINE_SYNCTEX_TREE__SET(WHAT) \
SYNCTEX_INLINE static synctex_node_p __synctex_tree_set_##WHAT(synctex_NON_NULL_node_p node, synctex_node_p new_value) {\
synctex_node_p old = __synctex_tree_##WHAT(node);\
node->data[node->class->navigator->WHAT].as_node=new_value;\
return old;\
}
# define DEFINE_SYNCTEX_TREE_SET(WHAT) \
DEFINE_SYNCTEX_TREE__SET(WHAT) \
SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_##WHAT(synctex_node_p node, synctex_node_p new_value) {\
return _synctex_tree_has_##WHAT(node)?\
__synctex_tree_set_##WHAT(node,new_value):NULL;\
}
# define DEFINE_SYNCTEX_TREE__GETSETRESET(WHAT) \
DEFINE_SYNCTEX_TREE__GET(WHAT) \
DEFINE_SYNCTEX_TREE__SET(WHAT) \
DEFINE_SYNCTEX_TREE__RESET(WHAT)
# define DEFINE_SYNCTEX_TREE_GETSET(WHAT) \
DEFINE_SYNCTEX_TREE_HAS(WHAT) \
DEFINE_SYNCTEX_TREE_GET(WHAT) \
DEFINE_SYNCTEX_TREE_SET(WHAT)
# define DEFINE_SYNCTEX_TREE_GETRESET(WHAT) \
DEFINE_SYNCTEX_TREE_HAS(WHAT) \
DEFINE_SYNCTEX_TREE_GET(WHAT) \
DEFINE_SYNCTEX_TREE_RESET(WHAT)
# define DEFINE_SYNCTEX_TREE_GETSETRESET(WHAT) \
DEFINE_SYNCTEX_TREE_HAS(WHAT) \
DEFINE_SYNCTEX_TREE_GET(WHAT) \
DEFINE_SYNCTEX_TREE_SET(WHAT) \
DEFINE_SYNCTEX_TREE_RESET(WHAT)
DEFINE_SYNCTEX_TREE__GETSETRESET(sibling)
DEFINE_SYNCTEX_TREE_GETSETRESET(parent)
DEFINE_SYNCTEX_TREE_GETSETRESET(child)
DEFINE_SYNCTEX_TREE_GETSETRESET(friend)
DEFINE_SYNCTEX_TREE_GETSET(last)
DEFINE_SYNCTEX_TREE_GETSET(next_hbox)
DEFINE_SYNCTEX_TREE_GETSET(arg_sibling)
DEFINE_SYNCTEX_TREE_GETSET(target)
SYNCTEX_INLINE static synctex_node_p _synctex_tree_setup_target(synctex_node_p node, synctex_node_p target) {
synctex_node_p old = _synctex_tree_target(node);
synctex_node_p beyond = _synctex_tree_target(target);
_synctex_tree_set_target(node,beyond?beyond:target);
return old;
}
/**
* Free the given node.
* - parameter node: of type synctex_node_p
* - note: a node is meant to own its child and sibling.
* It is not owned by its parent, unless it is its first child.
* This destructor is for all nodes with children.
*/
static void _synctex_free_node(synctex_node_p node) {
if (node) {
synctex_node_free(__synctex_tree_sibling(node));
synctex_node_free(_synctex_tree_child(node));
_synctex_free(node);
}
return;
}
#define SYNCTEX_HAS_CHILDREN(NODE) (NODE && _synctex_tree_child(NODE))
/**
* Free the given node.
* - parameter node: of type synctex_node_p
* - note: a node is meant to own its child and sibling.
* It is not owned by its parent, unless it is its first child.
* This destructor is for all nodes with no children.
*/
static void _synctex_free_leaf(synctex_node_p node) {
if (node) {
synctex_node_free(__synctex_tree_sibling(node));
_synctex_free(node);
}
return;
}
# ifdef __SYNCTEX_WORK__
# include "/usr/include/zlib.h"
# else
# include <zlib.h>
# endif
#ifdef NOTHING
#pragma mark -
#pragma mark SCANNER
#endif
/**
* The synctex scanner is the root object.
* Is is initialized with the contents of a text file or a gzipped file.
* The buffer_.* are first used to parse the text.
*/
struct synctex_scanner_t {
gzFile file; /* The (possibly compressed) file */
SYNCTEX_DECLARE_CHAR_OFFSET;
char * buffer_cur; /* current location in the buffer */
char * buffer_start; /* start of the buffer */
char * buffer_end; /* end of the buffer */
char * output_fmt; /* dvi or pdf, not yet used */
char * output; /* the output name used to create the scanner */
char * synctex; /* the .synctex or .synctex.gz name used to create the scanner */
synctex_iterator_p iterator;/* result iterator */
int version; /* 1, not yet used */
struct {
unsigned has_parsed:1; /* Whether the scanner has parsed its underlying synctex file. */
unsigned postamble:1; /* Whether the scanner has parsed its underlying synctex file. */
unsigned reserved:sizeof(unsigned)-2; /* alignment */
} flags;
int pre_magnification; /* magnification from the synctex preamble */
int pre_unit; /* unit from the synctex preamble */
int pre_x_offset; /* X offset from the synctex preamble */
int pre_y_offset; /* Y offset from the synctex preamble */
int count; /* Number of records, from the synctex postamble */
float unit; /* real unit, from synctex preamble or post scriptum */
float x_offset; /* X offset, from synctex preamble or post scriptum */
float y_offset; /* Y Offset, from synctex preamble or post scriptum */
synctex_node_p input; /* The first input node, its siblings are the other input nodes */
synctex_node_p sheet; /* The first sheet node, its siblings are the other sheet nodes */
synctex_node_p form; /* The first form, its siblings are the other forms */
synctex_node_p ref_in_sheet; /* The first form ref node in sheet, its friends are the other form ref nodes */
synctex_node_p ref_in_form; /* The first form ref node, its friends are the other form ref nodes in sheet */
int number_of_lists; /* The number of friend lists */
synctex_node_r lists_of_friends;/* The friend lists */
synctex_class_s class[synctex_node_number_of_types]; /* The classes of the nodes of the scanner */
int lastv; /* last vertical position read, for compression purpose */
int line_number;
int display_switcher;
char * display_prompt;
};
/**
* Create a new node of the given type.
* - parameter scanner: of type synctex_node_p
* - parameter type: a type, the client is responsible
* to ask for an acceptable type.
*/
synctex_node_p synctex_node_new(synctex_scanner_p scanner, synctex_node_type_t type) {
return scanner? scanner->class[type].new(scanner):NULL;
}
/**
SYNCTEX_CUR, SYNCTEX_START and SYNCTEX_END are convenient shortcuts
*/
# define SYNCTEX_CUR (scanner->buffer_cur)
# define SYNCTEX_START (scanner->buffer_start)
# define SYNCTEX_END (scanner->buffer_end)
/* Here are gathered all the possible status that the next scanning functions will return.
* All these functions return a status, and pass their result through pointers.
* Negative values correspond to errors.
* The management of the buffer is causing some significant overhead.
* Every function that may access the buffer returns a status related to the buffer and file state.
* status >= SYNCTEX_STATUS_OK means the function worked as expected
* status < SYNCTEX_STATUS_OK means the function did not work as expected
* status == SYNCTEX_STATUS_NOT_OK means the function did not work as expected but there is still some material to parse.
* status == SYNCTEX_STATUS_EOF means the function did not work as expected and there is no more material.
* status<SYNCTEX_STATUS_EOF means an error
*/
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark STATUS
# endif
/* When the end of the synctex file has been reached: */
# define SYNCTEX_STATUS_EOF 0
/* When the function could not return the value it was asked for: */
# define SYNCTEX_STATUS_NOT_OK (SYNCTEX_STATUS_EOF+1)
/* When the function returns the value it was asked for:
It must be the biggest one */
# define SYNCTEX_STATUS_OK (SYNCTEX_STATUS_NOT_OK+1)
/* Generic error: */
# define SYNCTEX_STATUS_ERROR (SYNCTEX_STATUS_EOF-1)
/* Parameter error: */
# define SYNCTEX_STATUS_BAD_ARGUMENT (SYNCTEX_STATUS_ERROR-1)
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Decoding prototypes
# endif
typedef struct {
int integer;
synctex_status_t status;
} synctex_is_s;
static synctex_is_s _synctex_decode_int(synctex_scanner_p scanner);
static synctex_is_s _synctex_decode_int_opt(synctex_scanner_p scanner, int default_value);
static synctex_is_s _synctex_decode_int_v(synctex_scanner_p scanner);
typedef struct {
char * string;
synctex_status_t status;
} synctex_ss_s;
static synctex_ss_s _synctex_decode_string(synctex_scanner_p scanner);
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Data SETGET
# endif
/**
* The next macros are used to access the node data info
* SYNCTEX_DATA(node) points to the first synctex integer or pointer data of node
* SYNCTEX_DATA(node)[index] is the information at index
* for example, the page of a sheet is stored in SYNCTEX_DATA(sheet)[_synctex_data_page_idx]
* - parameter NODE: of type synctex_node_p
*/
# define SYNCTEX_DATA(NODE) ((*((((NODE)->class))->info))(NODE))
#if defined SYNCTEX_DEBUG > 1000
# define DEFINE_SYNCTEX_DATA_HAS(WHAT) \
SYNCTEX_INLINE static synctex_bool_t __synctex_data_has_##WHAT(synctex_node_p node) {\
return (node && (node->class->modelator->WHAT>=0));\
}\
SYNCTEX_INLINE static synctex_bool_t _synctex_data_has_##WHAT(synctex_node_p node) {\
if (node && (node->class->modelator->WHAT<0)) {\
printf("WARNING: NO %s for %s\n", #WHAT, synctex_node_isa(node));\
}\
return __synctex_data_has_##WHAT(node);\
}
#else
# define DEFINE_SYNCTEX_DATA_HAS(WHAT) \
SYNCTEX_INLINE static synctex_bool_t __synctex_data_has_##WHAT(synctex_node_p node) {\
return (node && (node->class->modelator->WHAT>=0));\
}\
SYNCTEX_INLINE static synctex_bool_t _synctex_data_has_##WHAT(synctex_node_p node) {\
return __synctex_data_has_##WHAT(node);\
}
#endif
SYNCTEX_INLINE static synctex_data_p __synctex_data(synctex_node_p node) {
return node->data+node->class->navigator->size;
}
# define DEFINE_SYNCTEX_DATA_INT_GETSET(WHAT) \
DEFINE_SYNCTEX_DATA_HAS(WHAT)\
static int _synctex_data_##WHAT(synctex_node_p node) {\
if (_synctex_data_has_##WHAT(node)) {\
return __synctex_data(node)[node->class->modelator->WHAT].as_integer;\
}\
return 0;\
}\
static int _synctex_data_set_##WHAT(synctex_node_p node, int new_value) {\
int old = 0;\
if (_synctex_data_has_##WHAT(node)) {\
old = __synctex_data(node)[node->class->modelator->WHAT].as_integer;\
__synctex_data(node)[node->class->modelator->WHAT].as_integer=new_value;\
}\
return old;\
}
#define DEFINE_SYNCTEX_DATA_INT_DECODE(WHAT) \
static synctex_status_t _synctex_data_decode_##WHAT(synctex_node_p node) {\
if (_synctex_data_has_##WHAT(node)) {\
synctex_is_s is = _synctex_decode_int(node->class->scanner);\
if (is.status == SYNCTEX_STATUS_OK) {\
_synctex_data_set_##WHAT(node,is.integer);\
} \
return is.status;\
}\
return SYNCTEX_STATUS_BAD_ARGUMENT;\
}
# define DEFINE_SYNCTEX_DATA_INT_DECODE_v(WHAT) \
static synctex_status_t _synctex_data_decode_##WHAT##_v(synctex_node_p node) {\
if (_synctex_data_has_##WHAT(node)) {\
synctex_is_s is = _synctex_decode_int_v(node->class->scanner);\
if (is.status == SYNCTEX_STATUS_OK) {\
_synctex_data_set_##WHAT(node,is.integer);\
} \
return is.status;\
}\
return SYNCTEX_STATUS_BAD_ARGUMENT;\
}
#define DEFINE_SYNCTEX_DATA_STR_GETSET(WHAT) \
DEFINE_SYNCTEX_DATA_HAS(WHAT)\
static char * _synctex_data_##WHAT(synctex_node_p node) {\
if (_synctex_data_has_##WHAT(node)) {\
return node->data[node->class->navigator->size+node->class->modelator->WHAT].as_string;\
}\
return NULL;\
}\
static char * _synctex_data_set_##WHAT(synctex_node_p node, char * new_value) {\
char * old = "";\
if (_synctex_data_has_##WHAT(node)) {\
old = node->data[node->class->navigator->size+node->class->modelator->WHAT].as_string;\
node->data[node->class->navigator->size+node->class->modelator->WHAT].as_string =new_value;\
}\
return old;\
}
#define DEFINE_SYNCTEX_DATA_STR_DECODE(WHAT) \
static synctex_status_t _synctex_data_decode_##WHAT(synctex_node_p node) {\
if (_synctex_data_has_##WHAT(node)) {\
synctex_ss_s ss = _synctex_decode_string(node->class->scanner);\
if (ss.status == SYNCTEX_STATUS_OK) {\
_synctex_data_set_##WHAT(node,ss.string);\
} \
return ss.status;\
}\
return SYNCTEX_STATUS_BAD_ARGUMENT;\
}
#define DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(WHAT) \
DEFINE_SYNCTEX_DATA_INT_GETSET(WHAT) \
DEFINE_SYNCTEX_DATA_INT_DECODE(WHAT)
#define DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE_v(WHAT) \
DEFINE_SYNCTEX_DATA_INT_GETSET(WHAT) \
DEFINE_SYNCTEX_DATA_INT_DECODE_v(WHAT)
#define DEFINE_SYNCTEX_DATA_STR_GETSET_DECODE(WHAT) \
DEFINE_SYNCTEX_DATA_STR_GETSET(WHAT) \
DEFINE_SYNCTEX_DATA_STR_DECODE(WHAT)
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark OBJECTS, their creators and destructors.
# endif
# ifdef SYNCTEX_NOTHING
# pragma mark input.
# endif
DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(tag)
DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(line)
DEFINE_SYNCTEX_DATA_STR_GETSET_DECODE(name)
/* Input nodes only know about their sibling, which is another input node.
* The synctex information is the _synctex_data_tag and _synctex_data_name*/
# define SYNCTEX_INPUT_MARK "Input:"
static const synctex_tree_model_s synctex_tree_model_input = {
synctex_tree_sibling_idx, /* sibling */
-1, /* parent */
-1, /* child */
-1, /* friend */
-1, /* last */
-1, /* next_hbox */
-1, /* arg_sibling */
-1, /* target */
synctex_tree_s_input_max
};
static const synctex_data_model_s synctex_data_model_input = {
synctex_data_input_tag_idx, /* tag */
synctex_data_input_line_idx,/* line */
-1, /* column */
-1, /* h */
-1, /* v */
-1, /* width */
-1, /* height */
-1, /* depth */
-1, /* mean_line */
-1, /* weight */
-1, /* h_V */
-1, /* v_V */
-1, /* width_V */
-1, /* height_V */
-1, /* depth_V */
synctex_data_input_name_idx, /* name */
-1, /* page */
synctex_data_input_tln_max
};
#define SYNCTEX_INSPECTOR_GETTER_F(WHAT)\
&_synctex_data_##WHAT, &_synctex_data_set_##WHAT
static synctex_node_p _synctex_new_input(synctex_scanner_p scanner);
static void _synctex_free_input(synctex_node_p node);
static void _synctex_log_input(synctex_node_p node);
static char * _synctex_abstract_input(synctex_node_p node);
static void _synctex_display_input(synctex_node_p node);
static const synctex_tlcpector_s synctex_tlcpector_input = {
&_synctex_data_tag, /* tag */
&_synctex_int_none, /* line */
&_synctex_int_none, /* column */
};
static synctex_class_s synctex_class_input = {
NULL, /* No scanner yet */
synctex_node_type_input, /* Node type */
synctex_node_mask_input, /* Node mask */
&_synctex_new_input, /* creator */
&_synctex_free_input, /* destructor */
&_synctex_log_input, /* log */
&_synctex_display_input, /* display */
&_synctex_abstract_input, /* abstract */
&synctex_tree_model_input, /* tree model */
&synctex_data_model_input, /* data model */
&synctex_tlcpector_input, /* inspector */
&synctex_inspector_none, /* inspector */
&synctex_vispector_none, /* vispector */
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_s_input_max+synctex_data_input_tln_max];
} synctex_input_s;
static synctex_node_p _synctex_new_input(synctex_scanner_p scanner) {
if (scanner) {
synctex_node_p node = _synctex_malloc(sizeof(synctex_input_s));
if (node) {
SYNCTEX_IMPLEMENT_CHARINDEX(node,strlen(SYNCTEX_INPUT_MARK));
node->class = scanner->class+synctex_node_type_input;
}
return node;
}
return NULL;
}
static void _synctex_free_input(synctex_node_p node){
if (node) {
synctex_node_free(__synctex_tree_sibling(node));
_synctex_free(_synctex_data_name(node));
_synctex_free(node);
}
}
/* The sheet is a first level node.
* It has no parent (the owner is the scanner itself)
* Its sibling points to another sheet.
* Its child points to its first child, in general a box.
* A sheet node contains only one synctex information: the page.
* This is the 1 based page index as given by TeX.
*/
# ifdef SYNCTEX_NOTHING
# pragma mark sheet.
# endif
/**
* Every node has the same structure, but not the same size.
*/
DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(page)
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_scn_sheet_max+synctex_data_p_sheet_max];
} synctex_node_sheet_s;
/* sheet node creator */
#define DEFINE_synctex_new_scanned_NODE(NAME)\
static synctex_node_p _synctex_new_##NAME(synctex_scanner_p scanner) {\
if (scanner) {\
++SYNCTEX_CUR;\
synctex_node_p node = _synctex_malloc(sizeof(synctex_node_##NAME##_s));\
if (node) {\
SYNCTEX_IMPLEMENT_CHARINDEX(node,0);\
node->class = scanner->class+synctex_node_type_##NAME;\
}\
return node;\
}\
return NULL;\
}
DEFINE_synctex_new_scanned_NODE(sheet)
static void _synctex_log_sheet(synctex_node_p node);
static char * _synctex_abstract_sheet(synctex_node_p node);
static void _synctex_display_sheet(synctex_node_p node);
static const synctex_tree_model_s synctex_tree_model_sheet = {
synctex_tree_sibling_idx, /* sibling */
-1, /* parent */
synctex_tree_s_child_idx, /* child */
-1, /* friend */
-1, /* last */
synctex_tree_sc_next_hbox_idx, /* next_hbox */
-1, /* arg_sibling */
-1, /* target */
synctex_tree_scn_sheet_max
};
static const synctex_data_model_s synctex_data_model_sheet = {
-1, /* tag */
-1, /* line */
-1, /* column */
-1, /* h */
-1, /* v */
-1, /* width */
-1, /* height */
-1, /* depth */
-1, /* mean_line */
-1, /* weight */
-1, /* h_V */
-1, /* v_V */
-1, /* width_V */
-1, /* height_V */
-1, /* depth_V */
-1, /* name */
synctex_data_sheet_page_idx, /* page */
synctex_data_p_sheet_max
};
static synctex_class_s synctex_class_sheet = {
NULL, /* No scanner yet */
synctex_node_type_sheet, /* Node type */
synctex_node_mask_sf, /* Node mask */
&_synctex_new_sheet, /* creator */
&_synctex_free_node, /* destructor */
&_synctex_log_sheet, /* log */
&_synctex_display_sheet, /* display */
&_synctex_abstract_sheet, /* abstract */
&synctex_tree_model_sheet, /* tree model */
&synctex_data_model_sheet, /* data model */
&synctex_tlcpector_none, /* tlcpector */
&synctex_inspector_none, /* inspector */
&synctex_vispector_none, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark form.
# endif
/**
* Every node has the same structure, but not the same size.
*/
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_sct_form_max+synctex_data_t_form_max];
} synctex_node_form_s;
DEFINE_synctex_new_scanned_NODE(form)
static char * _synctex_abstract_form(synctex_node_p node);
static void _synctex_display_form(synctex_node_p node);
static void _synctex_log_form(synctex_node_p node);
static const synctex_tree_model_s synctex_tree_model_form = {
synctex_tree_sibling_idx, /* sibling */
-1, /* parent */
synctex_tree_s_child_idx, /* child */
-1, /* friend */
-1, /* last */
-1, /* next_hbox */
-1, /* arg_sibling */
synctex_tree_sc_target_idx, /* target */
synctex_tree_sct_form_max
};
static const synctex_data_model_s synctex_data_model_form = {
synctex_data_form_tag_idx, /* tag */
-1, /* line */
-1, /* column */
-1, /* h */
-1, /* v */
-1, /* width */
-1, /* height */
-1, /* depth */
-1, /* mean_line */
-1, /* weight */
-1, /* h_V */
-1, /* v_V */
-1, /* width_V */
-1, /* height_V */
-1, /* depth_V */
-1, /* name */
-1, /* page */
synctex_data_t_form_max
};
static synctex_class_s synctex_class_form = {
NULL, /* No scanner yet */
synctex_node_type_form, /* Node type */
synctex_node_mask_sf, /* Node mask */
&_synctex_new_form, /* creator */
&_synctex_free_node, /* destructor */
&_synctex_log_form, /* log */
&_synctex_display_form, /* display */
&_synctex_abstract_form, /* abstract */
&synctex_tree_model_form, /* tree model */
&synctex_data_model_form, /* data model */
&synctex_tlcpector_none, /* tlcpector */
&synctex_inspector_none, /* inspector */
&synctex_vispector_none, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark vbox.
# endif
/* A box node contains navigation and synctex information
* There are different kinds of boxes.
* Only horizontal boxes are treated differently because of their visible size.
*/
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spcfl_vbox_max+synctex_data_box_max];
} synctex_node_vbox_s;
/* vertical box node creator */
DEFINE_synctex_new_scanned_NODE(vbox)
static char * _synctex_abstract_vbox(synctex_node_p node);
static void _synctex_display_vbox(synctex_node_p node);
static void _synctex_log_vbox(synctex_node_p node);
static const synctex_tree_model_s synctex_tree_model_vbox = {
synctex_tree_sibling_idx, /* sibling */
synctex_tree_s_parent_idx, /* parent */
synctex_tree_sp_child_idx, /* child */
synctex_tree_spc_friend_idx, /* friend */
synctex_tree_spcf_last_idx, /* last */
-1, /* next_hbox */
-1, /* arg_sibling */
-1, /* target */
synctex_tree_spcfl_vbox_max
};
DEFINE_SYNCTEX_DATA_INT_GETSET(column)
static synctex_status_t _synctex_data_decode_column(synctex_node_p node) {
if (_synctex_data_has_column(node)) {
synctex_is_s is = _synctex_decode_int_opt(node->class->scanner,-1);
if (is.status == SYNCTEX_STATUS_OK) {
_synctex_data_set_column(node,is.integer);
}
return is.status;
}
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(h)
DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE_v(v)
DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(width)
DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(height)
DEFINE_SYNCTEX_DATA_INT_GETSET_DECODE(depth)
static const synctex_data_model_s synctex_data_model_box = {
synctex_data_tag_idx, /* tag */
synctex_data_line_idx, /* line */
synctex_data_column_idx,/* column */
synctex_data_h_idx, /* h */
synctex_data_v_idx, /* v */
synctex_data_width_idx, /* width */
synctex_data_height_idx,/* height */
synctex_data_depth_idx, /* depth */
-1, /* mean_line */
-1, /* weight */
-1, /* h_V */
-1, /* v_V */
-1, /* width_V */
-1, /* height_V */
-1, /* depth_V */
-1, /* name */
-1, /* page */
synctex_data_box_max
};
static const synctex_tlcpector_s synctex_tlcpector_default = {
&_synctex_data_tag, /* tag */
&_synctex_data_line, /* line */
&_synctex_data_column, /* column */
};
static const synctex_inspector_s synctex_inspector_box = {
&_synctex_data_h,
&_synctex_data_v,
&_synctex_data_width,
&_synctex_data_height,
&_synctex_data_depth,
};
static float __synctex_node_visible_h(synctex_node_p node);
static float __synctex_node_visible_v(synctex_node_p node);
static float __synctex_node_visible_width(synctex_node_p node);
static float __synctex_node_visible_height(synctex_node_p node);
static float __synctex_node_visible_depth(synctex_node_p node);
static synctex_vispector_s synctex_vispector_box = {
&__synctex_node_visible_h,
&__synctex_node_visible_v,
&__synctex_node_visible_width,
&__synctex_node_visible_height,
&__synctex_node_visible_depth,
};
/* These are static class objects, each scanner will make a copy of them and setup the scanner field.
*/
static synctex_class_s synctex_class_vbox = {
NULL, /* No scanner yet */
synctex_node_type_vbox, /* Node type */
synctex_node_mask_vbox, /* Node mask */
&_synctex_new_vbox, /* creator */
&_synctex_free_node, /* destructor */
&_synctex_log_vbox, /* log */
&_synctex_display_vbox, /* display */
&_synctex_abstract_vbox, /* abstract */
&synctex_tree_model_vbox, /* tree model */
&synctex_data_model_box, /* data model */
&synctex_tlcpector_none, /* tlcpector */
&synctex_inspector_box, /* inspector */
&synctex_vispector_box, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark hbox.
# endif
/* Horizontal boxes must contain visible size, because 0 width does not mean emptiness.
* They also contain an average of the line numbers of the containing nodes. */
static const synctex_tree_model_s synctex_tree_model_hbox = {
synctex_tree_sibling_idx, /* sibling */
synctex_tree_s_parent_idx, /* parent */
synctex_tree_sp_child_idx, /* child */
synctex_tree_spc_friend_idx, /* friend */
synctex_tree_spcf_last_idx, /* last */
synctex_tree_spcfl_next_hbox_idx,/* next_hbox */
-1, /* arg_sibling */
-1, /* target */
synctex_tree_spcfln_hbox_max
};
DEFINE_SYNCTEX_DATA_INT_GETSET(mean_line)
DEFINE_SYNCTEX_DATA_INT_GETSET(weight)
DEFINE_SYNCTEX_DATA_INT_GETSET(h_V)
DEFINE_SYNCTEX_DATA_INT_GETSET(v_V)
DEFINE_SYNCTEX_DATA_INT_GETSET(width_V)
DEFINE_SYNCTEX_DATA_INT_GETSET(height_V)
DEFINE_SYNCTEX_DATA_INT_GETSET(depth_V)
/**
* The hbox model.
* It contains V variants of geometrical information.
* It happens that hboxes contain material that is not used to compute
* the bounding box. Some letters may appear out of the box given by TeX.
* In such a situation, the visible bouding box is bigger ence the V variant.
* Only hboxes have such variant. It does not make sense for void boxes
* and it is not used here for vboxes.
* - author: JL
*/
static const synctex_data_model_s synctex_data_model_hbox = {
synctex_data_tag_idx, /* tag */
synctex_data_line_idx, /* line */
synctex_data_column_idx,/* column */
synctex_data_h_idx, /* h */
synctex_data_v_idx, /* v */
synctex_data_width_idx, /* width */
synctex_data_height_idx,/* height */
synctex_data_depth_idx, /* depth */
synctex_data_mean_line_idx, /* mean_line */
synctex_data_weight_idx, /* weight */
synctex_data_h_V_idx, /* h_V */
synctex_data_v_V_idx, /* v_V */
synctex_data_width_V_idx, /* width_V */
synctex_data_height_V_idx, /* height_V */
synctex_data_depth_V_idx, /* depth_V */
-1, /* name */
-1, /* page */
synctex_data_hbox_max
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spcfln_hbox_max+synctex_data_hbox_max];
} synctex_node_hbox_s;
/* horizontal box node creator */
DEFINE_synctex_new_scanned_NODE(hbox)
static void _synctex_log_hbox(synctex_node_p node);
static char * _synctex_abstract_hbox(synctex_node_p node);
static void _synctex_display_hbox(synctex_node_p node);
static synctex_class_s synctex_class_hbox = {
NULL, /* No scanner yet */
synctex_node_type_hbox, /* Node type */
synctex_node_mask_hbox, /* Node mask */
&_synctex_new_hbox, /* creator */
&_synctex_free_node, /* destructor */
&_synctex_log_hbox, /* log */
&_synctex_display_hbox, /* display */
&_synctex_abstract_hbox, /* abstract */
&synctex_tree_model_hbox, /* tree model */
&synctex_data_model_hbox, /* data model */
&synctex_tlcpector_default, /* tlcpector */
&synctex_inspector_box, /* inspector */
&synctex_vispector_box, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark void vbox.
# endif
/* This void box node implementation is either horizontal or vertical
* It does not contain a child field.
*/
static const synctex_tree_model_s synctex_tree_model_spf = {
synctex_tree_sibling_idx, /* sibling */
synctex_tree_s_parent_idx, /* parent */
-1, /* child */
synctex_tree_sp_friend_idx, /* friend */
-1, /* last */
-1, /* next_hbox */
-1, /* arg_sibling */
-1, /* target */
synctex_tree_spf_max
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spf_max+synctex_data_box_max];
} synctex_node_void_vbox_s;
/* vertical void box node creator */
DEFINE_synctex_new_scanned_NODE(void_vbox)
static void _synctex_log_void_box(synctex_node_p node);
static char * _synctex_abstract_void_vbox(synctex_node_p node);
static void _synctex_display_void_vbox(synctex_node_p node);
static synctex_class_s synctex_class_void_vbox = {
NULL, /* No scanner yet */
synctex_node_type_void_vbox,/* Node type */
synctex_node_mask_void_vbox,/* Node mask */
&_synctex_new_void_vbox, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_void_box, /* log */
&_synctex_display_void_vbox,/* display */
&_synctex_abstract_void_vbox,/* abstract */
&synctex_tree_model_spf, /* tree model */
&synctex_data_model_box, /* data model */
&synctex_tlcpector_default, /* tlcpector */
&synctex_inspector_box, /* inspector */
&synctex_vispector_box, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark void hbox.
# endif
typedef synctex_node_void_vbox_s synctex_node_void_hbox_s;
/* horizontal void box node creator */
DEFINE_synctex_new_scanned_NODE(void_hbox)
static char * _synctex_abstract_void_hbox(synctex_node_p node);
static void _synctex_display_void_hbox(synctex_node_p node);
static synctex_class_s synctex_class_void_hbox = {
NULL, /* No scanner yet */
synctex_node_type_void_hbox,/* Node type */
synctex_node_mask_void_hbox,/* Node mask */
&_synctex_new_void_hbox, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_void_box, /* log */
&_synctex_display_void_hbox,/* display */
&_synctex_abstract_void_hbox,/* abstract */
&synctex_tree_model_spf, /* tree model */
&synctex_data_model_box, /* data model */
&synctex_tlcpector_default, /* tlcpector */
&synctex_inspector_box, /* inspector */
&synctex_vispector_box, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark form ref.
# endif
/* The form ref node. */
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spfa_max+synctex_data_ref_thv_max];
} synctex_node_ref_s;
/* form ref node creator */
DEFINE_synctex_new_scanned_NODE(ref)
static void _synctex_log_ref(synctex_node_p node);
static char * _synctex_abstract_ref(synctex_node_p node);
static void _synctex_display_ref(synctex_node_p node);
static const synctex_tree_model_s synctex_tree_model_spfa = {
synctex_tree_sibling_idx, /* sibling */
synctex_tree_s_parent_idx, /* parent */
-1, /* child */
synctex_tree_sp_friend_idx, /* friend */
-1, /* last */
-1, /* next_hbox */
synctex_tree_spf_arg_sibling_idx, /* arg_sibling */
-1, /* target */
synctex_tree_spfa_max
};
static const synctex_data_model_s synctex_data_model_ref = {
synctex_data_tag_idx, /* tag */
-1, /* line */
-1, /* column */
synctex_data_ref_h_idx, /* h */
synctex_data_ref_v_idx, /* v */
-1, /* width */
-1, /* height */
-1, /* depth */
-1, /* mean_line */
-1, /* weight */
-1, /* h_V */
-1, /* v_V */
-1, /* width_V */
-1, /* height_V */
-1, /* depth_V */
synctex_data_ref_thv_max
};
static synctex_class_s synctex_class_ref = {
NULL, /* No scanner yet */
synctex_node_type_ref, /* Node type */
synctex_node_mask_nvnn, /* Node mask */
&_synctex_new_ref, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_ref, /* log */
&_synctex_display_ref, /* display */
&_synctex_abstract_ref, /* abstract */
&synctex_tree_model_spfa, /* navigator */
&synctex_data_model_ref, /* data model */
&synctex_tlcpector_none, /* tlcpector */
&synctex_inspector_none, /* inspector */
&synctex_vispector_none, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark small node.
# endif
/* The small nodes correspond to glue, penalty, math and boundary nodes. */
static const synctex_data_model_s synctex_data_model_tlchv = {
synctex_data_tag_idx, /* tag */
synctex_data_line_idx, /* line */
synctex_data_column_idx, /* column */
synctex_data_h_idx, /* h */
synctex_data_v_idx, /* v */
-1, /* width */
-1, /* height */
-1, /* depth */
-1, /* mean_line */
-1, /* weight */
-1, /* h_V */
-1, /* v_V */
-1, /* width_V */
-1, /* height_V */
-1, /* depth_V */
-1, /* name */
-1, /* page */
synctex_data_tlchv_max
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spf_max+synctex_data_tlchv_max];
} synctex_node_tlchv_s;
static void _synctex_log_tlchv_node(synctex_node_p node);
# ifdef SYNCTEX_NOTHING
# pragma mark math.
# endif
typedef synctex_node_tlchv_s synctex_node_math_s;
/* math node creator */
DEFINE_synctex_new_scanned_NODE(math)
static char * _synctex_abstract_math(synctex_node_p node);
static void _synctex_display_math(synctex_node_p node);
static synctex_inspector_s synctex_inspector_hv = {
&_synctex_data_h,
&_synctex_data_v,
&_synctex_int_none,
&_synctex_int_none,
&_synctex_int_none,
};
static synctex_vispector_s synctex_vispector_hv = {
&__synctex_node_visible_h,
&__synctex_node_visible_v,
&_synctex_float_none,
&_synctex_float_none,
&_synctex_float_none,
};
static synctex_class_s synctex_class_math = {
NULL, /* No scanner yet */
synctex_node_type_math, /* Node type */
synctex_node_mask_nvnn, /* Node mask */
&_synctex_new_math, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_tlchv_node, /* log */
&_synctex_display_math, /* display */
&_synctex_abstract_math, /* abstract */
&synctex_tree_model_spf, /* tree model */
&synctex_data_model_tlchv, /* data model */
&synctex_tlcpector_default, /* tlcpector */
&synctex_inspector_hv, /* inspector */
&synctex_vispector_hv, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark kern node.
# endif
static const synctex_data_model_s synctex_data_model_tlchvw = {
synctex_data_tag_idx, /* tag */
synctex_data_line_idx, /* line */
synctex_data_column_idx,/* column */
synctex_data_h_idx, /* h */
synctex_data_v_idx, /* v */
synctex_data_width_idx, /* width */
-1, /* height */
-1, /* depth */
-1, /* mean_line */
-1, /* weight */
-1, /* h_V */
-1, /* v_V */
-1, /* width_V */
-1, /* height_V */
-1, /* depth_V */
-1, /* name */
-1, /* page */
synctex_data_tlchvw_max
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spf_max+synctex_data_tlchvw_max];
} synctex_node_kern_s;
/* kern node creator */
DEFINE_synctex_new_scanned_NODE(kern)
static void _synctex_log_kern_node(synctex_node_p node);
static char * _synctex_abstract_kern(synctex_node_p node);
static void _synctex_display_kern(synctex_node_p node);
static synctex_inspector_s synctex_inspector_kern = {
&_synctex_data_h,
&_synctex_data_v,
&_synctex_data_width,
&_synctex_int_none,
&_synctex_int_none,
};
static float __synctex_kern_visible_h(synctex_node_p node);
static float __synctex_kern_visible_width(synctex_node_p node);
static synctex_vispector_s synctex_vispector_kern = {
&__synctex_kern_visible_h,
&__synctex_node_visible_v,
&__synctex_kern_visible_width,
&_synctex_float_none,
&_synctex_float_none,
};
static synctex_class_s synctex_class_kern = {
NULL, /* No scanner yet */
synctex_node_type_kern, /* Node type */
synctex_node_mask_nvnn, /* Node mask */
&_synctex_new_kern, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_kern_node, /* log */
&_synctex_display_kern, /* display */
&_synctex_abstract_kern, /* abstract */
&synctex_tree_model_spf, /* tree model */
&synctex_data_model_tlchvw, /* data model */
&synctex_tlcpector_default, /* tlcpector */
&synctex_inspector_kern, /* inspector */
&synctex_vispector_kern, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark glue.
# endif
/* glue node creator */
typedef synctex_node_tlchv_s synctex_node_glue_s;
DEFINE_synctex_new_scanned_NODE(glue)
static char * _synctex_abstract_glue(synctex_node_p node);
static void _synctex_display_glue(synctex_node_p node);
static synctex_class_s synctex_class_glue = {
NULL, /* No scanner yet */
synctex_node_type_glue, /* Node type */
synctex_node_mask_nvnn, /* Node mask */
&_synctex_new_glue, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_tlchv_node, /* log */
&_synctex_display_glue, /* display */
&_synctex_abstract_glue, /* abstract */
&synctex_tree_model_spf, /* tree model */
&synctex_data_model_tlchv, /* data model */
&synctex_tlcpector_default, /* tlcpector */
&synctex_inspector_hv, /* inspector */
&synctex_vispector_hv, /* vispector */
};
/* The small nodes correspond to glue and boundary nodes. */
# ifdef SYNCTEX_NOTHING
# pragma mark rule.
# endif
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spf_max+synctex_data_box_max];
} synctex_node_rule_s;
DEFINE_synctex_new_scanned_NODE(rule)
static void _synctex_log_rule(synctex_node_p node);
static char * _synctex_abstract_rule(synctex_node_p node);
static void _synctex_display_rule(synctex_node_p node);
static float __synctex_rule_visible_h(synctex_node_p node);
static float __synctex_rule_visible_v(synctex_node_p node);
static float __synctex_rule_visible_width(synctex_node_p node);
static float __synctex_rule_visible_height(synctex_node_p node);
static float __synctex_rule_visible_depth(synctex_node_p node);
static synctex_vispector_s synctex_vispector_rule = {
&__synctex_rule_visible_h,
&__synctex_rule_visible_v,
&__synctex_rule_visible_width,
&__synctex_rule_visible_height,
&__synctex_rule_visible_depth,
};
static synctex_class_s synctex_class_rule = {
NULL, /* No scanner yet */
synctex_node_type_rule, /* Node type */
synctex_node_mask_nvnn, /* Node mask */
&_synctex_new_rule, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_rule, /* log */
&_synctex_display_rule, /* display */
&_synctex_abstract_rule, /* abstract */
&synctex_tree_model_spf, /* tree model */
&synctex_data_model_box, /* data model */
&synctex_tlcpector_default, /* tlcpector */
&synctex_inspector_box, /* inspector */
&synctex_vispector_rule, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark boundary.
# endif
/* boundary node creator */
typedef synctex_node_tlchv_s synctex_node_boundary_s;
DEFINE_synctex_new_scanned_NODE(boundary)
static char * _synctex_abstract_boundary(synctex_node_p node);
static void _synctex_display_boundary(synctex_node_p node);
static synctex_class_s synctex_class_boundary = {
NULL, /* No scanner yet */
synctex_node_type_boundary, /* Node type */
synctex_node_mask_nvnn, /* Node mask */
&_synctex_new_boundary, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_tlchv_node, /* log */
&_synctex_display_boundary, /* display */
&_synctex_abstract_boundary,/* abstract */
&synctex_tree_model_spf, /* tree model */
&synctex_data_model_tlchv, /* data model */
&synctex_tlcpector_default, /* tlcpector */
&synctex_inspector_hv, /* inspector */
&synctex_vispector_hv, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark box boundary.
# endif
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spfa_max+synctex_data_tlchv_max];
} synctex_node_box_bdry_s;
#define DEFINE_synctex_new_unscanned_NODE(NAME)\
static synctex_node_p _synctex_new_##NAME(synctex_scanner_p scanner) {\
if (scanner) {\
synctex_node_p node = _synctex_malloc(sizeof(synctex_node_##NAME##_s));\
if (node) {\
SYNCTEX_IMPLEMENT_CHARINDEX(node,0);\
node->class = scanner->class+synctex_node_type_##NAME;\
}\
return node;\
}\
return NULL;\
}
DEFINE_synctex_new_unscanned_NODE(box_bdry)
static char * _synctex_abstract_box_bdry(synctex_node_p node);
static void _synctex_display_box_bdry(synctex_node_p node);
static synctex_class_s synctex_class_box_bdry = {
NULL, /* No scanner yet */
synctex_node_type_box_bdry, /* Node type */
synctex_node_mask_nvnn, /* Node mask */
&_synctex_new_box_bdry, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_tlchv_node, /* log */
&_synctex_display_box_bdry, /* display */
&_synctex_abstract_box_bdry,/* display */
&synctex_tree_model_spfa, /* tree model */
&synctex_data_model_tlchv, /* data model */
&synctex_tlcpector_default, /* tlcpector */
&synctex_inspector_hv, /* inspector */
&synctex_vispector_hv, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark hbox proxy.
# endif
/**
* Standard nodes refer to TeX nodes: math, kern, boxes...
* Proxy nodes are used to support forms.
* A form is parsed as a tree of standard nodes starting
* at the top left position.
* When a reference is used, the form is duplicated
* to the location specified by the reference.
* As the same form can be duplicated at different locations,
* the geometrical information is relative to its own top left point.
* As we need absolute locations, we use proxy nodes.
* A proxy node records an offset and the target node.
* The target partly acts as a delegate.
* The h and v position of the proxy node is the h and v
* position of the target shifted by the proxy's offset.
* The width, height and depth are not sensitive to offsets.
* When are proxies created ?
* 1) when the synctex file has been parsed, all the form refs
* are replaced by proxies to the content of a form.
* This content is a node with siblings (actually none).
* Those root proxies have the parent of the ref they replace,
* so their parents exist and are no proxy.
* Moreover, if they have no sibling, it means that their target have no
* sibling as well.
* Such nodes are called root proxies.
* 2) On the fly, when a proxy is asked for its child
* (or sibling) and has none, a proxy to its target's child
* (or sibling) is created if any. There are only 2 possible situations:
* either the newly created proxy is the child of a proxy,
* or it is the sibling of a proxy created on the fly.
* In both cases, the parent is a proxy with children.
* Such nodes are called child proxies.
* How to compute the offset of a proxy ?
* The offset of root proxy objects is exactly
* the offset of the ref they replace.
* The offset of other proxies is their owner's,
* except when pointing to a root proxy.
* What happens for cascading forms ?
* Here is an example diagram
*
* At parse time, the arrow means "owns":
* sheet0 -> ref_to1
*
* target1 -> ref_to2
*
* target2 -> child22
*
* After replacing the refs:
* sheet0 -> proxy00 -> proxy01 -> proxy02
* | | |
* target1 -> proxy11 -> proxy12
* | |
* target2 -> proxy22
*
* proxy00, proxy11 and proxy22 are root proxies.
* Their offset is the one of the ref they replace
* proxy01, proxy02 and proxy12 are child proxies.
* Their proxy is the one of their parent.
* Optimization.
* After all the refs are replaced, there are only root nodes
* targeting standard node. We make sure that each child proxy
* also targets a standard node.
* It is possible for a proxy to have a standard sibling
* whereas its target has no sibling at all. Root proxies
* are such nodes, and are the only ones.
* The consequence is that proxies created on the fly
* must take into account this situation.
*/
/* A proxy to a hbox.
* A proxy do have a target, which can be a proxy
*/
static const synctex_tree_model_s synctex_tree_model_hbox_proxy = {
synctex_tree_sibling_idx, /* sibling */
synctex_tree_s_parent_idx, /* parent */
synctex_tree_sp_child_idx, /* child */
synctex_tree_spc_friend_idx, /* friend */
synctex_tree_spcf_last_idx, /* last */
synctex_tree_spcfl_next_hbox_idx,/* next_hbox */
-1, /* arg_sibling */
synctex_tree_spcfln_target_idx, /* target */
synctex_tree_spcflnt_hbox_proxy_max
};
static const synctex_data_model_s synctex_data_model_proxy = {
-1, /* tag */
-1, /* line */
-1, /* column */
synctex_data_proxy_h_idx, /* h */
synctex_data_proxy_v_idx, /* v */
-1, /* width */
-1, /* height */
-1, /* depth */
-1, /* mean_line */
-1, /* weight */
-1, /* h_V */
-1, /* v_V */
-1, /* width_V */
-1, /* height_V */
-1, /* depth_V */
-1, /* name */
-1, /* page */
synctex_data_proxy_hv_max
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spcflnt_hbox_proxy_max+synctex_data_proxy_hv_max];
} synctex_node_hbox_proxy_s;
/* box proxy node creator */
DEFINE_synctex_new_unscanned_NODE(hbox_proxy)
static void _synctex_log_proxy(synctex_node_p node);
static char * _synctex_abstract_hbox_proxy(synctex_node_p node);
static void _synctex_display_hbox_proxy(synctex_node_p node);
static int _synctex_proxy_tag(synctex_node_p);
static int _synctex_proxy_line(synctex_node_p);
static int _synctex_proxy_column(synctex_node_p);
static synctex_tlcpector_s synctex_tlcpector_proxy = {
&_synctex_proxy_tag,
&_synctex_proxy_line,
&_synctex_proxy_column,
};
static int _synctex_proxy_h(synctex_node_p);
static int _synctex_proxy_v(synctex_node_p);
static int _synctex_proxy_width(synctex_node_p);
static int _synctex_proxy_height(synctex_node_p);
static int _synctex_proxy_depth(synctex_node_p);
static synctex_inspector_s synctex_inspector_proxy = {
&_synctex_proxy_h,
&_synctex_proxy_v,
&_synctex_proxy_width,
&_synctex_proxy_height,
&_synctex_proxy_depth,
};
static float __synctex_proxy_visible_h(synctex_node_p);
static float __synctex_proxy_visible_v(synctex_node_p);
static float __synctex_proxy_visible_width(synctex_node_p);
static float __synctex_proxy_visible_height(synctex_node_p);
static float __synctex_proxy_visible_depth(synctex_node_p);
static synctex_vispector_s synctex_vispector_box_proxy = {
&__synctex_proxy_visible_h,
&__synctex_proxy_visible_v,
&__synctex_proxy_visible_width,
&__synctex_proxy_visible_height,
&__synctex_proxy_visible_depth,
};
static synctex_class_s synctex_class_hbox_proxy = {
NULL, /* No scanner yet */
synctex_node_type_hbox_proxy, /* Node type */
synctex_node_mask_hbox_proxy, /* Node mask */
&_synctex_new_hbox_proxy, /* creator */
&_synctex_free_node, /* destructor */
&_synctex_log_proxy, /* log */
&_synctex_display_hbox_proxy, /* display */
&_synctex_abstract_hbox_proxy, /* abstract */
&synctex_tree_model_hbox_proxy, /* tree model */
&synctex_data_model_proxy, /* data model */
&synctex_tlcpector_none, /* tlcpector */
&synctex_inspector_proxy, /* inspector */
&synctex_vispector_box_proxy, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark vbox proxy.
# endif
/* A proxy to a vbox. */
static const synctex_tree_model_s synctex_tree_model_vbox_proxy = {
synctex_tree_sibling_idx, /* sibling */
synctex_tree_s_parent_idx, /* parent */
synctex_tree_sp_child_idx, /* child */
synctex_tree_spc_friend_idx, /* friend */
synctex_tree_spcf_last_idx, /* last */
-1, /* next_hbox */
-1, /* arg_sibling */
synctex_tree_spcfl_target_idx, /* target */
synctex_tree_spcflt_vbox_proxy_max
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spcflt_vbox_proxy_max+synctex_data_proxy_hv_max];
} synctex_node_vbox_proxy_s;
/* box proxy node creator */
DEFINE_synctex_new_unscanned_NODE(vbox_proxy)
static void _synctex_log_proxy(synctex_node_p node);
static char * _synctex_abstract_vbox_proxy(synctex_node_p node);
static void _synctex_display_vbox_proxy(synctex_node_p node);
static synctex_class_s synctex_class_vbox_proxy = {
NULL, /* No scanner yet */
synctex_node_type_vbox_proxy, /* Node type */
synctex_node_mask_vbox_proxy, /* Node mask */
&_synctex_new_vbox_proxy, /* creator */
&_synctex_free_node, /* destructor */
&_synctex_log_proxy, /* log */
&_synctex_display_vbox_proxy, /* display */
&_synctex_abstract_vbox_proxy, /* abstract */
&synctex_tree_model_vbox_proxy, /* tree model */
&synctex_data_model_proxy, /* data model */
&synctex_tlcpector_proxy, /* tlcpector */
&synctex_inspector_proxy, /* inspector */
&synctex_vispector_box_proxy, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark proxy.
# endif
/**
* A proxy to a node but a box.
*/
static const synctex_tree_model_s synctex_tree_model_proxy = {
synctex_tree_sibling_idx, /* sibling */
synctex_tree_s_parent_idx, /* parent */
-1, /* child */
synctex_tree_sp_friend_idx, /* friend */
-1, /* last */
-1, /* next_hbox */
-1, /* arg_sibling */
synctex_tree_spf_target_idx,/* target */
synctex_tree_spft_proxy_max
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spft_proxy_max+synctex_data_proxy_hv_max];
} synctex_node_proxy_s;
/* proxy node creator */
DEFINE_synctex_new_unscanned_NODE(proxy)
static void _synctex_log_proxy(synctex_node_p node);
static char * _synctex_abstract_proxy(synctex_node_p node);
static void _synctex_display_proxy(synctex_node_p node);
static synctex_vispector_s synctex_vispector_proxy = {
&__synctex_proxy_visible_h,
&__synctex_proxy_visible_v,
&__synctex_proxy_visible_width,
&_synctex_float_none,
&_synctex_float_none,
};
static synctex_class_s synctex_class_proxy = {
NULL, /* No scanner yet */
synctex_node_type_proxy, /* Node type */
synctex_node_mask_proxy, /* Node mask */
&_synctex_new_proxy, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_proxy, /* log */
&_synctex_display_proxy, /* display */
&_synctex_abstract_proxy, /* abstract */
&synctex_tree_model_proxy, /* tree model */
&synctex_data_model_proxy, /* data model */
&synctex_tlcpector_proxy, /* tlcpector */
&synctex_inspector_proxy, /* inspector */
&synctex_vispector_proxy, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark last proxy.
# endif
/**
* A proxy to the last proxy/box boundary.
*/
static const synctex_tree_model_s synctex_tree_model_last_proxy = {
synctex_tree_sibling_idx, /* sibling */
synctex_tree_s_parent_idx, /* parent */
-1, /* child */
synctex_tree_sp_friend_idx, /* friend */
-1, /* last */
-1, /* next_hbox */
synctex_tree_spf_arg_sibling_idx, /* arg_sibling */
synctex_tree_spfa_target_idx, /* target */
synctex_tree_spfat_last_proxy_max
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spfat_last_proxy_max+synctex_data_proxy_hv_max];
} synctex_node_last_proxy_s;
/* proxy node creator */
DEFINE_synctex_new_unscanned_NODE(last_proxy)
static void _synctex_log_proxy(synctex_node_p node);
static char * _synctex_abstract_proxy(synctex_node_p node);
static void _synctex_display_proxy(synctex_node_p node);
static synctex_class_s synctex_class_last_proxy = {
NULL, /* No scanner yet */
synctex_node_type_last_proxy, /* Node type */
synctex_node_mask_proxy, /* Node mask */
&_synctex_new_proxy, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_proxy, /* log */
&_synctex_display_proxy, /* display */
&_synctex_abstract_proxy, /* abstract */
&synctex_tree_model_last_proxy, /* tree model */
&synctex_data_model_proxy, /* data model */
&synctex_tlcpector_proxy, /* tlcpector */
&synctex_inspector_proxy, /* inspector */
&synctex_vispector_proxy, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark result.
# endif
/**
* A proxy to a result node.
*/
static const synctex_tree_model_s synctex_tree_model_result = {
synctex_tree_sibling_idx, /* sibling */
synctex_tree_s_parent_idx, /* parent */
synctex_tree_sp_child_idx, /* child */
-1, /* friend */
-1, /* last */
-1, /* next_hbox */
-1, /* arg_sibling */
synctex_tree_spc_target_idx,/* target */
synctex_tree_spct_result_max
};
typedef struct {
SYNCTEX_DECLARE_CHARINDEX
synctex_class_p class;
synctex_data_u data[synctex_tree_spct_result_max+0];
} synctex_node_result_s;
/* proxy node creator */
DEFINE_synctex_new_unscanned_NODE(result)
static void _synctex_log_result(synctex_node_p node);
static char * _synctex_abstract_result(synctex_node_p node);
static void _synctex_display_result(synctex_node_p node);
static synctex_class_s synctex_class_result = {
NULL, /* No scanner yet */
synctex_node_type_result, /* Node type */
0, /* Node mask */
&_synctex_new_result, /* creator */
&_synctex_free_leaf, /* destructor */
&_synctex_log_result, /* log */
&_synctex_display_result, /* display */
&_synctex_abstract_result, /* abstract */
&synctex_tree_model_result, /* tree model */
&synctex_data_model_none, /* data model */
&synctex_tlcpector_proxy, /* tlcpector */
&synctex_inspector_none, /* inspector */
&synctex_vispector_none, /* vispector */
};
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Navigation
# endif
synctex_node_p synctex_node_parent(synctex_node_p node)
{
return _synctex_tree_parent(node);
}
synctex_node_p synctex_node_parent_sheet(synctex_node_p node)
{
while(node && SYNCTEX_TYPE(node) != synctex_node_type_sheet) {
node = _synctex_tree_parent(node);
}
/* exit the while loop either when node is NULL or node is a sheet */
return node;
}
synctex_node_p synctex_node_parent_form(synctex_node_p node)
{
while(node && SYNCTEX_TYPE(node) != synctex_node_type_form) {
node = _synctex_tree_parent(node);
}
/* exit the while loop either when node is NULL or node is a form */
return node;
}
/**
* The returned proxy will be the child or a sibling of source.
* The returned proxy has no parent, child nor sibling.
* Used only by __synctex_replace_ref.
* argument to_node: a box, not a proxy nor anything else.
*/
SYNCTEX_INLINE static synctex_node_p __synctex_new_proxy_from_ref_to(synctex_node_p ref, synctex_node_p to_node) {
synctex_node_p proxy = NULL;
if (!ref || !to_node) {
return NULL;
}
switch(SYNCTEX_TYPE(to_node)) {
case synctex_node_type_vbox:
proxy = _synctex_new_vbox_proxy(ref->class->scanner);
break;
case synctex_node_type_hbox:
proxy = _synctex_new_hbox_proxy(ref->class->scanner);
break;
default:
_synctex_error("! __synctex_new_proxy_from_ref_to. Unexpected form child (%s). Please report.", synctex_node_isa(to_node));
return NULL;
}
if (!proxy) {
_synctex_error("! __synctex_new_proxy_from_ref_to. Internal error. Please report.");
return NULL;
}
_synctex_data_set_h(proxy, _synctex_data_h(ref));
_synctex_data_set_v(proxy, _synctex_data_v(ref));
_synctex_tree_set_target(proxy,to_node);
# if defined(SYNCTEX_USE_CHARINDEX)
proxy->line_index=to_node?to_node->line_index:0;
proxy->char_index=to_node?to_node->char_index:0;
# endif
return proxy;
}
/**
* The returned proxy will be the child or a sibling of owning_proxy.
* The returned proxy has no parent, nor child.
* Used only by synctex_node_child and synctex_node_sibling
* to create proxies on the fly.
* If the to_node has an already computed sibling,
* then the returned proxy has itself a sibling
* pointing to that already computed sibling.
*/
SYNCTEX_INLINE static synctex_node_p __synctex_new_child_proxy_to(synctex_node_p owner, synctex_node_p to_node) {
synctex_node_p proxy = NULL;
synctex_node_p target = to_node;
if (!owner) {
return NULL;
}
switch(SYNCTEX_TYPE(target)) {
case synctex_node_type_vbox:
if ((proxy = _synctex_new_vbox_proxy(owner->class->scanner))) {
exit_standard:
_synctex_data_set_h(proxy, _synctex_data_h(owner));
_synctex_data_set_v(proxy, _synctex_data_v(owner));
exit0:
_synctex_tree_set_target(proxy,target);
# if defined(SYNCTEX_USE_CHARINDEX)
proxy->line_index=to_node?to_node->line_index:0;
proxy->char_index=to_node?to_node->char_index:0;
# endif
return proxy;
};
break;
case synctex_node_type_vbox_proxy:
if ((proxy = _synctex_new_vbox_proxy(owner->class->scanner))) {
exit_proxy:
target = _synctex_tree_target(to_node);
_synctex_data_set_h(proxy, _synctex_data_h(owner)+_synctex_data_h(to_node));
_synctex_data_set_v(proxy, _synctex_data_v(owner)+_synctex_data_v(to_node));
goto exit0;
};
break;
case synctex_node_type_hbox:
if ((proxy = _synctex_new_hbox_proxy(owner->class->scanner))) {
goto exit_standard;
};
break;
case synctex_node_type_hbox_proxy:
if ((proxy = _synctex_new_hbox_proxy(owner->class->scanner))) {
goto exit_proxy;
};
break;
case synctex_node_type_proxy:
if ((proxy = _synctex_new_proxy(owner->class->scanner))) {
goto exit_proxy;
};
break;
default:
if ((proxy = _synctex_new_proxy(owner->class->scanner))) {
goto exit_standard;
};
break;
}
_synctex_error("! __synctex_new_child_proxy_to. "
"Internal error. "
"Please report.");
return NULL;
}
SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_sibling(synctex_node_p node, synctex_node_p new_sibling);
typedef struct synctex_nns_t {
synctex_node_p first;
synctex_node_p last;
synctex_status_t status;
} synctex_nns_s;
/**
* Given a target node, create a list of proxies.
* The first proxy points to the target node,
* its sibling points to the target's sibling and so on.
* Returns the first created proxy, the last one and
* an error status.
*/
SYNCTEX_INLINE static synctex_nns_s _synctex_new_child_proxies_to(synctex_node_p owner, synctex_node_p to_node) {
synctex_nns_s nns = {NULL,NULL,SYNCTEX_STATUS_OK};
if ((nns.first = nns.last = __synctex_new_child_proxy_to(owner,to_node))) {
synctex_node_p to_sibling = to_node;
while (synctex_YES) {
synctex_node_p to_next_sibling = NULL;
synctex_node_p sibling;
if ((to_next_sibling = __synctex_tree_sibling(to_sibling))) {
/* This is not the last sibling */
if((sibling = __synctex_new_child_proxy_to(owner,to_sibling))) {
_synctex_tree_set_sibling(nns.last,sibling);
nns.last = sibling;
to_sibling = to_next_sibling;
continue;
} else {
_synctex_error("! _synctex_new_child_proxy_to. "
"Internal error (1). "
"Please report.");
nns.status = SYNCTEX_STATUS_ERROR;
}
} else if((sibling = _synctex_new_last_proxy(owner->class->scanner))) {
_synctex_tree_set_sibling(nns.last,sibling);
nns.last = sibling;
_synctex_data_set_h(nns.last, _synctex_data_h(nns.first));
_synctex_data_set_v(nns.last, _synctex_data_v(nns.first));
_synctex_tree_set_target(nns.last,to_sibling);
# if defined(SYNCTEX_USE_CHARINDEX)
nns.last->line_index=to_sibling->line_index;
nns.last->char_index=to_sibling->char_index;
# endif
} else {
_synctex_error("! _synctex_new_child_proxy_to. "
"Internal error (2). "
"Please report.");
nns.status = SYNCTEX_STATUS_ERROR;
}
break;
}
}
return nns;
}
static char * _synctex_node_abstract(synctex_node_p node);
SYNCTEX_INLINE static synctex_node_p synctex_tree_set_friend(synctex_node_p node,synctex_node_p new_friend) {
#if SYNCTEX_DEBUG
synctex_node_p F = new_friend;
while (F) {
if (node == F) {
printf("THIS IS AN ERROR\n");
F = new_friend;
while (F) {
printf("%s\n",_synctex_node_abstract(F));
if (node == F) {
return NULL;
}
F = _synctex_tree_friend(F);
}
return NULL;
}
F = _synctex_tree_friend(F);
}
#endif
return new_friend?_synctex_tree_set_friend(node,new_friend):_synctex_tree_reset_friend(node);
}
/**
*
*/
SYNCTEX_INLINE static synctex_node_p __synctex_node_make_friend(synctex_node_p node, int i) {
synctex_node_p old = NULL;
if (i>=0) {
i = i%(node->class->scanner->number_of_lists);
old = synctex_tree_set_friend(node,(node->class->scanner->lists_of_friends)[i]);
(node->class->scanner->lists_of_friends)[i] = node;
#if SYNCTEX_DEBUG>500
printf("tl(%i)=>",i);
synctex_node_log(node);
if (synctex_node_parent_form(node)) {
printf("! ERROR. No registration expected!\n");
}
#endif
}
return old;
}
SYNCTEX_INLINE static synctex_node_p __synctex_node_make_friend_tlc(synctex_node_p node) {
int i = _synctex_data_tag(node)+_synctex_data_line(node);
return __synctex_node_make_friend(node,i);
}
/**
* All proxies have tlc attributes, on behalf of their target.
* The purpose is to register all af them.
* - argument node: is the first proxy
*/
SYNCTEX_INLINE static synctex_node_p __synctex_proxy_make_friend_and_next_hbox(synctex_node_p node) {
synctex_node_p old = NULL;
synctex_node_p target = _synctex_tree_target(node);
if (target) {
int i = _synctex_data_tag(target)+_synctex_data_line(target);
old = __synctex_node_make_friend(node,i);
} else {
old = __synctex_tree_reset_friend(node);
}
if (SYNCTEX_TYPE(node) == synctex_node_type_hbox_proxy) {
synctex_node_p sheet = synctex_node_parent_sheet(node);
if (sheet) {
_synctex_tree_set_next_hbox(node,_synctex_tree_next_hbox(sheet));
_synctex_tree_set_next_hbox(sheet,node);
}
}
return old;
}
/**
*
*/
SYNCTEX_INLINE static void _synctex_node_make_friend_tlc(synctex_node_p node) {
if (node) {
__synctex_node_make_friend_tlc(node);
}
}
static synctex_node_p _synctex_node_set_child(synctex_node_p node, synctex_node_p new_child);
/* At parse time, non void box nodes have children.
* In order to support pdf forms, proxies are created
* to place form nodes at real locations.
* If form ref nodes have no children, one is created
* as a proxy to the box contained in the referenced form.
* This is the only place where child proxies are created.
*/
synctex_node_p synctex_node_child(synctex_node_p node) {
synctex_node_p child = NULL;
synctex_node_p target = NULL;
if ((child = _synctex_tree_child(node))) {
return child;
} else if ((target = _synctex_tree_target(node))) {
if ((child = synctex_node_child(target))) {
/* This is a proxy with no child
* which target does have a child. */
synctex_nns_s nns = _synctex_new_child_proxies_to(node, child);
if (nns.first) {
_synctex_node_set_child(node,nns.first);
#if SYNCTEX_DEBUG>500
printf("! Child proxy (as child):\n");
synctex_node_display(proxy);
synctex_node_display(_synctex_tree_target(proxy));
#endif
return nns.first;
} else {
_synctex_error("! synctex_node_child. Internal inconsistency. Please report.");
}
}
}
return NULL;
}
static synctex_node_p _synctex_node_set_child(synctex_node_p node, synctex_node_p new_child) {
if (node && new_child){
synctex_node_p child = new_child;
synctex_node_p last_child = NULL;
synctex_node_p old = _synctex_tree_set_child(node,child);
do {
_synctex_tree_set_parent(child,node);
last_child = child;
} while ((child = __synctex_tree_sibling(child)));
_synctex_tree_set_last(node,last_child);
return old;
}
return NULL;
}
/* The last child of the given node, or NULL.
*/
synctex_node_p synctex_node_last_child(synctex_node_p node) {
return _synctex_tree_last(node);
}
/**
* All nodes siblings are properly set up at parse time
* except for non root proxies.
*/
synctex_node_p synctex_node_sibling(synctex_node_p node) {
return node? __synctex_tree_sibling(node): NULL;
}
/**
* All the _synctex_tree_... methods refer to the tree model.
* __synctex_tree_... methods are low level.
*/
/**
* Replace the sibling.
* Connect to the arg_sibling of the new_sibling if relevant.
* - returns the old sibling.
* The caller is responsible for releasing the old sibling.
*/
SYNCTEX_INLINE static synctex_node_p _synctex_tree_set_sibling(synctex_node_p node, synctex_node_p new_sibling) {
synctex_node_p old = node? __synctex_tree_set_sibling(node,new_sibling): NULL;
_synctex_tree_set_arg_sibling(new_sibling,node);
return old;
}
/**
* Replace the sibling.
* Set the parent of the new sibling (and further siblings)
* to the parent of the receiver.
* - argument new_sibling: must not be NULL.
* - returns the old sibling.
* The caller is responsible for releasing the old sibling.
*/
static synctex_node_p _synctex_node_set_sibling(synctex_node_p node, synctex_node_p new_sibling) {
if (node && new_sibling) {
synctex_node_p old = _synctex_tree_set_sibling(node,new_sibling);
if (_synctex_tree_has_parent(node)) {
synctex_node_p parent = __synctex_tree_parent(node);
if (parent) {
synctex_node_p N = new_sibling;
while (synctex_YES) {
if (_synctex_tree_has_parent(N)) {
__synctex_tree_set_parent(N,parent);
_synctex_tree_set_last(parent,N);
N = __synctex_tree_sibling(N);
continue;
} else if (N) {
_synctex_error("! synctex_node_sibling. "
"Internal inconsistency. "
"Please report.");
}
break;
}
}
}
return old;
}
return NULL;
}
/**
* The last sibling of the given node, or NULL with node.
*/
synctex_node_p synctex_node_last_sibling(synctex_node_p node) {
synctex_node_p sibling;
do {
sibling = node;
} while((node = synctex_node_sibling(node)));
return sibling;
}
/**
* The next nodes corresponds to a deep first tree traversal.
* Creates child proxies as side effect.
* May loop initfinitely many times is the tree
* is not properly built (contains loops).
*/
synctex_node_p synctex_node_next(synctex_node_p node) {
synctex_node_p N = synctex_node_child(node);
if (N) {
return N;
}
while (synctex_YES) {
if ((N = __synctex_tree_sibling(node))) {
return N;
} else if ((node = _synctex_tree_parent(node))) {
if (SYNCTEX_TYPE(node) == synctex_node_type_sheet) {/* EXC_BAD_ACCESS? */
return NULL;
} else if (SYNCTEX_TYPE(node) == synctex_node_type_form) {
return NULL;
}
} else {
return NULL;
}
}
}
synctex_node_p _synctex_node_next(synctex_node_p node) {
synctex_node_p N = _synctex_tree_child(node);
if (N) {
return N;
}
while (synctex_YES) {
if ((N = __synctex_tree_sibling(node))) {
return N;
} else if ((node = _synctex_tree_parent(node))) {
if (SYNCTEX_TYPE(node) == synctex_node_type_sheet) {/* EXC_BAD_ACCESS? */
return NULL;
} else if (SYNCTEX_TYPE(node) == synctex_node_type_form) {
return NULL;
}
} else {
return NULL;
}
}
}
/**
* The node which argument is the sibling.
* - return: NULL if the argument has no parent or
* is the first child of its parent.
* - Input nodes have no arg siblings
*/
synctex_node_p synctex_node_arg_sibling(synctex_node_p node) {
#if 1
return _synctex_tree_arg_sibling(node);
#else
synctex_node_p N = _synctex_tree_parent(node);
if ((N = _synctex_tree_child(N))) {
do {
synctex_node_p NN = __synctex_tree_sibling(N);
if (NN == node) {
return N;
}
N = NN;
} while (N);
}
return N;
#endif
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark CLASS
# endif
/* Public node accessor: the type */
synctex_node_type_t synctex_node_type(synctex_node_p node) {
if (node) {
return (((node)->class))->type;
}
return synctex_node_type_none;
}
/* Public node accessor: the type */
synctex_node_type_t synctex_node_target_type(synctex_node_p node) {
if (SYNCTEX_IS_PROXY(node)) {
synctex_node_p target = _synctex_tree_target(node);
if (target) {
node = target;
}
return (((node)->class))->type;
}
if (node) {
return (((node)->class))->type;
}
return synctex_node_type_none;
}
/* Public node accessor: the human readable type */
const char * synctex_node_isa(synctex_node_p node) {
static const char * isa[synctex_node_number_of_types] =
{"Not a node",
"input",
"sheet",
"form",
"ref",
"vbox",
"void vbox",
"hbox",
"void hbox",
"kern",
"glue",
"rule",
"math",
"boundary",
"box_bdry",
"proxy",
"last proxy",
"vbox proxy",
"hbox proxy",
"result"};
return isa[synctex_node_type(node)];
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark LOG
# endif
/* Public node logger */
void synctex_node_log(synctex_node_p node) {
SYNCTEX_MSG_SEND(node,log);
}
static void _synctex_log_input(synctex_node_p node) {
if (node) {
printf("%s:%i,%s(%i)\n",synctex_node_isa(node),
_synctex_data_tag(node),
_synctex_data_name(node),
_synctex_data_line(node));
printf("SELF:%p\n",(void *)node);
printf(" SIBLING:%p\n",
(void *)__synctex_tree_sibling(node));
}
}
static void _synctex_log_sheet(synctex_node_p node) {
if (node) {
printf("%s:%i",synctex_node_isa(node),_synctex_data_page(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" FRIEND:%p\n",(void *)_synctex_tree_friend(node));
printf(" NEXT_hbox:%p\n",(void *)_synctex_tree_next_hbox(node));
}
}
static void _synctex_log_form(synctex_node_p node) {
if (node) {
printf("%s:%i",synctex_node_isa(node),_synctex_data_tag(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" FRIEND:%p\n",(void *)_synctex_tree_friend(node));
}
}
static void _synctex_log_ref(synctex_node_p node) {
if (node) {
printf("%s:%i:%i,%i",
synctex_node_isa(node),
_synctex_data_tag(node),
_synctex_data_h(node),
_synctex_data_v(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
}
}
static void _synctex_log_tlchv_node(synctex_node_p node) {
if (node) {
printf("%s:%i,%i:%i,%i",
synctex_node_isa(node),
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" FRIEND:%p\n",(void *)_synctex_tree_friend(node));
}
}
static void _synctex_log_kern_node(synctex_node_p node) {
if (node) {
printf("%s:%i,%i:%i,%i:%i",
synctex_node_isa(node),
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" FRIEND:%p\n",(void *)_synctex_tree_friend(node));
}
}
static void _synctex_log_rule(synctex_node_p node) {
if (node) {
printf("%s:%i,%i:%i,%i",
synctex_node_isa(node),
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node));
printf(":%i",_synctex_data_width(node));
printf(",%i",_synctex_data_height(node));
printf(",%i",_synctex_data_depth(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" FRIEND:%p\n",(void *)_synctex_tree_friend(node));
}
}
static void _synctex_log_void_box(synctex_node_p node) {
if (node) {
printf("%s",synctex_node_isa(node));
printf(":%i",_synctex_data_tag(node));
printf(",%i",_synctex_data_line(node));
printf(",%i",0);
printf(":%i",_synctex_data_h(node));
printf(",%i",_synctex_data_v(node));
printf(":%i",_synctex_data_width(node));
printf(",%i",_synctex_data_height(node));
printf(",%i",_synctex_data_depth(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" FRIEND:%p\n",(void *)_synctex_tree_friend(node));
}
}
static void _synctex_log_vbox(synctex_node_p node) {
if (node) {
printf("%s",synctex_node_isa(node));
printf(":%i",_synctex_data_tag(node));
printf(",%i",_synctex_data_line(node));
printf(",%i",0);
printf(":%i",_synctex_data_h(node));
printf(",%i",_synctex_data_v(node));
printf(":%i",_synctex_data_width(node));
printf(",%i",_synctex_data_height(node));
printf(",%i",_synctex_data_depth(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" FRIEND:%p\n",(void *)_synctex_tree_friend(node));
printf(" NEXT_hbox:%p\n",(void *)_synctex_tree_next_hbox(node));
}
}
static void _synctex_log_hbox(synctex_node_p node) {
if (node) {
printf("%s",synctex_node_isa(node));
printf(":%i",_synctex_data_tag(node));
printf(",%i~%i*%i",_synctex_data_line(node),_synctex_data_mean_line(node),_synctex_data_weight(node));
printf(",%i",0);
printf(":%i",_synctex_data_h(node));
printf(",%i",_synctex_data_v(node));
printf(":%i",_synctex_data_width(node));
printf(",%i",_synctex_data_height(node));
printf(",%i",_synctex_data_depth(node));
printf("/%i",_synctex_data_h_V(node));
printf(",%i",_synctex_data_v_V(node));
printf(":%i",_synctex_data_width_V(node));
printf(",%i",_synctex_data_height_V(node));
printf(",%i",_synctex_data_depth_V(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" PARENT:%p\n",(void *)_synctex_tree_parent(node));
printf(" CHILD:%p\n",(void *)_synctex_tree_child(node));
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" FRIEND:%p\n",(void *)_synctex_tree_friend(node));
printf(" NEXT_hbox:%p\n",(void *)_synctex_tree_next_hbox(node));
}
}
static void _synctex_log_proxy(synctex_node_p node) {
if (node) {
synctex_node_p N = _synctex_tree_target(node);
printf("%s",synctex_node_isa(node));
printf(":%i",_synctex_data_h(node));
printf(",%i",_synctex_data_v(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" FRIEND:%p\n",(void *)_synctex_tree_friend(node));
printf(" ->%s\n",_synctex_node_abstract(N));
}
}
static void _synctex_log_result(synctex_node_p node) {
if (node) {
synctex_node_p N = _synctex_tree_target(node);
printf("%s",synctex_node_isa(node));
SYNCTEX_PRINT_CHARINDEX_NL;
printf("SELF:%p\n",(void *)node);
printf(" SIBLING:%p\n",(void *)__synctex_tree_sibling(node));
printf(" ->%s\n",_synctex_node_abstract(N));
}
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark SYNCTEX_DISPLAY
# endif
int synctex_scanner_display_switcher(synctex_scanner_p scanR) {
return scanR->display_switcher;
}
void synctex_scanner_set_display_switcher(synctex_scanner_p scanR, int switcher) {
scanR->display_switcher = switcher;
}
static const char * const _synctex_display_prompt = "................................";
static char * _synctex_scanner_display_prompt_down(synctex_scanner_p scanR) {
if (scanR->display_prompt>_synctex_display_prompt) {
--scanR->display_prompt;
}
return scanR->display_prompt;
}
static char * _synctex_scanner_display_prompt_up(synctex_scanner_p scanR) {
if (scanR->display_prompt+1<_synctex_display_prompt+strlen(_synctex_display_prompt)) {
++scanR->display_prompt;
}
return scanR->display_prompt;
}
void synctex_node_display(synctex_node_p node) {
if (node) {
synctex_scanner_p scanR = node->class->scanner;
if (scanR) {
if (scanR->display_switcher<0) {
SYNCTEX_MSG_SEND(node, display);
} else if (scanR->display_switcher>0 && --scanR->display_switcher>0) {
SYNCTEX_MSG_SEND(node, display);
} else if (scanR->display_switcher-->=0) {
printf("%s Next display skipped. Reset display switcher.\n",node->class->scanner->display_prompt);
}
} else {
SYNCTEX_MSG_SEND(node, display);
}
}
}
static char * _synctex_node_abstract(synctex_node_p node) {
return (node && node->class->abstract)? node->class->abstract(node):"none";
}
SYNCTEX_INLINE static void _synctex_display_child(synctex_node_p node) {
synctex_node_p N = _synctex_tree_child(node);
if (N) {
_synctex_scanner_display_prompt_down(N->class->scanner);
synctex_node_display(N);
_synctex_scanner_display_prompt_up(N->class->scanner);
}
}
SYNCTEX_INLINE static void _synctex_display_sibling(synctex_node_p node) {
synctex_node_display(__synctex_tree_sibling(node));
}
#define SYNCTEX_ABSTRACT_MAX 128
static char * _synctex_abstract_input(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"Input:%i:%s(%i)" SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_name(node),
_synctex_data_line(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_input(synctex_node_p node) {
if (node) {
printf("Input:%i:%s(%i)"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
_synctex_data_tag(node),
_synctex_data_name(node),
_synctex_data_line(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
synctex_node_display(__synctex_tree_sibling(node));
}
}
static char * _synctex_abstract_sheet(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"{%i...}" SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_page(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_sheet(synctex_node_p node) {
if (node) {
printf("%s{%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_page(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_child(node);
printf("%s}\n",node->class->scanner->display_prompt);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_form(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"<%i...>" SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
SYNCTEX_PRINT_CHARINDEX;
}
return abstract;
}
static void _synctex_display_form(synctex_node_p node) {
if (node) {
printf("%s<%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_child(node);
printf("%s>\n",node->class->scanner->display_prompt);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_vbox(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"[%i,%i:%i,%i:%i,%i,%i...]"
SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_vbox(synctex_node_p node) {
if (node) {
printf("%s[%i,%i:%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_child(node);
printf("%s]\n%slast:",node->class->scanner->display_prompt,node->class->scanner->display_prompt);
printf("%s\n",_synctex_node_abstract(_synctex_tree_last(node)));
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_hbox(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"(%i,%i~%i*%i:%i,%i:%i,%i,%i...)"
SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_mean_line(node),
_synctex_data_weight(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_hbox(synctex_node_p node) {
if (node) {
printf("%s(%i,%i~%i*%i:%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_mean_line(node),
_synctex_data_weight(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_child(node);
printf("%s)\n%slast:%s\n",
node->class->scanner->display_prompt,
node->class->scanner->display_prompt,
_synctex_node_abstract(_synctex_tree_last(node)));
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_void_vbox(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"v%i,%i;%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_void_vbox(synctex_node_p node) {
if (node) {
printf("%sv%i,%i;%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_void_hbox(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"h%i,%i:%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_void_hbox(synctex_node_p node) {
if (node) {
printf("%sh%i,%i:%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_glue(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"glue:%i,%i:%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_glue(synctex_node_p node) {
if (node) {
printf("%sglue:%i,%i:%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_rule(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
printf("rule:%i,%i:%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_rule(synctex_node_p node) {
if (node) {
printf("%srule:%i,%i:%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node),
_synctex_data_height(node),
_synctex_data_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_math(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"math:%i,%i:%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_math(synctex_node_p node) {
if (node) {
printf("%smath:%i,%i:%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_kern(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"kern:%i,%i:%i,%i:%i"
SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_kern(synctex_node_p node) {
if (node) {
printf("%skern:%i,%i:%i,%i:%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
_synctex_data_width(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_boundary(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"boundary:%i,%i:%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_boundary(synctex_node_p node) {
if (node) {
printf("%sboundary:%i,%i:%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_box_bdry(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"box bdry:%i,%i:%i,%i" SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_box_bdry(synctex_node_p node) {
if (node) {
printf("%sbox bdry:%i,%i:%i,%i",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node));
SYNCTEX_PRINT_CHARINDEX_NL;
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_ref(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"form ref:%i:%i,%i" SYNCTEX_PRINT_CHARINDEX_FMT,
_synctex_data_tag(node),
_synctex_data_h(node),
_synctex_data_v(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_ref(synctex_node_p node) {
if (node) {
printf("%sform ref:%i:%i,%i",
node->class->scanner->display_prompt,
_synctex_data_tag(node),
_synctex_data_h(node),
_synctex_data_v(node));
SYNCTEX_PRINT_CHARINDEX_NL;
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_proxy(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
synctex_node_p N = _synctex_tree_target(node);
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"%s:%i,%i:%i,%i/%p%s",
synctex_node_isa(node),
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node),
node,
_synctex_node_abstract(N));
}
return abstract;
}
static void _synctex_display_proxy(synctex_node_p node) {
if (node) {
synctex_node_p N = _synctex_tree_target(node);
printf("%s%s:%i,%i:%i,%i",
node->class->scanner->display_prompt,
synctex_node_isa(node),
_synctex_data_tag(node),
_synctex_data_line(node),
_synctex_data_h(node),
_synctex_data_v(node));
if (N) {
printf("=%i,%i:%i,%i,%i->%s",
synctex_node_h(node),
synctex_node_v(node),
synctex_node_width(node),
synctex_node_height(node),
synctex_node_depth(node),
_synctex_node_abstract(N));
}
printf("\n");
_synctex_display_child(node);
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_vbox_proxy(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,
"[*%i,%i:%i,%i:%i,%i,%i...*]"
SYNCTEX_PRINT_CHARINDEX_FMT,
synctex_node_tag(node),
synctex_node_line(node),
synctex_node_h(node),
synctex_node_v(node),
synctex_node_width(node),
synctex_node_height(node),
synctex_node_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_vbox_proxy(synctex_node_p node) {
if (node) {
printf("%s[*%i,%i:%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
synctex_node_tag(node),
synctex_node_line(node),
synctex_node_h(node),
synctex_node_v(node),
synctex_node_width(node),
synctex_node_height(node),
synctex_node_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_child(node);
printf("%s*]\n%slast:%s\n",
node->class->scanner->display_prompt,
node->class->scanner->display_prompt,
_synctex_node_abstract(_synctex_tree_last(node)));
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_hbox_proxy(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"(*%i,%i~%i*%i:%i,%i:%i,%i,%i...*)/%p"
SYNCTEX_PRINT_CHARINDEX_FMT,
synctex_node_tag(node),
synctex_node_line(node),
synctex_node_mean_line(node),
synctex_node_weight(node),
synctex_node_h(node),
synctex_node_v(node),
synctex_node_width(node),
synctex_node_height(node),
synctex_node_depth(node),
node
SYNCTEX_PRINT_CHARINDEX_WHAT);
}
return abstract;
}
static void _synctex_display_hbox_proxy(synctex_node_p node) {
if (node) {
printf("%s(*%i,%i~%i*%i:%i,%i:%i,%i,%i"
SYNCTEX_PRINT_CHARINDEX_FMT
"\n",
node->class->scanner->display_prompt,
synctex_node_tag(node),
synctex_node_line(node),
synctex_node_mean_line(node),
synctex_node_weight(node),
synctex_node_h(node),
synctex_node_v(node),
synctex_node_width(node),
synctex_node_height(node),
synctex_node_depth(node)
SYNCTEX_PRINT_CHARINDEX_WHAT);
_synctex_display_child(node);
printf("%s*)\n%slast:%s",
node->class->scanner->display_prompt,
node->class->scanner->display_prompt,
_synctex_node_abstract(_synctex_tree_last(node)));
_synctex_display_sibling(node);
}
}
static char * _synctex_abstract_result(synctex_node_p node) {
static char abstract[SYNCTEX_ABSTRACT_MAX] = "none";
if (node) {
synctex_node_p N = _synctex_tree_target(node);
snprintf(abstract,SYNCTEX_ABSTRACT_MAX,"%s:%s",
synctex_node_isa(node),
(N?_synctex_node_abstract(N):""));
}
return abstract;
}
static void _synctex_display_result(synctex_node_p node) {
if (node) {
synctex_node_p N = _synctex_tree_target(node);
printf("%s%s:->%s\n",
node->class->scanner->display_prompt,
synctex_node_isa(node),
_synctex_node_abstract(N));
_synctex_display_child(node);
_synctex_display_sibling(node);
}
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark STATUS
# endif
/* Actually, the minimum buffer size is driven by integer and float parsing, including the unit.
* ±0.123456789e123??
*/
# define SYNCTEX_BUFFER_MIN_SIZE 32
# define SYNCTEX_BUFFER_SIZE 32768
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Prototypes
# endif
typedef struct {
size_t size;
synctex_status_t status;
} synctex_zs_s;
static synctex_zs_s _synctex_buffer_get_available_size(synctex_scanner_p scanner, size_t size);
static synctex_status_t _synctex_next_line(synctex_scanner_p scanner);
static synctex_status_t _synctex_match_string(synctex_scanner_p scanner, const char * the_string);
typedef struct synctex_ns_t {
synctex_node_p node;
synctex_status_t status;
} synctex_ns_s;
static synctex_ns_s __synctex_parse_new_input(synctex_scanner_p scanner);
static synctex_status_t _synctex_scan_preamble(synctex_scanner_p scanner);
typedef struct {
float value;
synctex_status_t status;
} synctex_fs_s;
static synctex_fs_s _synctex_scan_float_and_dimension(synctex_scanner_p scanner);
static synctex_status_t _synctex_scan_post_scriptum(synctex_scanner_p scanner);
static synctex_status_t _synctex_scan_postamble(synctex_scanner_p scanner);
static synctex_status_t _synctex_setup_visible_hbox(synctex_node_p box);
static synctex_status_t _synctex_scan_content(synctex_scanner_p scanner);
int synctex_scanner_pre_x_offset(synctex_scanner_p scanner);
int synctex_scanner_pre_y_offset(synctex_scanner_p scanner);
const char * synctex_scanner_get_output_fmt(synctex_scanner_p scanner);
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark SCANNER UTILITIES
# endif
# define SYNCTEX_FILE (scanner->file)
/**
* Try to ensure that the buffer contains at least size bytes.
* Passing a huge size argument means the whole buffer length.
* Passing a 0 size argument means return the available buffer length, without reading the file.
* In that case, the return status is always SYNCTEX_STATUS_OK unless the given scanner is NULL.
* The size_t value returned is the number of bytes now available in the buffer. This is a nonnegative integer, it may take the value 0.
* It is the responsibility of the caller to test whether this size is conforming to its needs.
* Negative values may return in case of error, actually
* when there was an error reading the synctex file.
* - parameter scanner: The owning scanner. When NULL, returns SYNCTEX_STATUS_BAD_ARGUMENT.
* - parameter expected: expected number of bytes.
* - returns: a size and a status.
*/
static synctex_zs_s _synctex_buffer_get_available_size(synctex_scanner_p scanner, size_t expected) {
size_t size = 0;
if (NULL == scanner) {
return (synctex_zs_s){0,SYNCTEX_STATUS_BAD_ARGUMENT};
}
if (expected>SYNCTEX_BUFFER_SIZE){
expected = SYNCTEX_BUFFER_SIZE;
}
size = SYNCTEX_END - SYNCTEX_CUR; /* available is the number of unparsed chars in the buffer */
if (expected<=size) {
/* There are already sufficiently many characters in the buffer */
return (synctex_zs_s){size,SYNCTEX_STATUS_OK};
}
if (SYNCTEX_FILE) {
/* Copy the remaining part of the buffer to the beginning,
* then read the next part of the file */
int already_read = 0;
# if defined(SYNCTEX_USE_CHARINDEX)
scanner->charindex_offset += SYNCTEX_CUR - SYNCTEX_START;
# endif
if (size) {
memmove(SYNCTEX_START, SYNCTEX_CUR, size);
}
SYNCTEX_CUR = SYNCTEX_START + size; /* the next character after the move, will change. */
/* Fill the buffer up to its end */
already_read = gzread(SYNCTEX_FILE,(void *)SYNCTEX_CUR,(int)(SYNCTEX_BUFFER_SIZE - size));
if (already_read>0) {
/* We assume that 0<already_read<=SYNCTEX_BUFFER_SIZE - size, such that
* SYNCTEX_CUR + already_read = SYNCTEX_START + size + already_read <= SYNCTEX_START + SYNCTEX_BUFFER_SIZE */
SYNCTEX_END = SYNCTEX_CUR + already_read;
/* If the end of the file was reached, all the required SYNCTEX_BUFFER_SIZE - available
* may not be filled with values from the file.
* In that case, the buffer should stop properly after already_read characters. */
* SYNCTEX_END = '\0'; /* there is enough room */
SYNCTEX_CUR = SYNCTEX_START;
/* May be available is less than size, the caller will have to test. */
return (synctex_zs_s){SYNCTEX_END - SYNCTEX_CUR,SYNCTEX_STATUS_OK};
} else if (0>already_read) {
/* There is a possible error in reading the file */
int errnum = 0;
const char * error_string = gzerror(SYNCTEX_FILE, &errnum);
if (Z_ERRNO == errnum) {
/* There is an error in zlib caused by the file system */
_synctex_error("gzread error from the file system (%i)",errno);
return (synctex_zs_s){0,SYNCTEX_STATUS_ERROR};
} else if (errnum) {
_synctex_error("gzread error (%i:%i,%s)",already_read,errnum,error_string);
return (synctex_zs_s){0,SYNCTEX_STATUS_ERROR};
}
}
/* Nothing was read, we are at the end of the file. */
gzclose(SYNCTEX_FILE);
SYNCTEX_FILE = NULL;
SYNCTEX_END = SYNCTEX_CUR;
SYNCTEX_CUR = SYNCTEX_START;
* SYNCTEX_END = '\0';/* Terminate the string properly.*/
/* there might be a bit of text left */
return (synctex_zs_s){SYNCTEX_END - SYNCTEX_CUR,SYNCTEX_STATUS_EOF};
}
/* We cannot enlarge the buffer because the end of the file was reached. */
return (synctex_zs_s){size,SYNCTEX_STATUS_EOF};
}
/* Used when parsing the synctex file.
* Advance to the next character starting a line.
* Actually, only '\n' is recognized as end of line marker.
* On normal completion, the returned value is the number of unparsed characters available in the buffer.
* In general, it is a positive value, 0 meaning that the end of file was reached.
* -1 is returned in case of error, actually because there was an error while feeding the buffer.
* When the function returns with no error, SYNCTEX_CUR points to the first character of the next line, if any.
* J. Laurens: Sat May 10 07:52:31 UTC 2008
*/
static synctex_status_t _synctex_next_line(synctex_scanner_p scanner) {
synctex_status_t status = SYNCTEX_STATUS_OK;
if (NULL == scanner) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
infinite_loop:
while(SYNCTEX_CUR<SYNCTEX_END) {
if (*SYNCTEX_CUR == '\n') {
++SYNCTEX_CUR;
++scanner->line_number;
return _synctex_buffer_get_available_size(scanner, 1).status;
}
++SYNCTEX_CUR;
}
/* Here, we have SYNCTEX_CUR == SYNCTEX_END, such that the next call to _synctex_buffer_get_available_size
* will read another bunch of synctex file. Little by little, we advance to the end of the file. */
status = _synctex_buffer_get_available_size(scanner, 1).status;
if (status<=SYNCTEX_STATUS_EOF) {
return status;
}
goto infinite_loop;
}
/* Scan the given string.
* Both scanner and the_string must not be NULL, and the_string must not be 0 length.
* SYNCTEX_STATUS_OK is returned if the string is found,
* SYNCTEX_STATUS_EOF is returned when the EOF is reached,
* SYNCTEX_STATUS_NOT_OK is returned is the string is not found,
* an error status is returned otherwise.
* This is a critical method because buffering renders things more difficult.
* The given string might be as long as the maximum size_t value.
* As side effect, the buffer state may have changed if the given argument string can't fit into the buffer.
*/
static synctex_status_t _synctex_match_string(synctex_scanner_p scanner, const char * the_string) {
size_t tested_len = 0; /* the number of characters at the beginning of the_string that match */
size_t remaining_len = 0; /* the number of remaining characters of the_string that should match */
size_t available = 0;
synctex_zs_s zs = {0,0};
if (NULL == scanner || NULL == the_string) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
remaining_len = strlen(the_string); /* All the_string should match */
if (0 == remaining_len) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
/* How many characters available in the buffer? */
zs = _synctex_buffer_get_available_size(scanner,remaining_len);
if (zs.status<SYNCTEX_STATUS_EOF) {
return zs.status;
}
/* Maybe we have less characters than expected because the buffer is too small. */
if (zs.size>=remaining_len) {
/* The buffer is sufficiently big to hold the expected number of characters. */
if (strncmp((char *)SYNCTEX_CUR,the_string,remaining_len)) {
return SYNCTEX_STATUS_NOT_OK;
}
return_OK:
/* Advance SYNCTEX_CUR to the next character after the_string. */
SYNCTEX_CUR += remaining_len;
return SYNCTEX_STATUS_OK;
} else if (strncmp((char *)SYNCTEX_CUR,the_string,zs.size)) {
/* No need to go further, this is not the expected string in the buffer. */
return SYNCTEX_STATUS_NOT_OK;
} else if (SYNCTEX_FILE) {
/* The buffer was too small to contain remaining_len characters.
* We have to cut the string into pieces. */
z_off_t offset = 0L;
/* the first part of the string is found, advance the_string to the next untested character. */
the_string += zs.size;
/* update the remaining length and the parsed length. */
remaining_len -= zs.size;
tested_len += zs.size;
SYNCTEX_CUR += zs.size; /* We validate the tested characters. */
if (0 == remaining_len) {
/* Nothing left to test, we have found the given string. */
return SYNCTEX_STATUS_OK;
}
/* We also have to record the current state of the file cursor because
* if the_string does not match, all this should be a totally blank operation,
* for which the file and buffer states should not be modified at all.
* In fact, the states of the buffer before and after this function are in general different
* but they are totally equivalent as long as the values of the buffer before SYNCTEX_CUR
* can be safely discarded. */
offset = gztell(SYNCTEX_FILE);
/* offset now corresponds to the first character of the file that was not buffered. */
/* SYNCTEX_CUR - SYNCTEX_START is the number of chars that where already buffered and
* that match the head of the_string. If in fine the_string does not match, all these chars must be recovered
* because the whole buffer contents is replaced in _synctex_buffer_get_available_size.
* They were buffered from offset-len location in the file. */
offset -= SYNCTEX_CUR - SYNCTEX_START;
more_characters:
/* There is still some work to be done, so read another bunch of file.
* This is the second call to _synctex_buffer_get_available_size,
* which means that the actual contents of the buffer will be discarded.
* We will definitely have to recover the previous state in case we do not find the expected string. */
zs = _synctex_buffer_get_available_size(scanner,remaining_len);
if (zs.status<SYNCTEX_STATUS_EOF) {
return zs.status; /* This is an error, no need to go further. */
}
if (zs.size==0) {
/* Missing characters: recover the initial state of the file and return. */
return_NOT_OK:
if (offset != gzseek(SYNCTEX_FILE,offset,SEEK_SET)) {
/* This is a critical error, we could not recover the previous state. */
_synctex_error("Can't seek file");
return SYNCTEX_STATUS_ERROR;
}
/* Next time we are asked to fill the buffer,
* we will read a complete bunch of text from the file. */
SYNCTEX_CUR = SYNCTEX_END;
return SYNCTEX_STATUS_NOT_OK;
}
if (zs.size<remaining_len) {
/* We'll have to loop one more time. */
if (strncmp((char *)SYNCTEX_CUR,the_string,zs.size)) {
/* This is not the expected string, recover the previous state and return. */
goto return_NOT_OK;
}
/* Advance the_string to the first untested character. */
the_string += available;
/* update the remaining length and the parsed length. */
remaining_len -= zs.size;
tested_len += zs.size;
SYNCTEX_CUR += zs.size; /* We validate the tested characters. */
goto more_characters;
}
/* This is the last step. */
if (strncmp((char *)SYNCTEX_CUR,the_string,remaining_len)) {
/* This is not the expected string, recover the previous state and return. */
goto return_NOT_OK;
}
goto return_OK;
} else {
/* The buffer can't contain the given string argument, and the EOF was reached */
return SYNCTEX_STATUS_EOF;
}
}
/* Used when parsing the synctex file.
* Decode an integer.
* First, field separators, namely ':' and ',' characters are skipped
* The returned value is negative if there is an unrecoverable error.
* It is SYNCTEX_STATUS_NOT_OK if an integer could not be parsed, for example
* if the characters at the current cursor position are not digits or
* if the end of the file has been reached.
* It is SYNCTEX_STATUS_OK if an int has been successfully parsed.
* The given scanner argument must not be NULL, on the contrary, value_ref may be NULL.
*/
static synctex_is_s _synctex_decode_int(synctex_scanner_p scanner) {
char * ptr = NULL;
char * end = NULL;
synctex_zs_s zs = {0,0};
int result;
if (NULL == scanner) {
return (synctex_is_s){0, SYNCTEX_STATUS_BAD_ARGUMENT};
}
zs = _synctex_buffer_get_available_size(scanner, SYNCTEX_BUFFER_MIN_SIZE);
if (zs.status<SYNCTEX_STATUS_EOF) {
return (synctex_is_s){0,zs.status};
}
if (zs.size==0) {
return (synctex_is_s){0,SYNCTEX_STATUS_NOT_OK};
}
ptr = SYNCTEX_CUR;
/* Optionally parse the separator */
if (*ptr==':' || *ptr==',') {
++ptr;
--zs.size;
if (zs.size==0) {
return (synctex_is_s){0,SYNCTEX_STATUS_NOT_OK};
}
}
result = (int)strtol(ptr, &end, 10);
if (end>ptr) {
SYNCTEX_CUR = end;
return (synctex_is_s){result,SYNCTEX_STATUS_OK};
}
return (synctex_is_s){result,SYNCTEX_STATUS_NOT_OK};
}
static synctex_is_s _synctex_decode_int_opt(synctex_scanner_p scanner, int default_value) {
char * ptr = NULL;
char * end = NULL;
synctex_zs_s zs = {0, 0};
if (NULL == scanner) {
return (synctex_is_s){default_value, SYNCTEX_STATUS_BAD_ARGUMENT};
}
zs = _synctex_buffer_get_available_size(scanner, SYNCTEX_BUFFER_MIN_SIZE);
if (zs.status<SYNCTEX_STATUS_EOF) {
return (synctex_is_s){default_value,zs.status};
}
if (zs.size==0) {
return (synctex_is_s){default_value,SYNCTEX_STATUS_OK};
}
ptr = SYNCTEX_CUR;
/* Comma separator required */
if (*ptr==',') {
int result;
++ptr;
--zs.size;
if (zs.size==0) {
return (synctex_is_s){default_value,SYNCTEX_STATUS_NOT_OK};
}
result = (int)strtol(ptr, &end, 10);
if (end>ptr) {
SYNCTEX_CUR = end;
return (synctex_is_s){result,SYNCTEX_STATUS_OK};
}
return (synctex_is_s){default_value,SYNCTEX_STATUS_NOT_OK};
}
return (synctex_is_s){default_value,SYNCTEX_STATUS_OK};
}
/* Used when parsing the synctex file.
* Decode an integer for a v field.
* Try the _synctex_decode_int version and set the last v field scanned.
* If it does not succeed, tries to match an '=' sign,
* which is a shortcut for the last v field scanned.
*/
# define SYNCTEX_INPUT_COMEQUALS ",="
static synctex_is_s _synctex_decode_int_v(synctex_scanner_p scanner) {
synctex_is_s is = _synctex_decode_int(scanner);
if (SYNCTEX_STATUS_OK == is.status) {
scanner->lastv = is.integer;
return is;
}
is.status = _synctex_match_string(scanner,SYNCTEX_INPUT_COMEQUALS);
if (is.status<SYNCTEX_STATUS_OK) {
return is;
}
is.integer = scanner->lastv;
return is;
}
/* The purpose of this function is to read a string.
* A string is an array of characters from the current parser location
* and before the next '\n' character.
* If a string was properly decoded, it is returned in value_ref and
* the cursor points to the new line marker.
* The returned string was alloced on the heap, the caller is the owner and
* is responsible to free it in due time.
* If no string is parsed, * value_ref is undefined.
* The maximum length of a string that a scanner can decode is platform dependent, namely UINT_MAX.
* If you just want to blindly parse the file up to the end of the current line,
* use _synctex_next_line instead.
* On return, the scanner cursor is unchanged if a string could not be scanned or
* points to the terminating '\n' character otherwise. As a consequence,
* _synctex_next_line is necessary after.
* If either scanner or value_ref is NULL, it is considered as an error and
* SYNCTEX_STATUS_BAD_ARGUMENT is returned.
*/
static synctex_ss_s _synctex_decode_string(synctex_scanner_p scanner) {
char * end = NULL;
size_t len = 0;/* The number of bytes to copy */
size_t already_len = 0;
synctex_zs_s zs = {0,0};
char * string = NULL;
if (NULL == scanner) {
return (synctex_ss_s){NULL,SYNCTEX_STATUS_BAD_ARGUMENT};
}
/* The buffer must at least contain one character: the '\n' end of line marker */
if (SYNCTEX_CUR>=SYNCTEX_END) {
more_characters:
zs = _synctex_buffer_get_available_size(scanner,1);
if (zs.status < SYNCTEX_STATUS_EOF) {
return (synctex_ss_s){NULL,zs.status};
} else if (0 == zs.size) {
return (synctex_ss_s){NULL,SYNCTEX_STATUS_EOF};
}
}
/* Now we are sure that there is at least one available character, either because
* SYNCTEX_CUR was already < SYNCTEX_END, or because the buffer has been properly filled. */
/* end will point to the next unparsed '\n' character in the file, when mapped to the buffer. */
end = SYNCTEX_CUR;
/* We scan all the characters up to the next '\n' */
while (end<SYNCTEX_END && *end != '\n') {
++end;
}
/* OK, we found where to stop:
* either end == SYNCTEX_END
* or *end == '\n' */
len = end - SYNCTEX_CUR;
if (len<UINT_MAX-already_len) {
if ((string = realloc(string,len+already_len+1)) != NULL) {
if (memcpy(string+already_len,SYNCTEX_CUR,len)) {
already_len += len;
string[already_len]='\0'; /* Terminate the string */
SYNCTEX_CUR += len;/* Advance to the terminating '\n' */
if (SYNCTEX_CUR==SYNCTEX_END) {
/* No \n found*/
goto more_characters;
}
return (synctex_ss_s){string,SYNCTEX_STATUS_OK};
}
free(string);
_synctex_error("could not copy memory (1).");
return (synctex_ss_s){NULL,SYNCTEX_STATUS_ERROR};
}
}
_synctex_error("could not (re)allocate memory (1).");
return (synctex_ss_s){NULL,SYNCTEX_STATUS_ERROR};
}
/* Used when parsing the synctex file.
* Read an Input record.
* - parameter scanner: non NULL scanner
* - returns SYNCTEX_STATUS_OK on successful completions, others values otherwise.
*/
static synctex_ns_s __synctex_parse_new_input(synctex_scanner_p scanner) {
synctex_node_p input = NULL;
synctex_status_t status = SYNCTEX_STATUS_BAD_ARGUMENT;
synctex_zs_s zs = {0,0};
if (NULL == scanner) {
return (synctex_ns_s){NULL,status};;
}
if ((status=_synctex_match_string(scanner,SYNCTEX_INPUT_MARK))<SYNCTEX_STATUS_OK) {
return (synctex_ns_s){NULL,status};
}
/* Create a node */
if (NULL == (input = _synctex_new_input(scanner))) {
_synctex_error("Could not create an input node.");
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
/* Decode the tag */
if ((status=_synctex_data_decode_tag(input))<SYNCTEX_STATUS_OK) {
_synctex_error("Bad format of input node.");
synctex_node_free(input);
return (synctex_ns_s){NULL,status};
}
/* The next character is a field separator, we expect one character in the buffer. */
zs = _synctex_buffer_get_available_size(scanner, 1);
if (zs.status<=SYNCTEX_STATUS_ERROR) {
return (synctex_ns_s){NULL,status};
}
if (0 == zs.size) {
return (synctex_ns_s){NULL,SYNCTEX_STATUS_EOF};
}
/* We can now safely advance to the next character, stepping over the field separator. */
++SYNCTEX_CUR;
--zs.size;
/* Then we scan the file name */
if ((status=_synctex_data_decode_name(input))<SYNCTEX_STATUS_OK) {
synctex_node_free(input);
_synctex_next_line(scanner);/* Ignore this whole line */
return (synctex_ns_s){NULL,status};
}
/* Prepend this input node to the input linked list of the scanner */
__synctex_tree_set_sibling(input,scanner->input);/* input has no parent */
scanner->input = input;
# if SYNCTEX_VERBOSE
synctex_node_log(input);
# endif
return (synctex_ns_s){input,_synctex_next_line(scanner)};/* read the line termination character, if any */
}
typedef synctex_is_s (*synctex_decoder_t)(synctex_scanner_p);
/* Used when parsing the synctex file.
* Read one of the settings.
* On normal completion, returns SYNCTEX_STATUS_OK.
* On error, returns SYNCTEX_STATUS_ERROR.
* Both arguments must not be NULL.
* On return, the scanner points to the next character after the decoded object whatever it is.
* It is the responsibility of the caller to prepare the scanner for the next line.
*/
static synctex_status_t _synctex_scan_named(synctex_scanner_p scanner,const char * name) {
synctex_status_t status = 0;
if (NULL == scanner || NULL == name) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
not_found:
status = _synctex_match_string(scanner,name);
if (status<SYNCTEX_STATUS_NOT_OK) {
return status;
} else if (status == SYNCTEX_STATUS_NOT_OK) {
status = _synctex_next_line(scanner);
if (status<SYNCTEX_STATUS_OK) {
return status;
}
goto not_found;
}
return SYNCTEX_STATUS_OK;
}
/* Used when parsing the synctex file.
* Read the preamble.
*/
static synctex_status_t _synctex_scan_preamble(synctex_scanner_p scanner) {
synctex_status_t status = 0;
synctex_is_s is = {0,0};
synctex_ss_s ss = {NULL,0};
if (NULL == scanner) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
status = _synctex_scan_named(scanner,"SyncTeX Version:");
if (status<SYNCTEX_STATUS_OK) {
return status;
}
is = _synctex_decode_int(scanner);
if (is.status<SYNCTEX_STATUS_OK) {
return is.status;
}
status = _synctex_next_line(scanner);
if (status<SYNCTEX_STATUS_OK) {
return status;
}
scanner->version = is.integer;
/* Read all the input records */
do {
status = __synctex_parse_new_input(scanner).status;
if (status<SYNCTEX_STATUS_NOT_OK) {
return status;
}
} while(status == SYNCTEX_STATUS_OK);
/* the loop exits when status == SYNCTEX_STATUS_NOT_OK */
/* Now read all the required settings. */
if ((status=_synctex_scan_named(scanner,"Output:"))<SYNCTEX_STATUS_OK) {
return status;
}
if ((ss=_synctex_decode_string(scanner)).status<SYNCTEX_STATUS_OK) {
return is.status;
}
if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
return status;
}
scanner->output_fmt = ss.string;
if ((status=_synctex_scan_named(scanner,"Magnification:"))<SYNCTEX_STATUS_OK) {
return status;
}
if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
return is.status;
}
if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
return status;
}
scanner->pre_magnification = is.integer;
if ((status=_synctex_scan_named(scanner,"Unit:"))<SYNCTEX_STATUS_OK) {
return status;
}
if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
return is.status;
}
if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
return status;
}
scanner->pre_unit = is.integer;
if ((status=_synctex_scan_named(scanner,"X Offset:"))<SYNCTEX_STATUS_OK) {
return status;
}
if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
return is.status;
}
if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
return status;
}
scanner->pre_x_offset = is.integer;
if ((status=_synctex_scan_named(scanner,"Y Offset:"))<SYNCTEX_STATUS_OK) {
return status;
}
if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
return is.status;
}
if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
return status;
}
scanner->pre_y_offset = is.integer;
return SYNCTEX_STATUS_OK;
}
/* parse a float with a dimension */
static synctex_fs_s _synctex_scan_float_and_dimension(synctex_scanner_p scanner) {
synctex_fs_s fs = {0,0};
synctex_zs_s zs = {0,0};
char * endptr = NULL;
#ifdef HAVE_SETLOCALE
char * loc = setlocale(LC_NUMERIC, NULL);
#endif
if (NULL == scanner) {
return (synctex_fs_s){0,SYNCTEX_STATUS_BAD_ARGUMENT};
}
zs = _synctex_buffer_get_available_size(scanner, SYNCTEX_BUFFER_MIN_SIZE);
if (zs.status<SYNCTEX_STATUS_EOF) {
_synctex_error("Problem with float.");
return (synctex_fs_s){0,zs.status};
}
#ifdef HAVE_SETLOCALE
setlocale(LC_NUMERIC, "C");
#endif
fs.value = strtod(SYNCTEX_CUR,&endptr);
#ifdef HAVE_SETLOCALE
setlocale(LC_NUMERIC, loc);
#endif
if (endptr == SYNCTEX_CUR) {
_synctex_error("A float was expected.");
return (synctex_fs_s){0,SYNCTEX_STATUS_ERROR};
}
SYNCTEX_CUR = endptr;
if ((fs.status = _synctex_match_string(scanner,"in")) >= SYNCTEX_STATUS_OK) {
fs.value *= 72.27f*65536;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
report_unit_error:
_synctex_error("problem with unit.");
return fs;
} else if ((fs.status = _synctex_match_string(scanner,"cm")) >= SYNCTEX_STATUS_OK) {
fs.value *= 72.27f*65536/2.54f;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
} else if ((fs.status = _synctex_match_string(scanner,"mm")) >= SYNCTEX_STATUS_OK) {
fs.value *= 72.27f*65536/25.4f;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
} else if ((fs.status = _synctex_match_string(scanner,"pt")) >= SYNCTEX_STATUS_OK) {
fs.value *= 65536.0f;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
} else if ((fs.status = _synctex_match_string(scanner,"bp")) >= SYNCTEX_STATUS_OK) {
fs.value *= 72.27f/72*65536.0f;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
} else if ((fs.status = _synctex_match_string(scanner,"pc")) >= SYNCTEX_STATUS_OK) {
fs.value *= 12.0*65536.0f;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
} else if ((fs.status = _synctex_match_string(scanner,"sp")) >= SYNCTEX_STATUS_OK) {
fs.value *= 1.0f;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
} else if ((fs.status = _synctex_match_string(scanner,"dd")) >= SYNCTEX_STATUS_OK) {
fs.value *= 1238.0f/1157*65536.0f;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
} else if ((fs.status = _synctex_match_string(scanner,"cc")) >= SYNCTEX_STATUS_OK) {
fs.value *= 14856.0f/1157*65536;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
} else if ((fs.status = _synctex_match_string(scanner,"nd")) >= SYNCTEX_STATUS_OK) {
fs.value *= 685.0f/642*65536;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
} else if ((fs.status = _synctex_match_string(scanner,"nc")) >= SYNCTEX_STATUS_OK) {
fs.value *= 1370.0f/107*65536;
} else if (fs.status<SYNCTEX_STATUS_EOF) {
goto report_unit_error;
}
return fs;
}
/* parse the post scriptum
* SYNCTEX_STATUS_OK is returned on completion
* a negative error is returned otherwise */
static synctex_status_t _synctex_scan_post_scriptum(synctex_scanner_p scanner) {
synctex_status_t status = 0;
synctex_fs_s fs = {0,0};
char * endptr = NULL;
#ifdef HAVE_SETLOCALE
char * loc = setlocale(LC_NUMERIC, NULL);
#endif
if (NULL == scanner) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
/* Scan the file until a post scriptum line is found */
post_scriptum_not_found:
status = _synctex_match_string(scanner,"Post scriptum:");
if (status<SYNCTEX_STATUS_NOT_OK) {
return status;
}
if (status == SYNCTEX_STATUS_NOT_OK) {
status = _synctex_next_line(scanner);
if (status<SYNCTEX_STATUS_EOF) {
return status;
} else if (status<SYNCTEX_STATUS_OK) {
return SYNCTEX_STATUS_OK;/* The EOF is found, we have properly scanned the file */
}
goto post_scriptum_not_found;
}
/* We found the name, advance to the next line. */
next_line:
status = _synctex_next_line(scanner);
if (status<SYNCTEX_STATUS_EOF) {
return status;
} else if (status<SYNCTEX_STATUS_OK) {
return SYNCTEX_STATUS_OK;/* The EOF is found, we have properly scanned the file */
}
/* Scanning the information */
status = _synctex_match_string(scanner,"Magnification:");
if (status == SYNCTEX_STATUS_OK ) {
#ifdef HAVE_SETLOCALE
setlocale(LC_NUMERIC, "C");
#endif
scanner->unit = strtod(SYNCTEX_CUR,&endptr);
#ifdef HAVE_SETLOCALE
setlocale(LC_NUMERIC, loc);
#endif
if (endptr == SYNCTEX_CUR) {
_synctex_error("bad magnification in the post scriptum, a float was expected.");
return SYNCTEX_STATUS_ERROR;
}
if (scanner->unit<=0) {
_synctex_error("bad magnification in the post scriptum, a positive float was expected.");
return SYNCTEX_STATUS_ERROR;
}
SYNCTEX_CUR = endptr;
goto next_line;
}
if (status<SYNCTEX_STATUS_EOF){
report_record_problem:
_synctex_error("Problem reading the Post Scriptum records");
return status; /* echo the error. */
}
status = _synctex_match_string(scanner,"X Offset:");
if (status == SYNCTEX_STATUS_OK) {
fs = _synctex_scan_float_and_dimension(scanner);
if (fs.status<SYNCTEX_STATUS_OK) {
_synctex_error("Problem with X offset in the Post Scriptum.");
return fs.status;
}
scanner->x_offset = fs.value;
goto next_line;
} else if (status<SYNCTEX_STATUS_EOF){
goto report_record_problem;
}
status = _synctex_match_string(scanner,"Y Offset:");
if (status==SYNCTEX_STATUS_OK) {
fs = _synctex_scan_float_and_dimension(scanner);
if (fs.status<SYNCTEX_STATUS_OK) {
_synctex_error("Problem with Y offset in the Post Scriptum.");
return fs.status;
}
scanner->x_offset = fs.value;
goto next_line;
} else if (status<SYNCTEX_STATUS_EOF){
goto report_record_problem;
}
goto next_line;
}
/* SYNCTEX_STATUS_OK is returned if the postamble is read
* SYNCTEX_STATUS_NOT_OK is returned if the postamble is not at the current location
* a negative error otherwise
* The postamble comprises the post scriptum section.
*/
static synctex_status_t _synctex_scan_postamble(synctex_scanner_p scanner) {
synctex_status_t status = 0;
synctex_is_s is = {0,0};
if (NULL == scanner) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
if (!scanner->flags.postamble && (status=_synctex_match_string(scanner,"Postamble:"))<SYNCTEX_STATUS_OK) {
return status;
}
count_again:
if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
return status;
}
if ((status=_synctex_scan_named(scanner,"Count:"))< SYNCTEX_STATUS_EOF) {
return status; /* forward the error */
} else if (status < SYNCTEX_STATUS_OK) { /* No Count record found */
goto count_again;
}
if ((is=_synctex_decode_int(scanner)).status<SYNCTEX_STATUS_OK) {
return is.status;
}
if ((status=_synctex_next_line(scanner))<SYNCTEX_STATUS_OK) {
return status;
}
scanner->count = is.integer;
/* Now we scan the last part of the SyncTeX file: the Post Scriptum section. */
return _synctex_scan_post_scriptum(scanner);
}
/* Horizontal boxes also have visible size.
* Visible size are bigger than real size.
* For example 0 width boxes may contain text.
* At creation time, the visible size is set to the values of the real size.
*/
static synctex_status_t _synctex_setup_visible_hbox(synctex_node_p box) {
if (box) {
switch(SYNCTEX_TYPE(box)) {
case synctex_node_type_hbox:
_synctex_data_set_h_V(box,_synctex_data_h(box));
_synctex_data_set_v_V(box,_synctex_data_v(box));
_synctex_data_set_width_V(box,_synctex_data_width(box));
_synctex_data_set_height_V(box,_synctex_data_height(box));
_synctex_data_set_depth_V(box,_synctex_data_depth(box));
return SYNCTEX_STATUS_OK;
}
}
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
/* This method is sent to an horizontal box to setup the visible size
* Some box have 0 width but do contain text material.
* With this method, one can enlarge the box to contain the given point (h,v).
*/
static synctex_status_t _synctex_make_hbox_contain_point(synctex_node_p node,synctex_point_s point) {
int min, max, n;
if (NULL == node || SYNCTEX_TYPE(node) != synctex_node_type_hbox) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
if ((n = _synctex_data_width_V(node))<0) {
max = _synctex_data_h_V(node);
min = max+n;
if (point.h<min) {
_synctex_data_set_width_V(node,point.h-max);
} else if (point.h>max) {
_synctex_data_set_h_V(node,point.h);
_synctex_data_set_width_V(node,min-point.h);
}
} else {
min = _synctex_data_h_V(node);
max = min+n;
if (point.h<min) {
_synctex_data_set_h_V(node,point.h);
_synctex_data_set_width_V(node,max - point.h);
} else if (point.h>max) {
_synctex_data_set_width_V(node,point.h - min);
}
}
n = _synctex_data_v_V(node);
min = n - _synctex_data_height_V(node);
max = n + _synctex_data_depth_V(node);
if (point.v<min) {
_synctex_data_set_height_V(node,n-point.v);
} else if (point.v>max) {
_synctex_data_set_depth_V(node,point.v-n);
}
return SYNCTEX_STATUS_OK;
}
static synctex_status_t _synctex_make_hbox_contain_box(synctex_node_p node,synctex_box_s box) {
int min, max, n;
if (NULL == node || SYNCTEX_TYPE(node) != synctex_node_type_hbox) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
if ((n = _synctex_data_width_V(node))<0) {
max = _synctex_data_h_V(node);
min = max+n;
if (box.min.h <min) {
_synctex_data_set_width_V(node,box.min.h-max);
} else if (box.max.h>max) {
_synctex_data_set_h_V(node,box.max.h);
_synctex_data_set_width_V(node,min-box.max.h);
}
} else {
min = _synctex_data_h_V(node);
max = min+n;
if (box.min.h<min) {
_synctex_data_set_h_V(node,box.min.h);
_synctex_data_set_width_V(node,max - box.min.h);
} else if (box.max.h>max) {
_synctex_data_set_width_V(node,box.max.h - min);
}
}
n = _synctex_data_v_V(node);
min = n - _synctex_data_height_V(node);
max = n + _synctex_data_depth_V(node);
if (box.min.v<min) {
_synctex_data_set_height_V(node,n-box.min.v);
} else if (box.max.v>max) {
_synctex_data_set_depth_V(node,box.max.v-n);
}
return SYNCTEX_STATUS_OK;
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark SPECIAL CHARACTERS
# endif
/* Here are the control characters that strat each line of the synctex output file.
* Their values define the meaning of the line.
*/
# define SYNCTEX_CHAR_BEGIN_SHEET '{'
# define SYNCTEX_CHAR_END_SHEET '}'
# define SYNCTEX_CHAR_BEGIN_FORM '<'
# define SYNCTEX_CHAR_END_FORM '>'
# define SYNCTEX_CHAR_BEGIN_VBOX '['
# define SYNCTEX_CHAR_END_VBOX ']'
# define SYNCTEX_CHAR_BEGIN_HBOX '('
# define SYNCTEX_CHAR_END_HBOX ')'
# define SYNCTEX_CHAR_ANCHOR '!'
# define SYNCTEX_CHAR_VOID_VBOX 'v'
# define SYNCTEX_CHAR_VOID_HBOX 'h'
# define SYNCTEX_CHAR_KERN 'k'
# define SYNCTEX_CHAR_GLUE 'g'
# define SYNCTEX_CHAR_RULE 'r'
# define SYNCTEX_CHAR_MATH '$'
# define SYNCTEX_CHAR_FORM_REF 'f'
# define SYNCTEX_CHAR_BOUNDARY 'x'
# define SYNCTEX_CHAR_CHARACTER 'c'
# define SYNCTEX_RETURN(STATUS) return STATUS;
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark SCANNERS & PARSERS
# endif
# define SYNCTEX_DECODE_FAILED(NODE,WHAT) \
(_synctex_data_decode_##WHAT(NODE)<SYNCTEX_STATUS_OK)
# define SYNCTEX_DECODE_FAILED_V(NODE,WHAT) \
(_synctex_data_decode_##WHAT##_v(NODE)<SYNCTEX_STATUS_OK)
#define SYNCTEX_NS_NULL (synctex_ns_s){NULL,SYNCTEX_STATUS_NOT_OK}
static synctex_ns_s _synctex_parse_new_sheet(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_sheet(scanner))) {
if (
SYNCTEX_DECODE_FAILED(node,page)) {
_synctex_error("Bad sheet record.");
} else if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of sheet.");
} else {
/* Now set the owner */
if (scanner->sheet) {
synctex_node_p last_sheet = scanner->sheet;
synctex_node_p next_sheet = NULL;
while ((next_sheet = __synctex_tree_sibling(last_sheet))) {
last_sheet = next_sheet;
}
__synctex_tree_set_sibling(last_sheet,node); /* sheets have no parent */
} else {
scanner->sheet = node;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_free_node(node);
}
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
/**
* - requirement: scanner != NULL
*/
static synctex_ns_s _synctex_parse_new_form(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_form(scanner))) {
if (
SYNCTEX_DECODE_FAILED(node,tag)) {
_synctex_error("Bad sheet record.");
} else if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of form.");
} else {
/* Now set the owner */
if (scanner->form) {
synctex_node_p last_form = scanner->form;
synctex_node_p next_form = NULL;
while ((next_form = __synctex_tree_sibling(last_form))) {
last_form = next_form;
}
__synctex_tree_set_sibling(last_form,node);
} else {
scanner->form = node;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_free_node(node);
}
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
# define SYNCTEX_SHOULD_DECODE_FAILED(NODE,WHAT) \
(_synctex_data_has_##WHAT(NODE) &&(_synctex_data_decode_##WHAT(NODE)<SYNCTEX_STATUS_OK))
# define SYNCTEX_SHOULD_DECODE_FAILED_V(NODE,WHAT) \
(_synctex_data_has_##WHAT(NODE) &&(_synctex_data_decode_##WHAT##_v(NODE)<SYNCTEX_STATUS_OK))
static synctex_status_t _synctex_data_decode_tlchvwhd(synctex_node_p node) {
return SYNCTEX_SHOULD_DECODE_FAILED(node,tag)
|| SYNCTEX_SHOULD_DECODE_FAILED(node,line)
|| SYNCTEX_SHOULD_DECODE_FAILED(node,column)
|| SYNCTEX_SHOULD_DECODE_FAILED(node,h)
|| SYNCTEX_SHOULD_DECODE_FAILED_V(node,v)
|| SYNCTEX_SHOULD_DECODE_FAILED(node,width)
|| SYNCTEX_SHOULD_DECODE_FAILED(node,height)
|| SYNCTEX_SHOULD_DECODE_FAILED(node,depth);
}
static synctex_ns_s _synctex_parse_new_vbox(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_vbox(scanner))) {
if (_synctex_data_decode_tlchvwhd(node)) {
_synctex_error("Bad vbox record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of vbox.");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
SYNCTEX_INLINE static synctex_node_p __synctex_node_make_friend_tlc(synctex_node_p node);
static synctex_ns_s _synctex_parse_new_hbox(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_hbox(scanner))) {
if (_synctex_data_decode_tlchvwhd(node)) {
_synctex_error("Bad hbox record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of hbox.");
goto out;
}
if (_synctex_setup_visible_hbox(node)<SYNCTEX_STATUS_OK) {
_synctex_error("Unexpected error (_synctex_parse_new_hbox).");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
static synctex_ns_s _synctex_parse_new_void_vbox(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_void_vbox(scanner))) {
if (_synctex_data_decode_tlchvwhd(node)) {
_synctex_error("Bad void vbox record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of container.");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
static synctex_ns_s _synctex_parse_new_void_hbox(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_void_hbox(scanner))) {
if (_synctex_data_decode_tlchvwhd(node)) {
_synctex_error("Bad void hbox record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of container.");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
static synctex_ns_s _synctex_parse_new_kern(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_kern(scanner))) {
if (_synctex_data_decode_tlchvwhd(node)) {
_synctex_error("Bad kern record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of container.");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
static synctex_ns_s _synctex_parse_new_glue(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_glue(scanner))) {
if (_synctex_data_decode_tlchvwhd(node)) {
_synctex_error("Bad glue record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of container.");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
static synctex_ns_s _synctex_parse_new_rule(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_rule(scanner))) {
if (_synctex_data_decode_tlchvwhd(node)) {
_synctex_error("Bad rule record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of container.");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
static synctex_ns_s _synctex_parse_new_math(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_math(scanner))) {
if (_synctex_data_decode_tlchvwhd(node)) {
_synctex_error("Bad math record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of container.");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
static synctex_ns_s _synctex_parse_new_boundary(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_boundary(scanner))) {
if (_synctex_data_decode_tlchvwhd(node)) {
_synctex_error("Bad boundary record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of container.");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
SYNCTEX_INLINE static synctex_ns_s _synctex_parse_new_ref(synctex_scanner_p scanner) {
synctex_node_p node;
if ((node = _synctex_new_ref(scanner))) {
if (SYNCTEX_DECODE_FAILED(node,tag)
|| SYNCTEX_DECODE_FAILED(node,h)
|| SYNCTEX_DECODE_FAILED_V(node,v)) {
_synctex_error("Bad form ref record.");
_synctex_next_line(scanner);
out:
_synctex_free_node(node);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of container.");
goto out;
}
return (synctex_ns_s){node,SYNCTEX_STATUS_OK};
}
_synctex_next_line(scanner);
return (synctex_ns_s){NULL,SYNCTEX_STATUS_ERROR};
}
# undef SYNCTEX_DECODE_FAILED
# undef SYNCTEX_DECODE_FAILED_V
SYNCTEX_INLINE static synctex_point_s _synctex_data_point(synctex_node_p node);
SYNCTEX_INLINE static synctex_point_s _synctex_data_point_V(synctex_node_p node);
SYNCTEX_INLINE static synctex_point_s _synctex_data_set_point(synctex_node_p node, synctex_point_s point);
SYNCTEX_INLINE static synctex_box_s _synctex_data_box(synctex_node_p node);
SYNCTEX_INLINE static synctex_box_s _synctex_data_xob(synctex_node_p node);
SYNCTEX_INLINE static synctex_box_s _synctex_data_box_V(synctex_node_p node);
SYNCTEX_INLINE static synctex_node_p _synctex_input_register_line(synctex_node_p input,synctex_node_p node) {
if (node && _synctex_data_tag(input) != _synctex_data_tag(node)) {
input = synctex_scanner_input_with_tag(node->class->scanner,_synctex_data_tag(node));
}
if (_synctex_data_line(node)>_synctex_data_line(input)) {
_synctex_data_set_line(input,_synctex_data_line(node));
}
return input;
}
/**
* Scan sheets, forms and input records.
* - parameter scanner: owning scanner
* - returns: status
*/
static synctex_status_t __synctex_parse_sfi(synctex_scanner_p scanner) {
synctex_status_t status = SYNCTEX_STATUS_OK;
synctex_zs_s zs = {0,0};
synctex_ns_s input = SYNCTEX_NS_NULL;
synctex_node_p sheet = NULL;
synctex_node_p form = NULL;
synctex_node_p parent = NULL;
synctex_node_p child = NULL;
synctex_ns_s ns = SYNCTEX_NS_NULL;
int form_depth = 0;
int ignored_form_depth = 0;
synctex_bool_t try_input = synctex_YES;
# ifdef SYNCTEX_NOTHING
# pragma mark MAIN LOOP
# endif
main_loop:
status = SYNCTEX_STATUS_OK;
sheet = form = parent = child = NULL;
# define SYNCTEX_START_SCAN(WHAT)\
(*SYNCTEX_CUR == SYNCTEX_CHAR_##WHAT)
if (SYNCTEX_CUR<SYNCTEX_END) {
if (SYNCTEX_START_SCAN(BEGIN_FORM)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN FORM
# endif
scan_form:
ns = _synctex_parse_new_form(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
++form_depth;
if (_synctex_tree_parent(form)) {
/* This form is already being parsed */
++ignored_form_depth;
goto ignore_loop;
}
_synctex_tree_set_parent(ns.node,form);
form = ns.node;
parent = form;
child = NULL;
goto content_loop;
}
if (form || sheet) {
goto content_loop;
}
try_input = synctex_YES;
goto main_loop;
} else if (SYNCTEX_START_SCAN(BEGIN_SHEET)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN SHEET
# endif
try_input = synctex_YES;
ns = _synctex_parse_new_sheet(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
sheet = ns.node;
parent = sheet;
goto content_loop;
}
goto main_loop;
} else if (SYNCTEX_START_SCAN(ANCHOR)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN ANCHOR
# endif
scan_anchor:
++SYNCTEX_CUR;
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing anchor.");
SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
}
if (form || sheet) {
goto content_loop;
}
try_input = synctex_YES;
goto main_loop;
} else if (try_input) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN INPUT
# endif
try_input = synctex_NO;
do {
input = __synctex_parse_new_input(scanner);
} while (input.status == SYNCTEX_STATUS_OK);
goto main_loop;
}
status = _synctex_match_string(scanner,"Postamble:");
if (status==SYNCTEX_STATUS_OK) {
scanner->flags.postamble = 1;
return status;
}
status = _synctex_next_line(scanner);
if (status<SYNCTEX_STATUS_OK) {
return status;
}
}
/* At least 1 more character */
zs = _synctex_buffer_get_available_size(scanner,1);
if (zs.size == 0){
_synctex_error("Uncomplete synctex file, postamble missing.");
SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
}
goto main_loop;
/* Unreachable. */
# ifdef SYNCTEX_NOTHING
# pragma mark IGNORE LOOP
# endif
ignore_loop:
ns = SYNCTEX_NS_NULL;
if (SYNCTEX_CUR<SYNCTEX_END) {
if (SYNCTEX_START_SCAN(BEGIN_FORM)) {
++ignored_form_depth;
} else if (SYNCTEX_START_SCAN(END_FORM)) {
--ignored_form_depth;
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Uncomplete container.");
SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
}
} else {
zs = _synctex_buffer_get_available_size(scanner,1);
if (zs.size == 0){
_synctex_error("Uncomplete synctex file, postamble missing.");
SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
}
}
if (ignored_form_depth) {
goto ignore_loop;
} else {
goto content_loop;
}
# ifdef SYNCTEX_NOTHING
# pragma mark CONTENT LOOP
# endif
content_loop:
/* Either in a form, a sheet or a box.
* - in a sheet, "{" is not possible, only boxes and "}" at top level.
* - in a form, "{" is not possible, only boxes, "<" and ">" at top level.
* - in a box, the unique possibility is '<', '[', '(' or ">".
* We still keep the '(' for a sheet, because that dos not cost too much.
* We must also consider void boxes as children.
*/
/* forms are everywhere */
ns = SYNCTEX_NS_NULL;
#if SYNCTEX_VERBOSE
synctex_scanner_set_display_switcher(scanner,-1);
printf("NEW CONTENT LOOP\n");
#if SYNCTEX_DEBUG>500
synctex_node_display(sheet);
#endif
#endif
if (SYNCTEX_CUR<SYNCTEX_END) {
if (SYNCTEX_START_SCAN(BEGIN_FORM)) {
goto scan_form;
} else if (SYNCTEX_START_SCAN(BEGIN_VBOX)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN VBOX
# endif
ns = _synctex_parse_new_vbox(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
parent = ns.node;
child = _synctex_tree_last(parent);
# if SYNCTEX_VERBOSE
synctex_node_log(parent);
# endif
input.node = _synctex_input_register_line(input.node,parent);
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(END_VBOX)) {
if (SYNCTEX_TYPE(parent) == synctex_node_type_vbox) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN XOBV
# endif
++SYNCTEX_CUR;
if (NULL == _synctex_tree_child(parent) && !form) {
/* only void v boxes are friends */
_synctex_node_make_friend_tlc(parent);
}
child = parent;
parent = _synctex_tree_parent(child);
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Uncomplete container.");
SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
}
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(BEGIN_HBOX)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN HBOX
# endif
# if defined(SYNCTEX_USE_CHARINDEX)
synctex_charindex_t char_index = (synctex_charindex_t)(scanner->charindex_offset+SYNCTEX_CUR-SYNCTEX_START);
synctex_lineindex_t line_index = scanner->line_number;
# endif
ns = _synctex_parse_new_hbox(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
parent = ns.node;
/* add a box boundary node at the start */
if ((child = _synctex_new_box_bdry(scanner))) {
# if defined(SYNCTEX_USE_CHARINDEX)
child->line_index=line_index;
child->char_index=char_index;
# endif
_synctex_node_set_child(parent,child);
_synctex_data_set_tag(child,_synctex_data_tag(parent));
_synctex_data_set_line(child,_synctex_data_line(parent));
_synctex_data_set_h(child,_synctex_data_h(parent));
_synctex_data_set_v(child,_synctex_data_v(parent));
if (!form) {
__synctex_node_make_friend_tlc(child);
}
} else {
_synctex_error("Can't create box bdry record.");
}
# if SYNCTEX_VERBOSE
synctex_node_log(parent);
# endif
input.node = _synctex_input_register_line(input.node,parent);
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(END_HBOX)) {
if (SYNCTEX_TYPE(parent) == synctex_node_type_hbox) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN XOBH
# endif
++SYNCTEX_CUR;
{
/* setting the next horizontal box at the end ensures
* that a child is recorded before any of its ancestors.
*/
if (form == NULL /* && sheet != NULL*/ ) {
_synctex_tree_set_next_hbox(parent,_synctex_tree_next_hbox(sheet));
_synctex_tree_set_next_hbox(sheet,parent);
}
/* Update the mean line number */
synctex_node_p node = _synctex_tree_child(parent);
synctex_node_p sibling = NULL;
/* Ignore the first node (a box_bdry) */
if (node && (node = __synctex_tree_sibling(node))) {
unsigned int node_weight = 0;
unsigned int cumulated_line_numbers = 0;
do {
if (synctex_node_type(node)==synctex_node_type_hbox) {
if (_synctex_data_weight(node)) {
node_weight += _synctex_data_weight(node);
cumulated_line_numbers += _synctex_data_mean_line(node)*_synctex_data_weight(node);
} else {
++node_weight;
cumulated_line_numbers += _synctex_data_mean_line(node);
}
} else {
++node_weight;
cumulated_line_numbers += synctex_node_line(node);
}
} while ((node = __synctex_tree_sibling(node)));
_synctex_data_set_mean_line(parent,(cumulated_line_numbers + node_weight/2)/node_weight);
_synctex_data_set_weight(parent,node_weight);
} else {
_synctex_data_set_mean_line(parent,_synctex_data_line(parent));
_synctex_data_set_weight(parent,1);
}
if ((sibling = _synctex_new_box_bdry(scanner))) {
# if defined(SYNCTEX_USE_CHARINDEX)
sibling->line_index=child->line_index;
sibling->char_index=child->char_index;
# endif
_synctex_node_set_sibling(child,sibling);
_synctex_data_set_tag(sibling,_synctex_data_tag(child));
_synctex_data_set_line(sibling,_synctex_data_line(child));
_synctex_data_set_h(sibling,_synctex_data_h_V(parent)+_synctex_data_width_V(parent));
_synctex_data_set_v(sibling,_synctex_data_v_V(parent));
child = sibling;
} else {
_synctex_error("Can't create box bdry record.");
}
sibling = _synctex_tree_child(parent);
_synctex_data_set_point(sibling,_synctex_data_point_V(parent));
child = parent;
parent = _synctex_tree_parent(child);
_synctex_make_hbox_contain_box(parent,_synctex_data_box_V(child));
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Uncomplete container.");
SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
}
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(VOID_VBOX)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN VOID VBOX
# endif
ns = _synctex_parse_new_void_vbox(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
child = ns.node;
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
input.node = _synctex_input_register_line(input.node,child);
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(VOID_HBOX)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN VOID HBOX
# endif
ns = _synctex_parse_new_void_hbox(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
if (_synctex_data_width(ns.node)<0) {
printf("Negative width\n");
}
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
child = ns.node;
_synctex_make_hbox_contain_box(parent,_synctex_data_box(child));
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
input.node = _synctex_input_register_line(input.node,child);
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(KERN)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN KERN
# endif
ns = _synctex_parse_new_kern(scanner);
continue_scan:
if (ns.status == SYNCTEX_STATUS_OK) {
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
child = ns.node;
if (!form) {
__synctex_node_make_friend_tlc(child);
}
_synctex_make_hbox_contain_box(parent,_synctex_data_xob(child));
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
input.node = _synctex_input_register_line(input.node,child);
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(GLUE)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN GLUE
# endif
ns = _synctex_parse_new_glue(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
child = ns.node;
if (!form) {
__synctex_node_make_friend_tlc(child);
}
_synctex_make_hbox_contain_point(parent,_synctex_data_point(child));
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
input.node = _synctex_input_register_line(input.node,child);
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(RULE)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN RULE
# endif
ns = _synctex_parse_new_rule(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
child = ns.node;
if (!form) {
__synctex_node_make_friend_tlc(child);
}
/* Rules are sometimes far too big
_synctex_make_hbox_contain_box(parent,_synctex_data_box(child));
*/
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
input.node = _synctex_input_register_line(input.node,child);
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(MATH)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN MATH
# endif
ns = _synctex_parse_new_math(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
child = ns.node;
if (!form) {
__synctex_node_make_friend_tlc(child);
}
_synctex_make_hbox_contain_point(parent,_synctex_data_point(child));
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
input.node = _synctex_input_register_line(input.node,child);
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(FORM_REF)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN FORM REF
# endif
#if SYNCTEX_DEBUG>500
synctex_node_display(parent);
synctex_node_display(child);
#endif
ns = _synctex_parse_new_ref(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
child = ns.node;
if (form) {
if (scanner->ref_in_form) {
synctex_tree_set_friend(child,scanner->ref_in_form);
}
scanner->ref_in_form = child;
} else {
if (scanner->ref_in_sheet) {
synctex_tree_set_friend(child,scanner->ref_in_sheet);
}
scanner->ref_in_sheet = child;
}
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(BOUNDARY)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN BOUNDARY
# endif
ns = _synctex_parse_new_boundary(scanner);
if (ns.status == SYNCTEX_STATUS_OK) {
if (child) {
_synctex_node_set_sibling(child,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
child = ns.node;
if (!form) {
__synctex_node_make_friend_tlc(child);
}
_synctex_make_hbox_contain_point(parent,_synctex_data_point(child));
# if SYNCTEX_VERBOSE
synctex_node_log(child);
# endif
input.node = _synctex_input_register_line(input.node,child);
goto content_loop;
}
} else if (SYNCTEX_START_SCAN(CHARACTER)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN CHARACTER
# endif
++SYNCTEX_CUR;
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of container.");
SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
}
goto content_loop;
} else if (SYNCTEX_START_SCAN(ANCHOR)) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN ANCHOR
# endif
goto scan_anchor;
} else if (SYNCTEX_START_SCAN(END_SHEET)) {
if (sheet && parent == sheet) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN TEEHS
# endif
++SYNCTEX_CUR;
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing anchor.");
}
parent = sheet = NULL;
goto main_loop;
}
} else if (SYNCTEX_START_SCAN(END_FORM)) {
if (parent == form && form_depth > 0) {
# ifdef SYNCTEX_NOTHING
# pragma mark + SCAN MROF
# endif
++SYNCTEX_CUR;
--form_depth;
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK
&& (form_depth || sheet)) {
_synctex_error("Missing end of container.");
return SYNCTEX_STATUS_ERROR;
}
if ((parent = _synctex_tree_parent(form))) {
_synctex_tree_reset_parent(form);
child = form;
form = parent;
goto content_loop;
} else if (sheet) {
form = NULL;
parent = sheet;
child = synctex_node_last_sibling(child);
goto content_loop;
}
goto main_loop;
}
}
_synctex_error("Ignored record <%.20s...>(line %i)\n",SYNCTEX_CUR, scanner->line_number+1);
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Missing end of sheet/form.");
SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
}
goto content_loop;
}
zs = _synctex_buffer_get_available_size(scanner,1);
if (zs.size == 0){
_synctex_error("Uncomplete synctex file, postamble missing.");
SYNCTEX_RETURN(SYNCTEX_STATUS_ERROR);
}
goto content_loop;
}
/**
* Replace ref in its tree hierarchy by a single box
* proxy to the contents of the associated form.
* - argument ref: a ref node with no friend
* - return the proxy created.
* - note: Does nothing if ref is not owned.
* - note: On return, ref will have no parent nor sibling.
* The caller is responsible for releasing ref.
*/
SYNCTEX_INLINE static synctex_ns_s __synctex_replace_ref(synctex_node_p ref) {
synctex_ns_s ns = {NULL,SYNCTEX_STATUS_OK};
synctex_node_p parent;
if ((parent = _synctex_tree_parent(ref))) {
synctex_node_p sibling = __synctex_tree_reset_sibling(ref);
synctex_node_p arg_sibling = synctex_node_arg_sibling(ref);
/* arg_sibling != NULL because it is
* at least a box boundary. */
synctex_node_p target = synctex_form_content(ref->class->scanner, _synctex_data_tag(ref));
/* The target is a single node (box)
* with children and no siblings. */
if ((ns.node = __synctex_new_proxy_from_ref_to(ref, target))) {
/* Insert this proxy instead of ref. */
if (arg_sibling) {
_synctex_node_set_sibling(arg_sibling,ns.node);
} else {
_synctex_node_set_child(parent,ns.node);
}
/* Then append the original sibling of ref. */
_synctex_tree_set_sibling(ns.node,sibling);
# if defined(SYNCTEX_USE_CHARINDEX)
if (synctex_node_type(sibling) == synctex_node_type_box_bdry) {
sibling->char_index = arg_sibling->char_index;
sibling->line_index = arg_sibling->line_index;
}
#endif
#if SYNCTEX_DEBUG>500
printf("! Ref replacement:\n");
synctex_node_log(ref);
synctex_node_display(synctex_node_sibling(ref));
synctex_node_log(proxy);
synctex_node_display(synctex_node_sibling(proxy));
#endif
/* Now P == _synctex_tree_parent(N) */
} else /* simply remove ref */ if (arg_sibling) {
_synctex_tree_set_sibling(arg_sibling,sibling);
} else {
__synctex_tree_set_child(parent,sibling);
}
__synctex_tree_reset_parent(ref);
} else {
_synctex_error("! Missing parent in __synctex_replace_ref. "
"Please report.");
ns.status = SYNCTEX_STATUS_BAD_ARGUMENT;
}
return ns;
}
/**
* The ref is the starting point of a linked list of refs.
* The link is made through the friend field.
* Returns the status and the list of all the proxies created.
* The link is made through the friend field.
*/
SYNCTEX_INLINE static synctex_ns_s _synctex_post_process_ref(synctex_node_p ref) {
synctex_ns_s ns = {NULL, SYNCTEX_STATUS_OK};
while (ref) {
synctex_node_p next_ref = _synctex_tree_reset_friend(ref);
synctex_ns_s sub_ns = __synctex_replace_ref(ref);
if (sub_ns.status < ns.status) {
ns.status = sub_ns.status;
} else {
/* Insert all the created proxies in the list
* sub_ns.node is the last friend,
*/
synctex_tree_set_friend(sub_ns.node,ns.node);
ns.node = sub_ns.node;
}
synctex_node_free(ref);
ref = next_ref;
}
return ns;
}
typedef synctex_node_p (* synctex_processor_f)(synctex_node_p node);
/**
* Apply the processor f to the tree hierarchy rooted at proxy.
* proxy has replaced a form ref, no children yet.
* As a side effect all the hierarchy of nodes will be created.
*/
SYNCTEX_INLINE static synctex_status_t _synctex_post_process_proxy(synctex_node_p proxy, synctex_processor_f f) {
while(proxy) {
synctex_node_p next_proxy = _synctex_tree_friend(proxy);
synctex_node_p halt = __synctex_tree_sibling(proxy);
/* if proxy is the last sibling, halt is NULL.
* Find what should be a next node,
* without creating new nodes. */
if (!halt) {
synctex_node_p parent = _synctex_tree_parent(proxy);
halt = __synctex_tree_sibling(parent);
while (!halt && parent) {
parent = _synctex_tree_parent(parent);
halt = __synctex_tree_sibling(parent);
}
}
do {
printf("POST PROCESSING %s\n",_synctex_node_abstract(proxy));
#if SYNCTEX_DEBUG>500
{
int i,j = 0;
for (i=0;i<proxy->class->scanner->number_of_lists;++i) {
synctex_node_p N = proxy->class->scanner->lists_of_friends[i];
do {
if (N==proxy) {
++j;
printf("%s",)_synctex_node_abstract(N));
}
} while ((N = _synctex_tree_friend(N)));
}
if (j) {
printf("\nBeforehand %i match\n",j);
}
}
#endif
f(proxy);
#if SYNCTEX_DEBUG>500
{
int i,j = 0;
for (i=0;i<proxy->class->scanner->number_of_lists;++i) {
synctex_node_p N = proxy->class->scanner->lists_of_friends[i];
do {
if (N==proxy) {
++j;
printf("%s",_synctex_node_abstract(N));
}
} while ((N = _synctex_tree_friend(N)));
}
if (j) {
printf("\n%i match\n",j);
}
}
#endif
/* Side effect: create the hierarchy on the fly */
proxy = synctex_node_next(proxy); /* Change is here */
#if SYNCTEX_DEBUG>500
if (proxy) {
int i,j = 0;
for (i=0;i<proxy->class->scanner->number_of_lists;++i) {
synctex_node_p N = proxy->class->scanner->lists_of_friends[i];
do {
if (N==proxy) {
++j;
printf("%s",_synctex_node_abstract(N));
}
} while ((N = _synctex_tree_friend(N)));
}
if (j) {
printf("\nnext %i match\n",j);
}
}
#endif
} while (proxy && proxy != halt);
proxy = next_proxy;
}
return SYNCTEX_STATUS_OK;
}
/**
* Replace all the form refs by root box proxies.
* Create the node hierarchy and update the friends.
* On entry, the refs are collected as a friend list
* in either a form or a sheet
* - parameter: the owning scanner
*/
SYNCTEX_INLINE static synctex_status_t _synctex_post_process(synctex_scanner_p scanner) {
synctex_status_t status = SYNCTEX_STATUS_OK;
synctex_ns_s ns = {NULL,SYNCTEX_STATUS_NOT_OK};
#if SYNCTEX_DEBUG>500
printf("! entering _synctex_post_process.\n");
synctex_node_display(scanner->sheet);
synctex_node_display(scanner->form);
#endif
/* replace form refs inside forms by box proxies */
ns = _synctex_post_process_ref(scanner->ref_in_form);
if (ns.status<status) {
status = ns.status;
}
scanner->ref_in_form = NULL;
/* Create all the form proxy nodes on the fly.
* ns.node is the root of the list of
* newly created proxies.
* There might be a problem with cascading proxies.
* In order to be properly managed, the data must
* be organized in the right way.
* The inserted form must be defined before
* the inserting one. */
ns.status = _synctex_post_process_proxy(ns.node,&_synctex_tree_reset_friend);
if (ns.status<status) {
status = ns.status;
}
/* replace form refs inside sheets by box proxies */
ns = _synctex_post_process_ref(scanner->ref_in_sheet);
if (ns.status<status) {
status = ns.status;
}
scanner->ref_in_sheet = NULL;
#if 0
{
int i;
for (i=0;i<scanner->number_of_lists;++i) {
synctex_node_p P = ns.node;
do {
synctex_node_p N = scanner->lists_of_friends[i];
do {
if (P == N) {
printf("Already registered.\n");
synctex_node_display(N);
break;
}
} while ((N = _synctex_tree_friend(N)));
} while((P = _synctex_tree_friend(P)));
}
}
#endif
#if 1
{
int i;
for (i=0;i<scanner->number_of_lists;++i) {
synctex_node_p P = scanner->lists_of_friends[i];
int j = 0;
while (P) {
++j;
synctex_node_log(P);
P = _synctex_tree_friend(P);
}
if (j) {
printf("friends %i -> # %i\n",i,j);
}
}
}
#endif
ns.status = _synctex_post_process_proxy(ns.node,&__synctex_proxy_make_friend_and_next_hbox);
if (ns.status<status) {
status = ns.status;
}
#if SYNCTEX_DEBUG>500
printf("! exiting _synctex_post_process.\n");
synctex_node_display(scanner->sheet);
synctex_node_display(scanner->form);
printf("! display all.\n");
synctex_node_display(scanner->sheet);
synctex_node_display(scanner->form);
#endif
return status;
}
/* Used when parsing the synctex file
*/
static synctex_status_t _synctex_scan_content(synctex_scanner_p scanner) {
scanner->lastv = -1;
synctex_status_t status = 0;
if (NULL == scanner) {
return SYNCTEX_STATUS_BAD_ARGUMENT;
}
/* Find where this section starts */
content_not_found:
status = _synctex_match_string(scanner,"Content:");
if (status<SYNCTEX_STATUS_EOF) {
return status;
}
if (_synctex_next_line(scanner)<SYNCTEX_STATUS_OK) {
_synctex_error("Uncomplete Content.");
return SYNCTEX_STATUS_ERROR;
}
if (status == SYNCTEX_STATUS_NOT_OK) {
goto content_not_found;
}
status = __synctex_parse_sfi(scanner);
if (status == SYNCTEX_STATUS_OK) {
status = _synctex_post_process(scanner);
}
return status;
}
static synctex_status_t _synctex_open(const char * output, const char * build_directory, char ** synctex_name_ref, gzFile * file_ref, synctex_bool_t add_quotes, synctex_io_mode_t * io_modeRef);
synctex_scanner_p synctex_scanner_new() {
synctex_scanner_p scanner =(synctex_scanner_p)_synctex_malloc(sizeof(synctex_scanner_s));
if (scanner) {
# ifdef SYNCTEX_NOTHING
# pragma mark -
# endif
# define DEFINE_synctex_scanner_class(NAME)\
scanner->class[synctex_node_type_##NAME] = synctex_class_##NAME;\
(scanner->class[synctex_node_type_##NAME]).scanner = scanner
DEFINE_synctex_scanner_class(input);
DEFINE_synctex_scanner_class(sheet);
DEFINE_synctex_scanner_class(form);
DEFINE_synctex_scanner_class(hbox);
DEFINE_synctex_scanner_class(void_hbox);
DEFINE_synctex_scanner_class(vbox);
DEFINE_synctex_scanner_class(void_vbox);
DEFINE_synctex_scanner_class(kern);
DEFINE_synctex_scanner_class(glue);
DEFINE_synctex_scanner_class(rule);
DEFINE_synctex_scanner_class(math);
DEFINE_synctex_scanner_class(boundary);
DEFINE_synctex_scanner_class(box_bdry);
DEFINE_synctex_scanner_class(ref);
DEFINE_synctex_scanner_class(hbox_proxy);
DEFINE_synctex_scanner_class(vbox_proxy);
DEFINE_synctex_scanner_class(proxy);
DEFINE_synctex_scanner_class(last_proxy);
DEFINE_synctex_scanner_class(result);
/* set up the lists of friends */
scanner->number_of_lists = 1024;
scanner->lists_of_friends = (synctex_node_r)_synctex_malloc(scanner->number_of_lists*sizeof(synctex_node_p));
if (NULL == scanner->lists_of_friends) {
synctex_scanner_free(scanner);
_synctex_error("malloc:2");
return NULL;
}
scanner->display_switcher = 100;
scanner->display_prompt = (char *)_synctex_display_prompt+strlen(_synctex_display_prompt)-1;
}
return scanner;
}
/* Where the synctex scanner is created. */
synctex_scanner_p synctex_scanner_new_with_output_file(const char * output, const char * build_directory, int parse) {
gzFile file = NULL;
char * synctex = NULL;
synctex_scanner_p scanner = NULL;
synctex_io_mode_t io_mode = 0;
/* We ensure that SYNCTEX_BUFFER_SIZE < UINT_MAX, I don't know if it makes sense... */
if (SYNCTEX_BUFFER_SIZE >= UINT_MAX) {
_synctex_error("Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (1)");
return NULL;
}
/* for integers: */
if (SYNCTEX_BUFFER_SIZE < SYNCTEX_BUFFER_MIN_SIZE) {
_synctex_error("Internal inconsistency, bad SYNCTEX_BUFFER_SIZE (2)");
return NULL;
}
/* now open the synctex file */
if (_synctex_open(output,build_directory,&synctex,&file,synctex_ADD_QUOTES,&io_mode)<SYNCTEX_STATUS_OK || !file) {
if (_synctex_open(output,build_directory,&synctex,&file,synctex_DONT_ADD_QUOTES,&io_mode)<SYNCTEX_STATUS_OK || !file) {
return NULL;
}
}
scanner = synctex_scanner_new();
if (NULL == scanner) {
_synctex_error("malloc problem");
free(synctex);
gzclose(file);
return NULL;
}
/* make a private copy of output for the scanner */
if (NULL == (scanner->output = (char *)malloc(strlen(output)+1))){
_synctex_error("! synctex_scanner_new_with_output_file: Memory problem (2), scanner's output is not reliable.");
} else if (scanner->output != strcpy(scanner->output,output)) {
_synctex_error("! synctex_scanner_new_with_output_file: Copy problem, scanner's output is not reliable.");
}
scanner->synctex = synctex;/* Now the scanner owns synctex */
SYNCTEX_FILE = file;
return parse? synctex_scanner_parse(scanner):scanner;
}
/* This functions opens the file at the "output" given location.
* It manages the problem of quoted filenames that appear with pdftex and filenames containing the space character.
* In TeXLive 2008, the synctex file created with pdftex did contain unexpected quotes.
* This function will remove them if possible.
* All the reference arguments will take a value on return. They must be non NULL.
* - returns: 0 on success, non 0 on error. */
static synctex_status_t __synctex_open(const char * output, char ** synctex_name_ref, gzFile * file_ref, synctex_bool_t add_quotes, synctex_io_mode_t * io_mode_ref) {
if (synctex_name_ref && file_ref && io_mode_ref) {
/* 1 local variable that uses dynamic memory */
char * synctex_name = NULL;
gzFile the_file = NULL;
char * quoteless_synctex_name = NULL;
size_t size = 0;
synctex_io_mode_t io_mode = *io_mode_ref;
const char * mode = _synctex_get_io_mode_name(io_mode);
/* now create the synctex file name */
size = strlen(output)+strlen(synctex_suffix)+strlen(synctex_suffix_gz)+1;
synctex_name = (char *)malloc(size);
if (NULL == synctex_name) {
_synctex_error("! __synctex_open: Memory problem (1)\n");
return SYNCTEX_STATUS_ERROR;
}
/* we have reserved for synctex enough memory to copy output (including its 2 eventual quotes), both suffices,
* including the terminating character. size is free now. */
if (synctex_name != strcpy(synctex_name,output)) {
_synctex_error("! __synctex_open: Copy problem\n");
return_on_error:
free(synctex_name);
free(quoteless_synctex_name);/* We MUST have quoteless_synctex_name<>synctex_name */
return SYNCTEX_STATUS_ERROR;
}
/* remove the last path extension if any */
_synctex_strip_last_path_extension(synctex_name);
if (!strlen(synctex_name)) {
goto return_on_error;
}
/* now insert quotes. */
if (add_quotes) {
char * quoted = NULL;
if (_synctex_copy_with_quoting_last_path_component(synctex_name,"ed,size) || quoted == NULL) {
/* There was an error or quoting does not make sense: */
goto return_on_error;
}
}
/* Now add to synctex_name the first path extension. */
if (synctex_name != strcat(synctex_name,synctex_suffix)){
_synctex_error("! __synctex_open: Concatenation problem (can't add suffix '%s')\n",synctex_suffix);
goto return_on_error;
}
/* Add to quoteless_synctex_name as well, if relevant. */
if (quoteless_synctex_name && (quoteless_synctex_name != strcat(quoteless_synctex_name,synctex_suffix))){
free(quoteless_synctex_name);
quoteless_synctex_name = NULL;
}
if (NULL == (the_file = gzopen(synctex_name,mode))) {
/* Could not open this file */
if (errno != ENOENT) {
/* The file does exist, this is a lower level error, I can't do anything. */
_synctex_error("could not open %s, error %i\n",synctex_name,errno);
goto return_on_error;
}
/* Apparently, there is no uncompressed synctex file. Try the compressed version */
if (synctex_name != strcat(synctex_name,synctex_suffix_gz)){
_synctex_error("! __synctex_open: Concatenation problem (can't add suffix '%s')\n",synctex_suffix_gz);
goto return_on_error;
}
io_mode |= synctex_io_gz_mask;
mode = _synctex_get_io_mode_name(io_mode); /* the file is a compressed and is a binary file, this caused errors on Windows */
/* Add the suffix to the quoteless_synctex_name as well. */
if (quoteless_synctex_name && (quoteless_synctex_name != strcat(quoteless_synctex_name,synctex_suffix_gz))){
free(quoteless_synctex_name);
quoteless_synctex_name = NULL;
}
if (NULL == (the_file = gzopen(synctex_name,mode))) {
/* Could not open this file */
if (errno != ENOENT) {
/* The file does exist, this is a lower level error, I can't do anything. */
_synctex_error("Could not open %s, error %i\n",synctex_name,errno);
}
goto return_on_error;
}
}
/* At this point, the file is properly open.
* If we are in the add_quotes mode, we change the file name by removing the quotes. */
if (quoteless_synctex_name) {
gzclose(the_file);
if (rename(synctex_name,quoteless_synctex_name)) {
_synctex_error("Could not rename %s to %s, error %i\n",synctex_name,quoteless_synctex_name,errno);
/* We could not rename, reopen the file with the quoted name. */
if (NULL == (the_file = gzopen(synctex_name,mode))) {
/* No luck, could not re open this file, something has happened meanwhile */
if (errno != ENOENT) {
/* The file does not exist any more, it has certainly be removed somehow
* this is a lower level error, I can't do anything. */
_synctex_error("Could not open again %s, error %i\n",synctex_name,errno);
}
goto return_on_error;
}
} else {
/* The file has been successfully renamed */
if (NULL == (the_file = gzopen(quoteless_synctex_name,mode))) {
/* Could not open this file */
if (errno != ENOENT) {
/* The file does exist, this is a lower level error, I can't do anything. */
_synctex_error("Could not open renamed %s, error %i\n",quoteless_synctex_name,errno);
}
goto return_on_error;
}
/* The quote free file name should replace the old one:*/
free(synctex_name);
synctex_name = quoteless_synctex_name;
quoteless_synctex_name = NULL;
}
}
/* The operation is successfull, return the arguments by value. */
* file_ref = the_file;
* io_mode_ref = io_mode;
* synctex_name_ref = synctex_name;
return SYNCTEX_STATUS_OK;
}
return SYNCTEX_STATUS_BAD_ARGUMENT; /* Bad parameter. */
}
/* Opens the ouput file, taking into account the eventual build_directory.
* 0 on success, non 0 on error. */
static synctex_status_t _synctex_open(const char * output, const char * build_directory, char ** synctex_name_ref, gzFile * file_ref, synctex_bool_t add_quotes, synctex_io_mode_t * io_mode_ref) {
# define synctex_name (*synctex_name_ref)
# define the_file (*file_ref)
synctex_status_t result = __synctex_open(output,synctex_name_ref,file_ref,add_quotes,io_mode_ref);
if ((result < SYNCTEX_STATUS_OK || !*file_ref) && build_directory && strlen(build_directory)) {
char * build_output;
const char *lpc;
size_t size;
synctex_bool_t is_absolute;
build_output = NULL;
lpc = _synctex_last_path_component(output);
size = strlen(build_directory)+strlen(lpc)+2; /* One for the '/' and one for the '\0'. */
is_absolute = _synctex_path_is_absolute(build_directory);
if (!is_absolute) {
size += strlen(output);
}
if ((build_output = (char *)malloc(size))) {
if (is_absolute) {
build_output[0] = '\0';
} else {
if (build_output != strcpy(build_output,output)) {
free(build_output);
return -4;
}
build_output[lpc-output]='\0';
}
if (build_output == strcat(build_output,build_directory)) {
/* Append a path separator if necessary. */
if (!SYNCTEX_IS_PATH_SEPARATOR(build_output[strlen(build_directory)-1])) {
if (build_output != strcat(build_output,"/")) {
free(build_output);
return -2;
}
}
/* Append the last path component of the output. */
if (build_output != strcat(build_output,lpc)) {
free(build_output);
return -3;
}
result = __synctex_open(build_output,synctex_name_ref,file_ref,add_quotes,io_mode_ref);
free(build_output);
return result;
}
free(build_output);
}
return -1;
}
return result;
# undef synctex_name
# undef the_file
}
/* The scanner destructor
*/
void synctex_scanner_free(synctex_scanner_p scanner) {
if (NULL == scanner) {
return;
}
if (SYNCTEX_FILE) {
gzclose(SYNCTEX_FILE);
SYNCTEX_FILE = NULL;
}
synctex_node_free(scanner->sheet);
synctex_node_free(scanner->form);
synctex_node_free(scanner->input);
synctex_iterator_free(scanner->iterator);
free(SYNCTEX_START);
free(scanner->output_fmt);
free(scanner->output);
free(scanner->synctex);
free(scanner->lists_of_friends);
free(scanner);
}
/* Where the synctex scanner parses the contents of the file. */
synctex_scanner_p synctex_scanner_parse(synctex_scanner_p scanner) {
synctex_status_t status = 0;
if (!scanner || scanner->flags.has_parsed) {
return scanner;
}
scanner->flags.has_parsed=1;
scanner->pre_magnification = 1000;
scanner->pre_unit = 8192;
scanner->pre_x_offset = scanner->pre_y_offset = 578;
/* initialize the offset with a fake unprobable value,
* If there is a post scriptum section, this value will be overriden by the real life value */
scanner->x_offset = scanner->y_offset = 6.027e23f;
scanner->line_number = 1;
SYNCTEX_START = (char *)malloc(SYNCTEX_BUFFER_SIZE+1); /* one more character for null termination */
if (NULL == SYNCTEX_START) {
_synctex_error("! malloc error in synctex_scanner_parse.");
bailey:
#ifdef SYNCTEX_DEBUG
return scanner;
#else
synctex_scanner_free(scanner);
return NULL;
#endif
}
synctex_scanner_set_display_switcher(scanner, 1000);
SYNCTEX_END = SYNCTEX_START+SYNCTEX_BUFFER_SIZE;
/* SYNCTEX_END always points to a null terminating character.
* Maybe there is another null terminating character between SYNCTEX_CUR and SYNCTEX_END-1.
* At least, we are sure that SYNCTEX_CUR points to a string covering a valid part of the memory. */
*SYNCTEX_END = '\0';
SYNCTEX_CUR = SYNCTEX_END;
# if defined(SYNCTEX_USE_CHARINDEX)
scanner->charindex_offset = -SYNCTEX_BUFFER_SIZE;
# endif
status = _synctex_scan_preamble(scanner);
if (status<SYNCTEX_STATUS_OK) {
_synctex_error("Bad preamble\n");
goto bailey;
}
status = _synctex_scan_content(scanner);
if (status<SYNCTEX_STATUS_OK) {
_synctex_error("Bad content\n");
goto bailey;
}
status = _synctex_scan_postamble(scanner);
if (status<SYNCTEX_STATUS_OK) {
_synctex_error("Bad postamble. Ignored\n");
}
#if SYNCTEX_DEBUG>500
synctex_scanner_set_display_switcher(scanner, 100);
synctex_node_display(scanner->sheet);
synctex_node_display(scanner->form);
#endif
synctex_scanner_set_display_switcher(scanner, 1000);
/* Everything is finished, free the buffer, close the file */
free((void *)SYNCTEX_START);
SYNCTEX_START = SYNCTEX_CUR = SYNCTEX_END = NULL;
gzclose(SYNCTEX_FILE);
SYNCTEX_FILE = NULL;
/* Final tuning: set the default values for various parameters */
/* 1 pre_unit = (scanner->pre_unit)/65536 pt = (scanner->pre_unit)/65781.76 bp
* 1 pt = 65536 sp */
if (scanner->pre_unit<=0) {
scanner->pre_unit = 8192;
}
if (scanner->pre_magnification<=0) {
scanner->pre_magnification = 1000;
}
if (scanner->unit <= 0) {
/* no post magnification */
scanner->unit = scanner->pre_unit / 65781.76;/* 65781.76 or 65536.0*/
} else {
/* post magnification */
scanner->unit *= scanner->pre_unit / 65781.76;
}
scanner->unit *= scanner->pre_magnification / 1000.0;
if (scanner->x_offset > 6e23) {
/* no post offset */
scanner->x_offset = scanner->pre_x_offset * (scanner->pre_unit / 65781.76);
scanner->y_offset = scanner->pre_y_offset * (scanner->pre_unit / 65781.76);
} else {
/* post offset */
scanner->x_offset /= 65781.76f;
scanner->y_offset /= 65781.76f;
}
return scanner;
#undef SYNCTEX_FILE
}
/* Scanner accessors.
*/
int synctex_scanner_pre_x_offset(synctex_scanner_p scanner){
return scanner?scanner->pre_x_offset:0;
}
int synctex_scanner_pre_y_offset(synctex_scanner_p scanner){
return scanner?scanner->pre_y_offset:0;
}
int synctex_scanner_x_offset(synctex_scanner_p scanner){
return scanner?scanner->x_offset:0;
}
int synctex_scanner_y_offset(synctex_scanner_p scanner){
return scanner?scanner->y_offset:0;
}
float synctex_scanner_magnification(synctex_scanner_p scanner){
return scanner?scanner->unit:1;
}
void synctex_scanner_display(synctex_scanner_p scanner) {
if (NULL == scanner) {
return;
}
printf("The scanner:\noutput:%s\noutput_fmt:%s\nversion:%i\n",scanner->output,scanner->output_fmt,scanner->version);
printf("pre_unit:%i\nx_offset:%i\ny_offset:%i\n",scanner->pre_unit,scanner->pre_x_offset,scanner->pre_y_offset);
printf("count:%i\npost_magnification:%f\npost_x_offset:%f\npost_y_offset:%f\n",
scanner->count,scanner->unit,scanner->x_offset,scanner->y_offset);
printf("The input:\n");
synctex_node_display(scanner->input);
if (scanner->count<1000) {
printf("The sheets:\n");
synctex_node_display(scanner->sheet);
printf("The friends:\n");
if (scanner->lists_of_friends) {
int i = scanner->number_of_lists;
synctex_node_p node;
while(i--) {
printf("Friend index:%i\n",i);
node = (scanner->lists_of_friends)[i];
while(node) {
printf("%s:%i,%i\n",
synctex_node_isa(node),
_synctex_data_tag(node),
_synctex_data_line(node)
);
node = _synctex_tree_friend(node);
}
}
}
} else {
printf("SyncTeX Warning: Too many objects\n");
}
}
/* Public */
const char * synctex_scanner_get_name(synctex_scanner_p scanner,int tag) {
synctex_node_p input = NULL;
if (NULL == scanner) {
return NULL;
}
if ((input = scanner->input)) {;
do {
if (tag == _synctex_data_tag(input)) {
return (_synctex_data_name(input));
}
} while((input = __synctex_tree_sibling(input)));
}
return NULL;
}
static int _synctex_scanner_get_tag(synctex_scanner_p scanner,const char * name);
static int _synctex_scanner_get_tag(synctex_scanner_p scanner,const char * name) {
synctex_node_p input = NULL;
if (NULL == scanner) {
return 0;
}
if ((input = scanner->input)) {
do {
if (_synctex_is_equivalent_file_name(name,(_synctex_data_name(input)))) {
return _synctex_data_tag(input);
}
} while((input = __synctex_tree_sibling(input)));
}
// 2011 version
name = _synctex_base_name(name);
if ((input = scanner->input)) {
do {
if (_synctex_is_equivalent_file_name(name,_synctex_base_name(_synctex_data_name(input)))) {
synctex_node_p other_input = input;
while((other_input = __synctex_tree_sibling(other_input))) {
if (_synctex_is_equivalent_file_name(name,_synctex_base_name(_synctex_data_name(other_input)))
&& (strlen(_synctex_data_name(input))!=strlen(_synctex_data_name(other_input))
|| strncmp(_synctex_data_name(other_input),_synctex_data_name(input),strlen(_synctex_data_name(input))))) {
// There is a second possible candidate
return 0;
}
}
return _synctex_data_tag(input);
}
} while((input = __synctex_tree_sibling(input)));
}
return 0;
}
int synctex_scanner_get_tag(synctex_scanner_p scanner,const char * name) {
size_t char_index = strlen(name);
if ((scanner = synctex_scanner_parse(scanner)) && (0 < char_index)) {
/* the name is not void */
char_index -= 1;
if (!SYNCTEX_IS_PATH_SEPARATOR(name[char_index])) {
/* the last character of name is not a path separator */
int result = _synctex_scanner_get_tag(scanner,name);
if (result) {
return result;
} else {
/* the given name was not the one known by TeX
* try a name relative to the enclosing directory of the scanner->output file */
const char * relative = name;
const char * ptr = scanner->output;
while((strlen(relative) > 0) && (strlen(ptr) > 0) && (*relative == *ptr))
{
relative += 1;
ptr += 1;
}
/* Find the last path separator before relative */
while(relative > name) {
if (SYNCTEX_IS_PATH_SEPARATOR(*(relative-1))) {
break;
}
relative -= 1;
}
if ((relative > name) && (result = _synctex_scanner_get_tag(scanner,relative))) {
return result;
}
if (SYNCTEX_IS_PATH_SEPARATOR(name[0])) {
/* No tag found for the given absolute name,
* Try each relative path starting from the shortest one */
while(0<char_index) {
char_index -= 1;
if (SYNCTEX_IS_PATH_SEPARATOR(name[char_index])
&& (result = _synctex_scanner_get_tag(scanner,name+char_index+1))) {
return result;
}
}
}
}
return result;
}
}
return 0;
}
synctex_node_p synctex_scanner_input(synctex_scanner_p scanner) {
return scanner?scanner->input:NULL;
}
synctex_node_p synctex_scanner_input_with_tag(synctex_scanner_p scanner, int tag) {
synctex_node_p input = scanner?scanner->input:NULL;
while (_synctex_data_tag(input)!=tag) {
if ((input = __synctex_tree_sibling(input))) {
continue;
}
break;
}
return input;
}
const char * synctex_scanner_get_output_fmt(synctex_scanner_p scanner) {
return NULL != scanner && scanner->output_fmt?scanner->output_fmt:"";
}
const char * synctex_scanner_get_output(synctex_scanner_p scanner) {
return NULL != scanner && scanner->output?scanner->output:"";
}
const char * synctex_scanner_get_synctex(synctex_scanner_p scanner) {
return NULL != scanner && scanner->synctex?scanner->synctex:"";
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Public node attributes
# endif
# define SYNCTEX_DEFINE_NODE_HVWHD(WHAT) \
int synctex_node_##WHAT(synctex_node_p node) { \
if (node && node->class->inspector->WHAT) { \
return node->class->inspector->WHAT(node); \
} else { \
return 0; \
} \
}
# define SYNCTEX_DEFINE_PROXY_HV(WHAT) \
static int _synctex_proxy_##WHAT(synctex_node_p proxy) { \
synctex_node_p target = _synctex_tree_target(proxy); \
if (target) { \
return _synctex_data_##WHAT(proxy)+synctex_node_##WHAT(target); \
} else if (proxy) { \
return _synctex_data_##WHAT(proxy); \
} else { \
return 0; \
} \
}
#define SYNCTEX_DEFINE_PROXY_TLCWVD(WHAT) \
static int _synctex_proxy_##WHAT(synctex_node_p proxy) { \
synctex_node_p target = _synctex_tree_target(proxy); \
if (target) { \
return synctex_node_##WHAT(target); \
} else { \
return 0; \
} \
}
/**
* The horizontal location of the node.
* Idem for v, width, height and depth.
* - parameter node: a node with geometrical information.
* - returns: an integer.
* - requires: every proxy node has a target.
* - note: recursive call if the parameter is a proxy.
* - author: JL
*/
SYNCTEX_DEFINE_NODE_HVWHD(h)
SYNCTEX_DEFINE_NODE_HVWHD(v)
SYNCTEX_DEFINE_NODE_HVWHD(width)
SYNCTEX_DEFINE_NODE_HVWHD(height)
SYNCTEX_DEFINE_NODE_HVWHD(depth)
SYNCTEX_DEFINE_PROXY_TLCWVD(tag)
SYNCTEX_DEFINE_PROXY_TLCWVD(line)
SYNCTEX_DEFINE_PROXY_TLCWVD(column)
SYNCTEX_DEFINE_PROXY_HV(h)
SYNCTEX_DEFINE_PROXY_HV(v)
SYNCTEX_DEFINE_PROXY_TLCWVD(width)
SYNCTEX_DEFINE_PROXY_TLCWVD(height)
SYNCTEX_DEFINE_PROXY_TLCWVD(depth)
synctex_visible_range_s synctex_node_h_visible_range(synctex_node_p node) {
float h = synctex_node_h(node);
float w = synctex_node_width(node);
if (w<0) {
return (synctex_visible_range_s){h+w,-w};
} else {
return (synctex_visible_range_s){h,w};
}
}
/**
* The horizontal location of the first box enclosing node.
* - parameter node: a node with geometrical information.
* - returns: an integer.
* - author: JL
*/
int synctex_node_box_h(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node) || (node = _synctex_tree_parent(node))) {
return synctex_node_h(node);
}
return 0;
}
/**
* The vertical location of the first box enclosing node.
* - parameter node: a node with geometrical information.
* - returns: an integer.
* - author: JL
*/
int synctex_node_box_v(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node) || (node = _synctex_tree_parent(node))) {
return synctex_node_v(node);
}
return 0;
}
/**
* The width of the first box enclosing node.
* - parameter node: a node with geometrical information.
* - returns: an integer.
* - author: JL
*/
int synctex_node_box_width(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node) || (node = _synctex_tree_parent(node))) {
return synctex_node_width(node);
}
return 0;
}
/**
* The height of the first box enclosing node.
* - parameter node: a node with geometrical information.
* - returns: an integer.
* - author: JL
*/
int synctex_node_box_height(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node) || (node = _synctex_tree_parent(node))) {
return synctex_node_height(node);
}
return 0;
}
/**
* The depth of the first box enclosing node.
* - parameter node: a node with geometrical information.
* - returns: an integer.
* - author: JL
*/
int synctex_node_box_depth(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node) || (node = _synctex_tree_parent(node))) {
return synctex_node_depth(node);
}
return 0;
}
/**
* The horizontal location of an hbox, corrected with contents.
* - parameter node: an hbox node.
* - returns: an integer, 0 if node is not an hbox or an hbox proxy.
* - note: recursive call when node is an hbox proxy.
* - author: JL
*/
int synctex_node_hbox_h(synctex_node_p node) {
switch(SYNCTEX_TYPE(node)) {
case synctex_node_type_hbox:
return _synctex_data_h_V(node);
case synctex_node_type_hbox_proxy:
return _synctex_data_h(node)+synctex_node_hbox_h(_synctex_tree_target(node));
}
return 0;
}
/**
* The vertical location of an hbox, corrected with contents.
* - parameter node: an hbox node.
* - returns: an integer, 0 if node is not an hbox or an hbox proxy.
* - note: recursive call when node is an hbox proxy.
* - author: JL
*/
int synctex_node_hbox_v(synctex_node_p node) {
switch(SYNCTEX_TYPE(node)) {
case synctex_node_type_hbox:
return _synctex_data_v_V(node);
case synctex_node_type_hbox_proxy:
return _synctex_data_v(node)+synctex_node_hbox_v(_synctex_tree_target(node));
}
return 0;
}
/**
* The width of an hbox, corrected with contents.
* - parameter node: an hbox node, 0 if node is not an hbox or an hbox proxy.
* - note: recursive call when node is an hbox proxy.
* - returns: an integer.
* - author: JL
*/
int synctex_node_hbox_width(synctex_node_p node) {
switch(SYNCTEX_TYPE(node)) {
case synctex_node_type_hbox:
return _synctex_data_width_V(node);
case synctex_node_type_hbox_proxy:
return synctex_node_hbox_width(_synctex_tree_target(node));
}
return 0;
}
/**
* The height of an hbox, corrected with contents.
* - parameter node: an hbox node.
* - returns: an integer, 0 if node is not an hbox or an hbox proxy.
* - note: recursive call when node is an hbox proxy.
* - author: JL
*/
int synctex_node_hbox_height(synctex_node_p node) {
switch(SYNCTEX_TYPE(node)) {
case synctex_node_type_hbox:
return _synctex_data_height_V(node);
case synctex_node_type_hbox_proxy:
return synctex_node_hbox_height(_synctex_tree_target(node));
}
return 0;
}
/**
* The depth of an hbox, corrected with contents.
* - parameter node: an hbox node.
* - returns: an integer, 0 if node is not an hbox or an hbox proxy.
* - note: recursive call when node is an hbox proxy.
* - author: JL
*/
int synctex_node_hbox_depth(synctex_node_p node) {
switch(SYNCTEX_TYPE(node)) {
case synctex_node_type_hbox:
return _synctex_data_depth_V(node);
case synctex_node_type_hbox_proxy:
return synctex_node_hbox_depth(_synctex_tree_target(node));
}
return 0;
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Public node visible attributes
# endif
#define SYNCTEX_VISIBLE_SIZE(s) \
(s)*node->class->scanner->unit
#define SYNCTEX_VISIBLE_DISTANCE_h(d) \
((d)*node->class->scanner->unit+node->class->scanner->x_offset)
#define SYNCTEX_VISIBLE_DISTANCE_v(d) \
((d)*node->class->scanner->unit+node->class->scanner->y_offset)
static float __synctex_node_visible_h(synctex_node_p node) {
return SYNCTEX_VISIBLE_DISTANCE_h(synctex_node_h(node));
}
static float __synctex_node_visible_v(synctex_node_p node) {
return SYNCTEX_VISIBLE_DISTANCE_v(synctex_node_v(node));
}
static float __synctex_node_visible_width(synctex_node_p node) {
return SYNCTEX_VISIBLE_SIZE(synctex_node_width(node));
}
static float __synctex_node_visible_height(synctex_node_p node) {
return SYNCTEX_VISIBLE_SIZE(synctex_node_height(node));
}
static float __synctex_node_visible_depth(synctex_node_p node) {
return SYNCTEX_VISIBLE_SIZE(synctex_node_depth(node));
}
static float __synctex_proxy_visible_h(synctex_node_p node) {
return SYNCTEX_VISIBLE_DISTANCE_h(synctex_node_h(node));
}
static float __synctex_proxy_visible_v(synctex_node_p node) {
return SYNCTEX_VISIBLE_DISTANCE_v(synctex_node_v(node));
}
static float __synctex_proxy_visible_width(synctex_node_p node) {
synctex_node_p target = _synctex_tree_target(node);
return __synctex_node_visible_width(target);
}
static float __synctex_proxy_visible_height(synctex_node_p node) {
synctex_node_p target = _synctex_tree_target(node);
return __synctex_node_visible_height(target);
}
static float __synctex_proxy_visible_depth(synctex_node_p node) {
synctex_node_p target = _synctex_tree_target(node);
return __synctex_node_visible_depth(target);
}
static float __synctex_kern_visible_h(synctex_node_p node) {
int h = _synctex_data_h(node);
int width = _synctex_data_width(node);
return SYNCTEX_VISIBLE_DISTANCE_h(width>0?h-width:h);
}
static float __synctex_kern_visible_width(synctex_node_p node) {
int width = _synctex_data_width(node);
return SYNCTEX_VISIBLE_SIZE(width>0?width:-width);
}
static float __synctex_rule_visible_h(synctex_node_p node) {
int h = _synctex_data_h(node);
int width = _synctex_data_width(node);
return SYNCTEX_VISIBLE_DISTANCE_h(width>0?h:h-width);
}
static float __synctex_rule_visible_width(synctex_node_p node) {
int width = _synctex_data_width(node);
return SYNCTEX_VISIBLE_SIZE(width>0?width:-width);
}
static float __synctex_rule_visible_v(synctex_node_p node) {
return __synctex_node_visible_v(node);
}
static float __synctex_rule_visible_height(synctex_node_p node) {
return __synctex_node_visible_height(node);
}
static float __synctex_rule_visible_depth(synctex_node_p node) {
return __synctex_node_visible_depth(node);
}
/**
* The horizontal location of node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_visible_h(synctex_node_p node){
return node? node->class->vispector->h(node): 0;
}
/**
* The vertical location of node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_visible_v(synctex_node_p node){
return node? node->class->vispector->v(node): 0;
}
/**
* The width of node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_visible_width(synctex_node_p node){
return node? node->class->vispector->width(node): 0;
}
/**
* The height of node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_visible_height(synctex_node_p node){
return node? node->class->vispector->height(node): 0;
}
/**
* The depth of node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_visible_depth(synctex_node_p node){
return node? node->class->vispector->depth(node): 0;
}
/**
* The V variant of geometrical information.
* - parameter node: a node.
* - returns: an integer.
* - author: JL
*/
#define SYNCTEX_DEFINE_V(WHAT)\
SYNCTEX_INLINE static int _synctex_node_##WHAT##_V(synctex_node_p node) { \
synctex_node_p target = _synctex_tree_target(node); \
if (target) { \
return _synctex_data_##WHAT(node)+_synctex_node_##WHAT##_V(target); \
} else if (_synctex_data_has_##WHAT##_V(node)) { \
return _synctex_data_##WHAT##_V(node); \
} else { \
return _synctex_data_##WHAT(node); \
} \
}
SYNCTEX_DEFINE_V(h)
SYNCTEX_DEFINE_V(v)
SYNCTEX_DEFINE_V(width)
SYNCTEX_DEFINE_V(height)
SYNCTEX_DEFINE_V(depth)
SYNCTEX_INLINE static synctex_point_s _synctex_data_point(synctex_node_p node) {
return (synctex_point_s){synctex_node_h(node),synctex_node_v(node)};
}
SYNCTEX_INLINE static synctex_point_s _synctex_data_point_V(synctex_node_p node) {
return (synctex_point_s){_synctex_node_h_V(node),_synctex_node_v_V(node)};
}
SYNCTEX_INLINE static synctex_point_s _synctex_data_set_point(synctex_node_p node, synctex_point_s point) {
synctex_point_s old = _synctex_data_point(node);
_synctex_data_set_h(node,point.h);
_synctex_data_set_v(node,point.v);
return old;
}
SYNCTEX_INLINE static synctex_box_s _synctex_data_box(synctex_node_p node) {
synctex_box_s box = {0,0,0,0};
int n;
n = synctex_node_width(node);
if (n<0) {
box.max.h = synctex_node_h(node);
box.min.h = box.max.h + n;
} else {
box.min.h = synctex_node_h(node);
box.max.h = box.min.h + n;
}
n = synctex_node_v(node);
box.min.v = n - synctex_node_height(node);
box.max.v = n + synctex_node_depth(node);
return box;
}
SYNCTEX_INLINE static synctex_box_s _synctex_data_xob(synctex_node_p node) {
synctex_box_s box = {0,0,0,0};
int n;
n = synctex_node_width(node);
if (n>0) {
box.max.h = synctex_node_h(node);
box.min.h = box.max.h - n;
} else {
box.min.h = synctex_node_h(node);
box.max.h = box.min.h - n;
}
n = synctex_node_v(node);
box.min.v = n - synctex_node_height(node);
box.max.v = n + synctex_node_depth(node);
return box;
}
SYNCTEX_INLINE static synctex_box_s _synctex_data_box_V(synctex_node_p node) {
synctex_box_s box = {0,0,0,0};
int n;
n = _synctex_node_width_V(node);
if (n<0) {
box.max.h = _synctex_node_h_V(node);
box.min.h = box.max.h + n;
} else {
box.min.h = _synctex_node_h_V(node);
box.max.h = box.min.h + n;
}
n = _synctex_node_v_V(node);
box.min.v = n - _synctex_node_height_V(node);
box.max.v = n + _synctex_node_depth_V(node);
return box;
}
/**
* The horizontal location of the first box enclosing node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_box_visible_h(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node)) {
return SYNCTEX_VISIBLE_DISTANCE_h(_synctex_node_h_V(node));
} else if (SYNCTEX_IS_BOX(node = _synctex_tree_parent(node))) {
return SYNCTEX_VISIBLE_DISTANCE_h(_synctex_node_h_V(node));
}
return 0;
}
/**
* The vertical location of the first box enclosing node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_box_visible_v(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node) || SYNCTEX_IS_BOX(node = _synctex_tree_parent(node))) {
return SYNCTEX_VISIBLE_DISTANCE_v(_synctex_node_v_V(node));
}
return 0;
}
/**
* The width of the first box enclosing node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_box_visible_width(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node) || SYNCTEX_IS_BOX(node = _synctex_tree_parent(node))) {
return SYNCTEX_VISIBLE_SIZE(_synctex_node_width_V(node));
}
return 0;
}
/**
* The height of the first box enclosing node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_box_visible_height(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node) || SYNCTEX_IS_BOX(node = _synctex_tree_parent(node))) {
return SYNCTEX_VISIBLE_SIZE(_synctex_node_height_V(node));
}
return 0;
}
/**
* The depth of the first box enclosing node, in page coordinates.
* - parameter node: a node.
* - returns: a float.
* - author: JL
*/
float synctex_node_box_visible_depth(synctex_node_p node) {
if (SYNCTEX_IS_BOX(node) || SYNCTEX_IS_BOX(node = _synctex_tree_parent(node))) {
return SYNCTEX_VISIBLE_SIZE(_synctex_node_depth_V(node));
}
return 0;
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Other public node attributes
# endif
/**
* The page number of the sheet enclosing node.
* - parameter node: a node.
* - returns: the page number or -1 if node does not belong to a sheet tree.
* - author: JL
*/
int synctex_node_page(synctex_node_p node){
if (node) {
synctex_node_p parent = _synctex_tree_parent(node);
while(parent) {
node = parent;
parent = _synctex_tree_parent(node);
}
if (SYNCTEX_TYPE(node) == synctex_node_type_sheet) {
return _synctex_data_page(node);
}
}
return -1;
}
/**
* The page number of the target of the result node.
* - parameter node: a node.
* - returns: the page number or -1 if target's node does not belong to a sheet tree.
* - author: JL
*/
SYNCTEX_INLINE static int _synctex_result_page(synctex_node_p node){
return synctex_node_page(_synctex_tree_target(node));
}
#if defined (SYNCTEX_USE_CHARINDEX)
synctex_charindex_t synctex_node_charindex(synctex_node_p node) {
return node?SYNCTEX_CHARINDEX(node):0;
}
#endif
/**
* The tag of the node.
* - parameter node: a node.
* - returns: the tag or -1 if node is NULL.
* - author: JL
*/
int synctex_node_tag(synctex_node_p node) {
return node? node->class->tlcpector->tag(node): -1;
}
/**
* The line of the node.
* - parameter node: a node.
* - returns: the line or -1 if node is NULL.
* - author: JL
*/
int synctex_node_line(synctex_node_p node) {
return node? node->class->tlcpector->line(node): -1;
}
/**
* The column of the node.
* - parameter node: a node.
* - returns: the column or -1 if node is NULL.
* - author: JL
*/
int synctex_node_column(synctex_node_p node) {
return node? node->class->tlcpector->column(node): -1;
}
/**
* The mean line number of the node.
* - parameter node: a node.
* - returns: the line or -1 if node is NULL.
* - note: recursive call for proxies.
* - author: JL
*/
int synctex_node_mean_line(synctex_node_p node) {
if (_synctex_tree_target(node)) {
return synctex_node_mean_line(_synctex_tree_target(node));
}
return node?(SYNCTEX_TYPE(node)==synctex_node_type_hbox?_synctex_data_mean_line(node):_synctex_data_line(node)):-1;
}
/**
* The weight of the node.
* - parameter node: a node.
* - returns: the weight or -1 if node is NULL.
* - note: recursive call for proxies.
* - author: JL
*/
int synctex_node_weight(synctex_node_p node) {
if (_synctex_tree_target(node)) {
return synctex_node_weight(_synctex_tree_target(node));
}
return node?(SYNCTEX_TYPE(node)==synctex_node_type_hbox?_synctex_data_weight(node):0):-1;
}
/**
* The number of children of the node.
* - parameter node: a node.
* - returns: the count or -1 if node is NULL.
* - note: recursive call for proxies.
* - author: JL
*/
int synctex_node_child_count(synctex_node_p node) {
if (_synctex_tree_target(node)) {
return synctex_node_child_count(_synctex_tree_target(node));
}
return node?(SYNCTEX_TYPE(node)==synctex_node_type_hbox?_synctex_data_weight(node):0):-1;
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Sheet & Form
# endif
/**
* The sheet of the scanner with a given page number.
* - parameter scanner: a scanner.
* - parameter page: a 1 based page number.
* - returns: a sheet or NULL.
* - author: JL
*/
synctex_node_p synctex_sheet(synctex_scanner_p scanner,int page) {
if (scanner) {
synctex_node_p sheet = scanner->sheet;
while(sheet) {
if (page == _synctex_data_page(sheet)) {
return sheet;
}
sheet = __synctex_tree_sibling(sheet);
}
}
return NULL;
}
/**
* The form of the scanner with a given tag.
* - parameter scanner: a scanner.
* - parameter tag: an integer identifier.
* - returns: a form.
* - note: use this to create a form instead of _synctex_new_form.
* - author: JL
*/
synctex_node_p synctex_form(synctex_scanner_p scanner,int tag) {
if (scanner) {
synctex_node_p form = scanner->form;
while(form) {
if (tag == _synctex_data_tag(form)) {
return form;
}
form = __synctex_tree_sibling(form);
}
}
return NULL;
}
/**
* The content of the sheet with given page number.
* - parameter scanner: a scanner.
* - parameter page: a 1 based page number.
* - returns: a (vertical) box node.
* - author: JL
*/
synctex_node_p synctex_sheet_content(synctex_scanner_p scanner,int page) {
if (scanner) {
return _synctex_tree_child(synctex_sheet(scanner,page));
}
return NULL;
}
/**
* The content of the sheet with given page number.
* - parameter scanner: a scanner.
* - parameter tag: an integer identifier.
* - returns: a box node.
* - author: JL
*/
synctex_node_p synctex_form_content(synctex_scanner_p scanner,int tag) {
if (scanner) {
return _synctex_tree_child(synctex_form(scanner,tag));
}
return NULL;
}
SYNCTEX_INLINE static synctex_node_p _synctex_scanner_friend(synctex_scanner_p scanner,int i) {
if (i>=0) {
i = _synctex_abs(i)%(scanner->number_of_lists);
return (scanner->lists_of_friends)[i];
}
return NULL;
}
SYNCTEX_INLINE static synctex_node_p _synctex_vertically_sorted(synctex_node_p sibling) {
synctex_node_p child = NULL;
synctex_node_p best_child = sibling;
synctex_node_p next_child = _synctex_tree_reset_child(best_child);
synctex_node_p target = _synctex_tree_target(best_child);
synctex_node_p best_parent = _synctex_tree_parent(target);
synctex_node_p parent = NULL;
unsigned int best_weight = _synctex_data_weight(best_parent);
unsigned int weight;
int best_match = abs(_synctex_data_line(target)-_synctex_data_mean_line(best_parent));
int match;
synctex_node_type_t best_type = synctex_node_type(target);
synctex_node_type_t type;
/* Navigate through the other children */
while ((child = next_child)) {
next_child = _synctex_tree_reset_child(child);
target = _synctex_tree_target(child);
parent = _synctex_tree_parent(target);
match = abs(_synctex_data_line(target)-_synctex_data_mean_line(parent));
weight = _synctex_data_weight(parent);
type = synctex_node_type(target);
if (match<best_match
|| (match==best_match && weight>=best_weight)) {
if (best_type>type) {
_synctex_tree_set_child(child,best_child);
best_child = child;
best_parent = parent;
best_match = match;
best_weight = weight;
best_type = type;
} else {
_synctex_tree_set_child(child,_synctex_tree_set_child(best_child,child));
}
} else {
synctex_node_free(child);
}
}
return best_child;
}
SYNCTEX_INLINE static synctex_bool_t _synctex_point_in_box_v2(synctex_point_p hitP, synctex_node_p node);
/* This struct records distances, the left one is non negative and the right one is non positive.
* When comparing the locations of 2 different graphical objects on the page, we will have to also record the
* horizontal distance as signed to keep track of the typesetting order.*/
typedef struct {
synctex_node_p node;
int distance;
} synctex_nd_s;
#define SYNCTEX_ND_0 (synctex_nd_s){NULL,INT_MAX}
typedef synctex_nd_s * synctex_nd_p;
typedef struct {
synctex_nd_s l;
synctex_nd_s r;
} synctex_nd_lr_s;
/* The best container is the deeper box that contains the hit point (H,V).
* _synctex_eq_deepest_container_v2 starts with node whereas
* _synctex_box_child_deepest starts with node's children, if any
* if node is not a box, or a void box, NULL is returned.
* We traverse the node tree in a deep first manner and stop as soon as a result is found. */
static synctex_node_p _synctex_eq_deepest_container_v2(synctex_point_p hitP, synctex_node_p node);
SYNCTEX_INLINE static synctex_nd_lr_s _synctex_eq_get_closest_children_in_box_v2(synctex_point_p hitP, synctex_node_p node);
/* Closest child, recursive. */
static synctex_nd_s __synctex_closest_deep_child_v2(synctex_point_p hitP, synctex_node_p node);
/* The smallest container between two has the smallest width or height.
* This comparison is used when there are 2 overlapping boxes that contain the hit point.
* For ConTeXt, the problem appears at each page.
* The chosen box is the one with the smallest height, then the smallest width. */
SYNCTEX_INLINE static synctex_node_p _synctex_smallest_container_v2(synctex_node_p node, synctex_node_p other_node);
/* Returns the distance between the hit point hit point=(H,V) and the given node. */
static int _synctex_point_node_distance_v2(synctex_point_p hitP, synctex_node_p node);
/* The closest container is the box that is the one closest to the given point.
* The "visible" version takes into account the visible dimensions instead of the real ones given by TeX. */
static synctex_nd_s _synctex_eq_closest_child_v2(synctex_point_p hitP, synctex_node_p node);
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Queries
# endif
typedef struct synctex_iterator_t {
synctex_node_p result;
synctex_node_p next;
int count0;
int count;
} synctex_iterator_s;
SYNCTEX_INLINE static synctex_iterator_p _synctex_iterator_new(synctex_node_p result, int count) {
synctex_iterator_p iterator;
if ((iterator = _synctex_malloc(sizeof(synctex_iterator_s)))) {
iterator->result = iterator->next = result;
iterator->count0 = iterator->count = count;
}
return iterator;
};
void synctex_iterator_free(synctex_iterator_p iterator) {
_synctex_free(iterator);
}
synctex_bool_t synctex_iterator_has_next(synctex_iterator_p iterator) {
return iterator->count>0;
}
int synctex_iterator_count(synctex_iterator_p iterator) {
return iterator? iterator->count: 0;
}
synctex_node_p synctex_iterator_next(synctex_iterator_p iterator) {
if (iterator && iterator->count>0) {
synctex_node_p N = iterator->next;
iterator->next = __synctex_tree_sibling(N);
--iterator->count;
return _synctex_tree_target(N);
}
return NULL;
}
int synctex_iterator_reset(synctex_iterator_p iterator) {
if (iterator) {
iterator->next = iterator->result;
return iterator->count = iterator->count0;
}
return 0;
}
synctex_iterator_p synctex_iterator_new_edit(synctex_scanner_p scanner,int page,float h,float v){
if (scanner) {
synctex_node_p sheet = NULL;
synctex_point_s hit;
synctex_node_p node = NULL;
synctex_nd_lr_s nds = {{NULL,0},{NULL,0}};
if (NULL == (scanner = synctex_scanner_parse(scanner)) || 0 >= scanner->unit) {/* scanner->unit must be >0 */
return NULL;
}
/* Find the proper sheet */
sheet = synctex_sheet(scanner,page);
if (NULL == sheet) {
return NULL;
}
/* Now sheet points to the sheet node with proper page number. */
/* Now that scanner has been initialized, we can convert
* the given point to scanner integer coordinates */
hit = (synctex_point_s)
{(h-scanner->x_offset)/scanner->unit,
(v-scanner->y_offset)/scanner->unit};
/* At first, we browse all the horizontal boxes of the sheet
* until we find one containing the hit point. */
if ((node = _synctex_tree_next_hbox(sheet))) {
do {
if (_synctex_point_in_box_v2(&hit,node)) {
/* Maybe the hit point belongs to a contained vertical box.
* This is the most likely situation.
*/
synctex_node_p next = node;
#if defined(SYNCTEX_DEBUG)
printf("--- We are lucky\n");
#endif
/* This trick is for catching overlapping boxes */
while ((next = _synctex_tree_next_hbox(next))) {
if (_synctex_point_in_box_v2(&hit,next)) {
node = _synctex_smallest_container_v2(next,node);
}
}
/* node is the smallest horizontal box that contains hit,
* unless there is no hbox at all.
*/
node = _synctex_eq_deepest_container_v2(&hit, node);
nds = _synctex_eq_get_closest_children_in_box_v2(&hit, node);
end:
if (nds.r.node && nds.l.node) {
if ((_synctex_data_tag(nds.r.node)!=_synctex_data_tag(nds.l.node))
|| (_synctex_data_line(nds.r.node)!=_synctex_data_line(nds.l.node))
|| (_synctex_data_column(nds.r.node)!=_synctex_data_column(nds.l.node))) {
if (nds.l.distance>nds.r.distance) {
node = nds.r.node;
nds.r.node = nds.l.node;
nds.l.node = node;
}
if((node = _synctex_new_result(scanner))) {
synctex_node_p other_result;
_synctex_tree_setup_target(node,nds.l.node);
if((other_result = _synctex_new_result(scanner))) {
_synctex_tree_setup_target(other_result,nds.r.node);
_synctex_tree_set_sibling(node,other_result);
return _synctex_iterator_new(node,2);
}
return _synctex_iterator_new(node,1);
}
return NULL;
}
/* both nodes have the same input coordinates
* We choose the one closest to the hit point */
if (nds.l.distance>nds.r.distance) {
nds.l.node = nds.r.node;
}
nds.r.node = NULL;
} else if (nds.r.node) {
nds.l = nds.r;
} else if (!nds.l.node) {
nds.l.node = node;
}
if((node = _synctex_new_result(scanner))) {
_synctex_tree_setup_target(node,nds.l.node);
return _synctex_iterator_new(node,1);
}
return 0;
}
} while ((node = _synctex_tree_next_hbox(node)));
/* All the horizontal boxes have been tested,
* None of them contains the hit point.
*/
}
/* We are not lucky,
* we test absolutely all the node
* to find the closest... */
if ((node = _synctex_tree_child(sheet))) {
#if defined(SYNCTEX_DEBUG)
printf("--- We are not lucky\n");
#endif
nds.l = __synctex_closest_deep_child_v2(&hit, node);
#if defined(SYNCTEX_DEBUG)
printf("Edit query best: %i\n", nds.l.distance);
#endif
goto end;
}
}
return NULL;
}
SYNCTEX_INLINE static synctex_node_p _synctex_new_result_with_target(synctex_node_p target) {
if (target) {
synctex_node_p result = _synctex_new_result(target->class->scanner);
if (result) {
_synctex_tree_set_target(result,target);
return result;
}
}
return NULL;
}
/**
* Loop the candidate friendly list to find the ones with the proper
* tag and line.
* Returns a tree of results targeting the found candidates.
* At the top level each sibling has its own page number.
* All the results with the same page number are linked by child/parent entry.
* - parameter candidate: a friendly list of candidates
*/
static synctex_node_p _synctex_display_query(synctex_node_p target, int tag, int line, synctex_node_type_t type) {
synctex_node_p first_result = NULL;
/* Search the first match */
if (target == NULL) {
return first_result;
}
do {
int page;
if ((synctex_node_type_none != type
&& synctex_node_type(target)!=type)
|| (tag != synctex_node_tag(target))
|| (line != synctex_node_line(target))) {
continue;
}
/* We found a first match, create a result targeting that candidate */
first_result = _synctex_new_result_with_target(target);
if (first_result == NULL) {
return first_result;
}
page = synctex_node_page(target);
/* Now create all the other results */
while ((target = _synctex_tree_friend(target))) {
synctex_node_p result = NULL;
if ((synctex_node_type_none != type
&& synctex_node_type(target)!=type)
|| (tag != synctex_node_tag(target))
|| (line != synctex_node_line(target))) {
continue;
}
/* Another match, same page number ? */
result = _synctex_new_result_with_target(target);
if (NULL == result ) {
return first_result;
}
/* is it the same page number ? */
if (synctex_node_page(target) == page) {
__synctex_tree_set_child(result, first_result);
first_result = result;
} else {
/* We have 2 page numbers involved */
__synctex_tree_set_sibling(first_result, result);
while ((target = _synctex_tree_friend(target))) {
synctex_node_p same_page;
if ((synctex_node_type_none != type
&& synctex_node_type(target)!=type)
|| (tag != synctex_node_tag(target))
|| (line != synctex_node_line(target))) {
continue;
}
/* New match found, which page? */
result = _synctex_new_result_with_target(target);
if (NULL == result) {
return first_result;
}
same_page = first_result;
page = synctex_node_page(target);
/* Find a result with the same page number */;
do {
if (_synctex_result_page(same_page) == page) {
_synctex_tree_set_child(result,_synctex_tree_set_child(same_page,result));
} else if ((same_page = __synctex_tree_sibling(same_page))) {
continue;
} else {
/* This is a new page number */
__synctex_tree_set_sibling(result,first_result);
first_result = result;
}
break;
} while (synctex_YES);
}
return first_result;
}
}
} while ((target = _synctex_tree_friend(target)));
return first_result;
}
synctex_iterator_p synctex_iterator_new_display(synctex_scanner_p scanner,const char * name,int line,int column, int page_hint) {
# ifdef __DARWIN_UNIX03
# pragma unused(column)
# endif
if (scanner) {
int tag = synctex_scanner_get_tag(scanner,name);/* parse if necessary */
int max_line = 0;
int line_offset = 1;
int try_count = 100;
synctex_node_p node = NULL;
synctex_node_p result = NULL;
if (tag == 0) {
printf("SyncTeX Warning: No tag for %s\n",name);
return NULL;
}
node = synctex_scanner_input_with_tag(scanner, tag);
max_line = _synctex_data_line(node);
/* node = NULL; */
if (line>max_line) {
line = max_line;
}
while(try_count--) {
if (line<=max_line) {
/* This loop will only be performed once for advanced viewers */
synctex_node_p friend = _synctex_scanner_friend(scanner,tag+line);
if ((node = friend)) {
result = _synctex_display_query(node,tag,line,synctex_node_type_boundary);
if (!result) {
/* We did not find any matching boundary, retry with kern */
node = friend;/* no need to test it again, already done */
result = _synctex_display_query(node,tag,line,synctex_node_type_kern);
if (!result) {
/* We did not find any boundary or kern, retry with glue */
node = friend;/* no need to test it again, already done */
result = _synctex_display_query(node,tag,line,synctex_node_type_glue);
if (!result) {
/* We did not find any boundary, kern or glue, retry with everything */
node = friend;/* no need to test it again, already done */
result = _synctex_display_query(node,tag,line,synctex_node_type_none);
}
}
}
/* Now reverse the order to have nodes in display order, and then keep just a few nodes.
* Order first the best node. */
/* The result is a tree. At the root level, all nodes
* correspond to different page numbers.
* Each node has a child which corresponds to the same
* page number if relevant.
* Then reorder the nodes to put first the one which fits best.
* The idea is to walk along the list of nodes and pick up the first one
* which line info is exactly the mean line of its parent, or at least very close.
* Then we choose among all such node the one with the maximum weight.
* Then we switch with the first node.
*/
if (result) {
/* navigate through siblings,
then children */
int count = 1;
synctex_node_p next_sibling = __synctex_tree_reset_sibling(result);
int best_match = abs(page_hint-_synctex_result_page(result));
synctex_node_p sibling;
int match;
result = _synctex_vertically_sorted(result);
while((sibling = next_sibling)) {
/* What is next? Do not miss that step! */
next_sibling = __synctex_tree_reset_sibling(sibling);
sibling = _synctex_vertically_sorted(sibling);
match = abs(page_hint-_synctex_result_page(sibling));
if (match<best_match) {
/* Order this node first */
__synctex_tree_set_sibling(sibling,result);
result = sibling;
} else /*if (match>best_match)*/ {
__synctex_tree_set_sibling(sibling,__synctex_tree_sibling(result));
__synctex_tree_set_sibling(result,sibling);
}
++count;
}
/* Now order first the result closest to the page hint */
return _synctex_iterator_new(result,count);
}
}
# if defined(__SYNCTEX_STRONG_DISPLAY_QUERY__)
break;
# else
line += line_offset;
line_offset=line_offset<0?-(line_offset-1):-(line_offset+1);
if (line <= 0) {
line += line_offset;
line_offset=line_offset<0?-(line_offset-1):-(line_offset+1);
}
# endif
}
}
}
return NULL;
}
synctex_status_t synctex_display_query(synctex_scanner_p scanner,const char * name,int line,int column, int page_hint) {
if (scanner) {
synctex_iterator_free(scanner->iterator);
scanner->iterator = synctex_iterator_new_display(scanner, name,line,column, page_hint);
return synctex_iterator_count(scanner->iterator);
}
return SYNCTEX_STATUS_ERROR;
}
synctex_status_t synctex_edit_query(synctex_scanner_p scanner,int page,float h,float v) {
if (scanner) {
synctex_iterator_free(scanner->iterator);
scanner->iterator = synctex_iterator_new_edit(scanner, page, h, v);
return synctex_iterator_count(scanner->iterator);
}
return SYNCTEX_STATUS_ERROR;
}
synctex_node_p synctex_next_result(synctex_scanner_p scanner) {
return scanner? synctex_iterator_next(scanner->iterator): NULL;
}
synctex_status_t synctex_reset_result(synctex_scanner_p scanner) {
return scanner? synctex_iterator_reset(scanner->iterator): SYNCTEX_STATUS_ERROR;
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Geometric utilities
# endif
/** Rougly speaking, this is:
* node's h coordinate - hit point's h coordinate.
* If node is to the right of the hit point, then this distance is positive,
* if node is to the left of the hit point, this distance is negative.
* If the argument is a pdf form reference, then the child is used and returned instead.
* Last Revision: Mon Apr 24 07:05:27 UTC 2017
*/
static synctex_nd_s _synctex_point_h_ordered_distance_v2
(synctex_point_p hit, synctex_node_p node) {
synctex_nd_s nd = {node,INT_MAX};
if (node) {
int min,med,max,width;
switch(SYNCTEX_TYPE(node)) {
/* The distance between a point and a box is special.
* It is not the euclidian distance, nor something similar.
* We have to take into account the particular layout,
* and the box hierarchy.
* Given a box, there are 9 regions delimited by the lines of the edges of the box.
* The origin being at the top left corner of the page,
* we also give names to the vertices of the box.
*
* 1 | 2 | 3
* ---A---B--->
* 4 | 5 | 6
* ---C---D--->
* 7 | 8 | 9
* v v
*/
case synctex_node_type_vbox:
case synctex_node_type_void_vbox:
case synctex_node_type_void_hbox:
/* getting the box bounds, taking into account negative width, height and depth. */
width = _synctex_data_width(node);
min = _synctex_data_h(node);
max = min + (width>0?width:-width);
/* We allways have min <= max */
if (hit->h<min) {
nd.distance = min - hit->h; /* regions 1+4+7, result is > 0 */
} else if (hit->h>max) {
nd.distance = max - hit->h; /* regions 3+6+9, result is < 0 */
} else {
nd.distance = 0; /* regions 2+5+8, inside the box, except for vertical coordinates */
}
break;
case synctex_node_type_vbox_proxy:
/* getting the box bounds, taking into account negative width, height and depth. */
width = synctex_node_width(node);
min = synctex_node_h(node);
max = min + (width>0?width:-width);
/* We allways have min <= max */
if (hit->h<min) {
nd.distance = min - hit->h; /* regions 1+4+7, result is > 0 */
} else if (hit->h>max) {
nd.distance = max - hit->h; /* regions 3+6+9, result is < 0 */
} else {
nd.distance = 0; /* regions 2+5+8, inside the box, except for vertical coordinates */
}
break;
case synctex_node_type_hbox:
case synctex_node_type_hbox_proxy:
/* getting the box bounds, taking into account negative width, height and depth. */
width = synctex_node_hbox_width(node);
min = synctex_node_hbox_h(node);
max = min + (width>0?width:-width);
/* We allways have min <= max */
if (hit->h<min) {
nd.distance = min - hit->h; /* regions 1+4+7, result is > 0 */
} else if (hit->h>max) {
nd.distance = max - hit->h; /* regions 3+6+9, result is < 0 */
} else {
nd.distance = 0; /* regions 2+5+8, inside the box, except for vertical coordinates */
}
break;
case synctex_node_type_kern:
/* IMPORTANT NOTICE: the location of the kern is recorded AFTER the move.
* The distance to the kern is very special,
* in general, there is no text material in the kern,
* this is why we compute the offset relative to the closest edge of the kern.*/
max = _synctex_data_width(node);
if (max<0) {
min = _synctex_data_h(node);
max = min - max;
} else {
min = -max;
max = _synctex_data_h(node);
min += max;
}
med = (min+max)/2;
/* positive kern: '.' means text, '>' means kern offset
* .............
* min>>>>med>>>>max
* ...............
* negative kern: '.' means text, '<' means kern offset
* ............................
* min<<<<med<<<<max
* .................................
* Actually, we do not take into account negative widths.
* There is a problem for such situation when there is effectively overlapping text.
* But this should be extremely rare. I guess that in that case, many different choices
* could be made, one being in contradiction with the other.
* It means that the best choice should be made according to the situation that occurs
* most frequently.
*/
if (hit->h<min) {
nd.distance = min - hit->h + 1; /* penalty to ensure other nodes are chosen first in case of overlapping ones */
} else if (hit->h>max) {
nd.distance = max - hit->h - 1; /* same kind of penalty */
} else if (hit->h>med) {
/* do things like if the node had 0 width and was placed at the max edge + 1*/
nd.distance = max - hit->h + 1; /* positive, the kern is to the right of the hit point */
} else {
nd.distance = min - hit->h - 1; /* negative, the kern is to the left of the hit point */
}
break;
case synctex_node_type_glue:
case synctex_node_type_math:
case synctex_node_type_boundary:
case synctex_node_type_box_bdry:
nd.distance = _synctex_data_h(node) - hit->h;
break;
case synctex_node_type_ref:
nd.node = synctex_node_child(node);
nd = _synctex_point_h_ordered_distance_v2(hit,nd.node);
break;
case synctex_node_type_proxy:
{
/* shift the hit point to be relative to the proxy origin,
* then compute the distance to the target
*/
synctex_point_s otherHit = *hit;
otherHit.h -= _synctex_data_h(node);
otherHit.v -= _synctex_data_v(node);
nd.node = _synctex_tree_target(node);
nd = _synctex_point_h_ordered_distance_v2(&otherHit,nd.node);
nd.node = node;
}
}
}
return nd;
}
/** Rougly speaking, this is:
* node's v coordinate - hit point's v coordinate.
* If node is at the top of the hit point, then this distance is positive,
* if node is at the bottom of the hit point, this distance is negative.
*/
static synctex_nd_s _synctex_point_v_ordered_distance_v2
(synctex_point_p hit, synctex_node_p node) {
synctex_nd_s nd = {node, INT_MAX};
int min,max,depth,height;
switch(SYNCTEX_TYPE(node)) {
/* The distance between a point and a box is special.
* It is not the euclidian distance, nor something similar.
* We have to take into account the particular layout,
* and the box hierarchy.
* Given a box, there are 9 regions delimited by the lines of the edges of the box.
* The origin being at the top left corner of the page,
* we also give names to the vertices of the box.
*
* 1 | 2 | 3
* ---A---B--->
* 4 | 5 | 6
* ---C---D--->
* 7 | 8 | 9
* v v
*/
case synctex_node_type_vbox:
case synctex_node_type_void_vbox:
case synctex_node_type_void_hbox:
/* getting the box bounds, taking into account negative width, height and depth. */
min = synctex_node_v(node);
max = min + _synctex_abs(_synctex_data_depth(node));
min -= _synctex_abs(_synctex_data_height(node));
/* We allways have min <= max */
if (hit->v<min) {
nd.distance = min - hit->v; /* regions 1+2+3, result is > 0 */
} else if (hit->v>max) {
nd.distance = max - hit->v; /* regions 7+8+9, result is < 0 */
} else {
nd.distance = 0; /* regions 4.5.6, inside the box, except for horizontal coordinates */
}
break;
case synctex_node_type_vbox_proxy:
/* getting the box bounds, taking into account negative width, height and depth. */
min = synctex_node_v(node);
max = min + _synctex_abs(synctex_node_depth(node));
min -= _synctex_abs(synctex_node_height(node));
/* We allways have min <= max */
if (hit->v<min) {
nd.distance = min - hit->v; /* regions 1+2+3, result is > 0 */
} else if (hit->v>max) {
nd.distance = max - hit->v; /* regions 7+8+9, result is < 0 */
} else {
nd.distance = 0; /* regions 4.5.6, inside the box, except for horizontal coordinates */
}
break;
case synctex_node_type_hbox:
case synctex_node_type_hbox_proxy:
/* getting the box bounds, taking into account negative height and depth. */
min = synctex_node_hbox_v(node);
depth = synctex_node_hbox_depth(node);
max = min + (depth>0?depth:-depth);
height = synctex_node_hbox_height(node);
min -= (height>0?height:-height);
/* We allways have min <= max */
if (hit->v<min) {
nd.distance = min - hit->v; /* regions 1+2+3, result is > 0 */
} else if (hit->v>max) {
nd.distance = max - hit->v; /* regions 7+8+9, result is < 0 */
} else {
nd.distance = 0; /* regions 4.5.6, inside the box, except for horizontal coordinates */
}
break;
case synctex_node_type_kern:
case synctex_node_type_glue:
case synctex_node_type_math:
min = _synctex_data_v(node);
max = min + _synctex_abs(_synctex_data_depth(_synctex_tree_parent(node)));
min -= _synctex_abs(_synctex_data_height(_synctex_tree_parent(node)));
/* We allways have min <= max */
if (hit->v<min) {
nd.distance = min - hit->v; /* regions 1+2+3, result is > 0 */
} else if (hit->v>max) {
nd.distance = max - hit->v; /* regions 7+8+9, result is < 0 */
} else {
nd.distance = 0; /* regions 4.5.6, inside the box, except for horizontal coordinates */
}
break;
case synctex_node_type_ref:
nd.node = synctex_node_child(node);
nd = _synctex_point_v_ordered_distance_v2(hit,nd.node);
break;
case synctex_node_type_proxy:
{
synctex_point_s otherHit = *hit;
otherHit.h -= _synctex_data_h(node);
otherHit.v -= _synctex_data_v(node);
nd.node = _synctex_tree_target(node);
nd = _synctex_point_v_ordered_distance_v2(&otherHit,nd.node);
nd.node = node;
}
}
return nd;
}
/**
* The smallest is the one with the smallest area.
* The area is width*height where width and height may be big.
* So there is a real risk of overflow.
*/
SYNCTEX_INLINE static synctex_node_p _synctex_smallest_container_v2(synctex_node_p node, synctex_node_p other_node) {
int total_height, other_total_height;
unsigned long area, other_area;
int width = synctex_node_hbox_width(node);
int other_width = synctex_node_hbox_width(other_node);
if (width<0) {
width = -width;
}
if (other_width<0) {
other_width = -other_width;
}
total_height = _synctex_abs(_synctex_data_depth(node)) + _synctex_abs(_synctex_data_height(node));
other_total_height = _synctex_abs(_synctex_data_depth(other_node)) + _synctex_abs(_synctex_data_height(other_node));
area = total_height*width;
other_area = other_total_height*other_width;
if (area<other_area) {
return node;
}
if (area>other_area) {
return other_node;
}
if (_synctex_abs(_synctex_data_width(node))>_synctex_abs(_synctex_data_width(other_node))) {
return node;
}
if (_synctex_abs(_synctex_data_width(node))<_synctex_abs(_synctex_data_width(other_node))) {
return other_node;
}
if (total_height<other_total_height) {
return node;
}
if (total_height>other_total_height) {
return other_node;
}
return node;
}
SYNCTEX_INLINE static synctex_bool_t _synctex_point_in_box_v2(synctex_point_p hit, synctex_node_p node) {
if (node) {
if (0 == _synctex_point_h_ordered_distance_v2(hit,node).distance
&& 0 == _synctex_point_v_ordered_distance_v2(hit,node).distance) {
return synctex_YES;
}
}
return synctex_NO;
}
static int _synctex_distance_to_box_v2(synctex_point_p hit,synctex_box_p box) {
/* The distance between a point and a box is special.
* It is not the euclidian distance, nor something similar.
* We have to take into account the particular layout,
* and the box hierarchy.
* Given a box, there are 9 regions delimited by the lines of the edges of the box.
* The origin being at the top left corner of the page,
* we also give names to the vertices of the box.
*
* 1 | 2 | 3
* ---A---B--->
* 4 | 5 | 6
* ---C---D--->
* 7 | 8 | 9
* v v
* In each region, there is a different formula.
* In the end we have a continuous distance which may not be a mathematical distance but who cares. */
if (hit->v<box->min.v) {
/* Regions 1, 2 or 3 */
if (hit->h<box->min.h) {
/* This is region 1. The distance to the box is the L1 distance PA. */
return box->min.v - hit->v + box->min.h - hit->h;/* Integer overflow? probability epsilon */
} else if (hit->h<=box->max.h) {
/* This is region 2. The distance to the box is the geometrical distance to the top edge. */
return box->min.v - hit->v;
} else {
/* This is region 3. The distance to the box is the L1 distance PB. */
return box->min.v - hit->v + hit->h - box->max.h;
}
} else if (hit->v<=box->max.v) {
/* Regions 4, 5 or 6 */
if (hit->h<box->min.h) {
/* This is region 4. The distance to the box is the geometrical distance to the left edge. */
return box->min.h - hit->h;
} else if (hit->h<=box->max.h) {
/* This is region 5. We are inside the box. */
return 0;
} else {
/* This is region 6. The distance to the box is the geometrical distance to the right edge. */
return hit->h - box->max.h;
}
} else {
/* Regions 7, 8 or 9 */
if (hit->h<box->min.h) {
/* This is region 7. The distance to the box is the L1 distance PC. */
return hit->v - box->max.v + box->min.h - hit->h;
} else if (hit->h<=box->max.h) {
/* This is region 8. The distance to the box is the geometrical distance to the top edge. */
return hit->v - box->max.v;
} else {
/* This is region 9. The distance to the box is the L1 distance PD. */
return hit->v - box->max.v + hit->h - box->max.h;
}
}
}
/**
* The distance from the hit point to the node.
*/
static int _synctex_point_node_distance_v2(synctex_point_p hit, synctex_node_p node) {
int d = INT_MAX;
if (node) {
synctex_box_s box = {{0,0},{0,0}};
int dd = INT_MAX;
switch(SYNCTEX_TYPE(node)) {
case synctex_node_type_vbox:
box.min.h = _synctex_data_h(node);
box.max.h = box.min.h + _synctex_abs(_synctex_data_width(node));
box.min.v = synctex_node_v(node);
box.max.v = box.min.v + _synctex_abs(_synctex_data_depth(node));
box.min.v -= _synctex_abs(_synctex_data_height(node));
return _synctex_distance_to_box_v2(hit,&box);
case synctex_node_type_vbox_proxy:
box.min.h = synctex_node_h(node);
box.max.h = box.min.h + _synctex_abs(synctex_node_width(node));
box.min.v = synctex_node_v(node);
box.max.v = box.min.v + _synctex_abs(synctex_node_depth(node));
box.min.v -= _synctex_abs(synctex_node_height(node));
return _synctex_distance_to_box_v2(hit,&box);
case synctex_node_type_hbox:
case synctex_node_type_hbox_proxy:
box.min.h = synctex_node_hbox_h(node);
box.max.h = box.min.h + _synctex_abs(synctex_node_hbox_width(node));
box.min.v = synctex_node_hbox_v(node);
box.max.v = box.min.v + _synctex_abs(synctex_node_hbox_depth(node));
box.min.v -= _synctex_abs(synctex_node_hbox_height(node));
return _synctex_distance_to_box_v2(hit,&box);
case synctex_node_type_void_vbox:
case synctex_node_type_void_hbox:
/* best of distances from the left edge and right edge*/
box.min.h = _synctex_data_h(node);
box.max.h = box.min.h;
box.min.v = _synctex_data_v(node);
box.max.v = box.min.v + _synctex_abs(_synctex_data_depth(node));
box.min.v -= _synctex_abs(_synctex_data_height(node));
d = _synctex_distance_to_box_v2(hit,&box);
box.min.h = box.min.h + _synctex_abs(_synctex_data_width(node));
box.max.h = box.min.h;
dd = _synctex_distance_to_box_v2(hit,&box);
return d<dd ? d:dd;
case synctex_node_type_kern:
box.min.h = _synctex_data_h(node);
box.max.h = box.min.h;
box.max.v = _synctex_data_v(node);
box.min.v = box.max.v - _synctex_abs(_synctex_data_height(_synctex_tree_parent(node)));
d = _synctex_distance_to_box_v2(hit,&box);
box.min.h -= _synctex_data_width(node);
box.max.h = box.min.h;
dd = _synctex_distance_to_box_v2(hit,&box);
return d<dd ? d:dd;
case synctex_node_type_glue:
case synctex_node_type_math:
case synctex_node_type_boundary:
case synctex_node_type_box_bdry:
box.min.h = _synctex_data_h(node);
box.max.h = box.min.h;
box.max.v = _synctex_data_v(node);
box.min.v = box.max.v - _synctex_abs(_synctex_data_height(_synctex_tree_parent(node)));
return _synctex_distance_to_box_v2(hit,&box);
case synctex_node_type_proxy:
{
synctex_point_s otherHit = *hit;
otherHit.h -= _synctex_data_h(node);
otherHit.v -= _synctex_data_v(node);
return _synctex_point_node_distance_v2(&otherHit, _synctex_tree_target(node));
}
}
}
return d;
}
static synctex_node_p _synctex_eq_deepest_container_v2(synctex_point_p hit, synctex_node_p node) {
if (node) {
/**/
synctex_node_p child;
if ((child = synctex_node_child(node))) {
/* Non void hbox or vbox, form ref or proxy */
/* We go deep first because some boxes have 0 dimensions
* despite they do contain some black material.
*/
do {
if ((_synctex_point_in_box_v2(hit,child))) {
synctex_node_p deep = _synctex_eq_deepest_container_v2(hit,child);
if (deep) {
/* One of the children contains the hit. */
return deep;
}
}
} while((child = synctex_node_sibling(child)));
/* is the hit point inside the box? */
if (SYNCTEX_TYPE(node) == synctex_node_type_vbox
|| SYNCTEX_TYPE(node) == synctex_node_type_vbox_proxy) {
/* For vboxes we try to use some node inside.
* Walk through the list of siblings until we find the closest one.
* Only consider siblings with children inside. */
if ((child = _synctex_tree_child(node))) {
synctex_nd_s best = SYNCTEX_ND_0;
do {
if (_synctex_tree_child(child)) {
int d = _synctex_point_node_distance_v2(hit,child);
if (d <= best.distance) {
best = (synctex_nd_s){child, d};
}
}
} while((child = __synctex_tree_sibling(child)));
if (best.node) {
return best.node;
}
}
}
if (_synctex_point_in_box_v2(hit,node)) {
return node;
}
}
}
return NULL;
}
static synctex_nd_s _synctex_eq_deepest_container_v3(synctex_point_p hit, synctex_node_p node) {
if (node) {
synctex_node_p child = NULL;
if ((child = synctex_node_child(node))) {
/* Non void hbox, vbox, box proxy or form ref */
/* We go deep first because some boxes have 0 dimensions
* despite they do contain some black material.
*/
do {
synctex_nd_s deep = _synctex_eq_deepest_container_v3(hit, child);
if (deep.node) {
/* One of the children contains the hit-> */
return deep;
}
} while((child = synctex_node_sibling(child)));
/* For vboxes we try to use some node inside.
* Walk through the list of siblings until we find the closest one.
* Only consider siblings with children inside. */
if (SYNCTEX_TYPE(node) == synctex_node_type_vbox
|| SYNCTEX_TYPE(node) == synctex_node_type_vbox_proxy) {
if ((child = synctex_node_child(node))) {
synctex_nd_s best = SYNCTEX_ND_0;
do {
if (synctex_node_child(child)) {
int d = _synctex_point_node_distance_v2(hit,child);
if (d < best.distance) {
best = (synctex_nd_s){child,d};
}
}
} while((child = synctex_node_sibling(child)));
if (best.node) {
return best;
}
}
}
/* is the hit point inside the box? */
if (_synctex_point_in_box_v2(hit,node)) {
return (synctex_nd_s){node, 0};
}
}
}
return SYNCTEX_ND_0;
}
/* Compares the locations of the hit point with the locations of
* the various nodes contained in the box.
* As it is an horizontal box, we only compare horizontal coordinates.
*/
SYNCTEX_INLINE static synctex_nd_lr_s __synctex_eq_get_closest_children_in_hbox_v2(synctex_point_p hitP, synctex_node_p node) {
synctex_nd_s childd = SYNCTEX_ND_0;
synctex_nd_lr_s nds = {SYNCTEX_ND_0,SYNCTEX_ND_0};
if ((childd.node = synctex_node_child(node))) {
synctex_nd_s nd = SYNCTEX_ND_0;
do {
childd = _synctex_point_h_ordered_distance_v2(hitP,childd.node);
if (childd.distance > 0) {
/* node is to the right of the hit point.
* We compare node and the previously recorded one, through the recorded distance.
* If the nodes have the same tag, prefer the one with the smallest line number,
* if the nodes also have the same line number, prefer the one with the smallest column. */
if (nds.r.distance > childd.distance) {
nds.r = childd;
} else if (nds.r.distance == childd.distance && nds.r.node) {
if (_synctex_data_tag(nds.r.node) == _synctex_data_tag(childd.node)
&& (_synctex_data_line(nds.r.node) > _synctex_data_line(childd.node)
|| (_synctex_data_line(nds.r.node) == _synctex_data_line(childd.node)
&& _synctex_data_column(nds.r.node) > _synctex_data_column(childd.node)))) {
nds.r = childd;
}
}
} else if (childd.distance == 0) {
/* hit point is inside node. */
return _synctex_eq_get_closest_children_in_box_v2(hitP, childd.node);
} else { /* here childd.distance < 0, the hit point is to the right of node */
childd.distance = -childd.distance;
if (nds.l.distance > childd.distance) {
nds.l = childd;
} else if (nds.l.distance == childd.distance && nds.l.node) {
if (_synctex_data_tag(nds.l.node) == _synctex_data_tag(childd.node)
&& (_synctex_data_line(nds.l.node) > _synctex_data_line(childd.node)
|| (_synctex_data_line(nds.l.node) == _synctex_data_line(childd.node)
&& _synctex_data_column(nds.l.node) > _synctex_data_column(childd.node)))) {
nds.l = childd;
}
}
}
} while((childd.node = synctex_node_sibling(childd.node)));
if (nds.l.node) {
/* the left node is new, try to narrow the result */
if ((nd = _synctex_eq_deepest_container_v3(hitP,nds.l.node)).node) {
nds.l = nd;
}
if((nd = __synctex_closest_deep_child_v2(hitP,nds.l.node)).node) {
nds.l.node = nd.node;
}
}
if (nds.r.node) {
/* the right node is new, try to narrow the result */
if ((nd = _synctex_eq_deepest_container_v3(hitP,nds.r.node)).node) {
nds.r = nd;
}
if((nd = __synctex_closest_deep_child_v2(hitP,nds.r.node)).node) {
nds.r.node = nd.node;
}
}
}
return nds;
}
#if 0
SYNCTEX_INLINE static synctex_nd_lr_s __synctex_eq_get_closest_children_in_hbox_v3(synctex_point_p hitP, synctex_node_p nodeP) {
synctex_nd_s nd = SYNCTEX_ND_0;
synctex_nd_lr_s nds = {SYNCTEX_ND_0,SYNCTEX_ND_0};
if ((nd.node = _synctex_tree_child(nodeP))) {
do {
nd = _synctex_point_h_ordered_distance_v2(hitP,nd.node);
if (nd.distance > 0) {
/* node is to the right of the hit point.
* We compare node and the previously recorded one, through the recorded distance.
* If the nodes have the same tag, prefer the one with the smallest line number,
* if the nodes also have the same line number, prefer the one with the smallest column. */
if (nds.r.distance > nd.distance) {
nds.r = nd;
} else if (nds.r.distance == nd.distance && nds.r.node) {
if (_synctex_data_tag(nds.r.node) == _synctex_data_tag(nd.node)
&& (_synctex_data_line(nds.r.node) > _synctex_data_line(nd.node)
|| (_synctex_data_line(nds.r.node) == _synctex_data_line(nd.node)
&& _synctex_data_column(nds.r.node) > _synctex_data_column(nd.node)))) {
nds.r = nd;
}
}
} else if (nd.distance == 0) {
/* hit point is inside node. */
nds.l = nd;
} else { /* here nd.d < 0, the hit point is to the right of node */
nd.distance = -nd.distance;
if (nds.l.distance > nd.distance) {
nds.l = nd;
} else if (nds.l.distance == nd.distance && nds.l.node) {
if (_synctex_data_tag(nds.l.node) == _synctex_data_tag(nd.node)
&& (_synctex_data_line(nds.l.node) > _synctex_data_line(nd.node)
|| (_synctex_data_line(nds.l.node) == _synctex_data_line(nd.node)
&& _synctex_data_column(nds.l.node) > _synctex_data_column(nd.node)))) {
nds.l = nd;
}
}
}
} while((nd.node = __synctex_tree_sibling(nd.node)));
if (nds.l.node) {
/* the left node is new, try to narrow the result */
if ((nd.node = _synctex_eq_deepest_container_v2(hitP,nds.l.node))) {
nds.l.node = nd.node;
}
if((nd = _synctex_eq_closest_child_v2(hitP,nds.l.node)).node) {
nds.l.node = nd.node;
}
}
if (nds.r.node) {
/* the right node is new, try to narrow the result */
if ((nd.node = _synctex_eq_deepest_container_v2(hitP,nds.r.node))) {
nds.r.node = nd.node;
}
if((nd = _synctex_eq_closest_child_v2(hitP,nds.r.node)).node) {
nds.r.node = nd.node;
}
}
}
return nds;
}
#endif
SYNCTEX_INLINE static synctex_nd_lr_s __synctex_eq_get_closest_children_in_vbox_v2(synctex_point_p hitP, synctex_node_p nodeP) {
synctex_nd_lr_s nds = {SYNCTEX_ND_0,SYNCTEX_ND_0};
synctex_nd_s nd = SYNCTEX_ND_0;
if ((nd.node = synctex_node_child(nd.node))) {
do {
nd = _synctex_point_v_ordered_distance_v2(hitP,nd.node);
/* this is what makes the difference with the h version above */
if (nd.distance > 0) {
/* node is to the top of the hit point (below because TeX is oriented from top to bottom.
* We compare node and the previously recorded one, through the recorded distance.
* If the nodes have the same tag, prefer the one with the smallest line number,
* if the nodes also have the same line number, prefer the one with the smallest column. */
if (nds.r.distance > nd.distance) {
nds.r = nd;
} else if (nds.r.distance == nd.distance && nds.r.node) {
if (_synctex_data_tag(nds.r.node) == _synctex_data_tag(nd.node)
&& (_synctex_data_line(nds.r.node) > _synctex_data_line(nd.node)
|| (_synctex_data_line(nds.r.node) == _synctex_data_line(nd.node)
&& _synctex_data_column(nds.r.node) > _synctex_data_column(nd.node)))) {
nds.r = nd;
}
}
} else if (nd.distance == 0) {
nds.l = nd;
} else { /* here nd < 0 */
nd.distance = -nd.distance;
if (nds.l.distance > nd.distance) {
nds.l = nd;
} else if (nds.l.distance == nd.distance && nds.l.node) {
if (_synctex_data_tag(nds.l.node) == _synctex_data_tag(nd.node)
&& (_synctex_data_line(nds.l.node) > _synctex_data_line(nd.node)
|| (_synctex_data_line(nds.l.node) == _synctex_data_line(nd.node)
&& _synctex_data_column(nds.l.node) > _synctex_data_column(nd.node)))) {
nds.l = nd;
}
}
}
} while((nd.node = synctex_node_sibling(nd.node)));
if (nds.l.node) {
if ((nd.node = _synctex_eq_deepest_container_v2(hitP,nds.l.node))) {
nds.l.node = nd.node;
}
if((nd = _synctex_eq_closest_child_v2(hitP,nds.l.node)).node) {
nds.l.node = nd.node;
}
}
if (nds.r.node) {
if ((nd.node = _synctex_eq_deepest_container_v2(hitP,nds.r.node))) {
nds.r.node = nd.node;
}
if((nd = _synctex_eq_closest_child_v2(hitP,nds.r.node)).node) {
nds.r.node = nd.node;
}
}
}
return nds;
}
/**
* Get the child closest to the hit point.
* - parameter: hit point
* - parameter: containing node
* - returns: the child and the distance to the hit point.
* SYNCTEX_ND_0 if the parameter node has no children.
* - note: recursive call.
*/
static synctex_nd_s __synctex_closest_deep_child_v2(synctex_point_p hitP, synctex_node_p node) {
synctex_nd_s best = SYNCTEX_ND_0;
synctex_node_p child = NULL;
if ((child = synctex_node_child(node))) {
#if defined(SYNCTEX_DEBUG)
printf("Closest deep child on box at line %i\n",
SYNCTEX_LINEINDEX(node));
#endif
do {
#if SYNCTEX_DEBUG>500
synctex_node_display(child);
#endif
synctex_nd_s nd = SYNCTEX_ND_0;
if (SYNCTEX_IS_BOX(child)) {
nd = __synctex_closest_deep_child_v2(hitP,child);
} else {
nd = (synctex_nd_s) {child, _synctex_point_node_distance_v2(hitP,child)};
}
if (nd.distance < best.distance ||(nd.distance == best.distance
&& SYNCTEX_TYPE(nd.node) != synctex_node_type_kern)) {
#if defined(SYNCTEX_DEBUG)
if(nd.node) {
printf("New best %i<=%i line %i\n",nd.distance,
best.distance,SYNCTEX_LINEINDEX(nd.node));
}
#endif
best = nd;
}
} while((child = synctex_node_sibling(child)));
#if defined(SYNCTEX_DEBUG)
if(best.node) {
printf("Found new best %i line %i\n",best.distance,SYNCTEX_LINEINDEX(best.node));
}
#endif
}
return best;
}
/**
* Return the closest child.
* - parameter: a pointer to the hit point,
* - parameter: the container
* - return: SYNCTEX_ND_0 if node has no child,
* the __synctex_closest_deep_child_v2 otherwise.
*/
static synctex_nd_s _synctex_eq_closest_child_v2(synctex_point_p hitP, synctex_node_p node) {
synctex_nd_s nd = SYNCTEX_ND_0;
if (SYNCTEX_IS_BOX(node)) {
nd = __synctex_closest_deep_child_v2(hitP, node);
if (SYNCTEX_IS_BOX(nd.node)) {
synctex_node_p child = NULL;
if ((child = synctex_node_child(nd.node))) {
synctex_nd_s best = {child,_synctex_point_node_distance_v2(hitP,child)};
while((child = synctex_node_sibling(child))) {
int d = _synctex_point_node_distance_v2(hitP,child);
if (d < best.distance) {
best = (synctex_nd_s){child,d};
} else if (d == best.distance && SYNCTEX_TYPE(child) != synctex_node_type_kern) {
best.node = child;
}
}
return best;
}
}
return nd;
}
return SYNCTEX_ND_0;
}
#define SYNCTEX_IS_NON_VOID_HBOX(NODE)\
(((SYNCTEX_NODE_MASK(NODE)&synctex_mask_non_void_hbox)==synctex_mask_non_void_hbox))
#define SYNCTEX_IS_NON_VOID_VBOX(NODE)\
(((SYNCTEX_NODE_MASK(NODE)&synctex_mask_non_void_vbox)==synctex_mask_non_void_vbox))
SYNCTEX_INLINE static synctex_nd_lr_s _synctex_eq_get_closest_children_in_box_v2(synctex_point_p hitP, synctex_node_p node) {
synctex_nd_lr_s nds = {SYNCTEX_ND_0,SYNCTEX_ND_0};
if(SYNCTEX_IS_NON_VOID_HBOX(node)) {
return __synctex_eq_get_closest_children_in_hbox_v2(hitP,node);
} else if(SYNCTEX_IS_NON_VOID_VBOX(node)) {
return __synctex_eq_get_closest_children_in_vbox_v2(hitP,node);
}
return nds;
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Updater
# endif
typedef int (*synctex_fprintf_t)(void *, const char * , ...); /* print formatted to either FILE * or gzFile */
# define SYNCTEX_BITS_PER_BYTE 8
struct synctex_updater_t {
gzFile file; /* the foo.synctex or foo.synctex.gz I/O identifier */
synctex_fprintf_t fprintf; /* either fprintf or gzprintf */
int length; /* the number of chars appended */
struct _flags {
unsigned int no_gz:1; /* Whether zlib is used or not */
unsigned int reserved:SYNCTEX_BITS_PER_BYTE*sizeof(int)-1; /* Align */
} flags;
};
# define SYNCTEX_FILE updater->file
# define SYNCTEX_NO_GZ ((updater->flags).no_gz)
# define SYNCTEX_fprintf (*(updater->fprintf))
synctex_updater_p synctex_updater_new_with_output_file(const char * output, const char * build_directory) {
synctex_updater_p updater = NULL;
char * synctex = NULL;
synctex_io_mode_t io_mode = 0;
const char * mode = NULL;
/* prepare the updater, the memory is the only one dynamically allocated */
updater = (synctex_updater_p)_synctex_malloc(sizeof(synctex_updater_s));
if (NULL == updater) {
_synctex_error("! synctex_updater_new_with_file: malloc problem");
return NULL;
}
if (_synctex_open(output,build_directory,&synctex,&SYNCTEX_FILE,synctex_ADD_QUOTES,&io_mode)
&& _synctex_open(output,build_directory,&synctex,&SYNCTEX_FILE,synctex_DONT_ADD_QUOTES,&io_mode)) {
return_on_error:
free(updater);
updater = NULL;
return NULL;
}
/* OK, the file exists, we close it and reopen it with the correct mode.
* The receiver is now the owner of the "synctex" variable. */
gzclose(SYNCTEX_FILE);
SYNCTEX_FILE = NULL;
SYNCTEX_NO_GZ = (io_mode&synctex_io_gz_mask)?synctex_NO:synctex_YES;
mode = _synctex_get_io_mode_name(io_mode|synctex_io_append_mask);/* either "a" or "ab", depending on the file extension */
if (SYNCTEX_NO_GZ) {
if (NULL == (SYNCTEX_FILE = (void *)fopen(synctex,mode))) {
no_write_error:
_synctex_error("! synctex_updater_new_with_file: Can't append to %s",synctex);
free(synctex);
goto return_on_error;
}
updater->fprintf = (synctex_fprintf_t)(&fprintf);
} else {
if (NULL == (SYNCTEX_FILE = (void *)gzopen(synctex,mode))) {
goto no_write_error;
}
updater->fprintf = (synctex_fprintf_t)(&gzprintf);
}
printf("SyncTeX: updating %s...",synctex);
free(synctex);
return updater;
}
void synctex_updater_append_magnification(synctex_updater_p updater, char * magnification){
if (NULL==updater) {
return;
}
if (magnification && strlen(magnification)) {
updater->length += SYNCTEX_fprintf(SYNCTEX_FILE,"Magnification:%s\n",magnification);
}
}
void synctex_updater_append_x_offset(synctex_updater_p updater, char * x_offset){
if (NULL==updater) {
return;
}
if (x_offset && strlen(x_offset)) {
updater->length += SYNCTEX_fprintf(SYNCTEX_FILE,"X Offset:%s\n",x_offset);
}
}
void synctex_updater_append_y_offset(synctex_updater_p updater, char * y_offset){
if (NULL==updater) {
return;
}
if (y_offset && strlen(y_offset)) {
updater->length += SYNCTEX_fprintf(SYNCTEX_FILE,"Y Offset:%s\n",y_offset);
}
}
void synctex_updater_free(synctex_updater_p updater){
if (NULL==updater) {
return;
}
if (updater->length>0) {
SYNCTEX_fprintf(SYNCTEX_FILE,"!%i\n",updater->length);
}
if (SYNCTEX_NO_GZ) {
fclose((FILE *)SYNCTEX_FILE);
} else {
gzclose((gzFile)SYNCTEX_FILE);
}
free(updater);
printf("... done.\n");
return;
}
# ifdef SYNCTEX_NOTHING
# pragma mark -
# pragma mark Testers
# endif
#if defined(SYNCTEX_TESTING)
int synctex_test_setup_scanner_sheets_421(synctex_scanner_p scanner) {
synctex_node_p sheet = synctex_node_new(scanner,synctex_node_type_sheet);
_synctex_data_set_page(sheet,4);
SYNCTEX_TEST_BODY(_synctex_data_page(sheet)==4,"");
synctex_node_free(scanner->sheet);
scanner->sheet = sheet;
sheet = synctex_node_new(scanner,synctex_node_type_sheet);
_synctex_data_set_page(sheet,2);
SYNCTEX_TEST_BODY(_synctex_data_page(sheet)==2,"");
__synctex_tree_set_sibling(sheet, scanner->sheet);
scanner->sheet = sheet;
sheet = synctex_node_new(scanner,synctex_node_type_sheet);
_synctex_data_set_page(sheet,1);
SYNCTEX_TEST_BODY(_synctex_data_page(sheet)==1,"");
__synctex_tree_set_sibling(sheet, scanner->sheet);
scanner->sheet = sheet;
return 1;
}
int synctex_test_input(synctex_scanner_p scanner) {
synctex_node_p input = synctex_node_new(scanner,synctex_node_type_input);
_synctex_data_set_tag(input,421);
SYNCTEX_TEST_BODY(_synctex_data_tag(input)==421,"");
_synctex_data_set_tag(input,124);
SYNCTEX_TEST_BODY(_synctex_data_tag(input)==124,"");
_synctex_data_set_line(input,421);
SYNCTEX_TEST_BODY(_synctex_data_line(input)==421,"");
_synctex_data_set_line(input,214);
SYNCTEX_TEST_BODY(_synctex_data_line(input)==214,"");
_synctex_data_set_line(input,214);
SYNCTEX_TEST_BODY(_synctex_data_line(input)==214,"");
_synctex_data_set_name(input,"214");
SYNCTEX_TEST_BODY(0==memcmp(_synctex_data_name(input),"214",4),"");
_synctex_data_set_name(input,"421421");
SYNCTEX_TEST_BODY(0==memcmp(_synctex_data_name(input),"421421",4),"");
return 1;
}
int synctex_test_proxy(synctex_scanner_p scanner) {
synctex_node_p proxy = synctex_node_new(scanner,synctex_node_type_proxy);
synctex_node_p target = synctex_node_new(scanner,synctex_node_type_rule);
_synctex_tree_set_target(proxy,target);
_synctex_data_set_tag(target,421);
SYNCTEX_TEST_BODY(_synctex_data_tag(target)==421,"");
SYNCTEX_TEST_BODY(synctex_node_tag(target)==421,"");
SYNCTEX_TEST_BODY(synctex_node_tag(proxy)==421,"");
return 1;
}
int synctex_test_result(synctex_scanner_p scanner) {
synctex_node_p result = synctex_node_new(scanner,synctex_node_type_result);
synctex_node_p proxy = synctex_node_new(scanner, synctex_node_type_proxy);
synctex_node_p target = synctex_node_new(scanner,synctex_node_type_rule);
_synctex_tree_set_target(result,target);
_synctex_data_set_tag(target,421);
SYNCTEX_TEST_BODY(_synctex_data_tag(target)==421,"");
SYNCTEX_TEST_BODY(synctex_node_tag(target)==421,"");
SYNCTEX_TEST_BODY(synctex_node_tag(result)==421,"");
_synctex_data_set_line(target,214);
SYNCTEX_TEST_BODY(_synctex_data_line(target)==214,"");
SYNCTEX_TEST_BODY(synctex_node_line(target)==214,"");
SYNCTEX_TEST_BODY(synctex_node_line(result)==214,"");
_synctex_data_set_column(target,142);
SYNCTEX_TEST_BODY(_synctex_data_column(target)==142,"");
SYNCTEX_TEST_BODY(synctex_node_column(target)==142,"");
SYNCTEX_TEST_BODY(synctex_node_column(result)==142,"");
_synctex_tree_set_target(proxy,target);
_synctex_tree_set_target(result,proxy);
_synctex_data_set_tag(target,412);
SYNCTEX_TEST_BODY(_synctex_data_tag(target)==412,"");
SYNCTEX_TEST_BODY(synctex_node_tag(target)==412,"");
SYNCTEX_TEST_BODY(synctex_node_tag(result)==412,"");
_synctex_data_set_line(target,124);
SYNCTEX_TEST_BODY(_synctex_data_line(target)==124,"");
SYNCTEX_TEST_BODY(synctex_node_line(target)==124,"");
SYNCTEX_TEST_BODY(synctex_node_line(result)==124,"");
_synctex_data_set_column(target,241);
SYNCTEX_TEST_BODY(_synctex_data_column(target)==241,"");
SYNCTEX_TEST_BODY(synctex_node_column(target)==241,"");
SYNCTEX_TEST_BODY(synctex_node_column(result)==241,"");
return 1;
}
int synctex_test_setup_scanner_input(synctex_scanner_p scanner) {
synctex_node_p input = synctex_node_new(scanner,synctex_node_type_input);
_synctex_data_set_tag(input,4);
_synctex_data_set_name(input,"21");
_synctex_data_set_line(input,421);
synctex_node_free(scanner->input);
scanner->input = input;
SYNCTEX_TEST_BODY(_synctex_data_tag(input)==4,"");
SYNCTEX_TEST_BODY(strcmp(_synctex_data_name(input),"21")==0,"");
SYNCTEX_TEST_BODY(_synctex_data_line(input)==421,"");
return 1;
}
int synctex_test_setup_nodes(synctex_scanner_p scanner, synctex_node_r nodes) {
int n;
for (n=0;n<synctex_node_number_of_types;++n) {
nodes[n] = synctex_node_new(scanner,n);
SYNCTEX_TEST_BODY(nodes[n]!=NULL,"");
}
return 1;
}
int synctex_test_teardown_nodes(synctex_scanner_p scanner, synctex_node_r nodes) {
int n;
for (n=0;n<synctex_node_number_of_types;++n) {
synctex_node_free(nodes[n]);
nodes[n]=NULL;
}
return 1;
}
int synctex_test_tree(synctex_scanner_p scanner) {
synctex_node_p nodes1[synctex_node_number_of_types];
synctex_node_p nodes2[synctex_node_number_of_types];
synctex_node_p nodes3[synctex_node_number_of_types];
int i,j,k;
synctex_node_type_t with_child[synctex_node_number_of_types];
synctex_test_setup_nodes(scanner,nodes1);
synctex_test_setup_nodes(scanner,nodes2);
synctex_test_setup_nodes(scanner,nodes3);
/* Every node has a sibling */
for (i=0;i<synctex_node_number_of_types;++i) {
for (j=0;j<synctex_node_number_of_types;++j) {
_synctex_tree_set_sibling(nodes1[i],nodes2[i]);
SYNCTEX_TEST_BODY(nodes2[i]==synctex_node_sibling(nodes1[i]),"");
}
}
synctex_test_teardown_nodes(scanner,nodes3);
synctex_test_teardown_nodes(scanner,nodes2);
synctex_test_teardown_nodes(scanner,nodes1);
return 1;
}
int synctex_test_page(synctex_scanner_p scanner) {
int count = synctex_test_setup_scanner_sheets_421(scanner);
synctex_node_p sheet = scanner->sheet;
synctex_node_p node = synctex_node_new(scanner,synctex_node_type_rule);
_synctex_data_set_tag(node,4);
_synctex_data_set_line(node,21);
_synctex_node_set_child(sheet,node);
SYNCTEX_TEST_BODY(synctex_node_page(node)==synctex_node_page(sheet),"");
return count;
}
int synctex_test_display_query(synctex_scanner_p scanner) {
int count = synctex_test_setup_scanner_sheets_421(scanner);
synctex_node_p sheet = scanner->sheet;
synctex_node_p node = synctex_node_new(scanner,synctex_node_type_rule);
_synctex_data_set_tag(node,4);
_synctex_data_set_line(node,21);
_synctex_tree_set_child(sheet,node);
SYNCTEX_TEST_BODY(node==synctex_node_child(sheet),"");
__synctex_node_make_friend_tlc(node);
SYNCTEX_TEST_BODY(_synctex_scanner_friend(scanner, 25)==node,"");
sheet = __synctex_tree_sibling(sheet);
node = synctex_node_new(scanner,synctex_node_type_rule);
_synctex_data_set_tag(node,4);
_synctex_data_set_line(node,21);
_synctex_node_set_child(sheet,node);
SYNCTEX_TEST_BODY(node==synctex_node_child(sheet),"");
__synctex_node_make_friend_tlc(node);
SYNCTEX_TEST_BODY(_synctex_scanner_friend(scanner, 25)==node,"");
sheet = __synctex_tree_sibling(sheet);
node = synctex_node_new(scanner,synctex_node_type_rule);
_synctex_data_set_tag(node,4);
_synctex_data_set_line(node,21);
_synctex_tree_set_child(sheet,node);
SYNCTEX_TEST_BODY(node==synctex_node_child(sheet),"");
__synctex_node_make_friend_tlc(node);
SYNCTEX_TEST_BODY((_synctex_scanner_friend(scanner, 25)==node),"");
synctex_test_setup_scanner_input(scanner);
scanner->flags.has_parsed = synctex_YES;
SYNCTEX_TEST_BODY((synctex_display_query(scanner,"21",21,4,-1)==3),"");
return count;
}
#endif
|