1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 11240 11241 11242 11243 11244 11245 11246 11247 11248 11249 11250 11251 11252 11253 11254 11255 11256 11257 11258 11259 11260 11261 11262 11263 11264 11265 11266 11267 11268 11269 11270 11271 11272 11273 11274 11275 11276 11277 11278 11279 11280 11281 11282 11283 11284 11285 11286 11287 11288 11289 11290 11291 11292 11293 11294 11295 11296 11297 11298 11299 11300 11301 11302 11303 11304 11305 11306 11307 11308 11309 11310 11311 11312 11313 11314 11315 11316 11317 11318 11319 11320 11321 11322 11323 11324 11325 11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 11349 11350 11351 11352 11353 11354 11355 11356 11357 11358 11359 11360 11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 11411 11412 11413 11414 11415 11416 11417 11418 11419 11420 11421 11422 11423 11424 11425 11426 11427 11428 11429 11430 11431 11432 11433 11434 11435 11436 11437 11438 11439 11440 11441 11442 11443 11444 11445 11446 11447 11448 11449 11450 11451 11452 11453 11454 11455 11456 11457 11458 11459 11460 11461 11462 11463 11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 11477 11478 11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493 11494 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535 11536 11537 11538 11539 11540 11541 11542 11543 11544 11545 11546 11547 11548 11549 11550 11551 11552 11553 11554 11555 11556 11557 11558 11559 11560 11561 11562 11563 11564 11565 11566 11567 11568 11569 11570 11571 11572 11573 11574 11575 11576 11577 11578 11579 11580 11581 11582 11583 11584 11585 11586 11587 11588 11589 11590 11591 11592 11593 11594 11595 11596 11597 11598 11599 11600 11601 11602 11603 11604 11605 11606 11607 11608 11609 11610 11611 11612 11613 11614 11615 11616 11617 11618 11619 11620 11621 11622 11623 11624 11625 11626 11627 11628 11629 11630 11631 11632 11633 11634 11635 11636 11637 11638 11639 11640 11641 11642 11643 11644 11645 11646 11647 11648 11649 11650 11651 11652 11653 11654 11655 11656 11657 11658 11659 11660 11661 11662 11663 11664 11665 11666 11667 11668 11669 11670 11671 11672 11673 11674 11675 11676 11677 11678 11679 11680 11681 11682 11683 11684 11685 11686 11687 11688 11689 11690 11691 11692 11693 11694 11695 11696 11697 11698 11699 11700 11701 11702 11703 11704 11705 11706 11707 11708 11709 11710 11711 11712 11713 11714 11715 11716 11717 11718 11719 11720 11721 11722 11723 11724 11725 11726 11727 11728 11729 11730 11731 11732 11733 11734 11735 11736 11737 11738 11739 11740 11741 11742 11743 11744 11745 11746 11747 11748 11749 11750 11751 11752 11753 11754 11755 11756 11757 11758 11759 11760 11761 11762 11763 11764 11765 11766 11767 11768 11769 11770 11771 11772 11773 11774 11775 11776 11777 11778 11779 11780 11781 11782 11783 11784 11785 11786 11787 11788 11789 11790 11791 11792 11793 11794 11795 11796 11797 11798 11799 11800 11801 11802 11803 11804 11805 11806 11807 11808 11809 11810 11811 11812 11813 11814 11815 11816 11817 11818 11819 11820 11821 11822 11823 11824 11825 11826 11827 11828 11829 11830 11831 11832 11833 11834 11835 11836 11837 11838 11839 11840 11841 11842 11843 11844 11845 11846 11847 11848 11849 11850 11851 11852 11853 11854 11855 11856 11857 11858 11859 11860 11861 11862 11863 11864 11865 11866 11867 11868 11869 11870 11871 11872 11873 11874 11875 11876 11877 11878 11879 11880 11881 11882 11883 11884 11885 11886 11887 11888 11889 11890 11891 11892 11893 11894 11895 11896 11897 11898 11899 11900 11901 11902 11903 11904 11905 11906 11907 11908 11909 11910 11911 11912 11913 11914 11915 11916 11917 11918 11919 11920 11921 11922 11923 11924 11925 11926 11927 11928 11929 11930 11931 11932 11933 11934 11935 11936 11937 11938 11939 11940 11941 11942 11943 11944 11945 11946 11947 11948 11949 11950 11951 11952 11953 11954 11955 11956 11957 11958 11959 11960 11961 11962 11963 11964 11965 11966 11967 11968 11969 11970 11971 11972 11973 11974 11975 11976 11977 11978 11979 11980 11981 11982 11983 11984 11985 11986 11987 11988 11989 11990 11991 11992 11993 11994 11995 11996 11997 11998 11999 12000 12001 12002 12003 12004 12005 12006 12007 12008 12009 12010 12011 12012 12013 12014 12015 12016 12017 12018 12019 12020 12021 12022 12023 12024 12025 12026 12027 12028 12029 12030 12031 12032 12033 12034 12035 12036 12037 12038 12039 12040 12041 12042 12043 12044 12045 12046 12047 12048 12049 12050 12051 12052 12053 12054 12055 12056 12057 12058 12059 12060 12061 12062 12063 12064 12065 12066 12067 12068 12069 12070 12071 12072 12073 12074 12075 12076 12077 12078 12079 12080 12081 12082 12083 12084 12085 12086 12087 12088 12089 12090 12091 12092 12093 12094 12095 12096 12097 12098 12099 12100 12101 12102 12103 12104 12105 12106 12107 12108 12109 12110 12111 12112 12113 12114 12115 12116 12117 12118 12119 12120 12121 12122 12123 12124 12125 12126 12127 12128 12129 12130 12131 12132 12133 12134 12135 12136 12137 12138 12139 12140 12141 12142 12143 12144 12145 12146 12147 12148 12149 12150 12151 12152 12153 12154 12155 12156 12157 12158 12159 12160 12161 12162 12163 12164 12165 12166 12167 12168 12169 12170 12171 12172 12173 12174 12175 12176 12177 12178 12179 12180 12181 12182 12183 12184 12185 12186 12187 12188 12189 12190 12191 12192 12193 12194 12195 12196 12197 12198 12199 12200 12201 12202 12203 12204 12205 12206 12207 12208 12209 12210 12211 12212 12213 12214 12215 12216 12217 12218 12219 12220 12221 12222 12223 12224 12225 12226 12227 12228 12229 12230 12231 12232 12233 12234 12235 12236 12237 12238 12239 12240 12241 12242 12243 12244 12245 12246 12247 12248 12249 12250 12251 12252 12253 12254 12255 12256 12257 12258 12259 12260 12261 12262 12263 12264 12265 12266 12267 12268 12269 12270 12271 12272 12273 12274 12275 12276 12277 12278 12279 12280 12281 12282 12283 12284 12285 12286 12287 12288 12289 12290 12291 12292 12293 12294 12295 12296 12297 12298 12299 12300 12301 12302 12303 12304 12305 12306 12307 12308 12309 12310 12311 12312 12313 12314 12315 12316 12317 12318 12319 12320 12321 12322 12323 12324 12325 12326 12327 12328 12329 12330 12331 12332 12333 12334 12335 12336 12337 12338 12339 12340 12341 12342 12343 12344 12345 12346 12347 12348 12349 12350 12351 12352 12353 12354 12355 12356 12357 12358 12359 12360 12361 12362 12363 12364 12365 12366 12367 12368 12369 12370 12371 12372 12373 12374 12375 12376 12377 12378 12379 12380 12381 12382 12383 12384 12385 12386 12387 12388 12389 12390 12391 12392 12393 12394 12395 12396 12397 12398 12399 12400 12401 12402 12403 12404 12405 12406 12407 12408 12409 12410 12411 12412 12413 12414 12415 12416 12417 12418 12419 12420 12421 12422 12423 12424 12425 12426 12427 12428 12429 12430 12431 12432 12433 12434 12435 12436 12437 12438 12439 12440 12441 12442 12443 12444 12445 12446 12447 12448 12449 12450 12451 12452 12453 12454 12455 12456 12457 12458 12459 12460 12461 12462 12463 12464 12465 12466 12467 12468 12469 12470 12471 12472 12473 12474 12475 12476 12477 12478 12479 12480 12481 12482 12483 12484 12485 12486 12487 12488 12489 12490 12491 12492 12493 12494 12495 12496 12497 12498 12499 12500 12501 12502 12503 12504 12505 12506 12507 12508 12509 12510 12511 12512 12513 12514 12515 12516 12517 12518 12519 12520 12521 12522 12523 12524 12525 12526 12527 12528 12529 12530 12531 12532 12533 12534 12535 12536 12537 12538 12539 12540 12541 12542 12543 12544 12545 12546 12547 12548 12549 12550 12551 12552 12553 12554 12555 12556 12557 12558 12559 12560 12561 12562 12563 12564 12565 12566 12567 12568 12569 12570 12571 12572 12573 12574 12575 12576 12577 12578 12579 12580 12581 12582 12583 12584 12585 12586 12587 12588 12589 12590 12591 12592 12593 12594 12595 12596 12597 12598 12599 12600 12601 12602 12603 12604 12605 12606 12607 12608 12609 12610 12611 12612 12613 12614 12615 12616 12617 12618 12619 12620 12621 12622 12623 12624 12625 12626 12627 12628 12629 12630 12631 12632 12633 12634 12635 12636 12637 12638 12639 12640 12641 12642 12643 12644 12645 12646 12647 12648 12649 12650 12651 12652 12653 12654 12655 12656 12657 12658 12659 12660 12661 12662 12663 12664 12665 12666 12667 12668 12669 12670 12671 12672 12673 12674 12675 12676 12677 12678 12679 12680 12681 12682 12683 12684 12685 12686 12687 12688 12689 12690 12691 12692 12693 12694 12695 12696 12697 12698 12699 12700 12701 12702 12703 12704 12705 12706 12707 12708 12709 12710 12711 12712 12713 12714 12715 12716 12717 12718 12719 12720 12721 12722 12723 12724 12725 12726 12727 12728 12729 12730 12731 12732 12733 12734 12735 12736 12737 12738 12739 12740 12741 12742 12743 12744 12745 12746 12747 12748 12749 12750 12751 12752 12753 12754 12755 12756 12757 12758 12759 12760 12761 12762 12763 12764 12765 12766 12767 12768 12769 12770 12771 12772 12773 12774 12775 12776 12777 12778 12779 12780 12781 12782 12783 12784 12785 12786 12787 12788 12789 12790 12791 12792 12793 12794 12795 12796 12797 12798 12799 12800 12801 12802 12803 12804 12805 12806 12807 12808 12809 12810 12811 12812 12813 12814 12815 12816 12817 12818 12819 12820 12821 12822 12823 12824 12825 12826 12827 12828 12829 12830 12831 12832 12833 12834 12835 12836 12837 12838 12839 12840 12841 12842 12843 12844 12845 12846 12847 12848 12849 12850 12851 12852 12853 12854 12855 12856 12857 12858 12859 12860 12861 12862 12863 12864 12865 12866 12867 12868 12869 12870 12871 12872 12873 12874 12875 12876 12877 12878 12879 12880 12881 12882 12883 12884 12885 12886 12887 12888 12889 12890 12891 12892 12893 12894 12895 12896 12897 12898 12899 12900 12901 12902 12903 12904 12905 12906 12907 12908 12909 12910 12911 12912 12913 12914 12915 12916 12917 12918 12919 12920 12921 12922 12923 12924 12925 12926 12927 12928 12929 12930 12931 12932 12933 12934 12935 12936 12937 12938 12939 12940 12941 12942 12943 12944 12945 12946 12947 12948 12949 12950 12951 12952 12953 12954 12955 12956 12957 12958 12959 12960 12961 12962 12963 12964 12965 12966 12967 12968 12969 12970 12971 12972 12973 12974 12975 12976 12977 12978 12979 12980 12981 12982 12983 12984 12985 12986 12987 12988 12989 12990 12991 12992 12993 12994 12995 12996 12997 12998 12999 13000 13001 13002 13003 13004 13005 13006 13007 13008 13009 13010 13011 13012 13013 13014 13015 13016 13017 13018 13019 13020 13021 13022 13023 13024 13025 13026 13027 13028 13029 13030 13031 13032 13033 13034 13035 13036 13037 13038 13039 13040 13041 13042 13043 13044 13045 13046 13047 13048 13049 13050 13051 13052 13053 13054 13055 13056 13057 13058 13059 13060 13061 13062 13063 13064 13065 13066 13067 13068 13069 13070 13071 13072 13073 13074 13075 13076 13077 13078 13079 13080 13081 13082 13083 13084 13085 13086 13087 13088 13089 13090 13091 13092 13093 13094 13095 13096 13097 13098 13099 13100 13101 13102 13103 13104 13105 13106 13107 13108 13109 13110 13111 13112 13113 13114 13115 13116 13117 13118 13119 13120 13121 13122 13123 13124 13125 13126 13127 13128 13129 13130 13131 13132 13133 13134 13135 13136 13137 13138 13139 13140 13141 13142 13143 13144 13145 13146 13147 13148 13149 13150 13151 13152 13153 13154 13155 13156 13157 13158 13159 13160 13161 13162 13163 13164 13165 13166 13167 13168 13169 13170 13171 13172 13173 13174 13175 13176 13177 13178 13179 13180 13181 13182 13183 13184 13185 13186 13187 13188 13189 13190 13191 13192 13193 13194 13195 13196 13197 13198 13199 13200 13201 13202 13203 13204 13205 13206 13207 13208 13209 13210 13211 13212 13213 13214 13215 13216 13217 13218 13219 13220 13221 13222 13223 13224 13225 13226 13227 13228 13229 13230 13231 13232 13233 13234 13235 13236 13237 13238 13239 13240 13241 13242 13243 13244 13245 13246 13247 13248 13249 13250 13251 13252 13253 13254 13255 13256 13257 13258 13259 13260 13261 13262 13263 13264 13265 13266 13267 13268 13269 13270 13271 13272 13273 13274 13275 13276 13277 13278 13279 13280 13281 13282 13283 13284 13285 13286 13287 13288 13289 13290 13291 13292 13293 13294 13295 13296 13297 13298 13299 13300 13301 13302 13303 13304 13305 13306 13307 13308 13309 13310 13311 13312 13313 13314 13315 13316 13317 13318 13319 13320 13321 13322 13323 13324 13325 13326 13327 13328 13329 13330 13331 13332 13333 13334 13335 13336 13337 13338 13339 13340 13341 13342 13343 13344 13345 13346 13347 13348 13349 13350 13351 13352 13353 13354 13355 13356 13357 13358 13359 13360 13361 13362 13363 13364 13365 13366 13367 13368 13369 13370 13371 13372 13373 13374 13375 13376 13377 13378 13379 13380 13381 13382 13383 13384 13385 13386 13387 13388 13389 13390 13391 13392 13393 13394 13395 13396 13397 13398 13399 13400 13401 13402 13403 13404 13405 13406 13407 13408 13409 13410 13411 13412 13413 13414 13415 13416 13417 13418 13419 13420 13421 13422 13423 13424 13425 13426 13427 13428 13429 13430 13431 13432 13433 13434 13435 13436 13437 13438 13439 13440 13441 13442 13443 13444 13445 13446 13447 13448 13449 13450 13451 13452 13453 13454 13455 13456 13457 13458 13459 13460 13461 13462 13463 13464 13465 13466 13467 13468 13469 13470 13471 13472 13473 13474 13475 13476 13477 13478 13479 13480 13481 13482 13483 13484 13485 13486 13487 13488 13489 13490 13491 13492 13493 13494 13495 13496 13497 13498 13499 13500 13501 13502 13503 13504 13505 13506 13507 13508 13509 13510 13511 13512 13513 13514 13515 13516 13517 13518 13519 13520 13521 13522 13523 13524 13525 13526 13527 13528 13529 13530 13531 13532 13533 13534 13535 13536 13537 13538 13539 13540 13541 13542 13543 13544 13545 13546 13547 13548 13549 13550 13551 13552 13553 13554 13555 13556 13557 13558 13559 13560 13561 13562 13563 13564 13565 13566 13567 13568 13569 13570 13571 13572 13573 13574 13575 13576 13577 13578 13579 13580 13581 13582 13583 13584 13585 13586 13587 13588 13589 13590 13591 13592 13593 13594 13595 13596 13597 13598 13599 13600 13601 13602 13603 13604 13605 13606 13607 13608 13609 13610 13611 13612 13613 13614 13615 13616 13617 13618 13619 13620 13621 13622 13623 13624 13625 13626 13627 13628 13629 13630 13631 13632 13633 13634 13635 13636 13637 13638 13639 13640 13641 13642 13643 13644 13645 13646 13647 13648 13649 13650 13651 13652 13653 13654 13655 13656 13657 13658 13659 13660 13661 13662 13663 13664 13665 13666 13667 13668 13669 13670 13671 13672 13673 13674 13675 13676 13677 13678 13679 13680 13681 13682 13683 13684 13685 13686 13687 13688 13689 13690 13691 13692 13693 13694 13695 13696 13697 13698 13699 13700 13701 13702 13703 13704 13705 13706 13707 13708 13709 13710 13711 13712 13713 13714 13715 13716 13717 13718 13719 13720 13721 13722 13723 13724 13725 13726 13727 13728 13729 13730 13731 13732 13733 13734 13735 13736 13737 13738 13739 13740 13741 13742 13743 13744 13745 13746 13747 13748 13749 13750 13751 13752 13753 13754 13755 13756 13757 13758 13759 13760 13761 13762 13763 13764 13765 13766 13767 13768 13769 13770 13771 13772 13773 13774 13775 13776 13777 13778 13779 13780 13781 13782 13783 13784 13785 13786 13787 13788 13789 13790 13791 13792 13793 13794 13795 13796 13797 13798 13799 13800 13801 13802 13803 13804 13805 13806 13807 13808 13809 13810 13811 13812 13813 13814 13815 13816 13817 13818 13819 13820 13821 13822 13823 13824 13825 13826 13827 13828 13829 13830 13831 13832 13833 13834 13835 13836 13837 13838 13839 13840 13841 13842 13843 13844 13845 13846 13847 13848 13849 13850 13851 13852 13853 13854 13855 13856 13857 13858 13859 13860 13861 13862 13863 13864 13865 13866 13867 13868 13869 13870 13871 13872 13873 13874 13875 13876 13877 13878 13879 13880 13881 13882 13883 13884 13885 13886 13887 13888 13889 13890 13891 13892 13893 13894 13895 13896 13897 13898 13899 13900 13901 13902 13903 13904 13905 13906 13907 13908 13909 13910 13911 13912 13913 13914 13915 13916 13917 13918 13919 13920 13921 13922 13923 13924 13925 13926 13927 13928 13929 13930 13931 13932 13933 13934 13935 13936 13937 13938 13939 13940 13941 13942 13943 13944 13945 13946 13947 13948 13949 13950 13951 13952 13953 13954 13955 13956 13957 13958 13959 13960 13961 13962 13963 13964 13965 13966 13967 13968 13969 13970 13971 13972 13973 13974 13975 13976 13977 13978 13979 13980 13981 13982 13983 13984 13985 13986 13987 13988 13989 13990 13991 13992 13993 13994 13995 13996 13997 13998 13999 14000 14001 14002 14003 14004 14005 14006 14007 14008 14009 14010 14011 14012 14013 14014 14015 14016 14017 14018 14019 14020 14021 14022 14023 14024 14025 14026 14027 14028 14029 14030 14031 14032 14033 14034 14035 14036 14037 14038 14039 14040 14041 14042 14043 14044 14045 14046 14047 14048 14049 14050 14051 14052 14053 14054 14055 14056 14057 14058 14059 14060 14061 14062 14063 14064 14065 14066 14067 14068 14069 14070 14071 14072 14073 14074 14075 14076 14077 14078 14079 14080 14081 14082 14083 14084 14085 14086 14087 14088 14089 14090 14091 14092 14093 14094 14095 14096 14097 14098 14099 14100 14101 14102 14103 14104 14105 14106 14107 14108 14109 14110 14111 14112 14113 14114 14115 14116 14117 14118 14119 14120 14121 14122 14123 14124 14125 14126 14127 14128 14129 14130 14131 14132 14133 14134 14135 14136 14137 14138 14139 14140 14141 14142 14143 14144 14145 14146 14147 14148 14149 14150 14151 14152 14153 14154 14155 14156 14157 14158 14159 14160 14161 14162 14163 14164 14165 14166 14167 14168 14169 14170 14171 14172 14173 14174 14175 14176 14177 14178 14179 14180 14181 14182 14183 14184 14185 14186 14187 14188 14189 14190 14191 14192 14193 14194 14195 14196 14197 14198 14199 14200 14201 14202 14203 14204 14205 14206 14207 14208 14209 14210 14211 14212 14213 14214 14215 14216 14217 14218 14219 14220 14221 14222 14223 14224 14225 14226 14227 14228 14229 14230 14231 14232 14233 14234 14235 14236 14237 14238 14239 14240 14241 14242 14243 14244 14245 14246 14247 14248 14249 14250 14251 14252 14253 14254 14255 14256 14257 14258 14259 14260 14261 14262 14263 14264 14265 14266 14267 14268 14269 14270 14271 14272 14273 14274 14275 14276 14277 14278 14279 14280 14281 14282 14283 14284 14285 14286 14287 14288 14289 14290 14291 14292 14293 14294 14295 14296 14297 14298 14299 14300 14301 14302 14303 14304 14305 14306 14307 14308 14309 14310 14311 14312 14313 14314 14315 14316 14317 14318 14319 14320 14321 14322 14323 14324 14325 14326 14327 14328 14329 14330 14331 14332 14333 14334 14335 14336 14337 14338 14339 14340 14341 14342 14343 14344 14345 14346 14347 14348 14349 14350 14351 14352 14353 14354 14355 14356 14357 14358 14359 14360 14361 14362 14363 14364 14365 14366 14367 14368 14369 14370 14371 14372 14373 14374 14375 14376 14377 14378 14379 14380 14381 14382 14383 14384 14385 14386 14387 14388 14389 14390 14391 14392 14393 14394 14395 14396 14397 14398 14399 14400 14401 14402 14403 14404 14405 14406 14407 14408 14409 14410 14411 14412 14413 14414 14415 14416 14417 14418 14419 14420 14421 14422 14423 14424 14425 14426 14427 14428 14429 14430 14431 14432 14433 14434 14435 14436 14437 14438 14439 14440 14441 14442 14443 14444 14445 14446 14447 14448 14449 14450 14451 14452 14453 14454 14455 14456 14457 14458 14459 14460 14461 14462 14463 14464 14465 14466 14467 14468 14469 14470 14471 14472 14473 14474 14475 14476 14477 14478 14479 14480 14481 14482 14483 14484 14485 14486 14487 14488 14489 14490 14491 14492 14493 14494 14495 14496 14497 14498 14499 14500 14501 14502 14503 14504 14505 14506 14507 14508 14509 14510 14511 14512 14513 14514 14515 14516 14517 14518 14519 14520 14521 14522 14523 14524 14525 14526 14527 14528 14529 14530 14531 14532 14533 14534 14535 14536 14537 14538 14539 14540 14541 14542 14543 14544 14545 14546 14547 14548 14549 14550 14551 14552 14553 14554 14555 14556 14557 14558 14559 14560 14561 14562 14563 14564 14565 14566 14567 14568 14569 14570 14571 14572 14573 14574 14575 14576 14577 14578 14579 14580 14581 14582 14583 14584 14585 14586 14587 14588 14589 14590 14591 14592 14593 14594 14595 14596 14597 14598 14599 14600 14601 14602 14603 14604 14605 14606 14607 14608 14609 14610 14611 14612 14613 14614 14615 14616 14617 14618 14619 14620 14621 14622 14623 14624 14625 14626 14627 14628 14629 14630 14631 14632 14633 14634 14635 14636 14637 14638 14639 14640 14641 14642 14643 14644 14645 14646 14647 14648 14649 14650 14651 14652 14653 14654 14655 14656 14657 14658 14659 14660 14661 14662 14663 14664 14665 14666 14667 14668 14669 14670 14671 14672 14673 14674 14675 14676 14677 14678 14679 14680 14681 14682 14683 14684 14685 14686 14687 14688 14689 14690 14691 14692 14693 14694 14695 14696 14697 14698 14699 14700 14701 14702 14703 14704 14705 14706 14707 14708 14709 14710 14711 14712 14713 14714 14715 14716 14717 14718 14719 14720 14721 14722 14723 14724 14725 14726 14727 14728 14729 14730 14731 14732 14733 14734 14735 14736 14737 14738 14739 14740 14741 14742 14743 14744 14745 14746 14747 14748 14749
|
#!/usr/bin/perl
# cloc -- Count Lines of Code {{{1
# Copyright (C) 2006-2020 Al Danial <al.danial@gmail.com>
# First release August 2006
#
# Includes code from:
# - SLOCCount v2.26
# http://www.dwheeler.com/sloccount/
# by David Wheeler.
# - Regexp::Common v2013031301
# http://search.cpan.org/~abigail/Regexp-Common-2013031301/lib/Regexp/Common.pm
# by Damian Conway and Abigail.
# - Win32::Autoglob
# http://search.cpan.org/~sburke/Win32-Autoglob-1.01/Autoglob.pm
# by Sean M. Burke.
# - Algorithm::Diff
# http://search.cpan.org/~tyemq/Algorithm-Diff-1.1902/lib/Algorithm/Diff.pm
# by Tye McQueen.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details:
# <http://www.gnu.org/licenses/gpl.txt>.
#
# 1}}}
my $VERSION = "1.86"; # odd number == beta; even number == stable
my $URL = "github.com/AlDanial/cloc"; # 'https://' pushes header too wide
require 5.006;
# use modules {{{1
use warnings;
use strict;
use Getopt::Long;
use File::Basename;
use File::Temp qw { tempfile tempdir };
use File::Find;
use File::Path;
use File::Spec;
use IO::File;
use List::Util qw( min max );
use Cwd;
use POSIX qw { strftime ceil};
# Parallel::ForkManager isn't in the standard distribution.
# Use it only if installed, and only if --processes=N is given.
# The module load happens in get_max_processes().
my $HAVE_Parallel_ForkManager = 0;
# Digest::MD5 isn't in the standard distribution. Use it only if installed.
my $HAVE_Digest_MD5 = 0;
eval "use Digest::MD5;";
if (defined $Digest::MD5::VERSION) {
$HAVE_Digest_MD5 = 1;
} else {
warn "Digest::MD5 not installed; will skip file uniqueness checks.\n";
}
# Time::HiRes became standard with Perl 5.8
my $HAVE_Time_HiRes = 0;
eval "use Time::HiRes;";
$HAVE_Time_HiRes = 1 if defined $Time::HiRes::VERSION;
my $HAVE_Rexexp_Common;
# Regexp::Common isn't in the standard distribution. It will
# be installed in a temp directory if necessary.
BEGIN {
if (eval "use Regexp::Common;") {
$HAVE_Rexexp_Common = 1;
} else {
$HAVE_Rexexp_Common = 0;
}
}
my $HAVE_Algorith_Diff = 0;
# Algorithm::Diff isn't in the standard distribution. It will
# be installed in a temp directory if necessary.
eval "use Algorithm::Diff qw ( sdiff ) ";
if (defined $Algorithm::Diff::VERSION) {
$HAVE_Algorith_Diff = 1;
} else {
Install_Algorithm_Diff();
}
# print "2 HAVE_Algorith_Diff = $HAVE_Algorith_Diff\n";
# test_alg_diff($ARGV[$#ARGV - 1], $ARGV[$#ARGV]); die;
# die "Hre=$HAVE_Rexexp_Common Had=$HAVE_Algorith_Diff";
# Uncomment next two lines when building Windows executable with perl2exe
# or if running on a system that already has Regexp::Common.
#use Regexp::Common;
#$HAVE_Rexexp_Common = 1;
#perl2exe_include "Regexp/Common/whitespace.pm"
#perl2exe_include "Regexp/Common/URI.pm"
#perl2exe_include "Regexp/Common/URI/fax.pm"
#perl2exe_include "Regexp/Common/URI/file.pm"
#perl2exe_include "Regexp/Common/URI/ftp.pm"
#perl2exe_include "Regexp/Common/URI/gopher.pm"
#perl2exe_include "Regexp/Common/URI/http.pm"
#perl2exe_include "Regexp/Common/URI/pop.pm"
#perl2exe_include "Regexp/Common/URI/prospero.pm"
#perl2exe_include "Regexp/Common/URI/news.pm"
#perl2exe_include "Regexp/Common/URI/tel.pm"
#perl2exe_include "Regexp/Common/URI/telnet.pm"
#perl2exe_include "Regexp/Common/URI/tv.pm"
#perl2exe_include "Regexp/Common/URI/wais.pm"
#perl2exe_include "Regexp/Common/CC.pm"
#perl2exe_include "Regexp/Common/SEN.pm"
#perl2exe_include "Regexp/Common/number.pm"
#perl2exe_include "Regexp/Common/delimited.pm"
#perl2exe_include "Regexp/Common/profanity.pm"
#perl2exe_include "Regexp/Common/net.pm"
#perl2exe_include "Regexp/Common/zip.pm"
#perl2exe_include "Regexp/Common/comment.pm"
#perl2exe_include "Regexp/Common/balanced.pm"
#perl2exe_include "Regexp/Common/lingua.pm"
#perl2exe_include "Regexp/Common/list.pm"
#perl2exe_include "File/Glob.pm"
use Text::Tabs qw { expand };
use Cwd qw { cwd };
use File::Glob;
# 1}}}
# Usage information, options processing. {{{1
my $ON_WINDOWS = 0;
$ON_WINDOWS = 1 if ($^O =~ /^MSWin/) or ($^O eq "Windows_NT");
if ($ON_WINDOWS and $ENV{'SHELL'}) {
if ($ENV{'SHELL'} =~ m{^/}) {
$ON_WINDOWS = 0; # make Cygwin look like Unix
} else {
$ON_WINDOWS = 1; # MKS defines $SHELL but still acts like Windows
}
}
my $config_file = '';
if ( $ENV{'HOME'} ) {
$config_file = File::Spec->catfile( $ENV{'HOME'}, '.config', 'cloc', 'options.txt');
} elsif ( $ENV{'APPDATA'} and $ON_WINDOWS ) {
$config_file = File::Spec->catfile( $ENV{'APPDATA'}, 'cloc');
}
my $NN = chr(27) . "[0m"; # normal
$NN = "" if $ON_WINDOWS or !(-t STDOUT); # -t STDOUT: is it a terminal?
my $BB = chr(27) . "[1m"; # bold
$BB = "" if $ON_WINDOWS or !(-t STDOUT);
my $script = basename $0;
# Intended for v1.88:
# --git-diff-simindex Git diff strategy #3: use git's similarity index
# (git diff -M --name-status) to identify file pairs
# to compare. This is especially useful to compare
# files that were renamed between the commits.
my $brief_usage = "
cloc -- Count Lines of Code
Usage:
$script [options] <file(s)/dir(s)/git hash(es)>
Count physical lines of source code and comments in the given files
(may be archives such as compressed tarballs or zip files) and/or
recursively below the given directories or git commit hashes.
Example: cloc src/ include/ main.c
$script [options] --diff <set1> <set2>
Compute differences of physical lines of source code and comments
between any pairwise combination of directory names, archive
files or git commit hashes.
Example: cloc --diff Python-3.5.tar.xz python-3.6/
$script --help shows full documentation on the options.
https://$URL has numerous examples and more information.
";
my $usage = "
Usage: $script [options] <file(s)/dir(s)/git hash(es)> | <set 1> <set 2> | <report files>
Count, or compute differences of, physical lines of source code in the
given files (may be archives such as compressed tarballs or zip files,
or git commit hashes or branch names) and/or recursively below the
given directories.
${BB}Input Options${NN}
--extract-with=<cmd> This option is only needed if cloc is unable
to figure out how to extract the contents of
the input file(s) by itself.
Use <cmd> to extract binary archive files (e.g.:
.tar.gz, .zip, .Z). Use the literal '>FILE<' as
a stand-in for the actual file(s) to be
extracted. For example, to count lines of code
in the input files
gcc-4.2.tar.gz perl-5.8.8.tar.gz
on Unix use
--extract-with='gzip -dc >FILE< | tar xf -'
or, if you have GNU tar,
--extract-with='tar zxf >FILE<'
and on Windows use, for example:
--extract-with=\"\\\"c:\\Program Files\\WinZip\\WinZip32.exe\\\" -e -o >FILE< .\"
(if WinZip is installed there).
--list-file=<file> Take the list of file and/or directory names to
process from <file>, which has one file/directory
name per line. Only exact matches are counted;
relative path names will be resolved starting from
the directory where cloc is invoked. Set <file>
to - to read file names from a STDIN pipe.
See also --exclude-list-file.
--diff-list-file=<file> Take the pairs of file names to be diff'ed from
<file>, whose format matches the output of
--diff-alignment. (Run with that option to
see a sample.) The language identifier at the
end of each line is ignored. This enables --diff
mode and by-passes file pair alignment logic.
--vcs=<VCS> Invoke a system call to <VCS> to obtain a list of
files to work on. If <VCS> is 'git', then will
invoke 'git ls-files' to get a file list and
'git submodule status' to get a list of submodules
whose contents will be ignored. See also --git
which accepts git commit hashes and branch names.
If <VCS> is 'svn' then will invoke 'svn list -R'.
The primary benefit is that cloc will then skip
files explicitly excluded by the versioning tool
in question, ie, those in .gitignore or have the
svn:ignore property.
Alternatively <VCS> may be any system command
that generates a list of files.
Note: cloc must be in a directory which can read
the files as they are returned by <VCS>. cloc will
not download files from remote repositories.
'svn list -R' may refer to a remote repository
to obtain file names (and therefore may require
authentication to the remote repository), but
the files themselves must be local.
Setting <VCS> to 'auto' selects between 'git'
and 'svn' (or neither) depending on the presence
of a .git or .svn subdirectory below the directory
where cloc is invoked.
--unicode Check binary files to see if they contain Unicode
expanded ASCII text. This causes performance to
drop noticeably.
${BB}Processing Options${NN}
--autoconf Count .in files (as processed by GNU autoconf) of
recognized languages. See also --no-autogen.
--by-file Report results for every source file encountered.
--by-file-by-lang Report results for every source file encountered
in addition to reporting by language.
--config <file> Read command line switches from <file> instead of
the default location of $config_file.
The file should contain one switch, along with
arguments (if any), per line. Blank lines and lines
beginning with '#' are skipped. Options given on
the command line take priority over entries read from
the file.
--count-and-diff <set1> <set2>
First perform direct code counts of source file(s)
of <set1> and <set2> separately, then perform a diff
of these. Inputs may be pairs of files, directories,
or archives. If --out or --report-file is given,
three output files will be created, one for each
of the two counts and one for the diff. See also
--diff, --diff-alignment, --diff-timeout,
--ignore-case, --ignore-whitespace.
--diff <set1> <set2> Compute differences in code and comments between
source file(s) of <set1> and <set2>. The inputs
may be any mix of files, directories, archives,
or git commit hashes. Use --diff-alignment to
generate a list showing which file pairs where
compared. When comparing git branches, only files
which have changed in either commit are compared.
See also --git, --count-and-diff, --diff-alignment,
--diff-list-file, --diff-timeout, --ignore-case,
--ignore-whitespace.
--diff-timeout <N> Ignore files which take more than <N> seconds
to process. Default is 10 seconds. Setting <N>
to 0 allows unlimited time. (Large files with many
repeated lines can cause Algorithm::Diff::sdiff()
to take hours.) See also --timeout.
--docstring-as-code cloc considers docstrings to be comments, but this is
not always correct as docstrings represent regular
strings when they appear on the right hand side of an
assignment or as function arguments. This switch
forces docstrings to be counted as code.
--follow-links [Unix only] Follow symbolic links to directories
(sym links to files are always followed).
See also --stat.
--force-lang=<lang>[,<ext>]
Process all files that have a <ext> extension
with the counter for language <lang>. For
example, to count all .f files with the
Fortran 90 counter (which expects files to
end with .f90) instead of the default Fortran 77
counter, use
--force-lang=\"Fortran 90\",f
If <ext> is omitted, every file will be counted
with the <lang> counter. This option can be
specified multiple times (but that is only
useful when <ext> is given each time).
See also --script-lang, --lang-no-ext.
--force-lang-def=<file> Load language processing filters from <file>,
then use these filters instead of the built-in
filters. Note: languages which map to the same
file extension (for example:
MATLAB/Mathematica/Objective C/MUMPS/Mercury;
Pascal/PHP; Lisp/OpenCL; Lisp/Julia; Perl/Prolog)
will be ignored as these require additional
processing that is not expressed in language
definition files. Use --read-lang-def to define
new language filters without replacing built-in
filters (see also --write-lang-def,
--write-lang-def-incl-dup).
--git Forces the inputs to be interpreted as git targets
(commit hashes, branch names, et cetera) if these
are not first identified as file or directory
names. This option overrides the --vcs=git logic
if this is given; in other words, --git gets its
list of files to work on directly from git using
the hash or branch name rather than from
'git ls-files'. This option can be used with
--diff to perform line count diffs between git
commits, or between a git commit and a file,
directory, or archive. Use -v/--verbose to see
the git system commands cloc issues.
--git-diff-rel Same as --git --diff, or just --diff if the inputs
are recognized as git targets. Only files which
have changed in either commit are compared.
--git-diff-all Git diff strategy #2: compare all files in the
repository between the two commits.
--ignore-whitespace Ignore horizontal white space when comparing files
with --diff. See also --ignore-case.
--ignore-case Ignore changes in case within file contents;
consider upper- and lowercase letters equivalent
when comparing files with --diff. See also
--ignore-whitespace.
--ignore-case-ext Ignore case of file name extensions. This will
cause problems counting some languages
(specifically, .c and .C are associated with C and
C++; this switch would count .C files as C rather
than C++ on *nix operating systems). File name
case insensitivity is always true on Windows.
--lang-no-ext=<lang> Count files without extensions using the <lang>
counter. This option overrides internal logic
for files without extensions (where such files
are checked against known scripting languages
by examining the first line for #!). See also
--force-lang, --script-lang.
--max-file-size=<MB> Skip files larger than <MB> megabytes when
traversing directories. By default, <MB>=100.
cloc's memory requirement is roughly twenty times
larger than the largest file so running with
files larger than 100 MB on a computer with less
than 2 GB of memory will cause problems.
Note: this check does not apply to files
explicitly passed as command line arguments.
--no-autogen[=list] Ignore files generated by code-production systems
such as GNU autoconf. To see a list of these files
(then exit), run with --no-autogen list
See also --autoconf.
--original-dir [Only effective in combination with
--strip-comments] Write the stripped files
to the same directory as the original files.
--read-binary-files Process binary files in addition to text files.
This is usually a bad idea and should only be
attempted with text files that have embedded
binary data.
--read-lang-def=<file> Load new language processing filters from <file>
and merge them with those already known to cloc.
If <file> defines a language cloc already knows
about, cloc's definition will take precedence.
Use --force-lang-def to over-ride cloc's
definitions (see also --write-lang-def,
--write-lang-def-incl-dup).
--script-lang=<lang>,<s> Process all files that invoke <s> as a #!
scripting language with the counter for language
<lang>. For example, files that begin with
#!/usr/local/bin/perl5.8.8
will be counted with the Perl counter by using
--script-lang=Perl,perl5.8.8
The language name is case insensitive but the
name of the script language executable, <s>,
must have the right case. This option can be
specified multiple times. See also --force-lang,
--lang-no-ext.
--sdir=<dir> Use <dir> as the scratch directory instead of
letting File::Temp chose the location. Files
written to this location are not removed at
the end of the run (as they are with File::Temp).
--skip-uniqueness Skip the file uniqueness check. This will give
a performance boost at the expense of counting
files with identical contents multiple times
(if such duplicates exist).
--stat Some file systems (AFS, CD-ROM, FAT, HPFS, SMB)
do not have directory 'nlink' counts that match
the number of its subdirectories. Consequently
cloc may undercount or completely skip the
contents of such file systems. This switch forces
File::Find to stat directories to obtain the
correct count. File search spead will decrease.
See also --follow-links.
--stdin-name=<file> Give a file name to use to determine the language
for standard input. (Use - as the input name to
receive source code via STDIN.)
--strip-comments=<ext> For each file processed, write to the current
directory a version of the file which has blank
and commented lines removed (in-line comments
persist). The name of each stripped file is the
original file name with .<ext> appended to it.
It is written to the current directory unless
--original-dir is on.
--strip-str-comments Replace comment markers embedded in strings with
'xx'. This attempts to work around a limitation
in Regexp::Common::Comment where comment markers
embedded in strings are seen as actual comment
markers and not strings, often resulting in a
'Complex regular subexpression recursion limit'
warning and incorrect counts. There are two
disadvantages to using this switch: 1/code count
performance drops, and 2/code generated with
--strip-comments will contain different strings
where ever embedded comments are found.
--sum-reports Input arguments are report files previously
created with the --report-file option in plain
format (eg. not JSON, YAML, XML, or SQL).
Makes a cumulative set of results containing the
sum of data from the individual report files.
--timeout <N> Ignore files which take more than <N> seconds
to process at any of the language's filter stages.
The default maximum number of seconds spent on a
filter stage is the number of lines in the file
divided by one thousand. Setting <N> to 0 allows
unlimited time. See also --diff-timeout.
--processes=NUM [Available only on systems with a recent version
of the Parallel::ForkManager module. Not
available on Windows.] Sets the maximum number of
cores that cloc uses. The default value of 0
disables multiprocessing.
--unix Override the operating system autodetection
logic and run in UNIX mode. See also
--windows, --show-os.
--use-sloccount If SLOCCount is installed, use its compiled
executables c_count, java_count, pascal_count,
php_count, and xml_count instead of cloc's
counters. SLOCCount's compiled counters are
substantially faster than cloc's and may give
a performance improvement when counting projects
with large files. However, these cloc-specific
features will not be available: --diff,
--count-and-diff, --strip-comments, --unicode.
--windows Override the operating system autodetection
logic and run in Microsoft Windows mode.
See also --unix, --show-os.
${BB}Filter Options${NN}
--exclude-content=<regex> Exclude files containing text that matches the given
regular expression.
--exclude-dir=<D1>[,D2,] Exclude the given comma separated directories
D1, D2, D3, et cetera, from being scanned. For
example --exclude-dir=.cache,test will skip
all files and subdirectories that have /.cache/
or /test/ as their parent directory.
Directories named .bzr, .cvs, .hg, .git, .svn,
and .snapshot are always excluded.
This option only works with individual directory
names so including file path separators is not
allowed. Use --fullpath and --not-match-d=<regex>
to supply a regex matching multiple subdirectories.
--exclude-ext=<ext1>[,<ext2>[...]]
Do not count files having the given file name
extensions.
--exclude-lang=<L1>[,L2[...]]
Exclude the given comma separated languages
L1, L2, L3, et cetera, from being counted.
--exclude-list-file=<file> Ignore files and/or directories whose names
appear in <file>. <file> should have one file
name per line. Only exact matches are ignored;
relative path names will be resolved starting from
the directory where cloc is invoked.
See also --list-file.
--fullpath Modifies the behavior of --match-f, --not-match-f,
and --not-match-d to include the file's path
in the regex, not just the file's basename.
(This does not expand each file to include its
absolute path, instead it uses as much of
the path as is passed in to cloc.)
Note: --match-d always looks at the full
path and therefore is unaffected by --fullpath.
--include-ext=<ext1>[,ext2[...]]
Count only languages having the given comma
separated file extensions. Use --show-ext to
see the recognized extensions.
--include-lang=<L1>[,L2[...]]
Count only the given comma separated languages
L1, L2, L3, et cetera. Use --show-lang to see
the list of recognized languages.
--match-d=<regex> Only count files in directories matching the Perl
regex. For example
--match-d='/(src|include)/'
only counts files in directories containing
/src/ or /include/. Unlike --not-match-d,
--match-f, and --not-match-f, --match-d always
compares the fully qualified path against the
regex.
--not-match-d=<regex> Count all files except those in directories
matching the Perl regex. Only the trailing
directory name is compared, for example, when
counting in /usr/local/lib, only 'lib' is
compared to the regex.
Add --fullpath to compare parent directories to
the regex.
Do not include file path separators at the
beginning or end of the regex.
--match-f=<regex> Only count files whose basenames match the Perl
regex. For example
--match-f='^[Ww]idget'
only counts files that start with Widget or widget.
Add --fullpath to include parent directories
in the regex instead of just the basename.
--not-match-f=<regex> Count all files except those whose basenames
match the Perl regex. Add --fullpath to include
parent directories in the regex instead of just
the basename.
--skip-archive=<regex> Ignore files that end with the given Perl regular
expression. For example, if given
--skip-archive='(zip|tar(\.(gz|Z|bz2|xz|7z))?)'
the code will skip files that end with .zip,
.tar, .tar.gz, .tar.Z, .tar.bz2, .tar.xz, and
.tar.7z.
--skip-win-hidden On Windows, ignore hidden files.
${BB}Debug Options${NN}
--categorized=<file> Save names of categorized files to <file>.
--counted=<file> Save names of processed source files to <file>.
--diff-alignment=<file> Write to <file> a list of files and file pairs
showing which files were added, removed, and/or
compared during a run with --diff. This switch
forces the --diff mode on.
--explain=<lang> Print the filters used to remove comments for
language <lang> and exit. In some cases the
filters refer to Perl subroutines rather than
regular expressions. An examination of the
source code may be needed for further explanation.
--help Print this usage information and exit.
--found=<file> Save names of every file found to <file>.
--ignored=<file> Save names of ignored files and the reason they
were ignored to <file>.
--print-filter-stages Print processed source code before and after
each filter is applied.
--show-ext[=<ext>] Print information about all known (or just the
given) file extensions and exit.
--show-lang[=<lang>] Print information about all known (or just the
given) languages and exit.
--show-os Print the value of the operating system mode
and exit. See also --unix, --windows.
-v[=<n>] Verbose switch (optional numeric value).
-verbose[=<n>] Long form of -v.
--version Print the version of this program and exit.
--write-lang-def=<file> Writes to <file> the language processing filters
then exits. Useful as a first step to creating
custom language definitions. Note: languages which
map to the same file extension will be excluded.
(See also --force-lang-def, --read-lang-def).
--write-lang-def-incl-dup=<file>
Same as --write-lang-def, but includes duplicated
extensions. This generates a problematic language
definition file because cloc will refuse to use
it until duplicates are removed.
${BB}Output Options${NN}
--3 Print third-generation language output.
(This option can cause report summation to fail
if some reports were produced with this option
while others were produced without it.)
--by-percent X Instead of comment and blank line counts, show
these values as percentages based on the value
of X in the denominator:
X = 'c' -> # lines of code
X = 'cm' -> # lines of code + comments
X = 'cb' -> # lines of code + blanks
X = 'cmb' -> # lines of code + comments + blanks
For example, if using method 'c' and your code
has twice as many lines of comments as lines
of code, the value in the comment column will
be 200%. The code column remains a line count.
--csv Write the results as comma separated values.
--csv-delimiter=<C> Use the character <C> as the delimiter for comma
separated files instead of ,. This switch forces
--file-encoding=<E> Write output files using the <E> encoding instead of
the default ASCII (<E> = 'UTF-7'). Examples: 'UTF-16',
'euc-kr', 'iso-8859-16'. Known encodings can be
printed with
perl -MEncode -e 'print join(\"\\n\", Encode->encodings(\":all\")), \"\\n\"'
--hide-rate Do not show line and file processing rates in the
output header. This makes output deterministic.
--json Write the results as JavaScript Object Notation
(JSON) formatted output.
--md Write the results as Markdown-formatted text.
--out=<file> Synonym for --report-file=<file>.
--progress-rate=<n> Show progress update after every <n> files are
processed (default <n>=100). Set <n> to 0 to
suppress progress output (useful when redirecting
output to STDOUT).
--quiet Suppress all information messages except for
the final report.
--report-file=<file> Write the results to <file> instead of STDOUT.
--sql=<file> Write results as SQL create and insert statements
which can be read by a database program such as
SQLite. If <file> is -, output is sent to STDOUT.
--sql-append Append SQL insert statements to the file specified
by --sql and do not generate table creation
statements. Only valid with the --sql option.
--sql-project=<name> Use <name> as the project identifier for the
current run. Only valid with the --sql option.
--sql-style=<style> Write SQL statements in the given style instead
of the default SQLite format. Styles include
'Oracle' and 'Named_Columns'.
--sum-one For plain text reports, show the SUM: output line
even if only one input file is processed.
--xml Write the results in XML.
--xsl=<file> Reference <file> as an XSL stylesheet within
the XML output. If <file> is 1 (numeric one),
writes a default stylesheet, cloc.xsl (or
cloc-diff.xsl if --diff is also given).
This switch forces --xml on.
--yaml Write the results in YAML.
";
# Help information for options not yet implemented:
# --inline Process comments that appear at the end
# of lines containing code.
# --html Create HTML files of each input file showing
# comment and code lines in different colors.
$| = 1; # flush STDOUT
my $start_time = get_time();
my (
$opt_categorized ,
$opt_found ,
@opt_force_lang ,
$opt_lang_no_ext ,
@opt_script_lang ,
$opt_count_diff ,
$opt_diff ,
$opt_diff_alignment ,
$opt_diff_list_file ,
$opt_diff_timeout ,
$opt_timeout ,
$opt_html ,
$opt_ignored ,
$opt_counted ,
$opt_show_ext ,
$opt_show_lang ,
$opt_progress_rate ,
$opt_print_filter_stages ,
$opt_v ,
$opt_vcs ,
$opt_version ,
$opt_exclude_content ,
$opt_exclude_lang ,
$opt_exclude_list_file ,
$opt_exclude_dir ,
$opt_explain ,
$opt_include_ext ,
$opt_include_lang ,
$opt_force_lang_def ,
$opt_read_lang_def ,
$opt_write_lang_def ,
$opt_write_lang_def_incl_dup,
$opt_strip_comments ,
$opt_original_dir ,
$opt_quiet ,
$opt_report_file ,
$opt_sdir ,
$opt_sum_reports ,
$opt_hide_rate ,
$opt_processes ,
$opt_unicode ,
$opt_no3 , # accept it but don't use it
$opt_3 ,
$opt_extract_with ,
$opt_by_file ,
$opt_by_file_by_lang ,
$opt_by_percent ,
$opt_xml ,
$opt_xsl ,
$opt_yaml ,
$opt_csv ,
$opt_csv_delimiter ,
$opt_fullpath ,
$opt_json ,
$opt_md ,
$opt_match_f ,
$opt_not_match_f ,
$opt_match_d ,
$opt_not_match_d ,
$opt_skip_uniqueness ,
$opt_list_file ,
$opt_help ,
$opt_skip_win_hidden ,
$opt_read_binary_files ,
$opt_sql ,
$opt_sql_append ,
$opt_sql_project ,
$opt_sql_style ,
$opt_inline ,
$opt_exclude_ext ,
$opt_ignore_whitespace ,
$opt_ignore_case ,
$opt_ignore_case_ext ,
$opt_follow_links ,
$opt_autoconf ,
$opt_sum_one ,
$opt_stdin_name ,
$opt_force_on_windows ,
$opt_force_on_unix , # actually forces !$ON_WINDOWS
$opt_show_os ,
$opt_skip_archive ,
$opt_max_file_size , # in MB
$opt_use_sloccount ,
$opt_no_autogen ,
$opt_force_git ,
$opt_git_diff_rel ,
$opt_git_diff_all ,
$opt_git_diff_simindex ,
$opt_config_file ,
$opt_strip_str_comments ,
$opt_file_encoding ,
$opt_docstring_as_code ,
$opt_stat ,
);
my $getopt_success = GetOptions( # {{{1
"by_file|by-file" => \$opt_by_file ,
"by_file_by_lang|by-file-by-lang" => \$opt_by_file_by_lang ,
"categorized=s" => \$opt_categorized ,
"counted=s" => \$opt_counted ,
"include_ext|include-ext=s" => \$opt_include_ext ,
"include_lang|include-lang=s" => \$opt_include_lang ,
"exclude_content|exclude-content=s" => \$opt_exclude_content ,
"exclude_lang|exclude-lang=s" => \$opt_exclude_lang ,
"exclude_dir|exclude-dir=s" => \$opt_exclude_dir ,
"exclude_list_file|exclude-list-file=s" => \$opt_exclude_list_file ,
"explain=s" => \$opt_explain ,
"extract_with|extract-with=s" => \$opt_extract_with ,
"found=s" => \$opt_found ,
"count_and_diff|count-and-diff" => \$opt_count_diff ,
"diff" => \$opt_diff ,
"diff-alignment|diff_alignment=s" => \$opt_diff_alignment ,
"diff-timeout|diff_timeout=i" => \$opt_diff_timeout ,
"diff-list-file|diff_list_file=s" => \$opt_diff_list_file ,
"timeout=i" => \$opt_timeout ,
"html" => \$opt_html ,
"ignored=s" => \$opt_ignored ,
"quiet" => \$opt_quiet ,
"force_lang_def|force-lang-def=s" => \$opt_force_lang_def ,
"read_lang_def|read-lang-def=s" => \$opt_read_lang_def ,
"show_ext|show-ext:s" => \$opt_show_ext ,
"show_lang|show-lang:s" => \$opt_show_lang ,
"progress_rate|progress-rate=i" => \$opt_progress_rate ,
"print_filter_stages|print-filter-stages" => \$opt_print_filter_stages ,
"report_file|report-file=s" => \$opt_report_file ,
"out=s" => \$opt_report_file ,
"script_lang|script-lang=s" => \@opt_script_lang ,
"sdir=s" => \$opt_sdir ,
"skip_uniqueness|skip-uniqueness" => \$opt_skip_uniqueness ,
"strip_comments|strip-comments=s" => \$opt_strip_comments ,
"original_dir|original-dir" => \$opt_original_dir ,
"sum_reports|sum-reports" => \$opt_sum_reports ,
"hide_rate|hide-rate" => \$opt_hide_rate ,
"processes=n" => \$opt_processes ,
"unicode" => \$opt_unicode ,
"no3" => \$opt_no3 , # ignored
"3" => \$opt_3 ,
"v|verbose:i" => \$opt_v ,
"vcs=s" => \$opt_vcs ,
"version" => \$opt_version ,
"write_lang_def|write-lang-def=s" => \$opt_write_lang_def ,
"write_lang_def_incl_dup|write-lang-def-incl-dup=s" => \$opt_write_lang_def_incl_dup,
"xml" => \$opt_xml ,
"xsl=s" => \$opt_xsl ,
"force_lang|force-lang=s" => \@opt_force_lang ,
"lang_no_ext|lang-no-ext=s" => \$opt_lang_no_ext ,
"yaml" => \$opt_yaml ,
"csv" => \$opt_csv ,
"csv_delimeter|csv-delimiter=s" => \$opt_csv_delimiter ,
"json" => \$opt_json ,
"md" => \$opt_md ,
"fullpath" => \$opt_fullpath ,
"match_f|match-f=s" => \$opt_match_f ,
"not_match_f|not-match-f=s" => \$opt_not_match_f ,
"match_d|match-d=s" => \$opt_match_d ,
"not_match_d|not-match-d=s" => \$opt_not_match_d ,
"list_file|list-file=s" => \$opt_list_file ,
"help" => \$opt_help ,
"skip_win_hidden|skip-win-hidden" => \$opt_skip_win_hidden ,
"read_binary_files|read-binary-files" => \$opt_read_binary_files ,
"sql=s" => \$opt_sql ,
"sql_project|sql-project=s" => \$opt_sql_project ,
"sql_append|sql-append" => \$opt_sql_append ,
"sql_style|sql-style=s" => \$opt_sql_style ,
"inline" => \$opt_inline ,
"exclude_ext|exclude-ext=s" => \$opt_exclude_ext ,
"ignore_whitespace|ignore-whitespace" => \$opt_ignore_whitespace ,
"ignore_case|ignore-case" => \$opt_ignore_case ,
"ignore_case_ext|ignore-case-ext" => \$opt_ignore_case_ext ,
"follow_links|follow-links" => \$opt_follow_links ,
"autoconf" => \$opt_autoconf ,
"sum_one|sum-one" => \$opt_sum_one ,
"by_percent|by-percent=s" => \$opt_by_percent ,
"stdin_name|stdin-name=s" => \$opt_stdin_name ,
"windows" => \$opt_force_on_windows ,
"unix" => \$opt_force_on_unix ,
"show_os|show-os" => \$opt_show_os ,
"skip_archive|skip-archive=s" => \$opt_skip_archive ,
"max_file_size|max-file-size=i" => \$opt_max_file_size ,
"use_sloccount|use-sloccount" => \$opt_use_sloccount ,
"no_autogen|no-autogen" => \$opt_no_autogen ,
"git" => \$opt_force_git ,
"git_diff_rel|git-diff-rel" => \$opt_git_diff_rel ,
"git_diff_all|git-diff-all" => \$opt_git_diff_all ,
# "git_diff_simindex|git-diff-simindex" => \$opt_git_diff_simindex ,
"config=s" => \$opt_config_file ,
"strip_str_comments|strip-str-comments" => \$opt_strip_str_comments ,
"file_encoding|file-encoding=s" => \$opt_file_encoding ,
"docstring_as_code|docstring-as-code" => \$opt_docstring_as_code ,
"stat" => \$opt_stat ,
);
# 1}}}
$config_file = $opt_config_file if defined $opt_config_file;
load_from_config_file($config_file, # {{{2
\$opt_by_file ,
\$opt_by_file_by_lang ,
\$opt_categorized ,
\$opt_counted ,
\$opt_include_ext ,
\$opt_include_lang ,
\$opt_exclude_content ,
\$opt_exclude_lang ,
\$opt_exclude_dir ,
\$opt_exclude_list_file ,
\$opt_explain ,
\$opt_extract_with ,
\$opt_found ,
\$opt_count_diff ,
\$opt_diff ,
\$opt_diff_alignment ,
\$opt_diff_timeout ,
\$opt_timeout ,
\$opt_html ,
\$opt_ignored ,
\$opt_quiet ,
\$opt_force_lang_def ,
\$opt_read_lang_def ,
\$opt_show_ext ,
\$opt_show_lang ,
\$opt_progress_rate ,
\$opt_print_filter_stages ,
\$opt_report_file ,
\@opt_script_lang ,
\$opt_sdir ,
\$opt_skip_uniqueness ,
\$opt_strip_comments ,
\$opt_original_dir ,
\$opt_sum_reports ,
\$opt_hide_rate ,
\$opt_processes ,
\$opt_unicode ,
\$opt_3 ,
\$opt_v ,
\$opt_vcs ,
\$opt_version ,
\$opt_write_lang_def ,
\$opt_write_lang_def_incl_dup,
\$opt_xml ,
\$opt_xsl ,
\@opt_force_lang ,
\$opt_lang_no_ext ,
\$opt_yaml ,
\$opt_csv ,
\$opt_csv_delimiter ,
\$opt_json ,
\$opt_md ,
\$opt_fullpath ,
\$opt_match_f ,
\$opt_not_match_f ,
\$opt_match_d ,
\$opt_not_match_d ,
\$opt_list_file ,
\$opt_help ,
\$opt_skip_win_hidden ,
\$opt_read_binary_files ,
\$opt_sql ,
\$opt_sql_project ,
\$opt_sql_append ,
\$opt_sql_style ,
\$opt_inline ,
\$opt_exclude_ext ,
\$opt_ignore_whitespace ,
\$opt_ignore_case ,
\$opt_ignore_case_ext ,
\$opt_follow_links ,
\$opt_autoconf ,
\$opt_sum_one ,
\$opt_by_percent ,
\$opt_stdin_name ,
\$opt_force_on_windows ,
\$opt_force_on_unix ,
\$opt_show_os ,
\$opt_skip_archive ,
\$opt_max_file_size ,
\$opt_use_sloccount ,
\$opt_no_autogen ,
\$opt_force_git ,
\$opt_strip_str_comments ,
\$opt_file_encoding ,
\$opt_docstring_as_code ,
\$opt_stat ,
); # 2}}} Not pretty. Not at all.
if ($opt_version) {
printf "$VERSION\n";
exit;
}
$opt_by_file = 1 if defined $opt_by_file_by_lang;
my $CLOC_XSL = "cloc.xsl"; # created with --xsl
$CLOC_XSL = "cloc-diff.xsl" if $opt_diff;
die "\n" unless $getopt_success;
print $usage and exit if $opt_help;
my %Exclude_Language = ();
%Exclude_Language = map { $_ => 1 } split(/,/, $opt_exclude_lang)
if $opt_exclude_lang;
my %Exclude_Dir = ();
%Exclude_Dir = map { $_ => 1 } split(/,/, $opt_exclude_dir )
if $opt_exclude_dir ;
die unless exclude_dir_validates(\%Exclude_Dir);
my %Include_Ext = ();
%Include_Ext = map { $_ => 1 } split(/,/, $opt_include_ext)
if $opt_include_ext;
my %Include_Language = ();
%Include_Language = map { $_ => 1 } split(/,/, $opt_include_lang)
if $opt_include_lang;
# Forcibly exclude .svn, .cvs, .hg, .git, .bzr directories. The contents of these
# directories often conflict with files of interest.
$opt_exclude_dir = 1;
$Exclude_Dir{".svn"} = 1;
$Exclude_Dir{".cvs"} = 1;
$Exclude_Dir{".hg"} = 1;
$Exclude_Dir{".git"} = 1;
$Exclude_Dir{".bzr"} = 1;
$Exclude_Dir{".snapshot"} = 1; # NetApp backups
$Exclude_Dir{".config"} = 1;
$opt_count_diff = defined $opt_count_diff ? 1 : 0;
$opt_diff = 1 if $opt_diff_alignment or
$opt_diff_list_file or
$opt_git_diff_rel or
$opt_git_diff_all or
$opt_git_diff_simindex;
$opt_force_git = 1 if $opt_git_diff_rel or
$opt_git_diff_all or
$opt_git_diff_simindex;
$opt_diff_alignment = 0 if $opt_diff_list_file;
$opt_exclude_ext = "" unless $opt_exclude_ext;
$opt_ignore_whitespace = 0 unless $opt_ignore_whitespace;
$opt_ignore_case = 0 unless $opt_ignore_case;
$opt_ignore_case_ext = 0 unless $opt_ignore_case_ext;
$opt_lang_no_ext = 0 unless $opt_lang_no_ext;
$opt_follow_links = 0 unless $opt_follow_links;
if (defined $opt_diff_timeout) {
# if defined but with a value of <= 0, set to 2^31 seconds = 68 years
$opt_diff_timeout = 2**31 unless $opt_diff_timeout > 0;
} else {
$opt_diff_timeout =10; # seconds
}
if (defined $opt_timeout) {
# if defined but with a value of <= 0, set to 2^31 seconds = 68 years
$opt_timeout = 2**31 unless $opt_timeout > 0;
# else is computed dynamically, ref $max_duration_sec
}
$opt_csv = 1 if $opt_csv_delimiter;
$ON_WINDOWS = 1 if $opt_force_on_windows;
$ON_WINDOWS = 0 if $opt_force_on_unix;
$opt_max_file_size = 100 unless $opt_max_file_size;
my $HAVE_SLOCCOUNT_c_count = 0;
if (!$ON_WINDOWS and $opt_use_sloccount) {
# Only bother doing this kludgey test is user explicitly wants
# to use SLOCCount. Debian based systems will hang if just doing
# external_utility_exists("c_count")
# if c_count is in $PATH; c_count expects to have input.
$HAVE_SLOCCOUNT_c_count = external_utility_exists("c_count /bin/sh");
}
if ($opt_use_sloccount) {
if (!$HAVE_SLOCCOUNT_c_count) {
warn "c_count could not be found; ignoring --use-sloccount\n";
$opt_use_sloccount = 0;
} else {
warn "Using c_count, php_count, xml_count, pascal_count from SLOCCount\n";
warn "--diff is disabled with --use-sloccount\n" if $opt_diff;
warn "--count-and-diff is disabled with --use-sloccount\n" if $opt_count_diff;
warn "--unicode is disabled with --use-sloccount\n" if $opt_unicode;
warn "--strip-comments is disabled with --use-sloccount\n" if $opt_strip_comments;
$opt_diff = 0;
$opt_count_diff = undef;
$opt_unicode = 0;
$opt_strip_comments = 0;
}
}
$opt_vcs = 0 if $opt_force_git;
my @COUNT_DIFF_ARGV = undef;
my $COUNT_DIFF_report_file = undef;
if ($opt_count_diff and !$opt_diff_list_file) {
die "--count-and-diff requires two arguments; got ", scalar @ARGV, "\n"
if scalar @ARGV != 2;
# prefix with a dummy term so that $opt_count_diff is the
# index into @COUNT_DIFF_ARGV to work on at each pass
@COUNT_DIFF_ARGV = (undef, $ARGV[0],
$ARGV[1],
[$ARGV[0], $ARGV[1]]); # 3rd pass: diff them
$COUNT_DIFF_report_file = $opt_report_file if $opt_report_file;
}
# Options defaults:
$opt_quiet = 1 if ($opt_md or $opt_json) and !defined $opt_report_file;
$opt_progress_rate = 100 unless defined $opt_progress_rate;
$opt_progress_rate = 0 if defined $opt_quiet;
if (!defined $opt_v) {
$opt_v = 0;
} elsif (!$opt_v) {
$opt_v = 1;
}
if (defined $opt_xsl) {
$opt_xsl = $CLOC_XSL if $opt_xsl eq "1";
$opt_xml = 1;
}
my $skip_generate_report = 0;
$opt_sql_style = 0 unless defined $opt_sql_style;
$opt_sql = 0 unless $opt_sql_style or defined $opt_sql;
if ($opt_sql eq "-" || $opt_sql eq "1") { # stream SQL output to STDOUT
$opt_quiet = 1;
$skip_generate_report = 1;
$opt_by_file = 1;
$opt_sum_reports = 0;
$opt_progress_rate = 0;
} elsif ($opt_sql) { # write SQL output to a file
$opt_by_file = 1;
$skip_generate_report = 1;
$opt_sum_reports = 0;
}
if ($opt_sql_style) {
$opt_sql_style = lc $opt_sql_style;
if (!grep { lc $_ eq $opt_sql_style } qw ( Oracle Named_Columns )) {
die "'$opt_sql_style' is not a recognized SQL style.\n";
}
}
$opt_by_percent = '' unless defined $opt_by_percent;
if ($opt_by_percent and $opt_by_percent !~ m/^(c|cm|cb|cmb)$/i) {
die "--by-percent must be either 'c', 'cm', 'cb', or 'cmb'\n";
}
$opt_by_percent = lc $opt_by_percent;
if (defined $opt_vcs) {
if ($opt_vcs eq "auto") {
if (-d ".git") {
$opt_vcs = "git";
} elsif (-d ".svn") {
$opt_vcs = "svn";
} else {
warn "--vcs auto: unable to determine versioning system\n";
}
}
if ($opt_vcs eq "git") {
$opt_vcs = "git ls-files";
my @submodules = invoke_generator('git submodule status');
foreach my $SM (@submodules) {
$SM =~ s/^\s+//; # may have leading space
$SM =~ s/\(\S+\)\s*$//; # may end with something like (heads/master)
my ($checksum, $dir) = split(' ', $SM, 2);
$dir =~ s/\s+$//;
$Exclude_Dir{$dir} = 1;
}
} elsif ($opt_vcs eq "svn") {
$opt_vcs = "svn list -R";
}
}
my $list_no_autogen = 0;
if (defined $opt_no_autogen and scalar @ARGV == 1 and $ARGV[0] eq "list") {
$list_no_autogen = 1;
}
die $brief_usage unless defined $opt_version or
defined $opt_show_lang or
defined $opt_show_ext or
defined $opt_show_os or
defined $opt_write_lang_def or
defined $opt_write_lang_def_incl_dup or
defined $opt_list_file or
defined $opt_diff_list_file or
defined $opt_vcs or
defined $opt_xsl or
defined $opt_explain or
$list_no_autogen or
scalar @ARGV >= 1;
if (!$opt_diff_list_file) {
die "--diff requires two arguments; got ", scalar @ARGV, "\n"
if $opt_diff and !$opt_sum_reports and scalar @ARGV != 2;
die "--diff arguments are identical; nothing done", "\n"
if $opt_diff and !$opt_sum_reports and scalar @ARGV == 2
and $ARGV[0] eq $ARGV[1];
}
trick_pp_packer_encode() if $ON_WINDOWS and $opt_file_encoding;
$File::Find::dont_use_nlink = 1 if $opt_stat or top_level_SMB_dir(\@ARGV);
my @git_similarity = (); # only populated with --git-diff-simindex
replace_git_hash_with_tarfile(\@ARGV, \@git_similarity);
# 1}}}
# Step 1: Initialize global constants. {{{1
#
my $nFiles_Found = 0; # updated in make_file_list
my (%Language_by_Extension, %Language_by_Script,
%Filters_by_Language, %Not_Code_Extension, %Not_Code_Filename,
%Language_by_File, %Scale_Factor, %Known_Binary_Archives,
%EOL_Continuation_re,
);
my $ALREADY_SHOWED_HEADER = 0;
my $ALREADY_SHOWED_XML_SECTION = 0;
my %Error_Codes = ( 'Unable to read' => -1,
'Neither file nor directory' => -2,
'Diff error (quoted comments?)' => -3,
'Diff error, exceeded timeout' => -4,
'Line count, exceeded timeout' => -5,
);
my %Extension_Collision = (
'ADSO/IDSM' => [ 'adso' ] ,
'C#/Smalltalk' => [ 'cs' ] ,
'D/dtrace' => [ 'd' ] ,
'F#/Forth' => [ 'fs' ] ,
'Fortran 77/Forth' => [ 'f', 'for' ] ,
'IDL/Qt Project/Prolog/ProGuard' => [ 'pro' ] ,
'Lisp/Julia' => [ 'jl' ] ,
'Lisp/OpenCL' => [ 'cl' ] ,
'MATLAB/Mathematica/Objective C/MUMPS/Mercury' => [ 'm' ] ,
'Pascal/Puppet' => [ 'pp' ] ,
'Perl/Prolog' => [ 'pl', 'PL' ] ,
'PHP/Pascal' => [ 'inc' ] ,
'Raku/Prolog' => [ 'p6', 'P6' ] ,
'Qt/Glade' => [ 'ui' ] ,
'TypeScript/Qt Linguist' => [ 'ts' ] ,
'Verilog-SystemVerilog/Coq' => [ 'v' ] ,
'Visual Basic/TeX/Apex Class' => [ 'cls' ] ,
'Scheme/SaltStack' => [ 'sls' ] ,
);
my @Autogen_to_ignore = no_autogen_files($list_no_autogen);
if ($opt_force_lang_def) {
# replace cloc's definitions
read_lang_def(
$opt_force_lang_def , # Sample values:
\%Language_by_Extension, # Language_by_Extension{f} = 'Fortran 77'
\%Language_by_Script , # Language_by_Script{sh} = 'Bourne Shell'
\%Language_by_File , # Language_by_File{makefile} = 'make'
\%Filters_by_Language , # Filters_by_Language{Bourne Shell}[0] =
# [ 'remove_matches' , '^\s*#' ]
\%Not_Code_Extension , # Not_Code_Extension{jpg} = 1
\%Not_Code_Filename , # Not_Code_Filename{README} = 1
\%Scale_Factor , # Scale_Factor{Perl} = 4.0
\%EOL_Continuation_re , # EOL_Continuation_re{C++} = '\\$'
);
} else {
set_constants( #
\%Language_by_Extension, # Language_by_Extension{f} = 'Fortran 77'
\%Language_by_Script , # Language_by_Script{sh} = 'Bourne Shell'
\%Language_by_File , # Language_by_File{makefile} = 'make'
\%Filters_by_Language , # Filters_by_Language{Bourne Shell}[0] =
# [ 'remove_matches' , '^\s*#' ]
\%Not_Code_Extension , # Not_Code_Extension{jpg} = 1
\%Not_Code_Filename , # Not_Code_Filename{README} = 1
\%Scale_Factor , # Scale_Factor{Perl} = 4.0
\%Known_Binary_Archives, # Known_Binary_Archives{.tar} = 1
\%EOL_Continuation_re , # EOL_Continuation_re{C++} = '\\$'
);
if ($opt_no_autogen) {
foreach my $F (@Autogen_to_ignore) { $Not_Code_Filename{ $F } = 1; }
}
}
if ($opt_read_lang_def) {
# augment cloc's definitions (keep cloc's where there are overlaps)
merge_lang_def(
$opt_read_lang_def , # Sample values:
\%Language_by_Extension, # Language_by_Extension{f} = 'Fortran 77'
\%Language_by_Script , # Language_by_Script{sh} = 'Bourne Shell'
\%Language_by_File , # Language_by_File{makefile} = 'make'
\%Filters_by_Language , # Filters_by_Language{Bourne Shell}[0] =
# [ 'remove_matches' , '^\s*#' ]
\%Not_Code_Extension , # Not_Code_Extension{jpg} = 1
\%Not_Code_Filename , # Not_Code_Filename{README} = 1
\%Scale_Factor , # Scale_Factor{Perl} = 4.0
\%EOL_Continuation_re , # EOL_Continuation_re{C++} = '\\$'
);
}
if ($opt_lang_no_ext and !defined $Filters_by_Language{$opt_lang_no_ext}) {
die_unknown_lang($opt_lang_no_ext, "--lang-no-ext")
}
check_scale_existence(\%Filters_by_Language, \%Language_by_Extension,
\%Scale_Factor);
my $nCounted = 0;
# Process command line provided extension-to-language mapping overrides.
# Make a hash of known languages in lower case for easier matching.
my %Recognized_Language_lc = (); # key = language name in lc, value = true name
foreach my $language (keys %Filters_by_Language) {
my $lang_lc = lc $language;
$Recognized_Language_lc{$lang_lc} = $language;
}
my %Forced_Extension = (); # file name extensions which user wants to count
my $All_One_Language = 0; # set to !0 if --force-lang's <ext> is missing
foreach my $pair (@opt_force_lang) {
my ($lang, $extension) = split(',', $pair);
my $lang_lc = lc $lang;
if (defined $extension) {
$Forced_Extension{$extension} = $lang;
die_unknown_lang($lang, "--force-lang")
unless $Recognized_Language_lc{$lang_lc};
$Language_by_Extension{$extension} = $Recognized_Language_lc{$lang_lc};
} else {
# the scary case--count everything as this language
$All_One_Language = $Recognized_Language_lc{$lang_lc};
}
}
foreach my $pair (@opt_script_lang) {
my ($lang, $script_name) = split(',', $pair);
my $lang_lc = lc $lang;
if (!defined $script_name) {
die "The --script-lang option requires a comma separated pair of ".
"strings.\n";
}
die_unknown_lang($lang, "--script-lang")
unless $Recognized_Language_lc{$lang_lc};
$Language_by_Script{$script_name} = $Recognized_Language_lc{$lang_lc};
}
# If user provided file extensions to ignore, add these to
# the exclusion list.
foreach my $ext (map { $_ => 1 } split(/,/, $opt_exclude_ext ) ) {
$ext = lc $ext if $ON_WINDOWS or $opt_ignore_case_ext;
$Not_Code_Extension{$ext} = 1;
}
# If SQL or --by-file output is requested, keep track of directory names
# generated by File::Temp::tempdir and used to temporarily hold the results
# of compressed archives. Contents of the SQL table 't' will be much
# cleaner if these meaningless directory names are stripped from the front
# of files pulled from the archives.
my %TEMP_DIR = ();
my $TEMP_OFF = 0; # Needed for --sdir; keep track of the number of
# scratch directories made in this run to avoid
# file overwrites by multiple extractions to same
# sdir.
# Also track locations where temporary installations, if necessary, of
# Algorithm::Diff and/or Regexp::Common are done. Make sure these
# directories are not counted as inputs (ref bug #80 2012-11-23).
my %TEMP_INST = ();
# invert %Language_by_Script hash to get an easy-to-look-up list of known
# scripting languages
my %Script_Language = map { $_ => 1 } values %Language_by_Script ;
# 1}}}
# Step 2: Early exits for display, summation. {{{1
#
print_extension_info( $opt_show_ext ) if defined $opt_show_ext ;
print_language_info( $opt_show_lang, '') if defined $opt_show_lang;
print_language_filters( $opt_explain ) if defined $opt_explain ;
exit if (defined $opt_show_ext) or
(defined $opt_show_lang) or
(defined $opt_explain) or
$list_no_autogen;
Top_of_Processing_Loop:
# Sorry, coding purists. Using a goto to implement --count-and-diff
# which has to do three passes over the main code, starting with
# a clean slate each time.
if ($opt_count_diff) {
@ARGV = ( $COUNT_DIFF_ARGV[ $opt_count_diff ] );
if ($opt_count_diff == 3) {
$opt_diff = 1;
@ARGV = @{$COUNT_DIFF_ARGV[ $opt_count_diff ]}; # last arg is list of list
}
if ($opt_report_file) {
# Instead of just one output file, will have three.
# Keep their names unique otherwise results are clobbered.
# Replace file path separators with underscores otherwise
# may end up with illegal file names.
my ($fn_0, $fn_1) = (undef, undef);
if ($ON_WINDOWS) {
($fn_0 = $ARGV[0]) =~ s{\\}{_}g;
$fn_0 =~ s{::}{_}g;
($fn_1 = $ARGV[1]) =~ s{\\}{_}g if defined $ARGV[1];
$fn_1 =~ s{::}{_}g if defined $ARGV[1];
} else {
($fn_0 = $ARGV[0]) =~ s{/}{_}g;
($fn_1 = $ARGV[1]) =~ s{/}{_}g if defined $ARGV[1];
}
if ($opt_count_diff == 3) {
$opt_report_file = $COUNT_DIFF_report_file . ".diff.$fn_0.$fn_1";
} else {
$opt_report_file = $COUNT_DIFF_report_file . "." . $fn_0;
}
} else {
# STDOUT; print a header showing what it's working on
if ($opt_count_diff == 3) {
print "\ndiff $ARGV[0] $ARGV[1]::\n";
} else {
print "\n" if $opt_count_diff > 1;
print "$ARGV[0]::\n";
}
}
$ALREADY_SHOWED_HEADER = 0;
$ALREADY_SHOWED_XML_SECTION = 0;
}
#print "Before glob have [", join(",", @ARGV), "]\n";
@ARGV = windows_glob(@ARGV) if $ON_WINDOWS;
#print "after glob have [", join(",", @ARGV), "]\n";
# filter out archive files if requested to do so
if (defined $opt_skip_archive) {
my @non_archive = ();
foreach my $candidate (@ARGV) {
if ($candidate !~ m/${opt_skip_archive}$/) {
push @non_archive, $candidate;
}
}
@ARGV = @non_archive;
}
if ($opt_sum_reports and $opt_diff) {
my @results = ();
if ($opt_list_file) { # read inputs from the list file
my @list = read_list_file($opt_list_file);
@results = combine_diffs(\@list);
} elsif ($opt_vcs) { # read inputs from the VCS generator
my @list = invoke_generator($opt_vcs, \@ARGV);
@results = combine_diffs(\@list);
} else { # get inputs from the command line
@results = combine_diffs(\@ARGV);
}
if ($opt_report_file) {
write_file($opt_report_file, {}, @results);
} else {
print "\n", join("\n", @results), "\n";
}
exit;
}
if ($opt_sum_reports) {
my %Results = ();
foreach my $type( "by language", "by report file" ) {
my $found_lang = undef;
if ($opt_list_file or $opt_vcs) {
# read inputs from the list file
my @list;
if ($opt_vcs) {
@list = invoke_generator($opt_vcs, \@ARGV);
} else {
@list = read_list_file($opt_list_file);
}
$found_lang = combine_results(\@list,
$type,
\%{$Results{ $type }},
\%Filters_by_Language );
} else { # get inputs from the command line
$found_lang = combine_results(\@ARGV,
$type,
\%{$Results{ $type }},
\%Filters_by_Language );
}
next unless %Results;
my $end_time = get_time();
my @results = generate_report($VERSION, $end_time - $start_time,
$type,
\%{$Results{ $type }}, \%Scale_Factor);
if ($opt_report_file) {
my $ext = ".lang";
$ext = ".file" unless $type eq "by language";
next if !$found_lang and $ext eq ".lang";
write_file($opt_report_file . $ext, {}, @results);
} else {
print "\n", join("\n", @results), "\n";
}
}
exit;
}
if ($opt_write_lang_def or $opt_write_lang_def_incl_dup) {
my $file = $opt_write_lang_def if $opt_write_lang_def;
$file = $opt_write_lang_def_incl_dup if $opt_write_lang_def_incl_dup;
write_lang_def($file ,
\%Language_by_Extension,
\%Language_by_Script ,
\%Language_by_File ,
\%Filters_by_Language ,
\%Not_Code_Extension ,
\%Not_Code_Filename ,
\%Scale_Factor ,
\%EOL_Continuation_re ,
);
exit;
}
if ($opt_show_os) {
if ($ON_WINDOWS) {
print "Windows\n";
} else {
print "UNIX\n";
}
exit;
}
my $max_processes = get_max_processes();
# 1}}}
# Step 3: Create a list of files to consider. {{{1
# a) If inputs are binary archives, first cd to a temp
# directory, expand the archive with the user-given
# extraction tool, then add the temp directory to
# the list of dirs to process.
# b) Create a list of every file that might contain source
# code. Ignore binary files, zero-sized files, and
# any file in a directory the user says to exclude.
# c) Determine the language for each file in the list.
#
my @binary_archive = ();
my $cwd = cwd();
if ($opt_extract_with) {
#print "cwd main = [$cwd]\n";
my @extract_location = ();
foreach my $bin_file (@ARGV) {
my $extract_dir = undef;
if ($opt_sdir) {
++$TEMP_OFF;
$extract_dir = "$opt_sdir/$TEMP_OFF";
File::Path::rmtree($extract_dir) if is_dir($extract_dir);
File::Path::mkpath($extract_dir) unless is_dir($extract_dir);
} else {
$extract_dir = tempdir( CLEANUP => 1 ); # 1 = delete on exit
}
$TEMP_DIR{ $extract_dir } = 1 if $opt_sql or $opt_by_file;
print "mkdir $extract_dir\n" if $opt_v;
print "cd $extract_dir\n" if $opt_v;
chdir $extract_dir;
my $bin_file_full_path = "";
if (File::Spec->file_name_is_absolute( $bin_file )) {
$bin_file_full_path = $bin_file;
#print "bin_file_full_path (was ful) = [$bin_file_full_path]\n";
} else {
$bin_file_full_path = File::Spec->catfile( $cwd, $bin_file );
#print "bin_file_full_path (was rel) = [$bin_file_full_path]\n";
}
my $extract_cmd = uncompress_archive_cmd($bin_file_full_path);
print $extract_cmd, "\n" if $opt_v;
system $extract_cmd;
push @extract_location, $extract_dir;
chdir $cwd;
}
# It is possible that the binary archive itself contains additional
# files compressed the same way (true for Java .ear files). Go
# through all the files that were extracted, see if they are binary
# archives and try to extract them. Lather, rinse, repeat.
my $binary_archives_exist = 1;
my $count_binary_archives = 0;
my $previous_count = 0;
my $n_pass = 0;
while ($binary_archives_exist) {
@binary_archive = ();
foreach my $dir (@extract_location) {
find(\&archive_files, $dir); # populates global @binary_archive
}
foreach my $archive (@binary_archive) {
my $extract_dir = undef;
if ($opt_sdir) {
++$TEMP_OFF;
$extract_dir = "$opt_sdir/$TEMP_OFF";
File::Path::rmtree($extract_dir) if is_dir($extract_dir);
File::Path::mkpath($extract_dir) unless is_dir($extract_dir);
} else {
$extract_dir = tempdir( CLEANUP => 1 ); # 1 = delete on exit
}
$TEMP_DIR{ $extract_dir } = 1 if $opt_sql or $opt_by_file;
print "mkdir $extract_dir\n" if $opt_v;
print "cd $extract_dir\n" if $opt_v;
chdir $extract_dir;
my $extract_cmd = uncompress_archive_cmd($archive);
print $extract_cmd, "\n" if $opt_v;
system $extract_cmd;
push @extract_location, $extract_dir;
unlink $archive; # otherwise will be extracting it forever
}
$count_binary_archives = scalar @binary_archive;
if ($count_binary_archives == $previous_count) {
$binary_archives_exist = 0;
}
$previous_count = $count_binary_archives;
}
chdir $cwd;
@ARGV = @extract_location;
} else {
# see if any of the inputs need to be auto-uncompressed &/or expanded
my @updated_ARGS = ();
replace_git_hash_with_tarfile(\@ARGV, \@git_similarity) if $opt_force_git;
foreach my $Arg (@ARGV) {
if (is_dir($Arg)) {
push @updated_ARGS, $Arg;
next;
}
my $full_path = "";
if (File::Spec->file_name_is_absolute( $Arg )) {
$full_path = $Arg;
} else {
$full_path = File::Spec->catfile( $cwd, $Arg );
}
#print "full_path = [$full_path]\n";
my $extract_cmd = uncompress_archive_cmd($full_path);
if ($extract_cmd) {
my $extract_dir = undef;
if ($opt_sdir) {
++$TEMP_OFF;
$extract_dir = "$opt_sdir/$TEMP_OFF";
File::Path::rmtree($extract_dir) if is_dir($extract_dir);
File::Path::mkpath($extract_dir) unless is_dir($extract_dir);
} else {
$extract_dir = tempdir( CLEANUP => 1 ); # 1 = delete on exit
}
$TEMP_DIR{ $extract_dir } = 1 if $opt_sql or $opt_by_file;
print "mkdir $extract_dir\n" if $opt_v;
print "cd $extract_dir\n" if $opt_v;
chdir $extract_dir;
print $extract_cmd, "\n" if $opt_v;
system $extract_cmd;
push @updated_ARGS, $extract_dir;
chdir $cwd;
} else {
# this is a conventional, uncompressed, unarchived file
# or a directory; keep as-is
push @updated_ARGS, $Arg;
}
}
@ARGV = @updated_ARGS;
# make sure we're not counting any directory containing
# temporary installations of Regexp::Common, Algorithm::Diff
foreach my $d (sort keys %TEMP_INST) {
foreach my $a (@ARGV) {
next unless is_dir($a);
if ($opt_v > 2) {
printf "Comparing %s (location of %s) to input [%s]\n",
$d, $TEMP_INST{$d}, $a;
}
if ($a eq $d) {
die "File::Temp::tempdir chose directory ",
$d, " to install ", $TEMP_INST{$d}, " but this ",
"matches one of your input directories. Rerun ",
"with --sdir and supply a different temporary ",
"directory for ", $TEMP_INST{$d}, "\n";
}
}
}
}
# 1}}}
my @Errors = ();
my @file_list = (); # global variable updated in files()
my %Ignored = (); # files that are not counted (language not recognized or
# problems reading the file)
my @Lines_Out = ();
if ($opt_diff) {
# Step 4: Separate code from non-code files. {{{1
my @fh = ();
my @files_for_set = ();
my @files_added_tot = ();
my @files_removed_tot = ();
my @file_pairs_tot = ();
# make file lists for each separate argument
if ($opt_diff_list_file) {
@files_for_set = ( (), () );
file_pairs_from_file($opt_diff_list_file, # in
\@files_added_tot , # out
\@files_removed_tot , # out
\@file_pairs_tot , # out
);
foreach my $F (@files_added_tot) {
push @{$files_for_set[1]}, $F;
}
foreach my $F (@files_removed_tot) {
push @{$files_for_set[0]}, $F;
}
foreach my $pair (@file_pairs_tot) {
push @{$files_for_set[0]}, $pair->[0];
push @{$files_for_set[1]}, $pair->[1];
}
@ARGV = (1, 2); # place holders
}
for (my $i = 0; $i < scalar @ARGV; $i++) {
if ($opt_diff_list_file) {
push @fh, make_file_list($files_for_set[$i],
\%Error_Codes, \@Errors, \%Ignored);
@{$files_for_set[$i]} = @file_list;
} else {
push @fh, make_file_list([ $ARGV[$i] ],
\%Error_Codes, \@Errors, \%Ignored);
@{$files_for_set[$i]} = @file_list;
}
if ($opt_exclude_list_file) {
# note: process_exclude_list_file() references global @file_list
process_exclude_list_file($opt_exclude_list_file,
\%Exclude_Dir,
\%Ignored);
}
if ($opt_no_autogen) {
exclude_autogenerated_files(\@{$files_for_set[$i]}, # in/out
\%Error_Codes, \@Errors, \%Ignored);
}
@file_list = ();
}
# 1}}}
# Step 5: Remove duplicate files. {{{1
#
my %Language = ();
my %unique_source_file = ();
my $n_set = 0;
foreach my $FH (@fh) { # loop over each pair of file sets
++$n_set;
remove_duplicate_files($FH,
\%{$Language{$FH}} ,
\%{$unique_source_file{$FH}} ,
\%Error_Codes ,
\@Errors ,
\%Ignored );
if ($opt_exclude_content) {
exclude_by_regex($opt_exclude_content, # in
\%{$unique_source_file{$FH}}, # in/out
\%Ignored); # out
}
if ($opt_include_lang) {
# remove files associated with languages not
# specified by --include-lang
my @delete_file = ();
foreach my $file (keys %{$unique_source_file{$FH}}) {
my $keep_file = 0;
foreach my $keep_lang (keys %Include_Language) {
if ($Language{$FH}{$file} eq $keep_lang) {
$keep_file = 1;
last;
}
}
next if $keep_file;
push @delete_file, $file;
}
foreach my $file (@delete_file) {
delete $Language{$FH}{$file};
}
}
printf "%2d: %8d unique file%s. \r",
$n_set,
plural_form(scalar keys %unique_source_file)
unless $opt_quiet;
}
# 1}}}
# Step 6: Count code, comments, blank lines. {{{1
#
my %Results_by_Language = ();
my %Results_by_File = ();
my %Delta_by_Language = ();
my %Delta_by_File = ();
my %alignment = ();
my $fset_a = $fh[0];
my $fset_b = $fh[1];
my $n_filepairs_compared = 0;
my $tot_counted = 0;
if ( scalar @fh != 2 ) {
print "Error: incorrect length fh array when preparing diff at step 6.\n";
exit 1;
}
if (!$opt_diff_list_file) {
align_by_pairs(\%{$unique_source_file{$fset_a}} , # in
\%{$unique_source_file{$fset_b}} , # in
\@files_added_tot , # out
\@files_removed_tot , # out
\@file_pairs_tot , # out
);
}
#use Data::Dumper;
#print "added : ", Dumper(\@files_added_tot);
#print "removed : ", Dumper(\@files_removed_tot);
#print "pairs : ", Dumper(\@file_pairs_tot);
if ( $max_processes == 0) {
# Multiprocessing is disabled
my $part = count_filesets ( $fset_a, $fset_b, \@files_added_tot,
\@files_removed_tot, \@file_pairs_tot,
0, \%Language, \%Ignored);
%Results_by_File = %{$part->{'results_by_file'}};
%Results_by_Language= %{$part->{'results_by_language'}};
%Delta_by_File = %{$part->{'delta_by_file'}};
%Delta_by_Language= %{$part->{'delta_by_language'}};
%Ignored = ( %Ignored, %{$part->{'ignored'}});
%alignment = %{$part->{'alignment'}};
$n_filepairs_compared = $part->{'n_filepairs_compared'};
push ( @Errors, @{$part->{'errors'}});
} else {
# Multiprocessing is enabled
# Do not create more processes than the amount of data to be processed
my $num_processes = min(max(scalar @files_added_tot,
scalar @files_removed_tot,
scalar @file_pairs_tot),
$max_processes);
# ... but use at least one process.
$num_processes = 1
if $num_processes == 0;
# Start processes for counting
my $pm = Parallel::ForkManager->new($num_processes);
# When processes finish, they will use the embedded subroutine for
# merging the data into global variables.
$pm->run_on_finish ( sub {
my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $part) = @_;
my $part_ignored = $part->{'ignored'};
my $part_result_by_file = $part->{'results_by_file'};
my $part_result_by_language = $part->{'results_by_language'};
my $part_delta_by_file = $part->{'delta_by_file'};
my $part_delta_by_language = $part->{'delta_by_language'};
my $part_alignment = $part->{'alignment'};
my $part_errors = $part->{'errors'};
$tot_counted += scalar keys %$part_result_by_file;
$n_filepairs_compared += $part->{'n_filepairs_compared'};
# Since files are processed by multiple processes, we can't measure
# the number of processed files exactly. We approximate this by showing
# the number of files counted by finished processes.
printf "Counting: %d\r", $tot_counted
if $opt_progress_rate;
foreach my $this_language ( keys %$part_result_by_language ) {
my $counts = $part_result_by_language->{$this_language};
foreach my $inner_key ( keys %$counts ) {
$Results_by_Language{$this_language}{$inner_key} +=
$counts->{$inner_key};
}
}
foreach my $this_language ( keys %$part_delta_by_language ) {
my $counts = $part_delta_by_language->{$this_language};
foreach my $inner_key ( keys %$counts ) {
my $statuses = $counts->{$inner_key};
foreach my $inner_status ( keys %$statuses ) {
$Delta_by_Language{$this_language}{$inner_key}{$inner_status} +=
$counts->{$inner_key}->{$inner_status};
}
}
}
foreach my $label ( keys %$part_alignment ) {
my $inner = $part_alignment->{$label};
foreach my $key ( keys %$inner ) {
$alignment{$label}{$key} = 1;
}
}
%Results_by_File = ( %Results_by_File, %$part_result_by_file );
%Delta_by_File = ( %Delta_by_File, %$part_delta_by_file );
%Ignored = (%Ignored, %$part_ignored );
push ( @Errors, @$part_errors );
} );
my $num_filepairs_per_part = ceil ( ( scalar @file_pairs_tot ) / $num_processes );
my $num_filesremoved_per_part = ceil ( ( scalar @files_removed_tot ) / $num_processes );
my $num_filesadded_per_part = ceil ( ( scalar @files_added_tot ) / $num_processes );
while ( 1 ) {
my @files_added_part = splice @files_added_tot, 0, $num_filesadded_per_part;
my @files_removed_part = splice @files_removed_tot, 0, $num_filesremoved_per_part;
my @filepairs_part = splice @file_pairs_tot, 0, $num_filepairs_per_part;
if ( scalar @files_added_part == 0 and scalar @files_removed_part == 0 and
scalar @filepairs_part == 0 ) {
last;
}
$pm->start() and next;
my $count_result = count_filesets ( $fset_a, $fset_b,
\@files_added_part, \@files_removed_part,
\@filepairs_part, 1, \%Language, \%Ignored );
$pm->finish(0 , $count_result);
}
# Wait for processes to finish
$pm->wait_all_children();
}
# Write alignment data, if needed
if ($opt_diff_alignment) {
write_alignment_data ( $opt_diff_alignment, $n_filepairs_compared, \%alignment ) ;
}
my @ignored_reasons = map { "$_: $Ignored{$_}" } sort keys %Ignored;
write_file($opt_ignored, {"file_type" => "ignored",
"separator" => ": ",
"columns" => ["file", "reason"],
}, @ignored_reasons ) if $opt_ignored;
write_file($opt_counted, {}, sort keys %Results_by_File) if $opt_counted;
# 1}}}
# Step 7: Assemble results. {{{1
#
my $end_time = get_time();
printf "%8d file%s ignored. \n",
plural_form(scalar keys %Ignored) unless $opt_quiet;
print_errors(\%Error_Codes, \@Errors) if @Errors;
if (!%Delta_by_Language) {
print "Nothing to count.\n";
exit;
}
if ($opt_by_file) {
@Lines_Out = diff_report($VERSION, get_time() - $start_time,
"by file",
\%Delta_by_File, \%Scale_Factor);
} else {
@Lines_Out = diff_report($VERSION, get_time() - $start_time,
"by language",
\%Delta_by_Language, \%Scale_Factor);
}
# 1}}}
} else {
# Step 4: Separate code from non-code files. {{{1
my $fh = 0;
if ($opt_list_file or $opt_vcs) {
my @list;
if ($opt_vcs) {
@list = invoke_generator($opt_vcs, \@ARGV);
} else {
@list = read_list_file($opt_list_file);
}
$fh = make_file_list(\@list, \%Error_Codes, \@Errors, \%Ignored);
} else {
$fh = make_file_list(\@ARGV, \%Error_Codes, \@Errors, \%Ignored);
# make_file_list populates global variable @file_list via call to
# File::Find's find() which in turn calls files()
}
if ($opt_exclude_list_file) {
# note: process_exclude_list_file() references global @file_list
process_exclude_list_file($opt_exclude_list_file,
\%Exclude_Dir,
\%Ignored);
}
if ($opt_skip_win_hidden and $ON_WINDOWS) {
my @file_list_minus_hidded = ();
# eval code to run on Unix without 'missing Win32::File module' error.
my $win32_file_invocation = '
use Win32::File;
foreach my $F (@file_list) {
my $attr = undef;
Win32::File::GetAttributes($F, $attr);
if ($attr & HIDDEN) {
$Ignored{$F} = "Windows hidden file";
print "Ignoring $F since it is a Windows hidden file\n"
if $opt_v > 1;
} else {
push @file_list_minus_hidded, $F;
}
}';
eval $win32_file_invocation;
@file_list = @file_list_minus_hidded;
}
if ($opt_no_autogen) {
exclude_autogenerated_files(\@file_list, # in/out
\%Error_Codes, \@Errors, \%Ignored);
}
#printf "%8d file%s excluded. \n",
# plural_form(scalar keys %Ignored)
# unless $opt_quiet;
# die print ": ", join("\n: ", @file_list), "\n";
# 1}}}
# Step 5: Remove duplicate files. {{{1
#
my %Language = ();
my %unique_source_file = ();
remove_duplicate_files($fh , # in
\%Language , # out
\%unique_source_file , # out
\%Error_Codes , # in
\@Errors , # out
\%Ignored ); # out
if ($opt_exclude_content) {
exclude_by_regex($opt_exclude_content, # in
\%unique_source_file , # in/out
\%Ignored); # out
}
printf "%8d unique file%s. \n",
plural_form(scalar keys %unique_source_file)
unless $opt_quiet;
# 1}}}
# Step 6: Count code, comments, blank lines. {{{1
#
my %Results_by_Language = ();
my %Results_by_File = ();
my @results_parts = ();
my @sorted_files = sort keys %unique_source_file;
if ( $max_processes == 0) {
# Multiprocessing is disabled
my $part = count_files ( \@sorted_files , 0, \%Language);
%Results_by_File = %{$part->{'results_by_file'}};
%Results_by_Language= %{$part->{'results_by_language'}};
%Ignored = ( %Ignored, %{$part->{'ignored'}});
push ( @Errors, @{$part->{'errors'}});
} else {
# Do not create more processes than the number of files to be processed
my $num_files = scalar @sorted_files;
my $num_processes = $num_files >= $max_processes ? $max_processes : $num_files;
# Use at least one process.
$num_processes = 1
if $num_processes == 0;
# Start processes for counting
my $pm = Parallel::ForkManager->new($num_processes);
# When processes finish, they will use the embedded subroutine for
# merging the data into global variables.
$pm->run_on_finish ( sub {
my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $part) = @_;
my $part_ignored = $part->{'ignored'};
my $part_result_by_file = $part->{'results_by_file'};
my $part_result_by_language = $part->{'results_by_language'};
my $part_errors = $part->{'errors'};
my $nCounted+= scalar keys %$part_result_by_file;
# Since files are processed by multiple processes, we can't measure
# the number of processed files exactly. We approximate this by showing
# the number of files counted by finished processes.
printf "Counting: %d\r", $nCounted
if $opt_progress_rate;
foreach my $this_language ( keys %$part_result_by_language ) {
my $counts = $part_result_by_language->{$this_language};
foreach my $inner_key ( keys %$counts ) {
$Results_by_Language{$this_language}{$inner_key} +=
$counts->{$inner_key};
}
}
%Results_by_File = ( %Results_by_File, %$part_result_by_file );
%Ignored = (%Ignored, %$part_ignored);
push ( @Errors, @$part_errors);
} );
my $num_files_per_part = ceil ( ( scalar @sorted_files ) / $num_processes );
while ( my @part = splice @sorted_files, 0 , $num_files_per_part ) {
$pm->start() and next;
my $count_result = count_files ( \@part, 1, \%Language );
$pm->finish(0 , $count_result);
}
# Wait for processes to finish
$pm->wait_all_children();
}
my @ignored_reasons = map { "$_: $Ignored{$_}" } sort keys %Ignored;
write_file($opt_ignored, {"file_type" => "ignored",
"separator" => ": ",
"columns" => ["file", "reason"],
}, @ignored_reasons ) if $opt_ignored;
write_file($opt_counted, {}, sort keys %Results_by_File) if $opt_counted;
# 1}}}
# Step 7: Assemble results. {{{1
#
my $end_time = get_time();
printf "%8d file%s ignored.\n", plural_form(scalar keys %Ignored)
unless $opt_quiet;
print_errors(\%Error_Codes, \@Errors) if @Errors;
exit unless %Results_by_Language;
generate_sql($end_time - $start_time,
\%Results_by_File, \%Scale_Factor) if $opt_sql;
exit if $skip_generate_report;
if ($opt_by_file_by_lang) {
push @Lines_Out, generate_report( $VERSION, $end_time - $start_time,
"by file",
\%Results_by_File, \%Scale_Factor);
push @Lines_Out, generate_report( $VERSION, $end_time - $start_time,
"by language",
\%Results_by_Language, \%Scale_Factor);
} elsif ($opt_by_file) {
push @Lines_Out, generate_report( $VERSION, $end_time - $start_time,
"by file",
\%Results_by_File, \%Scale_Factor);
} else {
push @Lines_Out, generate_report( $VERSION, $end_time - $start_time,
"by language",
\%Results_by_Language, \%Scale_Factor);
}
# 1}}}
}
if ($opt_report_file) { write_file($opt_report_file, {}, @Lines_Out); }
else { print "\n", join("\n", @Lines_Out), "\n"; }
if ($opt_count_diff) {
++$opt_count_diff;
exit if $opt_count_diff > 3;
goto Top_of_Processing_Loop;
}
sub exclude_by_regex { # {{{1
my ($regex,
$rh_unique_source_file, # in/out
$rh_ignored , # out
) = @_;
my @exclude = ();
foreach my $file (keys %{$rh_unique_source_file}) {
my $line_num = 0;
foreach my $line (read_file($file)) {
++$line_num;
if ($line =~ /$regex/) {
$rh_ignored->{$file} = "line $line_num match for --exclude-content=$regex";
push @exclude, $file;
last;
}
}
}
foreach my $file (@exclude) {
delete $rh_unique_source_file->{$file};
}
} # 1}}}
sub get_max_processes { # {{{1
# If user has specified valid number of processes, use that.
if (defined $opt_processes) {
eval "use Parallel::ForkManager 0.7.6;";
if ( defined $Parallel::ForkManager::VERSION ) {
$HAVE_Parallel_ForkManager = 1;
}
if ( $opt_processes !~ /^\d+$/ ) {
print "Error: processes option argument must be numeric.\n";
exit 1;
}
elsif ( $opt_processes >0 and ! $HAVE_Parallel_ForkManager ) {
print "Error: cannot use multiple processes, because " .
"Parallel::ForkManager is not installed, or the version is too old.\n";
exit 1;
}
elsif ( $opt_processes >0 and $ON_WINDOWS ) {
print "Error: cannot use multiple processes on Windows systems.\n";
exit 1;
}
else {
return $opt_processes;
}
}
# Disable multiprocessing on Windows - does not work reliably
if ($ON_WINDOWS) {
return 0;
}
# Disable multiprocessing if Parallel::ForkManager is not available
if ( ! $HAVE_Parallel_ForkManager ) {
return 0;
}
# Set to number of cores on Linux
if ( $^O =~ /linux/i and -x '/usr/bin/nproc' ) {
my $numavcores_linux = `/usr/bin/nproc`;
chomp $numavcores_linux;
if ( $numavcores_linux =~ /^\d+$/ ) {
return $numavcores_linux;
}
}
# Set to number of cores on MacOS
if ( $^O =~ /darwin/i and -x '/usr/sbin/sysctl') {
my $numavcores_macos = `/usr/sbin/sysctl -n hw.physicalcpu`;
chomp $numavcores_macos;
if ($numavcores_macos =~ /^\d+$/ ) {
return $numavcores_macos;
}
}
# Disable multiprocessing in other cases
return 0;
} # 1}}}
sub exclude_autogenerated_files { # {{{1
my ($ra_file_list, # in
$rh_Err , # in hash of error codes
$raa_errors , # out
$rh_Ignored , # out
) = @_;
print "-> exclude_autogenerated_files()\n" if $opt_v > 2;
my @file_list_minus_autogen = ();
foreach my $file (@{$ra_file_list}) {
if ($file !~ /\.go$/) {
# at the moment, only know Go autogenerated files
push @file_list_minus_autogen, $file;
next;
}
my $first_line = first_line($file, $rh_Err, $raa_errors);
if ($first_line =~ m{^//\s+Code\s+generated\s+.*?\s+DO\s+NOT\s+EDIT\.$}) {
$rh_Ignored->{$file} = 'Go autogenerated file';
} else {
# Go, but not autogenerated
push @file_list_minus_autogen, $file;
}
}
@{$ra_file_list} = @file_list_minus_autogen;
print "<- exclude_autogenerated_files()\n" if $opt_v > 2;
} # 1}}}
sub file_extension { # {{{1
my ($fname, ) = @_;
$fname =~ m/\.(\w+)$/;
if ($1) {
return $1;
} else {
return "";
}
} # 1}}}
sub count_files { # {{{1
my ($filelist, $counter_type, $language_hash) = @_;
print "-> count_files()\n" if $opt_v > 2;
my @p_errors = ();
my %p_ignored = ();
my %p_rbl = ();
my %p_rbf = ();
my %Language = %{$language_hash};
foreach my $file (@$filelist) {
if ( ! $counter_type ) {
# Multithreading disabled
$nCounted++;
printf "Counting: %d\r", $nCounted
unless (!$opt_progress_rate or ($nCounted % $opt_progress_rate));
}
next if $Ignored{$file};
if ($opt_include_ext and not $Include_Ext{ file_extension($file) }) {
$p_ignored{$file} = "not in --include-ext=$opt_include_ext";
next;
}
if ($opt_include_lang and not $Include_Language{$Language{$file}}) {
$p_ignored{$file} = "not in --include-lang=$opt_include_lang";
next;
}
if ($Exclude_Language{$Language{$file}}) {
$p_ignored{$file} = "--exclude-lang=$Language{$file}";
next;
}
my $Filters_by_Language_Language_file = ! @{$Filters_by_Language{$Language{$file}} };
if ($Filters_by_Language_Language_file) {
if ($Language{$file} eq "(unknown)") {
$p_ignored{$file} = "language unknown (#1)";
} else {
$p_ignored{$file} = "missing Filters_by_Language{$Language{$file}}";
}
next;
}
my ($all_line_count, $blank_count, $comment_count, $code_count);
if ($opt_use_sloccount and $Language{$file} =~ /^(C|C\+\+|XML|PHP|Pascal|Java)$/) {
chomp ($blank_count = `grep -cv \"[^[:space:]]\" '$file'`);
chomp ($all_line_count = `cat '$file' | wc -l`);
if ($Language{$file} =~ /^(C|C\+\+)$/) {
$code_count = `cat '$file' | c_count | head -n 1`;
} elsif ($Language{$file} eq "XML") {
$code_count = `cat '$file' | xml_count | head -n 1`;
} elsif ($Language{$file} eq "PHP") {
$code_count = `cat '$file' | php_count | head -n 1`;
} elsif ($Language{$file} eq "Pascal") {
$code_count = `cat '$file' | pascal_count | head -n 1`;
} elsif ($Language{$file} eq "Java") {
$code_count = `cat '$file' | java_count | head -n 1`;
} else {
die "SLOCCount match failure: file=[$file] lang=[$Language{$file}]";
}
$code_count = substr($code_count, 0, -2);
$comment_count = $all_line_count - $code_count - $blank_count;
} else {
($all_line_count,
$blank_count ,
$comment_count ,) = call_counter($file, $Language{$file}, \@Errors);
$code_count = $all_line_count - $blank_count - $comment_count;
}
if ($opt_by_file) {
$p_rbf{$file}{'code' } = $code_count ;
$p_rbf{$file}{'blank' } = $blank_count ;
$p_rbf{$file}{'comment'} = $comment_count ;
$p_rbf{$file}{'lang' } = $Language{$file};
$p_rbf{$file}{'nFiles' } = 1;
} else {
$p_rbf{$file} = 1; # just keep track of counted files
}
$p_rbl{$Language{$file}}{'nFiles'}++;
$p_rbl{$Language{$file}}{'code'} += $code_count ;
$p_rbl{$Language{$file}}{'blank'} += $blank_count ;
$p_rbl{$Language{$file}}{'comment'} += $comment_count;
}
print "<- count_files()\n" if $opt_v > 2;
return {
"ignored" => \%p_ignored,
"errors" => \@p_errors,
"results_by_file" => \%p_rbf,
"results_by_language" => \%p_rbl,
}
} # 1}}}
sub count_filesets { # {{{1
my ($fset_a,
$fset_b,
$files_added,
$files_removed,
$file_pairs,
$counter_type,
$language_hash,
$rh_Ignored) = @_;
print "-> count_filesets()\n" if $opt_v > 2;
my @p_errors = ();
my %p_alignment = ();
my %p_ignored = ();
my %p_rbl = ();
my %p_rbf = ();
my %p_dbl = ();
my %p_dbf = ();
my %Language = %$language_hash;
my $nCounted = 0;
my %already_counted = (); # already_counted{ filename } = 1
if (!@$file_pairs) {
# Special case where all files were either added or deleted.
# In this case, one of these arrays will be empty:
# @files_added, @files_removed
# so loop over both to cover both cases.
my $status = @$files_added ? 'added' : 'removed';
my $fset = @$files_added ? $fset_b : $fset_a;
foreach my $file (@$files_added, @$files_removed) {
next unless defined $Language{$fset}{$file};
my $Lang = $Language{$fset}{$file};
next if $Lang eq '(unknown)';
my ($all_line_count,
$blank_count ,
$comment_count ,
) = call_counter($file, $Lang, \@p_errors);
$already_counted{$file} = 1;
my $code_count = $all_line_count-$blank_count-$comment_count;
if ($opt_by_file) {
$p_dbf{$file}{'code' }{$status} += $code_count ;
$p_dbf{$file}{'blank' }{$status} += $blank_count ;
$p_dbf{$file}{'comment'}{$status} += $comment_count;
$p_dbf{$file}{'lang' }{$status} = $Lang ;
$p_dbf{$file}{'nFiles' }{$status} += 1 ;
}
$p_dbl{$Lang}{'code' }{$status} += $code_count ;
$p_dbl{$Lang}{'blank' }{$status} += $blank_count ;
$p_dbl{$Lang}{'comment'}{$status} += $comment_count;
$p_dbl{$Lang}{'nFiles' }{$status} += 1 ;
}
}
#use Data::Dumper::Simple;
#use Data::Dumper;
#print Dumper(\@files_added, \@files_removed, \@file_pairs);
#print "after align_by_pairs:\n";
#print "added:\n";
foreach my $f (@$files_added) {
next if $already_counted{$f};
#printf "%10s -> %s\n", $f, $Language{$fh[$F+1]}{$f};
# Don't proceed unless the file (both L and R versions)
# is in a known language.
next if $opt_include_ext
and not $Include_Ext{ file_extension($f) };
next if $opt_include_lang
and not $Include_Language{$Language{$fset_b}{$f}};
my $this_lang = $Language{$fset_b}{$f};
if ($this_lang eq "(unknown)") {
$p_ignored{$f} = "uknown language";
next;
}
if ($Exclude_Language{$this_lang}) {
$p_ignored{$f} = "--exclude-lang=$this_lang";
next;
}
$p_alignment{"added"}{sprintf " + %s ; %s\n", $f, $this_lang} = 1;
++$p_dbl{ $this_lang }{'nFiles'}{'added'};
# Additionally, add contents of file $f to
# Delta_by_File{$f}{comment/blank/code}{'added'}
# Delta_by_Language{$lang}{comment/blank/code}{'added'}
# via the $p_dbl and $p_dbf variables.
my ($all_line_count,
$blank_count ,
$comment_count ,
) = call_counter($f, $this_lang, \@p_errors);
$p_dbl{ $this_lang }{'comment'}{'added'} += $comment_count;
$p_dbl{ $this_lang }{'blank'}{'added'} += $blank_count;
$p_dbl{ $this_lang }{'code'}{'added'} +=
$all_line_count - $blank_count - $comment_count;
$p_dbf{ $f }{'comment'}{'added'} = $comment_count;
$p_dbf{ $f }{'blank'}{'added'} = $blank_count;
$p_dbf{ $f }{'code'}{'added'} =
$all_line_count - $blank_count - $comment_count;
}
#print "removed:\n";
foreach my $f (@$files_removed) {
next if $already_counted{$f};
# Don't proceed unless the file (both L and R versions)
# is in a known language.
next if $opt_include_ext
and not $Include_Ext{ file_extension($f) };
next if $opt_include_lang
and (not defined $Language{$fset_a}{$f}
or not defined $Include_Language{$Language{$fset_a}{$f}});
my $this_lang = $Language{$fset_a}{$f};
if ($this_lang eq "(unknown)") {
$p_ignored{$f} = "uknown language";
next;
}
if ($Exclude_Language{$this_lang}) {
$p_ignored{$f} = "--exclude-lang=$this_lang";
next;
}
++$p_dbl{ $this_lang }{'nFiles'}{'removed'};
$p_alignment{"removed"}{sprintf " - %s ; %s\n", $f, $this_lang} = 1;
#printf "%10s -> %s\n", $f, $Language{$fh[$F ]}{$f};
# Additionally, add contents of file $f to
# Delta_by_File{$f}{comment/blank/code}{'removed'}
# Delta_by_Language{$lang}{comment/blank/code}{'removed'}
# via the $p_dbl and $p_dbf variables.
my ($all_line_count,
$blank_count ,
$comment_count ,
) = call_counter($f, $this_lang, \@p_errors);
$p_dbl{ $this_lang}{'comment'}{'removed'} += $comment_count;
$p_dbl{ $this_lang}{'blank'}{'removed'} += $blank_count;
$p_dbl{ $this_lang}{'code'}{'removed'} +=
$all_line_count - $blank_count - $comment_count;
$p_dbf{ $f }{'comment'}{'removed'} = $comment_count;
$p_dbf{ $f }{'blank'}{'removed'} = $blank_count;
$p_dbf{ $f }{'code'}{'removed'} =
$all_line_count - $blank_count - $comment_count;
}
my $n_file_pairs_compared = 0;
# Don't know ahead of time how many file pairs will be compared
# since duplicates are weeded out below. The answer is
# scalar @file_pairs only if there are no duplicates.
foreach my $pair (@$file_pairs) {
my $file_L = $pair->[0];
my $file_R = $pair->[1];
my $Lang_L = $Language{$fset_a}{$file_L};
my $Lang_R = $Language{$fset_b}{$file_R};
if (!defined($Lang_L) or !defined($Lang_R)) {
print " -> count_filesets skipping $file_L, $file_R ",
"because language cannot be inferred\n" if $opt_v;
next;
}
#print "main step 6 file_L=$file_L file_R=$file_R\n";
++$nCounted;
printf "Counting: %d\r", $nCounted
unless ($counter_type or !$opt_progress_rate or ($nCounted % $opt_progress_rate));
next if $p_ignored{$file_L} or $p_ignored{$file_R};
# filter out non-included extensions
if ($opt_include_ext and not $Include_Ext{ file_extension($file_L) }
and not $Include_Ext{ file_extension($file_R) }) {
$p_ignored{$file_L} = "not in --include-lang=$opt_include_ext";
$p_ignored{$file_R} = "not in --include-lang=$opt_include_ext";
next;
}
# filter out non-included languages
if ($opt_include_lang and not $Include_Language{$Lang_L}
and not $Include_Language{$Lang_R}) {
$p_ignored{$file_L} = "not in --include-lang=$opt_include_lang";
$p_ignored{$file_R} = "not in --include-lang=$opt_include_lang";
next;
}
# filter out excluded or unrecognized languages
if ($Exclude_Language{$Lang_L} or $Exclude_Language{$Lang_R}) {
$p_ignored{$file_L} = "--exclude-lang=$Lang_L";
$p_ignored{$file_R} = "--exclude-lang=$Lang_R";
next;
}
my $not_Filters_by_Language_Lang_LR = 0;
#print "file_LR = [$file_L] [$file_R]\n";
#print "Lang_LR = [$Lang_L] [$Lang_R]\n";
if (($Lang_L eq "(unknown)") or
($Lang_R eq "(unknown)") or
!(@{$Filters_by_Language{$Lang_L} }) or
!(@{$Filters_by_Language{$Lang_R} })) {
$not_Filters_by_Language_Lang_LR = 1;
}
if ($not_Filters_by_Language_Lang_LR) {
if (($Lang_L eq "(unknown)") or ($Lang_R eq "(unknown)")) {
$p_ignored{$fset_a}{$file_L} = "language unknown (#1)";
$p_ignored{$fset_b}{$file_R} = "language unknown (#1)";
} else {
$p_ignored{$fset_a}{$file_L} = "missing Filters_by_Language{$Lang_L}";
$p_ignored{$fset_b}{$file_R} = "missing Filters_by_Language{$Lang_R}";
}
next;
}
# filter out explicitly excluded files
if ($opt_exclude_list_file and
($rh_Ignored->{$file_L} or $rh_Ignored->{$file_R})) {
my $msg_2;
if ($rh_Ignored->{$file_L}) {
$msg_2 = "$file_L (paired to $file_R)";
} else {
$msg_2 = "$file_R (paired to $file_L)";
}
my $msg_1 = "in --exclude-list-file=$opt_exclude_list_file";
$p_ignored{$file_L} = "$msg_1, $msg_2";
$p_ignored{$file_R} = "$msg_1, $msg_2";
next;
}
#print "DIFF($file_L, $file_R)\n";
# step 0: compare the two files' contents
chomp ( my @lines_L = read_file($file_L) );
chomp ( my @lines_R = read_file($file_R) );
my $language_file_L = "";
if (defined $Language{$fset_a}{$file_L}) {
$language_file_L = $Language{$fset_a}{$file_L};
} else {
# files $file_L and $file_R do not contain known language
next;
}
my $contents_are_same = 1;
if (scalar @lines_L == scalar @lines_R) {
# same size, must compare line-by-line
for (my $i = 0; $i < scalar @lines_L; $i++) {
if ($lines_L[$i] ne $lines_R[$i]) {
$contents_are_same = 0;
last;
}
}
if ($contents_are_same) {
++$p_dbl{$language_file_L}{'nFiles'}{'same'};
} else {
++$p_dbl{$language_file_L}{'nFiles'}{'modified'};
}
} else {
$contents_are_same = 0;
# different sizes, contents have changed
++$p_dbl{$language_file_L}{'nFiles'}{'modified'};
}
if ($opt_diff_alignment) {
my $str = "$file_L | $file_R ; $language_file_L";
if ($contents_are_same) {
$p_alignment{"pairs"}{" == $str"} = 1;
} else {
$p_alignment{"pairs"}{" != $str"} = 1;
}
++$n_file_pairs_compared;
}
my ($all_line_count_L, $blank_count_L , $comment_count_L ,
$all_line_count_R, $blank_count_R , $comment_count_R , ) = (0,0,0,0,0,0,);
if (!$contents_are_same) {
# step 1: identify comments in both files
#print "Diff blank removal L language= $Lang_L";
#print " scalar(lines_L)=", scalar @lines_L, "\n";
my @original_minus_blanks_L
= rm_blanks( \@lines_L, $Lang_L, \%EOL_Continuation_re);
#print "1: scalar(original_minus_blanks_L)=", scalar @original_minus_blanks_L, "\n";
@lines_L = @original_minus_blanks_L;
#print "2: scalar(lines_L)=", scalar @lines_L, "\n";
@lines_L = add_newlines(\@lines_L); # compensate for rm_comments()
@lines_L = rm_comments( \@lines_L, $Lang_L, $file_L,
\%EOL_Continuation_re);
#print "3: scalar(lines_L)=", scalar @lines_L, "\n";
#print "Diff blank removal R language= $Lang_R\n";
my @original_minus_blanks_R
= rm_blanks( \@lines_R, $Lang_R, \%EOL_Continuation_re);
@lines_R = @original_minus_blanks_R;
@lines_R = add_newlines(\@lines_R); # taken away by rm_comments()
@lines_R = rm_comments( \@lines_R, $Lang_R, $file_R,
\%EOL_Continuation_re);
my (@diff_LL, @diff_LR, );
array_diff( $file_L , # in
\@original_minus_blanks_L , # in
\@lines_L , # in
"comment" , # in
\@diff_LL, \@diff_LR , # out
\@p_errors); # in/out
my (@diff_RL, @diff_RR, );
array_diff( $file_R , # in
\@original_minus_blanks_R , # in
\@lines_R , # in
"comment" , # in
\@diff_RL, \@diff_RR , # out
\@p_errors); # in/out
# each line of each file is now classified as
# code or comment
#use Data::Dumper;
#print Dumper("diff_LL", \@diff_LL, "diff_LR", \@diff_LR, );
#print Dumper("diff_RL", \@diff_RL, "diff_RR", \@diff_RR, );
#die;
# step 2: separate code from comments for L and R files
my @code_L = ();
my @code_R = ();
my @comm_L = ();
my @comm_R = ();
foreach my $line_info (@diff_LL) {
if ($line_info->{'type'} eq "code" ) {
push @code_L, $line_info->{char};
} elsif ($line_info->{'type'} eq "comment") {
push @comm_L, $line_info->{char};
} else {
die "Diff unexpected line type ",
$line_info->{'type'}, "for $file_L line ",
$line_info->{'lnum'};
}
}
foreach my $line_info (@diff_RL) {
if ($line_info->{type} eq "code" ) {
push @code_R, $line_info->{'char'};
} elsif ($line_info->{type} eq "comment") {
push @comm_R, $line_info->{'char'};
} else {
die "Diff unexpected line type ",
$line_info->{'type'}, "for $file_R line ",
$line_info->{'lnum'};
}
}
if ($opt_ignore_whitespace) {
# strip all whitespace from each line of source code
# and comments then use these stripped arrays in diffs
foreach (@code_L) { s/\s+//g }
foreach (@code_R) { s/\s+//g }
foreach (@comm_L) { s/\s+//g }
foreach (@comm_R) { s/\s+//g }
}
if ($opt_ignore_case) {
# change all text to lowercase in diffs
foreach (@code_L) { $_ = lc }
foreach (@code_R) { $_ = lc }
foreach (@comm_L) { $_ = lc }
foreach (@comm_R) { $_ = lc }
}
# step 3: compute code diffs
array_diff("$file_L v. $file_R" , # in
\@code_L , # in
\@code_R , # in
"revision" , # in
\@diff_LL, \@diff_LR , # out
\@p_errors); # in/out
#print Dumper("diff_LL", \@diff_LL, "diff_LR", \@diff_LR, );
#print Dumper("diff_LR", \@diff_LR);
foreach my $line_info (@diff_LR) {
my $status = $line_info->{'desc'}; # same|added|removed|modified
++$p_dbl{$Lang_L}{'code'}{$status};
if ($opt_by_file) {
++$p_dbf{$file_L}{'code'}{$status};
}
}
#use Data::Dumper;
#print Dumper("code diffs:", \@diff_LL, \@diff_LR);
# step 4: compute comment diffs
array_diff("$file_L v. $file_R" , # in
\@comm_L , # in
\@comm_R , # in
"revision" , # in
\@diff_LL, \@diff_LR , # out
\@Errors); # in/out
#print Dumper("comment diff_LR", \@diff_LR);
foreach my $line_info (@diff_LR) {
my $status = $line_info->{'desc'}; # same|added|removed|modified
++$p_dbl{$Lang_L}{'comment'}{$status};
if ($opt_by_file) {
++$p_dbf{$file_L}{'comment'}{$status};
}
}
#print Dumper("comment diffs:", \@diff_LL, \@diff_LR);
# step 5: compute difference in blank lines (kind of pointless)
next if $Lang_L eq '(unknown)' or
$Lang_R eq '(unknown)';
($all_line_count_L,
$blank_count_L ,
$comment_count_L ,
) = call_counter($file_L, $Lang_L, \@Errors);
($all_line_count_R,
$blank_count_R ,
$comment_count_R ,
) = call_counter($file_R, $Lang_R, \@Errors);
} else {
# L and R file contents are identical, no need to diff
($all_line_count_L,
$blank_count_L ,
$comment_count_L ,
) = call_counter($file_L, $Lang_L, \@Errors);
$all_line_count_R = $all_line_count_L;
$blank_count_R = $blank_count_L ;
$comment_count_R = $comment_count_L ;
my $code_lines_R = $all_line_count_R - ($blank_count_R + $comment_count_R);
$p_dbl{$Lang_L}{'blank'}{'same'} += $blank_count_R;
$p_dbl{$Lang_L}{'comment'}{'same'} += $comment_count_R;
$p_dbl{$Lang_L}{'code'}{'same'} += $code_lines_R;
if ($opt_by_file) {
$p_dbf{$file_L}{'blank'}{'same'} += $blank_count_R;
$p_dbf{$file_L}{'comment'}{'same'} += $comment_count_R;
$p_dbf{$file_L}{'code'}{'same'} += $code_lines_R;
}
}
if ($blank_count_L < $blank_count_R) {
my $D = $blank_count_R - $blank_count_L;
$p_dbl{$Lang_L}{'blank'}{'added'} += $D;
} else {
my $D = $blank_count_L - $blank_count_R;
$p_dbl{$Lang_L}{'blank'}{'removed'} += $D;
}
if ($opt_by_file) {
if ($blank_count_L < $blank_count_R) {
my $D = $blank_count_R - $blank_count_L;
$p_dbf{$file_L}{'blank'}{'added'} += $D;
} else {
my $D = $blank_count_L - $blank_count_R;
$p_dbf{$file_L}{'blank'}{'removed'} += $D;
}
}
my $code_count_L = $all_line_count_L-$blank_count_L-$comment_count_L;
if ($opt_by_file) {
$p_rbf{$file_L}{'code' } = $code_count_L ;
$p_rbf{$file_L}{'blank' } = $blank_count_L ;
$p_rbf{$file_L}{'comment'} = $comment_count_L ;
$p_rbf{$file_L}{'lang' } = $Lang_L ;
$p_rbf{$file_L}{'nFiles' } = 1 ;
} else {
$p_rbf{$file_L} = 1; # just keep track of counted files
}
$p_rbl{$Lang_L}{'nFiles'}++;
$p_rbl{$Lang_L}{'code'} += $code_count_L ;
$p_rbl{$Lang_L}{'blank'} += $blank_count_L ;
$p_rbl{$Lang_L}{'comment'} += $comment_count_L;
}
print "<- count_filesets()\n" if $opt_v > 2;
return {
"ignored" => \%p_ignored,
"errors" => \@p_errors,
"results_by_file" => \%p_rbf,
"results_by_language" => \%p_rbl,
"delta_by_file" => \%p_dbf,
"delta_by_language" => \%p_dbl,
"alignment" => \%p_alignment,
"n_filepairs_compared" => $n_file_pairs_compared
}
} # 1}}}
sub write_alignment_data { # {{{1
my ($filename, $n_filepairs_compared, $data ) = @_;
my @output = ();
if ( $data->{'added'} ) {
my %added_lines = %{$data->{'added'}};
push (@output, "Files added: " . (scalar keys %added_lines) . "\n");
foreach my $line ( sort keys %added_lines ) {
push (@output, $line);
}
push (@output, "\n" );
}
if ( $data->{'removed'} ) {
my %removed_lines = %{$data->{'removed'}};
push (@output, "Files removed: " . (scalar keys %removed_lines) . "\n");
foreach my $line ( sort keys %removed_lines ) {
push (@output, $line);
}
push (@output, "\n");
}
if ( $data->{'pairs'} ) {
my %pairs = %{$data->{'pairs'}};
push (@output, "File pairs compared: " . $n_filepairs_compared . "\n");
foreach my $pair ( sort keys %pairs ) {
push (@output, $pair);
}
}
write_file($filename, {}, @output);
} # 1}}}
sub exclude_dir_validates { # {{{1
my ($rh_Exclude_Dir) = @_;
my $is_OK = 1;
foreach my $dir (keys %{$rh_Exclude_Dir}) {
if (($ON_WINDOWS and $dir =~ m{\\}) or ($dir =~ m{/})) {
$is_OK = 0;
warn "--exclude-dir '$dir' : cannot specify directory paths\n";
}
}
if (!$is_OK) {
warn "Use '--fullpath --not-match-d=REGEX' instead\n";
}
return $is_OK;
} # 1}}}
sub process_exclude_list_file { # {{{1
my ($list_file , # in
$rh_exclude_dir , # out
$rh_ignored , # out
) = @_;
# note: references global @file_list
print "-> process_exclude_list_file($list_file)\n" if $opt_v > 2;
# reject a specific set of files and/or directories
my @reject_list = read_list_file($list_file);
my @file_reject_list = ();
foreach my $F_or_D (@reject_list) {
if (is_dir($F_or_D)) {
$rh_exclude_dir->{$F_or_D} = 1;
} elsif (is_file($F_or_D)) {
push @file_reject_list, $F_or_D;
}
}
# Normalize file names for better comparison.
my %normalized_input = normalize_file_names(@file_list);
my %normalized_reject = normalize_file_names(@file_reject_list);
my %normalized_exclude = normalize_file_names(keys %{$rh_exclude_dir});
foreach my $F (keys %normalized_input) {
if ($normalized_reject{$F} or is_excluded($F, \%normalized_exclude)) {
my $orig_F = $normalized_input{$F};
$rh_ignored->{$orig_F} = "listed in exclusion file $opt_exclude_list_file";
print "Ignoring $orig_F because it appears in $opt_exclude_list_file\n"
if $opt_v > 1;
}
}
print "<- process_exclude_list_file\n" if $opt_v > 2;
} # 1}}}
sub combine_results { # {{{1
# returns 1 if the inputs are categorized by language
# 0 if no identifiable language was found
my ($ra_report_files, # in
$report_type , # in "by language" or "by report file"
$rhh_count , # out count{TYPE}{nFiles|code|blank|comment|scaled}
$rhaa_Filters_by_Language , # in
) = @_;
print "-> combine_results(report_type=$report_type)\n" if $opt_v > 2;
my $found_language = 0;
foreach my $file (@{$ra_report_files}) {
my $n_results_found = 0;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
next;
}
while (<$IN>) {
next if /^(http|Language|SUM|-----)/;
if (!$opt_by_file and
m{^(.*?)\s+ # language
(\d+)\s+ # files
(\d+)\s+ # blank
(\d+)\s+ # comments
(\d+)\s+ # code
( # next four entries missing with -no3
x\s+ # x
\d+\.\d+\s+ # scale
=\s+ # =
(\d+\.\d+)\s* # scaled code
)?
$}x) {
if ($report_type eq "by language") {
if (!defined $rhaa_Filters_by_Language->{$1}) {
warn "Unrecognized language '$1' in $file ignored\n";
next;
}
# above test necessary to avoid trying to sum reports
# of reports (which have no language breakdown).
$found_language = 1;
$rhh_count->{$1 }{'nFiles' } += $2;
$rhh_count->{$1 }{'blank' } += $3;
$rhh_count->{$1 }{'comment'} += $4;
$rhh_count->{$1 }{'code' } += $5;
$rhh_count->{$1 }{'scaled' } += $7 if $opt_3;
} else {
$rhh_count->{$file}{'nFiles' } += $2;
$rhh_count->{$file}{'blank' } += $3;
$rhh_count->{$file}{'comment'} += $4;
$rhh_count->{$file}{'code' } += $5;
$rhh_count->{$file}{'scaled' } += $7 if $opt_3;
}
++$n_results_found;
} elsif ($opt_by_file and
m{^(.*?)\s+ # language
(\d+)\s+ # blank
(\d+)\s+ # comments
(\d+)\s+ # code
( # next four entries missing with -no3
x\s+ # x
\d+\.\d+\s+ # scale
=\s+ # =
(\d+\.\d+)\s* # scaled code
)?
$}x) {
if ($report_type eq "by language") {
next unless %{$rhaa_Filters_by_Language->{$1}};
# above test necessary to avoid trying to sum reports
# of reports (which have no language breakdown).
$found_language = 1;
$rhh_count->{$1 }{'nFiles' } += 1;
$rhh_count->{$1 }{'blank' } += $2;
$rhh_count->{$1 }{'comment'} += $3;
$rhh_count->{$1 }{'code' } += $4;
$rhh_count->{$1 }{'scaled' } += $6 if $opt_3;
} else {
$rhh_count->{$file}{'nFiles' } += 1;
$rhh_count->{$file}{'blank' } += $2;
$rhh_count->{$file}{'comment'} += $3;
$rhh_count->{$file}{'code' } += $4;
$rhh_count->{$file}{'scaled' } += $6 if $opt_3;
}
++$n_results_found;
}
}
warn "No counts found in $file--is the file format correct?\n"
unless $n_results_found;
}
print "<- combine_results\n" if $opt_v > 2;
return $found_language;
} # 1}}}
sub compute_denominator { # {{{1
my ($method, $nCode, $nComment, $nBlank, ) = @_;
print "-> compute_denominator\n" if $opt_v > 2;
my %den = ( "c" => $nCode );
$den{"cm"} = $den{"c"} + $nComment;
$den{"cmb"} = $den{"cm"} + $nBlank;
$den{"cb"} = $den{"c"} + $nBlank;
print "<- compute_denominator\n" if $opt_v > 2;
return $den{ $method };
} # 1}}}
sub yaml_to_json_separators { # {{{1
# YAML and JSON are closely related. Their differences can be captured
# by trailing commas ($C), braces ($open_B, $close_B), and
# quotes around text ($Q).
print "-> yaml_to_json_separators()\n" if $opt_v > 2;
my ($Q, $open_B, $close_B, $start, $C);
if ($opt_json) {
$C = ',';
$Q = '"';
$open_B = '{';
$close_B = '}';
$start = '{';
} else {
$C = '';
$Q = '' ;
$open_B = '' ;
$close_B = '';
$start = "---\n# $URL\n";
}
print "<- yaml_to_json_separators()\n" if $opt_v > 2;
return ($Q, $open_B, $close_B, $start, $C);
} # 1}}}
sub diff_report { # {{{1
# returns an array of lines containing the results
print "-> diff_report\n" if $opt_v > 2;
if ($opt_xml) {
print "<- diff_report\n" if $opt_v > 2;
return diff_xml_report(@_)
} elsif ($opt_yaml) {
print "<- diff_report\n" if $opt_v > 2;
return diff_yaml_report(@_)
} elsif ($opt_json) {
print "<- diff_report\n" if $opt_v > 2;
return diff_json_report(@_)
} elsif ($opt_csv or $opt_md) {
print "<- diff_report\n" if $opt_v > 2;
return diff_csv_report(@_)
}
my ($version , # in
$elapsed_sec, # in
$report_type, # in "by language" | "by report file" | "by file"
$rhhh_count , # in count{TYPE}{nFiles|code|blank|comment}{a|m|r|s}
$rh_scale , # in
) = @_;
#use Data::Dumper;
#print "diff_report: ", Dumper($rhhh_count), "\n";
my @results = ();
my $languages = ();
my %sum = (); # sum{nFiles|blank|comment|code}{same|modified|added|removed}
my $max_len = 0;
foreach my $language (keys %{$rhhh_count}) {
foreach my $V (qw(nFiles blank comment code)) {
foreach my $S (qw(added same modified removed)) {
$rhhh_count->{$language}{$V}{$S} = 0 unless
defined $rhhh_count->{$language}{$V}{$S};
$sum{$V}{$S} += $rhhh_count->{$language}{$V}{$S};
}
}
$max_len = length($language) if length($language) > $max_len;
}
my $column_1_offset = 0;
$column_1_offset = $max_len - 17 if $max_len > 17;
$elapsed_sec = 0.5 unless $elapsed_sec;
my $spacing_0 = 23;
my $spacing_1 = 13;
my $spacing_2 = 9;
my $spacing_3 = 17;
if (!$opt_3) {
$spacing_1 = 19;
$spacing_2 = 14;
$spacing_3 = 27;
}
$spacing_0 += $column_1_offset;
$spacing_1 += $column_1_offset;
$spacing_3 += $column_1_offset;
my %Format = (
'1' => { 'xml' => 'name="%s" ',
'txt' => "\%-${spacing_0}s ",
},
'2' => { 'xml' => 'name="%s" ',
'txt' => "\%-${spacing_3}s ",
},
'3' => { 'xml' => 'files_count="%d" ',
'txt' => '%6d ',
},
'4' => { 'xml' => 'blank="%d" comment="%d" code="%d" ',
'txt' => "\%${spacing_2}d \%${spacing_2}d \%${spacing_2}d",
},
'5' => { 'xml' => 'blank="%.2f" comment="%.2f" code="%d" ',
'txt' => "\%3.2f \%3.2f \%${spacing_2}d",
},
'6' => { 'xml' => 'factor="%.2f" scaled="%.2f" ',
'txt' => ' x %6.2f = %14.2f',
},
);
my $Style = "txt";
$Style = "xml" if $opt_xml ;
$Style = "xml" if $opt_yaml; # not a typo; just set to anything but txt
$Style = "xml" if $opt_json; # not a typo; just set to anything but txt
$Style = "xml" if $opt_csv ; # not a typo; just set to anything but txt
my $hyphen_line = sprintf "%s", '-' x (79 + $column_1_offset);
$hyphen_line = sprintf "%s", '-' x (68 + $column_1_offset)
if (!$opt_3) and (68 + $column_1_offset) > 79;
my $data_line = "";
my $first_column;
my $BY_LANGUAGE = 0;
my $BY_FILE = 0;
if ($report_type eq "by language") {
$first_column = "Language";
$BY_LANGUAGE = 1;
} elsif ($report_type eq "by file") {
$first_column = "File";
$BY_FILE = 1;
} else {
$first_column = "Report File";
}
# column headers
if (!$opt_3 and $BY_FILE) {
my $spacing_n = $spacing_1 - 11;
$data_line = sprintf "%-${spacing_n}s" , $first_column;
} else {
$data_line = sprintf "%-${spacing_1}s ", $first_column;
}
if ($BY_FILE) {
$data_line .= sprintf "%${spacing_2}s" , "" ;
} else {
$data_line .= sprintf "%${spacing_2}s " , "files";
}
my $PCT_symbol = "";
$PCT_symbol = " \%" if $opt_by_percent;
$data_line .= sprintf "%${spacing_2}s %${spacing_2}s %${spacing_2}s",
"blank${PCT_symbol}" ,
"comment${PCT_symbol}" ,
"code";
if ($Style eq "txt") {
push @results, $data_line;
push @results, $hyphen_line;
}
# sort diff output in descending order of cumulative entries
foreach my $lang_or_file (sort {
($rhhh_count->{$b}{'code'}{'added'} +
$rhhh_count->{$b}{'code'}{'same'} +
$rhhh_count->{$b}{'code'}{'modified'} +
$rhhh_count->{$b}{'code'}{'removed'} ) <=>
($rhhh_count->{$a}{'code'}{'added'} +
$rhhh_count->{$a}{'code'}{'same'} +
$rhhh_count->{$a}{'code'}{'modified'} +
$rhhh_count->{$a}{'code'}{'removed'})
or $a cmp $b }
keys %{$rhhh_count}) {
if ($BY_FILE) {
push @results, rm_leading_tempdir($lang_or_file, \%TEMP_DIR);
} else {
push @results, $lang_or_file;
}
foreach my $S (qw(same modified added removed)) {
my $indent = $spacing_1 - 2;
my $line .= sprintf " %-${indent}s", $S;
if ($BY_FILE) {
$line .= sprintf " ";
} else {
$line .= sprintf " %${spacing_2}s", $rhhh_count->{$lang_or_file}{'nFiles'}{$S};
}
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent ,
$rhhh_count->{$lang_or_file}{'code'}{$S} ,
$rhhh_count->{$lang_or_file}{'comment'}{$S},
$rhhh_count->{$lang_or_file}{'blank'}{$S} );
if ($rhhh_count->{$lang_or_file}{'code'}{$S} > 0) {
$line .= sprintf " %14.2f %14.2f %${spacing_2}s",
$rhhh_count->{$lang_or_file}{'blank'}{$S} / $DEN * 100,
$rhhh_count->{$lang_or_file}{'comment'}{$S} / $DEN * 100,
$rhhh_count->{$lang_or_file}{'code'}{$S} ;
} else {
$line .= sprintf " %14.2f %14.2f %${spacing_2}s",
0.0, 0.0, $rhhh_count->{$lang_or_file}{'code'}{$S} ;
}
} else {
$line .= sprintf " %${spacing_2}s %${spacing_2}s %${spacing_2}s",
$rhhh_count->{$lang_or_file}{'blank'}{$S} ,
$rhhh_count->{$lang_or_file}{'comment'}{$S} ,
$rhhh_count->{$lang_or_file}{'code'}{$S} ;
}
push @results, $line;
}
}
push @results, $hyphen_line;
push @results, "SUM:";
my $sum_files = 0;
my $sum_lines = 0;
foreach my $S (qw(same modified added removed)) {
my $indent = $spacing_1 - 2;
my $line .= sprintf " %-${indent}s", $S;
if ($BY_FILE) {
$line .= sprintf " ";
$sum_files += 1;
} else {
$line .= sprintf " %${spacing_2}s", $sum{'nFiles'}{$S};
$sum_files += $sum{'nFiles'}{$S};
}
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent,
$sum{'code'}{$S}, $sum{'comment'}{$S}, $sum{'blank'}{$S});
if ($sum{'code'}{$S} > 0) {
$line .= sprintf " %14.2f %14.2f %${spacing_2}s",
$sum{'blank'}{$S} / $DEN * 100,
$sum{'comment'}{$S} / $DEN * 100,
$sum{'code'}{$S} ;
} else {
$line .= sprintf " %14.2f %14.2f %${spacing_2}s",
0.0, 0.0, $sum{'code'}{$S} ;
}
} else {
$line .= sprintf " %${spacing_2}s %${spacing_2}s %${spacing_2}s",
$sum{'blank'}{$S} ,
$sum{'comment'}{$S} ,
$sum{'code'}{$S} ;
}
$sum_lines += $sum{'blank'}{$S} + $sum{'comment'}{$S} + $sum{'code'}{$S};
push @results, $line;
}
my $header_line = sprintf "%s v %s", $URL, $version;
$header_line .= sprintf(" T=%.2f s (%.1f files/s, %.1f lines/s)",
$elapsed_sec ,
$sum_files/$elapsed_sec,
$sum_lines/$elapsed_sec) unless $opt_sum_reports or $opt_hide_rate;
if ($Style eq "txt") {
unshift @results, output_header($header_line, $hyphen_line, $BY_FILE);
}
push @results, $hyphen_line;
write_xsl_file() if $opt_xsl and $opt_xsl eq $CLOC_XSL;
print "<- diff_report\n" if $opt_v > 2;
return @results;
} # 1}}}
sub xml_yaml_or_json_header { # {{{1
my ($URL, $version, $elapsed_sec, $sum_files, $sum_lines, $by_file) = @_;
print "-> xml_yaml_or_json_header\n" if $opt_v > 2;
my $header = "";
my $file_rate = $sum_files/$elapsed_sec;
my $line_rate = $sum_lines/$elapsed_sec;
my $type = "";
$type = "diff_" if $opt_diff;
my $report_file = "";
if ($opt_report_file) {
if ($opt_sum_reports) {
if ($by_file) {
$report_file = " <report_file>$opt_report_file.file</report_file>"
} else {
$report_file = " <report_file>$opt_report_file.lang</report_file>"
}
} else {
$report_file = " <report_file>$opt_report_file</report_file>"
}
}
if ($opt_xml) {
$header = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
$header .= "\n<?xml-stylesheet type=\"text/xsl\" href=\"" . $opt_xsl . "\"?>" if $opt_xsl;
$header .= "<${type}results>
<header>
<cloc_url>$URL</cloc_url>
<cloc_version>$version</cloc_version>
<elapsed_seconds>$elapsed_sec</elapsed_seconds>
<n_files>$sum_files</n_files>
<n_lines>$sum_lines</n_lines>
<files_per_second>$file_rate</files_per_second>
<lines_per_second>$line_rate</lines_per_second>";
$header .= "\n$report_file"
if $opt_report_file;
$header .= "\n</header>";
} elsif ($opt_yaml or $opt_json) {
my ($Q, $open_B, $close_B, $start, $C) = yaml_to_json_separators();
$header = "${start}${Q}header${Q} : $open_B
${Q}cloc_url${Q} : ${Q}$URL${Q}${C}
${Q}cloc_version${Q} : ${Q}$version${Q}${C}
${Q}elapsed_seconds${Q} : $elapsed_sec${C}
${Q}n_files${Q} : $sum_files${C}
${Q}n_lines${Q} : $sum_lines${C}
${Q}files_per_second${Q} : $file_rate${C}
${Q}lines_per_second${Q} : $line_rate";
if ($opt_report_file) {
if ($opt_sum_reports) {
if ($by_file) {
$header .= "$C\n ${Q}report_file${Q} : ${Q}$opt_report_file.file${Q}"
} else {
$header .= "$C\n ${Q}report_file${Q} : ${Q}$opt_report_file.lang${Q}"
}
} else {
$header .= "$C\n ${Q}report_file${Q} : ${Q}$opt_report_file${Q}";
}
}
$header .= "${close_B}${C}";
}
print "<- xml_yaml_or_json_header\n" if $opt_v > 2;
return $header;
} # 1}}}
sub diff_yaml_report { # {{{1
# returns an array of lines containing the results
my ($version , # in
$elapsed_sec, # in
$report_type, # in "by language" | "by report file" | "by file"
$rhhh_count , # in count{TYPE}{nFiles|code|blank|comment}{a|m|r|s}
$rh_scale , # in
) = @_;
print "-> diff_yaml_report\n" if $opt_v > 2;
$elapsed_sec = 0.5 unless $elapsed_sec;
my @results = ();
my %sum = ();
my ($sum_lines, $sum_files, $BY_FILE, $BY_LANGUAGE) =
diff_header_sum($report_type, $rhhh_count, \%sum);
if (!$ALREADY_SHOWED_HEADER) {
push @results,
xml_yaml_or_json_header($URL, $version, $elapsed_sec,
$sum_files, $sum_lines, $BY_FILE);
$ALREADY_SHOWED_HEADER = 1;
}
foreach my $S (qw(added same modified removed)) {
push @results, "$S :";
foreach my $F_or_L (keys %{$rhhh_count}) {
# force quoted language or filename in case these
# have embedded funny characters, issue #312
push @results, " '" . rm_leading_tempdir($F_or_L, \%TEMP_DIR) . "' :";
foreach my $k (keys %{$rhhh_count->{$F_or_L}}) {
next if $k eq "lang"; # present only in those cases
# where code exists for action $S
$rhhh_count->{$F_or_L}{$k}{$S} = 0 unless
defined $rhhh_count->{$F_or_L}{$k}{$S};
push @results,
" $k : $rhhh_count->{$F_or_L}{$k}{$S}";
}
}
}
push @results, "SUM :";
foreach my $S (qw(added same modified removed)) {
push @results, " $S :";
foreach my $topic (keys %sum) {
push @results, " $topic : $sum{$topic}{$S}";
}
}
print "<- diff_yaml_report\n" if $opt_v > 2;
return @results;
} # 1}}}
sub diff_json_report { # {{{1
# returns an array of lines containing the results
my ($version , # in
$elapsed_sec, # in
$report_type, # in "by language" | "by report file" | "by file"
$rhhh_count , # in count{TYPE}{nFiles|code|blank|comment}{a|m|r|s}
$rh_scale , # in
) = @_;
print "-> diff_json_report\n" if $opt_v > 2;
$elapsed_sec = 0.5 unless $elapsed_sec;
my @results = ();
my %sum = ();
my ($sum_lines, $sum_files, $BY_FILE, $BY_LANGUAGE) =
diff_header_sum($report_type, $rhhh_count, \%sum);
if (!$ALREADY_SHOWED_HEADER) {
push @results,
xml_yaml_or_json_header($URL, $version, $elapsed_sec,
$sum_files, $sum_lines, $BY_FILE);
$ALREADY_SHOWED_HEADER = 1;
}
foreach my $S (qw(added same modified removed)) {
push @results, " \"$S\" : {";
foreach my $F_or_L (keys %{$rhhh_count}) {
push @results, " \"" . rm_leading_tempdir($F_or_L, \%TEMP_DIR) . "\" : {";
foreach my $k (keys %{$rhhh_count->{$F_or_L}}) {
next if $k eq "lang"; # present only in those cases
# where code exists for action $S
$rhhh_count->{$F_or_L}{$k}{$S} = 0 unless
defined $rhhh_count->{$F_or_L}{$k}{$S};
push @results,
" \"$k\" : $rhhh_count->{$F_or_L}{$k}{$S},";
}
$results[-1] =~ s/,\s*$//;
push @results, " },"
}
$results[-1] =~ s/,\s*$//;
push @results, " },"
}
push @results, " \"SUM\" : {";
foreach my $S (qw(added same modified removed)) {
push @results, " \"$S\" : {";
foreach my $topic (keys %sum) {
push @results, " \"$topic\" : $sum{$topic}{$S},";
}
$results[-1] =~ s/,\s*$//;
push @results, "},";
}
$results[-1] =~ s/,\s*$//;
push @results, "} }";
print "<- diff_json_report\n" if $opt_v > 2;
return @results;
} # 1}}}
sub diff_header_sum { # {{{1
my ($report_type, # in "by language" | "by report file" | "by file"
$rhhh_count , # in count{TYPE}{nFiles|code|blank|comment}{a|m|r|s}
$rhh_sum , # out sum{nFiles|blank|comment|code}{same|modified|added|removed}
) = @_;
my $sum_files = 0;
my $sum_lines = 0;
foreach my $language (keys %{$rhhh_count}) {
foreach my $V (qw(nFiles blank comment code)) {
foreach my $S (qw(added same modified removed)) {
$rhhh_count->{$language}{$V}{$S} = 0 unless
defined $rhhh_count->{$language}{$V}{$S};
$rhh_sum->{$V}{$S} += $rhhh_count->{$language}{$V}{$S};
if ($V eq "nFiles") {
$sum_files += $rhhh_count->{$language}{$V}{$S};
} else {
$sum_lines += $rhhh_count->{$language}{$V}{$S};
}
}
}
}
my $BY_LANGUAGE = 0;
my $BY_FILE = 0;
if ($report_type eq "by language") {
$BY_LANGUAGE = 1;
} elsif ($report_type eq "by file") {
$BY_FILE = 1;
}
return $sum_lines, $sum_files, $BY_FILE, $BY_LANGUAGE;
} # 1}}}
sub diff_xml_report { # {{{1
# returns an array of lines containing the results
my ($version , # in
$elapsed_sec, # in
$report_type, # in "by language" | "by report file" | "by file"
$rhhh_count , # in count{TYPE}{nFiles|code|blank|comment}{a|m|r|s}
$rh_scale , # in
) = @_;
print "-> diff_xml_report\n" if $opt_v > 2;
my ($Q, $open_B, $close_B, $start, $C) = yaml_to_json_separators();
#print "diff_report: ", Dumper($rhhh_count), "\n";
$elapsed_sec = 0.5 unless $elapsed_sec;
my @results = ();
my %sum = ();
my $languages = ();
my ($sum_lines, $sum_files, $BY_FILE, $BY_LANGUAGE) =
diff_header_sum($report_type, $rhhh_count, \%sum);
my $data_line = "";
if (!$ALREADY_SHOWED_HEADER) {
push @results,
xml_yaml_or_json_header($URL, $version, $elapsed_sec,
$sum_files, $sum_lines, $BY_FILE);
$ALREADY_SHOWED_HEADER = 1;
}
foreach my $S (qw(same modified added removed)) {
push @results, " <$S>";
foreach my $lang_or_file (sort {
$rhhh_count->{$b}{'code'} <=>
$rhhh_count->{$a}{'code'}
}
keys %{$rhhh_count}) {
my $L = "";
if ($BY_FILE) {
$L .= sprintf " <file name=\"%s\" files_count=\"1\" ",
xml_metachars(
rm_leading_tempdir($lang_or_file, \%TEMP_DIR));
} else {
$L .= sprintf " <language name=\"%s\" files_count=\"%d\" ",
$lang_or_file ,
$rhhh_count->{$lang_or_file}{'nFiles'}{$S};
}
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent ,
$rhhh_count->{$lang_or_file}{'code'}{$S} ,
$rhhh_count->{$lang_or_file}{'comment'}{$S},
$rhhh_count->{$lang_or_file}{'blank'}{$S} );
foreach my $T (qw(blank comment)) {
if ($rhhh_count->{$lang_or_file}{'code'}{$S} > 0) {
$L .= sprintf "%s=\"%.2f\" ",
$T, $rhhh_count->{$lang_or_file}{$T}{$S} / $DEN * 100;
} else {
$L .= sprintf "%s=\"0.0\" ", $T;
}
}
foreach my $T (qw(code)) {
$L .= sprintf "%s=\"%d\" ",
$T, $rhhh_count->{$lang_or_file}{$T}{$S};
}
} else {
foreach my $T (qw(blank comment code)) {
$L .= sprintf "%s=\"%d\" ",
$T, $rhhh_count->{$lang_or_file}{$T}{$S};
}
}
push @results, $L . "/>";
}
my $L = sprintf " <total sum_files=\"%d\" ", $sum{'nFiles'}{$S};
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent,
$sum{'code'}{$S} ,
$sum{'comment'}{$S},
$sum{'blank'}{$S} );
foreach my $V (qw(blank comment)) {
if ($sum{'code'}{$S} > 0) {
$L .= sprintf "%s=\"%.2f\" ", $V, $sum{$V}{$S} / $DEN * 100;
} else {
$L .= sprintf "%s=\"0.0\" ", $V;
}
}
foreach my $V (qw(code)) {
$L .= sprintf "%s=\"%d\" ", $V, $sum{$V}{$S};
}
} else {
foreach my $V (qw(blank comment code)) {
$L .= sprintf "%s=\"%d\" ", $V, $sum{$V}{$S};
}
}
push @results, $L . "/>";
push @results, " </$S>";
}
push @results, "</diff_results>";
write_xsl_file() if $opt_xsl and $opt_xsl eq $CLOC_XSL;
print "<- diff_xml_report\n" if $opt_v > 2;
return @results;
} # 1}}}
sub diff_csv_report { # {{{1
# returns an array of lines containing the results
my ($version , # in
$elapsed_sec, # in
$report_type, # in "by language" | "by report file" | "by file"
$rhhh_count , # in count{TYPE}{nFiles|code|blank|comment}{a|m|r|s}
$rh_scale , # in unused
) = @_;
print "-> diff_csv_report\n" if $opt_v > 2;
my @results = ();
my $languages = ();
my $data_line = "";
my $BY_LANGUAGE = 0;
my $BY_FILE = 0;
if ($report_type eq "by language") {
$BY_LANGUAGE = 1;
} elsif ($report_type eq "by file") {
$BY_FILE = 1;
}
my $DELIM = ",";
$DELIM = $opt_csv_delimiter if defined $opt_csv_delimiter;
$DELIM = "|" if defined $opt_md;
$elapsed_sec = 0.5 unless $elapsed_sec;
my $line = "Language${DELIM} ";
$line = "File${DELIM} " if $BY_FILE;
foreach my $item (qw(files blank comment code)) {
next if $BY_FILE and $item eq 'files';
foreach my $symbol ( '==', '!=', '+', '-', ) {
$line .= "$symbol $item${DELIM} ";
}
}
my $T_elapsed_sec = "T=$elapsed_sec s";
$T_elapsed_sec = "" if $opt_hide_rate;
if ($opt_md) {
push @results, "cloc|$URL v $version $T_elapsed_sec";
push @results, "--- | ---";
push @results, "";
push @results, $line;
my @col_header = ();
push @col_header, ":-------";
foreach (1..16) {
push @col_header, "-------:";
}
push @results, join("|", @col_header) . "|";
} else {
$line .= "\"$URL v $version $T_elapsed_sec\"";
push @results, $line;
}
foreach my $lang_or_file (keys %{$rhhh_count}) {
$rhhh_count->{$lang_or_file}{'code'}{'added'} = 0 unless
defined $rhhh_count->{$lang_or_file}{'code'};
}
foreach my $lang_or_file (sort {
$rhhh_count->{$b}{'code'} <=>
$rhhh_count->{$a}{'code'}
}
keys %{$rhhh_count}) {
if ($BY_FILE) {
$line = rm_leading_tempdir($lang_or_file, \%TEMP_DIR) . "$DELIM ";
} else {
$line = $lang_or_file . "${DELIM} ";
}
if ($opt_by_percent) {
foreach my $item (qw(nFiles)) {
next if $BY_FILE and $item eq 'nFiles';
foreach my $symbol (qw(same modified added removed)) {
if (defined $rhhh_count->{$lang_or_file}{$item}{$symbol}) {
$line .= "$rhhh_count->{$lang_or_file}{$item}{$symbol}${DELIM} ";
} else {
$line .= "0${DELIM} ";
}
}
}
foreach my $item (qw(blank comment)) {
foreach my $symbol (qw(same modified added removed)) {
if (defined $rhhh_count->{$lang_or_file}{$item}{$symbol} and
defined $rhhh_count->{$lang_or_file}{'code'}{$symbol} and
$rhhh_count->{$lang_or_file}{'code'}{$symbol} > 0) {
$line .= sprintf("%.2f", $rhhh_count->{$lang_or_file}{$item}{$symbol} / $rhhh_count->{$lang_or_file}{'code'}{$symbol} * 100).${DELIM};
} else {
$line .= "0.00${DELIM} ";
}
}
}
foreach my $item (qw(code)) {
foreach my $symbol (qw(same modified added removed)) {
if (defined $rhhh_count->{$lang_or_file}{$item}{$symbol}) {
$line .= "$rhhh_count->{$lang_or_file}{$item}{$symbol}${DELIM} ";
} else {
$line .= "0${DELIM} ";
}
}
}
} else {
foreach my $item (qw(nFiles blank comment code)) {
next if $BY_FILE and $item eq 'nFiles';
foreach my $symbol (qw(same modified added removed)) {
if (defined $rhhh_count->{$lang_or_file}{$item}{$symbol}) {
$line .= "$rhhh_count->{$lang_or_file}{$item}{$symbol}${DELIM} ";
} else {
$line .= "0${DELIM} ";
}
}
}
}
push @results, $line;
}
print "<- diff_csv_report\n" if $opt_v > 2;
return @results;
} # 1}}}
sub rm_leading_tempdir { # {{{1
my ($in_file, $rh_temp_dirs, ) = @_;
my $clean_filename = $in_file;
foreach my $temp_d (keys %{$rh_temp_dirs}) {
if ($ON_WINDOWS) {
# \ -> / necessary to allow the next if test's
# m{} to work in the presence of spaces in file names
$temp_d =~ s{\\}{/}g;
$clean_filename =~ s{\\}{/}g;
}
if ($clean_filename =~ m{^$temp_d/}) {
$clean_filename =~ s{^$temp_d/}{};
last;
}
}
if ($ON_WINDOWS and $opt_by_file) { # then go back from / to \
if ($opt_json) {
$clean_filename =~ s{/}{\\\\}g;
} else {
$clean_filename =~ s{/}{\\}g;
}
}
return $clean_filename;
} # 1}}}
sub generate_sql { # {{{1
my ($elapsed_sec, # in
$rhh_count , # in count{TYPE}{lang|code|blank|comment|scaled}
$rh_scale , # in
) = @_;
print "-> generate_sql\n" if $opt_v > 2;
#print "generate_sql A [$opt_sql_project]\n";
$opt_sql_project = cwd() unless defined $opt_sql_project;
$opt_sql_project = '' unless defined $opt_sql_project; # have seen cwd() fail
#print "generate_sql B [$opt_sql_project]\n";
$opt_sql_project =~ s{/}{\\}g if $ON_WINDOWS;
#print "generate_sql C [$opt_sql_project]\n";
my $schema = undef;
if ($opt_sql_style eq "oracle") {
$schema = "
CREATE TABLE metadata
(
timestamp TIMESTAMP,
project VARCHAR2(500 CHAR),
elapsed_s NUMBER(10, 6)
)
/
CREATE TABLE t
(
project VARCHAR2(500 CHAR),
language VARCHAR2(500 CHAR),
file_fullname VARCHAR2(500 CHAR),
file_dirname VARCHAR2(500 CHAR),
file_basename VARCHAR2(500 CHAR),
nblank INTEGER,
ncomment INTEGER,
ncode INTEGER,
nscaled NUMBER(10, 6)
)
/
";
} else {
$schema = "
create table metadata ( -- $URL v $VERSION
timestamp varchar(500),
Project varchar(500),
elapsed_s real);
create table t (
Project varchar(500) ,
Language varchar(500) ,
File varchar(500) ,
File_dirname varchar(500) ,
File_basename varchar(500) ,
nBlank integer ,
nComment integer ,
nCode integer ,
nScaled real );
";
}
$opt_sql = "-" if $opt_sql eq "1";
my $open_mode = ">";
$open_mode = ">>" if $opt_sql_append;
my $fh = new IO::File; # $opt_sql, "w";
if (!$fh->open("${open_mode}${opt_sql}")) {
die "Unable to write to $opt_sql $!\n";
}
print $fh $schema unless defined $opt_sql_append;
my $insert_into_t = "insert into t ";
if ($opt_sql_style eq "oracle") {
printf $fh "insert into metadata values(TO_TIMESTAMP('%s','yyyy-mm-dd hh24:mi:ss'), '%s', %f);\n",
strftime("%Y-%m-%d %H:%M:%S", localtime(time())),
$opt_sql_project, $elapsed_sec;
} elsif ($opt_sql_style eq "named_columns") {
print $fh "begin transaction;\n";
$insert_into_t .= "( Project, Language, File, File_dirname, File_basename, nBlank, nComment, nCode, nScaled )";
} else {
print $fh "begin transaction;\n";
printf $fh "insert into metadata values('%s', '%s', %f);\n",
strftime("%Y-%m-%d %H:%M:%S", localtime(time())),
$opt_sql_project, $elapsed_sec;
}
my $nIns = 0;
foreach my $file (keys %{$rhh_count}) {
my $language = $rhh_count->{$file}{'lang'};
my $clean_filename = $file;
# If necessary (that is, if the input contained an
# archive file [.tar.gz, etc]), strip the temporary
# directory name which was used to expand the archive
# from the file name.
$clean_filename = rm_leading_tempdir($clean_filename, \%TEMP_DIR);
$clean_filename =~ s/\'/''/g; # double embedded single quotes
# to escape them
printf $fh "$insert_into_t values('%s', '%s', '%s', '%s', '%s', " .
"%d, %d, %d, %f);\n",
$opt_sql_project ,
$language ,
$clean_filename ,
dirname( $clean_filename) ,
basename($clean_filename) ,
$rhh_count->{$file}{'blank'},
$rhh_count->{$file}{'comment'},
$rhh_count->{$file}{'code'} ,
$rhh_count->{$file}{'code'}*$rh_scale->{$language};
++$nIns;
if (!($nIns % 10_000) and ($opt_sql_style ne "oracle")) {
print $fh "commit;\n";
print $fh "begin transaction;\n";
}
}
if ($opt_sql_style ne "oracle") {
print $fh "commit;\n";
}
$fh->close unless $opt_sql eq "-"; # don't try to close STDOUT
print "<- generate_sql\n" if $opt_v > 2;
# sample query:
#
# select project, language,
# sum(nCode) as Code,
# sum(nComment) as Comments,
# sum(nBlank) as Blank,
# sum(nCode)+sum(nComment)+sum(nBlank) as All_Lines,
# 100.0*sum(nComment)/(sum(nCode)+sum(nComment)) as Comment_Pct
# from t group by Project, Language order by Project, Code desc;
#
} # 1}}}
sub output_header { # {{{1
my ($header_line,
$hyphen_line,
$BY_FILE ,) = @_;
print "-> output_header\n" if $opt_v > 2;
my @R = ();
if ($opt_xml) {
if (!$ALREADY_SHOWED_XML_SECTION) {
push @R, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>";
push @R, '<?xml-stylesheet type="text/xsl" href="' .
$opt_xsl . '"?>' if $opt_xsl;
push @R, "<results>";
push @R, "<header>$header_line</header>";
$ALREADY_SHOWED_XML_SECTION = 1;
}
if ($BY_FILE) {
push @R, "<files>";
} else {
push @R, "<languages>";
}
} elsif ($opt_yaml) {
push @R, "---\n# $header_line";
} elsif ($opt_csv or $opt_md) {
# append the header to the end of the column headers
# to keep the output a bit cleaner from a spreadsheet
# perspective
} else {
if ($ALREADY_SHOWED_HEADER) {
push @R, "";
} else {
push @R, $header_line;
$ALREADY_SHOWED_HEADER = 1;
}
push @R, $hyphen_line;
}
print "<- output_header\n" if $opt_v > 2;
return @R;
} # 1}}}
sub generate_report { # {{{1
# returns an array of lines containing the results
my ($version , # in
$elapsed_sec, # in
$report_type, # in "by language" | "by report file" | "by file"
$rhh_count , # in count{TYPE}{nFiles|code|blank|comment|scaled}
$rh_scale , # in
) = @_;
print "-> generate_report\n" if $opt_v > 2;
my $DELIM = ",";
$DELIM = $opt_csv_delimiter if defined $opt_csv_delimiter;
$DELIM = "|" if defined $opt_md;
my @results = ();
my $languages = ();
my $sum_files = 0;
my $sum_code = 0;
my $sum_blank = 0;
my $sum_comment = 0;
my $max_len = 0;
foreach my $language (keys %{$rhh_count}) {
$sum_files += $rhh_count->{$language}{'nFiles'} ;
$sum_blank += $rhh_count->{$language}{'blank'} ;
$sum_comment += $rhh_count->{$language}{'comment'};
$sum_code += $rhh_count->{$language}{'code'} ;
$max_len = length($language) if length($language) > $max_len;
}
my $column_1_offset = 0;
$column_1_offset = $max_len - 17 if $max_len > 17;
my $sum_lines = $sum_blank + $sum_comment + $sum_code;
$elapsed_sec = 0.5 unless $elapsed_sec;
my $spacing_0 = 23;
my $spacing_1 = 13;
my $spacing_2 = 9;
my $spacing_3 = 17;
if (!$opt_3) {
$spacing_1 = 19;
$spacing_2 = 14;
$spacing_3 = 27;
}
$spacing_0 += $column_1_offset;
$spacing_1 += $column_1_offset;
$spacing_3 += $column_1_offset;
my %Format = (
'1' => { 'xml' => 'name="%s" ',
'txt' => "\%-${spacing_0}s ",
},
'2' => { 'xml' => 'name="%s" ',
'txt' => "\%-${spacing_3}s ",
},
'3' => { 'xml' => 'files_count="%d" ',
'txt' => '%6d ',
},
'4' => { 'xml' => 'blank="%d" comment="%d" code="%d" ',
'txt' => "\%${spacing_2}d \%${spacing_2}d \%${spacing_2}d",
},
'5' => { 'xml' => 'blank="%3.2f" comment="%3.2f" code="%d" ',
'txt' => "\%14.2f \%14.2f \%${spacing_2}d",
},
'6' => { 'xml' => 'factor="%.2f" scaled="%.2f" ',
'txt' => ' x %6.2f = %14.2f',
},
);
my $Style = "txt";
$Style = "xml" if $opt_xml ;
$Style = "xml" if $opt_yaml; # not a typo; just set to anything but txt
$Style = "xml" if $opt_json; # not a typo; just set to anything but txt
$Style = "xml" if $opt_csv ; # not a typo; just set to anything but txt
my $hyphen_line = sprintf "%s", '-' x (79 + $column_1_offset);
$hyphen_line = sprintf "%s", '-' x (68 + $column_1_offset)
if (!$opt_sum_reports) and (!$opt_3) and (68 + $column_1_offset) > 79;
my $data_line = "";
my $first_column;
my $BY_LANGUAGE = 0;
my $BY_FILE = 0;
if ($report_type eq "by language") {
$first_column = "Language";
$BY_LANGUAGE = 1;
} elsif ($report_type eq "by file") {
$first_column = "File";
$BY_FILE = 1;
} elsif ($report_type eq "by report file") {
$first_column = "File";
} else {
$first_column = "Report File";
}
my $header_line = sprintf "%s v %s", $URL, $version;
$header_line .= sprintf(" T=%.2f s (%.1f files/s, %.1f lines/s)",
$elapsed_sec ,
$sum_files/$elapsed_sec,
$sum_lines/$elapsed_sec) unless $opt_sum_reports or $opt_hide_rate;
if ($opt_xml or $opt_yaml or $opt_json) {
if (!$ALREADY_SHOWED_HEADER) {
if ($opt_by_file_by_lang and $opt_json) {
push @results, '{ "by_file" : ';
}
push @results, xml_yaml_or_json_header($URL, $version, $elapsed_sec,
$sum_files, $sum_lines, $BY_FILE);
# $ALREADY_SHOWED_HEADER = 1 unless $opt_sum_reports;
# --sum-reports yields two xml or yaml files, one by
# language and one by report file, each of which needs a header
}
if ($opt_xml) {
if ($BY_FILE or ($report_type eq "by report file")) {
push @results, "<files>";
} else {
push @results, "<languages>";
}
}
} else {
push @results, output_header($header_line, $hyphen_line, $BY_FILE);
}
if ($Style eq "txt") {
# column headers
if (!$opt_3 and $BY_FILE) {
my $spacing_n = $spacing_1 - 11;
$data_line = sprintf "%-${spacing_n}s ", $first_column;
} else {
$data_line = sprintf "%-${spacing_1}s ", $first_column;
}
if ($BY_FILE) {
$data_line .= sprintf "%${spacing_2}s " , " " ;
} else {
$data_line .= sprintf "%${spacing_2}s " , "files";
}
my $PCT_symbol = "";
$PCT_symbol = " \%" if $opt_by_percent;
$data_line .= sprintf "%${spacing_2}s %${spacing_2}s %${spacing_2}s",
"blank${PCT_symbol}" ,
"comment${PCT_symbol}" ,
"code";
$data_line .= sprintf " %8s %14s",
"scale" ,
"3rd gen. equiv"
if $opt_3;
if ($opt_md) {
my @col_header = ();
if ($data_line =~ m{\s%}) {
$data_line =~ s{\s%}{_%}g;
foreach my $w ( split(' ', $data_line) ) {
$w =~ s{_%}{ %};
push @col_header, $w;
}
} else {
push @col_header, split(' ', $data_line);
}
my @col_hyphens = ( '-------:') x scalar(@col_header);
$col_hyphens[0] = ':-------'; # first column left justified
push @results, join("|", @col_header );
push @results, join("|", @col_hyphens);
} else {
push @results, $data_line;
push @results, $hyphen_line;
}
}
if ($opt_csv) {
my $header2;
if ($BY_FILE) {
$header2 = "language${DELIM}filename";
} else {
$header2 = "files${DELIM}language";
}
$header2 .= "${DELIM}blank${DELIM}comment${DELIM}code";
$header2 .= "${DELIM}scale${DELIM}3rd gen. equiv" if $opt_3;
$header2 .= ${DELIM} . '"' . $header_line . '"';
push @results, $header2;
}
my $sum_scaled = 0;
foreach my $lang_or_file (sort {
$rhh_count->{$b}{'code'} <=>
$rhh_count->{$a}{'code'}
or $a cmp $b
}
keys %{$rhh_count}) {
next if $lang_or_file eq "by report file";
my ($factor, $scaled);
if ($BY_LANGUAGE or $BY_FILE) {
$factor = 1;
if ($BY_LANGUAGE) {
if (defined $rh_scale->{$lang_or_file}) {
$factor = $rh_scale->{$lang_or_file};
} else {
warn "No scale factor for $lang_or_file; using 1.00";
}
} else { # by individual code file
if ($report_type ne "by report file") {
next unless defined $rhh_count->{$lang_or_file}{'lang'};
next unless defined $rh_scale->{$rhh_count->{$lang_or_file}{'lang'}};
$factor = $rh_scale->{$rhh_count->{$lang_or_file}{'lang'}};
}
}
$scaled = $factor*$rhh_count->{$lang_or_file}{'code'};
} else {
if (!defined $rhh_count->{$lang_or_file}{'scaled'}) {
$opt_3 = 0;
# If we're summing together files previously generated
# with --no3 then rhh_count->{$lang_or_file}{'scaled'}
# this variable will be undefined. That should only
# happen when summing together by file however.
} elsif ($BY_LANGUAGE) {
warn "Missing scaled language info for $lang_or_file\n";
}
if ($opt_3) {
$scaled = $rhh_count->{$lang_or_file}{'scaled'};
$factor = $scaled/$rhh_count->{$lang_or_file}{'code'};
}
}
if ($BY_FILE) {
my $clean_filename = rm_leading_tempdir($lang_or_file, \%TEMP_DIR);
$clean_filename = xml_metachars($clean_filename) if $opt_xml;
$data_line = sprintf $Format{'1'}{$Style}, $clean_filename;
} else {
$data_line = sprintf $Format{'2'}{$Style}, $lang_or_file;
}
$data_line .= sprintf $Format{3}{$Style} ,
$rhh_count->{$lang_or_file}{'nFiles'} unless $BY_FILE;
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent ,
$rhh_count->{$lang_or_file}{'code'} ,
$rhh_count->{$lang_or_file}{'comment'},
$rhh_count->{$lang_or_file}{'blank'} );
$data_line .= sprintf $Format{5}{$Style} ,
$rhh_count->{$lang_or_file}{'blank'} / $DEN * 100,
$rhh_count->{$lang_or_file}{'comment'} / $DEN * 100,
$rhh_count->{$lang_or_file}{'code'} ;
} else {
$data_line .= sprintf $Format{4}{$Style} ,
$rhh_count->{$lang_or_file}{'blank'} ,
$rhh_count->{$lang_or_file}{'comment'},
$rhh_count->{$lang_or_file}{'code'} ;
}
$data_line .= sprintf $Format{6}{$Style} ,
$factor ,
$scaled if $opt_3;
$sum_scaled += $scaled if $opt_3;
if ($opt_xml) {
if (defined $rhh_count->{$lang_or_file}{'lang'}) {
my $lang = $rhh_count->{$lang_or_file}{'lang'};
if (!defined $languages->{$lang}) {
$languages->{$lang} = $lang;
}
$data_line.=' language="' . $lang . '" ';
}
if ($BY_FILE or ($report_type eq "by report file")) {
push @results, " <file " . $data_line . "/>";
} else {
push @results, " <language " . $data_line . "/>";
}
} elsif ($opt_yaml or $opt_json) {
my ($Q, $open_B, $close_B, $start, $C) = yaml_to_json_separators();
if ($opt_yaml) {
# YAML: force quoted language or filename in case these
# have embedded funny characters, issue #312
push @results,"'" . rm_leading_tempdir($lang_or_file, \%TEMP_DIR). "' :$open_B";
} else {
push @results,"${Q}" . rm_leading_tempdir($lang_or_file, \%TEMP_DIR). "${Q} :$open_B";
}
push @results," ${Q}nFiles${Q}: " . $rhh_count->{$lang_or_file}{'nFiles'} . $C
unless $BY_FILE;
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent ,
$rhh_count->{$lang_or_file}{'code'} ,
$rhh_count->{$lang_or_file}{'comment'},
$rhh_count->{$lang_or_file}{'blank'} );
push @results," ${Q}blank_pct${Q}: " .
sprintf("%3.2f", $rhh_count->{$lang_or_file}{'blank'} / $DEN * 100) . $C;
push @results," ${Q}comment_pct${Q}: " .
sprintf("%3.2f", $rhh_count->{$lang_or_file}{'comment'} / $DEN * 100) . $C;
push @results," ${Q}code${Q}: " . $rhh_count->{$lang_or_file}{'code'} . $C;
} else {
push @results," ${Q}blank${Q}: " . $rhh_count->{$lang_or_file}{'blank'} . $C;
push @results," ${Q}comment${Q}: " . $rhh_count->{$lang_or_file}{'comment'} . $C;
push @results," ${Q}code${Q}: " . $rhh_count->{$lang_or_file}{'code'} . $C;
}
push @results," ${Q}language${Q}: " . $Q . $rhh_count->{$lang_or_file}{'lang'} . $Q . $C
if $BY_FILE;
if ($opt_3) {
push @results, " ${Q}scaled${Q}: " . $scaled . $C;
push @results, " ${Q}factor${Q}: " . $factor . $C;
}
if ($opt_json) { # replace the trailing comma with }, on the last line
$results[-1] =~ s/,\s*$/},/;
}
} elsif ($opt_csv or $opt_md) {
my $extra_3 = "";
$extra_3 = "${DELIM}$factor${DELIM}$scaled" if $opt_3;
my $first_column = undef;
my $clean_name = $lang_or_file;
my $str;
if ($opt_csv) {
if ($BY_FILE) {
$first_column = $rhh_count->{$lang_or_file}{'lang'};
$clean_name = rm_leading_tempdir($lang_or_file, \%TEMP_DIR);
} else {
$first_column = $rhh_count->{$lang_or_file}{'nFiles'};
}
$str = $first_column . ${DELIM} .
$clean_name . ${DELIM};
} else {
if ($BY_FILE) {
$first_column = $rhh_count->{$lang_or_file}{'lang'};
$clean_name = rm_leading_tempdir($lang_or_file, \%TEMP_DIR);
$str = $clean_name . ${DELIM};
} else {
$first_column = $rhh_count->{$lang_or_file}{'nFiles'};
$str = $clean_name . ${DELIM} .
$first_column . ${DELIM};
}
}
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent ,
$rhh_count->{$lang_or_file}{'code'} ,
$rhh_count->{$lang_or_file}{'comment'},
$rhh_count->{$lang_or_file}{'blank'} );
$str .= sprintf("%3.2f", $rhh_count->{$lang_or_file}{'blank'} / $DEN * 100) . ${DELIM} .
sprintf("%3.2f", $rhh_count->{$lang_or_file}{'comment'} / $DEN * 100) . ${DELIM} .
$rhh_count->{$lang_or_file}{'code'};
} else {
$str .= $rhh_count->{$lang_or_file}{'blank'} . ${DELIM} .
$rhh_count->{$lang_or_file}{'comment'}. ${DELIM} .
$rhh_count->{$lang_or_file}{'code'};
}
$str .= $extra_3;
push @results, $str;
} else {
push @results, $data_line;
}
}
my $avg_scale = 1; # weighted average of scale factors
$avg_scale = sprintf("%.2f", $sum_scaled / $sum_code)
if $sum_code and $opt_3;
if ($opt_xml) {
$data_line = "";
if (!$BY_FILE) {
$data_line .= sprintf "sum_files=\"%d\" ", $sum_files;
}
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent ,
$sum_code, $sum_comment, $sum_blank);
$data_line .= sprintf $Format{'5'}{$Style},
$sum_blank / $DEN * 100,
$sum_comment / $DEN * 100,
$sum_code ;
} else {
$data_line .= sprintf $Format{'4'}{$Style},
$sum_blank ,
$sum_comment ,
$sum_code ;
}
$data_line .= sprintf $Format{'6'}{$Style},
$avg_scale ,
$sum_scaled if $opt_3;
push @results, " <total " . $data_line . "/>";
if ($BY_FILE or ($report_type eq "by report file")) {
push @results, "</files>";
} else {
foreach my $language (keys %{$languages}) {
push @results, ' <language name="' . $language . '"/>';
}
push @results, "</languages>";
}
if (!$opt_by_file_by_lang or $ALREADY_SHOWED_XML_SECTION) {
push @results, "</results>";
} else {
$ALREADY_SHOWED_XML_SECTION = 1;
}
} elsif ($opt_yaml or $opt_json) {
my ($Q, $open_B, $close_B, $start, $C) = yaml_to_json_separators();
push @results, "${Q}SUM${Q}: ${open_B}";
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent ,
$sum_code, $sum_comment, $sum_blank);
push @results, " ${Q}blank${Q}: " . sprintf("%.2f", $sum_blank / $DEN * 100) . $C;
push @results, " ${Q}comment${Q}: ". sprintf("%.2f", $sum_comment / $DEN * 100) . $C;
push @results, " ${Q}code${Q}: " . $sum_code . $C;
} else {
push @results, " ${Q}blank${Q}: " . $sum_blank . $C;
push @results, " ${Q}comment${Q}: ". $sum_comment . $C;
push @results, " ${Q}code${Q}: " . $sum_code . $C;
}
push @results, " ${Q}nFiles${Q}: " . $sum_files . $C;
if ($opt_3) {
push @results, " ${Q}scaled${Q}: " . $sum_scaled . $C;
push @results, " ${Q}factor${Q}: " . $avg_scale . $C;
}
if ($opt_json) {
$results[-1] =~ s/,\s*$/} }/;
if ($opt_by_file_by_lang) {
if ($ALREADY_SHOWED_HEADER) {
$results[-1] .= ' }';
} else {
$results[-1] .= ', "by_lang" : {';
}
}
}
} elsif ($opt_csv) {
my @entries = ();
if ($opt_by_file) {
push @entries, "SUM";
push @entries, "";
} else {
push @entries, $sum_files;
push @entries, "SUM";
}
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent ,
$sum_code, $sum_comment, $sum_blank);
push @entries, sprintf("%.2f", $sum_blank / $DEN * 100);
push @entries, sprintf("%.2f", $sum_comment / $DEN * 100);
} else {
push @entries, $sum_blank;
push @entries, $sum_comment;
}
push @entries, $sum_code;
if ($opt_3) {
push @entries, $sum_scaled;
push @entries, $avg_scale ;
}
push @results, join(",", @entries);
} else {
if ($BY_FILE) {
$data_line = sprintf "%-${spacing_0}s ", "SUM:" ;
} else {
$data_line = sprintf "%-${spacing_1}s ", "SUM:" ;
$data_line .= sprintf "%${spacing_2}d ", $sum_files;
}
if ($opt_by_percent) {
my $DEN = compute_denominator($opt_by_percent ,
$sum_code, $sum_comment, $sum_blank);
$data_line .= sprintf $Format{'5'}{$Style},
$sum_blank / $DEN * 100,
$sum_comment / $DEN * 100,
$sum_code ;
} else {
$data_line .= sprintf $Format{'4'}{$Style},
$sum_blank ,
$sum_comment ,
$sum_code ;
}
$data_line .= sprintf $Format{'6'}{$Style},
$avg_scale ,
$sum_scaled if $opt_3;
if ($opt_md) {
my @words = split(' ', $data_line);
my $n_cols = scalar(@words);
# my $n_cols = scalar(split(' ', $data_line)); # deprecated
$data_line =~ s/\s+/\|/g;
my @col_hyphens = ( '--------') x $n_cols;
push @results, join("|", @col_hyphens);
push @results, $data_line if $sum_files > 1 or $opt_sum_one;
unshift @results, ( "cloc|$header_line", "--- | ---", "", );
} else {
push @results, $hyphen_line if $sum_files > 1 or $opt_sum_one;
push @results, $data_line if $sum_files > 1 or $opt_sum_one;
push @results, $hyphen_line;
}
}
write_xsl_file() if $opt_xsl and $opt_xsl eq $CLOC_XSL;
$ALREADY_SHOWED_HEADER = 1 unless $opt_sum_reports;
print "<- generate_report\n" if $opt_v > 2;
return @results;
} # 1}}}
sub print_errors { # {{{1
my ($rh_Error_Codes, # in
$raa_errors , # in
) = @_;
print "-> print_errors\n" if $opt_v > 2;
my %error_string = reverse(%{$rh_Error_Codes});
my $nErrors = scalar @{$raa_errors};
warn sprintf "\n%d error%s:\n", plural_form(scalar @Errors);
for (my $i = 0; $i < $nErrors; $i++) {
warn sprintf "%s: %s\n",
$error_string{ $raa_errors->[$i][0] },
$raa_errors->[$i][1] ;
}
print "<- print_errors\n" if $opt_v > 2;
} # 1}}}
sub write_lang_def { # {{{1
my ($file ,
$rh_Language_by_Extension , # in
$rh_Language_by_Script , # in
$rh_Language_by_File , # in
$rhaa_Filters_by_Language , # in
$rh_Not_Code_Extension , # in
$rh_Not_Code_Filename , # in
$rh_Scale_Factor , # in
$rh_EOL_Continuation_re , # in
) = @_;
print "-> write_lang_def($file)\n" if $opt_v > 2;
my @outlines = ();
foreach my $language (sort keys %{$rhaa_Filters_by_Language}) {
next if $language =~ /(Brain|\(unknown\))/;
next if defined $Extension_Collision{$language};
push @outlines, $language;
foreach my $filter (@{$rhaa_Filters_by_Language->{$language}}) {
my $line = "";
$line .= sprintf " filter %s", $filter->[0];
$line .= sprintf " %s", $filter->[1] if defined $filter->[1];
# $filter->[0] == 'remove_between_general',
# 'remove_between_regex', and
# 'remove_matches_2re' have two args
$line .= sprintf " %s", $filter->[2] if defined $filter->[2];
# $filter->[0] == 'replace_between_regex' has three or four args
$line .= sprintf " %s", $filter->[3] if defined $filter->[3];
$line .= sprintf " %s", $filter->[4] if defined $filter->[4];
push @outlines, $line;
}
# file extension won't appear if the extension maps to
# multiple languages; work around this
my $found = 0;
foreach my $ext (sort keys %{$rh_Language_by_Extension}) {
if ($language eq $rh_Language_by_Extension->{$ext}) {
push @outlines, sprintf " extension %s\n", $ext;
$found = 1;
}
}
if (!$found and $opt_write_lang_def_incl_dup) {
foreach my $multilang (sort keys %Extension_Collision) {
my %Languages = map { $_ => 1 } split('/', $multilang);
next unless $Languages{$language};
foreach my $ext (@{$Extension_Collision{$multilang}}) {
push @outlines, sprintf " extension %s\n", $ext;
}
}
}
foreach my $filename (sort keys %{$rh_Language_by_File}) {
if ($language eq $rh_Language_by_File->{$filename}) {
push @outlines, sprintf " filename %s\n", $filename;
}
}
foreach my $script_exe (sort keys %{$rh_Language_by_Script}) {
if ($language eq $rh_Language_by_Script->{$script_exe}) {
push @outlines, sprintf " script_exe %s\n", $script_exe;
}
}
push @outlines, sprintf " 3rd_gen_scale %.2f\n", $rh_Scale_Factor->{$language};
if (defined $rh_EOL_Continuation_re->{$language}) {
push @outlines, sprintf " end_of_line_continuation %s\n",
$rh_EOL_Continuation_re->{$language};
}
}
write_file($file, {}, @outlines);
print "<- write_lang_def\n" if $opt_v > 2;
} # 1}}}
sub read_lang_def { # {{{1
my ($file ,
$rh_Language_by_Extension , # out
$rh_Language_by_Script , # out
$rh_Language_by_File , # out
$rhaa_Filters_by_Language , # out
$rh_Not_Code_Extension , # out
$rh_Not_Code_Filename , # out
$rh_Scale_Factor , # out
$rh_EOL_Continuation_re , # out
$rh_EOL_abc,
) = @_;
print "-> read_lang_def($file)\n" if $opt_v > 2;
my $IN = new IO::File $file, "r";
die "Unable to read $file.\n" unless defined $IN;
my $language = "";
while (<$IN>) {
next if /^\s*#/ or /^\s*$/;
if (/^(\w+.*?)\s*$/) {
$language = $1;
next;
}
die "Missing computer language name, line $. of $file\n"
unless $language;
if (/^\s{4}filter\s+(remove_between_(general|2re|regex))
\s+(\S+)\s+(\S+)\s*$/x) {
push @{$rhaa_Filters_by_Language->{$language}}, [
$1 , $3 , $4 ]
} elsif (/^\s{4}filter\s+(replace_between_regex)
\s+(\S+)\s+(\S+)\s+(\S+|\".*\")\s+(\S+)\s*$/x) {
push @{$rhaa_Filters_by_Language->{$language}}, [
$1 , $2 , $3 , $4 , $5]
} elsif (/^\s{4}filter\s+(replace_between_regex)
\s+(\S+)\s+(\S+)\s+(.*?)\s*$/x) {
push @{$rhaa_Filters_by_Language->{$language}}, [
$1 , $2 , $3 , $4 ]
} elsif (/^\s{4}filter\s+(replace_regex)\s+(\S+)\s*$/) {
push @{$rhaa_Filters_by_Language->{$language}}, [
$1 , $2 , '' ]
} elsif (/^\s{4}filter\s+(replace_regex)
\s+(\S+)\s+(.+?)\s*$/x) {
push @{$rhaa_Filters_by_Language->{$language}}, [
$1 , $2 , $3 ]
} elsif (/^\s{4}filter\s+(\w+)\s*$/) {
push @{$rhaa_Filters_by_Language->{$language}}, [ $1 ]
} elsif (/^\s{4}filter\s+(\w+)\s+(.*?)\s*$/) {
push @{$rhaa_Filters_by_Language->{$language}}, [ $1 , $2 ]
} elsif (/^\s{4}extension\s+(\S+)\s*$/) {
if (defined $rh_Language_by_Extension->{$1}) {
die "File extension collision: $1 ",
"maps to languages '$rh_Language_by_Extension->{$1}' ",
"and '$language'\n" ,
"Edit $file and remove $1 from one of these two ",
"language definitions.\n";
}
$rh_Language_by_Extension->{$1} = $language;
} elsif (/^\s{4}filename\s+(\S+)\s*$/) {
$rh_Language_by_File->{$1} = $language;
} elsif (/^\s{4}script_exe\s+(\S+)\s*$/) {
$rh_Language_by_Script->{$1} = $language;
} elsif (/^\s{4}3rd_gen_scale\s+(\S+)\s*$/) {
$rh_Scale_Factor->{$language} = $1;
} elsif (/^\s{4}end_of_line_continuation\s+(\S+)\s*$/) {
$rh_EOL_Continuation_re->{$language} = $1;
} else {
die "Unexpected data line $. of $file:\n$_\n";
}
}
$IN->close;
print "<- read_lang_def\n" if $opt_v > 2;
} # 1}}}
sub merge_lang_def { # {{{1
my ($file ,
$rh_Language_by_Extension , # in/out
$rh_Language_by_Script , # in/out
$rh_Language_by_File , # in/out
$rhaa_Filters_by_Language , # in/out
$rh_Not_Code_Extension , # in/out
$rh_Not_Code_Filename , # in/out
$rh_Scale_Factor , # in/out
$rh_EOL_Continuation_re , # in/out
$rh_EOL_abc,
) = @_;
print "-> merge_lang_def($file)\n" if $opt_v > 2;
my $IN = new IO::File $file, "r";
die "Unable to read $file.\n" unless defined $IN;
my $language = "";
my $already_know_it = undef;
while (<$IN>) {
next if /^\s*#/ or /^\s*$/;
if (/^(\w+.*?)\s*$/) {
$language = $1;
$already_know_it = defined $rh_Scale_Factor->{$language};
next;
}
die "Missing computer language name, line $. of $file\n"
unless $language;
if (/^\s{4}filter\s+(remove_between_(general|2re|regex))
\s+(\S+)\s+(\S+)\s*$/x) {
next if $already_know_it;
push @{$rhaa_Filters_by_Language->{$language}}, [
$1 , $3 , $4 ]
} elsif (/^\s{4}filter\s+(replace_between_regex)
\s+(\S+)\s+(\S+)\s+(\S+|\".*\")\s+(\S+)\s*$/x) {
next if $already_know_it;
push @{$rhaa_Filters_by_Language->{$language}}, [
$1 , $2 , $3 , $4 , $5]
} elsif (/^\s{4}filter\s+(replace_between_regex)
\s+(\S+)\s+(\S+)\s+(.*?)\s*$/x) {
next if $already_know_it;
push @{$rhaa_Filters_by_Language->{$language}}, [
$1 , $2 , $3 , $4 ]
} elsif (/^\s{4}filter\s+(replace_regex)
\s+(\S+)\s+(.+?)\s*$/x) {
next if $already_know_it;
push @{$rhaa_Filters_by_Language->{$language}}, [
$1 , $2 , $3 ]
} elsif (/^\s{4}filter\s+(\w+)\s*$/) {
next if $already_know_it;
push @{$rhaa_Filters_by_Language->{$language}}, [ $1 ]
} elsif (/^\s{4}filter\s+(\w+)\s+(.*?)\s*$/) {
next if $already_know_it;
push @{$rhaa_Filters_by_Language->{$language}}, [ $1 , $2 ]
} elsif (/^\s{4}extension\s+(\S+)\s*$/) {
next if $already_know_it;
if (defined $rh_Language_by_Extension->{$1}) {
die "File extension collision: $1 ",
"maps to languages '$rh_Language_by_Extension->{$1}' ",
"and '$language'\n" ,
"Edit $file and remove $1 from one of these two ",
"language definitions.\n";
}
$rh_Language_by_Extension->{$1} = $language;
} elsif (/^\s{4}filename\s+(\S+)\s*$/) {
next if $already_know_it;
$rh_Language_by_File->{$1} = $language;
} elsif (/^\s{4}script_exe\s+(\S+)\s*$/) {
next if $already_know_it;
$rh_Language_by_Script->{$1} = $language;
} elsif (/^\s{4}3rd_gen_scale\s+(\S+)\s*$/) {
next if $already_know_it;
$rh_Scale_Factor->{$language} = $1;
} elsif (/^\s{4}end_of_line_continuation\s+(\S+)\s*$/) {
next if $already_know_it;
$rh_EOL_Continuation_re->{$language} = $1;
} else {
die "Unexpected data line $. of $file:\n$_\n";
}
}
$IN->close;
print "<- merge_lang_def\n" if $opt_v > 2;
} # 1}}}
sub print_extension_info { # {{{1
my ($extension,) = @_;
if ($extension) { # show information on this extension
foreach my $ext (sort {lc $a cmp lc $b or $a cmp $b } keys %Language_by_Extension) {
# Language_by_Extension{f} = 'Fortran 77'
next if $Language_by_Extension{$ext} =~ /Brain/;
printf "%-15s -> %s\n", $ext, $Language_by_Extension{$ext}
if $ext =~ m{$extension}i;
}
} else { # show information on all extensions
foreach my $ext (sort {lc $a cmp lc $b or $a cmp $b } keys %Language_by_Extension) {
next if $Language_by_Extension{$ext} =~ /Brain/;
# Language_by_Extension{f} = 'Fortran 77'
printf "%-15s -> %s\n", $ext, $Language_by_Extension{$ext};
}
}
} # 1}}}
sub print_language_info { # {{{1
my ($language,
$prefix ,) = @_;
my %extensions = (); # the subset matched by the given $language value
if ($language) { # show information on this language
foreach my $ext (sort {lc $a cmp lc $b or $a cmp $b } keys %Language_by_Extension) {
# Language_by_Extension{f} = 'Fortran 77'
push @{$extensions{$Language_by_Extension{$ext}} }, $ext
if lc $Language_by_Extension{$ext} eq lc $language;
# if $Language_by_Extension{$ext} =~ m{$language}i;
}
} else { # show information on all languages
foreach my $ext (sort {lc $a cmp lc $b or $a cmp $b } keys %Language_by_Extension) {
# Language_by_Extension{f} = 'Fortran 77'
push @{$extensions{$Language_by_Extension{$ext}} }, $ext
}
}
# add exceptions (one file extension mapping to multiple languages)
if (!$language or $language =~ /^(Objective C|MATLAB|Mathematica|MUMPS|Mercury)$/i) {
push @{$extensions{'Objective C'}}, "m";
push @{$extensions{'MATLAB'}} , "m";
push @{$extensions{'Mathematica'}}, "m";
push @{$extensions{'MUMPS'}} , "m";
delete $extensions{'MATLAB/Mathematica/Objective C/MUMPS/Mercury'};
}
if (!$language or $language =~ /^(Lisp|OpenCL)$/i) {
push @{$extensions{'Lisp'}} , "cl";
push @{$extensions{'OpenCL'}}, "cl";
delete $extensions{'Lisp/OpenCL'};
}
if (!$language or $language =~ /^(Lisp|Julia)$/i) {
push @{$extensions{'Lisp'}} , "jl";
push @{$extensions{'Julia'}} , "jl";
delete $extensions{'Lisp/Julia'};
}
if (!$language or $language =~ /^(Perl|Prolog)$/i) {
push @{$extensions{'Perl'}} , "pl";
push @{$extensions{'Prolog'}}, "pl";
delete $extensions{'Perl/Prolog'};
}
if (!$language or $language =~ /^(Raku|Prolog)$/i) {
push @{$extensions{'Perl'}} , "p6";
push @{$extensions{'Prolog'}}, "p6";
delete $extensions{'Perl/Prolog'};
}
if (!$language or $language =~ /^(IDL|Qt Project|Prolog|ProGuard)$/i) {
push @{$extensions{'IDL'}} , "pro";
push @{$extensions{'Qt Project'}}, "pro";
push @{$extensions{'Prolog'}} , "pro";
push @{$extensions{'ProGuard'}} , "pro";
delete $extensions{'IDL/Qt Project/Prolog/ProGuard'};
}
if (!$language or $language =~ /^(D|dtrace)$/i) {
push @{$extensions{'D'}} , "d";
push @{$extensions{'dtrace'}} , "d";
delete $extensions{'D/dtrace'};
}
if (!$language or $language =~ /^Forth$/) {
push @{$extensions{'Forth'}} , "fs";
push @{$extensions{'Forth'}} , "f";
push @{$extensions{'Forth'}} , "for";
delete $extensions{'Fortran 77/Forth'};
delete $extensions{'F#/Forth'};
}
if (!$language or $language =~ /^Fortran 77$/) {
push @{$extensions{'Fortran 77'}}, "f";
push @{$extensions{'Fortran 77'}}, "for";
push @{$extensions{'F#'}} , "fs";
delete $extensions{'Fortran 77/Forth'};
}
if (!$language or $language =~ /^F#$/) {
push @{$extensions{'F#'}} , "fs";
delete $extensions{'F#/Forth'};
}
if (!$language or $language =~ /^(Verilog-SystemVerilog|Coq)$/) {
push @{$extensions{'Coq'}} , "v";
push @{$extensions{'Verilog-SystemVerilog'}} , "v";
delete $extensions{'Verilog-SystemVerilog/Coq'};
}
if (!$language or $language =~ /^(TypeScript|Qt Linguist)$/) {
push @{$extensions{'TypeScript'}} , "ts";
push @{$extensions{'Qt Linguist'}} , "ts";
delete $extensions{'TypeScript/Qt Linguist'};
}
if (!$language or $language =~ /^(Qt|Glade)$/) {
push @{$extensions{'Glade'}} , "ui";
push @{$extensions{'Qt'}} , "ui";
delete $extensions{'Qt/Glade'};
}
if (!$language or $language =~ /^(C#|Smalltalk)$/) {
push @{$extensions{'C#'}} , "cs";
push @{$extensions{'Smalltalk'}} , "cs";
delete $extensions{'C#/Smalltalk'};
}
if (!$language or $language =~ /^(Visual\s+Basic|TeX|Apex\s+Class)$/i) {
push @{$extensions{'Visual Basic'}} , "cls";
push @{$extensions{'TeX'}} , "cls";
push @{$extensions{'Apex Class'}} , "cls";
delete $extensions{'Visual Basic/TeX/Apex Class'};
}
if (!$language or $language =~ /^(Ant)$/i) {
push @{$extensions{'Ant'}} , "build.xml";
delete $extensions{'Ant/XML'};
}
if (!$language or $language =~ /^(Scheme|SaltStack)$/i) {
push @{$extensions{'Scheme'}} , "sls";
push @{$extensions{'SaltStack'}} , "sls";
delete $extensions{'Scheme/SaltStack'};
}
if ($opt_explain) {
return unless $extensions{$language};
if ($prefix) {
printf "%s %s\n", $prefix, join(", ", @{$extensions{$language}});
} else {
printf "%-26s (%s)\n", $language, join(", ", @{$extensions{$language}});
}
} else {
if (%extensions) {
foreach my $lang (sort {lc $a cmp lc $b } keys %extensions) {
next if $lang =~ /Brain/;
if ($prefix) {
printf "%s %s\n", $prefix, join(", ", @{$extensions{$lang}});
} else {
printf "%-26s (%s)\n", $lang, join(", ", @{$extensions{$lang}});
}
}
}
}
} # 1}}}
sub print_language_filters { # {{{1
my ($language,) = @_;
if (!$Filters_by_Language{$language} or
!@{$Filters_by_Language{$language}}) {
warn "Unknown language: $language\n";
warn "Use --show-lang to list all defined languages.\n";
return;
}
printf "%s\n", $language;
foreach my $filter (@{$Filters_by_Language{$language}}) {
printf " filter %s", $filter->[0];
printf " %s", $filter->[1] if defined $filter->[1];
printf " %s", $filter->[2] if defined $filter->[2];
printf " %s", $filter->[3] if defined $filter->[3];
printf " %s", $filter->[4] if defined $filter->[4];
print "\n";
}
print_language_info($language, " extensions:");
} # 1}}}
sub top_level_SMB_dir { # {{{1
# Ref https://github.com/AlDanial/cloc/issues/392, if the
# user supplies a directory name which is an SMB mount
# point, this directory will appear to File::Find as
# though it is empty unless $File::Find::dont_use_nlink
# is set to 1. This subroutine checks to see if any SMB
# mounts (identified from stat()'s fourth entry, nlink,
# having a value of 2) were passed in on the command line.
my ($ra_arg_list,) = @_; # in user supplied file name, directory name, git hash, etc
foreach my $entry (@{$ra_arg_list}) {
next unless -d $entry;
# gets here if $entry is a directory; now get its nlink value
my @stats = stat($entry);
my $nlink = $stats[3];
return 1 if $nlink == 2; # meaning it is an SMB mount
}
return 0;
}
# 1}}}
sub replace_git_hash_with_tarfile { # {{{1
my ($ra_arg_list, # in file name, directory name and/or
# git commit hash to examine
$ra_git_similarity) = @_; # out only if --opt-git-diff-simindex
# replace git hashes in $ra_arg_list with tar files
# Diff mode and count mode behave differently:
# Diff:
# file git_hash
# Extract file from the git repo and only compare to it.
# git_hash1 git_hash2
# Get listings of all files in git_hash1 and git_hash2.
# git ls-tree --name-only -r *git_hash1*
# git ls-tree --name-only -r *git_hash2*
# Next, get listings of files that changed with git_hash1
# and git_hash2.
# git diff-tree -r --no-commit-id --name-only *git_hash1* *git_hash2*
# Finally, make two tar files of git repos1 and 2 where the file
# listing is the union of changes.
# git archive -o tarfile1 *git_hash1* \
# <union of files that changed and exist in this commit>
# git archive -o tarfile2 *git_hash2* \
# <union of files that changed and exist in this commit>
# To avoid "Argument list too long" error, repeat the git
# achive step with chunks of 30,000 files at a time then
# merge the tar files as the final step.
# Regular count:
# Simply make a tar file of all files in the git repo.
my $prt_args = join(",", @{$ra_arg_list});
print "-> replace_git_hash_with_tarfile($prt_args)\n" if $opt_v > 2;
#print "ra_arg_list 1: @{$ra_arg_list}\n";
my $hash_regex = qr/^([a-f\d]{5,40}|master|HEAD)$/;
my %replacement_arg_list = ();
# early exit if none of the inputs look like git hashes
my %git_hash = ();
my $i = 0;
foreach my $file_or_dir (@{$ra_arg_list}) {
++$i;
if (-r $file_or_dir) { # readable file or dir; not a git hash
$replacement_arg_list{$i} = $file_or_dir;
next;
} elsif ($opt_force_git or $file_or_dir =~ m/$hash_regex/) {
$git_hash{$file_or_dir} = $i;
} # else the input can't be understood; ignore for now
}
return unless %git_hash;
my $have_tar_git = external_utility_exists($ON_WINDOWS ? "unzip" : "tar --version") &&
external_utility_exists("git --version");
if (!$have_tar_git) {
warn "One or more inputs looks like a git hash but " .
"either git or tar is unavailable.\n";
return;
}
my %repo_listing = (); # $repo_listing{hash}{files} = 1;
foreach my $hash (sort keys %git_hash) {
my $git_list_cmd = "git ls-tree --name-only -r ";
if ($hash =~ m/(.*?):(.*?)$/) {
# requesting specific file(s) from this hash; grep for them
# Note: this capability not fully implemented yet
$git_list_cmd .= "$1|grep '$2'";
} else {
$git_list_cmd .= $hash;
}
print "$git_list_cmd\n" if $opt_v;
foreach my $file (`$git_list_cmd`) {
$file =~ s/\s+$//;
$repo_listing{$hash}{$file} = 1;
}
}
# logic for each of the modes
if ($opt_diff) {
#print "A DIFF\n";
# set the default git diff algorithm
$opt_git_diff_rel = 1 unless $opt_git_diff_all or
$opt_git_diff_simindex;
# is it git to git, or git to file/dir ?
my ($Left, $Right) = @{$ra_arg_list};
#use Data::Dumper;
#print "diff_listing= "; print Dumper(\%diff_listing);
#print "git_hash= "; print Dumper(\%git_hash);
if ($git_hash{$Left} and $git_hash{$Right}) {
#print "A DIFF git-to-git\n";
# git to git
# first make a union of all files that have changed in both commits
my %files_union = ();
my @left_files = ();
my @right_files = ();
if ($opt_git_diff_rel) {
# Strategy 1: Union files are what git consinders have changed
# between the two commits.
my $git_list_cmd = "git diff-tree -r --no-commit-id --name-only $Left $Right";
# print "$git_list_cmd\n" if $opt_v;
foreach my $file (`$git_list_cmd`) {
chomp($file);
$files_union{$file} = 1;
}
} elsif ($opt_git_diff_all) {
# Strategy 2: Union files all files in both repos.
foreach my $file (keys %{$repo_listing{$Left }},
keys %{$repo_listing{$Right}}) {
$files_union{$file} = 1;
}
} elsif ($opt_git_diff_simindex) {
# Strategy 3: Use git's own similarity index to figure
# out which files to compare.
git_similarity_index($Left , # in
$Right , # in
\@left_files , # out
\@right_files , # out
$ra_git_similarity); # out
}
#use Data::Dumper;
#print "files_union =\n", Dumper(\%files_union);
#print "repo_listing=\n", Dumper(\%repo_listing);
# then make trucated tar files of those union files which
# actually exist in each repo
foreach my $file (sort keys %files_union) {
push @left_files , $file if $repo_listing{$Left }{$file};
push @right_files, $file if $repo_listing{$Right}{$file};
}
# backslash whitespace, weird chars within file names (#257, #284)
# my @Lfiles= map {$_ =~ s/([\s\(\)\[\]{}';\^\$\?])/\\$1/g; $_} @left_files;
# my @Lfiles= @left_files;
if(scalar(@left_files) > 0) {
$replacement_arg_list{$git_hash{$Left}} = git_archive($Left , \@left_files);
} else {
# In the right side commit ONLY file(s) was added, so no file(s) will exist in the left side commit.
# Create empty TAR to detect added lines of code.
$replacement_arg_list{$git_hash{$Left}} = empty_tar();
}
# $replacement_arg_list{$git_hash{$Left}} = git_archive($Left , \@Lfiles);
# my @Rfiles= map {$_ =~ s/([\s\(\)\[\]{}';\^\$\?])/\\$1/g; $_} @right_files ;
# my @Rfiles= @right_files ;
#use Data::Dumper;
#print Dumper('left' , \@left_files);
#print Dumper('right', \@right_files);
#die;
if(scalar(@right_files) > 0) {
$replacement_arg_list{$git_hash{$Right}} = git_archive($Right, \@right_files);
} else {
# In the left side commit ONLY file(s) was deleted, so file(s) will not exist in right side commit.
# Create empty TAR to detect removed lines of code.
$replacement_arg_list{$git_hash{$Right}} = empty_tar();
}
# $replacement_arg_list{$git_hash{$Right}} = git_archive($Right, \@Rfiles);
#write_file("/tmp/Lfiles.txt", {}, sort @Lfiles);
#write_file("/tmp/Rfiles.txt", {}, sort @Rfiles);
#write_file("/tmp/files_union.txt", {}, sort keys %files_union);
} else {
#print "A DIFF git-to-file or file-to-git Left=$Left Right=$Right\n";
# git to file/dir or file/dir to git
if ($git_hash{$Left} and $repo_listing{$Left}{$Right} ) {
#print "A DIFF 1\n";
# $Left is a git hash and $Right is a file
$replacement_arg_list{$git_hash{$Left}} = git_archive($Left, $Right);
} elsif ($git_hash{$Right} and $repo_listing{$Right}{$Left}) {
#print "A DIFF 2\n";
# $Left is a file and $Right is a git hash
$replacement_arg_list{$git_hash{$Right}} = git_archive($Right, $Left);
} elsif ($git_hash{$Left}) {
#print "A DIFF 3\n";
# assume Right is a directory; tar the entire git archive at this hash
$replacement_arg_list{$git_hash{$Left}} = git_archive($Left, "");
} else {
#print "A DIFF 4\n";
# assume Left is a directory; tar the entire git archive at this hash
$replacement_arg_list{$git_hash{$Right}} = git_archive($Right, "");
}
}
} else {
#print "B COUNT\n";
foreach my $hash (sort keys %git_hash) {
$replacement_arg_list{$git_hash{$hash}} = git_archive($hash);
}
}
# print "git_hash= "; print Dumper(\%git_hash);
#print "repo_listing= "; print Dumper(\%repo_listing);
# replace the input arg list with the new one
@{$ra_arg_list} = ();
foreach my $index (sort {$a <=> $b} keys %replacement_arg_list) {
push @{$ra_arg_list}, $replacement_arg_list{$index};
}
#print "ra_arg_list 2: @{$ra_arg_list}\n";
print "<- replace_git_hash_with_tarfile()\n" if $opt_v > 2;
} # 1}}}
sub git_similarity_index { # {{{
my ($git_hash_Left , # in
$git_hash_Right , # in
$ra_left_files , # out
$ra_right_files , # out
$ra_git_similarity) = @_; # out
die "this option is not yet implemented";
print "-> git_similarity_index($git_hash_Left, $git_hash_Right)\n" if $opt_v > 2;
my $cmd = "git diff -M --name-status $git_hash_Left $git_hash_Right";
print $cmd, "\n" if $opt_v;
open(GSIM, "$cmd |") or die "Unable to run $cmd $!";
while (<GSIM>) {
print "git similarity> $_";
}
close(GSIM);
print "<- git_similarity_index\n" if $opt_v > 2;
} # 1}}}
sub empty_tar { # {{{1
my ($Tarfh, $Tarfile);
if ($opt_sdir) {
File::Path::mkpath($opt_sdir) unless is_dir($opt_sdir);
($Tarfh, $Tarfile) = tempfile(UNLINK => 1, DIR => $opt_sdir, SUFFIX => $ON_WINDOWS ? '.zip' : '.tar'); # delete on exit
} else {
($Tarfh, $Tarfile) = tempfile(UNLINK => 1, SUFFIX => $ON_WINDOWS ? '.zip' : '.tar'); # delete on exit
}
my $cmd = $ON_WINDOWS ? "type nul > $Tarfile" : "tar -cf $Tarfile -T /dev/null";
print $cmd, "\n" if $opt_v;
system $cmd;
if (!-r $Tarfile) {
# not readable
die "Failed to create empty tarfile.";
}
return $Tarfile;
} # 1}}}
sub git_archive { # {{{1
# Invoke 'git archive' as a system command to create a tar file
# using the given argument(s).
my ($A1, $A2) = @_;
print "-> git_archive($A1)\n" if $opt_v > 2;
my $args = undef;
my @File_Set = ( );
my $n_sets = 1;
if (ref $A2 eq 'ARRAY') {
# Avoid "Argument list too long" for the git archive command
# by splitting the inputs into sets of 10,000 files (issue 273).
my $FILES_PER_ARCHIVE = 1_000;
$FILES_PER_ARCHIVE = 100 if $ON_WINDOWS; # github.com/AlDanial/cloc/issues/404
my $n_files = scalar(@{$A2});
$n_sets = $n_files/$FILES_PER_ARCHIVE;
$n_sets = 1 + int($n_sets) if $n_sets > int($n_sets);
$n_sets = 1 if !$n_sets;
foreach my $i (0..$n_sets-1) {
@{$File_Set[$i]} = ( );
my $start = $i*$FILES_PER_ARCHIVE;
my $end = smaller(($i+1)*$FILES_PER_ARCHIVE, $n_files) - 1;
# Wrap each file name in single quotes to protect spaces
# and other odd characters. File names that themselves have
# single quotes are instead wrapped in double quotes. File
# names with both single and double quotes... jeez.
foreach my $fname (@{$A2}[$start .. $end]) {
if ($fname =~ /^".*?\\".*?"$/) {
# git pre-handles filenames with double quotes by backslashing
# each double quote then surrounding entire name in double
# quotes; undo this otherwise archive command crashes
$fname =~ s/\\"/"/g;
$fname =~ s/^"(.*)"$/$1/;
} elsif ($fname =~ /'/ or $ON_WINDOWS) {
push @{$File_Set[$i]}, "\"$fname\"";
} else {
push @{$File_Set[$i]}, "'$fname'";
}
}
unshift @{$File_Set[$i]}, "$A1 "; # prepend git hash to beginning of list
##xx# # don't include \$ in the regex because git handles these correctly
# # to each word in @{$A2}[$start .. $end]: first backslash each
# # single quote, then wrap all entries in single quotes (#320)
# push @File_Set,
# "$A1 " . join(" ", map {$_ =~ s/'/\'/g; $_ =~ s/^(.*)$/'$1'/g; $_}
## "$A1 " . join(" ", map {$_ =~ s/([\s\(\)\[\]{}';\^\?])/\\$1/g; $_}
# @{$A2}[$start .. $end]);
}
} else {
if (defined $A2) {
push @{$File_Set[0]}, "$A1 $A2";
} else {
push @{$File_Set[0]}, "$A1";
}
}
my $files_this_commit = join(" ", @{$File_Set[0]});
print " git_archive(file_set[0]=$files_this_commit)\n" if $opt_v > 2;
my ($Tarfh, $Tarfile);
if ($opt_sdir) {
File::Path::mkpath($opt_sdir) unless is_dir($opt_sdir);
($Tarfh, $Tarfile) = tempfile(UNLINK => 1, DIR => $opt_sdir, SUFFIX => $ON_WINDOWS ? '.zip' : '.tar'); # delete on exit
} else {
($Tarfh, $Tarfile) = tempfile(UNLINK => 1, SUFFIX => $ON_WINDOWS ? '.zip' : '.tar'); # delete on exit
}
my $cmd = "git archive -o $Tarfile $files_this_commit";
print $cmd, "\n" if $opt_v;
system $cmd;
if (!-r $Tarfile or !-s $Tarfile) {
# not readable, or zero sized
die "Failed to create tarfile of files from git.";
}
if ($n_sets > 1) {
foreach my $i (1..$n_sets-1) {
my $files_this_commit = join(" ", @{$File_Set[$i]});
my $cmd = "git archive -o ${Tarfile}_extra $files_this_commit";
print $cmd, "\n" if $opt_v;
system $cmd;
# and merge into the first one
# TODO: on Windows switch to .tar instead of .zip
$cmd = "tar -A -f ${Tarfile} ${Tarfile}_extra";
print $cmd, "\n" if $opt_v;
system $cmd;
}
unlink "${Tarfile}_extra";
}
print "<- git_archive()\n" if $opt_v > 2;
return $Tarfile
} # 1}}}
sub smaller { # {{{1
my( $a, $b ) = @_;
return $a < $b ? $a : $b;
} # 1}}}
sub make_file_list { # {{{1
my ($ra_arg_list, # in file and/or directory names to examine
$rh_Err , # in hash of error codes
$raa_errors , # out errors encountered
$rh_ignored , # out files not recognized as computer languages
) = @_;
print "-> make_file_list(@{$ra_arg_list})\n" if $opt_v > 2;
my ($fh, $filename);
if ($opt_categorized) {
$filename = $opt_categorized;
$fh = new IO::File $filename, "+>"; # open for read/write
die "Unable to write to $filename: $!\n" unless defined $fh;
} elsif ($opt_sdir) {
# write to the user-defined scratch directory
$filename = $opt_sdir . '/cloc_file_list.txt';
$fh = new IO::File $filename, "+>"; # open for read/write
die "Unable to write to $filename: $!\n" unless defined $fh;
} else {
# let File::Temp create a suitable temporary file
($fh, $filename) = tempfile(UNLINK => 1); # delete file on exit
print "Using temp file list [$filename]\n" if $opt_v;
}
my @dir_list = ();
foreach my $file_or_dir (@{$ra_arg_list}) {
#print "make_file_list file_or_dir=$file_or_dir\n";
my $size_in_bytes = 0;
if (!-r $file_or_dir) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file_or_dir];
next;
}
if (is_file($file_or_dir)) {
if (!(-s $file_or_dir)) { # 0 sized file, named pipe, socket
$rh_ignored->{$file_or_dir} = 'zero sized file';
next;
} elsif (-B $file_or_dir and !$opt_read_binary_files) {
# avoid binary files unless user insists on reading them
if ($opt_unicode) {
# only ignore if not a Unicode file w/trivial
# ASCII transliteration
if (!unicode_file($file_or_dir)) {
$rh_ignored->{$file_or_dir} = 'binary file';
next;
}
} else {
$rh_ignored->{$file_or_dir} = 'binary file';
next;
}
}
push @file_list, "$file_or_dir";
} elsif (is_dir($file_or_dir)) {
push @dir_list, $file_or_dir;
} else {
push @{$raa_errors}, [$rh_Err->{'Neither file nor directory'} , $file_or_dir];
$rh_ignored->{$file_or_dir} = 'not file, not directory';
}
}
# apply exclusion rules to file names passed in on the command line
my @new_file_list = ();
foreach my $File (@file_list) {
my ($volume, $directories, $filename) = File::Spec->splitpath( $File );
my $ignore_this_file = 0;
foreach my $Sub_Dir ( File::Spec->splitdir($directories) ) {
if ($Exclude_Dir{$Sub_Dir}) {
$Ignored{$Sub_Dir} = "($File) --exclude-dir=$Sub_Dir";
$ignore_this_file = 1;
last;
}
}
push @new_file_list, $File unless $ignore_this_file;
}
@file_list = @new_file_list;
foreach my $dir (@dir_list) {
#print "make_file_list dir=$dir Exclude_Dir{$dir}=$Exclude_Dir{$dir}\n";
# populates global variable @file_list
if ($Exclude_Dir{$dir}) {
$Ignored{$dir} = "--exclude-dir=$Exclude_Dir{$dir}";
next;
}
find({wanted => \&files ,
preprocess => \&find_preprocessor,
follow => $opt_follow_links }, $dir);
}
if ($opt_follow_links) {
# giving { 'follow' => 1 } to find() makes it skip the
# call to find_preprocessor() so have to call this manually
@file_list = manual_find_preprocessor(@file_list);
}
# there's a possibility of file duplication if user provided a list
# file or --vcs command that returns directory names; squash these
my %unique_file_list = map { $_ => 1 } @file_list;
@file_list = sort keys %unique_file_list;
$nFiles_Found = scalar @file_list;
printf "%8d text file%s.\n", plural_form($nFiles_Found) unless $opt_quiet;
write_file($opt_found, {}, sort @file_list) if $opt_found;
my $nFiles_Categorized = 0;
foreach my $file (@file_list) {
printf "classifying $file\n" if $opt_v > 2;
my $basename = basename $file;
if ($Not_Code_Filename{$basename}) {
$rh_ignored->{$file} = "listed in " . '$' .
"Not_Code_Filename{$basename}";
next;
} elsif ($basename =~ m{~$}) {
$rh_ignored->{$file} = "temporary editor file";
next;
}
my $size_in_bytes = (stat $file)[7];
my $language = "";
if ($All_One_Language) {
# user over-rode auto-language detection by using
# --force-lang with just a language name (no extension)
$language = $All_One_Language;
} else {
$language = classify_file($file ,
$rh_Err ,
$raa_errors,
$rh_ignored);
}
if (!defined $size_in_bytes) {
$rh_ignored->{$file} = "no longer readable";
next;
} elsif (!defined $language) {
$rh_ignored->{$file} = "unable to associate with a language";
next;
}
printf $fh "%d,%s,%s\n", $size_in_bytes, $language, $file;
++$nFiles_Categorized;
#printf "classified %d files\n", $nFiles_Categorized
# unless (!$opt_progress_rate or
# ($nFiles_Categorized % $opt_progress_rate));
}
printf "classified %d files\r", $nFiles_Categorized
if !$opt_quiet and $nFiles_Categorized > 1;
print "<- make_file_list()\n" if $opt_v > 2;
return $fh; # handle to the file containing the list of files to process
} # 1}}}
sub invoke_generator { # {{{1
my ($generator, $ra_user_inputs) = @_;
# If user provided file/directory inputs, only return
# generated files that are in user's request.
# Populates global variable %Ignored.
print "-> invoke_generator($generator)\n" if $opt_v > 2;
open(FH, "$generator |") or
die "Failed to pipe $generator: $!";
my @files = ();
while(<FH>) {
chomp;
my $F = $_;
print "VCS input: $F\n" if $opt_v >= 2;
if (!defined $ra_user_inputs or !@{$ra_user_inputs}) {
push @files, $F;
} else {
# is this file desired?
my $want_this_one = 0;
foreach my $file_dir (@{$ra_user_inputs}) {
if (/^$file_dir/) {
$want_this_one = 1;
last;
}
}
push @files, $F if $want_this_one;
}
}
close(FH);
# apply match/not-match file/dir filters to the list so far
my @post_filter = ();
foreach my $F (@files) {
if ($opt_match_f) {
push @post_filter, $F if basename($F) =~ m{$opt_match_f};
next;
}
if ($opt_match_d) {
push @post_filter, $F if $F =~ m{$opt_match_d};
next;
}
if ($opt_not_match_d) {
if ($opt_fullpath and $F =~ m{$opt_not_match_d}) {
$Ignored{$F} = "--not-match-d=$opt_not_match_d";
next;
} elsif (basename($F) =~ m{$opt_not_match_d}) {
$Ignored{$F} = "--not-match-d (basename) =$opt_not_match_d";
next;
}
}
if ($opt_not_match_f) {
push @post_filter, $F unless basename($F) =~ m{$opt_not_match_f};
next;
}
push @post_filter, $F;
}
print "<- invoke_generator\n" if $opt_v > 2;
return @post_filter;
} # 1}}}
sub remove_duplicate_files { # {{{1
my ($fh , # in
$rh_Language , # out
$rh_unique_source_file, # out
$rh_Err , # in
$raa_errors , # out errors encountered
$rh_ignored , # out
) = @_;
# Check for duplicate files by comparing file sizes.
# Where files are equally sized, compare their MD5 checksums.
print "-> remove_duplicate_files\n" if $opt_v > 2;
my $n = 0;
my %files_by_size = (); # files_by_size{ # bytes } = [ list of files ]
seek($fh, 0, 0); # rewind to beginning of the temp file
while (<$fh>) {
++$n;
my ($size_in_bytes, $language, $file) = split(/,/, $_, 3);
if (!defined($size_in_bytes) or
!defined($language) or
!defined($file)) {
print "-> remove_duplicate_files skipping error line [$_]\n"
if $opt_v;
next;
}
chomp($file);
$rh_Language->{$file} = $language;
push @{$files_by_size{$size_in_bytes}}, $file;
if ($opt_skip_uniqueness) {
$rh_unique_source_file->{$file} = 1;
}
}
return if $opt_skip_uniqueness;
if ($opt_progress_rate and ($n > $opt_progress_rate)) {
printf "Duplicate file check %d files (%d known unique)\r",
$n, scalar keys %files_by_size;
}
$n = 0;
foreach my $bytes (sort {$a <=> $b} keys %files_by_size) {
++$n;
printf "Unique: %8d files \r",
$n unless (!$opt_progress_rate or ($n % $opt_progress_rate));
if (scalar @{$files_by_size{$bytes}} == 1) {
# only one file is this big; must be unique
$rh_unique_source_file->{$files_by_size{$bytes}[0]} = 1;
next;
} else {
#print "equally sized files: ",join(", ", @{$files_by_size{$bytes}}), "\n";
# Files in the list @{$files_by_size{$bytes} all are
# $bytes long. Sort the list by file basename.
# # sorting on basename causes repeatability problems
# # if the basename is not unique (eg "includeA/x.h"
# # and "includeB/x.h". Instead, sort on full path.
# # Ref bug #114.
# my @sorted_bn = ();
# my %BN = map { basename($_) => $_ } @{$files_by_size{$bytes}};
# foreach my $F (sort keys %BN) {
# push @sorted_bn, $BN{$F};
# }
my @sorted_bn = sort @{$files_by_size{$bytes}};
foreach my $F (different_files(\@sorted_bn ,
$rh_Err ,
$raa_errors ,
$rh_ignored ) ) {
$rh_unique_source_file->{$F} = 1;
}
}
}
print "<- remove_duplicate_files\n" if $opt_v > 2;
} # 1}}}
sub manual_find_preprocessor { # {{{1
# When running with --follow-links, find_preprocessor() is not
# called by find(). Have to do it manually. Inputs here
# are only files, which differs from find_preprocessor() which
# gets directories too.
# Reads global variable %Exclude_Dir.
# Populates global variable %Ignored.
# Reject files/directories in cwd which are in the exclude list.
print "-> manual_find_preprocessor(", cwd(), ")\n" if $opt_v > 2;
my @ok = ();
foreach my $File (@_) { # pure file or directory name, no separators
my $Dir = dirname($File);
my $got_exclude_dir = 0;
foreach my $d (File::Spec->splitdir( $Dir )) {
# tests/inputs/issues/407/level2/level/Test/level2 ->
# $d iterates over tests, inputs, issues, 407,
# level2, level, Test, level2
# check every item against %Exclude_Dir
if ($Exclude_Dir{$d}) {
$got_exclude_dir = $d;
last;
}
}
if ($got_exclude_dir) {
$Ignored{$File} = "--exclude-dir=$Exclude_Dir{$got_exclude_dir}";
#print "ignoring $File\n";
} else {
if ($opt_not_match_d) {
if ($opt_fullpath) {
if ($Dir =~ m{^${opt_not_match_d}$}) {
$Ignored{$File} = "--not-match-d=$opt_not_match_d";
#print "matched fullpath\n"
} else {
push @ok, $File;
}
} elsif (basename($Dir) =~ m{$opt_not_match_d}) {
$Ignored{$File} = "--not-match-d=$opt_not_match_d";
#print "matched partial\n"
} else {
push @ok, $File;
}
} else {
push @ok, $File;
}
}
}
print "<- manual_find_preprocessor(@ok)\n" if $opt_v > 2;
return @ok;
} # 1}}}
sub find_preprocessor { # {{{1
# invoked by File::Find's find() each time it enters a new directory
# Reads global variable %Exclude_Dir.
# Populates global variable %Ignored.
# Reject files/directories in cwd which are in the exclude list.
print "-> find_preprocessor(", cwd(), ")\n" if $opt_v > 2;
my @ok = ();
#printf "TOP find_preprocessor\n";
foreach my $F_or_D (@_) { # pure file or directory name, no separators
next if $F_or_D =~ /^\.{1,2}$/; # skip . and ..
if ($Exclude_Dir{$F_or_D}) {
$Ignored{$File::Find::name} = "--exclude-dir=$Exclude_Dir{$F_or_D}";
} else {
#printf " F_or_D=%-20s File::Find::name=%s\n", $F_or_D, $File::Find::name;
if ($opt_not_match_d) {
if ($opt_fullpath) {
if ($File::Find::name =~ m{$opt_not_match_d}) {
$Ignored{$File::Find::name} = "--not-match-d=$opt_not_match_d";
} else {
push @ok, $F_or_D;
}
} elsif (!-d $F_or_D and basename($File::Find::name) =~ m{$opt_not_match_d}) {
$Ignored{$File::Find::name} = "--not-match-d (basename) =$opt_not_match_d";
} else {
push @ok, $F_or_D;
}
} else {
push @ok, $F_or_D;
}
}
}
print "<- find_preprocessor(@ok)\n" if $opt_v > 2;
return @ok;
} # 1}}}
sub files { # {{{1
# invoked by File::Find's find() Populates global variable @file_list.
# See also find_preprocessor() which prunes undesired directories.
my $Dir = fastcwd(); # not $File::Find::dir which just gives relative path
if ($opt_fullpath) {
# look at as much of the path as is known
if ($opt_match_f ) {
return unless $File::Find::name =~ m{$opt_match_f};
}
if ($opt_not_match_f) {
return if $File::Find::name =~ m{$opt_not_match_f};
}
} else {
# only look at the basename
if ($opt_match_f ) { return unless /$opt_match_f/; }
if ($opt_not_match_f) { return if /$opt_not_match_f/; }
}
if ($opt_match_d ) { return unless $Dir =~ m{$opt_match_d} }
my $nBytes = -s $_ ;
if (!$nBytes) {
$Ignored{$File::Find::name} = 'zero sized file';
printf "files(%s) zero size\n", $File::Find::name if $opt_v > 5;
}
return unless $nBytes ; # attempting other tests w/pipe or socket will hang
if ($nBytes > $opt_max_file_size*1024**2) {
$Ignored{$File::Find::name} = "file size of " .
$nBytes/1024**2 . " MB exceeds max file size of " .
"$opt_max_file_size MB";
printf "file(%s) exceeds $opt_max_file_size MB\n",
$File::Find::name if $opt_v > 5;
return;
}
my $is_dir = is_dir($_);
my $is_bin = -B $_ ;
printf "files(%s) size=%d is_dir=%d -B=%d\n",
$File::Find::name, $nBytes, $is_dir, $is_bin if $opt_v > 5;
$is_bin = 0 if $opt_unicode and unicode_file($_);
$is_bin = 0 if $opt_read_binary_files;
return if $is_dir or $is_bin;
++$nFiles_Found;
printf "%8d files\r", $nFiles_Found
unless (!$opt_progress_rate or ($nFiles_Found % $opt_progress_rate));
push @file_list, $File::Find::name;
} # 1}}}
sub archive_files { # {{{1
# invoked by File::Find's find() Populates global variable @binary_archive
foreach my $ext (keys %Known_Binary_Archives) {
push @binary_archive, $File::Find::name
if $File::Find::name =~ m{$ext$};
}
} # 1}}}
sub is_file { # {{{1
# portable method to test if item is a file
# (-f doesn't work in ActiveState Perl on Windows)
my $item = shift @_;
return (-f $item);
# Was:
####if ($ON_WINDOWS) {
#### my $mode = (stat $item)[2];
#### $mode = 0 unless $mode;
#### if ($mode & 0100000) { return 1; }
#### else { return 0; }
####} else {
#### return (-f $item); # works on Unix, Linux, CygWin, z/OS
####}
} # 1}}}
sub is_dir { # {{{1
my $item = shift @_;
return (-d $item); # should work everywhere now (July 2017)
# Was:
##### portable method to test if item is a directory
##### (-d doesn't work in older versions of ActiveState Perl on Windows)
####if ($ON_WINDOWS) {
#### my $mode = (stat $item)[2];
#### $mode = 0 unless $mode;
#### if ($mode & 0040000) { return 1; }
#### else { return 0; }
####} else {
#### return (-d $item); # works on Unix, Linux, CygWin, z/OS
####}
} # 1}}}
sub is_excluded { # {{{1
my ($file , # in
$excluded , # in hash of excluded directories
) = @_;
my($filename, $filepath, $suffix) = fileparse($file);
foreach my $path (sort keys %{$excluded}) {
return 1 if ($filepath =~ m{^$path/}i);
}
} # 1}}}
sub classify_file { # {{{1
my ($full_file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
$rh_ignored , # out
) = @_;
print "-> classify_file($full_file)\n" if $opt_v > 2;
my $language = "(unknown)";
if (basename($full_file) eq "-" && defined $opt_stdin_name) {
$full_file = $opt_stdin_name;
}
my $look_at_first_line = 0;
my $file = basename $full_file;
if ($opt_autoconf and $file =~ /\.in$/) {
$file =~ s/\.in$//;
}
return $language if $Not_Code_Filename{$file}; # (unknown)
return $language if $file =~ m{~$}; # a temp edit file (unknown)
if (defined $Language_by_File{$file}) {
if ($Language_by_File{$file} eq "Ant/XML") {
return Ant_or_XML( $full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_File{$file} eq "Maven/XML") {
return Maven_or_XML($full_file, $rh_Err, $raa_errors);
} else {
return $Language_by_File{$file};
}
}
if ($file =~ /\.([^\.]+)$/) { # has an extension
print "$full_file extension=[$1]\n" if $opt_v > 2;
my $extension = $1;
# Windows file names are case insensitive so map
# all extensions to lowercase there.
$extension = lc $extension if $ON_WINDOWS or $opt_ignore_case_ext;
my @extension_list = ( $extension );
if ($file =~ /\.([^\.]+\.[^\.]+)$/) { # has a double extension
my $extension = $1;
$extension = lc $extension if $ON_WINDOWS or $opt_ignore_case_ext;
unshift @extension_list, $extension; # examine double ext first
}
if ($file =~ /\.([^\.]+\.[^\.]+\.[^\.]+)$/) { # has a triple extension
my $extension = $1;
$extension = lc $extension if $ON_WINDOWS or $opt_ignore_case_ext;
unshift @extension_list, $extension; # examine triple ext first
}
foreach my $extension (@extension_list) {
if ($Not_Code_Extension{$extension} and
!$Forced_Extension{$extension}) {
# If .1 (for example) is an extension that would ordinarily be
# ignored but the user has insisted this be counted with the
# --force-lang option, then go ahead and count it.
$rh_ignored->{$full_file} =
'listed in $Not_Code_Extension{' . $extension . '}';
return $language;
}
if (defined $Language_by_Extension{$extension}) {
if ($Language_by_Extension{$extension} eq
'MATLAB/Mathematica/Objective C/MUMPS/Mercury') {
my $lang_M_or_O = "";
matlab_or_objective_C($full_file ,
$rh_Err ,
$raa_errors,
\$lang_M_or_O);
if ($lang_M_or_O) {
return $lang_M_or_O;
} else { # an error happened in matlab_or_objective_C()
$rh_ignored->{$full_file} =
'failure in matlab_or_objective_C()';
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'PHP/Pascal') {
if (really_is_php($full_file)) {
return 'PHP';
} elsif (really_is_incpascal($full_file)) {
return 'Pascal';
} else {
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'Pascal/Puppet') {
my $lang_Pasc_or_Pup = "";
pascal_or_puppet( $full_file ,
$rh_Err ,
$raa_errors,
\$lang_Pasc_or_Pup);
if ($lang_Pasc_or_Pup) {
return $lang_Pasc_or_Pup;
} else { # an error happened in pascal_or_puppet()
$rh_ignored->{$full_file} =
'failure in pascal_or_puppet()';
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'Lisp/OpenCL') {
return Lisp_or_OpenCL($full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'Lisp/Julia') {
return Lisp_or_Julia( $full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'Perl/Prolog') {
return Perl_or_Prolog($full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'Raku/Prolog') {
return Raku_or_Prolog($full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq
'IDL/Qt Project/Prolog/ProGuard') {
return IDL_or_QtProject($full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'D/dtrace') {
# is it D or an init.d shell script?
my $a_script = really_is_D($full_file, $rh_Err, $raa_errors);
if ($a_script) {
# could be dtrace, sh, bash or anything one would
# write an init.d script in
if (defined $Language_by_Script{$a_script}) {
return $Language_by_Script{$a_script};
} else {
$rh_ignored->{$full_file} =
"Unrecognized script language, '$a_script'";
}
} else {
return 'D';
}
} elsif ($Language_by_Extension{$extension} eq 'Fortran 77/Forth') {
return Forth_or_Fortran($full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'F#/Forth') {
return Forth_or_Fsharp( $full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'Verilog-SystemVerilog/Coq') {
return Verilog_or_Coq( $full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'Smarty') {
if ($extension ne "tpl") {
# unambiguous -- if ends with .smarty, is Smarty
return $Language_by_Extension{$extension};
}
# Smarty extension .tpl is generic; make sure the
# file at least roughly resembles PHP. Alternatively,
# if the user forces the issue, do the count.
my $force_smarty = 0;
foreach (@opt_force_lang) {
if (lc($_) eq "smarty,tpl") {
$force_smarty = 1;
last;
}
}
if (really_is_smarty($full_file) or $force_smarty) {
return 'Smarty';
} else {
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'TypeScript/Qt Linguist') {
return TypeScript_or_QtLinguist( $full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'Qt/Glade') {
return Qt_or_Glade( $full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'C#/Smalltalk') {
return Csharp_or_Smalltalk( $full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'Scheme/SaltStack') {
return Scheme_or_SaltStack( $full_file, $rh_Err, $raa_errors);
} elsif ($Language_by_Extension{$extension} eq 'Visual Basic/TeX/Apex Class') {
my $lang_VB_T_A = "";
Visual_Basic_or_TeX_or_Apex($full_file ,
$rh_Err ,
$raa_errors,
\$lang_VB_T_A);
if ($lang_VB_T_A) {
return $lang_VB_T_A;
} else { # an error happened in Visual_Basic_or_TeX_or_Apex
$rh_ignored->{$full_file} =
'failure in Visual_Basic_or_TeX_or_Apex()';
return $language; # (unknown)
}
} elsif ($Language_by_Extension{$extension} eq 'Brainfuck') {
if (really_is_bf($full_file)) {
return $Language_by_Extension{$extension};
} else {
return $language; # (unknown)
}
} else {
return $Language_by_Extension{$extension};
}
} else { # has an unmapped file extension
$look_at_first_line = 1;
}
}
} elsif (defined $Language_by_File{lc $file}) {
return $Language_by_File{lc $file};
} elsif ($opt_lang_no_ext and
defined $Filters_by_Language{$opt_lang_no_ext}) {
return $opt_lang_no_ext;
} else { # no file extension
$look_at_first_line = 1;
}
if ($look_at_first_line) {
# maybe it is a shell/Perl/Python/Ruby/etc script that
# starts with pound bang:
# #!/usr/bin/perl
# #!/usr/bin/env perl
my ($script_language, $L) = peek_at_first_line($full_file ,
$rh_Err ,
$raa_errors);
if (!$script_language) {
$rh_ignored->{$full_file} = "language unknown (#2)";
# returns (unknown)
}
if (defined $Language_by_Script{$script_language}) {
if (defined $Filters_by_Language{
$Language_by_Script{$script_language}}) {
$language = $Language_by_Script{$script_language};
} else {
$rh_ignored->{$full_file} =
"undefined: Filters_by_Language{" .
$Language_by_Script{$script_language} .
"} for scripting language $script_language";
# returns (unknown)
}
} else {
# #456: XML files can have a variety of domain-specific file
# extensions. If the extension is unrecognized, examine
# the first line of the file to see if it is XML
if ($L =~ /<\?xml\s/) {
$language = "XML";
delete $rh_ignored->{$full_file};
} else {
$rh_ignored->{$full_file} = "language unknown (#3)";
}
# returns (unknown)
}
}
print "<- classify_file($full_file)=$language\n" if $opt_v > 2;
return $language;
} # 1}}}
sub first_line { # {{{1
# return back the first line of text in the file
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
my $line = "";
print "-> first_line($file)\n" if $opt_v > 2;
if (!-r $file) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $line;
}
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
print "<- first_line($file)\n" if $opt_v > 2;
return $line;
}
chomp($line = <$IN>);
$IN->close;
print "<- first_line($file, '$line')\n" if $opt_v > 2;
return $line;
} # 1}}}
sub peek_at_first_line { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> peek_at_first_line($file)\n" if $opt_v > 2;
my $script_language = "";
my $first_line = first_line($file, $rh_Err, $raa_errors);
if (defined $first_line) {
#print "peek_at_first_line of [$file] first_line=[$first_line]\n";
if ($first_line =~ /^#\!\s*(\S.*?)$/) {
#print "peek_at_first_line 1=[$1]\n";
my @pound_bang = split(' ', $1);
#print "peek_at_first_line basename 0=[", basename($pound_bang[0]), "]\n";
if (basename($pound_bang[0]) eq "env" and
scalar @pound_bang > 1) {
$script_language = $pound_bang[1];
#print "peek_at_first_line pound_bang A $pound_bang[1]\n";
} else {
$script_language = basename $pound_bang[0];
#print "peek_at_first_line pound_bang B $script_language\n";
}
}
}
print "<- peek_at_first_line($file)\n" if $opt_v > 2;
return ($script_language, $first_line);
} # 1}}}
sub different_files { # {{{1
# See which of the given files are unique by computing each file's MD5
# sum. Return the subset of files which are unique.
my ($ra_files , # in
$rh_Err , # in
$raa_errors , # out
$rh_ignored , # out
) = @_;
print "-> different_files(@{$ra_files})\n" if $opt_v > 2;
my %file_hash = (); # file_hash{md5 hash} = [ file1, file2, ... ]
foreach my $F (@{$ra_files}) {
next if is_dir($F); # needed for Windows
my $IN = new IO::File $F, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $F];
$rh_ignored->{$F} = 'cannot read';
} else {
if ($HAVE_Digest_MD5) {
binmode $IN;
my $MD5 = Digest::MD5->new->addfile($IN)->hexdigest;
#print "$F, $MD5\n";
push @{$file_hash{$MD5}}, $F;
} else {
# all files treated unique
push @{$file_hash{$F}}, $F;
}
$IN->close;
}
}
# Loop over file sets having identical MD5 sums. Within
# each set, pick the file that most resembles known source
# code.
my @unique = ();
for my $md5 (sort keys %file_hash) {
my $i_best = 0;
for (my $i = 1; $i < scalar(@{$file_hash{$md5}}); $i++) {
my $F = $file_hash{$md5}[$i];
my (@nul_a, %nul_h);
my $language = classify_file($F, $rh_Err,
# don't save these errors; pointless
\@nul_a, \%nul_h);
$i_best = $i if $language ne "(unknown)";
}
# keep the best one found and identify the rest as ignored
for (my $i = 0; $i < scalar(@{$file_hash{$md5}}); $i++) {
if ($i == $i_best) {
push @unique, $file_hash{$md5}[$i_best];
} else {
$rh_ignored->{$file_hash{$md5}[$i]} = "duplicate of " .
$file_hash{$md5}[$i_best];
}
}
}
print "<- different_files(@unique)\n" if $opt_v > 2;
return @unique;
} # 1}}}
sub call_counter { # {{{1
my ($file , # in
$language , # in
$ra_Errors, # out
) = @_;
# Logic: pass the file through the following filters:
# 1. remove blank lines
# 2. remove comments using each filter defined for this language
# (example: SQL has two, remove_starts_with(--) and
# remove_c_comments() )
# 3. compute comment lines as
# total lines - blank lines - lines left over after all
# comment filters have been applied
print "-> call_counter($file, $language)\n" if $opt_v > 2;
#print "call_counter: ", Dumper(@routines), "\n";
my @lines = ();
my $ascii = "";
if (-B $file and $opt_unicode) {
# was binary so must be unicode
$/ = undef;
my $IN = new IO::File $file, "r";
my $bin_text = <$IN>;
$IN->close;
$/ = "\n";
$ascii = unicode_to_ascii( $bin_text );
@lines = split("\n", $ascii );
foreach (@lines) { $_ = "$_\n"; }
} else {
# regular text file
@lines = read_file($file);
$ascii = join('', @lines);
}
# implement --perl-ignore-data here
my @original_lines = @lines;
my $total_lines = scalar @lines;
print_lines($file, "Original file:", \@lines) if $opt_print_filter_stages;
@lines = rm_blanks(\@lines, $language, \%EOL_Continuation_re); # remove blank lines
print " call_counter: total_lines=$total_lines blank_lines=",
scalar(@lines), "\n" if $opt_v > 2;
my $blank_lines = $total_lines - scalar @lines;
print_lines($file, "Blank lines removed:", \@lines)
if $opt_print_filter_stages;
@lines = rm_comments(\@lines, $language, $file,
\%EOL_Continuation_re, $ra_Errors);
my $comment_lines = $total_lines - $blank_lines - scalar @lines;
if ($opt_strip_comments) {
my $stripped_file = "";
if ($opt_original_dir) {
$stripped_file = $file . ".$opt_strip_comments";
} else {
$stripped_file = basename $file . ".$opt_strip_comments";
}
write_file($stripped_file, {}, @lines);
}
if ($opt_html and !$opt_diff) {
chomp(@original_lines); # includes blank lines, comments
chomp(@lines); # no blank lines, no comments
my (@diff_L, @diff_R, %count);
# remove blank lines to get better quality diffs; count
# blank lines separately
my @original_lines_minus_white = ();
# however must keep track of how many blank lines were removed and
# where they were removed so that the HTML display can include it
my %blank_line = ();
my $insert_line = 0;
foreach (@original_lines) {
if (/^\s*$/) {
++$count{blank}{same};
++$blank_line{ $insert_line };
} else {
++$insert_line;
push @original_lines_minus_white, $_;
}
}
array_diff( $file , # in
\@original_lines_minus_white , # in
\@lines , # in
"comment" , # in
\@diff_L, \@diff_R, , # out
$ra_Errors); # in/out
write_comments_to_html($file, \@diff_L, \@diff_R, \%blank_line);
#print Dumper("count", \%count);
}
print "<- call_counter($total_lines, $blank_lines, $comment_lines)\n"
if $opt_v > 2;
return ($total_lines, $blank_lines, $comment_lines);
} # 1}}}
sub windows_glob { # {{{1
# Windows doesn't expand wildcards. Use code from Sean M. Burke's
# Win32::Autoglob module to do this.
return map {;
( defined($_) and m/[\*\?]/ ) ? sort(glob($_)) : $_
} @_;
} # 1}}}
sub write_file { # {{{1
my ($file , # in
$rh_options , # in
@lines , # in
) = @_;
my $local_formatting = 0;
foreach my $opt (sort keys %{$rh_options}) {
# print "write_file option $opt = $rh_options->{$opt}\n";
$local_formatting = 1;
}
#print "write_file 1 [$file]\n";
# Do ~ expansion (by Tim LaBerge, fixes bug 2787984)
my $preglob_filename = $file;
#print "write_file 2 [$preglob_filename]\n";
if ($ON_WINDOWS) {
$file = (windows_glob($file))[0];
} else {
$file = File::Glob::bsd_glob($file);
}
#print "write_file 3 [$file]\n";
$file = $preglob_filename unless $file;
#print "write_file 4 [$file]\n";
print "-> write_file($file)\n" if $opt_v > 2;
# Create the destination directory if it doesn't already exist.
my $abs_file_path = File::Spec->rel2abs( $file );
my ($volume, $directories, $filename) = File::Spec->splitpath( $abs_file_path );
mkpath($volume . $directories, 1, 0777);
my $OUT = undef;
unlink $file;
if ($opt_file_encoding) {
# $OUT = IO::File->new($file, ">:$opt_file_encoding"); # doesn't work?
open($OUT, "> :encoding($opt_file_encoding)", $file);
} else {
$OUT = new IO::File $file, "w";
}
my $n_col = undef;
if ($local_formatting) {
$n_col = scalar @{$rh_options->{'columns'}};
if ($opt_xml) {
print $OUT '<?xml version="1.0" encoding="UTF-8"?>', "\n";
print $OUT "<all_$rh_options->{'file_type'}>\n";
} elsif ($opt_yaml) {
print $OUT "---\n";
} elsif ($opt_md) {
print $OUT join("|", @{$rh_options->{'columns'}}) , "\n";
print $OUT join("|", map( ":------", 1 .. $n_col)), "\n";
}
}
if (!defined $OUT) {
warn "Unable to write to $file\n";
print "<- write_file\n" if $opt_v > 2;
return;
}
chomp(@lines);
if ($local_formatting) {
my @json_lines = ();
foreach my $L (@lines) {
my @entries;
if ($rh_options->{'separator'}) {
@entries = split($rh_options->{'separator'}, $L, $n_col);
} else {
@entries = ( $L );
}
if ($opt_xml) {
print $OUT " <$rh_options->{'file_type'} ";
for (my $i = 0; $i < $n_col; $i++) {
printf $OUT "%s=\"%s\" ", $rh_options->{'columns'}[$i], $entries[$i];
}
print $OUT "/>\n";
} elsif ($opt_yaml or $opt_json) {
my @pairs = ();
for (my $i = 0; $i < $n_col; $i++) {
push @pairs,
sprintf "\"%s\":\"%s\"", $rh_options->{'columns'}[$i], $entries[$i];
}
if ($opt_json) {
push @json_lines, join(", ", @pairs );
} else {
print $OUT "- {", join(", ", @pairs), "}\n";
}
} elsif ($opt_csv) {
print $OUT join(",", @entries), "\n";
} elsif ($opt_md) {
print $OUT join("|", @entries), "\n";
}
}
if ($opt_json) {
print $OUT "[{", join("}, {", @json_lines), "}]\n";
}
if (!$opt_json and !$opt_yaml and !$opt_xml and !$opt_csv) {
print $OUT join("\n", @lines), "\n";
}
} else {
print $OUT join("\n", @lines), "\n";
}
if ($local_formatting and $opt_xml) {
print $OUT "</all_$rh_options->{'file_type'}>\n";
}
$OUT->close;
if (-r $file) {
print "Wrote $file" unless $opt_quiet;
print ", $CLOC_XSL" if $opt_xsl and $opt_xsl eq $CLOC_XSL;
print "\n" unless $opt_quiet;
}
print "<- write_file\n" if $opt_v > 2;
} # 1}}}
sub file_pairs_from_file { # {{{1
my ($file , # in
$ra_added , # out
$ra_removed , # out
$ra_compare_list , # out
) = @_;
#
# Example valid input format for $file
# 1)
# A/d1/hello.f90 | B/d1/hello.f90
# A/hello.C | B/hello.C
# A/d2/hi.py | B/d2/hi.py
#
# 2)
# Files added: 1
# + B/extra_file.pl ; Perl
#
# Files removed: 1
# - A/d2/hello.java ; Java
#
# File pairs compared: 3
# != A/d1/hello.f90 | B/d1/hello.f90 ; Fortran 90
# != A/hello.C | B/hello.C ; C++
# == A/d2/hi.py | B/d2/hi.py ; Python
print "-> file_pairs_from_file($file)\n" if $opt_v and $opt_v > 2;
@{$ra_compare_list} = ();
my @lines = read_file($file);
my $mode = "compare";
foreach my $L (@lines) {
next if $L =~ /^\s*$/ or $L =~ /^\s*#/;
chomp($L);
if ($L =~ /^Files\s+(added|removed):/) {
$mode = $1;
} elsif ($L =~ /^File\s+pairs\s+compared:/) {
$mode = "compare";
} elsif ($mode eq "added" or $mode eq "removed") {
$L =~ m/^\s*[+-]\s+(.*?)\s+;/;
my $F = $1;
if (!defined $1) {
warn "file_pairs_from_file($file) parse failure\n",
"in $mode mode for '$L', ignoring\n";
next;
}
if ($mode eq "added") {
push @{$ra_added} , $F;
} else {
push @{$ra_removed}, $F;
}
} else {
$L =~ m/^\s*([!=]=\s*)?(.*?)\s*\|\s*(.*?)\s*(;.*?)?$/;
if (!defined $2 or !defined $3) {
warn "file_pairs_from_file($file) parse failure\n",
"in compare mode for '$L', ignoring\n";
next;
}
push @{$ra_compare_list}, ( [$2, $3] );
}
}
print "<- file_pairs_from_file\n" if $opt_v and $opt_v > 2;
}
sub read_file { # {{{1
my ($file, ) = @_;
my %BoM = (
"fe ff" => 2 ,
"ff fe" => 2 ,
"ef bb bf" => 3 ,
"f7 64 4c" => 3 ,
"0e fe ff" => 3 ,
"fb ee 28" => 3 ,
"00 00 fe ff" => 4 ,
"ff fe 00 00" => 4 ,
"2b 2f 76 38" => 4 ,
"2b 2f 76 39" => 4 ,
"2b 2f 76 2b" => 4 ,
"2b 2f 76 2f" => 4 ,
"dd 73 66 73" => 4 ,
"84 31 95 33" => 4 ,
"2b 2f 76 38 2d" => 5 ,
);
print "-> read_file($file)\n" if $opt_v and $opt_v > 2;
my @lines = ();
my $IN = new IO::File $file, "r";
if (defined $IN) {
@lines = <$IN>;
$IN->close;
if ($lines[$#lines]) { # test necessary for zero content files
# (superfluous?)
# Some files don't end with a new line. Force this:
$lines[$#lines] .= "\n" unless $lines[$#lines] =~ m/\n$/;
}
} else {
warn "Unable to read $file\n";
}
# Are first few characters of the file Unicode Byte Order
# Marks (http://en.wikipedia.org/wiki/Byte_Order_Mark)?
# If yes, remove them.
if (@lines) {
my @chrs = split('', $lines[0]);
my $n_chrs = scalar @chrs;
my ($n2, $n3, $n4, $n5) = ('', '', '', '');
$n2 = sprintf("%x %x", map ord, @chrs[0,1]) if $n_chrs >= 2;
$n3 = sprintf("%s %x", $n2, ord $chrs[2]) if $n_chrs >= 3;
$n4 = sprintf("%s %x", $n3, ord $chrs[3]) if $n_chrs >= 4;
$n5 = sprintf("%s %x", $n4, ord $chrs[4]) if $n_chrs >= 5;
if (defined $BoM{$n2}) { $lines[0] = substr $lines[0], 2;
} elsif (defined $BoM{$n3}) { $lines[0] = substr $lines[0], 3;
} elsif (defined $BoM{$n4}) { $lines[0] = substr $lines[0], 4;
} elsif (defined $BoM{$n5}) { $lines[0] = substr $lines[0], 5;
}
}
# Trim DOS line endings. This allows Windows files
# to be diff'ed with Unix files without line endings
# causing every line to differ.
foreach (@lines) { s/\cM$// }
print "<- read_file\n" if $opt_v and $opt_v > 2;
return @lines;
} # 1}}}
sub rm_blanks { # {{{1
my ($ra_in ,
$language ,
$rh_EOL_continuation_re) = @_;
print "-> rm_blanks(language=$language)\n" if $opt_v > 2;
#print "rm_blanks: language = [$language]\n";
my @out = ();
if ($language eq "COBOL") {
@out = remove_cobol_blanks($ra_in);
} else {
# removes blank lines
if (defined $rh_EOL_continuation_re->{$language}) {
@out = remove_matches_2re($ra_in, '^\s*$',
$rh_EOL_continuation_re->{$language});
} else {
@out = remove_matches($ra_in, '^\s*$');
}
}
print "<- rm_blanks(language=$language, n_remain= ",
scalar(@out), "\n" if $opt_v > 2;
return @out;
} # 1}}}
sub rm_comments { # {{{1
my ($ra_lines , # in, must be free of blank lines
$language , # in
$file , # in (some language counters, eg Haskell, need
# access to the original file)
$rh_EOL_continuation_re , # in
$raa_Errors , # out
) = @_;
print "-> rm_comments(file=$file)\n" if $opt_v > 2;
my @routines = @{$Filters_by_Language{$language}};
my @lines = @{$ra_lines};
my @original_lines = @{$ra_lines};
if (!scalar @original_lines) {
return @lines;
}
foreach my $call_string (@routines) {
my $subroutine = $call_string->[0];
next if $subroutine eq "rm_comments_in_strings" and !$opt_strip_str_comments;
if (! defined &{$subroutine}) {
warn "rm_comments undefined subroutine $subroutine for $file\n";
next;
}
print "rm_comments file=$file sub=$subroutine\n" if $opt_v > 1;
my @args = @{$call_string};
shift @args; # drop the subroutine name
if (@args and $args[0] eq '>filename<') {
shift @args;
unshift @args, $file;
}
# Unusual inputs, namely /* within strings without
# a corresponding */ can cause huge delays so put a timer on this.
my $max_duration_sec = scalar(@lines)/1000.0; # est lines per second
$max_duration_sec = 1.0 if $max_duration_sec < 1;
if (defined $opt_timeout) {
$max_duration_sec = $opt_timeout if $opt_timeout > 0;
}
#my $T_start = Time::HiRes::time();
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $max_duration_sec;
no strict 'refs';
@lines = &{$subroutine}(\@lines, @args); # apply filter...
alarm 0;
};
if ($@) {
# timed out
die unless $@ eq "alarm\n";
push @{$raa_Errors},
[ $Error_Codes{'Line count, exceeded timeout'}, $file ];
@lines = ();
if ($opt_v) {
warn "rm_comments($subroutine): exceeded timeout for $file--ignoring\n";
}
next;
}
#print "end time = ",Time::HiRes::time() - $T_start;
print " rm_comments after $subroutine line count=",
scalar(@lines), "\n" if $opt_v > 2;
#print "lines after=\n";
#print Dumper(\@lines);
print_lines($file, "After $subroutine(@args)", \@lines)
if $opt_print_filter_stages;
# then remove blank lines which are created by comment removal
if (defined $rh_EOL_continuation_re->{$language}) {
@lines = remove_matches_2re(\@lines, '^\s*$',
$rh_EOL_continuation_re->{$language});
} else {
@lines = remove_matches(\@lines, '^\s*$');
}
print_lines($file, "post $subroutine(@args) blank cleanup:", \@lines)
if $opt_print_filter_stages;
}
foreach (@lines) { chomp } # make sure no spurious newlines were added
# Exception for scripting languages: treat the first #! line as code.
# Will need to add it back in if it was removed earlier.
chomp( $original_lines[0] );
if (defined $Script_Language{$language} and
$original_lines[0] =~ /^#!/ and
(!scalar(@lines) or ($lines[0] ne $original_lines[0]))) {
unshift @lines, $original_lines[0]; # add the first line back
}
print "<- rm_comments\n" if $opt_v > 2;
return @lines;
} # 1}}}
sub remove_f77_comments { # {{{1
my ($ra_lines, ) = @_;
print "-> remove_f77_comments\n" if $opt_v > 2;
my @save_lines = ();
foreach (@{$ra_lines}) {
next if m{^[*cC]};
next if m{^\s*!};
push @save_lines, $_;
}
print "<- remove_f77_comments\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_f90_comments { # {{{1
# derived from SLOCCount
my ($ra_lines, ) = @_;
print "-> remove_f90_comments\n" if $opt_v > 2;
my @save_lines = ();
foreach (@{$ra_lines}) {
# a comment is m/^\s*!/
# an empty line is m/^\s*$/
# a HPF statement is m/^\s*!hpf\$/i
# an Open MP statement is m/^\s*!omp\$/i
if (! m/^(\s*!|\s*$)/ || m/^\s*!(hpf|omp)\$/i) {
push @save_lines, $_;
}
}
print "<- remove_f90_comments\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub reduce_to_rmd_code_blocks { #{{{1
my ($ra_lines) = @_; #in
print "-> reduce_to_rmd_code_blocks()\n" if $opt_v > 2;
my $in_code_block = 0;
my @save_lines = ();
foreach (@{$ra_lines}) {
if ( m/^```\{\s*[[:alpha:]]/ ) {
$in_code_block = 1;
next;
}
if ( m/^```\s*$/ ) {
$in_code_block = 0;
}
next if (!$in_code_block);
push @save_lines, $_;
}
print "<- reduce_to_rmd_code_blocks()\n" if $opt_v> 2;
return @save_lines;
} # 1}}}
sub remove_matches { # {{{1
my ($ra_lines, # in
$pattern , # in Perl regular expression (case insensitive)
) = @_;
print "-> remove_matches(pattern=$pattern)\n" if $opt_v > 2;
my @save_lines = ();
foreach (@{$ra_lines}) {
#chomp;
#print "remove_matches [$pattern] [$_]\n";
next if m{$pattern}i;
# s{$pattern}{}i;
# next unless /\S/; # at least one non space
push @save_lines, $_;
}
print "<- remove_matches\n" if $opt_v > 2;
#print "remove_matches returning\n ", join("\n ", @save_lines), "\n";
return @save_lines;
} # 1}}}
sub remove_matches_2re { # {{{1
my ($ra_lines, # in
$pattern1, # in Perl regex 1 (case insensitive) to match
$pattern2, # in Perl regex 2 (case insensitive) to not match prev line
) = @_;
print "-> remove_matches_2re(pattern=$pattern1,$pattern2)\n" if $opt_v > 2;
my @save_lines = ();
for (my $i = 0; $i < scalar @{$ra_lines}; $i++) {
# chomp($ra_lines->[$i]);
#print "remove_matches_2re [$pattern1] [$pattern2] [$ra_lines->[$i]]\n";
if ($i) {
#print "remove_matches_2re prev=[$ra_lines->[$i-1]] this=[$ra_lines->[$i]]\n";
next if ($ra_lines->[$i] =~ m{$pattern1}i) and
($ra_lines->[$i-1] !~ m{$pattern2}i);
} else {
# on first line
next if $ra_lines->[$i] =~ m{$pattern1}i;
}
push @save_lines, $ra_lines->[$i];
}
print "<- remove_matches_2re\n" if $opt_v > 2;
#print "remove_matches_2re returning\n ", join("\n ", @save_lines), "\n";
return @save_lines;
} # 1}}}
sub remove_inline { # {{{1
my ($ra_lines, # in
$pattern , # in Perl regular expression (case insensitive)
) = @_;
print "-> remove_inline(pattern=$pattern)\n" if $opt_v > 2;
my @save_lines = ();
unless ($opt_inline) {
return @{$ra_lines};
}
my $nLines_affected = 0;
foreach (@{$ra_lines}) {
#chomp; print "remove_inline [$pattern] [$_]\n";
if (m{$pattern}i) {
++$nLines_affected;
s{$pattern}{}i;
}
push @save_lines, $_;
}
print "<- remove_inline\n" if $opt_v > 2;
#print "remove_inline returning\n ", join("\n ", @save_lines), "\n";
return @save_lines;
} # 1}}}
sub remove_above { # {{{1
my ($ra_lines, $marker, ) = @_;
print "-> remove_above(marker=$marker)\n" if $opt_v > 2;
# Make two passes through the code:
# 1. check if the marker exists
# 2. remove anything above the marker if it exists,
# do nothing if the marker does not exist
# Pass 1
my $found_marker = 0;
for (my $line_number = 1;
$line_number <= scalar @{$ra_lines};
$line_number++) {
if ($ra_lines->[$line_number-1] =~ m{$marker}) {
$found_marker = $line_number;
last;
}
}
# Pass 2 only if needed
my @save_lines = ();
if ($found_marker) {
my $n = 1;
foreach (@{$ra_lines}) {
push @save_lines, $_
if $n >= $found_marker;
++$n;
}
} else { # marker wasn't found; save all lines
foreach (@{$ra_lines}) {
push @save_lines, $_;
}
}
print "<- remove_above\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_below { # {{{1
my ($ra_lines, $marker, ) = @_;
print "-> remove_below(marker=$marker)\n" if $opt_v > 2;
my @save_lines = ();
foreach (@{$ra_lines}) {
last if m{$marker};
push @save_lines, $_;
}
print "<- remove_below\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_below_above { # {{{1
my ($ra_lines, $marker_below, $marker_above, ) = @_;
# delete lines delimited by start and end line markers such
# as Perl POD documentation
print "-> remove_below_above(markerB=$marker_below, A=$marker_above)\n"
if $opt_v > 2;
my @save_lines = ();
my $between = 0;
foreach (@{$ra_lines}) {
if (!$between and m{$marker_below}) {
$between = 1;
next;
}
if ($between and m{$marker_above}) {
$between = 0;
next;
}
next if $between;
push @save_lines, $_;
}
print "<- remove_below_above\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_between { # {{{1
my ($ra_lines, $marker, ) = @_;
# $marker must contain one of the balanced pairs understood
# by Regexp::Common::balanced, namely
# '{}' '()' '[]' or '<>'
print "-> remove_between(marker=$marker)\n" if $opt_v > 2;
my %acceptable = ('{}'=>1, '()'=>1, '[]'=>1, '<>'=>1, );
die "remove_between: invalid delimiter '$marker'\n",
"the delimiter must be one of these four pairs:\n",
"{} () [] <>\n" unless
$acceptable{$marker};
Install_Regexp_Common() unless $HAVE_Rexexp_Common;
my $all_lines = join("", @{$ra_lines});
no strict 'vars';
# otherwise get:
# Global symbol "%RE" requires explicit package name at cloc line xx.
if ($all_lines =~ m/$RE{balanced}{-parens => $marker}/) {
no warnings;
$all_lines =~ s/$1//g;
}
print "<- remove_between\n" if $opt_v > 2;
return split("\n", $all_lines);
} # 1}}}
sub rm_comments_in_strings { # {{{1
my ($ra_lines, $string_marker, $start_comment, $end_comment, $multiline_mode) = @_;
$multiline_mode = 0 if not defined $multiline_mode;
# Replace comments within strings with 'xx'.
print "-> rm_comments_in_strings(string_marker=$string_marker, " .
"start_comment=$start_comment, end_comment=$end_comment)\n"
if $opt_v > 2;
my @save_lines = ();
my $in_ml_string = 0;
foreach my $line (@{$ra_lines}) {
#print "line=[$line]\n";
my $new_line = "";
if ($line !~ /${string_marker}/) {
# short circuit; no strings on this line
if ( $in_ml_string ) {
$line =~ s/\Q${start_comment}\E/xx/g;
$line =~ s/\Q${end_comment}\E/xx/g if $end_comment;
}
push @save_lines, $line;
next;
}
# replace backslashed string markers with 'Q'
$line =~ s/\\${string_marker}/Q/g;
if ( $in_ml_string and $line =~ /^(.*?)(${string_marker})(.*)$/ ) {
# A multiline string ends on this line. Process the part
# until the end of the multiline string first.
my ($lastpart_ml_string, $firstpart_marker, $rest_of_line ) = ($1, $2, $3);
$lastpart_ml_string =~ s/\Q${start_comment}\E/xx/g;
$lastpart_ml_string =~ s/\Q${end_comment}\E/xx/g if $end_comment;
$new_line = $lastpart_ml_string . $firstpart_marker;
$line = $rest_of_line;
$in_ml_string = 0;
}
my @tokens = split(/(${string_marker}.*?${string_marker})/, $line);
foreach my $t (@tokens) {
#printf " t0 = [$t]\n";
if ($t =~ /${string_marker}.*${string_marker}$/) {
# enclosed in quotes; process this token
$t =~ s/\Q${start_comment}\E/xx/g;
$t =~ s/\Q${end_comment}\E/xx/g if $end_comment;
}
elsif ( $multiline_mode and $t =~ /(${string_marker})/ ) {
# Unclosed quote present in line. If multiline_mode is enabled,
# consider it the start of a multiline string.
my $firstpart_marker = $1;
my @sub_token = split(/${string_marker}/, $t );
if ( scalar @sub_token == 1 ) {
# The line ends with a string marker that starts
# a multiline string.
$t = $sub_token[0] . $firstpart_marker;
$in_ml_string = 1;
}
elsif ( scalar @sub_token == 2 ) {
# The line has some more content after the string
# marker that starts a multiline string
$t = $sub_token[0] . $firstpart_marker;
$sub_token[1] =~ s/\Q${start_comment}\E/xx/g;
$sub_token[1] =~ s/\Q${end_comment}\E/xx/g if $end_comment;
$t .= $sub_token[1];
$in_ml_string = 1;
} else {
print "Warning: rm_comments_in_string length \@sub_token > 2\n";
}
}
#printf " t1 = [$t]\n";
$new_line .= $t;
}
push @save_lines, $new_line;
}
print "<- rm_comments_in_strings\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_between_general { # {{{1
my ($ra_lines, $start_marker, $end_marker, ) = @_;
# Start and end markers may be any length strings.
print "-> remove_between_general(start=$start_marker, end=$end_marker)\n"
if $opt_v > 2;
my $all_lines = join("", @{$ra_lines});
my @save_lines = ();
my $in_comment = 0;
foreach (@{$ra_lines}) {
next if /^\s*$/;
s/\Q$start_marker\E.*?\Q$end_marker\E//g; # strip one-line comments
next if /^\s*$/;
if ($in_comment) {
if (/\Q$end_marker\E/) {
s/^.*?\Q$end_marker\E//;
$in_comment = 0;
}
next if $in_comment;
}
next if /^\s*$/;
$in_comment = 1 if /^(.*?)\Q$start_marker\E/; # $1 may be blank or code
next if defined $1 and $1 =~ /^\s*$/; # leading blank; all comment
if ($in_comment) {
# part code, part comment; strip the comment and keep the code
s/^(.*?)\Q$start_marker\E.*$/$1/;
}
push @save_lines, $_;
}
print "<- remove_between_general\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_between_regex { # {{{1
my ($ra_lines, $start_RE, $end_RE, ) = @_;
# Start and end regex's may be any length strings.
print "-> remove_between_regex(start=$start_RE, end=$end_RE)\n"
if $opt_v > 2;
my $all_lines = join("", @{$ra_lines});
my @save_lines = ();
my $in_comment = 0;
foreach (@{$ra_lines}) {
next if /^\s*$/;
s/${start_RE}.*?${end_RE}//g; # strip one-line comments
next if /^\s*$/;
if ($in_comment) {
if (/$end_RE/) {
s/^.*?${end_RE}//;
$in_comment = 0;
}
next if $in_comment;
}
next if /^\s*$/;
$in_comment = 1 if /^(.*?)${start_RE}/; # $1 may be blank or code
next if defined $1 and $1 =~ /^\s*$/; # leading blank; all comment
if ($in_comment) {
# part code, part comment; strip the comment and keep the code
s/^(.*?)${start_RE}.*$/$1/;
}
push @save_lines, $_;
}
print "<- remove_between_regex\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub replace_regex { # {{{1
my ($ra_lines, $regex, $replace, ) = @_;
print "-> replace_regex(regex=$regex, replace=$replace)\n"
if $opt_v > 2;
my $all_lines = join("", @{$ra_lines});
my @save_lines = ();
my $in_comment = 0;
foreach (@{$ra_lines}) {
next if /^\s*$/;
s/${regex}/${replace}/g;
next if /^\s*$/;
push @save_lines, $_;
}
print "<- replace_regex\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub replace_between_regex { # {{{1
my ($ra_lines, $start_RE, $end_RE, $replace_RE, $multiline_mode ) = @_;
# If multiline_mode is enabled, $replace_RE should not refer
# to any captured groups in $start_RE.
$multiline_mode = 1 if not defined $multiline_mode;
# Start and end regex's may be any length strings.
print "-> replace_between_regex(start=$start_RE, end=$end_RE, replace=$replace_RE)\n"
if $opt_v > 2;
my $all_lines = join("", @{$ra_lines});
my @save_lines = ();
my $in_comment = 0;
foreach (@{$ra_lines}) {
next if /^\s*$/;
s/${start_RE}.*?${end_RE}/${replace_RE}/eeg; # strip one-line comments
next if /^\s*$/;
if ($in_comment) {
if (/$end_RE/) {
s/^.*?${end_RE}/${replace_RE}/ee;
$in_comment = 0;
}
next if $in_comment;
}
next if /^\s*$/;
$in_comment = 1 if $multiline_mode and /^(.*?)${start_RE}/ ; # $1 may be blank or code
next if defined $1 and $1 =~ /^\s*$/; # leading blank; all comment
if ($in_comment) {
# part code, part comment; strip the comment and keep the code
s/^(.*?)${start_RE}.*$/$1/;
}
push @save_lines, $_;
}
print "<- replace_between_regex\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_cobol_blanks { # {{{1
# subroutines derived from SLOCCount
my ($ra_lines, ) = @_;
my $free_format = 0; # Support "free format" source code.
my @save_lines = ();
foreach (@{$ra_lines}) {
next if m/^\s*$/;
my $line = expand($_); # convert tabs to equivalent spaces
$free_format = 1 if $line =~ m/^......\$.*SET.*SOURCEFORMAT.*FREE/i;
if ($free_format) {
push @save_lines, $_;
} else {
# Greg Toth:
# (1) Treat lines with any alphanum in cols 1-6 and
# blanks in cols 7 through 71 as blank line, and
# (2) Treat lines with any alphanum in cols 1-6 and
# slash (/) in col 7 as blank line (this is a
# page eject directive).
push @save_lines, $_ unless m/^\d{6}\s*$/ or
($line =~ m/^.{6}\s{66}/) or
($line =~ m/^......\//);
}
}
return @save_lines;
} # 1}}}
sub remove_cobol_comments { # {{{1
# subroutines derived from SLOCCount
my ($ra_lines, ) = @_;
my $free_format = 0; # Support "free format" source code.
my @save_lines = ();
foreach (@{$ra_lines}) {
if (m/^......\$.*SET.*SOURCEFORMAT.*FREE/i) {$free_format = 1;}
if ($free_format) {
push @save_lines, $_ unless m{^\s*\*};
} else {
push @save_lines, $_ unless m{^......\*} or m{^\*};
}
}
return @save_lines;
} # 1}}}
sub remove_jcl_comments { # {{{1
my ($ra_lines, ) = @_;
print "-> remove_jcl_comments\n" if $opt_v > 2;
my @save_lines = ();
my $in_comment = 0;
foreach (@{$ra_lines}) {
next if /^\s*$/;
next if m{^//\*};
last if m{^\s*//\s*$};
push @save_lines, $_;
}
print "<- remove_jcl_comments\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_jsp_comments { # {{{1
# JSP comment is <%-- body of comment --%>
my ($ra_lines, ) = @_;
print "-> remove_jsp_comments\n" if $opt_v > 2;
my @save_lines = ();
my $in_comment = 0;
foreach (@{$ra_lines}) {
next if /^\s*$/;
s/<\%\-\-.*?\-\-\%>//g; # strip one-line comments
next if /^\s*$/;
if ($in_comment) {
if (/\-\-\%>/) {
s/^.*?\-\-\%>//;
$in_comment = 0;
}
}
next if /^\s*$/;
$in_comment = 1 if /^(.*?)<\%\-\-/;
next if defined $1 and $1 =~ /^\s*$/;
next if ($in_comment);
push @save_lines, $_;
}
print "<- remove_jsp_comments\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_html_comments { # {{{1
# HTML comment is <!-- body of comment -->
# Need to use my own routine until the HTML comment regex in
# the Regexp::Common module can handle <!-- -- -->
my ($ra_lines, ) = @_;
print "-> remove_html_comments\n" if $opt_v > 2;
my @save_lines = ();
my $in_comment = 0;
foreach (@{$ra_lines}) {
next if /^\s*$/;
s/<!\-\-.*?\-\->//g; # strip one-line comments
next if /^\s*$/;
if ($in_comment) {
if (/\-\->/) {
s/^.*?\-\->//;
$in_comment = 0;
}
}
next if /^\s*$/;
$in_comment = 1 if /^(.*?)<!\-\-/;
next if defined $1 and $1 =~ /^\s*$/;
next if ($in_comment);
push @save_lines, $_;
}
print "<- remove_html_comments\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_bf_comments { # {{{1
my ($ra_lines, ) = @_;
print "-> remove_bf_comments\n" if $opt_v > 2;
my @save_lines = ();
my $in_comment = 0;
foreach (@{$ra_lines}) {
s/[^<>+-.,\[\]]+//g;
next if /^\s*$/;
push @save_lines, $_;
}
print "<- remove_bf_comments\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub really_is_bf { # {{{1
my ($file, ) = @_;
print "-> really_is_bf\n" if $opt_v > 2;
my $n_bf_indicators = 0;
my @lines = read_file($file);
foreach my $L (@lines) {
my $ind = 0;
if ($L =~ /([+-]{4,} | # at least four +'s or -'s in a row
[\[\]]{4,} | # at least four [ or ] in a row
[<>][+-] | # >- or >+ or <+ or <-
<{3,} | # at least three < in a row
^\s*[\[\]]\s*$)/x) { # [ or ] on line by itself
++$n_bf_indicators;
$ind = 1;
}
# if ($ind) { print "YES: $L"; } else { print "NO : $L"; }
}
my $ratio = $n_bf_indicators/scalar(@lines);
my $decision = ($ratio > 0.5) || ($n_bf_indicators > 5);
printf "<- really_is_bf(Y/N=%d %s, R=%.3f, N=%d)\n",
$decision, $file, $ratio, $n_bf_indicators if $opt_v > 2;
return $decision;
} # 1}}}
sub remove_intented_block { # {{{1
# Haml block comments are defined by a silent comment marker like
# /
# or
# -#
# followed by indented text on subsequent lines.
# http://haml.info/docs/yardoc/file.REFERENCE.html#comments
my ($ra_lines, $regex, ) = @_;
print "-> remove_intented_block\n" if $opt_v > 2;
my @save_lines = ();
my $in_comment = 0;
foreach (@{$ra_lines}) {
next if /^\s*$/;
my $line = expand($_); # convert tabs to equivalent spaces
if ($in_comment) {
$line =~ /^(\s*)/;
# print "indent=", length $1, "\n";
if (length $1 < $in_comment) {
# indent level is less than comment level
# are back in code
$in_comment = 0;
} else {
# still in comments, don't use this line
next;
}
} elsif ($line =~ m{$regex}) {
if ($1) {
$in_comment = length($1) + 1; # number of leading spaces + 1
} else {
$in_comment = 1;
}
# print "in_comment=$in_comment\n";
next;
}
push @save_lines, $line;
}
print "<- remove_intented_block\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_haml_block { # {{{1
# Haml block comments are defined by a silent comment marker like
# /
# or
# -#
# followed by indented text on subsequent lines.
# http://haml.info/docs/yardoc/file.REFERENCE.html#comments
my ($ra_lines, ) = @_;
return remove_intented_block($ra_lines, '^(\s*)(/|-#)\s*$');
} # 1}}}
sub remove_pug_block { # {{{1
# Haml block comments are defined by a silent comment marker like
# //
# followed by indented text on subsequent lines.
# http://jade-lang.com/reference/comments/
my ($ra_lines, ) = @_;
return remove_intented_block($ra_lines, '^(\s*)(//)\s*$');
} # 1}}}
sub remove_OCaml_comments { # {{{1
my ($ra_lines, ) = @_;
print "-> remove_OCaml_comments\n" if $opt_v > 2;
my @save_lines = ();
my $in_comment = 0; # counter to depth of nested comments
foreach my $L (@{$ra_lines}) {
next if $L =~ /^\s*$/;
# make an array of tokens where a token is a start comment
# marker, end comment marker, string, or anything else
my $clean_line = ""; # ie, free of comments
my @tokens = split(/(\(\*|\*\)|".*?")/, $L);
foreach my $t (@tokens) {
next unless $t;
if ($t eq "(*") {
++$in_comment;
} elsif ($t eq "*)") {
--$in_comment;
} elsif (!$in_comment) {
$clean_line .= $t;
}
}
push @save_lines, $clean_line if $clean_line;
}
print "<- remove_OCaml_comments\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub remove_slim_block { # {{{1
# slim comments start with /
# followed by indented text on subsequent lines.
# http://www.rubydoc.info/gems/slim/frames
my ($ra_lines, ) = @_;
return remove_intented_block($ra_lines, '^(\s*)(/[^!])');
} # 1}}}
sub add_newlines { # {{{1
my ($ra_lines, ) = @_;
print "-> add_newlines \n" if $opt_v > 2;
my @save_lines = ();
foreach (@{$ra_lines}) {
push @save_lines, "$_\n";
}
print "<- add_newlines \n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub docstring_to_C { # {{{1
my ($ra_lines, ) = @_;
# Converts Python docstrings to C comments.
if ($opt_docstring_as_code) {
return @{$ra_lines};
}
print "-> docstring_to_C()\n" if $opt_v > 2;
my $in_docstring = 0;
foreach (@{$ra_lines}) {
while (/((""")|('''))/) {
if (!$in_docstring) {
s{[uU]?((""")|('''))}{/*};
$in_docstring = 1;
} else {
s{((""")|('''))}{*/};
$in_docstring = 0;
}
}
}
print "<- docstring_to_C\n" if $opt_v > 2;
return @{$ra_lines};
} # 1}}}
sub jupyter_nb { # {{{1
my ($ra_lines, ) = @_;
# Translate .ipynb file content into an equivalent set of code
# lines as expected by cloc.
print "-> jupyter_nb()\n" if $opt_v > 2;
my @save_lines = ();
my $in_code = 0;
my $in_source = 0;
foreach (@{$ra_lines}) {
if (!$in_code and !$in_source and /^\s*"cell_type":\s*"code",\s*$/) {
$in_code = 1;
} elsif ($in_code and !$in_source and /^\s*"source":\s*\[\s*$/) {
$in_source = 1;
} elsif ($in_code and $in_source) {
if (/^\s*"\s*\\n",\s*$/) { # "\n", -> empty line
next;
} elsif (/^\s*"\s*#/) { # comment within the code block
next;
} elsif (/^\s*\]\s*$/) {
$in_code = 0;
$in_source = 0;
} else {
push @save_lines, $_;
}
}
}
print "<- jupyter_nb\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub elixir_doc_to_C { # {{{1
my ($ra_lines, ) = @_;
# Converts Elixir docs to C comments.
print "-> elixir_doc_to_C()\n" if $opt_v > 2;
my $in_docstring = 0;
foreach (@{$ra_lines}) {
if (!$in_docstring && /(\@(module)?doc\s+(~[sScC])?['"]{3})/) {
s{$1}{/*};
$in_docstring = 1;
} elsif ($in_docstring && /(['"]{3})/) {
s{$1}{*/};
$in_docstring = 0;
}
}
print "<- elixir_doc_to_C\n" if $opt_v > 2;
return @{$ra_lines};
} # 1}}}
sub Forth_paren_to_C { # {{{1
my ($ra_lines, ) = @_;
# Converts Forth comment parentheses to C comments.
print "-> Forth_paren_to_C()\n" if $opt_v > 2;
my $in_comment = 0;
my $max_paren_pair_per_line = 255;
foreach (@{$ra_lines}) {
#print "Forth_paren_to_C: [$_]\n";
my $n_iter = 0;
while (/\s\(\s/ or ($in_comment and /\)/)) {
#print "TOP n_iter=$n_iter in_comment=$in_comment\n";
if (/\s\(\s.*?\)/) {
# in-line parenthesis comment; handle here
s/\s+\(\s+.*?\)//g;
#print "B\n";
} elsif (!$in_comment and /\s\(\s/) {
s{\s+\(\s+}{/*};
#print "C\n";
$in_comment = 1;
} elsif ($in_comment and /\)/) {
s{\)}{*/};
#print "D\n";
$in_comment = 0;
} else {
# gets here if it can't find a matching
# close parenthesis; in this case the
# results will likely be incorrect
++$n_iter;
#print "E\n";
last if $n_iter > $max_paren_pair_per_line;
}
}
}
print "<- Forth_paren_to_C\n" if $opt_v > 2;
return @{$ra_lines};
} # 1}}}
sub powershell_to_C { # {{{1
my ($ra_lines, ) = @_;
# Converts PowerShell block comment markers to C comments.
print "-> powershell_to_C()\n" if $opt_v > 2;
my $in_docstring = 0;
foreach (@{$ra_lines}) {
s{<#}{/*}g;
s{#>}{*/}g;
}
print "<- powershell_to_C\n" if $opt_v > 2;
return @{$ra_lines};
} # 1}}}
sub smarty_to_C { # {{{1
my ($ra_lines, ) = @_;
# Converts Smarty comments to C comments.
print "-> smarty_to_C()\n" if $opt_v > 2;
foreach (@{$ra_lines}) {
s[{\*][/*]g;
s[\*}][*/]g;
}
print "<- smarty_to_C\n" if $opt_v > 2;
return @{$ra_lines};
} # 1}}}
sub determine_lit_type { # {{{1
my ($file) = @_;
open (FILE, $file);
while (<FILE>) {
if (m/^\\begin\{code\}/) { close FILE; return 2; }
if (m/^>\s/) { close FILE; return 1; }
}
return 0;
} # 1}}}
sub remove_haskell_comments { # {{{1
# Bulk of code taken from SLOCCount's haskell_count script.
# Strips out {- .. -} and -- comments and counts the rest.
# Pragmas, {-#...}, are counted as SLOC.
# BUG: Doesn't handle strings with embedded block comment markers gracefully.
# In practice, that shouldn't be a problem.
my ($ra_lines, $file, ) = @_;
print "-> remove_haskell_comments\n" if $opt_v > 2;
my @save_lines = ();
my $in_comment = 0;
my $incomment = 0;
my ($literate, $inlitblock) = (0,0);
$literate = 1 if $file =~ /\.lhs$/;
if($literate) { $literate = determine_lit_type($file) }
foreach (@{$ra_lines}) {
if ($literate == 1) {
if (!s/^>//) { s/.*//; }
} elsif ($literate == 2) {
if ($inlitblock) {
if (m/^\\end\{code\}/) { s/.*//; $inlitblock = 0; }
} elsif (!$inlitblock) {
if (m/^\\begin\{code\}/) { s/.*//; $inlitblock = 1; }
else { s/.*//; }
}
}
if ($incomment) {
if (m/\-\}/) { s/^.*?\-\}//; $incomment = 0;}
else { s/.*//; }
}
if (!$incomment) {
s/--.*//;
s!{-[^#].*?-}!!g;
if (m/{-/ && (!m/{-#/)) {
s/{-.*//;
$incomment = 1;
}
}
if (m/\S/) { push @save_lines, $_; }
}
# if ($incomment) {print "ERROR: ended in comment in $ARGV\n";}
print "<- remove_haskell_comments\n" if $opt_v > 2;
return @save_lines;
} # 1}}}
sub print_lines { # {{{1
my ($file , # in
$title , # in
$ra_lines , # in
) = @_;
printf "->%-30s %s\n", $file, $title;
for (my $i = 0; $i < scalar @{$ra_lines}; $i++) {
printf "%5d | %s", $i+1, $ra_lines->[$i];
print "\n" unless $ra_lines->[$i] =~ m{\n$}
}
} # 1}}}
sub set_constants { # {{{1
my ($rh_Language_by_Extension , # out
$rh_Language_by_Script , # out
$rh_Language_by_File , # out
$rhaa_Filters_by_Language , # out
$rh_Not_Code_Extension , # out
$rh_Not_Code_Filename , # out
$rh_Scale_Factor , # out
$rh_Known_Binary_Archives , # out
$rh_EOL_continuation_re , # out
) = @_;
# 1}}}
%{$rh_Language_by_Extension} = ( # {{{1
'abap' => 'ABAP' ,
'ac' => 'm4' ,
'ada' => 'Ada' ,
'adb' => 'Ada' ,
'ads' => 'Ada' ,
'adso' => 'ADSO/IDSM' ,
'ahkl' => 'AutoHotkey' ,
'ahk' => 'AutoHotkey' ,
'agda' => 'Agda' ,
'lagda' => 'Agda' ,
'aj' => 'AspectJ' ,
'am' => 'make' ,
'ample' => 'AMPLE' ,
'apl' => 'APL' ,
'apla' => 'APL' ,
'aplf' => 'APL' ,
'aplo' => 'APL' ,
'apln' => 'APL' ,
'aplc' => 'APL' ,
'apli' => 'APL' ,
'dyalog' => 'APL' ,
'dyapp' => 'APL' ,
'mipage' => 'APL' ,
'as' => 'ActionScript' ,
'adoc' => 'AsciiDoc' ,
'asciidoc' => 'AsciiDoc' ,
'dofile' => 'AMPLE' ,
'startup' => 'AMPLE' ,
'axd' => 'ASP' ,
'ashx' => 'ASP' ,
'asa' => 'ASP' ,
'asax' => 'ASP.NET' ,
'ascx' => 'ASP.NET' ,
'asd' => 'Lisp' , # system definition file
'nasm' => 'Assembly' ,
'a51' => 'Assembly' ,
'asm' => 'Assembly' ,
'asmx' => 'ASP.NET' ,
'asp' => 'ASP' ,
'aspx' => 'ASP.NET' ,
'master' => 'ASP.NET' ,
'sitemap' => 'ASP.NET' ,
'cshtml' => 'Razor' ,
'razor' => 'Razor' , # Client-side Blazor
'nawk' => 'awk' ,
'mawk' => 'awk' ,
'gawk' => 'awk' ,
'auk' => 'awk' ,
'awk' => 'awk' ,
'bash' => 'Bourne Again Shell' ,
'bzl' => 'Bazel' ,
'bazel' => 'Bazel' ,
'BUILD' => 'Bazel' ,
'vbhtml' => 'Visual Basic' ,
'frx' => 'Visual Basic' ,
'bas' => 'Visual Basic' ,
'dxl' => 'DOORS Extension Language',
'bat' => 'DOS Batch' ,
'BAT' => 'DOS Batch' ,
'cmd' => 'DOS Batch' ,
'CMD' => 'DOS Batch' ,
'btm' => 'DOS Batch' ,
'BTM' => 'DOS Batch' ,
'blade' => 'Blade' ,
'blade.php' => 'Blade' ,
'build.xml' => 'Ant' ,
'b' => 'Brainfuck' ,
'bf' => 'Brainfuck' ,
'brs' => 'BrightScript' ,
'bzl' => 'Starlark' ,
'cpy' => 'COBOL' ,
'cobol' => 'COBOL' ,
'ccp' => 'COBOL' ,
'cbl' => 'COBOL' ,
'CBL' => 'COBOL' ,
'idc' => 'C' ,
'cats' => 'C' ,
'c' => 'C' ,
'tpp' => 'C++' ,
'tcc' => 'C++' ,
'ipp' => 'C++' ,
'inl' => 'C++' ,
'h++' => 'C++' ,
'C' => 'C++' ,
'cc' => 'C++' ,
'c++' => 'C++' ,
'ccs' => 'CCS' ,
'cfc' => 'ColdFusion CFScript' ,
'cfml' => 'ColdFusion' ,
'cfm' => 'ColdFusion' ,
'chpl' => 'Chapel' ,
'cl' => 'Lisp/OpenCL' ,
'riemann.config'=> 'Clojure' ,
'hic' => 'Clojure' ,
'cljx' => 'Clojure' ,
'cljscm' => 'Clojure' ,
'cljs.hl' => 'Clojure' ,
'cl2' => 'Clojure' ,
'boot' => 'Clojure' ,
'clj' => 'Clojure' ,
'cljs' => 'ClojureScript' ,
'cljc' => 'ClojureC' ,
'cls' => 'Visual Basic/TeX/Apex Class' ,
'cmake.in' => 'CMake' ,
'CMakeLists.txt' => 'CMake' ,
'cmake' => 'CMake' ,
'cob' => 'COBOL' ,
'COB' => 'COBOL' ,
'iced' => 'CoffeeScript' ,
'cjsx' => 'CoffeeScript' ,
'cakefile' => 'CoffeeScript' ,
'_coffee' => 'CoffeeScript' ,
'coffee' => 'CoffeeScript' ,
'component' => 'Visualforce Component' ,
'cpp' => 'C++' ,
'CPP' => 'C++' ,
'cr' => 'Crystal' ,
'cs' => 'C#/Smalltalk' ,
'csh' => 'C Shell' ,
'cson' => 'CSON' ,
'css' => "CSS" ,
'ctl' => 'Visual Basic' ,
'cu' => 'CUDA' ,
'cuh' => 'CUDA' , # CUDA header file
'cxx' => 'C++' ,
'd' => 'D/dtrace' ,
# in addition, .d can map to init.d files typically written as
# bash or sh scripts
'da' => 'DAL' ,
'dart' => 'Dart' ,
'def' => 'Windows Module Definition',
'dhall' => 'dhall' ,
'dt' => 'DIET' ,
'patch' => 'diff' ,
'diff' => 'diff' ,
'dmap' => 'NASTRAN DMAP' ,
'sthlp' => 'Stata' ,
'matah' => 'Stata' ,
'mata' => 'Stata' ,
'ihlp' => 'Stata' ,
'doh' => 'Stata' ,
'ado' => 'Stata' ,
'do' => 'Stata' ,
'DO' => 'Stata' ,
'pascal' => 'Pascal' ,
'lpr' => 'Pascal' ,
'dfm' => 'Pascal' ,
'dpr' => 'Pascal' ,
'dita' => 'DITA' ,
'drl' => 'Drools' ,
'dsr' => 'Visual Basic' ,
'dtd' => 'DTD' ,
'ec' => 'C' ,
'ecpp' => 'ECPP' ,
'eex' => 'EEx' ,
'el' => 'Lisp' ,
'elm' => 'Elm' ,
'exs' => 'Elixir' ,
'ex' => 'Elixir' ,
'ecr' => 'Embedded Crystal' ,
'ejs' => 'EJS' ,
'erb' => 'ERB' ,
'ERB' => 'ERB' ,
'yrl' => 'Erlang' ,
'xrl' => 'Erlang' ,
'rebar.lock' => 'Erlang' ,
'rebar.config.lock'=> 'Erlang' ,
'rebar.config'=> 'Erlang' ,
'emakefile' => 'Erlang' ,
'app.src' => 'Erlang' ,
'erl' => 'Erlang' ,
'exp' => 'Expect' ,
'4th' => 'Forth' ,
'fish' => 'Fish Shell' ,
'fnl' => 'Fennel' ,
'forth' => 'Forth' ,
'fr' => 'Forth' ,
'frt' => 'Forth' ,
'fth' => 'Forth' ,
'f83' => 'Forth' ,
'fb' => 'Forth' ,
'fpm' => 'Forth' ,
'e4' => 'Forth' ,
'rx' => 'Forth' ,
'ft' => 'Forth' ,
'f77' => 'Fortran 77' ,
'F77' => 'Fortran 77' ,
'f90' => 'Fortran 90' ,
'F90' => 'Fortran 90' ,
'f95' => 'Fortran 95' ,
'F95' => 'Fortran 95' ,
'f' => 'Fortran 77/Forth' ,
'F' => 'Fortran 77' ,
'for' => 'Fortran 77/Forth' ,
'FOR' => 'Fortran 77' ,
'ftl' => 'Freemarker Template' ,
'ftn' => 'Fortran 77' ,
'FTN' => 'Fortran 77' ,
'fmt' => 'Oracle Forms' ,
'focexec' => 'Focus' ,
'frm' => 'Visual Basic' ,
'fs' => 'F#/Forth' ,
'fsi' => 'F#' ,
'fsx' => 'F# Script' ,
'fxml' => 'FXML' ,
'gnumakefile' => 'make' ,
'Gnumakefile' => 'make' ,
'gd' => 'GDScript' ,
'vshader' => 'GLSL' ,
'vsh' => 'GLSL' ,
'vrx' => 'GLSL' ,
'gshader' => 'GLSL' ,
'glslv' => 'GLSL' ,
'geo' => 'GLSL' ,
'fshader' => 'GLSL' ,
'fsh' => 'GLSL' ,
'frg' => 'GLSL' ,
'fp' => 'GLSL' ,
'glsl' => 'GLSL' ,
'graphqls' => 'GraphQL' ,
'gql' => 'GraphQL' ,
'graphql' => 'GraphQL' ,
'vert' => 'GLSL' ,
'tesc' => 'GLSL' ,
'tese' => 'GLSL' ,
'geom' => 'GLSL' ,
'feature' => 'Cucumber' ,
'frag' => 'GLSL' ,
'comp' => 'GLSL' ,
'g' => 'ANTLR Grammar' ,
'g4' => 'ANTLR Grammar' ,
'go' => 'Go' ,
'gsp' => 'Grails' ,
'jenkinsfile' => 'Groovy' ,
'gvy' => 'Groovy' ,
'gtpl' => 'Groovy' ,
'grt' => 'Groovy' ,
'groovy' => 'Groovy' ,
'gant' => 'Groovy' ,
'gradle' => 'Gradle' ,
'gradle.kts' => 'Gradle' ,
'h' => 'C/C++ Header' ,
'H' => 'C/C++ Header' ,
'hh' => 'C/C++ Header' ,
'hpp' => 'C/C++ Header' ,
'hxx' => 'C/C++ Header' ,
'hb' => 'Harbour' ,
'hrl' => 'Erlang' ,
'hsc' => 'Haskell' ,
'hs' => 'Haskell' ,
'tfvars' => 'HCL' ,
'hcl' => 'HCL' ,
'tf' => 'HCL' ,
'nomad' => 'HCL' ,
'hlsli' => 'HLSL' ,
'fxh' => 'HLSL' ,
'hlsl' => 'HLSL' ,
'shader' => 'HLSL' ,
'cg' => 'HLSL' ,
'cginc' => 'HLSL' ,
'haml.deface' => 'Haml' ,
'haml' => 'Haml' ,
'handlebars' => 'Handlebars' ,
'hbs' => 'Handlebars' ,
'hxsl' => 'Haxe' ,
'hx' => 'Haxe' ,
'hoon' => 'Hoon' ,
'xht' => 'HTML' ,
'html.hl' => 'HTML' ,
'htm' => 'HTML' ,
'html' => 'HTML' ,
'i3' => 'Modula3' ,
'ice' => 'Slice' ,
'icl' => 'Clean' ,
'dcl' => 'Clean' ,
'dlm' => 'IDL' ,
'idl' => 'IDL' ,
'idr' => 'Idris' ,
'lidr' => 'Literate Idris' ,
'imba' => 'Imba' ,
'prefs' => 'INI' ,
'lektorproject'=> 'INI' ,
'buildozer.spec'=> 'INI' ,
'ini' => 'INI' ,
'ism' => 'InstallShield' ,
'ipl' => 'IPL' ,
'pro' => 'IDL/Qt Project/Prolog/ProGuard' ,
'ig' => 'Modula3' ,
'il' => 'SKILL' ,
'ils' => 'SKILL++' ,
'inc' => 'PHP/Pascal' , # might be PHP or Pascal
'inl' => 'C++' ,
'ino' => 'Arduino Sketch' ,
'ipf' => 'Igor Pro' ,
'pde' => 'Arduino Sketch' , # pre 1.0
'itk' => 'Tcl/Tk' ,
'java' => 'Java' ,
'jcl' => 'JCL' , # IBM Job Control Lang.
'jl' => 'Lisp/Julia' ,
'xsjslib' => 'JavaScript' ,
'xsjs' => 'JavaScript' ,
'ssjs' => 'JavaScript' ,
'sjs' => 'JavaScript' ,
'pac' => 'JavaScript' ,
'njs' => 'JavaScript' ,
'mjs' => 'JavaScript' ,
'jss' => 'JavaScript' ,
'jsm' => 'JavaScript' ,
'jsfl' => 'JavaScript' ,
'jscad' => 'JavaScript' ,
'jsb' => 'JavaScript' ,
'jakefile' => 'JavaScript' ,
'jake' => 'JavaScript' ,
'bones' => 'JavaScript' ,
'_js' => 'JavaScript' ,
'js' => 'JavaScript' ,
'es6' => 'JavaScript' ,
'jsf' => 'JavaServer Faces' ,
'jsx' => 'JSX' ,
'xhtml' => 'XHTML' ,
'yyp' => 'JSON' ,
'webmanifest' => 'JSON' ,
'webapp' => 'JSON' ,
'topojson' => 'JSON' ,
'tfstate.backup'=> 'JSON' ,
'tfstate' => 'JSON' ,
'mcmod.info' => 'JSON' ,
'mcmeta' => 'JSON' ,
'json-tmlanguage'=> 'JSON' ,
'jsonl' => 'JSON' ,
'har' => 'JSON' ,
'gltf' => 'JSON' ,
'geojson' => 'JSON' ,
'composer.lock'=> 'JSON' ,
'avsc' => 'JSON' ,
'watchmanconfig'=> 'JSON' ,
'tern-project'=> 'JSON' ,
'tern-config' => 'JSON' ,
'htmlhintrc' => 'JSON' ,
'arcconfig' => 'JSON' ,
'json' => 'JSON' ,
'json5' => 'JSON5' ,
'jsp' => 'JSP' , # Java server pages
'jspf' => 'JSP' , # Java server pages
'vm' => 'Velocity Template Language' ,
'ksc' => 'Kermit' ,
'ksh' => 'Korn Shell' ,
'ktm' => 'Kotlin' ,
'kt' => 'Kotlin' ,
'kts' => 'Kotlin' ,
'hlean' => 'Lean' ,
'lean' => 'Lean' ,
'lhs' => 'Haskell' ,
'lex' => 'lex' ,
'l' => 'lex' ,
'less' => 'LESS' ,
'lfe' => 'LFE' ,
'liquid' => 'liquid' ,
'lsp' => 'Lisp' ,
'lisp' => 'Lisp' ,
'lgt' => 'Logtalk' ,
'logtalk' => 'Logtalk' ,
'wlua' => 'Lua' ,
'rbxs' => 'Lua' ,
'pd_lua' => 'Lua' ,
'p8' => 'Lua' ,
'nse' => 'Lua' ,
'lua' => 'Lua' ,
'm3' => 'Modula3' ,
'm4' => 'm4' ,
'makefile' => 'make' ,
'Makefile' => 'make' ,
'mao' => 'Mako' ,
'mako' => 'Mako' ,
'workbook' => 'Markdown' ,
'ronn' => 'Markdown' ,
'mkdown' => 'Markdown' ,
'mkdn' => 'Markdown' ,
'mkd' => 'Markdown' ,
'mdx' => 'Markdown' ,
'mdwn' => 'Markdown' ,
'mdown' => 'Markdown' ,
'markdown' => 'Markdown' ,
'contents.lr' => 'Markdown' ,
'md' => 'Markdown' ,
'mc' => 'Windows Message File' ,
'met' => 'Teamcenter met' ,
'mg' => 'Modula3' ,
'mk' => 'make' ,
# 'mli' => 'ML' , # ML not implemented
# 'ml' => 'ML' ,
'ml4' => 'OCaml' ,
'eliomi' => 'OCaml' ,
'eliom' => 'OCaml' ,
'ml' => 'OCaml' ,
'mli' => 'OCaml' ,
'mly' => 'OCaml' ,
'mll' => 'OCaml' ,
'm' => 'MATLAB/Mathematica/Objective C/MUMPS/Mercury' ,
'mm' => 'Objective C++' ,
'msg' => 'Gencat NLS' ,
'nbp' => 'Mathematica' ,
'mathematica' => 'Mathematica' ,
'ma' => 'Mathematica' ,
'cdf' => 'Mathematica' ,
'mt' => 'Mathematica' ,
'wl' => 'Mathematica' ,
'wlt' => 'Mathematica' ,
'mustache' => 'Mustache' ,
'wdproj' => 'MSBuild script' ,
'csproj' => 'MSBuild script' ,
'vcproj' => 'MSBuild script' ,
'wixproj' => 'MSBuild script' ,
'vbproj' => 'MSBuild script' ,
'mps' => 'MUMPS' ,
'mth' => 'Teamcenter mth' ,
'n' => 'Nemerle' ,
'nims' => 'Nim' ,
'nimrod' => 'Nim' ,
'nimble' => 'Nim' ,
'nim.cfg' => 'Nim' ,
'nim' => 'Nim' ,
'nix' => 'Nix' ,
'nut' => 'Squirrel' ,
'oscript' => 'LiveLink OScript' ,
'bod' => 'Oracle PL/SQL' ,
'spc' => 'Oracle PL/SQL' ,
'fnc' => 'Oracle PL/SQL' ,
'prc' => 'Oracle PL/SQL' ,
'trg' => 'Oracle PL/SQL' ,
'pad' => 'Ada' , # Oracle Ada preprocessor
'page' => 'Visualforce Page' ,
'pas' => 'Pascal' ,
'pcc' => 'C++' , # Oracle C++ preprocessor
'rexfile' => 'Perl' ,
'psgi' => 'Perl' ,
'ph' => 'Perl' ,
'makefile.pl' => 'Perl' ,
'cpanfile' => 'Perl' ,
'al' => 'Perl' ,
'ack' => 'Perl' ,
'perl' => 'Perl' ,
'pfo' => 'Fortran 77' ,
'pgc' => 'C' , # Postgres embedded C/C++
'phpt' => 'PHP' ,
'phps' => 'PHP' ,
'phakefile' => 'PHP' ,
'ctp' => 'PHP' ,
'aw' => 'PHP' ,
'php_cs.dist' => 'PHP' ,
'php_cs' => 'PHP' ,
'php3' => 'PHP' ,
'php4' => 'PHP' ,
'php5' => 'PHP' ,
'php' => 'PHP' ,
'phtml' => 'PHP' ,
'pig' => 'Pig Latin' ,
'plh' => 'Perl' ,
'pl' => 'Perl/Prolog' ,
'PL' => 'Perl/Prolog' ,
'p6' => 'Raku/Prolog' ,
'P6' => 'Raku/Prolog' ,
'plx' => 'Perl' ,
'pm' => 'Perl' ,
'pm6' => 'Raku' ,
'raku' => 'Raku' ,
'rakumod' => 'Raku' ,
'pom.xml' => 'Maven' ,
'pom' => 'Maven' ,
'yap' => 'Prolog' ,
'prolog' => 'Prolog' ,
'P' => 'Prolog' ,
'p' => 'Pascal' ,
'pp' => 'Pascal/Puppet' ,
'viw' => 'SQL' ,
'udf' => 'SQL' ,
'tab' => 'SQL' ,
'mysql' => 'SQL' ,
'cql' => 'SQL' ,
'psql' => 'SQL' ,
'xpy' => 'Python' ,
'wsgi' => 'Python' ,
'wscript' => 'Python' ,
'workspace' => 'Python' ,
'tac' => 'Python' ,
'snakefile' => 'Python' ,
'sconstruct' => 'Python' ,
'sconscript' => 'Python' ,
'pyt' => 'Python' ,
'pyp' => 'Python' ,
'pyi' => 'Python' ,
'pyde' => 'Python' ,
'py3' => 'Python' ,
'lmi' => 'Python' ,
'gypi' => 'Python' ,
'gyp' => 'Python' ,
'build.bazel' => 'Python' ,
'buck' => 'Python' ,
'gclient' => 'Python' ,
'py' => 'Python' ,
'pyw' => 'Python' ,
'ipynb' => 'Jupyter Notebook' ,
'pyj' => 'RapydScript' ,
'pxi' => 'Cython' ,
'pxd' => 'Cython' ,
'pyx' => 'Cython' ,
'qbs' => 'QML' ,
'qml' => 'QML' ,
'watchr' => 'Ruby' ,
'vagrantfile' => 'Ruby' ,
'thorfile' => 'Ruby' ,
'thor' => 'Ruby' ,
'snapfile' => 'Ruby' ,
'ru' => 'Ruby' ,
'rbx' => 'Ruby' ,
'rbw' => 'Ruby' ,
'rbuild' => 'Ruby' ,
'rabl' => 'Ruby' ,
'puppetfile' => 'Ruby' ,
'podfile' => 'Ruby' ,
'mspec' => 'Ruby' ,
'mavenfile' => 'Ruby' ,
'jbuilder' => 'Ruby' ,
'jarfile' => 'Ruby' ,
'guardfile' => 'Ruby' ,
'god' => 'Ruby' ,
'gemspec' => 'Ruby' ,
'gemfile.lock'=> 'Ruby' ,
'gemfile' => 'Ruby' ,
'fastfile' => 'Ruby' ,
'eye' => 'Ruby' ,
'deliverfile' => 'Ruby' ,
'dangerfile' => 'Ruby' ,
'capfile' => 'Ruby' ,
'buildfile' => 'Ruby' ,
'builder' => 'Ruby' ,
'brewfile' => 'Ruby' ,
'berksfile' => 'Ruby' ,
'appraisals' => 'Ruby' ,
'pryrc' => 'Ruby' ,
'irbrc' => 'Ruby' ,
'rb' => 'Ruby' ,
'podspec' => 'Ruby' ,
'rake' => 'Ruby' ,
# 'resx' => 'ASP.NET' ,
'rex' => 'Oracle Reports' ,
'pprx' => 'Rexx' ,
'rexx' => 'Rexx' ,
'rhtml' => 'Ruby HTML' ,
'rs.in' => 'Rust' ,
'rs' => 'Rust' ,
'rst.txt' => 'reStructuredText' ,
'rest.txt' => 'reStructuredText' ,
'rest' => 'reStructuredText' ,
'rst' => 'reStructuredText' ,
's' => 'Assembly' ,
'S' => 'Assembly' ,
'SCA' => 'Visual Fox Pro' ,
'sca' => 'Visual Fox Pro' ,
'sbt' => 'Scala' ,
'kojo' => 'Scala' ,
'scala' => 'Scala' ,
'sbl' => 'Softbridge Basic' ,
'SBL' => 'Softbridge Basic' ,
'sed' => 'sed' ,
'ses' => 'Patran Command Language' ,
'sp' => 'SparForte' ,
'sol' => 'Solidity' ,
'pcl' => 'Patran Command Language' ,
'pl1' => 'PL/I' ,
'plm' => 'PL/M' ,
'lit' => 'PL/M' ,
'po' => 'PO File' ,
'pbt' => 'PowerBuilder' ,
'sra' => 'PowerBuilder' ,
'srf' => 'PowerBuilder' ,
'srm' => 'PowerBuilder' ,
'srs' => 'PowerBuilder' ,
'sru' => 'PowerBuilder' ,
'srw' => 'PowerBuilder' ,
'jade' => 'Pug' ,
'pug' => 'Pug' ,
'purs' => 'PureScript' ,
'prefab' => 'Unity-Prefab' ,
'proto' => 'Protocol Buffers' ,
'mat' => 'Unity-Prefab' ,
'ps1' => 'PowerShell' ,
'psd1' => 'PowerShell' ,
'psm1' => 'PowerShell' ,
'rsx' => 'R' ,
'rd' => 'R' ,
'expr-dist' => 'R' ,
'rprofile' => 'R' ,
'R' => 'R' ,
'r' => 'R' ,
'raml' => 'RAML' ,
'rktd' => 'Racket' ,
'rkt' => 'Racket' ,
'rktl' => 'Racket' ,
'Rmd' => 'Rmd' ,
're' => 'ReasonML' ,
'rei' => 'ReasonML' ,
'scrbl' => 'Racket' ,
'sps' => 'Scheme' ,
'sc' => 'Scheme' ,
'ss' => 'Scheme' ,
'scm' => 'Scheme' ,
'sch' => 'Scheme' ,
'sls' => 'Scheme/SaltStack' ,
'sld' => 'Scheme' ,
'robot' => 'RobotFramework' ,
'rc' => 'Windows Resource File' ,
'rc2' => 'Windows Resource File' ,
'sas' => 'SAS' ,
'sass' => 'Sass' ,
'scss' => 'Sass' ,
'sh' => 'Bourne Shell' ,
'smarty' => 'Smarty' ,
'sml' => 'Standard ML' ,
'sig' => 'Standard ML' ,
'fun' => 'Standard ML' ,
'slim' => 'Slim' ,
'e' => 'Specman e' ,
'sql' => 'SQL' ,
'SQL' => 'SQL' ,
'sproc.sql' => 'SQL Stored Procedure' ,
'spoc.sql' => 'SQL Stored Procedure' ,
'spc.sql' => 'SQL Stored Procedure' ,
'udf.sql' => 'SQL Stored Procedure' ,
'data.sql' => 'SQL Data' ,
'sss' => 'SugarSS' ,
'st' => 'Smalltalk' ,
'styl' => 'Stylus' ,
'i' => 'SWIG' ,
'svelte' => 'Svelte' ,
'sv' => 'Verilog-SystemVerilog' ,
'svh' => 'Verilog-SystemVerilog' ,
'svg' => 'SVG' ,
'SVG' => 'SVG' ,
'v' => 'Verilog-SystemVerilog/Coq' ,
'tcl' => 'Tcl/Tk' ,
'tcsh' => 'C Shell' ,
'tk' => 'Tcl/Tk' ,
'mkvi' => 'TeX' ,
'mkiv' => 'TeX' ,
'mkii' => 'TeX' ,
'ltx' => 'TeX' ,
'lbx' => 'TeX' ,
'ins' => 'TeX' ,
'cbx' => 'TeX' ,
'bib' => 'TeX' ,
'bbx' => 'TeX' ,
'aux' => 'TeX' ,
'tex' => 'TeX' , # TeX, LaTex, MikTex, ..
'toml' => 'TOML' ,
'sty' => 'TeX' ,
# 'cls' => 'TeX' ,
'dtx' => 'TeX' ,
'bst' => 'TeX' ,
'thrift' => 'Thrift' ,
'tpl' => 'Smarty' ,
'trigger' => 'Apex Trigger' ,
'ttcn' => 'TTCN' ,
'ttcn2' => 'TTCN' ,
'ttcn3' => 'TTCN' ,
'ttcnpp' => 'TTCN' ,
'sdl' => 'TNSDL' ,
'ssc' => 'TNSDL' ,
'sdt' => 'TNSDL' ,
'spd' => 'TNSDL' ,
'sst' => 'TNSDL' ,
'rou' => 'TNSDL' ,
'cin' => 'TNSDL' ,
'cii' => 'TNSDL' ,
'interface' => 'TNSDL' ,
'in1' => 'TNSDL' ,
'in2' => 'TNSDL' ,
'in3' => 'TNSDL' ,
'in4' => 'TNSDL' ,
'inf' => 'TNSDL' ,
'tpd' => 'TITAN Project File Information',
'ts' => 'TypeScript/Qt Linguist',
'tsx' => 'TypeScript' ,
'tss' => 'Titanium Style Sheet' ,
'twig' => 'Twig' ,
'ui' => 'Qt/Glade' ,
'glade' => 'Glade' ,
'vala' => 'Vala' ,
'vapi' => 'Vala Header' ,
'vhw' => 'VHDL' ,
'vht' => 'VHDL' ,
'vhs' => 'VHDL' ,
'vho' => 'VHDL' ,
'vhi' => 'VHDL' ,
'vhf' => 'VHDL' ,
'vhd' => 'VHDL' ,
'VHD' => 'VHDL' ,
'vhdl' => 'VHDL' ,
'VHDL' => 'VHDL' ,
'vba' => 'Visual Basic' ,
'VBA' => 'Visual Basic' ,
# 'vbp' => 'Visual Basic' , # .vbp - autogenerated
'vb' => 'Visual Basic' ,
'VB' => 'Visual Basic' ,
# 'vbw' => 'Visual Basic' , # .vbw - autogenerated
'vbs' => 'Visual Basic' ,
'VBS' => 'Visual Basic' ,
'vue' => 'Vuejs Component' ,
'webinfo' => 'ASP.NET' ,
'xmi' => 'XMI' ,
'XMI' => 'XMI' ,
'zcml' => 'XML' ,
'xul' => 'XML' ,
'xspec' => 'XML' ,
'xproj' => 'XML' ,
'xml.dist' => 'XML' ,
'xliff' => 'XML' ,
'xlf' => 'XML' ,
'xib' => 'XML' ,
'xacro' => 'XML' ,
'x3d' => 'XML' ,
'wsf' => 'XML' ,
'web.release.config'=> 'XML' ,
'web.debug.config'=> 'XML' ,
'web.config' => 'XML' ,
'vxml' => 'XML' ,
'vstemplate' => 'XML' ,
'vssettings' => 'XML' ,
'vsixmanifest'=> 'XML' ,
'vcxproj' => 'XML' ,
'ux' => 'XML' ,
'urdf' => 'XML' ,
'tmtheme' => 'XML' ,
'tmsnippet' => 'XML' ,
'tmpreferences'=> 'XML' ,
'tmlanguage' => 'XML' ,
'tml' => 'XML' ,
'tmcommand' => 'XML' ,
'targets' => 'XML' ,
'sublime-snippet'=> 'XML' ,
'sttheme' => 'XML' ,
'storyboard' => 'XML' ,
'srdf' => 'XML' ,
'shproj' => 'XML' ,
'sfproj' => 'XML' ,
'settings.stylecop'=> 'XML' ,
'scxml' => 'XML' ,
'rss' => 'XML' ,
'resx' => 'XML' ,
'rdf' => 'XML' ,
'pt' => 'XML' ,
'psc1' => 'XML' ,
'ps1xml' => 'XML' ,
'props' => 'XML' ,
'proj' => 'XML' ,
'plist' => 'XML' ,
'pkgproj' => 'XML' ,
'packages.config'=> 'XML' ,
'osm' => 'XML' ,
'odd' => 'XML' ,
'nuspec' => 'XML' ,
'nuget.config'=> 'XML' ,
'nproj' => 'XML' ,
'ndproj' => 'XML' ,
'natvis' => 'XML' ,
'mjml' => 'XML' ,
'mdpolicy' => 'XML' ,
'launch' => 'XML' ,
'kml' => 'XML' ,
'jsproj' => 'XML' ,
'jelly' => 'XML' ,
'ivy' => 'XML' ,
'iml' => 'XML' ,
'grxml' => 'XML' ,
'gmx' => 'XML' ,
'fsproj' => 'XML' ,
'filters' => 'XML' ,
'dotsettings' => 'XML' ,
'dll.config' => 'XML' ,
'ditaval' => 'XML' ,
'ditamap' => 'XML' ,
'depproj' => 'XML' ,
'ct' => 'XML' ,
'csl' => 'XML' ,
'csdef' => 'XML' ,
'cscfg' => 'XML' ,
'cproject' => 'XML' ,
'clixml' => 'XML' ,
'ccxml' => 'XML' ,
'ccproj' => 'XML' ,
'builds' => 'XML' ,
'axml' => 'XML' ,
'app.config' => 'XML' ,
'ant' => 'XML' ,
'admx' => 'XML' ,
'adml' => 'XML' ,
'project' => 'XML' ,
'classpath' => 'XML' ,
'xml' => 'XML' ,
'XML' => 'XML' ,
'mxml' => 'MXML' ,
'xml.builder' => 'builder' ,
'build' => 'NAnt script' ,
'vim' => 'vim script' ,
'swift' => 'Swift' ,
'xaml' => 'XAML' ,
'wast' => 'WebAssembly' ,
'wat' => 'WebAssembly' ,
'wxs' => 'WiX source' ,
'wxi' => 'WiX include' ,
'wxl' => 'WiX string localization' ,
'prw' => 'xBase' ,
'prg' => 'xBase' ,
'ch' => 'xBase Header' ,
'xqy' => 'XQuery' ,
'xqm' => 'XQuery' ,
'xql' => 'XQuery' ,
'xq' => 'XQuery' ,
'xquery' => 'XQuery' ,
'xsd' => 'XSD' ,
'XSD' => 'XSD' ,
'xslt' => 'XSLT' ,
'XSLT' => 'XSLT' ,
'xsl' => 'XSLT' ,
'XSL' => 'XSLT' ,
'xtend' => 'Xtend' ,
'yacc' => 'yacc' ,
'y' => 'yacc' ,
'yml.mysql' => 'YAML' ,
'yaml-tmlanguage'=> 'YAML' ,
'syntax' => 'YAML' ,
'sublime-syntax'=> 'YAML' ,
'rviz' => 'YAML' ,
'reek' => 'YAML' ,
'mir' => 'YAML' ,
'glide.lock' => 'YAML' ,
'gemrc' => 'YAML' ,
'clang-tidy' => 'YAML' ,
'clang-format'=> 'YAML' ,
'yaml' => 'YAML' ,
'yml' => 'YAML' ,
'zsh' => 'zsh' ,
);
# 1}}}
%{$rh_Language_by_Script} = ( # {{{1
'awk' => 'awk' ,
'bash' => 'Bourne Again Shell' ,
'bc' => 'bc' ,# calculator
'crystal' => 'Crystal' ,
'csh' => 'C Shell' ,
'dmd' => 'D' ,
'dtrace' => 'dtrace' ,
'escript' => 'Erlang' ,
'groovy' => 'Groovy' ,
'idl' => 'IDL' ,
'kermit' => 'Kermit' ,
'ksh' => 'Korn Shell' ,
'lua' => 'Lua' ,
'make' => 'make' ,
'octave' => 'Octave' ,
'perl5' => 'Perl' ,
'perl' => 'Perl' ,
'miniperl' => 'Perl' ,
'php' => 'PHP' ,
'php5' => 'PHP' ,
'python' => 'Python' ,
'python2.6'=> 'Python' ,
'python2.7'=> 'Python' ,
'python3' => 'Python' ,
'python3.3'=> 'Python' ,
'python3.4'=> 'Python' ,
'python3.5'=> 'Python' ,
'python3.6'=> 'Python' ,
'python3.7'=> 'Python' ,
'python3.8'=> 'Python' ,
'perl6' => 'Raku' ,
'raku' => 'Raku' ,
'rakudo' => 'Raku' ,
'rexx' => 'Rexx' ,
'regina' => 'Rexx' ,
'ruby' => 'Ruby' ,
'sed' => 'sed' ,
'sh' => 'Bourne Shell' ,
'swipl' => 'Prolog' ,
'tcl' => 'Tcl/Tk' ,
'tclsh' => 'Tcl/Tk' ,
'tcsh' => 'C Shell' ,
'wish' => 'Tcl/Tk' ,
'zsh' => 'zsh' ,
);
# 1}}}
%{$rh_Language_by_File} = ( # {{{1
'build.xml' => 'Ant/XML' ,
'BUILD' => 'Bazel' ,
'WORKSPACE' => 'Bazel' ,
'CMakeLists.txt' => 'CMake' ,
'Jamfile' => 'Jam' ,
'Jamrules' => 'Jam' ,
'Makefile' => 'make' ,
'makefile' => 'make' ,
'gnumakefile' => 'make' ,
'Gnumakefile' => 'make' ,
'pom.xml' => 'Maven/XML' ,
'Rakefile' => 'Ruby' ,
'rakefile' => 'Ruby' ,
'Dockerfile' => 'Dockerfile' ,
'Dockerfile.build' => 'Dockerfile' ,
'Dockerfile.test' => 'Dockerfile' ,
);
# 1}}}
%{$rhaa_Filters_by_Language} = ( # {{{1
'(unknown)' => [ ],
'ABAP' => [ [ 'remove_matches' , '^\*' ], ],
'ActionScript' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Apex Class' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'ASP' => [ [ 'remove_matches' , '^\s*\47'], ], # \47 = '
'ASP.NET' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C' ],
],
'Ada' => [ [ 'remove_matches' , '^\s*--' ], ],
'ADSO/IDSM' => [ [ 'remove_matches' , '^\s*\*[\+\!]' ], ],
'Agda' => [ [ 'remove_haskell_comments', '>filename<' ], ],
'AMPLE' => [ [ 'remove_matches' , '^\s*//' ], ],
'APL' => [
[ 'remove_matches' , '^\s*⍝' ],
],
'Ant/XML' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'ANTLR Grammar' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Ant' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Apex Trigger' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Arduino Sketch' => [ # Arduino IDE inserts problematic 0xA0 characters; strip them
[ 'replace_regex' , '\xa0', " " ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'AsciiDoc' => [
[ 'remove_between_general', '////', '////' ],
[ 'remove_matches' , '^\s*\/\/' ],
],
'AspectJ' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Assembly' => [
[ 'remove_matches' , '^\s*#' ],
[ 'call_regexp_common' , 'C++' ],
[ 'remove_matches' , '^\s*;' ],
[ 'remove_matches' , '^\s*\@' ],
[ 'remove_matches' , '^\s*\|' ],
[ 'remove_matches' , '^\s*!' ],
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , ';.*$' ],
[ 'remove_inline' , '\@.*$' ],
[ 'remove_inline' , '\|.*$' ],
[ 'remove_inline' , '!.*$' ],
[ 'remove_inline' , '#.*$' ],
[ 'remove_inline' , '--.*$' ],
[ 'remove_matches' , '^\*' ], # z/OS Assembly
],
'AutoHotkey' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_inline' , ';.*$' ],
],
'awk' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Bazel' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'bc' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Blade' => [
[ 'remove_between_general', '{{--', '--}}' ],
[ 'remove_html_comments', ],
],
'Bourne Again Shell' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Bourne Shell' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Brainfuck' => [ # puerile name for a language
# [ 'call_regexp_common' , 'Brainfuck' ], # inaccurate
[ 'remove_bf_comments', ],
],
'BrightScript' => [
[ 'remove_matches' , '^\s*rem', ],
[ 'remove_matches' , '^\s*\'', ],
],
'builder' => [
[ 'remove_matches' , '^\s*xml_markup.comment!' ],
],
'C' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Chapel' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'C++' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'C/C++ Header' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Clean' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Clojure' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_matches' , '^\s*#_' ],
],
'ClojureScript' => [ [ 'remove_matches' , '^\s*;' ], ],
'ClojureC' => [ [ 'remove_matches' , '^\s*;' ], ],
'CMake' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Crystal' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'CUDA' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Cython' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'remove_matches' , '^\s*#' ],
[ 'docstring_to_C' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_inline' , '#.*$' ],
],
'C#/Smalltalk' => [ [ 'die' , ], ], # never called
'C#' => [
# [ 'remove_matches' , '^\s*//' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'CCS' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C' ],
],
'CSS' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C' ],
],
'COBOL' => [ [ 'remove_cobol_comments', ], ],
'CoffeeScript' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'ColdFusion' => [ [ 'remove_html_comments', ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'HTML' ], ],
'ColdFusion CFScript'=> [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Coq' => [
[ 'remove_between_general', '(*', '*)' ],
],
'Crystal Reports' => [ [ 'remove_matches' , '^\s*//' ], ],
'CSON' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Cucumber' => [
[ 'remove_matches' , '^\s*#' ],
],
'D/dtrace' => [ [ 'die' , ], ], # never called
'D' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'rm_comments_in_strings', '"', '/+', '+/' ],
[ 'remove_between_general', '/+', '+/' ],
[ 'call_regexp_common' , 'C++' ],
],
'DAL' => [
[ 'remove_between_general', '[', ']', ],
],
'Dart' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'dhall' => [ [ 'remove_haskell_comments', '>filename<' ], ],
'DIET' => [ # same as Pug
[ 'remove_pug_block' , ],
[ 'remove_matches' , '^\s*//' ],
[ 'remove_inline' , '//.*$' ],
],
# diff is kind of weird: anything but a space in the first column
# will count as code, with the exception of #, ---, +++. Spaces
# in the first column denote context lines which aren't part of the
# difference.
'diff' => [
[ 'remove_matches' , '^#' ],
[ 'remove_matches' , '^\-\-\-' ],
[ 'remove_matches' , '^\+\+\+' ],
[ 'remove_matches' , '^\s' ],
],
'DITA' => [
[ 'remove_html_comments', ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'HTML' ],
],
'DOORS Extension Language' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Drools' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'dtrace' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'ECPP' => [
[ 'remove_between_general',
'<%doc>', '</%doc>', ],
[ 'remove_between_general',
'<#' , '#>' , ],
[ 'call_regexp_common' , 'HTML' ],
],
'EEx' => [
[ 'remove_between_general', '<%#', '%>' ],
],
'EJS' => [
[ 'remove_between_general', '<%#', '%>' ],
[ 'remove_html_comments', ],
],
'Elm' => [ [ 'remove_haskell_comments', '>filename<' ], ],
'Embedded Crystal' => [
[ 'remove_between_general', '<%#', '%>' ],
],
'ERB' => [
[ 'remove_between_general', '<%#', '%>' ],
],
'Gencat NLS' => [ [ 'remove_matches' , '^\$ .*$' ], ],
'NASTRAN DMAP' => [
[ 'remove_matches' , '^\s*\$' ],
[ 'remove_inline' , '\$.*$' ],
],
'Dockerfile' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'DOS Batch' => [ [ 'remove_matches' , '^\s*rem', ], ],
'DTD' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'Elixir' => [
[ 'remove_matches' , '^\s*#' ],
[ 'elixir_doc_to_C' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_inline' , '#.*$' ],
],
'Erlang' => [
[ 'remove_matches' , '^\s*%' ],
[ 'remove_inline' , '%.*$' ],
],
'Expect' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Fennel' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_inline' , ';.*$' ],
],
'Fish Shell' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Focus' => [ [ 'remove_matches' , '^\s*\-\*' ], ],
'Forth' => [
[ 'remove_matches' , '^\s*\\\\.*$' ],
[ 'Forth_paren_to_C' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
[ 'remove_inline' , '\\\\.*$' ],
],
'Fortran 77' => [
[ 'remove_f77_comments' , ],
[ 'remove_inline' , '\!.*$' ],
],
'Fortran 77/Forth' => [ [ 'die' , ], ], # never called
'F#/Forth' => [ [ 'die' , ], ], # never called
'Fortran 90' => [
[ 'remove_f77_comments' , ],
[ 'remove_f90_comments' , ],
[ 'remove_inline' , '\!.*$' ],
],
'Fortran 95' => [
[ 'remove_f77_comments' , ],
[ 'remove_f90_comments' , ],
[ 'remove_inline' , '\!.*$' ],
],
'Freemarker Template' => [
[ 'remove_between_general', '<#--', '-->' ],
],
'FXML' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'F#' => [
[ 'remove_between_general', '(*', '*)' ],
[ 'remove_matches' , '^\s*//' ],
],
'F# Script' => [
[ 'call_regexp_common' , 'Pascal' ],
[ 'remove_matches' , '^\s*//' ],
],
'GDScript' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Glade' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'GLSL' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Go' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
[ 'remove_inline' , '//.*$' ],
],
'Gradle' => [ # same as Groovy
[ 'remove_inline' , '//.*$' ],
# separate /* inside quoted strings with two
# concatenated strings split between / and *
[ 'replace_between_regex', '(["\'])(.*?/)(\*.*?)\g1',
'(.*?)' , '"$1$2$1 + $1$3$1$4"', 0],
[ 'rm_comments_in_strings', '"""', '/*', '*/', 1],
[ 'rm_comments_in_strings', '"""', '//', '', 1],
[ 'rm_comments_in_strings', "'''", '/*', '*/', 1],
[ 'rm_comments_in_strings', "'''", '//', '', 1],
[ 'call_regexp_common' , 'C++' ],
],
'Grails' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
[ 'remove_jsp_comments' , ],
[ 'add_newlines' , ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'GraphQL' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Groovy' => [
[ 'remove_inline' , '//.*$' ],
# separate /* inside quoted strings with two
# concatenated strings split between / and *
[ 'replace_between_regex', '(["\'])(.*?/)(\*.*?)\g1',
'(.*?)' , '"$1$2$1 + $1$3$1$4"', 0],
[ 'rm_comments_in_strings', '"""', '/*', '*/', 1],
[ 'rm_comments_in_strings', '"""', '//', '', 1],
[ 'rm_comments_in_strings', "'''", '/*', '*/', 1],
[ 'rm_comments_in_strings', "'''", '//', '', 1],
[ 'call_regexp_common' , 'C++' ],
],
'Handlebars' => [
[ 'remove_between_general', '{{!--', '--}}' ],
[ 'remove_between_general', '{{!', '}}' ],
[ 'remove_html_comments', ],
],
'Harbour' => [
[ 'remove_matches' , '^\s*\&\&' ],
[ 'remove_matches' , '^\s*\*' ],
[ 'remove_matches' , '^\s*NOTE' ],
[ 'remove_matches' , '^\s*note' ],
[ 'remove_matches' , '^\s*Note' ],
[ 'remove_inline' , '//.*$' ],
[ 'remove_inline' , '\&\&.*$' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Haml' => [
[ 'remove_haml_block' , ],
[ 'remove_html_comments', ],
[ 'remove_matches' , '^\s*/\s*\S+' ],
[ 'remove_matches' , '^\s*-#\s*\S+' ],
],
'Haxe' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'HCL' => [
[ 'remove_matches' , '^\s*#' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'HLSL' => [
[ 'remove_inline' , '//.*$' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'HTML' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Hoon' => [
[ 'remove_matches' , '^\s*:[:><]' ],
[ 'remove_inline' , ':[:><].*$' ],
],
'INI' => [
[ 'remove_matches' , '^\s*;' ],
],
'XHTML' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Haskell' => [ [ 'remove_haskell_comments', '>filename<' ], ],
'IDL' => [ [ 'remove_matches' , '^\s*;' ], ],
'IDL/Qt Project/Prolog/ProGuard' => [ [ 'die' , ], ], # never called
'Idris' => [
[ 'remove_haskell_comments', '>filename<' ],
[ 'remove_matches' , '^\s*\|{3}' ],
],
'Igor Pro' => [
[ 'remove_matches' , '^\s*//' ],
[ 'remove_inline' , '//.*$' ],
],
'Literate Idris' => [
[ 'remove_matches' , '^[^>]' ],
],
'Imba' => [
[ 'remove_matches' , '^\s*#\s'],
[ 'remove_inline' , '#\s.*$' ],
[ 'remove_between_regex', '###', '###' ],
],
'InstallShield' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'IPL' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Jam' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'JSP' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
[ 'remove_jsp_comments' , ],
[ 'remove_matches' , '^\s*//' ],
[ 'add_newlines' , ],
[ 'call_regexp_common' , 'C' ],
],
'JavaServer Faces' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Java' => [
[ 'replace_regex', '\\\\$', ' '],
# Java seems to have more path globs in strings
# than other languages. The variations makes
# it tricky to craft a universal fix.
[ 'replace_between_regex', '(["\'])(.*?/\*)\g1',
'(.*?)' , '"xx"'],
[ 'replace_between_regex', '(["\'])(.*?\*/)\g1',
'(.*?)' , '"xx"'],
## separate /* inside quoted strings with two
## concatenated strings split between / and *
## -> defeated by "xx/**/*_xx" issue 365
#[ 'replace_between_regex', '(["\'])(.*?/)(\*.*?)\g1',
# '(.*?)' , '"$1$2$1 + $1$3$1$4"'],
[ 'call_regexp_common' , 'C++' ],
],
'JavaScript' => [
[ 'rm_comments_in_strings', "'", '/*', '*/' ],
[ 'rm_comments_in_strings', "'", '//', '' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'JSX' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'JCL' => [ [ 'remove_jcl_comments' , ], ],
'JSON' => [ # ECMA-404, the JSON standard definition
# makes no provision for JSON comments
# so just use a placeholder filter
[ 'remove_matches' , '^\s*$' ],
],
'JSON5' => [ # same as JavaScript
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Julia' => [
[ 'remove_between_general', '#=', '=#' ],
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Kotlin' => [
[ 'rm_comments_in_strings', '"""', '/*', '*/', 1],
[ 'rm_comments_in_strings', '"""', '//', '', 1],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Lean' => [
[ 'remove_between_general', '/-', '-/' ],
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , '--.*$' ],
],
'LESS' => [
# [ 'remove_matches' , '^\s*//' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'LFE' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_between_general', '#|', '|#' ],
],
'liquid' => [
[ 'remove_between_general', '{% comment %}',
'{% endcomment %}' ],
[ 'remove_html_comments', ],
],
'Lisp' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_between_general', '#|', '|#' ],
],
'Lisp/OpenCL' => [ [ 'die' , ], ], # never called
'Lisp/Julia' => [ [ 'die' , ], ], # never called
'LiveLink OScript' => [ [ 'remove_matches' , '^\s*//' ], ],
'Logtalk' => [ # same filters as Prolog
[ 'remove_matches' , '^\s*\%' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_inline' , '(//|\%).*$' ],
],
# 'Lua' => [ [ 'call_regexp_common' , 'lua' ], ],
'Lua' => [
[ 'remove_between_general', '--[=====[', ']=====]' ],
[ 'remove_between_general', '--[====[', ']====]' ],
[ 'remove_between_general', '--[===[', ']===]' ],
[ 'remove_between_general', '--[==[', ']==]' ],
[ 'remove_between_general', '--[=[', ']=]' ],
[ 'remove_between_general', '--[[', ']]' ],
[ 'remove_matches' , '^\s*\-\-' ],
],
'make' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'MATLAB' => [
[ 'remove_matches' , '^\s*%' ],
[ 'remove_inline' , '%.*$' ],
],
'Mathematica' => [
[ 'remove_between_general', '(*', '*)' ],
],
'Maven/XML' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Maven' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Mercury' => [
[ 'remove_inline' , '%.*$' ],
[ 'remove_matches' , '^\s*%' ],
],
'Modula3' => [ [ 'call_regexp_common' , 'Pascal' ], ],
# Modula 3 comments are (* ... *) so applying the Pascal filter
# which also treats { ... } as a comment is not really correct.
'Nemerle' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Objective C' => [
# [ 'remove_matches' , '^\s*//' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Objective C++' => [
# [ 'remove_matches' , '^\s*//' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'OCaml' => [
[ 'remove_OCaml_comments', ],
],
'OpenCL' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'PHP/Pascal' => [ [ 'die' , ], ], # never called
'Mako' => [
[ 'remove_matches' , '##.*$' ],
],
'Markdown' => [
[ 'remove_between_regex',
'\[(comment|\/\/)?\]\s*:?\s*(<\s*>|#)?\s*\(.*?', '.*?\)' ],
# http://stackoverflow.com/questions/4823468/comments-in-markdown
],
'MATLAB/Mathematica/Objective C/MUMPS/Mercury' => [ [ 'die' , ], ], # never called
'MUMPS' => [ [ 'remove_matches' , '^\s*;' ], ],
'Mustache' => [
[ 'remove_between_general', '{{!', '}}' ],
],
'Nim' => [
[ 'remove_between_general', '#[', ']#' ],
[ 'remove_matches' , '^\s*#' ],
# [ 'docstring_to_C' ],
# [ 'call_regexp_common' , 'C' ],
[ 'remove_inline' , '#.*$' ],
],
'Nix' => [
[ 'call_regexp_common' , 'C' ],
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Octave' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Oracle Forms' => [ [ 'call_regexp_common' , 'C' ], ],
'Oracle Reports' => [ [ 'call_regexp_common' , 'C' ], ],
'Oracle PL/SQL' => [
[ 'call_regexp_common' , 'PL/SQL' ],
],
'Pascal' => [
[ 'remove_between_regex', '\{[^$]', '}' ],
[ 'remove_between_general', '(*', '*)' ],
[ 'remove_matches' , '^\s*//' ],
],
####'Pascal' => [
#### [ 'call_regexp_common' , 'Pascal' ],
#### [ 'remove_matches' , '^\s*//' ],
#### ],
'Pascal/Puppet' => [ [ 'die' , ], ], # never called
'Puppet' => [
[ 'remove_matches' , '^\s*#' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_inline' , '#.*$' ],
],
'PureScript' => [
[ 'remove_matches' , '^\s*--' ],
[ 'remove_between_general', '{-', '-}' ],
[ 'remove_inline' , '--.*$' ],
],
'Patran Command Language'=> [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_matches' , '^\s*\$#' ],
[ 'call_regexp_common' , 'C' ],
],
'PL/I' => [
[ 'call_regexp_common' , 'C' ],
],
'PL/M' => [
[ 'call_regexp_common' , 'C' ],
],
'Perl' => [ [ 'remove_below' , '^__(END|DATA)__'],
[ 'remove_matches' , '^\s*#' ],
[ 'remove_below_above' , '^=head1', '^=cut' ],
[ 'remove_inline' , '#.*$' ],
],
'Perl/Prolog' => [ [ 'die' , ], ], # never called
'Pig Latin' => [
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , '--.*$' ],
[ 'call_regexp_common' , 'C' ],
],
'ProGuard' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'PO File' => [
[ 'remove_matches' , '^\s*#[^,]' ], # '#,' is not a comment
],
'PowerBuilder' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'PowerShell' => [
[ 'powershell_to_C' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Prolog' => [
[ 'remove_matches' , '^\s*\%' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_inline' , '(//|\%).*$' ],
],
'Protocol Buffers' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Pug' => [
[ 'remove_pug_block' , ],
[ 'remove_matches' , '^\s*//' ],
[ 'remove_inline' , '//.*$' ],
],
'Python' => [
[ 'remove_matches' , '/\*' ],
[ 'remove_matches' , '\*/' ],
[ 'remove_matches' , '^\s*#' ],
[ 'docstring_to_C' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_inline' , '#.*$' ],
],
'Jupyter Notebook' => [ # these are JSON files; have no comments
# would have to parse JSON for
# "cell_type": "code"
# to count code lines
[ 'jupyter_nb' ],
[ 'remove_matches' , '^\s*$' ],
],
'PHP' => [
[ 'remove_matches' , '^\s*#' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
[ 'remove_inline' , '#.*$' ],
],
'QML' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
[ 'remove_inline' , '//.*$' ],
],
'Qt' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Qt Linguist' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Qt Project' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'R' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Rmd' => [
[ 'reduce_to_rmd_code_blocks' ],
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Racket' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_inline' , ';.*$' ],
],
'Raku' => [ [ 'remove_matches' , '^\s*#' ],
[ 'remove_below_above' , '^=head1', '^=cut' ],
[ 'remove_below_above' , '^=begin', '^=end' ],
[ 'remove_inline' , '#.*$' ],
],
'Raku/Prolog' => [ [ 'die' , ], ], # never called
'RAML' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'RapydScript' => [
[ 'remove_matches' , '^\s*#' ],
[ 'docstring_to_C' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_inline' , '#.*$' ],
],
'Razor' => [
[ 'remove_between_general', '@*', '*@' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'reStructuredText' => [
[ 'remove_between_regex', '^\.\.', '^[^ \n\t\r\f\.]' ]
],
'Rexx' => [ [ 'call_regexp_common' , 'C' ], ],
'ReasonML' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'remove_between_general', '/*', '*/' ],
],
'RobotFramework' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_matches' , '^\s*Comment' ],
[ 'remove_matches' , '^\s*\*{3}\s+(Variables|Test\s+Cases|Settings|Keywords)\s+\*{3}' ] ,
[ 'remove_matches' , '^\s*\[(Documentation|Tags)\]' ],
[ 'remove_inline' , '#.*$' ],
],
'Ruby' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_below_above' , '^=begin', '^=end' ],
[ 'remove_inline' , '#.*$' ],
],
'Ruby HTML' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'Rust' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'SaltStack' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'SAS' => [
[ 'call_regexp_common' , 'C' ],
[ 'remove_between_general', '*', ';' ],
],
'Sass' => [
[ 'remove_matches' , '^\s*//' ],
[ 'remove_inline' , '//.*$' ],
],
'Scala' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Scheme/SaltStack' => [ [ 'die' , ], ], # never called
'Scheme' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_inline' , ';.*$' ],
],
'sed' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Slice' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Slim' => [
[ 'remove_slim_block' , ],
],
'SKILL' => [
[ 'call_regexp_common' , 'C' ],
[ 'remove_matches' , '^\s*;' ],
],
'SKILL++' => [
[ 'call_regexp_common' , 'C' ],
[ 'remove_matches' , '^\s*;' ],
],
'Squirrel' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Starlark' => [
[ 'remove_matches' , '^\s*#' ],
[ 'docstring_to_C' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_inline' , '#.*$' ],
],
'Solidity' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'SparForte' => [
[ 'remove_matches' , '^\s*#!' ],
[ 'remove_matches' , '^\s*--' ],
],
'Specman e' => [
[ 'pre_post_fix' , "'>", "<'"],
[ 'remove_between_general', "^'>", "^<'" ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++', ],
[ 'remove_matches' , '^\s*--' ],
[ 'rm_last_line' , ], # undo pre_post_fix addition
# of trailing line of just <'
],
'SQL' => [
[ 'call_regexp_common' , 'C' ],
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , '--.*$' ],
],
'SQL Stored Procedure'=> [
[ 'call_regexp_common' , 'C' ],
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , '--.*$' ],
],
'SQL Data' => [
[ 'call_regexp_common' , 'C' ],
[ 'remove_matches' , '^\s*--' ],
[ 'remove_inline' , '--.*$' ],
],
'Smalltalk' => [
[ 'call_regexp_common' , 'Smalltalk' ],
],
'Smarty' => [
[ 'smarty_to_C' ],
[ 'call_regexp_common' , 'C' ],
],
'Standard ML' => [
[ 'remove_between_general', '(*', '*)' ],
],
'Stata' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Stylus' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'SugarSS' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Svelte' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'SVG' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Swift' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'SWIG' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'm4' => [ [ 'remove_matches' , '^dnl\s' ], ],
'C Shell' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Kermit' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_matches' , '^\s*;' ],
[ 'remove_inline' , '#.*$' ],
],
'Korn Shell' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Tcl/Tk' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Teamcenter met' => [ [ 'call_regexp_common' , 'C' ], ],
'Teamcenter mth' => [ [ 'remove_matches' , '^\s*#' ], ],
'TeX' => [
[ 'remove_matches' , '^\s*%' ],
[ 'remove_inline' , '%.*$' ],
],
'Thrift' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Titanium Style Sheet' => [
[ 'remove_matches' , '^\s*//' ],
[ 'remove_inline' , '//.*$' ],
[ 'remove_between_regex', '/[^/]', '[^/]/' ],
],
'TNSDL' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'call_regexp_common' , 'C++' ],
],
'TOML' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'TTCN' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'TITAN Project File Information' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Twig' => [
[ 'remove_between_general', '{#', '#}' ],
],
'TypeScript' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Unity-Prefab' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'Visual Fox Pro' => [
[ 'remove_matches' , '^\s*\*' ],
[ 'remove_inline' , '\*.*$' ],
[ 'remove_matches' , '^\s*&&' ],
[ 'remove_inline' , '&&.*$' ],
],
'Softbridge Basic' => [ [ 'remove_above' , '^\s*Attribute\s+VB_Name\s+=' ],
[ 'remove_matches' , '^\s*Attribute\s+'],
[ 'remove_matches' , '^\s*\47'], ], # \47 = '
# http://www.altium.com/files/learningguides/TR0114%20VHDL%20Language%20Reference.pdf
'Vala' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Vala Header' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Verilog-SystemVerilog/Coq' => [ ['die'] ], # never called
'Verilog-SystemVerilog' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'VHDL' => [
[ 'remove_matches' , '^\s*--' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
[ 'remove_inline' , '--.*$' ],
],
'vim script' => [
[ 'remove_matches' , '^\s*"' ],
[ 'remove_inline' , '".*$' ],
],
'Visual Basic' => [ [ 'remove_above' , '^\s*Attribute\s+VB_Name\s+=' ],
[ 'remove_matches' , '^\s*Attribute\s+'],
[ 'remove_matches' , '^\s*\47'], ], # \47 = '
'Visualforce Component' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Visualforce Page' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'Velocity Template Language' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
[ 'remove_jsp_comments' , ],
[ 'remove_matches' , '^\s*##' ],
[ 'remove_between_general', '#**', '*#' ],
[ 'add_newlines' , ],
],
'Vuejs Component' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'Teamcenter def' => [ [ 'remove_matches' , '^\s*#' ], ],
'Windows Module Definition' => [
[ 'remove_matches' , '^\s*;' ],
[ 'remove_inline' , ';.*$' ],
],
'yacc' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'YAML' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
'lex' => [ [ 'call_regexp_common' , 'C' ], ],
'XAML' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'xBase Header' => [
# [ 'remove_matches' , '^\s*//' ],
[ 'remove_matches' , '^\s*\&\&' ],
[ 'remove_matches' , '^\s*\*' ],
[ 'remove_matches' , '^\s*NOTE' ],
[ 'remove_matches' , '^\s*note' ],
[ 'remove_matches' , '^\s*Note' ],
[ 'remove_inline' , '\&\&.*$' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'xBase' => [
# [ 'remove_matches' , '^\s*//' ],
[ 'remove_matches' , '^\s*\&\&' ],
[ 'remove_matches' , '^\s*\*' ],
[ 'remove_matches' , '^\s*NOTE' ],
[ 'remove_matches' , '^\s*note' ],
[ 'remove_matches' , '^\s*Note' ],
[ 'remove_inline' , '\&\&.*$' ],
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'MXML' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
[ 'remove_matches' , '^\s*//' ],
[ 'add_newlines' , ],
[ 'call_regexp_common' , 'C' ],
],
'WebAssembly' => [
[ 'remove_matches' , '^\s*;;' ],
],
'Windows Message File' => [
[ 'remove_matches' , '^\s*;\s*//' ],
[ 'call_regexp_common' , 'C' ],
[ 'remove_matches' , '^\s*;\s*$' ],
# next line only hypothetical
# [ 'remove_matches_2re' , '^\s*;\s*/\*',
# '^\s*;\s*\*/', ],
],
'Windows Resource File' => [
[ 'rm_comments_in_strings', '"', '/*', '*/' ],
[ 'rm_comments_in_strings', '"', '//', '' ],
[ 'call_regexp_common' , 'C++' ],
],
'WiX source' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'WiX include' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'WiX string localization' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'XMI' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'XML' => [
[ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ],
],
'XQuery' => [
[ 'remove_between_general', '(:', ':)' ],
],
'XSD' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'XSLT' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'Xtend' => [ # copy of Java, plus triple << inline
# separate /* inside quoted strings with two
# concatenated strings split between / and *
[ 'replace_between_regex', '(["\'])(.*?/)(\*.*?)\g1',
'(.*?)' , '"$1$2$1 + $1$3$1$4"', 0],
[ 'call_regexp_common' , 'C++' ],
[ 'remove_matches' , '^\s*\x{c2ab}{3}' ], # doesn't work
# \xCA2B is unicode << character
],
'NAnt script' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'MSBuild script' => [ [ 'remove_html_comments', ],
[ 'call_regexp_common' , 'HTML' ], ],
'zsh' => [
[ 'remove_matches' , '^\s*#' ],
[ 'remove_inline' , '#.*$' ],
],
);
# 1}}}
%{$rh_EOL_continuation_re} = ( # {{{1
'ActionScript' => '\\\\$' ,
'AspectJ' => '\\\\$' ,
'Assembly' => '\\\\$' ,
'ASP' => '\\\\$' ,
'ASP.NET' => '\\\\$' ,
'Ada' => '\\\\$' ,
'awk' => '\\\\$' ,
'bc' => '\\\\$' ,
'C' => '\\\\$' ,
'C++' => '\\\\$' ,
'C/C++ Header' => '\\\\$' ,
'CMake' => '\\\\$' ,
'Cython' => '\\\\$' ,
'C#' => '\\\\$' ,
'D' => '\\\\$' ,
'Dart' => '\\\\$' ,
'Expect' => '\\\\$' ,
'Gencat NLS' => '\\\\$' ,
'Go' => '\\\\$' ,
'IDL' => '\$\\$' ,
'Igor Pro' => '\\$' ,
# 'Java' => '\\\\$' ,
'JavaScript' => '\\\\$' ,
'JSON5' => '\\\\$' ,
'JSX' => '\\\\$' ,
'LESS' => '\\\\$' ,
'Lua' => '\\\\$' ,
'make' => '\\\\$' ,
'MATLAB' => '\.\.\.\s*$' ,
'MXML' => '\\\\$' ,
'Objective C' => '\\\\$' ,
'Objective C++' => '\\\\$' ,
'OCaml' => '\\\\$' ,
'Octave' => '\.\.\.\s*$' ,
'Qt Project' => '\\\\$' ,
'Patran Command Language'=> '\\\\$' ,
'PowerBuilder' => '\\\\$' ,
'PowerShell' => '\\\\$' ,
'Python' => '\\\\$' ,
'R' => '\\\\$' ,
'Rmd' => '\\\\$' ,
'Ruby' => '\\\\$' ,
'sed' => '\\\\$' ,
'Swift' => '\\\\$' ,
'Bourne Again Shell' => '\\\\$' ,
'Bourne Shell' => '\\\\$' ,
'C Shell' => '\\\\$' ,
'Kermit' => '\\\\$' ,
'Korn Shell' => '\\\\$' ,
'Starlark' => '\\\\$' ,
'Solidity' => '\\\\$' ,
'Stata' => '///$' ,
'Stylus' => '\\\\$' ,
'Tcl/Tk' => '\\\\$' ,
'TTCN' => '\\\\$' ,
'TypeScript' => '\\\\$' ,
'lex' => '\\\\$' ,
'Vala' => '\\\\$' ,
'Vala Header' => '\\\\$' ,
'zsh' => '\\\\$' ,
);
# 1}}}
%{$rh_Not_Code_Extension} = ( # {{{1
'1' => 1, # Man pages (documentation):
'2' => 1,
'3' => 1,
'4' => 1,
'5' => 1,
'6' => 1,
'7' => 1,
'8' => 1,
'9' => 1,
'a' => 1, # Static object code.
'ad' => 1, # X application default resource file.
'afm' => 1, # font metrics
'arc' => 1, # arc(1) archive
'arj' => 1, # arj(1) archive
'au' => 1, # Audio sound filearj(1) archive
'bak' => 1, # Backup files - we only want to count the "real" files.
'bdf' => 1,
'bmp' => 1,
'bz2' => 1, # bzip2(1) compressed file
'csv' => 1, # comma separated values
'desktop' => 1,
'dic' => 1,
'doc' => 1,
'elc' => 1,
'eps' => 1,
'fig' => 1,
'gif' => 1,
'gz' => 1,
'hdf' => 1, # hierarchical data format
'in' => 1, # Debatable.
'jpg' => 1,
'kdelnk' => 1,
'man' => 1,
'mf' => 1,
'mp3' => 1,
'n' => 1,
'o' => 1, # Object code is generated from source code.
'o.cmd' => 1, # not DOS Batch; Linux kernel compilation optimization file
'pbm' => 1,
'pdf' => 1,
'pfb' => 1,
'png' => 1,
'ps' => 1, # Postscript is _USUALLY_ generated automatically.
'sgm' => 1,
'sgml' => 1,
'so' => 1, # Dynamically-loaded object code.
'Tag' => 1,
'text' => 1,
'tfm' => 1,
'tgz' => 1, # gzipped tarball
'tiff' => 1,
'tsv' => 1, # tab separated values
'txt' => 1,
'vf' => 1,
'wav' => 1,
'xbm' => 1,
'xpm' => 1,
'Y' => 1, # file compressed with "Yabba"
'Z' => 1, # file compressed with "compress"
'zip' => 1, # zip archive
'gitignore' => 1,
); # 1}}}
%{$rh_Not_Code_Filename} = ( # {{{1
'AUTHORS' => 1,
'BUGS' => 1,
'BUGS' => 1,
'Changelog' => 1,
'ChangeLog' => 1,
'ChangeLog' => 1,
'Changes' => 1,
'CHANGES' => 1,
'COPYING' => 1,
'COPYING' => 1,
'DESCRIPTION' => 1, # R packages metafile
'.cvsignore' => 1,
'Entries' => 1,
'FAQ' => 1,
'iconfig.h' => 1, # Skip "iconfig.h" files; they're used in Imakefiles.
'INSTALL' => 1,
'MAINTAINERS' => 1,
'MD5SUMS' => 1,
'NAMESPACE' => 1, # R packages metafile
'NEWS' => 1,
'readme' => 1,
'Readme' => 1,
'README' => 1,
'README.tk' => 1, # used in kdemultimedia, it's confusing.
'Repository' => 1,
'Root' => 1, # CVS
'TODO' => 1,
);
# 1}}}
%{$rh_Scale_Factor} = ( # {{{1
'(unknown)' => 0.00,
'1032/af' => 5.00,
'1st generation default' => 0.25,
'2nd generation default' => 0.75,
'3rd generation default' => 1.00,
'4th generation default' => 4.00,
'5th generation default' => 16.00,
'aas macro' => 0.88,
'abap/4' => 5.00,
'ABAP' => 5.00,
'accel' => 4.21,
'access' => 2.11,
'ActionScript' => 1.36,
'actor' => 3.81,
'acumen' => 2.86,
'Ada' => 0.52,
'Ada 83' => 1.13,
'Ada 95' => 1.63,
'adr/dl' => 2.00,
'adr/ideal/pdl' => 4.00,
'ads/batch' => 4.00,
'ads/online' => 4.00,
'ADSO/IDSM' => 3.00,
'advantage' => 2.11,
'Agda' => 2.11,
'ai shell default' => 1.63,
'ai shells' => 1.63,
'algol 68' => 0.75,
'algol w' => 0.75,
'ambush' => 2.50,
'aml' => 1.63,
'AMPLE' => 2.00,
'Ant/XML' => 1.90,
'Ant' => 1.90,
'ANTLR Grammar' => 2.00,
'amppl ii' => 1.25,
'ansi basic' => 1.25,
'ansi cobol 74' => 0.75,
'ansi cobol 85' => 0.88,
'SQL' => 6.15,
'SQL Stored Procedure' => 6.15,
'SQL Data' => 1.00,
'answer/db' => 6.15,
'Apex Class' => 1.50,
'APL' => 2.50,
'applesoft basic' => 0.63,
'application builder' => 4.00,
'application manager' => 2.22,
'aps' => 0.96,
'aps' => 4.71,
'apt' => 1.13,
'aptools' => 4.00,
'arc' => 1.63,
'ariel' => 0.75,
'arity' => 1.63,
'art' => 1.63,
'art enterprise' => 1.74,
'artemis' => 2.00,
'artim' => 1.74,
'AsciiDoc' => 1.50,
'AspectJ' => 1.36,
'as/set' => 4.21,
'asi/inquiry' => 6.15,
'ask windows' => 1.74,
'asa' => 1.29,
'ASP' => 1.29,
'ASP.NET' => 1.29,
'aspx' => 1.29,
'asax' => 1.29,
'ascx' => 1.29,
'asmx' => 1.29,
'config' => 1.29,
'webinfo' => 1.29,
'CCS' => 5.33,
'Apex Trigger' => 1.4 ,
'Arduino Sketch' => 1.00,
'Assembly' => 0.25,
'Assembly (macro)' => 0.51,
'associative default' => 1.25,
'autocoder' => 0.25,
'AutoHotkey' => 1.29,
'awk' => 3.81,
'aztec c' => 0.63,
'balm' => 0.75,
'base sas' => 1.51,
'basic' => 0.75,
'basic a' => 0.63,
'Bazel' => 1.00,
'bc' => 1.50,
'berkeley pascal' => 0.88,
'better basic' => 0.88,
'Blade' => 2.00,
'bliss' => 0.75,
'bmsgen' => 2.22,
'boeingcalc' => 13.33,
'bteq' => 6.15,
'Brainfuck' => 0.10,
'BrightScript' => 2.00,
'builder' => 2.00,
'C' => 0.77,
'c set 2' => 0.88,
'C#' => 1.36,
'C++' => 1.51,
'c86plus' => 0.63,
'cadbfast' => 2.00,
'caearl' => 2.86,
'cast' => 1.63,
'cbasic' => 0.88,
'cdadl' => 4.00,
'cellsim' => 1.74,
'ColdFusion' => 4.00,
'ColdFusion CFScript' => 4.00,
'Chapel' => 2.96,
'chili' => 0.75,
'chill' => 0.75,
'cics' => 1.74,
'clarion' => 1.38,
'clascal' => 1.00,
'Clean' => 2.50,
'cli' => 2.50,
'clipper' => 2.05,
'clipper db' => 2.00,
'clos' => 3.81,
'Clojure' => 1.25,
'ClojureScript' => 1.25,
'ClojureC' => 1.25,
'clout' => 2.00,
'CMake' => 1.00,
'cms2' => 0.75,
'cmsgen' => 4.21,
'COBOL' => 1.04,
'COBOL ii' => 0.75,
'COBOL/400' => 0.88,
'cobra' => 4.00,
'codecenter' => 2.22,
'cofac' => 2.22,
'CoffeeScript' => 2.00,
'cogen' => 2.22,
'cognos' => 2.22,
'cogo' => 1.13,
'comal' => 1.00,
'comit ii' => 1.25,
'common lisp' => 1.25,
'concurrent pascal' => 1.00,
'conniver' => 1.25,
'cool:gen/ief' => 2.58,
'Coq' => 5.00,
'coral 66' => 0.75,
'corvet' => 4.21,
'corvision' => 5.33,
'cpl' => 0.50,
'Crystal' => 2.50,
'Crystal Reports' => 4.00,
'csl' => 1.63,
'CSON' => 2.50,
'csp' => 1.51,
'cssl' => 1.74,
'CSS' => 1.0,
'Cucumber' => 3.00,
'CUDA' => 1.00,
'culprit' => 1.57,
'cxpert' => 1.63,
'cygnet' => 4.21,
'D' => 1.70,
'DAL' => 1.50,
'Dart' => 2.00,
'data base default' => 2.00,
'dataflex' => 2.00,
'datatrieve' => 4.00,
'dbase iii' => 2.00,
'dbase iv' => 1.54,
'DIET' => 2.00,
'diff' => 1.00,
'decision support default' => 2.22,
'decrally' => 2.00,
'delphi' => 2.76,
'dhall' => 2.11,
'DITA' => 1.90,
'dl/1' => 2.00,
'dtrace' => 2.00,
'NASTRAN DMAP' => 2.35,
'dna4' => 4.21,
'DOORS Extension Language' => 1.50,
'Dockerfile' => 2.00,
'DOS Batch' => 0.63,
'Drools' => 2.00,
'dsp assembly' => 0.50,
'dtabl' => 1.74,
'dtipt' => 1.74,
'dyana' => 1.13,
'dynamoiii' => 1.74,
'easel' => 2.76,
'easy' => 1.63,
'easytrieve+' => 2.35,
'eclipse' => 1.63,
'ECPP' => 1.90,
'eda/sql' => 6.67,
'edscheme 3.4' => 1.51,
'EEx' => 2.00,
'eiffel' => 3.81,
'EJS' => 2.50,
'Elixir' => 2.11,
'Elm' => 2.50,
'enform' => 1.74,
'englishbased default' => 1.51,
'ensemble' => 2.76,
'epos' => 4.00,
'Embedded Crystal' => 2.00,
'ERB' => 2.00,
'Erlang' => 2.11,
'esf' => 2.00,
'espadvisor' => 1.63,
'espl/i' => 1.13,
'euclid' => 0.75,
'excel' => 1.74,
'excel 12' => 13.33,
'excel 34' => 13.33,
'excel 5' => 13.33,
'express' => 2.22,
'exsys' => 1.63,
'extended common lisp' => 1.43,
'eznomad' => 2.22,
'facets' => 4.00,
'factorylink iv' => 2.76,
'fame' => 2.22,
'Fennel' => 2.50,
'filemaker pro' => 2.22,
'flavors' => 2.76,
'flex' => 1.74,
'flexgen' => 2.76,
'Focus' => 1.90,
'foil' => 1.51,
'forte' => 4.44,
'Forth' => 1.25,
'Fortran 66' => 0.63,
'Fortran 77' => 0.75,
'Fortran 90' => 1.00,
'Fortran 95' => 1.13,
'Fortran II' => 0.63,
'foundation' => 2.76,
'foxpro' => 2.29,
'foxpro 1' => 2.00,
'foxpro 2.5' => 2.35,
'framework' => 13.33,
'Freemarker Template' => 1.48,
'F#' => 2.50,
'F# Script' => 2.50,
'g2' => 1.63,
'gamma' => 5.00,
'genascript' => 2.96,
'gener/ol' => 6.15,
'genexus' => 5.33,
'genifer' => 4.21,
'geode 2.0' => 5.00,
'gfa basic' => 2.35,
'Glade' => 2.00,
'GLSL' => 2.00,
'gml' => 1.74,
'golden common lisp' => 1.25,
'gpss' => 1.74,
'guest' => 2.86,
'guru' => 1.63,
'GDScript' => 2.50,
'Go' => 2.50,
'Gradle' => 4.00,
'Grails' => 1.48,
'GraphQL' => 4.00,
'Groovy' => 4.10,
'gw basic' => 0.82,
'Harbour' => 2.00,
'Haskell' => 2.11,
'HCL' => 2.50,
'high c' => 0.63,
'hlevel' => 1.38,
'hp basic' => 0.63,
'Haml' => 2.50,
'Handlebars' => 2.50,
'Haxe' => 2.00,
'Hoon' => 2.00,
'HTML' => 1.90,
'XHTML' => 1.90,
'XMI' => 1.90,
'XML' => 1.90,
'FXML' => 1.90,
'MXML' => 1.90,
'XSLT' => 1.90,
'DTD' => 1.90,
'XSD' => 1.90,
'NAnt script' => 1.90,
'MSBuild script' => 1.90,
'HLSL' => 2.00,
'HTML 2' => 5.00,
'HTML 3' => 5.33,
'huron' => 5.00,
'ibm adf i' => 4.00,
'ibm adf ii' => 4.44,
'ibm advanced basic' => 0.82,
'ibm cics/vs' => 2.00,
'ibm compiled basic' => 0.88,
'ibm vs cobol' => 0.75,
'ibm vs cobol ii' => 0.88,
'ices' => 1.13,
'icon' => 1.00,
'ideal' => 1.54,
'idms' => 2.00,
'Idris' => 2.00,
'Literate Idris' => 2.00,
'ief' => 5.71,
'ief/cool:gen' => 2.58,
'iew' => 5.71,
'ifps/plus' => 2.50,
'Igor Pro' => 4.00,
'Imba' => 3.00,
'imprs' => 2.00,
'informix' => 2.58,
'ingres' => 2.00,
'INI' => 1.00,
'inquire' => 6.15,
'insight2' => 1.63,
'install/1' => 5.00,
'InstallShield' => 1.90,
'intellect' => 1.51,
'interlisp' => 1.38,
'interpreted basic' => 0.75,
'interpreted c' => 0.63,
'IPL' => 2.00,
'iqlisp' => 1.38,
'iqrp' => 6.15,
'j2ee' => 1.60,
'Jam' => 2.00,
'janus' => 1.13,
'Java' => 1.36,
'JavaScript' => 1.48,
'JavaServer Faces' => 1.5 ,
'JSON' => 2.50,
'JSON5' => 2.50,
'JSP' => 1.48,
'JSX' => 1.48,
'Velocity Template Language' => 1.00,
'JCL' => 1.67,
'joss' => 0.75,
'jovial' => 0.75,
'jsp' => 1.36,
'kappa' => 2.00,
'kbms' => 1.63,
'kcl' => 1.25,
'kee' => 1.63,
'keyplus' => 2.00,
'kl' => 1.25,
'klo' => 1.25,
'knowol' => 1.63,
'krl' => 1.38,
'Kermit' => 2.00,
'Korn Shell' => 3.81,
'Kotlin' => 2.00,
'ladder logic' => 2.22,
'lambit/l' => 1.25,
'lattice c' => 0.63,
'Lean' => 3.00,
'LESS' => 1.50,
'LFE' => 1.25,
'liana' => 0.63,
'lilith' => 1.13,
'linc ii' => 5.71,
'liquid' => 3.00,
'Lisp' => 1.25,
'LiveLink OScript' => 3.5 ,
'loglisp' => 1.38,
'Logtalk' => 2.00,
'loops' => 3.81,
'lotus 123 dos' => 13.33,
'lotus macros' => 0.75,
'lotus notes' => 3.64,
'lucid 3d' => 13.33,
'lyric' => 1.51,
'm4' => 1.00,
'm' => 5.00,
'macforth' => 1.25,
'mach1' => 2.00,
'machine language' => 0.13,
'maestro' => 5.00,
'magec' => 5.00,
'magik' => 3.81,
'Lake' => 3.81,
'make' => 2.50,
'Mako' => 1.50, # Not sure about the scaling.
'mantis' => 2.96,
'mapper' => 0.99,
'mark iv' => 2.00,
'mark v' => 2.22,
'Markdown' => 1.00,
'mathcad' => 16.00,
'Maven' => 1.90,
'mdl' => 2.22,
'mentor' => 1.51,
'mesa' => 0.75,
'microfocus cobol' => 1.00,
'microforth' => 1.25,
'microsoft c' => 0.63,
'microstep' => 4.00,
'miranda' => 2.00,
'model 204' => 2.11,
'modula 2' => 1.00,
'mosaic' => 13.33,
# 'ms c ++ v. 7' => 1.51,
'ms compiled basic' => 0.88,
'msl' => 1.25,
'mulisp' => 1.25,
'MUMPS' => 4.21,
'Mustache' => 1.75,
'Nastran' => 1.13,
'natural' => 1.54,
'natural 1' => 1.51,
'natural 2' => 1.74,
'natural construct' => 3.20,
'natural language' => 0.03,
'Nemerle' => 2.50,
'netron/cap' => 4.21,
'nexpert' => 1.63,
'nial' => 1.63,
'Nim' => 2.00,
'Nix' => 2.70,
'nomad2' => 2.00,
'nonprocedural default' => 2.22,
'notes vip' => 2.22,
'nroff' => 1.51,
'object assembler' => 1.25,
'object lisp' => 2.76,
'object logo' => 2.76,
'object pascal' => 2.76,
'object star' => 5.00,
'Objective C' => 2.96,
'Objective C++' => 2.96,
'objectoriented default' => 2.76,
'objectview' => 3.20,
'OCaml' => 3.00,
'ogl' => 1.00,
'omnis 7' => 2.00,
'oodl' => 2.76,
'ops' => 1.74,
'ops5' => 1.38,
'oracle' => 2.76,
'Oracle Reports' => 2.76,
'Oracle Forms' => 2.67,
'Oracle Developer/2000' => 3.48,
'oscar' => 0.75,
'pacbase' => 1.67,
'pace' => 2.00,
'paradox/pal' => 2.22,
'Pascal' => 0.88,
'Patran Command Language' => 2.50,
'pc focus' => 2.22,
'pdl millenium' => 3.81,
'pdp11 ade' => 1.51,
'peoplesoft' => 2.50,
'Perl' => 4.00,
'persistance object builder' => 3.81,
'Pig Latin' => 1.00,
'pilot' => 1.51,
'PL/I' => 1.38,
'pl/1' => 1.38,
'PL/M' => 1.13,
'pl/s' => 0.88,
'Oracle PL/SQL' => 2.58,
'pl/sql' => 2.58,
'planit' => 1.51,
'planner' => 1.25,
'planperfect 1' => 11.43,
'plato' => 1.51,
'PO File' => 1.50,
'polyforth' => 1.25,
'pop' => 1.38,
'poplog' => 1.38,
'power basic' => 1.63,
'PowerBuilder' => 3.33,
'powerhouse' => 5.71,
'PowerShell' => 3.00,
'ppl (plus)' => 2.00,
'problemoriented default' => 1.13,
'proc' => 2.96,
'procedural default' => 0.75,
'professional pascal' => 0.88,
'program generator default' => 5.00,
'progress v4' => 2.22,
'ProGuard' => 2.50,
'proiv' => 1.38,
'Prolog' => 1.25,
'prose' => 0.75,
'proteus' => 0.75,
'Protocol Buffers' => 2.00,
'Pug' => 2.00,
'Puppet' => 2.00,
'PureScript' => 2.00,
'qbasic' => 1.38,
'qbe' => 6.15,
'qmf' => 5.33,
'QML' => 1.25,
'Qt' => 2.00,
'Qt Linguist' => 1.00,
'Qt Project' => 1.00,
'qnial' => 1.63,
'quattro' => 13.33,
'quattro pro' => 13.33,
'query default' => 6.15,
'quick basic 1' => 1.25,
'quick basic 2' => 1.31,
'quick basic 3' => 1.38,
'quick c' => 0.63,
'quickbuild' => 2.86,
'quiz' => 5.33,
'R' => 3.00,
'Rmd' => 3.00,
'Racket' => 1.50,
'Raku' => 4.00,
'rally' => 2.00,
'ramis ii' => 2.00,
'RAML' => 0.90,
'rapidgen' => 2.86,
'ratfor' => 0.88,
'rdb' => 2.00,
'realia' => 1.74,
'realizer 1.0' => 2.00,
'realizer 2.0' => 2.22,
'ReasonML' => 2.50,
'relate/3000' => 2.00,
'reStructuredText' => 1.50,
'reuse default' => 16.00,
'Razor' => 2.00,
'Rexx' => 1.19,
'rm basic' => 0.88,
'rm cobol' => 0.75,
'rm fortran' => 0.75,
'RobotFramework' => 2.50,
'rpg i' => 1.00,
'rpg ii' => 1.63,
'rpg iii' => 1.63,
'rtexpert 1.4' => 1.38,
'Rust' => 1.00,
'sabretalk' => 0.90,
'sail' => 0.75,
'sapiens' => 5.00,
'sas' => 1.95,
'savvy' => 6.15,
'sbasic' => 0.88,
'Scala' => 4.10,
'sceptre' => 1.13,
'Scheme' => 1.51,
'screen painter default' => 13.33,
'sequal' => 6.67,
'Slim' => 3.00,
'Solidity' => 1.48,
'Bourne Shell' => 3.81,
'Bourne Again Shell' => 3.81,
'ksh' => 3.81,
'zsh' => 3.81,
'Fish Shell' => 3.81,
'C Shell' => 3.81,
'siebel tools ' => 6.15,
'SaltStack' => 2.00,
'SAS' => 1.5 ,
'Sass' => 1.5 ,
'simplan' => 2.22,
'simscript' => 1.74,
'simula' => 1.74,
'simula 67' => 1.74,
'simulation default' => 1.74,
'SKILL' => 2.00,
'SKILL++' => 2.00,
'slogan' => 0.98,
'Slice' => 1.50,
'Smalltalk' => 4.00,
'smalltalk 286' => 3.81,
'smalltalk 80' => 3.81,
'smalltalk/v' => 3.81,
'Smarty' => 3.50,
'snap' => 1.00,
'snobol24' => 0.63,
'softscreen' => 5.71,
'Softbridge Basic' => 2.76,
'solo' => 1.38,
'SparForte' => 3.80,
'speakeasy' => 2.22,
'spinnaker ppl' => 2.22,
'splus' => 2.50,
'spreadsheet default' => 13.33,
'sps' => 0.25,
'spss' => 2.50,
'Specman e' => 2.00,
'SQL' => 2.29,
'sqlwindows' => 6.67,
'Squirrel' => 2.50,
'statistical default' => 2.50,
'Standard ML' => 3.00,
'Stata' => 3.00,
'strategem' => 2.22,
'stress' => 1.13,
'strongly typed default' => 0.88,
'style' => 1.74,
'Stylus' => 1.48,
'SugarSS' => 2.50,
'superbase 1.3' => 2.22,
'surpass' => 13.33,
'Svelte' => 2.00,
'SVG' => 1.00,
'Swift' => 2.50,
'SWIG' => 2.50,
'sybase' => 2.00,
'symantec c++' => 2.76,
'symbolang' => 1.25,
'synchroworks' => 4.44,
'synon/2e' => 4.21,
'systemw' => 2.22,
'tandem access language' => 0.88,
'Tcl/Tk' => 4.00,
'Teamcenter def' => 1.00,
'Teamcenter met' => 1.00,
'Teamcenter mth' => 1.00,
'TeX' => 1.50,
'telon' => 5.00,
'tessaract' => 2.00,
'the twin' => 13.33,
'Thrift' => 2.50,
'tiief' => 5.71,
'Titanium Style Sheet' => 2.00,
'TOML' => 2.76,
'transform' => 5.33,
'translisp plus' => 1.43,
'treet' => 1.25,
'treetran' => 1.25,
'trs80 basic' => 0.63,
'true basic' => 1.25,
'turing' => 1.00,
'tutor' => 1.51,
'twaice' => 1.63,
'Twig' => 2.00,
'TNSDL' => 2.00,
'TTCN' => 2.00,
'TITAN Project File Information' => 1.90,
'TypeScript' => 2.00,
'ucsd pascal' => 0.88,
'ufo/ims' => 2.22,
'uhelp' => 2.50,
'uniface' => 5.00,
'Unity-Prefab' => 2.50,
'Vala' => 1.50,
'Vala Header' => 1.40,
'vax acms' => 1.38,
'vax ade' => 2.00,
'vbscript' => 2.35,
'vectran' => 0.75,
'Verilog-SystemVerilog' => 1.51,
'VHDL' => 4.21,
'vim script' => 3.00,
'visible c' => 1.63,
'visible cobol' => 2.00,
'visicalc 1' => 8.89,
'visual 4.0' => 2.76,
'visual basic' => 1.90,
'visual basic 1' => 1.74,
'visual basic 2' => 1.86,
'visual basic 3' => 2.00,
'visual basic 4' => 2.22,
'visual basic 5' => 2.76,
'Visual Basic' => 2.76,
'visual basic dos' => 2.00,
'visual c++' => 2.35,
'visual cobol' => 4.00,
'Visual Fox Pro' => 4.00, # Visual Fox Pro is not available in the language gearing ratios listed at Mayes Consulting web site
'visual objects' => 5.00,
'visualage' => 3.81,
'Visualforce Component' => 1.9 ,
'Visualforce Page' => 1.9 ,
'visualgen' => 4.44,
'VM' => 2.00,
'vpf' => 0.84,
'Vuejs Component' => 2.00,
'vulcan' => 1.25,
'vz programmer' => 2.22,
'warp x' => 2.00,
'watcom c' => 0.63,
'watcom c/386' => 0.63,
'waterloo c' => 0.63,
'waterloo pascal' => 0.88,
'watfiv' => 0.94,
'watfor' => 0.88,
'web scripts' => 5.33,
'WebAssembly' => 0.45,
'whip' => 0.88,
'Windows Message File' => 1.00,
'Windows Resource File' => 1.00,
'Windows Module Definition' => 1.00,
'WiX source' => 1.90,
'WiX include' => 1.90,
'WiX string localization' => 1.90,
'wizard' => 2.86,
'xBase' => 2.00,
'xBase Header' => 2.00,
'xlisp' => 1.25,
'XAML' => 1.90,
'XQuery' => 2.50,
'yacc' => 1.51,
'yacc++' => 1.51,
'YAML' => 0.90,
'zbasic' => 0.88,
'zim' => 4.21,
'zlisp' => 1.25,
'Expect' => 2.00,
'Gencat NLS' => 1.50,
'C/C++ Header' => 1.00,
'inc' => 1.00,
'lex' => 1.00,
'Julia' => 4.00,
'MATLAB' => 4.00,
'Mathematica' => 5.00,
'Mercury' => 3.00,
'Maven/XML' => 2.5,
'IDL' => 3.80,
'Octave' => 4.00,
'ML' => 3.00,
'Modula3' => 2.00,
'PHP' => 3.50,
'Jupyter Notebook' => 4.20,
'Python' => 4.20,
'RapydScript' => 4.20,
'Starlark' => 4.20,
'Cython' => 3.80,
'Ruby' => 4.20,
'Ruby HTML' => 4.00,
'sed' => 4.00,
'Lua' => 4.00,
'OpenCL' => 1.50,
'Xtend' => 2.00,
# aggregates; value is meaningless
'C#/Smalltalk' => 1.00,
'D/dtrace' => 1.00,
'F#/Forth' => 1.00,
'Fortran 77/Forth' => 1.00,
'Lisp/Julia' => 1.00,
'Lisp/OpenCL' => 1.00,
'PHP/Pascal' => 1.00,
'Pascal/Puppet' => 1.00,
'Perl/Prolog' => 1.00,
'Raku/Prolog' => 1.00,
'Verilog-SystemVerilog/Coq' => 1.00,
'MATLAB/Mathematica/Objective C/MUMPS/Mercury' => 1.00,
'IDL/Qt Project/Prolog/ProGuard' => 1.00,
);
# 1}}}
%{$rh_Known_Binary_Archives} = ( # {{{1
'.tar' => 1 ,
'.tar.Z' => 1 ,
'.tar.gz' => 1 ,
'.tar.bz2' => 1 ,
'.zip' => 1 ,
'.Zip' => 1 ,
'.ZIP' => 1 ,
'.ear' => 1 , # Java
'.war' => 1 , # contained within .ear
'.xz' => 1 ,
'.whl' => 1 , # Python wheel files (zip)
);
# 1}}}
} # end sub set_constants()
sub check_scale_existence { # {{{1
# do a few sanity checks
my ($rhaa_Filters_by_Language,
$rh_Language_by_Extension,
$rh_Scale_Factor) = @_;
my $OK = 1;
foreach my $language (sort keys %{$rhaa_Filters_by_Language}) {
next if defined $Extension_Collision{$language};
if (!defined $rh_Scale_Factor->{$language}) {
$OK = 0;
warn "Missing scale factor for $language\n";
}
}
my %seen_it = ();
foreach my $ext (sort keys %{$rh_Language_by_Extension}) {
my $language = $rh_Language_by_Extension->{$ext};
next if defined $Extension_Collision{$language};
next if $seen_it{$language};
if (!$rhaa_Filters_by_Language->{$language}) {
$OK = 0;
warn "Missing language filter for $language\n";
}
$seen_it{$language} = 1;
}
die unless $OK;
} # 1}}}
sub Install_Regexp_Common { # {{{1
# Installs portions of Damian Conway's & Abigail's Regexp::Common
# module, version 2013031301 into a temporary directory for the
# duration of this run.
my %Regexp_Common_Contents = ();
$Regexp_Common_Contents{'Common'} = <<'EOCommon'; # {{{2
package Regexp::Common;
use 5.00473;
use strict;
BEGIN {
# This makes sure 'use warnings' doesn't bomb out on 5.005_*;
# warnings won't be enabled on those old versions though.
# Since all other files use this file, we can use 'use warnings'
# elsewhere as well, but *AFTER* 'use Regexp::Common'.
if ($] < 5.006) {
$INC {"warnings.pm"} = 1;
no strict 'refs';
*{"warnings::unimport"} = sub {0};
}
}
use warnings;
use vars qw /$VERSION %RE %sub_interface $AUTOLOAD/;
$VERSION = '2013031301';
sub _croak {
require Carp;
goto &Carp::croak;
}
sub _carp {
require Carp;
goto &Carp::carp;
}
sub new {
my ($class, @data) = @_;
my %self;
tie %self, $class, @data;
return \%self;
}
sub TIEHASH {
my ($class, @data) = @_;
bless \@data, $class;
}
sub FETCH {
my ($self, $extra) = @_;
return bless ref($self)->new(@$self, $extra), ref($self);
}
my %imports = map {$_ => "Regexp::Common::$_"}
qw /balanced CC comment delimited lingua list
net number profanity SEN URI whitespace
zip/;
sub import {
shift; # Shift off the class.
tie %RE, __PACKAGE__;
{
no strict 'refs';
*{caller() . "::RE"} = \%RE;
}
my $saw_import;
my $no_defaults;
my %exclude;
foreach my $entry (grep {!/^RE_/} @_) {
if ($entry eq 'pattern') {
no strict 'refs';
*{caller() . "::pattern"} = \&pattern;
next;
}
# This used to prevent $; from being set. We still recognize it,
# but we won't do anything.
if ($entry eq 'clean') {
next;
}
if ($entry eq 'no_defaults') {
$no_defaults ++;
next;
}
if (my $module = $imports {$entry}) {
$saw_import ++;
eval "require $module;";
die $@ if $@;
next;
}
if ($entry =~ /^!(.*)/ && $imports {$1}) {
$exclude {$1} ++;
next;
}
# As a last resort, try to load the argument.
my $module = $entry =~ /^Regexp::Common/
? $entry
: "Regexp::Common::" . $entry;
eval "require $module;";
die $@ if $@;
}
unless ($saw_import || $no_defaults) {
foreach my $module (values %imports) {
next if $exclude {$module};
eval "require $module;";
die $@ if $@;
}
}
my %exported;
foreach my $entry (grep {/^RE_/} @_) {
if ($entry =~ /^RE_(\w+_)?ALL$/) {
my $m = defined $1 ? $1 : "";
my $re = qr /^RE_${m}.*$/;
while (my ($sub, $interface) = each %sub_interface) {
next if $exported {$sub};
next unless $sub =~ /$re/;
{
no strict 'refs';
*{caller() . "::$sub"} = $interface;
}
$exported {$sub} ++;
}
}
else {
next if $exported {$entry};
_croak "Can't export unknown subroutine &$entry"
unless $sub_interface {$entry};
{
no strict 'refs';
*{caller() . "::$entry"} = $sub_interface {$entry};
}
$exported {$entry} ++;
}
}
}
sub AUTOLOAD { _croak "Can't $AUTOLOAD" }
sub DESTROY {}
my %cache;
my $fpat = qr/^(-\w+)/;
sub _decache {
my @args = @{tied %{$_[0]}};
my @nonflags = grep {!/$fpat/} @args;
my $cache = get_cache(@nonflags);
_croak "Can't create unknown regex: \$RE{"
. join("}{",@args) . "}"
unless exists $cache->{__VAL__};
_croak "Perl $] does not support the pattern "
. "\$RE{" . join("}{",@args)
. "}.\nYou need Perl $cache->{__VAL__}{version} or later"
unless ($cache->{__VAL__}{version}||0) <= $];
my %flags = ( %{$cache->{__VAL__}{default}},
map { /$fpat\Q$;\E(.*)/ ? ($1 => $2)
: /$fpat/ ? ($1 => undef)
: ()
} @args);
$cache->{__VAL__}->_clone_with(\@args, \%flags);
}
use overload q{""} => \&_decache;
sub get_cache {
my $cache = \%cache;
foreach (@_) {
$cache = $cache->{$_}
|| ($cache->{$_} = {});
}
return $cache;
}
sub croak_version {
my ($entry, @args) = @_;
}
sub pattern {
my %spec = @_;
_croak 'pattern() requires argument: name => [ @list ]'
unless $spec{name} && ref $spec{name} eq 'ARRAY';
_croak 'pattern() requires argument: create => $sub_ref_or_string'
unless $spec{create};
if (ref $spec{create} ne "CODE") {
my $fixed_str = "$spec{create}";
$spec{create} = sub { $fixed_str }
}
my @nonflags;
my %default;
foreach ( @{$spec{name}} ) {
if (/$fpat=(.*)/) {
$default{$1} = $2;
}
elsif (/$fpat\s*$/) {
$default{$1} = undef;
}
else {
push @nonflags, $_;
}
}
my $entry = get_cache(@nonflags);
if ($entry->{__VAL__}) {
_carp "Overriding \$RE{"
. join("}{",@nonflags)
. "}";
}
$entry->{__VAL__} = bless {
create => $spec{create},
match => $spec{match} || \&generic_match,
subs => $spec{subs} || \&generic_subs,
version => $spec{version},
default => \%default,
}, 'Regexp::Common::Entry';
foreach (@nonflags) {s/\W/X/g}
my $subname = "RE_" . join ("_", @nonflags);
$sub_interface{$subname} = sub {
push @_ => undef if @_ % 2;
my %flags = @_;
my $pat = $spec{create}->($entry->{__VAL__},
{%default, %flags}, \@nonflags);
if (exists $flags{-keep}) { $pat =~ s/\Q(?k:/(/g; }
else { $pat =~ s/\Q(?k:/(?:/g; }
return exists $flags {-i} ? qr /(?i:$pat)/ : qr/$pat/;
};
return 1;
}
sub generic_match {$_ [1] =~ /$_[0]/}
sub generic_subs {$_ [1] =~ s/$_[0]/$_[2]/}
sub matches {
my ($self, $str) = @_;
my $entry = $self -> _decache;
$entry -> {match} -> ($entry, $str);
}
sub subs {
my ($self, $str, $newstr) = @_;
my $entry = $self -> _decache;
$entry -> {subs} -> ($entry, $str, $newstr);
return $str;
}
package Regexp::Common::Entry;
# use Carp;
use overload
q{""} => sub {
my ($self) = @_;
my $pat = $self->{create}->($self, $self->{flags}, $self->{args});
if (exists $self->{flags}{-keep}) {
$pat =~ s/\Q(?k:/(/g;
}
else {
$pat =~ s/\Q(?k:/(?:/g;
}
if (exists $self->{flags}{-i}) { $pat = "(?i)$pat" }
return $pat;
};
sub _clone_with {
my ($self, $args, $flags) = @_;
bless { %$self, args=>$args, flags=>$flags }, ref $self;
}
1;
#
# This software is Copyright (c) 2001 - 2011, Damian Conway and Abigail.
#
# This module is free software, and maybe used under any of the following
# licenses:
#
# 1) The Perl Artistic License. See the file COPYRIGHT.AL.
# 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.
# 3) The BSD Licence. See the file COPYRIGHT.BSD.
# 4) The MIT Licence. See the file COPYRIGHT.MIT.
EOCommon
# 2}}}
$Regexp_Common_Contents{'Common/comment'} = <<'EOC'; # {{{2
package Regexp::Common::comment;
use Regexp::Common qw /pattern clean no_defaults/;
use strict;
use warnings;
use vars qw /$VERSION/;
$VERSION = '2010010201';
my @generic = (
{languages => [qw /ABC Forth/],
to_eol => ['\\\\']}, # This is for just a *single* backslash.
{languages => [qw /Ada Alan Eiffel lua/],
to_eol => ['--']},
{languages => [qw /Advisor/],
to_eol => ['#|//']},
{languages => [qw /Advsys CQL Lisp LOGO M MUMPS REBOL Scheme
SMITH zonefile/],
to_eol => [';']},
{languages => ['Algol 60'],
from_to => [[qw /comment ;/]]},
{languages => [qw {ALPACA B C C-- LPC PL/I}],
from_to => [[qw {/* */}]]},
{languages => [qw /awk fvwm2 Icon m4 mutt Perl Python QML
R Ruby shell Tcl/],
to_eol => ['#']},
{languages => [[BASIC => 'mvEnterprise']],
to_eol => ['[*!]|REM']},
{languages => [qw /Befunge-98 Funge-98 Shelta/],
id => [';']},
{languages => ['beta-Juliet', 'Crystal Report', 'Portia', 'Ubercode'],
to_eol => ['//']},
{languages => ['BML'],
from_to => [['<?_c', '_c?>']],
},
{languages => [qw /C++/, 'C#', qw /AspectJ Cg ECMAScript FPL Java JavaScript JSX Stylus/],
to_eol => ['//'],
from_to => [[qw {/* */}]]},
{languages => [qw /CLU LaTeX slrn TeX/],
to_eol => ['%']},
{languages => [qw /False/],
from_to => [[qw !{ }!]]},
{languages => [qw /Fortran/],
to_eol => ['!']},
{languages => [qw /Haifu/],
id => [',']},
{languages => [qw /ILLGOL/],
to_eol => ['NB']},
{languages => [qw /INTERCAL/],
to_eol => [q{(?:(?:PLEASE(?:\s+DO)?|DO)\s+)?(?:NOT|N'T)}]},
{languages => [qw /J/],
to_eol => ['NB[.]']},
{languages => [qw /JavaDoc/],
from_to => [[qw {/** */}]]},
{languages => [qw /Nickle/],
to_eol => ['#'],
from_to => [[qw {/* */}]]},
{languages => [qw /Oberon/],
from_to => [[qw /(* *)/]]},
{languages => [[qw /Pascal Delphi/], [qw /Pascal Free/], [qw /Pascal GPC/]],
to_eol => ['//'],
from_to => [[qw !{ }!], [qw !(* *)!]]},
{languages => [[qw /Pascal Workshop/]],
id => [qw /"/],
from_to => [[qw !{ }!], [qw !(* *)!], [qw !/* */!]]},
{languages => [qw /PEARL/],
to_eol => ['!'],
from_to => [[qw {/* */}]]},
{languages => [qw /PHP/],
to_eol => ['#', '//'],
from_to => [[qw {/* */}]]},
{languages => [qw !PL/B!],
to_eol => ['[.;]']},
{languages => [qw !PL/SQL!],
to_eol => ['--'],
from_to => [[qw {/* */}]]},
{languages => [qw /Q-BAL/],
to_eol => ['`']},
{languages => [qw /Smalltalk/],
id => ['"']},
{languages => [qw /SQL/],
to_eol => ['-{2,}']},
{languages => [qw /troff/],
to_eol => ['\\\"']},
{languages => [qw /vi/],
to_eol => ['"']},
{languages => [qw /*W/],
from_to => [[qw {|| !!}]]},
{languages => [qw /ZZT-OOP/],
to_eol => ["'"]},
);
my @plain_or_nested = (
[Caml => undef, "(*" => "*)"],
[Dylan => "//", "/*" => "*/"],
[Haskell => "-{2,}", "{-" => "-}"],
[Hugo => "!(?!\\\\)", "!\\" => "\\!"],
[SLIDE => "#", "(*" => "*)"],
['Modula-2' => undef, "(*" => "*)"],
['Modula-3' => undef, "(*" => "*)"],
);
#
# Helper subs.
#
sub combine {
local $_ = join "|", @_;
if (@_ > 1) {
s/\(\?k:/(?:/g;
$_ = "(?k:$_)";
}
$_
}
sub to_eol ($) {"(?k:(?k:$_[0])(?k:[^\\n]*)(?k:\\n))"}
sub id ($) {"(?k:(?k:$_[0])(?k:[^$_[0]]*)(?k:$_[0]))"} # One char only!
sub from_to {
my ($begin, $end) = @_;
my $qb = quotemeta $begin;
my $qe = quotemeta $end;
my $fe = quotemeta substr $end => 0, 1;
my $te = quotemeta substr $end => 1;
"(?k:(?k:$qb)(?k:(?:[^$fe]+|$fe(?!$te))*)(?k:$qe))";
}
my $count = 0;
sub nested {
my ($begin, $end) = @_;
$count ++;
my $r = '(??{$Regexp::Common::comment ['. $count . ']})';
my $qb = quotemeta $begin;
my $qe = quotemeta $end;
my $fb = quotemeta substr $begin => 0, 1;
my $fe = quotemeta substr $end => 0, 1;
my $tb = quotemeta substr $begin => 1;
my $te = quotemeta substr $end => 1;
use re 'eval';
my $re;
if ($fb eq $fe) {
$re = qr /(?:$qb(?:(?>[^$fb]+)|$fb(?!$tb)(?!$te)|$r)*$qe)/;
}
else {
local $" = "|";
my @clauses = "(?>[^$fb$fe]+)";
push @clauses => "$fb(?!$tb)" if length $tb;
push @clauses => "$fe(?!$te)" if length $te;
push @clauses => $r;
$re = qr /(?:$qb(?:@clauses)*$qe)/;
}
$Regexp::Common::comment [$count] = qr/$re/;
}
#
# Process data.
#
foreach my $info (@plain_or_nested) {
my ($language, $mark, $begin, $end) = @$info;
pattern name => [comment => $language],
create =>
sub {my $re = nested $begin => $end;
my $prefix = defined $mark ? $mark . "[^\n]*\n|" : "";
exists $_ [1] -> {-keep} ? qr /($prefix$re)/
: qr /$prefix$re/
},
version => 5.006,
;
}
foreach my $group (@generic) {
my $pattern = combine +(map {to_eol $_} @{$group -> {to_eol}}),
(map {from_to @$_} @{$group -> {from_to}}),
(map {id $_} @{$group -> {id}}),
;
foreach my $language (@{$group -> {languages}}) {
pattern name => [comment => ref $language ? @$language : $language],
create => $pattern,
;
}
}
#
# Other languages.
#
# http://www.pascal-central.com/docs/iso10206.txt
pattern name => [qw /comment Pascal/],
create => '(?k:' . '(?k:[{]|[(][*])'
. '(?k:[^}*]*(?:[*](?![)])[^}*]*)*)'
. '(?k:[}]|[*][)])'
. ')'
;
# http://www.templetons.com/brad/alice/language/
pattern name => [qw /comment Pascal Alice/],
create => '(?k:(?k:[{])(?k:[^}\n]*)(?k:[}]))'
;
# http://westein.arb-phys.uni-dortmund.de/~wb/a68s.txt
pattern name => [qw (comment), 'Algol 68'],
create => q {(?k:(?:#[^#]*#)|} .
q {(?:\bco\b(?:[^c]+|\Bc|\bc(?!o\b))*\bco\b)|} .
q {(?:\bcomment\b(?:[^c]+|\Bc|\bc(?!omment\b))*\bcomment\b))}
;
# See rules 91 and 92 of ISO 8879 (SGML).
# Charles F. Goldfarb: "The SGML Handbook".
# Oxford: Oxford University Press. 1990. ISBN 0-19-853737-9.
# Ch. 10.3, pp 390.
pattern name => [qw (comment HTML)],
create => q {(?k:(?k:<!)(?k:(?:--(?k:[^-]*(?:-[^-]+)*)--\s*)*)(?k:>))},
;
pattern name => [qw /comment SQL MySQL/],
create => q {(?k:(?:#|-- )[^\n]*\n|} .
q {/\*(?:(?>[^*;"']+)|"[^"]*"|'[^']*'|\*(?!/))*(?:;|\*/))},
;
# Anything that isn't <>[]+-.,
# http://home.wxs.nl/~faase009/Ha_BF.html
pattern name => [qw /comment Brainfuck/],
create => '(?k:[^<>\[\]+\-.,]+)'
;
# Squeak is a variant of Smalltalk-80.
# http://www.squeak.
# http://mucow.com/squeak-qref.html
pattern name => [qw /comment Squeak/],
create => '(?k:(?k:")(?k:[^"]*(?:""[^"]*)*)(?k:"))'
;
#
# Scores of less than 5 or above 17....
# http://www.cliff.biffle.org/esoterica/beatnik.html
@Regexp::Common::comment::scores = (1, 3, 3, 2, 1, 4, 2, 4, 1, 8,
5, 1, 3, 1, 1, 3, 10, 1, 1, 1,
1, 4, 4, 8, 4, 10);
{
my ($s, $x);
pattern name => [qw /comment Beatnik/],
create => sub {
use re 'eval';
my $re = qr {\b([A-Za-z]+)\b
(?(?{($s, $x) = (0, lc $^N);
$s += $Regexp::Common::comment::scores
[ord (chop $x) - ord ('a')] while length $x;
$s >= 5 && $s < 18})XXX|)}x;
$re;
},
version => 5.008,
;
}
# http://www.cray.com/craydoc/manuals/007-3692-005/html-007-3692-005/
# (Goto table of contents/3.3 Source Form)
# Fortran, in fixed format. Comments start with a C, c or * in the first
# column, or a ! anywhere, but the sixth column. Then end with a newline.
pattern name => [qw /comment Fortran fixed/],
create => '(?k:(?k:(?:^[Cc*]|(?<!^.....)!))(?k:[^\n]*)(?k:\n))'
;
# http://www.csis.ul.ie/cobol/Course/COBOLIntro.htm
# Traditionally, comments in COBOL were indicated with an asterisk in
# the seventh column. Modern compilers may be more lenient.
pattern name => [qw /comment COBOL/],
create => '(?<=^......)(?k:(?k:[*])(?k:[^\n]*)(?k:\n))',
version => '5.008',
;
1;
EOC
# 2}}}
$Regexp_Common_Contents{'Common/balanced'} = <<'EOB'; # {{{2
package Regexp::Common::balanced; {
use Regexp::Common qw /pattern clean no_defaults/;
use strict;
use warnings;
use vars qw /$VERSION/;
$VERSION = '2013030901';
my %closer = ( '{'=>'}', '('=>')', '['=>']', '<'=>'>' );
my %cache;
sub nested {
my ($start, $finish) = @_;
return $cache {$start} {$finish} if exists $cache {$start} {$finish};
my @starts = map {s/\\(.)/$1/g; $_} grep {length}
$start =~ /([^|\\]+|\\.)+/gs;
my @finishes = map {s/\\(.)/$1/g; $_} grep {length}
$finish =~ /([^|\\]+|\\.)+/gs;
push @finishes => ($finishes [-1]) x (@starts - @finishes);
my @re;
local $" = "|";
foreach my $begin (@starts) {
my $end = shift @finishes;
my $qb = quotemeta $begin;
my $qe = quotemeta $end;
my $fb = quotemeta substr $begin => 0, 1;
my $fe = quotemeta substr $end => 0, 1;
my $tb = quotemeta substr $begin => 1;
my $te = quotemeta substr $end => 1;
my $add;
if ($fb eq $fe) {
push @re =>
qq /(?:$qb(?:(?>[^$fb]+)|$fb(?!$tb)(?!$te)|(?-1))*$qe)/;
}
else {
my @clauses = "(?>[^$fb$fe]+)";
push @clauses => "$fb(?!$tb)" if length $tb;
push @clauses => "$fe(?!$te)" if length $te;
push @clauses => "(?-1)";
push @re => qq /(?:$qb(?:@clauses)*$qe)/;
}
}
$cache {$start} {$finish} = qr /(@re)/;
}
pattern name => [qw /balanced -parens=() -begin= -end=/],
create => sub {
my $flag = $_[1];
unless (defined $flag -> {-begin} && length $flag -> {-begin} &&
defined $flag -> {-end} && length $flag -> {-end}) {
my @open = grep {index ($flag->{-parens}, $_) >= 0}
('[','(','{','<');
my @close = map {$closer {$_}} @open;
$flag -> {-begin} = join "|" => @open;
$flag -> {-end} = join "|" => @close;
}
return nested @$flag {qw /-begin -end/};
},
version => 5.010,
;
}
1;
# This software is Copyright (c) 2001 - 2013, Damian Conway and Abigail.
#
# This module is free software, and maybe used under any of the following
# licenses:
#
# 1) The Perl Artistic License. See the file COPYRIGHT.AL.
# 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.
# 3) The BSD Licence. See the file COPYRIGHT.BSD.
# 4) The MIT Licence. See the file COPYRIGHT.MIT.
EOB
# 2}}}
$Regexp_Common_Contents{'Common/delimited'} = <<'EOD'; # {{{3
package Regexp::Common::delimited;
use Regexp::Common qw /pattern clean no_defaults/;
use strict;
use warnings;
use vars qw /$VERSION/;
$VERSION = '2010010201';
sub gen_delimited {
my ($dels, $escs) = @_;
# return '(?:\S*)' unless $dels =~ /\S/;
if (length $escs) {
$escs .= substr ($escs, -1) x (length ($dels) - length ($escs));
}
my @pat = ();
my $i;
for ($i=0; $i < length $dels; $i++) {
my $del = quotemeta substr ($dels, $i, 1);
my $esc = length($escs) ? quotemeta substr ($escs, $i, 1) : "";
if ($del eq $esc) {
push @pat,
"(?k:$del)(?k:[^$del]*(?:(?:$del$del)[^$del]*)*)(?k:$del)";
}
elsif (length $esc) {
push @pat,
"(?k:$del)(?k:[^$esc$del]*(?:$esc.[^$esc$del]*)*)(?k:$del)";
}
else {
push @pat, "(?k:$del)(?k:[^$del]*)(?k:$del)";
}
}
my $pat = join '|', @pat;
return "(?k:$pat)";
}
sub _croak {
require Carp;
goto &Carp::croak;
}
pattern name => [qw( delimited -delim= -esc=\\ )],
create => sub {my $flags = $_[1];
_croak 'Must specify delimiter in $RE{delimited}'
unless length $flags->{-delim};
return gen_delimited (@{$flags}{-delim, -esc});
},
;
pattern name => [qw( quoted -esc=\\ )],
create => sub {my $flags = $_[1];
return gen_delimited (q{"'`}, $flags -> {-esc});
},
;
1;
# This software is Copyright (c) 2001 - 2009, Damian Conway and Abigail.
#
# This module is free software, and maybe used under any of the following
# licenses:
#
# 1) The Perl Artistic License. See the file COPYRIGHT.AL.
# 2) The Perl Artistic License 2.0. See the file COPYRIGHT.AL2.
# 3) The BSD Licence. See the file COPYRIGHT.BSD.
# 4) The MIT Licence. See the file COPYRIGHT.MIT.
EOD
# 2}}}
my $problems = 0;
$HAVE_Rexexp_Common = 0;
my $dir = "";
if ($opt_sdir) {
++$TEMP_OFF;
$dir = "$opt_sdir/$TEMP_OFF";
File::Path::rmtree($dir) if is_dir($dir);
File::Path::mkpath($dir) unless is_dir($dir);
} else {
# let File::Temp create a suitable temporary directory
$dir = tempdir( CLEANUP => 1 ); # 1 = delete on exit
$TEMP_INST{ $dir } = "Regexp::Common";
}
print "Using temp dir [$dir] to install Regexp::Common\n" if $opt_v;
my $Regexp_dir = "$dir/Regexp";
my $Regexp_Common_dir = "$dir/Regexp/Common";
mkdir $Regexp_dir ;
mkdir $Regexp_Common_dir;
foreach my $module_file (keys %Regexp_Common_Contents) {
my $OUT = new IO::File "$dir/Regexp/${module_file}.pm", "w";
if (defined $OUT) {
print $OUT $Regexp_Common_Contents{$module_file};
$OUT->close;
} else {
warn "Failed to install Regexp::${module_file}.pm\n";
$problems = 1;
}
}
push @INC, $dir;
eval "use Regexp::Common qw /comment RE_comment_HTML balanced/";
$HAVE_Rexexp_Common = 1 unless $problems;
} # 1}}}
sub Install_Algorithm_Diff { # {{{1
# Installs Tye McQueen's Algorithm::Diff module, v1.1902, into a
# temporary directory for the duration of this run.
my $Algorithm_Diff_Contents = <<'EOAlgDiff'; # {{{2
package Algorithm::Diff;
# Skip to first "=head" line for documentation.
use strict;
use integer; # see below in _replaceNextLargerWith() for mod to make
# if you don't use this
use vars qw( $VERSION @EXPORT_OK );
$VERSION = 1.19_02;
# ^ ^^ ^^-- Incremented at will
# | \+----- Incremented for non-trivial changes to features
# \-------- Incremented for fundamental changes
require Exporter;
*import = \&Exporter::import;
@EXPORT_OK = qw(
prepare LCS LCSidx LCS_length
diff sdiff compact_diff
traverse_sequences traverse_balanced
);
# McIlroy-Hunt diff algorithm
# Adapted from the Smalltalk code of Mario I. Wolczko, <mario@wolczko.com>
# by Ned Konz, perl@bike-nomad.com
# Updates by Tye McQueen, http://perlmonks.org/?node=tye
# Create a hash that maps each element of $aCollection to the set of
# positions it occupies in $aCollection, restricted to the elements
# within the range of indexes specified by $start and $end.
# The fourth parameter is a subroutine reference that will be called to
# generate a string to use as a key.
# Additional parameters, if any, will be passed to this subroutine.
#
# my $hashRef = _withPositionsOfInInterval( \@array, $start, $end, $keyGen );
sub _withPositionsOfInInterval
{
my $aCollection = shift; # array ref
my $start = shift;
my $end = shift;
my $keyGen = shift;
my %d;
my $index;
for ( $index = $start ; $index <= $end ; $index++ )
{
my $element = $aCollection->[$index];
my $key = &$keyGen( $element, @_ );
if ( exists( $d{$key} ) )
{
unshift ( @{ $d{$key} }, $index );
}
else
{
$d{$key} = [$index];
}
}
return wantarray ? %d : \%d;
}
# Find the place at which aValue would normally be inserted into the
# array. If that place is already occupied by aValue, do nothing, and
# return undef. If the place does not exist (i.e., it is off the end of
# the array), add it to the end, otherwise replace the element at that
# point with aValue. It is assumed that the array's values are numeric.
# This is where the bulk (75%) of the time is spent in this module, so
# try to make it fast!
sub _replaceNextLargerWith
{
my ( $array, $aValue, $high ) = @_;
$high ||= $#$array;
# off the end?
if ( $high == -1 || $aValue > $array->[-1] )
{
push ( @$array, $aValue );
return $high + 1;
}
# binary search for insertion point...
my $low = 0;
my $index;
my $found;
while ( $low <= $high )
{
$index = ( $high + $low ) / 2;
# $index = int(( $high + $low ) / 2); # without 'use integer'
$found = $array->[$index];
if ( $aValue == $found )
{
return undef;
}
elsif ( $aValue > $found )
{
$low = $index + 1;
}
else
{
$high = $index - 1;
}
}
# now insertion point is in $low.
$array->[$low] = $aValue; # overwrite next larger
return $low;
}
# This method computes the longest common subsequence in $a and $b.
# Result is array or ref, whose contents is such that
# $a->[ $i ] == $b->[ $result[ $i ] ]
# foreach $i in ( 0 .. $#result ) if $result[ $i ] is defined.
# An additional argument may be passed; this is a hash or key generating
# function that should return a string that uniquely identifies the given
# element. It should be the case that if the key is the same, the elements
# will compare the same. If this parameter is undef or missing, the key
# will be the element as a string.
# By default, comparisons will use "eq" and elements will be turned into keys
# using the default stringizing operator '""'.
# Additional parameters, if any, will be passed to the key generation
# routine.
sub _longestCommonSubsequence
{
my $a = shift; # array ref or hash ref
my $b = shift; # array ref or hash ref
my $counting = shift; # scalar
my $keyGen = shift; # code ref
my $compare; # code ref
if ( ref($a) eq 'HASH' )
{ # prepared hash must be in $b
my $tmp = $b;
$b = $a;
$a = $tmp;
}
# Check for bogus (non-ref) argument values
if ( !ref($a) || !ref($b) )
{
my @callerInfo = caller(1);
die 'error: must pass array or hash references to ' . $callerInfo[3];
}
# set up code refs
# Note that these are optimized.
if ( !defined($keyGen) ) # optimize for strings
{
$keyGen = sub { $_[0] };
$compare = sub { my ( $a, $b ) = @_; $a eq $b };
}
else
{
$compare = sub {
my $a = shift;
my $b = shift;
&$keyGen( $a, @_ ) eq &$keyGen( $b, @_ );
};
}
my ( $aStart, $aFinish, $matchVector ) = ( 0, $#$a, [] );
my ( $prunedCount, $bMatches ) = ( 0, {} );
if ( ref($b) eq 'HASH' ) # was $bMatches prepared for us?
{
$bMatches = $b;
}
else
{
my ( $bStart, $bFinish ) = ( 0, $#$b );
# First we prune off any common elements at the beginning
while ( $aStart <= $aFinish
and $bStart <= $bFinish
and &$compare( $a->[$aStart], $b->[$bStart], @_ ) )
{
$matchVector->[ $aStart++ ] = $bStart++;
$prunedCount++;
}
# now the end
while ( $aStart <= $aFinish
and $bStart <= $bFinish
and &$compare( $a->[$aFinish], $b->[$bFinish], @_ ) )
{
$matchVector->[ $aFinish-- ] = $bFinish--;
$prunedCount++;
}
# Now compute the equivalence classes of positions of elements
$bMatches =
_withPositionsOfInInterval( $b, $bStart, $bFinish, $keyGen, @_ );
}
my $thresh = [];
my $links = [];
my ( $i, $ai, $j, $k );
for ( $i = $aStart ; $i <= $aFinish ; $i++ )
{
$ai = &$keyGen( $a->[$i], @_ );
if ( exists( $bMatches->{$ai} ) )
{
$k = 0;
for $j ( @{ $bMatches->{$ai} } )
{
# optimization: most of the time this will be true
if ( $k and $thresh->[$k] > $j and $thresh->[ $k - 1 ] < $j )
{
$thresh->[$k] = $j;
}
else
{
$k = _replaceNextLargerWith( $thresh, $j, $k );
}
# oddly, it's faster to always test this (CPU cache?).
if ( defined($k) )
{
$links->[$k] =
[ ( $k ? $links->[ $k - 1 ] : undef ), $i, $j ];
}
}
}
}
if (@$thresh)
{
return $prunedCount + @$thresh if $counting;
for ( my $link = $links->[$#$thresh] ; $link ; $link = $link->[0] )
{
$matchVector->[ $link->[1] ] = $link->[2];
}
}
elsif ($counting)
{
return $prunedCount;
}
return wantarray ? @$matchVector : $matchVector;
}
sub traverse_sequences
{
my $a = shift; # array ref
my $b = shift; # array ref
my $callbacks = shift || {};
my $keyGen = shift;
my $matchCallback = $callbacks->{'MATCH'} || sub { };
my $discardACallback = $callbacks->{'DISCARD_A'} || sub { };
my $finishedACallback = $callbacks->{'A_FINISHED'};
my $discardBCallback = $callbacks->{'DISCARD_B'} || sub { };
my $finishedBCallback = $callbacks->{'B_FINISHED'};
my $matchVector = _longestCommonSubsequence( $a, $b, 0, $keyGen, @_ );
# Process all the lines in @$matchVector
my $lastA = $#$a;
my $lastB = $#$b;
my $bi = 0;
my $ai;
for ( $ai = 0 ; $ai <= $#$matchVector ; $ai++ )
{
my $bLine = $matchVector->[$ai];
if ( defined($bLine) ) # matched
{
&$discardBCallback( $ai, $bi++, @_ ) while $bi < $bLine;
&$matchCallback( $ai, $bi++, @_ );
}
else
{
&$discardACallback( $ai, $bi, @_ );
}
}
# The last entry (if any) processed was a match.
# $ai and $bi point just past the last matching lines in their sequences.
while ( $ai <= $lastA or $bi <= $lastB )
{
# last A?
if ( $ai == $lastA + 1 and $bi <= $lastB )
{
if ( defined($finishedACallback) )
{
&$finishedACallback( $lastA, @_ );
$finishedACallback = undef;
}
else
{
&$discardBCallback( $ai, $bi++, @_ ) while $bi <= $lastB;
}
}
# last B?
if ( $bi == $lastB + 1 and $ai <= $lastA )
{
if ( defined($finishedBCallback) )
{
&$finishedBCallback( $lastB, @_ );
$finishedBCallback = undef;
}
else
{
&$discardACallback( $ai++, $bi, @_ ) while $ai <= $lastA;
}
}
&$discardACallback( $ai++, $bi, @_ ) if $ai <= $lastA;
&$discardBCallback( $ai, $bi++, @_ ) if $bi <= $lastB;
}
return 1;
}
sub traverse_balanced
{
my $a = shift; # array ref
my $b = shift; # array ref
my $callbacks = shift || {};
my $keyGen = shift;
my $matchCallback = $callbacks->{'MATCH'} || sub { };
my $discardACallback = $callbacks->{'DISCARD_A'} || sub { };
my $discardBCallback = $callbacks->{'DISCARD_B'} || sub { };
my $changeCallback = $callbacks->{'CHANGE'};
my $matchVector = _longestCommonSubsequence( $a, $b, 0, $keyGen, @_ );
# Process all the lines in match vector
my $lastA = $#$a;
my $lastB = $#$b;
my $bi = 0;
my $ai = 0;
my $ma = -1;
my $mb;
while (1)
{
# Find next match indices $ma and $mb
do {
$ma++;
} while(
$ma <= $#$matchVector
&& !defined $matchVector->[$ma]
);
last if $ma > $#$matchVector; # end of matchVector?
$mb = $matchVector->[$ma];
# Proceed with discard a/b or change events until
# next match
while ( $ai < $ma || $bi < $mb )
{
if ( $ai < $ma && $bi < $mb )
{
# Change
if ( defined $changeCallback )
{
&$changeCallback( $ai++, $bi++, @_ );
}
else
{
&$discardACallback( $ai++, $bi, @_ );
&$discardBCallback( $ai, $bi++, @_ );
}
}
elsif ( $ai < $ma )
{
&$discardACallback( $ai++, $bi, @_ );
}
else
{
# $bi < $mb
&$discardBCallback( $ai, $bi++, @_ );
}
}
# Match
&$matchCallback( $ai++, $bi++, @_ );
}
while ( $ai <= $lastA || $bi <= $lastB )
{
if ( $ai <= $lastA && $bi <= $lastB )
{
# Change
if ( defined $changeCallback )
{
&$changeCallback( $ai++, $bi++, @_ );
}
else
{
&$discardACallback( $ai++, $bi, @_ );
&$discardBCallback( $ai, $bi++, @_ );
}
}
elsif ( $ai <= $lastA )
{
&$discardACallback( $ai++, $bi, @_ );
}
else
{
# $bi <= $lastB
&$discardBCallback( $ai, $bi++, @_ );
}
}
return 1;
}
sub prepare
{
my $a = shift; # array ref
my $keyGen = shift; # code ref
# set up code ref
$keyGen = sub { $_[0] } unless defined($keyGen);
return scalar _withPositionsOfInInterval( $a, 0, $#$a, $keyGen, @_ );
}
sub LCS
{
my $a = shift; # array ref
my $b = shift; # array ref or hash ref
my $matchVector = _longestCommonSubsequence( $a, $b, 0, @_ );
my @retval;
my $i;
for ( $i = 0 ; $i <= $#$matchVector ; $i++ )
{
if ( defined( $matchVector->[$i] ) )
{
push ( @retval, $a->[$i] );
}
}
return wantarray ? @retval : \@retval;
}
sub LCS_length
{
my $a = shift; # array ref
my $b = shift; # array ref or hash ref
return _longestCommonSubsequence( $a, $b, 1, @_ );
}
sub LCSidx
{
my $a= shift @_;
my $b= shift @_;
my $match= _longestCommonSubsequence( $a, $b, 0, @_ );
my @am= grep defined $match->[$_], 0..$#$match;
my @bm= @{$match}[@am];
return \@am, \@bm;
}
sub compact_diff
{
my $a= shift @_;
my $b= shift @_;
my( $am, $bm )= LCSidx( $a, $b, @_ );
my @cdiff;
my( $ai, $bi )= ( 0, 0 );
push @cdiff, $ai, $bi;
while( 1 ) {
while( @$am && $ai == $am->[0] && $bi == $bm->[0] ) {
shift @$am;
shift @$bm;
++$ai, ++$bi;
}
push @cdiff, $ai, $bi;
last if ! @$am;
$ai = $am->[0];
$bi = $bm->[0];
push @cdiff, $ai, $bi;
}
push @cdiff, 0+@$a, 0+@$b
if $ai < @$a || $bi < @$b;
return wantarray ? @cdiff : \@cdiff;
}
sub diff
{
my $a = shift; # array ref
my $b = shift; # array ref
my $retval = [];
my $hunk = [];
my $discard = sub {
push @$hunk, [ '-', $_[0], $a->[ $_[0] ] ];
};
my $add = sub {
push @$hunk, [ '+', $_[1], $b->[ $_[1] ] ];
};
my $match = sub {
push @$retval, $hunk
if 0 < @$hunk;
$hunk = []
};
traverse_sequences( $a, $b,
{ MATCH => $match, DISCARD_A => $discard, DISCARD_B => $add }, @_ );
&$match();
return wantarray ? @$retval : $retval;
}
sub sdiff
{
my $a = shift; # array ref
my $b = shift; # array ref
my $retval = [];
my $discard = sub { push ( @$retval, [ '-', $a->[ $_[0] ], "" ] ) };
my $add = sub { push ( @$retval, [ '+', "", $b->[ $_[1] ] ] ) };
my $change = sub {
push ( @$retval, [ 'c', $a->[ $_[0] ], $b->[ $_[1] ] ] );
};
my $match = sub {
push ( @$retval, [ 'u', $a->[ $_[0] ], $b->[ $_[1] ] ] );
};
traverse_balanced(
$a,
$b,
{
MATCH => $match,
DISCARD_A => $discard,
DISCARD_B => $add,
CHANGE => $change,
},
@_
);
return wantarray ? @$retval : $retval;
}
########################################
my $Root= __PACKAGE__;
package Algorithm::Diff::_impl;
use strict;
sub _Idx() { 0 } # $me->[_Idx]: Ref to array of hunk indices
# 1 # $me->[1]: Ref to first sequence
# 2 # $me->[2]: Ref to second sequence
sub _End() { 3 } # $me->[_End]: Diff between forward and reverse pos
sub _Same() { 4 } # $me->[_Same]: 1 if pos 1 contains unchanged items
sub _Base() { 5 } # $me->[_Base]: Added to range's min and max
sub _Pos() { 6 } # $me->[_Pos]: Which hunk is currently selected
sub _Off() { 7 } # $me->[_Off]: Offset into _Idx for current position
sub _Min() { -2 } # Added to _Off to get min instead of max+1
sub Die
{
require Carp;
Carp::confess( @_ );
}
sub _ChkPos
{
my( $me )= @_;
return if $me->[_Pos];
my $meth= ( caller(1) )[3];
Die( "Called $meth on 'reset' object" );
}
sub _ChkSeq
{
my( $me, $seq )= @_;
return $seq + $me->[_Off]
if 1 == $seq || 2 == $seq;
my $meth= ( caller(1) )[3];
Die( "$meth: Invalid sequence number ($seq); must be 1 or 2" );
}
sub getObjPkg
{
my( $us )= @_;
return ref $us if ref $us;
return $us . "::_obj";
}
sub new
{
my( $us, $seq1, $seq2, $opts ) = @_;
my @args;
for( $opts->{keyGen} ) {
push @args, $_ if $_;
}
for( $opts->{keyGenArgs} ) {
push @args, @$_ if $_;
}
my $cdif= Algorithm::Diff::compact_diff( $seq1, $seq2, @args );
my $same= 1;
if( 0 == $cdif->[2] && 0 == $cdif->[3] ) {
$same= 0;
splice @$cdif, 0, 2;
}
my @obj= ( $cdif, $seq1, $seq2 );
$obj[_End] = (1+@$cdif)/2;
$obj[_Same] = $same;
$obj[_Base] = 0;
my $me = bless \@obj, $us->getObjPkg();
$me->Reset( 0 );
return $me;
}
sub Reset
{
my( $me, $pos )= @_;
$pos= int( $pos || 0 );
$pos += $me->[_End]
if $pos < 0;
$pos= 0
if $pos < 0 || $me->[_End] <= $pos;
$me->[_Pos]= $pos || !1;
$me->[_Off]= 2*$pos - 1;
return $me;
}
sub Base
{
my( $me, $base )= @_;
my $oldBase= $me->[_Base];
$me->[_Base]= 0+$base if defined $base;
return $oldBase;
}
sub Copy
{
my( $me, $pos, $base )= @_;
my @obj= @$me;
my $you= bless \@obj, ref($me);
$you->Reset( $pos ) if defined $pos;
$you->Base( $base );
return $you;
}
sub Next {
my( $me, $steps )= @_;
$steps= 1 if ! defined $steps;
if( $steps ) {
my $pos= $me->[_Pos];
my $new= $pos + $steps;
$new= 0 if $pos && $new < 0;
$me->Reset( $new )
}
return $me->[_Pos];
}
sub Prev {
my( $me, $steps )= @_;
$steps= 1 if ! defined $steps;
my $pos= $me->Next(-$steps);
$pos -= $me->[_End] if $pos;
return $pos;
}
sub Diff {
my( $me )= @_;
$me->_ChkPos();
return 0 if $me->[_Same] == ( 1 & $me->[_Pos] );
my $ret= 0;
my $off= $me->[_Off];
for my $seq ( 1, 2 ) {
$ret |= $seq
if $me->[_Idx][ $off + $seq + _Min ]
< $me->[_Idx][ $off + $seq ];
}
return $ret;
}
sub Min {
my( $me, $seq, $base )= @_;
$me->_ChkPos();
my $off= $me->_ChkSeq($seq);
$base= $me->[_Base] if !defined $base;
return $base + $me->[_Idx][ $off + _Min ];
}
sub Max {
my( $me, $seq, $base )= @_;
$me->_ChkPos();
my $off= $me->_ChkSeq($seq);
$base= $me->[_Base] if !defined $base;
return $base + $me->[_Idx][ $off ] -1;
}
sub Range {
my( $me, $seq, $base )= @_;
$me->_ChkPos();
my $off = $me->_ChkSeq($seq);
if( !wantarray ) {
return $me->[_Idx][ $off ]
- $me->[_Idx][ $off + _Min ];
}
$base= $me->[_Base] if !defined $base;
return ( $base + $me->[_Idx][ $off + _Min ] )
.. ( $base + $me->[_Idx][ $off ] - 1 );
}
sub Items {
my( $me, $seq )= @_;
$me->_ChkPos();
my $off = $me->_ChkSeq($seq);
if( !wantarray ) {
return $me->[_Idx][ $off ]
- $me->[_Idx][ $off + _Min ];
}
return
@{$me->[$seq]}[
$me->[_Idx][ $off + _Min ]
.. ( $me->[_Idx][ $off ] - 1 )
];
}
sub Same {
my( $me )= @_;
$me->_ChkPos();
return wantarray ? () : 0
if $me->[_Same] != ( 1 & $me->[_Pos] );
return $me->Items(1);
}
my %getName;
BEGIN {
%getName= (
same => \&Same,
diff => \&Diff,
base => \&Base,
min => \&Min,
max => \&Max,
range=> \&Range,
items=> \&Items, # same thing
);
}
sub Get
{
my $me= shift @_;
$me->_ChkPos();
my @value;
for my $arg ( @_ ) {
for my $word ( split ' ', $arg ) {
my $meth;
if( $word !~ /^(-?\d+)?([a-zA-Z]+)([12])?$/
|| not $meth= $getName{ lc $2 }
) {
Die( $Root, ", Get: Invalid request ($word)" );
}
my( $base, $name, $seq )= ( $1, $2, $3 );
push @value, scalar(
4 == length($name)
? $meth->( $me )
: $meth->( $me, $seq, $base )
);
}
}
if( wantarray ) {
return @value;
} elsif( 1 == @value ) {
return $value[0];
}
Die( 0+@value, " values requested from ",
$Root, "'s Get in scalar context" );
}
my $Obj= getObjPkg($Root);
no strict 'refs';
for my $meth ( qw( new getObjPkg ) ) {
*{$Root."::".$meth} = \&{$meth};
*{$Obj ."::".$meth} = \&{$meth};
}
for my $meth ( qw(
Next Prev Reset Copy Base Diff
Same Items Range Min Max Get
_ChkPos _ChkSeq
) ) {
*{$Obj."::".$meth} = \&{$meth};
}
1;
# This version released by Tye McQueen (http://perlmonks.org/?node=tye).
#
# =head1 LICENSE
#
# Parts Copyright (c) 2000-2004 Ned Konz. All rights reserved.
# Parts by Tye McQueen.
#
# This program is free software; you can redistribute it and/or modify it
# under the same terms as Perl.
#
# =head1 MAILING LIST
#
# Mark-Jason still maintains a mailing list. To join a low-volume mailing
# list for announcements related to diff and Algorithm::Diff, send an
# empty mail message to mjd-perl-diff-request@plover.com.
# =head1 CREDITS
#
# Versions through 0.59 (and much of this documentation) were written by:
#
# Mark-Jason Dominus, mjd-perl-diff@plover.com
#
# This version borrows some documentation and routine names from
# Mark-Jason's, but Diff.pm's code was completely replaced.
#
# This code was adapted from the Smalltalk code of Mario Wolczko
# <mario@wolczko.com>, which is available at
# ftp://st.cs.uiuc.edu/pub/Smalltalk/MANCHESTER/manchester/4.0/diff.st
#
# C<sdiff> and C<traverse_balanced> were written by Mike Schilli
# <m@perlmeister.com>.
#
# The algorithm is that described in
# I<A Fast Algorithm for Computing Longest Common Subsequences>,
# CACM, vol.20, no.5, pp.350-353, May 1977, with a few
# minor improvements to improve the speed.
#
# Much work was done by Ned Konz (perl@bike-nomad.com).
#
# The OO interface and some other changes are by Tye McQueen.
#
EOAlgDiff
# 2}}}
my $problems = 0;
$HAVE_Algorith_Diff = 0;
my $dir = "";
if ($opt_sdir) {
++$TEMP_OFF;
$dir = "$opt_sdir/$TEMP_OFF";
File::Path::rmtree($dir) if is_dir($dir);
File::Path::mkpath($dir) unless is_dir($dir);
} else {
# let File::Temp create a suitable temporary directory
$dir = tempdir( CLEANUP => 1 ); # 1 = delete on exit
$TEMP_INST{ $dir } = "Algorithm::Diff";
}
print "Using temp dir [$dir] to install Algorithm::Diff\n" if $opt_v;
my $Algorithm_dir = "$dir/Algorithm";
my $Algorithm_Diff_dir = "$dir/Algorithm/Diff";
mkdir $Algorithm_dir ;
mkdir $Algorithm_Diff_dir;
my $OUT = new IO::File "$dir/Algorithm/Diff.pm", "w";
if (defined $OUT) {
print $OUT $Algorithm_Diff_Contents;
$OUT->close;
} else {
warn "Failed to install Algorithm/Diff.pm\n";
$problems = 1;
}
push @INC, $dir; # between this & Regexp::Common only need to do once
eval "use Algorithm::Diff qw / sdiff /";
$HAVE_Algorith_Diff = 1 unless $problems;
} # 1}}}
sub pre_post_fix { # {{{1
# Return the input lines prefixed and postfixed
# by the given strings.
my ($ra_lines, $prefix, $postfix ) = @_;
print "-> pre_post_fix with $prefix, $postfix\n" if $opt_v > 2;
my $all_lines = $prefix . join("" , @{$ra_lines}) . $postfix;
print "<- pre_post_fix\n" if $opt_v > 2;
return split("\n", $all_lines);
} # 1}}}
sub rm_last_line { # {{{1
# Return all but the last line.
my ($ra_lines, ) = @_;
print "-> rm_last_line\n" if $opt_v > 2;
print "<- rm_last_line\n" if $opt_v > 2;
my $n = scalar(@{$ra_lines}) - 2;
return @{$ra_lines}[0..$n];
} # 1}}}
sub call_regexp_common { # {{{1
my ($ra_lines, $language ) = @_;
print "-> call_regexp_common for $language\n" if $opt_v > 2;
Install_Regexp_Common() unless $HAVE_Rexexp_Common;
my $all_lines = undef;
if ($language eq "C++") { # Regexp::Common's C++ comment regex is multi-line
# $all_lines = join("\n", @{$ra_lines});
$all_lines = "";
foreach (@{$ra_lines}) {
if (m/\\$/) { # line ends with a continuation marker
$all_lines .= $_;
} else {
$all_lines .= "$_\n";
}
}
} else {
$all_lines = join("" , @{$ra_lines});
}
no strict 'vars';
# otherwise get:
# Global symbol "%RE" requires explicit package name at cloc line xx.
if ($all_lines =~ $RE{comment}{$language}) {
# Suppress "Use of uninitialized value in regexp compilation" that
# pops up when $1 is undefined--happens if there's a bug in the $RE
# This Pascal comment will trigger it:
# (* This is { another } test. **)
# Curiously, testing for "defined $1" breaks the substitution.
no warnings;
# Remove comments.
$all_lines =~ s/$1//g;
}
# a bogus use of %RE to avoid:
# Name "main::RE" used only once: possible typo at cloc line xx.
print scalar keys %RE if $opt_v < -20;
print "<- call_regexp_common\n" if $opt_v > 2;
return split("\n", $all_lines);
} # 1}}}
sub plural_form { # {{{1
# For getting the right plural form on some English nouns.
my $n = shift @_;
if ($n == 1) { return ( 1, "" ); }
else { return ($n, "s"); }
} # 1}}}
sub matlab_or_objective_C { # {{{1
# Decide if code is MATLAB, Mathematica, Objective C, MUMPS, or Mercury
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
$rs_language , # out
) = @_;
print "-> matlab_or_objective_C\n" if $opt_v > 2;
# matlab markers:
# first line starts with "function"
# some lines start with "%"
# high marks for lines that start with [
#
# Objective C markers:
# must have at least two brace characters, { }
# has /* ... */ style comments
# some lines start with @
# some lines start with #include
#
# MUMPS:
# has ; comment markers
# do not match: \w+\s*=\s*\w
# lines begin with \s*\.?\w+\s+\w
# high marks for lines that start with \s*K\s+ or \s*Kill\s+
#
# Mercury:
# any line that begins with :- immediately triggers this
#
# Mathematica:
# (* .. *)
# BeginPackage
${$rs_language} = "";
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return;
}
my $DEBUG = 0;
my $matlab_points = 0;
my $mathematica_points = 0;
my $objective_C_points = 0;
my $mumps_points = 0;
my $mercury_points = 0;
my $has_braces = 0;
while (<$IN>) {
++$has_braces if $_ =~ m/[{}]/;
#print "LINE $. has_braces=$has_braces\n";
++$mumps_points if $. == 1 and m{^[A-Z]};
if (m{^\s*/\*} or m {^\s*//}) { # /* or //
$objective_C_points += 5;
$matlab_points -= 5;
printf ".m: /*|// obj C=% 2d matlab=% 2d mathematica=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
} elsif (m{^:-\s+}) { # gotta be mercury
$mercury_points = 1000;
last;
} elsif (m{\w+\s*=\s*\[}) { # matrix assignment, very matlab
$matlab_points += 5;
}
if (m{\w+\[}) { # function call by []
$mathematica_points += 2;
printf ".m: \\w=[ obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
} elsif (m{^\s*\w+\s*=\s*}) { # definitely not MUMPS
--$mumps_points;
printf ".m: \\w= obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
} elsif (m{^\s*\.?(\w)\s+(\w)} and $1 !~ /\d/ and $2 !~ /\d/) {
++$mumps_points;
printf ".m: \\w \\w obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
} elsif (m{^\s*;}) {
++$mumps_points;
printf ".m: ; obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
}
if (m{^\s*#(include|import)}) {
# Objective C without a doubt
$objective_C_points = 1000;
$matlab_points = 0;
printf ".m: #includ obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
$has_braces = 2;
last;
} elsif (m{^\s*@(interface|implementation|protocol|public|protected|private|end)\s}o) {
# Objective C without a doubt
$objective_C_points = 1000;
$matlab_points = 0;
printf ".m: keyword obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
last;
} elsif (m{^\s*BeginPackage}) {
$mathematica_points += 2;
} elsif (m{^\s*\[}) { # line starts with [ -- very matlab
$matlab_points += 5;
printf ".m: [ obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
} elsif (m{^\sK(ill)?\s+}) {
$mumps_points += 5;
printf ".m: Kill obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
} elsif (m{^\s*function}) {
--$objective_C_points;
++$matlab_points;
printf ".m: funct obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
} elsif (m{^\s*%}) { # %
# matlab commented line
--$objective_C_points;
++$matlab_points;
printf ".m: pcent obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
}
}
$IN->close;
printf "END LOOP obj C=% 2d matlab=% 2d mumps=% 2d mercury= % 2d\n", $objective_C_points, $matlab_points, $mathematica_points, $mumps_points, $mercury_points if $DEBUG;
# next heuristic is unreliable for small files
# $objective_C_points = -9.9e20 unless $has_braces >= 2;
my %points = ( 'MATLAB' => $matlab_points ,
'Mathematica' => $mathematica_points ,
'MUMPS' => $mumps_points ,
'Objective C' => $objective_C_points,
'Mercury' => $mercury_points , );
${$rs_language} = (sort { $points{$b} <=> $points{$a} or $a cmp $b } keys %points)[0];
print "<- matlab_or_objective_C($file: matlab=$matlab_points, mathematica=$mathematica_points, C=$objective_C_points, mumps=$mumps_points, mercury=$mercury_points) => ${$rs_language}\n"
if $opt_v > 2;
} # 1}}}
sub Lisp_or_OpenCL { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Lisp_or_OpenCL\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $lisp_points = 0;
my $opcl_points = 0;
while (<$IN>) {
++$lisp_points if /^\s*;/;
++$lisp_points if /\((def|eval|require|export|let|loop|dec|format)/;
++$opcl_points if /^\s*(int|float|const|{)/;
}
$IN->close;
# print "lisp_points=$lisp_points opcl_points=$opcl_points\n";
if ($lisp_points > $opcl_points) {
$lang = "Lisp";
} else {
$lang = "OpenCL";
}
print "<- Lisp_or_OpenCL\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub Lisp_or_Julia { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Lisp_or_Julia\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $lisp_points = 0;
my $julia_points = 0;
while (<$IN>) {
++$lisp_points if /^\s*;/;
++$lisp_points if /\((def|eval|require|export|let|loop|dec|format)/;
++$julia_points if /^\s*(function|end|println|for|while)/;
}
$IN->close;
# print "lisp_points=$lisp_points julia_points=$julia_points\n";
if ($lisp_points > $julia_points) {
$lang = "Lisp";
} else {
$lang = "Julia";
}
print "<- Lisp_or_Julia\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub Perl_or_Prolog { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Perl_or_Prolog\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $perl_points = 0;
my $prolog_points = 0;
while (<$IN>) {
next if /^\s*$/;
if ($. == 1 and /^#!.*?\bperl/) {
$perl_points = 100;
last;
}
++$perl_points if /^=(head|over|item|cut)/;
++$perl_points if /;\s*$/;
++$perl_points if /(\{|\})/;
++$perl_points if /^\s*sub\s+/;
++$perl_points if /\s*<<'/; # start HERE block
++$perl_points if /\$(\w+\->|[_!])/;
++$prolog_points if !/\s*#/ and /\.\s*$/;
++$prolog_points if /:-/;
}
$IN->close;
# print "perl_points=$perl_points prolog_points=$prolog_points\n";
if ($perl_points > $prolog_points) {
$lang = "Perl";
} else {
$lang = "Prolog";
}
printf "<- Perl_or_Prolog(%s, Perl=%d Prolog=%d)\n",
$file, $perl_points, $prolog_points if $opt_v > 2;
return $lang;
} # 1}}}
sub IDL_or_QtProject { # {{{1
# IDL, QtProject, Prolog, or ProGuard
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> IDL_or_QtProject($file)\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $idl_points = 0;
my $qtproj_points = 0;
my $prolog_points = 0;
my $proguard_points = 0;
while (<$IN>) {
++$idl_points if /^\s*;/;
++$idl_points if /plot\(/i;
++$qtproj_points if /^\s*(qt|configs|sources|template|target|targetpath|subdirs)\b/i;
++$qtproj_points if /qthavemodule/i;
++$prolog_points if /\.\s*$/;
++$prolog_points if /:-/;
++$proguard_points if /^\s*#/;
++$proguard_points if /^-keep/;
++$proguard_points if /^-(dont)?obfuscate/;
}
$IN->close;
# print "idl_points=$idl_points qtproj_points=$qtproj_points\n";
my %points = ( 'IDL' => $idl_points ,
'Qt Project' => $qtproj_points ,
'Prolog' => $prolog_points ,
'ProGuard' => $proguard_points ,
);
$lang = (sort { $points{$b} <=> $points{$a} or $a cmp $b} keys %points)[0];
print "<- IDL_or_QtProject(idl_points=$idl_points, ",
"qtproj_points=$qtproj_points, prolog_points=$prolog_points, ",
"proguard_points=$proguard_points)\n"
if $opt_v > 2;
return $lang;
} # 1}}}
sub Ant_or_XML { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Ant_or_XML($file)\n" if $opt_v > 2;
my $lang = "XML";
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $Ant_points = 0;
my $XML_points = 1;
while (<$IN>) {
if (/^\s*<project\s+/) {
++$Ant_points ;
--$XML_points ;
}
if (/xmlns:artifact="antlib:org.apache.maven.artifact.ant"/) {
++$Ant_points ;
--$XML_points ;
}
}
$IN->close;
if ($XML_points >= $Ant_points) {
# tie or better goes to XML
$lang = "XML";
} else {
$lang = "Ant";
}
print "<- Ant_or_XML($lang)\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub Maven_or_XML { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Maven_or_XML($file)\n" if $opt_v > 2;
my $lang = "XML";
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $Mvn_points = 0;
my $XML_points = 1;
while (<$IN>) {
if (/^\s*<project\s+/) {
++$Mvn_points ;
--$XML_points ;
}
if (m{xmlns="http://maven.apache.org/POM/}) {
++$Mvn_points ;
--$XML_points ;
}
}
$IN->close;
if ($XML_points >= $Mvn_points) {
# tie or better goes to XML
$lang = "XML";
} else {
$lang = "Maven";
}
print "<- Maven_or_XML($lang)\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub pascal_or_puppet { # {{{1
# Decide if code is Pascal or Puppet manifest
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
$rs_language , # out
) = @_;
print "-> pascal_or_puppet\n" if $opt_v > 2;
${$rs_language} = "";
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return;
}
my $DEBUG = 0;
my $pascal_points = 0;
my $puppet_points = 0;
while (<$IN>) {
if ( /^\s*\#\s+/ ) {
$puppet_points += .001;
next;
}
++$pascal_points if /\bprogram\s+[A-Za-z]/i;
++$pascal_points if /\bunit\s+[A-Za-z]/i;
++$pascal_points if /\bmodule\s+[A-Za-z]/i;
++$pascal_points if /\bprocedure\b/i;
++$pascal_points if /\bfunction\b/i;
++$pascal_points if /^\s*interface\s+/i;
++$pascal_points if /^\s*implementation\s+/i;
++$pascal_points if /^\s*uses\s+/i;
++$pascal_points if /(?<!\:\:)\bbegin\b(?!\:\:)/i;
++$pascal_points if /(?<!\:\:)\bend\b(?!\:\:)/i;
++$pascal_points if /\:\=/;
++$pascal_points if /\<\>/;
++$pascal_points if /^\s*\{\$(I|INCLUDE)\s+.*\}/i;
++$pascal_points if /writeln/;
++$puppet_points if /^\s*class\s+/ and not /class\s+operator\s+/;
++$puppet_points if /^\s*case\s+/;
++$puppet_points if /^\s*package\s+/;
++$puppet_points if /^\s*file\s+/;
++$puppet_points if /^\s*include\s\w+/;
++$puppet_points if /^\s*service\s+/;
++$puppet_points if /\s\$\w+\s*\=\s*\S/;
++$puppet_points if /\S\s*\=\>\s*\S/;
# No need to process rest of file if language seems obvious.
last
if (abs ($pascal_points - $puppet_points ) > 20 );
}
$IN->close;
print "<- pascal_or_puppet(pascal=$pascal_points, puppet=$puppet_points)\n"
if $opt_v > 2;
if ($pascal_points > $puppet_points) {
${$rs_language} = "Pascal";
} else {
${$rs_language} = "Puppet";
}
} # 1}}}
sub Forth_or_Fortran { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Forth_or_Fortran\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $forth_points = 0;
my $fortran_points = 0;
while (<$IN>) {
++$forth_points if /^:\s/;
++$fortran_points if /^([c*][^a-z]|\s{6,}(subroutine|program|end|implicit)\s|\s*!)/i;
}
$IN->close;
if ($forth_points > $fortran_points) {
$lang = "Forth";
} else {
$lang = "Fortran 77";
}
print "<- Forth_or_Fortran\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub Forth_or_Fsharp { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Forth_or_Fsharp\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $forth_points = 0;
my $fsharp_points = 0;
while (<$IN>) {
++$forth_points if /^:\s/;
++$fsharp_points if /^\s*(#light|import|let|module|namespace|open|type)/;
}
$IN->close;
if ($forth_points > $fsharp_points) {
$lang = "Forth";
} else {
$lang = "F#";
}
print "<- Forth_or_Fsharp\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub Verilog_or_Coq { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Verilog_or_Coq\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $coq_points = 0;
my $verilog_points = 0;
while (<$IN>) {
++$verilog_points if /^\s*(module|begin|input|output|always)/;
++$coq_points if /\b(Inductive|Fixpoint|Definition|
Theorem|Lemma|Proof|Qed|forall|
Section|Check|Notation|Variable|
Goal|Fail|Require|Scheme|Module|Ltac|
Set|Unset|Parameter|Coercion|Axiom|
Locate|Type|Record|Existing|Class)\b/x;
}
$IN->close;
if ($coq_points > $verilog_points) {
$lang = "Coq";
} else {
$lang = "Verilog-SystemVerilog";
}
print "<- Verilog_or_Coq\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub TypeScript_or_QtLinguist { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> TypeScript_or_QtLinguist\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $tscript_points = 0;
my $linguist_points = 0;
while (<$IN>) {
++$linguist_points if m{\b</?(message|source|translation)>};
++$tscript_points if /^\s*(var|const|let|class|document)\b/;
++$tscript_points if /[;}]\s*$/;
++$tscript_points if m{^\s*//};
}
$IN->close;
if ($tscript_points >= $linguist_points) {
$lang = "TypeScript";
} else {
$lang = "Qt Linguist";
}
print "<- TypeScript_or_QtLinguist\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub Qt_or_Glade { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Qt_or_Glade\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $qt_points = 1;
my $glade_points = -1;
while (<$IN>) {
if (/generated\s+with\s+glade/i) {
$glade_points = 1;
$qt_points = -1;
last;
}
}
$IN->close;
if ($glade_points > $qt_points) {
$lang = "Glade";
} else {
$lang = "Qt";
}
print "<- Qt_or_Glade\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub Csharp_or_Smalltalk { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Csharp_or_Smalltalk($file)\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $cs_points = 0;
my $smalltalk_points = 0;
while (<$IN>) {
s{//.*?$}{}; # strip inline C# comments for better clarity
next if /^\s*$/;
if (/[;}{]\s*$/) {
++$cs_points ;
} elsif (/^(using|namespace)\s/) {
$cs_points += 20;
} elsif (/^\s*(public|private|new)\s/) {
$cs_points += 20;
} elsif (/^\s*\[assembly:/) {
++$cs_points ;
}
if (/(\!|\]\.)\s*$/) {
++$smalltalk_points;
--$cs_points ;
}
}
$IN->close;
if ($smalltalk_points > $cs_points) {
$lang = "Smalltalk";
} else {
$lang = "C#";
}
print "<- Csharp_or_Smalltalk($file)=$lang\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub Visual_Basic_or_TeX_or_Apex { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
$rs_language , # out
) = @_;
print "-> Visual_Basic_or_TeX_or_Apex($file)\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $VB_points = 0;
my $tex_points = 0;
my $apex_points = 0;
while (<$IN>) {
next if /^\s*$/;
#print "$_";
if (/\s*%/ or /\s*\\/) {
++$tex_points ;
} else {
if (/^\s*(public|private)\s/i) {
++$VB_points ;
++$apex_points ;
#print "+VB1 +A1";
} elsif (/^\s*(end|attribute|version)\s/i) {
++$VB_points ;
#print "+VB2";
}
if (/[{}]/ or /;\s*$/) {
++$apex_points ;
#print "+A2";
}
#print "\n";
}
}
$IN->close;
my %points = ( 'Visual Basic' => $VB_points ,
'TeX' => $tex_points ,
'Apex Class' => $apex_points ,);
${$rs_language} = (sort { $points{$b} <=> $points{$a} or $a cmp $b } keys %points)[0];
print "<- Visual_Basic_or_TeX_or_Apex($file: VB=$VB_points, TeX=$tex_points, Apex=$apex_points\n" if $opt_v > 2;
return $lang;
} # 1}}}
sub Scheme_or_SaltStack { # {{{1
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> Scheme_or_SaltStack($file)\n" if $opt_v > 2;
my $lang = undef;
my $IN = new IO::File $file, "r";
if (!defined $IN) {
push @{$raa_errors}, [$rh_Err->{'Unable to read'} , $file];
return $lang;
}
my $Sch_points = 0;
my $SS_points = 0;
while (<$IN>) {
next if /^\s*$/;
if (/{\%.*%}/) {
$SS_points += 5;
} elsif (/map\.jinja\b/) {
$SS_points += 5;
} elsif (/\((define|lambda|let|cond|do)\s/) {
$Sch_points += 1;
} else {
}
}
$IN->close;
print "<- Scheme_or_SaltStack($file: Scheme=$Sch_points, SaltStack=$SS_points\n" if $opt_v > 2;
if ($Sch_points > $SS_points) {
return "Scheme";
} else {
return "SaltStack";
}
} # 1}}}
sub html_colored_text { # {{{1
# http://www.pagetutor.com/pagetutor/makapage/pics/net216-2.gif
my ($color, $text) = @_;
#?#die "html_colored_text($text)";
if ($color =~ /^red$/i) {
$color = "#ff0000";
} elsif ($color =~ /^green$/i) {
$color = "#00ff00";
} elsif ($color =~ /^blue$/i) {
$color = "#0000ff";
} elsif ($color =~ /^grey$/i) {
$color = "#cccccc";
}
# return "" unless $text;
return '<font color="' . $color . '">' . html_metachars($text) . "</font>";
} # 1}}}
sub xml_metachars { # {{{1
# http://en.wikipedia.org/wiki/Character_encodings_in_HTML#XML_character_references
my ($string, ) = shift @_;
my @in_chars = split(//, $string);
my @out_chars = ();
foreach my $c (@in_chars) {
if ($c eq '&') { push @out_chars, '&'
} elsif ($c eq '<') { push @out_chars, '<'
} elsif ($c eq '>') { push @out_chars, '>'
} elsif ($c eq '"') { push @out_chars, '"'
} elsif ($c eq "'") { push @out_chars, '''
} else {
push @out_chars, $c;
}
}
return join "", @out_chars;
} # 1}}}
sub html_metachars { # {{{1
# Replace HTML metacharacters with their printable forms.
# Future: use HTML-Encoder-0.00_04/lib/HTML/Encoder.pm
# from Fabiano Reese Righetti's HTML::Encoder module if
# this subroutine proves to be too simplistic.
my ($string, ) = shift @_;
my @in_chars = split(//, $string);
my @out_chars = ();
foreach my $c (@in_chars) {
if ($c eq '<') {
push @out_chars, '<'
} elsif ($c eq '>') {
push @out_chars, '>'
} elsif ($c eq '&') {
push @out_chars, '&'
} else {
push @out_chars, $c;
}
}
return join "", @out_chars;
} # 1}}}
sub test_alg_diff { # {{{1
my ($file_1 ,
$file_2 )
= @_;
my $fh_1 = new IO::File $file_1, "r";
die "Unable to read $file_1: $!\n" unless defined $fh_1;
chomp(my @lines_1 = <$fh_1>);
$fh_1->close;
my $fh_2 = new IO::File $file_2, "r";
die "Unable to read $file_2: $!\n" unless defined $fh_2;
chomp(my @lines_2 = <$fh_2>);
$fh_2->close;
my $n_no_change = 0;
my $n_modified = 0;
my $n_added = 0;
my $n_deleted = 0;
my @min_sdiff = ();
my $NN = chr(27) . "[0m"; # normal
my $BB = chr(27) . "[1m"; # bold
my @sdiffs = sdiff( \@lines_1, \@lines_2 );
foreach my $entry (@sdiffs) {
my ($out_1, $out_2) = ('', '');
if ($entry->[0] eq 'u') {
++$n_no_change;
# $out_1 = $entry->[1];
# $out_2 = $entry->[2];
next;
}
# push @min_sdiff, $entry;
if ($entry->[0] eq 'c') {
++$n_modified;
($out_1, $out_2) = diff_two_strings($entry->[1], $entry->[2]);
$out_1 =~ s/\cA(\w)/${BB}$1${NN}/g;
$out_2 =~ s/\cA(\w)/${BB}$1${NN}/g;
# $out_1 =~ s/\cA//g;
# $out_2 =~ s/\cA//g;
} elsif ($entry->[0] eq '+') {
++$n_added;
$out_1 = $entry->[1];
$out_2 = $entry->[2];
} elsif ($entry->[0] eq '-') {
++$n_deleted;
$out_1 = $entry->[1];
$out_2 = $entry->[2];
} elsif ($entry->[0] eq 'u') {
} else { die "unknown entry->[0]=[$entry->[0]]\n"; }
printf "%-80s | %s\n", $out_1, $out_2;
}
# foreach my $entry (@min_sdiff) {
# printf "DIFF: %s %s %s\n", @{$entry};
# }
} # 1}}}
sub write_comments_to_html { # {{{1
my ($filename , # in
$rah_diff_L , # in see routine array_diff() for explanation
$rah_diff_R , # in see routine array_diff() for explanation
$rh_blank , # in location and counts of blank lines
) = @_;
print "-> write_comments_to_html($filename)\n" if $opt_v > 2;
my $file = $filename . ".html";
my $approx_line_count = scalar @{$rah_diff_L};
$approx_line_count = 1 unless $approx_line_count;
my $n_digits = 1 + int(log($approx_line_count)/2.30258509299405); # log_10
my $html_out = html_header($filename);
my $comment_line_number = 0;
for (my $i = 0; $i < scalar @{$rah_diff_R}; $i++) {
if (defined $rh_blank->{$i}) {
foreach (1..$rh_blank->{$i}) {
$html_out .= "<!-- blank -->\n";
}
}
my $line_num = "";
my $pre = "";
my $post = '</span> ';
warn "undef rah_diff_R[$i]{type} " unless defined $rah_diff_R->[$i]{type};
if ($rah_diff_R->[$i]{type} eq 'nonexist') {
++$comment_line_number;
$line_num = sprintf "\ <span class=\"clinenum\"> %0${n_digits}d %s",
$comment_line_number, $post;
$pre = '<span class="comment">';
$html_out .= $line_num;
$html_out .= $pre .
html_metachars($rah_diff_L->[$i]{char}) .
$post . "\n";
next;
}
if ($rah_diff_R->[$i]{type} eq 'code' and
$rah_diff_R->[$i]{desc} eq 'same') {
# entire line remains as-is
$line_num = sprintf "\ <span class=\"linenum\"> %0${n_digits}d %s",
$rah_diff_R->[$i]{lnum}, $post;
$pre = '<span class="normal">';
$html_out .= $line_num;
$html_out .= $pre .
html_metachars($rah_diff_R->[$i]{char}) . $post;
#XX } elsif ($rah_diff_R->[$i]{type} eq 'code') { # code+comments
#XX
#XX $line_num = '<span class="linenum">' .
#XX $rah_diff_R->[$i]{lnum} . $post;
#XX $html_out .= $line_num;
#XX
#XX my @strings = @{$rah_diff_R->[$i]{char}{strings}};
#XX my @type = @{$rah_diff_R->[$i]{char}{type}};
#XX for (my $i = 0; $i < scalar @strings; $i++) {
#XX if ($type[$i] eq 'u') {
#XX $pre = '<span class="normal">';
#XX } else {
#XX $pre = '<span class="comment">';
#XX }
#XX $html_out .= $pre . html_metachars($strings[$i]) . $post;
#XX }
# print Dumper(@strings, @type); die;
} elsif ($rah_diff_R->[$i]{type} eq 'comment') {
$line_num = '<span class="clinenum">' . $comment_line_number . $post;
# entire line is a comment
$pre = '<span class="comment">';
$html_out .= $pre .
html_metachars($rah_diff_R->[$i]{char}) . $post;
}
#printf "%-30s %s %-30s\n", $line_1, $separator, $line_2;
$html_out .= "\n";
}
$html_out .= html_end();
my $out_file = "$filename.html";
write_file($out_file, {}, ( $html_out ) );
print "<- write_comments_to_html\n" if $opt_v > 2;
} # 1}}}
sub array_diff { # {{{1
my ($file , # in only used for error reporting
$ra_lines_L , # in array of lines in Left file (no blank lines)
$ra_lines_R , # in array of lines in Right file (no blank lines)
$mode , # in "comment" | "revision"
$rah_diff_L , # out
$rah_diff_R , # out
$raa_Errors , # in/out
) = @_;
# This routine operates in two ways:
# A. Computes diffs of the same file with and without comments.
# This is used to classify lines as code, comments, or blank.
# B. Computes diffs of two revisions of a file. This method
# requires a prior run of method A using the older version
# of the file because it needs lines to be classified.
# $rah_diff structure:
# An array with n entries where n equals the number of lines in
# an sdiff of the two files. Each entry in the array describes
# the contents of the corresponding line in file Left and file Right:
# diff[]{type} = blank | code | code+comment | comment | nonexist
# {lnum} = line number within the original file (1-based)
# {desc} = same | added | removed | modified
# {char} = the input line unless {desc} = 'modified' in
# which case
# {char}{strings} = [ substrings ]
# {char}{type} = [ disposition (added, removed, etc)]
#
@{$rah_diff_L} = ();
@{$rah_diff_R} = ();
print "-> array_diff()\n" if $opt_v > 2;
my $COMMENT_MODE = 0;
$COMMENT_MODE = 1 if $mode eq "comment";
#print "array_diff(mode=$mode)\n";
#print Dumper("block left:" , $ra_lines_L);
#print Dumper("block right:", $ra_lines_R);
my @sdiffs = ();
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm $opt_diff_timeout;
@sdiffs = sdiff($ra_lines_L, $ra_lines_R);
alarm 0;
};
if ($@) {
# timed out
die unless $@ eq "alarm\n"; # propagate unexpected errors
push @{$raa_Errors},
[ $Error_Codes{'Diff error, exceeded timeout'}, $file ];
if ($opt_v) {
warn "array_diff: diff timeout failure for $file--ignoring\n";
}
return;
}
my $n_L = 0;
my $n_R = 0;
my $n_sdiff = 0; # index to $rah_diff_L, $rah_diff_R
foreach my $triple (@sdiffs) {
my $flag = $triple->[0];
my $line_L = $triple->[1];
my $line_R = $triple->[2];
$rah_diff_L->[$n_sdiff]{char} = $line_L;
$rah_diff_R->[$n_sdiff]{char} = $line_R;
if ($flag eq 'u') { # u = unchanged
++$n_L;
++$n_R;
if ($COMMENT_MODE) {
# line exists in both with & without comments, must be code
$rah_diff_L->[$n_sdiff]{type} = "code";
$rah_diff_R->[$n_sdiff]{type} = "code";
}
$rah_diff_L->[$n_sdiff]{desc} = "same";
$rah_diff_R->[$n_sdiff]{desc} = "same";
$rah_diff_L->[$n_sdiff]{lnum} = $n_L;
$rah_diff_R->[$n_sdiff]{lnum} = $n_R;
} elsif ($flag eq 'c') { # c = changed
# warn "per line sdiff() commented out\n"; if (0) {
++$n_L;
++$n_R;
if ($COMMENT_MODE) {
# line has text both with & without comments;
# count as code
$rah_diff_L->[$n_sdiff]{type} = "code";
$rah_diff_R->[$n_sdiff]{type} = "code";
}
my @chars_L = split '', $line_L;
my @chars_R = split '', $line_R;
$rah_diff_L->[$n_sdiff]{desc} = "modified";
$rah_diff_R->[$n_sdiff]{desc} = "modified";
$rah_diff_L->[$n_sdiff]{lnum} = $n_L;
$rah_diff_R->[$n_sdiff]{lnum} = $n_R;
} elsif ($flag eq '+') { # + = added
++$n_R;
if ($COMMENT_MODE) {
# should never get here, but may due to sdiff() bug,
# ref https://rt.cpan.org/Public/Bug/Display.html?id=131629
# Rather than failing, ignore and continue. A possible
# consequence is counts may be inconsistent.
##### @{$rah_diff_L} = ();
##### @{$rah_diff_R} = ();
##### push @{$raa_Errors},
##### [ $Error_Codes{'Diff error (quoted comments?)'}, $file ];
if ($opt_v) {
warn "array_diff: diff failure (diff says the\n";
warn "comment-free file has added lines).\n";
warn "$n_sdiff $line_L\n";
}
}
#### $rah_diff_L->[$n_sdiff]{type} = "nonexist";
$rah_diff_L->[$n_sdiff]{type} = "comment";
$rah_diff_L->[$n_sdiff]{desc} = "removed";
$rah_diff_R->[$n_sdiff]{desc} = "added";
$rah_diff_R->[$n_sdiff]{lnum} = $n_R;
} elsif ($flag eq '-') { # - = removed
++$n_L;
if ($COMMENT_MODE) {
# line must be comment because blanks already gone
$rah_diff_L->[$n_sdiff]{type} = "comment";
}
$rah_diff_R->[$n_sdiff]{type} = "nonexist";
$rah_diff_R->[$n_sdiff]{desc} = "removed";
$rah_diff_L->[$n_sdiff]{desc} = "added";
$rah_diff_L->[$n_sdiff]{lnum} = $n_L;
}
#printf "%-30s %s %-30s\n", $line_L, $separator, $line_R;
++$n_sdiff;
}
#use Data::Dumper::Simple;
#print Dumper($rah_diff_L, $rah_diff_R);
#print Dumper($rah_diff_L);
print "<- array_diff\n" if $opt_v > 2;
} # 1}}}
sub remove_leading_dir { # {{{1
my @filenames = @_;
#
# Input should be a list of file names
# with the same leading directory such as
#
# dir1/dir2/a.txt
# dir1/dir2/b.txt
# dir1/dir2/dir3/c.txt
#
# Output is the same list minus the common
# directory path:
#
# a.txt
# b.txt
# dir3/c.txt
#
print "-> remove_leading_dir()\n" if $opt_v > 2;
my @D = (); # a matrix: [ [ dir1, dir2 ], # dir1/dir2/a.txt
# [ dir1, dir2 ], # dir1/dir2/b.txt
# [ dir1, dir2 , dir3] ] # dir1/dir2/dir3/c.txt
if ($ON_WINDOWS) {
foreach my $F (@filenames) {
$F =~ s{\\}{/}g;
$F = ucfirst($F) if $F =~ /^\w:/; # uppercase drive letter
}
}
if (scalar @filenames == 1) {
# special case: with only one filename
# cannot determine a baseline, just remove first directory level
$filenames[0] =~ s{^.*?/}{};
# print "-> $filenames[0]\n";
return $filenames[0];
}
foreach my $F (@filenames) {
my ($Vol, $Dir, $File) = File::Spec->splitpath($F);
my @x = File::Spec->splitdir( $Dir );
pop @x unless $x[$#x]; # last entry usually null, remove it
if ($ON_WINDOWS) {
if (defined($Vol) and $Vol) {
# put the drive letter, eg, C:, at the front
unshift @x, uc $Vol;
}
}
#print "F=$F, Dir=$Dir x=[", join("][", @x), "]\n";
push @D, [ @x ];
}
# now loop over columns until either they are all
# eliminated or a unique column is found
my @common = (); # to contain the common leading directories
my $mismatch = 0;
while (!$mismatch) {
for (my $row = 1; $row < scalar @D; $row++) {
#print "comparing $D[$row][0] to $D[0][0]\n";
if (!defined $D[$row][0] or !defined $D[0][0] or
($D[$row][0] ne $D[0][0])) {
$mismatch = 1;
last;
}
}
#print "mismatch=$mismatch\n";
if (!$mismatch) {
push @common, $D[0][0];
# all terms in the leading match; unshift the batch
foreach my $ra (@D) {
shift @{$ra};
}
}
}
push @common, " "; # so that $leading will end with "/ "
my $leading = File::Spec->catdir( @common );
$leading =~ s{ $}{}; # now take back the bogus appended space
#print "remove_leading_dir leading=[$leading]\n"; die;
if ($ON_WINDOWS) {
$leading =~ s{\\}{/}g;
}
foreach my $F (@filenames) {
$F =~ s{^$leading}{};
}
print "<- remove_leading_dir()\n" if $opt_v > 2;
return @filenames;
} # 1}}}
sub strip_leading_dir { # {{{1
my ($leading, @filenames) = @_;
# removes the string $leading from each entry in @filenames
print "-> strip_leading_dir()\n" if $opt_v > 2;
#print "remove_leading_dir leading=[$leading]\n"; die;
if ($ON_WINDOWS) {
$leading =~ s{\\}{/}g;
foreach my $F (@filenames) {
$F =~ s{\\}{/}g;
}
}
foreach my $F (@filenames) {
$F =~ s{^$leading}{};
}
print "<- strip_leading_dir()\n" if $opt_v > 2;
return @filenames;
} # 1}}}
sub find_deepest_file { # {{{1
my @filenames = @_;
#
# Input should be a list of file names
# with the same leading directory such as
#
# dir1/dir2/a.txt
# dir1/dir2/b.txt
# dir1/dir2/dir3/c.txt
#
# Output is the file with the most parent directories:
#
# dir1/dir2/dir3/c.txt
print "-> find_deepest_file()\n" if $opt_v > 2;
my $deepest = undef;
my $max_subdir = -1;
foreach my $F (sort @filenames) {
my ($Vol, $Dir, $File) = File::Spec->splitpath($F);
my @x = File::Spec->splitdir( $Dir );
pop @x unless $x[$#x]; # last entry usually null, remove it
if (scalar @x > $max_subdir) {
$deepest = $F;
$max_subdir = scalar @x;
}
}
print "<- find_deepest_file()\n" if $opt_v > 2;
return $deepest;
} # 1}}}
sub find_uncommon_parent_dir { # {{{1
my ($file_L, $file_R) = @_;
#
# example:
#
# file_L = "perl-5.16.1/cpan/CPANPLUS/lib/CPANPLUS/Internals/Source/SQLite/Tie.pm"
# file_R = "/tmp/8VxQG0OLbp/perl-5.16.3/cpan/CPANPLUS/lib/CPANPLUS/Internals/Source/SQLite/Tie.pm"
#
# then return
#
# "perl-5.16.1",
# "/tmp/8VxQG0OLbp/perl-5.16.3",
my ($Vol_L, $Dir_L, $File_L) = File::Spec->splitpath($file_L);
my @x_L = File::Spec->splitdir( $Dir_L );
my ($Vol_R, $Dir_R, $File_R) = File::Spec->splitpath($file_R);
my @x_R = File::Spec->splitdir( $Dir_R );
my @common = ();
# work backwards
while ($x_L[$#x_L] eq $x_R[$#x_R]) {
push @common, $x_L[$#x_L];
pop @x_L;
pop @x_R;
}
my $success = scalar @common;
my $dirs_L = File::Spec->catdir( @x_L );
my $dirs_R = File::Spec->catdir( @x_R );
my $lead_L = File::Spec->catpath( $Vol_L, $dirs_L, "" );
my $lead_R = File::Spec->catpath( $Vol_R, $dirs_R, "" );
return $lead_L, $lead_R, $success;
} # 1}}}
sub get_leading_dirs { # {{{1
my ($rh_file_list_L, $rh_file_list_R) = @_;
# find uniquely named files in both sets to help determine the
# leading directory positions
my %unique_filename = ();
my %basename_L = ();
my %basename_R = ();
foreach my $f (keys %{$rh_file_list_L}) {
my $bn = basename($f);
$basename_L{ $bn }{'count'} += 1;
$basename_L{ $bn }{'fullpath'} = $f;
}
foreach my $f (keys %{$rh_file_list_R}) {
my $bn = basename($f);
$basename_R{ $bn }{'count'} += 1;
$basename_R{ $bn }{'fullpath'} = $f;
}
foreach my $f (keys %basename_L) {
next unless $basename_L{$f}{'count'} == 1;
next unless defined $basename_R{$f} and $basename_R{$f}{'count'} == 1;
$unique_filename{$f}{'L'} = $basename_L{ $f }{'fullpath'};
$unique_filename{$f}{'R'} = $basename_R{ $f }{'fullpath'};
}
return undef, undef, 0 unless %unique_filename;
####my %candidate_leading_dir_L = ();
####my %candidate_leading_dir_R = ();
my ($L_drop, $R_drop) = (undef, undef);
foreach my $f (keys %unique_filename) {
my $fL = $unique_filename{ $f }{'L'};
my $fR = $unique_filename{ $f }{'R'};
my @DL = File::Spec->splitdir($fL);
my @DR = File::Spec->splitdir($fR);
#printf "%-36s -> %-36s\n", $fL, $fR;
#print Dumper(@DL, @DR);
# find the most number of common directories between L and R
if (!defined $L_drop) {
$L_drop = dirname $fL;
}
if (!defined $R_drop) {
$R_drop = dirname $fR;
}
my $n_path_elements_L = scalar @DL;
my $n_path_elements_R = scalar @DR;
my $n_path_elem = $n_path_elements_L < $n_path_elements_R ?
$n_path_elements_L : $n_path_elements_R;
my ($n_L_drop_this_pair, $n_R_drop_this_pair) = (0, 0);
for (my $i = 0; $i < $n_path_elem; $i++) {
last if $DL[ $#DL - $i] ne $DR[ $#DR - $i];
++$n_L_drop_this_pair;
++$n_R_drop_this_pair;
}
my $L_common = File::Spec->catdir( @DL[0..($#DL-$n_L_drop_this_pair)] );
my $R_common = File::Spec->catdir( @DR[0..($#DR-$n_R_drop_this_pair)] );
#print "L_common=$L_common\n";
#print "R_common=$R_common\n";
$L_drop = $L_common if length $L_common < length $L_drop;
$R_drop = $R_common if length $R_common < length $R_drop;
########my $ptr_L = length($fL) - 1;
########my $ptr_R = length($fR) - 1;
########my @aL = split '', $fL;
########my @aR = split '', $fR;
########while ($ptr_L >= 0 and $ptr_R >= 0) {
######## last if $aL[$ptr_L] ne $aR[$ptr_R];
######## --$ptr_L;
######## --$ptr_R;
########}
########my $leading_dir_L = "";
######## $leading_dir_L = substr($fL, 0, $ptr_L+1) if $ptr_L >= 0;
########my $leading_dir_R = "";
######## $leading_dir_R = substr($fR, 0, $ptr_R+1) if $ptr_R >= 0;
########++$candidate_leading_dir_L{$leading_dir_L};
########++$candidate_leading_dir_R{$leading_dir_R};
}
#use Data::Dumper::Simple;
#print Dumper(%candidate_leading_dir_L);
#print Dumper(%candidate_leading_dir_R);
#die;
return $L_drop, $R_drop, 1;
####my $best_L = (sort {
#### $candidate_leading_dir_L{$b} <=>
#### $candidate_leading_dir_L{$a}} keys %candidate_leading_dir_L)[0];
####my $best_R = (sort {
#### $candidate_leading_dir_R{$b} <=>
#### $candidate_leading_dir_R{$a}} keys %candidate_leading_dir_R)[0];
####return $best_L, $best_R, 1;
} # 1}}}
sub align_by_pairs { # {{{1
my ($rh_file_list_L , # in
$rh_file_list_R , # in
$ra_added , # out
$ra_removed , # out
$ra_compare_list , # out
) = @_;
print "-> align_by_pairs()\n" if $opt_v > 2;
@{$ra_compare_list} = ();
my @files_L = sort keys %{$rh_file_list_L};
my @files_R = sort keys %{$rh_file_list_R};
return () unless @files_L or @files_R; # at least one must have stuff
if ( @files_L and !@files_R) {
# left side has stuff, right side is empty; everything deleted
@{$ra_added } = ();
@{$ra_removed } = @files_L;
@{$ra_compare_list} = ();
return;
} elsif (!@files_L and @files_R) {
# left side is empty, right side has stuff; everything added
@{$ra_added } = @files_R;
@{$ra_removed } = ();
@{$ra_compare_list} = ();
return;
} elsif (scalar(@files_L) == 1 and scalar(@files_R) == 1) {
# Special case of comparing one file against another. In
# this case force the pair to be aligned with each other,
# otherwise the file naming logic will think one file
# was added and the other deleted.
@{$ra_added } = ();
@{$ra_removed } = ();
@{$ra_compare_list} = ( [$files_L[0], $files_R[0]] );
return;
}
#use Data::Dumper::Simple;
#print Dumper("align_by_pairs", %{$rh_file_list_L}, %{$rh_file_list_R},);
#die;
# The harder case: compare groups of files. This only works
# if the groups are in different directories so the first step
# is to strip the leading directory names from file lists to
# make it possible to align by file names.
my @files_L_minus_dir = undef;
my @files_R_minus_dir = undef;
my $deepest_file_L = find_deepest_file(@files_L);
my $deepest_file_R = find_deepest_file(@files_R);
#print "deepest L = [$deepest_file_L]\n";
#print "deepest R = [$deepest_file_R]\n";
my ($leading_dir_L, $leading_dir_R, $success) =
get_leading_dirs($rh_file_list_L, $rh_file_list_R);
#print "leading_dir_L=[$leading_dir_L]\n";
#print "leading_dir_R=[$leading_dir_R]\n";
#print "success =[$success]\n";
if ($success) {
@files_L_minus_dir = strip_leading_dir($leading_dir_L, @files_L);
@files_R_minus_dir = strip_leading_dir($leading_dir_R, @files_R);
} else {
# otherwise fall back to old strategy
@files_L_minus_dir = remove_leading_dir(@files_L);
@files_R_minus_dir = remove_leading_dir(@files_R);
}
# Keys of the stripped_X arrays are canonical file names;
# should overlap mostly. Keys in stripped_L but not in
# stripped_R are files that have been deleted. Keys in
# stripped_R but not in stripped_L have been added.
my %stripped_L = ();
@stripped_L{ @files_L_minus_dir } = @files_L;
my %stripped_R = ();
@stripped_R{ @files_R_minus_dir } = @files_R;
my %common = ();
foreach my $f (keys %stripped_L) {
$common{$f} = 1 if defined $stripped_R{$f};
}
my %deleted = ();
foreach my $f (keys %stripped_L) {
$deleted{$stripped_L{$f}} = $f unless defined $stripped_R{$f};
}
my %added = ();
foreach my $f (keys %stripped_R) {
$added{$stripped_R{$f}} = $f unless defined $stripped_L{$f};
}
#use Data::Dumper::Simple;
#print Dumper("align_by_pairs", %stripped_L, %stripped_R);
#print Dumper("align_by_pairs", %common, %added, %deleted);
foreach my $f (keys %common) {
push @{$ra_compare_list}, [ $stripped_L{$f},
$stripped_R{$f} ];
}
@{$ra_added } = keys %added ;
@{$ra_removed } = keys %deleted;
print "<- align_by_pairs()\n" if $opt_v > 2;
return;
#print Dumper("align_by_pairs", @files_L_minus_dir, @files_R_minus_dir);
#die;
} # 1}}}
sub html_header { # {{{1
my ($title , ) = @_;
print "-> html_header\n" if $opt_v > 2;
return
'<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="GENERATOR" content="cloc http://github.com/AlDanial/cloc">
' .
"
<!-- Created by $script v$VERSION -->
<title>$title</title>
" .
'
<style TYPE="text/css">
<!--
body {
color: black;
background-color: white;
font-family: monospace
}
.whitespace {
background-color: gray;
}
.comment {
color: gray;
font-style: italic;
}
.clinenum {
color: red;
}
.linenum {
color: green;
}
-->
</style>
</head>
<body>
<pre><tt>
';
print "<- html_header\n" if $opt_v > 2;
} # 1}}}
sub html_end { # {{{1
return
'</tt></pre>
</body>
</html>
';
} # 1}}}
sub die_unknown_lang { # {{{1
my ($lang, $option_name) = @_;
die "Unknown language '$lang' used with $option_name option. " .
"The command\n $script --show-lang\n" .
"will print all recognized languages. Language names are " .
"case sensitive.\n" ;
} # 1}}}
sub unicode_file { # {{{1
my $file = shift @_;
print "-> unicode_file($file)\n" if $opt_v > 2;
return 0 if (-s $file > 2_000_000);
# don't bother trying to test binary files bigger than 2 MB
my $IN = new IO::File $file, "r";
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
return 0;
}
my @lines = <$IN>;
$IN->close;
if (unicode_to_ascii( join('', @lines) )) {
print "<- unicode_file()\n" if $opt_v > 2;
return 1;
} else {
print "<- unicode_file()\n" if $opt_v > 2;
return 0;
}
} # 1}}}
sub unicode_to_ascii { # {{{1
my $string = shift @_;
# A trivial attempt to convert UTF-16 little or big endian
# files into ASCII. These files exhibit the following byte
# sequence:
# byte 1: 255
# byte 2: 254
# byte 3: ord of ASCII character
# byte 4: 0
# byte 3+i: ord of ASCII character
# byte 4+i: 0
# or
# byte 1: 255
# byte 2: 254
# byte 3: 0
# byte 4: ord of ASCII character
# byte 3+i: 0
# byte 4+i: ord of ASCII character
my $length = length $string;
#print "length=$length\n";
return '' if $length <= 3;
my @unicode = split(//, $string);
# check the first 100 characters for big or little endian UTF-16 encoding
my $max_peek = $length < 200 ? $length : 200;
my @view_1 = ();
for (my $i = 2; $i < $max_peek; $i += 2) { push @view_1, $unicode[$i] }
my @view_2 = ();
for (my $i = 3; $i < $max_peek; $i += 2) { push @view_2, $unicode[$i] }
my $points_1 = 0;
foreach my $C (@view_1) {
++$points_1 if (32 <= ord($C) and ord($C) <= 127) or ord($C) == 13
or ord($C) == 10
or ord($C) == 9;
}
my $points_2 = 0;
foreach my $C (@view_2) {
++$points_2 if (32 <= ord($C) and ord($C) <= 127) or ord($C) == 13
or ord($C) == 10
or ord($C) == 9;
}
#print "points 1: $points_1\n";
#print "points 2: $points_2\n";
my $offset = undef;
if ($points_1 > 90) { $offset = 2; }
elsif ($points_2 > 90) { $offset = 3; }
else { return '' } # neither big or little endian UTF-16
my @ascii = ();
for (my $i = $offset; $i < $length; $i += 2) { push @ascii, $unicode[$i]; }
return join("", @ascii);
} # 1}}}
sub uncompress_archive_cmd { # {{{1
my ($archive_file, ) = @_;
# Wrap $archive_file in single or double quotes in the system
# commands below to avoid filename chicanery (including
# spaces in the names).
print "-> uncompress_archive_cmd($archive_file)\n" if $opt_v > 2;
my $extract_cmd = "";
my $missing = "";
if ($opt_extract_with) {
( $extract_cmd = $opt_extract_with ) =~ s/>FILE</$archive_file/g;
} elsif (basename($archive_file) eq "-" and !$ON_WINDOWS) {
$extract_cmd = "cat > -";
} elsif (($archive_file =~ /\.tar\.(gz|Z)$/ or
$archive_file =~ /\.tgz$/ ) and !$ON_WINDOWS) {
if (external_utility_exists("gzip --version")) {
if (external_utility_exists("tar --version")) {
$extract_cmd = "gzip -dc '$archive_file' | tar xf -";
} else {
$missing = "tar";
}
} else {
$missing = "gzip";
}
} elsif ($archive_file =~ /\.tar\.bz2$/ and !$ON_WINDOWS) {
if (external_utility_exists("bzip2 --help")) {
if (external_utility_exists("tar --version")) {
$extract_cmd = "bzip2 -dc '$archive_file' | tar xf -";
} else {
$missing = "tar";
}
} else {
$missing = "bzip2";
}
} elsif ($archive_file =~ /\.tar\.xz$/ and !$ON_WINDOWS) {
if (external_utility_exists("unxz --version")) {
if (external_utility_exists("tar --version")) {
$extract_cmd = "unxz -dc '$archive_file' | tar xf -";
} else {
$missing = "tar";
}
} else {
$missing = "bzip2";
}
} elsif ($archive_file =~ /\.tar$/ and !$ON_WINDOWS) {
$extract_cmd = "tar xf '$archive_file'";
} elsif ($archive_file =~ /\.src\.rpm$/i and !$ON_WINDOWS) {
if (external_utility_exists("cpio --version")) {
if (external_utility_exists("rpm2cpio")) {
$extract_cmd = "rpm2cpio '$archive_file' | cpio -i";
} else {
$missing = "rpm2cpio";
}
} else {
$missing = "bzip2";
}
} elsif ($archive_file =~ /\.(whl|zip)$/i and !$ON_WINDOWS) {
if (external_utility_exists("unzip")) {
$extract_cmd = "unzip -qq -d . '$archive_file'";
} else {
$missing = "unzip";
}
} elsif ($archive_file =~ /\.deb$/i and !$ON_WINDOWS) {
# only useful if the .deb contains source code--most
# .deb files just have compiled executables
if (external_utility_exists("dpkg-deb")) {
$extract_cmd = "dpkg-deb -x '$archive_file' .";
} else {
$missing = "dpkg-deb";
}
} elsif ($ON_WINDOWS and $archive_file =~ /\.(whl|zip)$/i) {
# use unzip on Windows (comes with git-for-Windows)
if (external_utility_exists("unzip")) {
$extract_cmd = "unzip -qq -d . \"$archive_file\" ";
} else {
$missing = "unzip";
}
}
print "<- uncompress_archive_cmd\n" if $opt_v > 2;
if ($missing) {
die "Unable to expand $archive_file because external\n",
"utility '$missing' is not available.\n",
"Another possibility is to use the --extract-with option.\n";
} else {
return $extract_cmd;
}
}
# 1}}}
sub read_list_file { # {{{1
my ($file, ) = @_;
# reads filenames from a STDIN pipe if $file == "-"
print "-> read_list_file($file)\n" if $opt_v > 2;
my $IN;
if ($file eq "-") {
open($IN, $file);
} else {
$IN = new IO::File $file, "r";
}
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
return ();
}
my @entry = ();
while (<$IN>) {
next if /^\s*$/ or /^\s*#/; # skip empty or commented lines
s/\cM$//; # DOS to Unix
chomp;
push @entry, $_;
}
$IN->close;
print "<- read_list_file\n" if $opt_v > 2;
return @entry;
}
# 1}}}
sub external_utility_exists { # {{{1
my $exe = shift @_;
my $success = 0;
if ($ON_WINDOWS) {
$success = 1 unless system $exe . ' > nul';
} else {
$success = 1 unless system $exe . ' >/dev/null 2>&1';
if (!$success) {
$success = 1 unless system "which" . " $exe" . ' >/dev/null 2>&1';
}
}
return $success;
} # 1}}}
sub write_xsl_file { # {{{1
print "-> write_xsl_file\n" if $opt_v > 2;
my $XSL = # <style> </style> {{{2
'<?xml version="1.0" encoding="UTF-8"?>
<!-- XSL file by Paul Schwann, January 2009.
Fixes for by-file and by-file-by-lang by d_uragan, November 2010.
-->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CLOC Results</title>
</head>
<style type="text/css">
table {
table-layout: auto;
border-collapse: collapse;
empty-cells: show;
}
td, th {
padding: 4px;
}
th {
background-color: #CCCCCC;
}
td {
text-align: center;
}
table, td, tr, th {
border: thin solid #999999;
}
</style>
<body>
<h3><xsl:value-of select="results/header"/></h3>
';
# 2}}}
if ($opt_by_file) {
$XSL .= # <table> </table>{{{2
' <table>
<thead>
<tr>
<th>File</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
<th>Language</th>
';
$XSL .=
' <th>3<sup>rd</sup> Generation Equivalent</th>
<th>Scale</th>
' if $opt_3;
$XSL .=
' </tr>
</thead>
<tbody>
<xsl:for-each select="results/files/file">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
<td><xsl:value-of select="@language"/></td>
';
$XSL .=
' <td><xsl:value-of select="@factor"/></td>
<td><xsl:value-of select="@scaled"/></td>
' if $opt_3;
$XSL .=
' </tr>
</xsl:for-each>
<tr>
<th>Total</th>
<th><xsl:value-of select="results/files/total/@blank"/></th>
<th><xsl:value-of select="results/files/total/@comment"/></th>
<th><xsl:value-of select="results/files/total/@code"/></th>
<th><xsl:value-of select="results/files/total/@language"/></th>
';
$XSL .=
' <th><xsl:value-of select="results/files/total/@factor"/></th>
<th><xsl:value-of select="results/files/total/@scaled"/></th>
' if $opt_3;
$XSL .=
' </tr>
</tbody>
</table>
<br/>
';
# 2}}}
}
if (!$opt_by_file or $opt_by_file_by_lang) {
$XSL .= # <table> </table> {{{2
' <table>
<thead>
<tr>
<th>Language</th>
<th>Files</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
';
$XSL .=
' <th>Scale</th>
<th>3<sup>rd</sup> Generation Equivalent</th>
' if $opt_3;
$XSL .=
' </tr>
</thead>
<tbody>
<xsl:for-each select="results/languages/language">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@files_count"/></td>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
';
$XSL .=
' <td><xsl:value-of select="@factor"/></td>
<td><xsl:value-of select="@scaled"/></td>
' if $opt_3;
$XSL .=
' </tr>
</xsl:for-each>
<tr>
<th>Total</th>
<th><xsl:value-of select="results/languages/total/@sum_files"/></th>
<th><xsl:value-of select="results/languages/total/@blank"/></th>
<th><xsl:value-of select="results/languages/total/@comment"/></th>
<th><xsl:value-of select="results/languages/total/@code"/></th>
';
$XSL .=
' <th><xsl:value-of select="results/languages/total/@factor"/></th>
<th><xsl:value-of select="results/languages/total/@scaled"/></th>
' if $opt_3;
$XSL .=
' </tr>
</tbody>
</table>
';
# 2}}}
}
$XSL.= <<'EO_XSL'; # {{{2
</body>
</html>
</xsl:template>
</xsl:stylesheet>
EO_XSL
# 2}}}
my $XSL_DIFF = <<'EO_DIFF_XSL'; # {{{2
<?xml version="1.0" encoding="UTF-8"?>
<!-- XSL file by Blazej Kroll, November 2010 -->
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:template match="/">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>CLOC Results</title>
</head>
<style type="text/css">
table {
table-layout: auto;
border-collapse: collapse;
empty-cells: show;
margin: 1em;
}
td, th {
padding: 4px;
}
th {
background-color: #CCCCCC;
}
td {
text-align: center;
}
table, td, tr, th {
border: thin solid #999999;
}
</style>
<body>
<h3><xsl:value-of select="results/header"/></h3>
EO_DIFF_XSL
# 2}}}
if ($opt_by_file) {
$XSL_DIFF.= <<'EO_DIFF_XSL'; # {{{2
<table>
<thead>
<tr><th colspan="4">Same</th>
</tr>
<tr>
<th>File</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/same/file">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
<table>
<thead>
<tr><th colspan="4">Modified</th>
</tr>
<tr>
<th>File</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/modified/file">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
<table>
<thead>
<tr><th colspan="4">Added</th>
</tr>
<tr>
<th>File</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/added/file">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
<table>
<thead>
<tr><th colspan="4">Removed</th>
</tr>
<tr>
<th>File</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/removed/file">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
EO_DIFF_XSL
# 2}}}
}
if (!$opt_by_file or $opt_by_file_by_lang) {
$XSL_DIFF.= <<'EO_DIFF_XSL'; # {{{2
<table>
<thead>
<tr><th colspan="5">Same</th>
</tr>
<tr>
<th>Language</th>
<th>Files</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/same/language">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@files_count"/></td>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
<table>
<thead>
<tr><th colspan="5">Modified</th>
</tr>
<tr>
<th>Language</th>
<th>Files</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/modified/language">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@files_count"/></td>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
<table>
<thead>
<tr><th colspan="5">Added</th>
</tr>
<tr>
<th>Language</th>
<th>Files</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/added/language">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@files_count"/></td>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
<table>
<thead>
<tr><th colspan="5">Removed</th>
</tr>
<tr>
<th>Language</th>
<th>Files</th>
<th>Blank</th>
<th>Comment</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<xsl:for-each select="diff_results/removed/language">
<tr>
<th><xsl:value-of select="@name"/></th>
<td><xsl:value-of select="@files_count"/></td>
<td><xsl:value-of select="@blank"/></td>
<td><xsl:value-of select="@comment"/></td>
<td><xsl:value-of select="@code"/></td>
</tr>
</xsl:for-each>
</tbody>
</table>
EO_DIFF_XSL
# 2}}}
}
$XSL_DIFF.= <<'EO_DIFF_XSL'; # {{{2
</body>
</html>
</xsl:template>
</xsl:stylesheet>
EO_DIFF_XSL
# 2}}}
if ($opt_diff) {
write_file($CLOC_XSL, {}, ( $XSL_DIFF ) );
} else {
write_file($CLOC_XSL, {}, ( $XSL ) );
}
print "<- write_xsl_file\n" if $opt_v > 2;
} # 1}}}
sub normalize_file_names { # {{{1
my (@files, ) = @_;
# Returns a hash of file names reduced to a canonical form
# (fully qualified file names, all path separators changed to /,
# Windows file names lowercased). Hash values are the original
# file name.
my %normalized = ();
foreach my $F (@files) {
my $F_norm = $F;
if ($ON_WINDOWS) {
$F_norm = lc $F_norm; # for case insensitive file name comparisons
$F_norm =~ s{\\}{/}g; # Windows directory separators to Unix
$F_norm =~ s{^\./}{}g; # remove leading ./
if (($F_norm !~ m{^/}) and ($F_norm !~ m{^\w:/})) {
# looks like a relative path; prefix with cwd
$F_norm = lc "$cwd/$F_norm";
}
} else {
$F_norm =~ s{^\./}{}g; # remove leading ./
if ($F_norm !~ m{^/}) {
# looks like a relative path; prefix with cwd
$F_norm = "$cwd/$F_norm";
}
}
# Remove trailing / so it does not interfere with further regex code
# that does not expect it
$F_norm =~ s{/+$}{};
$normalized{ $F_norm } = $F;
}
return %normalized;
} # 1}}}
sub combine_diffs { # {{{1
# subroutine by Andy (awalshe@sf.net)
# https://sourceforge.net/tracker/?func=detail&aid=3261017&group_id=174787&atid=870625
my ($ra_files) = @_;
my $res = "$URL v $VERSION\n";
my $dl = '-';
my $width = 79;
# columns are in this order
my @cols = ('files', 'blank', 'comment', 'code');
my %HoH = ();
foreach my $file (@{$ra_files}) {
my $IN = new IO::File $file, "r";
if (!defined $IN) {
warn "Unable to read $file; ignoring.\n";
next;
}
my $sec;
while (<$IN>) {
chomp;
s/\cM$//;
next if /^(http|Language|-----)/;
if (/^[A-Za-z0-9]+/) { # section title
$sec = $_;
chomp($sec);
$HoH{$sec} = () if ! exists $HoH{$sec};
next;
}
if (/^\s(same|modified|added|removed)/) { # calculated totals row
my @ar = grep { $_ ne '' } split(/ /, $_);
chomp(@ar);
my $ttl = shift @ar;
my $i = 0;
foreach(@ar) {
my $t = "${ttl}${dl}${cols[$i]}";
$HoH{$sec}{$t} = 0 if ! exists $HoH{$sec}{$t};
$HoH{$sec}{$t} += $_;
$i++;
}
}
}
$IN->close;
}
# rows are in this order
my @rows = ('same', 'modified', 'added', 'removed');
$res .= sprintf("%s\n", "-" x $width);
$res .= sprintf("%-19s %14s %14s %14s %14s\n", 'Language',
$cols[0], $cols[1], $cols[2], $cols[3]);
$res .= sprintf("%s\n", "-" x $width);
# no inputs? %HoH will be empty
return $res unless %HoH;
for my $sec ( keys %HoH ) {
next if $sec =~ /SUM:/;
next unless defined $HoH{$sec}; # eg, the header line
$res .= "$sec\n";
foreach (@rows) {
$res .= sprintf(" %-18s %14s %14s %14s %14s\n",
$_, $HoH{$sec}{"${_}${dl}${cols[0]}"},
$HoH{$sec}{"${_}${dl}${cols[1]}"},
$HoH{$sec}{"${_}${dl}${cols[2]}"},
$HoH{$sec}{"${_}${dl}${cols[3]}"});
}
}
$res .= sprintf("%s\n", "-" x $width);
my $sec = 'SUM:';
$res .= "$sec\n";
foreach (@rows) {
$res .= sprintf(" %-18s %14s %14s %14s %14s\n",
$_, $HoH{$sec}{"${_}${dl}${cols[0]}"},
$HoH{$sec}{"${_}${dl}${cols[1]}"},
$HoH{$sec}{"${_}${dl}${cols[2]}"},
$HoH{$sec}{"${_}${dl}${cols[3]}"});
}
$res .= sprintf("%s\n", "-" x $width);
return $res;
} # 1}}}
sub get_time { # {{{1
if ($HAVE_Time_HiRes) {
return Time::HiRes::time();
} else {
return time();
}
} # 1}}}
sub really_is_D { # {{{1
# Ref bug 131, files ending with .d could be init.d scripts
# instead of D language source files.
my ($file , # in
$rh_Err , # in hash of error codes
$raa_errors , # out
) = @_;
print "-> really_is_D($file)\n" if $opt_v > 2;
my ($possible_script, $L) = peek_at_first_line($file, $rh_Err, $raa_errors);
print "<- really_is_D($file)\n" if $opt_v > 2;
return $possible_script; # null string if D, otherwise a language
} # 1}}}
sub no_autogen_files { # {{{1
# ref https://github.com/AlDanial/cloc/issues/151
my ($print,) = @_;
print "-> no_autogen($print)\n" if $opt_v > 2;
# These sometimes created manually?
# acinclude.m4
# configure.ac
# Makefile.am
my @files = qw (
aclocal.m4
announce-gen
autogen.sh
bootstrap
compile
config.guess
config.h.in
config.rpath
config.status
config.sub
configure
configure.in
depcomp
gendocs.sh
gitlog-to-changelog
git-version-gen
gnupload
gnu-web-doc-update
install-sh
libtool
libtool.m4
link-warning.h
ltmain.sh
lt~obsolete.m4
ltoptions.m4
ltsugar.m4
ltversion.in
ltversion.m4
Makefile.in
mdate-sh
missing
mkinstalldirs
test-driver
texinfo.tex
update-copyright
useless-if-before-free
vc-list-files
ylwrap
);
if ($print) {
printf "cloc will ignore these %d files with --no-autogen:\n", scalar @files;
foreach my $F (@files) {
print " $F\n";
}
print "Additionally, Go files with '// Code generated by .* DO NOT EDIT.'\n";
print "on the first line are ignored.\n";
}
print "<- no_autogen()\n" if $opt_v > 2;
return @files;
} # 1}}}
sub load_from_config_file { # {{{1
# Supports all options except --config itself which would
# be pointless.
my ($config_file,
$rs_by_file ,
$rs_by_file_by_lang ,
$rs_categorized ,
$rs_counted ,
$rs_include_ext ,
$rs_include_lang ,
$rs_exclude_content ,
$rs_exclude_lang ,
$rs_exclude_dir ,
$rs_exclude_list_file ,
$rs_explain ,
$rs_extract_with ,
$rs_found ,
$rs_count_diff ,
$rs_diff ,
$rs_diff_alignment ,
$rs_diff_timeout ,
$rs_timeout ,
$rs_html ,
$rs_ignored ,
$rs_quiet ,
$rs_force_lang_def ,
$rs_read_lang_def ,
$rs_show_ext ,
$rs_show_lang ,
$rs_progress_rate ,
$rs_print_filter_stages ,
$rs_report_file ,
$ra_script_lang ,
$rs_sdir ,
$rs_skip_uniqueness ,
$rs_strip_comments ,
$rs_original_dir ,
$rs_sum_reports ,
$rs_hide_rate ,
$rs_processes ,
$rs_unicode ,
$rs_3 ,
$rs_v ,
$rs_vcs ,
$rs_version ,
$rs_write_lang_def ,
$rs_write_lang_def_incl_dup,
$rs_xml ,
$rs_xsl ,
$ra_force_lang ,
$rs_lang_no_ext ,
$rs_yaml ,
$rs_csv ,
$rs_csv_delimiter ,
$rs_json ,
$rs_md ,
$rs_fullpath ,
$rs_match_f ,
$rs_not_match_f ,
$rs_match_d ,
$rs_not_match_d ,
$rs_list_file ,
$rs_help ,
$rs_skip_win_hidden ,
$rs_read_binary_files ,
$rs_sql ,
$rs_sql_project ,
$rs_sql_append ,
$rs_sql_style ,
$rs_inline ,
$rs_exclude_ext ,
$rs_ignore_whitespace ,
$rs_ignore_case ,
$rs_ignore_case_ext ,
$rs_follow_links ,
$rs_autoconf ,
$rs_sum_one ,
$rs_by_percent ,
$rs_stdin_name ,
$rs_force_on_windows ,
$rs_force_on_unix ,
$rs_show_os ,
$rs_skip_archive ,
$rs_max_file_size ,
$rs_use_sloccount ,
$rs_no_autogen ,
$rs_force_git ,
$rs_strip_str_comments ,
$rs_file_encoding ,
$rs_docstring_as_code ,
$rs_stat ,
) = @_;
# look for runtime configuration file in
# $ENV{'HOME'}/.config/cloc/options.txt -> POSIX
# $ENV{'APPDATA'} . 'cloc'
print "-> load_from_config_file($config_file)\n" if $opt_v and $opt_v > 2;
if (!-f $config_file) {
print "<- load_from_config_file() (no such file: $config_file)\n" if $opt_v and $opt_v > 2;
return;
} elsif (!-r $config_file) {
print "<- load_from_config_file() (unable to read $config_file)\n" if $opt_v and $opt_v > 2;
return;
}
print "Reading options from $config_file.\n" if defined $opt_v;
my @lines = read_file($config_file);
foreach (@lines) {
next if /^\s*$/ or /^\s*#/;
s/\s*--//;
if (!defined ${$rs_by_file} and /by_file|by-file/) { ${$rs_by_file} = 1;
} elsif (!defined ${$rs_by_file_by_lang} and /by_file_by_lang|by-file-by-lang/) { ${$rs_by_file_by_lang} = 1;
} elsif (!defined ${$rs_categorized} and /categorized(=|\s+)(.*?)$/) { ${$rs_categorized} = $2;
} elsif (!defined ${$rs_counted} and /counted(=|\s+)(.*?)$/) { ${$rs_counted} = $2;
} elsif (!defined ${$rs_include_ext} and /include_ext|include-ext(=|\s+)(.*?)$/) { ${$rs_include_ext} = $2;
} elsif (!defined ${$rs_include_lang} and /include_lang|include-lang(=|\s+)(.*?)$/) { ${$rs_include_lang} = $2;
} elsif (!defined ${$rs_exclude_content} and /exclude_content|exclude-content(=|\s+)(.*?)$/) { ${$rs_exclude_content} = $2;
} elsif (!defined ${$rs_exclude_lang} and /exclude_lang|exclude-lang(=|\s+)(.*?)$/) { ${$rs_exclude_lang} = $2;
} elsif (!defined ${$rs_exclude_dir} and /exclude_dir|exclude-dir(=|\s+)(.*?)$/) { ${$rs_exclude_dir} = $2;
} elsif (!defined ${$rs_explain} and /explain(=|\s+)(.*?)$/) { ${$rs_explain} = $2;
} elsif (!defined ${$rs_extract_with} and /extract_with|extract-with(=|\s+)(.*?)$/) { ${$rs_extract_with} = $2;
} elsif (!defined ${$rs_found} and /found(=|\s+)(.*?)$/) { ${$rs_found} = $2;
} elsif (!defined ${$rs_count_diff} and /count_and_diff|count-and-diff/) { ${$rs_count_diff} = 1;
} elsif (!defined ${$rs_diff} and /diff/) { ${$rs_diff} = 1;
} elsif (!defined ${$rs_diff_alignment} and /diff-alignment|diff_alignment(=|\s+)(.*?)$/) { ${$rs_diff_alignment} = $2;
} elsif (!defined ${$rs_diff_timeout} and /diff-timeout|diff_timeout(=|\s+)i/) { ${$rs_diff_timeout} = $1;
} elsif (!defined ${$rs_timeout} and /timeout(=|\s+)i/) { ${$rs_timeout} = $1;
} elsif (!defined ${$rs_html} and /html/) { ${$rs_html} = 1;
} elsif (!defined ${$rs_ignored} and /ignored(=|\s+)(.*?)$/) { ${$rs_ignored} = $2;
} elsif (!defined ${$rs_quiet} and /quiet/) { ${$rs_quiet} = 1;
} elsif (!defined ${$rs_force_lang_def} and /force_lang_def|force-lang-def(=|\s+)(.*?)$/) { ${$rs_force_lang_def} = $2;
} elsif (!defined ${$rs_read_lang_def} and /read_lang_def|read-lang-def(=|\s+)(.*?)$/) { ${$rs_read_lang_def} = $2;
} elsif (!defined ${$rs_progress_rate} and /progress_rate|progress-rate(=|\s+)(\d+)/) { ${$rs_progress_rate} = $2;
} elsif (!defined ${$rs_print_filter_stages} and /print_filter_stages|print-filter-stages/) { ${$rs_print_filter_stages}= 1;
} elsif (!defined ${$rs_report_file} and /report_file|report-file(=|\s+)(.*?)$/) { ${$rs_report_file} = $2;
} elsif (!defined ${$rs_report_file} and /out(=|\s+)(.*?)$/) { ${$rs_report_file} = $2;
} elsif (!defined ${$rs_sdir} and /sdir(=|\s+)(.*?)$/) { ${$rs_sdir} = $2;
} elsif (!defined ${$rs_skip_uniqueness} and /skip_uniqueness|skip-uniqueness/) { ${$rs_skip_uniqueness} = 1;
} elsif (!defined ${$rs_strip_comments} and /strip_comments|strip-comments(=|\s+)(.*?)$/) { ${$rs_strip_comments} = $2;
} elsif (!defined ${$rs_original_dir} and /original_dir|original-dir/) { ${$rs_original_dir} = 1;
} elsif (!defined ${$rs_sum_reports} and /sum_reports|sum-reports/) { ${$rs_sum_reports} = 1;
} elsif (!defined ${$rs_hide_rate} and /hid_rate|hide-rate/) { ${$rs_hide_rate} = 1;
} elsif (!defined ${$rs_processes} and /processes(=|\s+)(\d+)/) { ${$rs_processes} = $2;
} elsif (!defined ${$rs_unicode} and /unicode/) { ${$rs_unicode} = 1;
} elsif (!defined ${$rs_3} and /3/) { ${$rs_3} = 1;
} elsif (!defined ${$rs_vcs} and /vcs(=|\s+)s/) { ${$rs_vcs} = $2;
} elsif (!defined ${$rs_version} and /version/) { ${$rs_version} = 1;
} elsif (!defined ${$rs_write_lang_def} and /write_lang_def|write-lang-def(=|\s+)(.*?)$/) { ${$rs_write_lang_def} = $2;
} elsif (!defined ${$rs_write_lang_def_incl_dup} and /write_lang_def_incl_dup|write-lang-def-incl-dup(=|\s+)(.*?)$/) { ${$rs_write_lang_def_incl_dup} = $2;
} elsif (!defined ${$rs_xml} and /xml/) { ${$rs_xml} = 1;
} elsif (!defined ${$rs_xsl} and /xsl(=|\s+)(.*?)$/) { ${$rs_xsl} = $2;
} elsif (!defined ${$rs_lang_no_ext} and /lang_no_ext|lang-no-ext(=|\s+)(.*?)$/) { ${$rs_lang_no_ext} = $2;
} elsif (!defined ${$rs_yaml} and /yaml/) { ${$rs_yaml} = 1;
} elsif (!defined ${$rs_csv} and /csv/) { ${$rs_csv} = 1;
} elsif (!defined ${$rs_csv_delimiter} and /csv_delimeter|csv-delimiter(=|\s+)(.*?)$/) { ${$rs_csv_delimiter} = $2;
} elsif (!defined ${$rs_json} and /json/) { ${$rs_json} = 1;
} elsif (!defined ${$rs_md} and /md/) { ${$rs_md} = 1;
} elsif (!defined ${$rs_fullpath} and /fullpath/) { ${$rs_fullpath} = 1;
} elsif (!defined ${$rs_match_f} and /match_f|match-f(=|\s+)(.*?)$/) { ${$rs_match_f} = $2;
} elsif (!defined ${$rs_not_match_f} and /not_match_f|not-match-f(=|\s+)(.*?)$/) { ${$rs_not_match_f} = $2;
} elsif (!defined ${$rs_match_d} and /match_d|match-d(=|\s+)(.*?)$/) { ${$rs_match_d} = $2;
} elsif (!defined ${$rs_not_match_d} and /not_match_d|not-match-d(=|\s+)(.*?)$/) { ${$rs_not_match_d} = $2;
} elsif (!defined ${$rs_list_file} and /list_file|list-file(=|\s+)(.*?)$/) { ${$rs_list_file} = $2;
} elsif (!defined ${$rs_help} and /help/) { ${$rs_help} = 1;
} elsif (!defined ${$rs_skip_win_hidden} and /skip_win_hidden|skip-win-hidden/) { ${$rs_skip_win_hidden} = 1;
} elsif (!defined ${$rs_read_binary_files} and /read_binary_files|read-binary-files/) { ${$rs_read_binary_files} = 1;
} elsif (!defined ${$rs_sql} and /sql(=|\s+)(.*?)$/) { ${$rs_sql} = $2;
} elsif (!defined ${$rs_sql_project} and /sql_project|sql-project(=|\s+)(.*?)$/) { ${$rs_sql_project} = $2;
} elsif (!defined ${$rs_sql_append} and /sql_append|sql-append/) { ${$rs_sql_append} = 1;
} elsif (!defined ${$rs_sql_style} and /sql_style|sql-style(=|\s+)(.*?)$/) { ${$rs_sql_style} = $2;
} elsif (!defined ${$rs_inline} and /inline/) { ${$rs_inline} = 1;
} elsif (!defined ${$rs_exclude_ext} and /exclude_ext|exclude-ext(=|\s+)(.*?)$/) { ${$rs_exclude_ext} = $2;
} elsif (!defined ${$rs_ignore_whitespace} and /ignore_whitespace|ignore-whitespace/) { ${$rs_ignore_whitespace} = 1;
} elsif (!defined ${$rs_ignore_case_ext} and /ignore_case_ext|ignore-case-ext/) { ${$rs_ignore_case_ext} = 1;
} elsif (!defined ${$rs_ignore_case} and /ignore_case|ignore-case/) { ${$rs_ignore_case} = 1;
} elsif (!defined ${$rs_follow_links} and /follow_links|follow-links/) { ${$rs_follow_links} = 1;
} elsif (!defined ${$rs_autoconf} and /autoconf/) { ${$rs_autoconf} = 1;
} elsif (!defined ${$rs_sum_one} and /sum_one|sum-one/) { ${$rs_sum_one} = 1;
} elsif (!defined ${$rs_by_percent} and /by_percent|by-percent(=|\s+)(.*?)$/) { ${$rs_by_percent} = $2;
} elsif (!defined ${$rs_stdin_name} and /stdin_name|stdin-name(=|\s+)(.*?)$/) { ${$rs_stdin_name} = $2;
} elsif (!defined ${$rs_force_on_windows} and /windows/) { ${$rs_force_on_windows} = 1;
} elsif (!defined ${$rs_force_on_unix} and /unix/) { ${$rs_force_on_unix} = 1;
} elsif (!defined ${$rs_show_os} and /show_os|show-os/) { ${$rs_show_os} = 1;
} elsif (!defined ${$rs_skip_archive} and /skip_archive|skip-archive(=|\s+)(.*?)$/) { ${$rs_skip_archive} = $2;
} elsif (!defined ${$rs_max_file_size} and /max_file_size|max-file-size(=|\s+)(\d+)/) { ${$rs_max_file_size} = $2;
} elsif (!defined ${$rs_use_sloccount} and /use_sloccount|use-sloccount/) { ${$rs_use_sloccount} = 1;
} elsif (!defined ${$rs_no_autogen} and /no_autogen|no-autogen/) { ${$rs_no_autogen} = 1;
} elsif (!defined ${$rs_force_git} and /git/) { ${$rs_force_git} = 1;
} elsif (!defined ${$rs_exclude_list_file} and /exclude_list_file|exclude-list-file(=|\s+)(.*?)$/)
{ ${$rs_exclude_list_file} = $2;
} elsif (!defined ${$rs_v} and /(verbose|v)((=|\s+)(\d+))?/) {
if (!defined $4) { ${$rs_v} = 0; }
else { ${$rs_v} = $4; }
} elsif (!defined $ra_script_lang and /script_lang|script-lang(=|\s+)(.*?)$/) {
push @{$ra_script_lang} , $2;
} elsif (!defined $ra_force_lang and /force_lang|force-lang(=|\s+)(.*?)$/) {
push @{$ra_force_lang} , $2;
} elsif (!defined ${$rs_show_ext} and /(show_ext|show-ext)((=|\s+)(.*))?$/) {
if (!defined $4) { ${$rs_show_ext} = 0; }
else { ${$rs_show_ext} = $4; }
} elsif (!defined ${$rs_show_lang} and /(show_lang|show-lang)((=|\s+)(.*))?s/){
if (!defined $4) { ${$rs_show_lang} = 0; }
else { ${$rs_show_lang} = $4; }
} elsif (!defined ${$rs_strip_str_comments} and /(strip_str_comments|strip-str-comments)/) { ${$rs_strip_str_comments} = 1;
} elsif (!defined ${$rs_file_encoding} and /file_encoding|file-encoding(=|\s+)(\S+)/) { ${$rs_file_encoding} = $2;
} elsif (!defined ${$rs_docstring_as_code} and /docstring_as_code|docstring-as-code/) { ${$rs_docstring_as_code} = 1;
} elsif (!defined ${$rs_stat} and /stat/) { ${$rs_stat} = 1;
}
}
} # 1}}}
sub trick_pp_packer_encode { # {{{1
use Encode;
# PAR::Packer gives 'Unknown PerlIO layer "encoding"' unless it is
# forced into using this module.
my ($OUT, $JunkFile) = tempfile(UNLINK => 1); # delete on exit
open($OUT, "> :encoding(utf8)", $JunkFile);
close($OUT);
}
# 1}}}
sub really_is_smarty { # {{{1
# Given filename, returns TRUE if its contents look like Smarty template
my ($filename, ) = @_;
print "-> really_is_smarty($filename)\n" if $opt_v > 2;
my @lines = read_file($filename);
my $points = 0;
foreach my $L (@lines) {
if (($L =~ /\{(if|include)\s/) or
($L =~ /\{\/if\}/) or
($L =~ /(\{\*|\*\})/) or
($L =~ /\{\$\w/)) {
++$points;
}
last if $points >= 2;
}
print "<- really_is_smarty(points=$points)\n" if $opt_v > 2;
return $points >= 2;
} # 1}}}
# subroutines copied from SLOCCount
my %php_files = (); # really_is_php()
sub really_is_pascal { # {{{1
# Given filename, returns TRUE if its contents really are Pascal.
# This isn't as obvious as it seems.
# Many ".p" files are Perl files
# (such as /usr/src/redhat/BUILD/ispell-3.1/dicts/czech/glob.p),
# others are C extractions
# (such as /usr/src/redhat/BUILD/linux/include/linux/umsdos_fs.p
# and some files in linuxconf).
# However, test files in "p2c" really are Pascal, for example.
# Note that /usr/src/redhat/BUILD/ucd-snmp-4.1.1/ov/bitmaps/UCD.20.p
# is actually C code. The heuristics determine that they're not Pascal,
# but because it ends in ".p" it's not counted as C code either.
# I believe this is actually correct behavior, because frankly it
# looks like it's automatically generated (it's a bitmap expressed as code).
# Rather than guess otherwise, we don't include it in a list of
# source files. Let's face it, someone who creates C files ending in ".p"
# and expects them to be counted by default as C files in SLOCCount needs
# their head examined. I suggest examining their head
# with a sucker rod (see syslogd(8) for more on sucker rods).
# This heuristic counts as Pascal such files such as:
# /usr/src/redhat/BUILD/teTeX-1.0/texk/web2c/tangleboot.p
# Which is hand-generated. We don't count woven documents now anyway,
# so this is justifiable.
my $filename = shift;
chomp($filename);
# The heuristic is as follows: it's Pascal _IF_ it has all of the following
# (ignoring {...} and (*...*) comments):
# 1. "^..program NAME" or "^..unit NAME",
# 2. "procedure", "function", "^..interface", or "^..implementation",
# 3. a "begin", and
# 4. it ends with "end.",
#
# Or it has all of the following:
# 1. "^..module NAME" and
# 2. it ends with "end.".
#
# Or it has all of the following:
# 1. "^..program NAME",
# 2. a "begin", and
# 3. it ends with "end.".
#
# The "end." requirements in particular filter out non-Pascal.
#
# Note (jgb): this does not detect Pascal main files in fpc, like
# fpc-1.0.4/api/test/testterminfo.pas, which does not have "program" in
# it
my $is_pascal = 0; # Value to determine.
my $has_program = 0;
my $has_unit = 0;
my $has_module = 0;
my $has_procedure_or_function = 0;
my $found_begin = 0;
my $found_terminating_end = 0;
my $has_begin = 0;
open(PASCAL_FILE, "<$filename") ||
die "Can't open $filename to determine if it's pascal.\n";
while(<PASCAL_FILE>) {
s/\{.*?\}//g; # Ignore {...} comments on this line; imperfect, but effective.
s/\(\*.*?\*\)//g; # Ignore (*...*) comments on this line; imperfect, but effective.
if (m/\bprogram\s+[A-Za-z]/i) {$has_program=1;}
if (m/\bunit\s+[A-Za-z]/i) {$has_unit=1;}
if (m/\bmodule\s+[A-Za-z]/i) {$has_module=1;}
if (m/\bprocedure\b/i) { $has_procedure_or_function = 1; }
if (m/\bfunction\b/i) { $has_procedure_or_function = 1; }
if (m/^\s*interface\s+/i) { $has_procedure_or_function = 1; }
if (m/^\s*implementation\s+/i) { $has_procedure_or_function = 1; }
if (m/\bbegin\b/i) { $has_begin = 1; }
# Originally I said:
# "This heuristic fails if there are multi-line comments after
# "end."; I haven't seen that in real Pascal programs:"
# But jgb found there are a good quantity of them in Debian, specially in
# fpc (at the end of a lot of files there is a multiline comment
# with the changelog for the file).
# Therefore, assume Pascal if "end." appears anywhere in the file.
if (m/end\.\s*$/i) {$found_terminating_end = 1;}
# elsif (m/\S/) {$found_terminating_end = 0;}
}
close(PASCAL_FILE);
# Okay, we've examined the entire file looking for clues;
# let's use those clues to determine if it's really Pascal:
if ( ( ($has_unit || $has_program) && $has_procedure_or_function &&
$has_begin && $found_terminating_end ) ||
( $has_module && $found_terminating_end ) ||
( $has_program && $has_begin && $found_terminating_end ) )
{$is_pascal = 1;}
return $is_pascal;
} # 1}}}
sub really_is_incpascal { # {{{1
# Given filename, returns TRUE if its contents really are Pascal.
# For .inc files (mainly seen in fpc)
my $filename = shift;
chomp($filename);
# The heuristic is as follows: it is Pascal if any of the following:
# 1. really_is_pascal returns true
# 2. Any usual reserved word is found (program, unit, const, begin...)
# If the general routine for Pascal files works, we have it
if (really_is_pascal($filename)) {
return 1;
}
my $is_pascal = 0; # Value to determine.
my $found_begin = 0;
open(PASCAL_FILE, "<$filename") ||
die "Can't open $filename to determine if it's pascal.\n";
while(<PASCAL_FILE>) {
s/\{.*?\}//g; # Ignore {...} comments on this line; imperfect, but effective.
s/\(\*.*?\*\)//g; # Ignore (*...*) comments on this line; imperfect, but effective.
if (m/\bprogram\s+[A-Za-z]/i) {$is_pascal=1;}
if (m/\bunit\s+[A-Za-z]/i) {$is_pascal=1;}
if (m/\bmodule\s+[A-Za-z]/i) {$is_pascal=1;}
if (m/\bprocedure\b/i) {$is_pascal = 1; }
if (m/\bfunction\b/i) {$is_pascal = 1; }
if (m/^\s*interface\s+/i) {$is_pascal = 1; }
if (m/^\s*implementation\s+/i) {$is_pascal = 1; }
if (m/\bconstant\s+/i) {$is_pascal=1;}
if (m/\bbegin\b/i) { $found_begin = 1; }
if ((m/end\.\s*$/i) && ($found_begin = 1)) {$is_pascal = 1;}
if ($is_pascal) {
last;
}
}
close(PASCAL_FILE);
return $is_pascal;
} # 1}}}
sub really_is_php { # {{{1
# Given filename, returns TRUE if its contents really is php.
my $filename = shift;
chomp($filename);
my $is_php = 0; # Value to determine.
# Need to find a matching pair of surrounds, with ending after beginning:
my $normal_surround = 0; # <?; bit 0 = <?, bit 1 = ?>
my $script_surround = 0; # <script..>; bit 0 = <script language="php">
my $asp_surround = 0; # <%; bit 0 = <%, bit 1 = %>
# Return cached result, if available:
if ($php_files{$filename}) { return $php_files{$filename};}
open(PHP_FILE, "<$filename") ||
die "Can't open $filename to determine if it's php.\n";
while(<PHP_FILE>) {
if (m/\<\?/) { $normal_surround |= 1; }
if (m/\?\>/ && ($normal_surround & 1)) { $normal_surround |= 2; }
if (m/\<script.*language="?php"?/i) { $script_surround |= 1; }
if (m/\<\/script\>/i && ($script_surround & 1)) { $script_surround |= 2; }
if (m/\<\%/) { $asp_surround |= 1; }
if (m/\%\>/ && ($asp_surround & 1)) { $asp_surround |= 2; }
}
close(PHP_FILE);
if ( ($normal_surround == 3) || ($script_surround == 3) ||
($asp_surround == 3)) {
$is_php = 1;
}
$php_files{$filename} = $is_php; # Store result in cache.
return $is_php;
} # 1}}}
__END__
mode values (stat $item)[2]
Unix Windows
file: 33188 33206
dir : 16832 16895
link: 33261 33206
pipe: 4544 null
|